From 59aa2d7ee29904bf1d67fecbac8fda72fb7c484e Mon Sep 17 00:00:00 2001 From: Folkert van Heusden Date: Thu, 7 Nov 2024 12:39:22 +0100 Subject: [PATCH] n_reads/writes for backend --- backend-file.cpp | 4 ++++ backend-nbd.cpp | 5 +++++ microcontrollers/RP2040W/backend-sdcard-rp2040w.cpp | 4 ++++ microcontrollers/backend-sdcard-teensy41.cpp | 4 ++++ microcontrollers/backend-sdcard.cpp | 4 ++++ 5 files changed, 21 insertions(+) diff --git a/backend-file.cpp b/backend-file.cpp index a91c5e4..a24e3ec 100644 --- a/backend-file.cpp +++ b/backend-file.cpp @@ -97,6 +97,7 @@ bool backend_file::write(const uint64_t block_nr, const uint32_t n_blocks, const ts_last_acces = end; bs.io_wait += end-start; bs.bytes_written += n_bytes; + bs.n_writes++; return rc == ssize_t(n_bytes); } @@ -157,6 +158,7 @@ bool backend_file::read(const uint64_t block_nr, const uint32_t n_blocks, uint8_ ts_last_acces = end; bs.io_wait += end-start; bs.bytes_read += n_bytes; + bs.n_reads++; return rc == ssize_t(n_bytes); } @@ -229,6 +231,8 @@ backend::cmpwrite_result_t backend_file::cmpwrite(const uint64_t block_nr, const auto end = get_micros(); bs.io_wait += end-start; + bs.n_reads++; + bs.n_writes++; delete [] buffer; diff --git a/backend-nbd.cpp b/backend-nbd.cpp index cc1dd11..ce44338 100644 --- a/backend-nbd.cpp +++ b/backend-nbd.cpp @@ -267,6 +267,7 @@ bool backend_nbd::write(const uint64_t block_nr, const uint32_t n_blocks, const ts_last_acces = get_micros(); bs.bytes_written += n_bytes; + bs.n_writes++; return rc; } @@ -304,6 +305,7 @@ bool backend_nbd::read(const uint64_t block_nr, const uint32_t n_blocks, uint8_t ts_last_acces = get_micros(); bs.bytes_read += n_bytes; + bs.n_reads++; return rc; } @@ -356,6 +358,9 @@ backend::cmpwrite_result_t backend_nbd::cmpwrite(const uint64_t block_nr, const unlock_range(lock_list); + bs.n_reads++; + bs.n_writes++; + return result; } diff --git a/microcontrollers/RP2040W/backend-sdcard-rp2040w.cpp b/microcontrollers/RP2040W/backend-sdcard-rp2040w.cpp index 969888b..86972b3 100644 --- a/microcontrollers/RP2040W/backend-sdcard-rp2040w.cpp +++ b/microcontrollers/RP2040W/backend-sdcard-rp2040w.cpp @@ -150,6 +150,7 @@ bool backend_sdcard_rp2040w::write(const uint64_t block_nr, const uint32_t n_blo write_led(led_write, LOW); bs.io_wait += end-start; + bs.n_writes++; ts_last_acces = end; return rc; @@ -208,6 +209,7 @@ bool backend_sdcard_rp2040w::read(const uint64_t block_nr, const uint32_t n_bloc DOLOG(logging::ll_error, "backend_sdcard_rp2040w::read", "-", "Cannot read: %d", file.error()); write_led(led_read, LOW); bs.io_wait += end-start; + bs.n_reads++; ts_last_acces = end; return rc; } @@ -267,6 +269,8 @@ backend::cmpwrite_result_t backend_sdcard_rp2040w::cmpwrite(const uint64_t block } uint64_t end = get_micros(); bs.io_wait += end-start; + bs.n_reads++; + bs.n_writes++; delete [] buffer; diff --git a/microcontrollers/backend-sdcard-teensy41.cpp b/microcontrollers/backend-sdcard-teensy41.cpp index 550c883..2961ccd 100644 --- a/microcontrollers/backend-sdcard-teensy41.cpp +++ b/microcontrollers/backend-sdcard-teensy41.cpp @@ -124,6 +124,7 @@ bool backend_sdcard_teensy41::write(const uint64_t block_nr, const uint32_t n_bl auto end = get_micros(); bs.io_wait += end-start; + bs.n_writes++; ts_last_acces = end; return rc; @@ -183,6 +184,7 @@ bool backend_sdcard_teensy41::read(const uint64_t block_nr, const uint32_t n_blo DOLOG(logging::ll_error, "backend_sdcard_teensy41::read", "-", "Cannot read: %d", file.getError()); write_led(led_read, LOW); bs.io_wait += end-start; + bs.n_reads++; ts_last_acces = end; return rc; } @@ -248,6 +250,8 @@ backend::cmpwrite_result_t backend_sdcard_teensy41::cmpwrite(const uint64_t bloc } auto end = get_micros(); bs.io_wait += end-start; + bs.n_reads++; + bs.n_writes++; delete [] buffer; diff --git a/microcontrollers/backend-sdcard.cpp b/microcontrollers/backend-sdcard.cpp index 1cd4ff2..722b50a 100644 --- a/microcontrollers/backend-sdcard.cpp +++ b/microcontrollers/backend-sdcard.cpp @@ -203,6 +203,7 @@ bool backend_sdcard::write(const uint64_t block_nr, const uint32_t n_blocks, con write_led(led_write, LOW); bs.io_wait += end-start; + bs.n_writes++; ts_last_acces = end; return rc; @@ -266,6 +267,7 @@ bool backend_sdcard::read(const uint64_t block_nr, const uint32_t n_blocks, uint #endif write_led(led_read, LOW); bs.io_wait += end-start; + bs.n_reads++; ts_last_acces = end; return rc; } @@ -331,6 +333,8 @@ backend::cmpwrite_result_t backend_sdcard::cmpwrite(const uint64_t block_nr, con auto end = get_micros(); bs.io_wait += end-start; + bs.n_reads++; + bs.n_writes++; delete [] buffer;