From 409402f0cc4cd3261fd4530bb4e6dd5293e4dfb2 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Fri, 28 Jun 2024 02:51:49 +0200 Subject: [PATCH] Bluetooth: Controller: Add ISR profiling using ticker ticks Add ISR profiling using ticker ticks, hence profile ISR CPU use outside radio events. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/hci/hci.c | 8 ++-- .../controller/ll_sw/nordic/lll/lll_prof.c | 40 +++++++++++++++++++ subsys/bluetooth/controller/ll_sw/pdu.h | 4 ++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 69c8d446c4c..9217a0804d1 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -8603,11 +8603,13 @@ static void encode_control(struct node_rx_pdu *node_rx, #if defined(CONFIG_BT_CTLR_PROFILE_ISR) case NODE_RX_TYPE_PROFILE: - LOG_INF("l: %u, %u, %u; t: %u, %u, %u; cpu: %u, %u, %u, %u.", + LOG_INF("l: %u, %u, %u; t: %u, %u, %u; cpu: %u (%u), %u (%u), %u (%u), %u (%u).", pdu_data->profile.lcur, pdu_data->profile.lmin, pdu_data->profile.lmax, pdu_data->profile.cur, pdu_data->profile.min, pdu_data->profile.max, - pdu_data->profile.radio, pdu_data->profile.lll, pdu_data->profile.ull_high, - pdu_data->profile.ull_low); + pdu_data->profile.radio, pdu_data->profile.radio_ticks, + pdu_data->profile.lll, pdu_data->profile.lll_ticks, + pdu_data->profile.ull_high, pdu_data->profile.ull_high_ticks, + pdu_data->profile.ull_low, pdu_data->profile.ull_low_ticks); return; #endif /* CONFIG_BT_CTLR_PROFILE_ISR */ diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_prof.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_prof.c index 18301f990a1..c75e82bf7e2 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_prof.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_prof.c @@ -15,6 +15,8 @@ #include "util/memq.h" +#include "ticker/ticker.h" + #include "pdu_df.h" #include "pdu_vendor.h" #include "pdu.h" @@ -23,7 +25,9 @@ static int send(struct node_rx_pdu *rx); static inline void sample(uint32_t *timestamp); +static inline void sample_ticks(uint32_t *timestamp_ticks); static inline void delta(uint32_t timestamp, uint16_t *cputime); +static inline void delta_ticks(uint32_t timestamp_ticks, uint8_t *cputime_ticks); static uint32_t timestamp_radio; static uint32_t timestamp_lll; @@ -41,44 +45,61 @@ static uint16_t cputime_max; static uint16_t cputime_prev; static uint32_t timestamp_latency; +static uint32_t timestamp_ticks_radio; +static uint32_t timestamp_ticks_lll; +static uint32_t timestamp_ticks_ull_high; +static uint32_t timestamp_ticks_ull_low; +static uint8_t cputime_ticks_radio; +static uint8_t cputime_ticks_lll; +static uint8_t cputime_ticks_ull_high; +static uint8_t cputime_ticks_ull_low; + void lll_prof_enter_radio(void) { sample(×tamp_radio); + sample_ticks(×tamp_ticks_radio); } void lll_prof_exit_radio(void) { delta(timestamp_radio, &cputime_radio); + delta_ticks(timestamp_ticks_radio, &cputime_ticks_radio); } void lll_prof_enter_lll(void) { sample(×tamp_lll); + sample_ticks(×tamp_ticks_lll); } void lll_prof_exit_lll(void) { delta(timestamp_lll, &cputime_lll); + delta_ticks(timestamp_ticks_lll, &cputime_ticks_lll); } void lll_prof_enter_ull_high(void) { sample(×tamp_ull_high); + sample_ticks(×tamp_ticks_ull_high); } void lll_prof_exit_ull_high(void) { delta(timestamp_ull_high, &cputime_ull_high); + delta_ticks(timestamp_ticks_ull_high, &cputime_ticks_ull_high); } void lll_prof_enter_ull_low(void) { sample(×tamp_ull_low); + sample_ticks(×tamp_ticks_ull_low); } void lll_prof_exit_ull_low(void) { delta(timestamp_ull_low, &cputime_ull_low); + delta_ticks(timestamp_ticks_ull_low, &cputime_ticks_ull_low); } void lll_prof_latency_capture(void) @@ -236,6 +257,10 @@ static int send(struct node_rx_pdu *rx) p->lll = cputime_lll; p->ull_high = cputime_ull_high; p->ull_low = cputime_ull_low; + p->radio_ticks = cputime_ticks_radio; + p->lll_ticks = cputime_ticks_lll; + p->ull_high_ticks = cputime_ticks_ull_high; + p->ull_low_ticks = cputime_ticks_ull_low; ull_rx_put_sched(rx->hdr.link, rx); @@ -248,6 +273,11 @@ static inline void sample(uint32_t *timestamp) *timestamp = radio_tmr_sample_get(); } +static inline void sample_ticks(uint32_t *timestamp_ticks) +{ + *timestamp_ticks = ticker_ticks_now_get(); +} + static inline void delta(uint32_t timestamp, uint16_t *cputime) { uint32_t delta; @@ -258,3 +288,13 @@ static inline void delta(uint32_t timestamp, uint16_t *cputime) *cputime = delta; } } + +static inline void delta_ticks(uint32_t timestamp_ticks, uint8_t *cputime_ticks) +{ + uint32_t delta; + + delta = ticker_ticks_now_get() - timestamp_ticks; + if (delta < UINT8_MAX && delta > *cputime_ticks) { + *cputime_ticks = delta; + } +} diff --git a/subsys/bluetooth/controller/ll_sw/pdu.h b/subsys/bluetooth/controller/ll_sw/pdu.h index 857b4ca3ee4..4450f3a1682 100644 --- a/subsys/bluetooth/controller/ll_sw/pdu.h +++ b/subsys/bluetooth/controller/ll_sw/pdu.h @@ -941,6 +941,10 @@ struct profile { uint16_t lll; uint16_t ull_high; uint16_t ull_low; + uint8_t radio_ticks; + uint8_t lll_ticks; + uint8_t ull_high_ticks; + uint8_t ull_low_ticks; } __packed; #endif /* CONFIG_BT_CTLR_PROFILE_ISR */