Skip to content

Commit

Permalink
Merge branch 'stats'
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertvanheusden committed Nov 7, 2024
2 parents 79397c0 + 7787edc commit 6af42db
Show file tree
Hide file tree
Showing 20 changed files with 154 additions and 206 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,8 @@ This software has a custom SNMP library (SNMP agent).
* .1.3.6.1.2.1.142.1.6.3.1.1 - logouts
* .1.3.6.1.4.1.2021.100.2 - software version (not in Posix version)
* .1.3.6.1.4.1.2021.100.3 - build date
* .1.3.6.1.4.1.2021.11.54 - I/O wait in 100ths of a second
* .1.3.6.1.4.1.2021.11.9.0 - CPU usage
* .1.3.6.1.4.1.2021.13.15.1.1.2 - device name
* .1.3.6.1.4.1.2021.13.15.1.1.3 - number of bytes read
* .1.3.6.1.4.1.2021.13.15.1.1.4 - number of bytes written
* .1.3.6.1.4.1.2021.13.15.1.1.5 - number of reads
* .1.3.6.1.4.1.2021.13.15.1.1.6 - number of writes
* .1.3.6.1.4.1.2021.4.11.0 - free RAM (kB heap space, only on microcontrollers)
* .1.3.6.1.4.1.2021.9.1.9.1 - disk free estimate (will only work when using TRIM/UNMAP/DISCARD)

Expand Down
7 changes: 0 additions & 7 deletions backend-file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ uint64_t backend_file::get_block_size() const

bool backend_file::sync()
{
n_syncs++;
ts_last_acces = get_micros();
#if defined(__MINGW32__)
if (_commit(fd) == 0)
Expand Down Expand Up @@ -91,7 +90,6 @@ bool backend_file::write(const uint64_t block_nr, const uint32_t n_blocks, const
if (rc == -1)
DOLOG(logging::ll_error, "backend_file::write", identifier, "ERROR writing: %s", strerror(errno));
ts_last_acces = get_micros();
bytes_written += n_bytes;
return rc == ssize_t(n_bytes);
}

Expand All @@ -117,7 +115,6 @@ bool backend_file::trim(const uint64_t block_nr, const uint32_t n_blocks)
#endif
if (rc == -1)
DOLOG(logging::ll_error, "backend_file::trim", identifier, "unmapping: %s", strerror(errno));
n_trims += n_blocks;
ts_last_acces = get_micros();
return rc == 0;
}
Expand Down Expand Up @@ -145,7 +142,6 @@ bool backend_file::read(const uint64_t block_nr, const uint32_t n_blocks, uint8_
else if (rc != ssize_t(n_bytes))
DOLOG(logging::ll_error, "backend_file::read", identifier, "short read, requested: %zu, received: %zd", n_bytes, rc);
ts_last_acces = get_micros();
bytes_read += n_bytes;
return rc == ssize_t(n_bytes);
}

Expand Down Expand Up @@ -183,7 +179,6 @@ backend::cmpwrite_result_t backend_file::cmpwrite(const uint64_t block_nr, const
result = cmpwrite_result_t::CWR_READ_ERROR;
break;
}
bytes_read += block_size;

// compare
if (memcmp(buffer, &data_compare[i * block_size], block_size) != 0) {
Expand All @@ -210,8 +205,6 @@ backend::cmpwrite_result_t backend_file::cmpwrite(const uint64_t block_nr, const
result = cmpwrite_result_t::CWR_WRITE_ERROR;
}
else {
bytes_written += block_size;

ts_last_acces = get_micros();
}
}
Expand Down
7 changes: 0 additions & 7 deletions backend-nbd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ bool backend_nbd::invoke_nbd(const uint32_t command, const uint64_t offset, cons

bool backend_nbd::sync()
{
n_syncs++;
ts_last_acces = get_micros();

return invoke_nbd(NBD_CMD_FLUSH, 0, 0, nullptr);
Expand All @@ -262,7 +261,6 @@ bool backend_nbd::write(const uint64_t block_nr, const uint32_t n_blocks, const
unlock_range(lock_list);

ts_last_acces = get_micros();
bytes_written += n_bytes;

return rc;
}
Expand All @@ -280,7 +278,6 @@ bool backend_nbd::trim(const uint64_t block_nr, const uint32_t n_blocks)
unlock_range(lock_list);

ts_last_acces = get_micros();
n_trims += n_blocks;

return rc;
}
Expand All @@ -299,7 +296,6 @@ bool backend_nbd::read(const uint64_t block_nr, const uint32_t n_blocks, uint8_t
unlock_range(lock_list);

ts_last_acces = get_micros();
bytes_read += n_bytes;

return rc;
}
Expand All @@ -324,7 +320,6 @@ backend::cmpwrite_result_t backend_nbd::cmpwrite(const uint64_t block_nr, const
result = cmpwrite_result_t::CWR_READ_ERROR;
break;
}
bytes_read += block_size;

// compare
if (memcmp(buffer, &data_compare[i * block_size], block_size) != 0) {
Expand All @@ -344,8 +339,6 @@ backend::cmpwrite_result_t backend_nbd::cmpwrite(const uint64_t block_nr, const
result = cmpwrite_result_t::CWR_WRITE_ERROR;
}
else {
bytes_written += block_size;

ts_last_acces = get_micros();
}
}
Expand Down
13 changes: 0 additions & 13 deletions backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ backend::~backend()
{
}

void backend::get_and_reset_stats(uint64_t *const bytes_read, uint64_t *const bytes_written, uint64_t *const n_syncs, uint64_t *const n_trims)
{
*bytes_read = this->bytes_read;
*bytes_written = this->bytes_written;
*n_syncs = this->n_syncs;
*n_trims = this->n_trims;

this->bytes_read = 0;
this->bytes_written = 0;
this->n_syncs = 0;
this->n_trims = 0;
}

std::pair<uint64_t, uint32_t> backend::get_idle_state()
{
return { ts_last_acces, 500000 };
Expand Down
7 changes: 0 additions & 7 deletions backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ class backend
{
protected:
const std::string identifier;

uint64_t bytes_read { 0 };
uint64_t bytes_written { 0 };
uint64_t n_syncs { 0 };
uint64_t n_trims { 0 };
uint64_t ts_last_acces { 0 };

#if !(defined(ARDUINO) || defined(TEENSY4_1) || defined(RP2040W))
Expand All @@ -51,8 +46,6 @@ class backend

virtual bool sync() = 0;

void get_and_reset_stats(uint64_t *const bytes_read, uint64_t *const bytes_written, uint64_t *const n_syncs, uint64_t *const n_trims);

enum cmpwrite_result_t { CWR_OK, CWR_MISMATCH, CWR_READ_ERROR, CWR_WRITE_ERROR };

virtual bool write (const uint64_t block_nr, const uint32_t n_blocks, const uint8_t *const data) = 0;
Expand Down
29 changes: 29 additions & 0 deletions gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,32 @@ struct data_descriptor {
uint64_t lba;
uint32_t n_sectors;
};

struct io_stats_t {
uint64_t n_reads { 0 };
uint64_t bytes_read { 0 };
uint64_t n_writes { 0 };
uint64_t bytes_written { 0 };
uint64_t n_syncs { 0 };
uint64_t blocks_trimmed { 0 };
// 1.3.6.1.4.1.2021.11.54: "The number of 'ticks' (typically 1/100s) spent waiting for IO."
// https://www.circitor.fr/Mibs/Html/U/UCD-SNMP-MIB.php#ssCpuRawWait
uint64_t io_wait { 0 };

io_stats_t() {
}

uint64_t get_n_iops() const {
return n_reads + n_writes;
}

void reset() {
n_reads = 0;
bytes_read = 0;
n_writes = 0;
bytes_written = 0;
n_syncs = 0;
blocks_trimmed = 0;
io_wait = 0;
}
};
2 changes: 1 addition & 1 deletion iscsi-pdu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ std::optional<iscsi_response_set> iscsi_pdu_scsi_cmd::get_response(scsi *const s
DOLOG(logging::ll_debug, "iscsi_pdu_scsi_cmd::get_response", ses->get_endpoint_name(), "working on ITT %08x for LUN %" PRIu64, get_Itasktag(), lun);

uint64_t iscsi_expected = get_ExpDatLen();
auto scsi_reply = sd->send(lun, get_CDB(), 16, data);
auto scsi_reply = sd->send(ses->get_io_stats(), lun, get_CDB(), 16, data);
if (scsi_reply.has_value() == false) {
DOLOG(logging::ll_warning, "iscsi_pdu_scsi_cmd::get_response", ses->get_endpoint_name(), "scsi::send returned nothing");
return { };
Expand Down
7 changes: 3 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ int main(int argc, char *argv[])

init_my_getrandom();

io_stats_t ios { };
iscsi_stats_t is { };
iscsi_stats_t is { };

backend *b = nullptr;

Expand All @@ -210,7 +209,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Failed to initialize storage backend\n");
return 1;
}
scsi sd(b, trim_level, &ios);
scsi sd(b, trim_level);

com_sockets c(ip_address, port, &stop);
if (c.begin() == false) {
Expand All @@ -234,7 +233,7 @@ int main(int argc, char *argv[])
snmp *snmp_ { nullptr };
snmp_data *snmp_data_ { nullptr };
if (use_snmp)
init_snmp(&snmp_, &snmp_data_, &ios, &is, get_diskspace, b, &cpu_usage, &ram_free_kb, &stop, snmp_port);
init_snmp(&snmp_, &snmp_data_, &is, get_diskspace, b, &cpu_usage, &ram_free_kb, &stop, snmp_port);

server s(&sd, &c, &is, target_name, digest_chk);

Expand Down
10 changes: 0 additions & 10 deletions microcontrollers/RP2040W/backend-sdcard-rp2040w.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,8 @@ backend_sdcard_rp2040w::~backend_sdcard_rp2040w()
bool backend_sdcard_rp2040w::sync()
{
write_led(led_write, HIGH);

n_syncs++;

if (file.sync() != FR_OK)
DOLOG(logging::ll_error, "backend_sdcard_rp2040w::sync", "-", "Cannot sync data to SD-card");

write_led(led_write, LOW);

ts_last_acces = get_micros();
Expand Down Expand Up @@ -129,7 +125,6 @@ bool backend_sdcard_rp2040w::write(const uint64_t block_nr, const uint32_t n_blo
}

size_t n_bytes_to_write = n_blocks * iscsi_block_size;
bytes_written += n_bytes_to_write;

bool rc = false;
for(int i=0; i<5; i++) { // 5 is arbitrarily chosen
Expand Down Expand Up @@ -165,7 +160,6 @@ bool backend_sdcard_rp2040w::trim(const uint64_t block_nr, const uint32_t n_bloc
}
delete [] data;
ts_last_acces = get_micros();
n_trims++;
return rc;
}

Expand All @@ -184,7 +178,6 @@ bool backend_sdcard_rp2040w::read(const uint64_t block_nr, const uint32_t n_bloc
}

size_t n_bytes_to_read = n_blocks * iscsi_block_size;
bytes_read += n_bytes_to_read;

bool rc = false;
for(int i=0; i<5; i++) { // 5 is arbitrarily chosen
Expand Down Expand Up @@ -232,7 +225,6 @@ backend::cmpwrite_result_t backend_sdcard_rp2040w::cmpwrite(const uint64_t block
DOLOG(logging::ll_error, "backend_sdcard_rp2040w::cmpwrite", "-", "Cannot read: %d", file.error());
break;
}
bytes_read += block_size;

// compare
if (memcmp(buffer, &data_compare[i * block_size], block_size) != 0) {
Expand All @@ -255,8 +247,6 @@ backend::cmpwrite_result_t backend_sdcard_rp2040w::cmpwrite(const uint64_t block
break;
}

bytes_written += block_size;

ts_last_acces = get_micros();
}

Expand Down
3 changes: 1 addition & 2 deletions microcontrollers/RP2040W/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ backend_sdcard_rp2040w *bs { nullptr };
scsi *sd { nullptr };
server *s { nullptr };
iscsi_stats_t is;
io_stats_t ios;
volatile bool wifi_connected { false };
int led_green { 17 };
int led_yellow { 18 };
Expand Down Expand Up @@ -79,7 +78,7 @@ void setup()
bs->begin();

Serial.println(F("Create SCSI instance"));
sd = new scsi(bs, 1, &ios);
sd = new scsi(bs, 1);

Serial.println(F("Instantiate iSCSI server"));
s = new server(sd, c, &is, "test", false);
Expand Down
10 changes: 0 additions & 10 deletions microcontrollers/backend-sdcard-teensy41.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,8 @@ backend_sdcard_teensy41::~backend_sdcard_teensy41()
bool backend_sdcard_teensy41::sync()
{
write_led(led_write, HIGH);

n_syncs++;

if (file.sync() == false)
DOLOG(logging::ll_error, "backend_sdcard_teensy41::sync", "-", "Cannot sync data to SD-card");

write_led(led_write, LOW);

ts_last_acces = get_micros();
Expand Down Expand Up @@ -102,7 +98,6 @@ bool backend_sdcard_teensy41::write(const uint64_t block_nr, const uint32_t n_bl
}

size_t n_bytes_to_write = n_blocks * iscsi_block_size;
bytes_written += n_bytes_to_write;

bool rc = false;
for(int i=0; i<5; i++) { // 5 is arbitrarily chosen
Expand Down Expand Up @@ -139,7 +134,6 @@ bool backend_sdcard_teensy41::trim(const uint64_t block_nr, const uint32_t n_blo
}
delete [] data;
ts_last_acces = get_micros();
n_trims += n_blocks;
return rc;
}

Expand All @@ -158,7 +152,6 @@ bool backend_sdcard_teensy41::read(const uint64_t block_nr, const uint32_t n_blo
}

size_t n_bytes_to_read = n_blocks * iscsi_block_size;
bytes_read += n_bytes_to_read;

bool rc = false;
for(int i=0; i<5; i++) { // 5 is arbitrarily chosen
Expand Down Expand Up @@ -209,7 +202,6 @@ backend::cmpwrite_result_t backend_sdcard_teensy41::cmpwrite(const uint64_t bloc
DOLOG(logging::ll_error, "backend_sdcard_teensy41::cmpwrite", "-", "Cannot read: %d", file.getError());
break;
}
bytes_read += block_size;

// compare
if (memcmp(buffer, &data_compare[i * block_size], block_size) != 0) {
Expand All @@ -233,8 +225,6 @@ backend::cmpwrite_result_t backend_sdcard_teensy41::cmpwrite(const uint64_t bloc
break;
}

bytes_written += block_size;

ts_last_acces = get_micros();
}

Expand Down
Loading

0 comments on commit 6af42db

Please sign in to comment.