summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Christophe Pince <jean.christophe.pince@qorvo.com>2023-03-02 00:40:17 +0100
committerNeil DI FOLCO <neil.difolco@qorvo.com>2023-03-31 19:42:05 +0200
commite7c87fec9c369916864ce492b21ee54106d30511 (patch)
treed64ab7c305b57acdb6ee2c0d3e462ce3c69480f6
parent3c0db8755483bd777294bdad15079c8ac3178d22 (diff)
downloaduwb-e7c87fec9c369916864ce492b21ee54106d30511.tar.gz
qm35: add flashing stats
Bug: 266449259 Change-Id: Id324f703657dc5ed0746c19edab0437112f91c38 Signed-off-by: Jean-Christophe Pince <jean.christophe.pince@qorvo.com>
-rw-r--r--libqmrom/src/qmrom_c0.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/libqmrom/src/qmrom_c0.c b/libqmrom/src/qmrom_c0.c
index 679f5cf..6d6d8a1 100644
--- a/libqmrom/src/qmrom_c0.c
+++ b/libqmrom/src/qmrom_c0.c
@@ -16,6 +16,10 @@
#define CHUNK_SIZE_C0 2040
#define SPI_READY_TIMEOUT_MS_C0 200
+#ifdef C0_WRITE_STATS
+#include <linux/ktime.h>
+#endif
+
#define SPI_SH_READY_CMD_BIT_MASK_C0 \
(SPI_SH_READY_CMD_BIT_MASK >> 4 | SPI_SH_READY_CMD_BIT_MASK)
@@ -262,11 +266,42 @@ int qmrom_c0_probe_device(struct qmrom_handle *handle)
return 0;
}
+#ifdef C0_WRITE_STATS
+static uint64_t total_bytes, total_time_ns;
+static uint32_t max_write_time_ns, min_write_time_ns = ~0;
+
+static void update_write_max_chunk_stats(ktime_t start_time)
+{
+ uint64_t elapsed_time_ns;
+
+ total_bytes += CHUNK_SIZE_C0;
+ elapsed_time_ns = ktime_to_ns(ktime_sub(ktime_get(), start_time));
+ total_time_ns += elapsed_time_ns;
+ if (elapsed_time_ns > max_write_time_ns)
+ max_write_time_ns = elapsed_time_ns;
+ if (elapsed_time_ns < min_write_time_ns)
+ min_write_time_ns = elapsed_time_ns;
+}
+
+static void dump_stats(void)
+{
+ uint32_t nb_chunks = total_bytes / CHUNK_SIZE_C0;
+ LOG_WARN(
+ "C0 flashing time stats: %llu bytes over %llu us (chunk size %u, write timings: mean %u us, min %u us, max %u us)\n",
+ total_bytes, total_time_ns / 1000, CHUNK_SIZE_C0,
+ (uint32_t)((total_time_ns / nb_chunks) / 1000),
+ min_write_time_ns / 1000, max_write_time_ns / 1000);
+}
+#endif
+
static int qmrom_c0_flash_data(struct qmrom_handle *handle, struct firmware *fw,
uint8_t cmd, uint8_t resp, bool skip_last_check)
{
int rc, sent = 0;
const char *bin_data = (const char *)fw->data;
+#ifdef C0_WRITE_STATS
+ ktime_t start_time;
+#endif
while (sent < fw->size) {
uint32_t tx_bytes = fw->size - sent;
@@ -275,6 +310,9 @@ static int qmrom_c0_flash_data(struct qmrom_handle *handle, struct firmware *fw,
LOG_DBG("%s: sending command %#x with %" PRIu32 " bytes\n",
__func__, cmd, tx_bytes);
+#ifdef C0_WRITE_STATS
+ start_time = ktime_get();
+#endif
rc = qmrom_write_size_cmd32_c0(handle, cmd, tx_bytes, bin_data);
if (rc)
return rc;
@@ -285,6 +323,10 @@ static int qmrom_c0_flash_data(struct qmrom_handle *handle, struct firmware *fw,
break;
}
qmrom_c0_poll_soc(handle);
+#ifdef C0_WRITE_STATS
+ if (tx_bytes == CHUNK_SIZE_C0)
+ update_write_max_chunk_stats(start_time);
+#endif
qmrom_pre_read_c0(handle);
qmrom_read_c0(handle);
if (handle->sstc->payload[0] != resp) {
@@ -382,6 +424,10 @@ static int qmrom_c0_flash_fw(struct qmrom_handle *handle,
ROM_CMD_C0_SEC_IMAGE_DATA,
WAITING_FOR_SEC_FILE_DATA, true);
+#ifdef C0_WRITE_STATS
+ dump_stats();
+#endif
+
end:
qmrom_free(all_fws.fw_img);
qmrom_free(all_fws.fw_crt);