Dualcpu: Add NS mailbox statistics functionalities
Add statistics module in NS mailbox.
It records the number of mailbox message submission and the total
number of occupied NS mailbox queue slots each time NS task
acquires a mailbox queue slot.
NS tests can call tfm_ns_mailbox_stats_avg_slots() to calculate
the average number of occupied NS mailbox queue slots each time
NS task acquires a mailbox queue slot. It can prove the feature of
multiple outstanding NS PSA Client calls feature in dual-core
mailbox.
Change-Id: Icd9553996c516901f6b3fc7d68b4c4d0f0f0a5da
Signed-off-by: David Hu <david.hu@arm.com>
diff --git a/interface/src/tfm_ns_mailbox.c b/interface/src/tfm_ns_mailbox.c
index 2690bd4..0b96e65 100644
--- a/interface/src/tfm_ns_mailbox.c
+++ b/interface/src/tfm_ns_mailbox.c
@@ -121,6 +121,70 @@
}
}
+#ifdef TFM_MULTI_CORE_TEST
+void tfm_ns_mailbox_tx_stats_init(void)
+{
+ if (!mailbox_queue_ptr) {
+ return;
+ }
+
+ tfm_ns_mailbox_hal_enter_critical();
+
+ mailbox_queue_ptr->nr_tx = 0;
+ mailbox_queue_ptr->nr_used_slots = 0;
+
+ tfm_ns_mailbox_hal_exit_critical();
+}
+
+static void mailbox_tx_stats_update(struct ns_mailbox_queue_t *ns_queue)
+{
+ mailbox_queue_status_t empty_status;
+ uint8_t idx, nr_empty = 0;
+
+ if (!ns_queue) {
+ return;
+ }
+
+ tfm_ns_mailbox_hal_enter_critical();
+
+ ns_queue->nr_tx++;
+
+ /* Count the number of used slots when this tx arrives */
+ empty_status = ns_queue->empty_slots;
+ tfm_ns_mailbox_hal_exit_critical();
+
+ if (empty_status) {
+ for (idx = 0; idx < NUM_MAILBOX_QUEUE_SLOT; idx++) {
+ if (empty_status & (0x1UL << idx)) {
+ nr_empty++;
+ }
+ }
+ }
+
+ tfm_ns_mailbox_hal_enter_critical();
+ ns_queue->nr_used_slots += (NUM_MAILBOX_QUEUE_SLOT - nr_empty);
+ tfm_ns_mailbox_hal_exit_critical();
+}
+
+void tfm_ns_mailbox_stats_avg_slot(struct ns_mailbox_stats_res_t *stats_res)
+{
+ uint32_t nr_used_slots, nr_tx;
+
+ if (!mailbox_queue_ptr || !stats_res) {
+ return;
+ }
+
+ tfm_ns_mailbox_hal_enter_critical();
+ nr_used_slots = mailbox_queue_ptr->nr_used_slots;
+ nr_tx = mailbox_queue_ptr->nr_tx;
+ tfm_ns_mailbox_hal_exit_critical();
+
+ stats_res->avg_nr_slots = nr_used_slots / nr_tx;
+ nr_used_slots %= nr_tx;
+ stats_res->avg_nr_slots_tenths = nr_used_slots * 10 / nr_tx;
+}
+#endif
+
mailbox_msg_handle_t tfm_ns_mailbox_tx_client_req(uint32_t call_type,
const struct psa_client_params_t *params,
int32_t client_id)
@@ -143,6 +207,10 @@
return MAILBOX_QUEUE_FULL;
}
+#ifdef TFM_MULTI_CORE_TEST
+ mailbox_tx_stats_update(mailbox_queue_ptr);
+#endif
+
/* Fill the mailbox message */
msg_ptr = &mailbox_queue_ptr->queue[idx].msg;
@@ -311,6 +379,10 @@
/* Platform specific initialization. */
ret = tfm_ns_mailbox_hal_init(queue);
+#ifdef TFM_MULTI_CORE_TEST
+ tfm_ns_mailbox_tx_stats_init();
+#endif
+
return ret;
}