Skip to content

Commit 929dae8

Browse files
cvinayaknashif
authored andcommitted
Bluetooth: controller: Add ISR cputime measurement
Adding ISR cputime measurement for Radio, LLL, ULL_HIGH and ULL_LOW execution contexts. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent c8d1c3b commit 929dae8

File tree

5 files changed

+123
-2
lines changed

5 files changed

+123
-2
lines changed

subsys/bluetooth/controller/hci/hci.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5731,13 +5731,17 @@ static void encode_control(struct node_rx_pdu *node_rx,
57315731

57325732
#if defined(CONFIG_BT_CTLR_PROFILE_ISR)
57335733
case NODE_RX_TYPE_PROFILE:
5734-
BT_INFO("l: %d, %d, %d; t: %d, %d, %d.",
5734+
BT_INFO("l: %u, %u, %u; t: %u, %u, %u; cpu: %u, %u, %u, %u.",
57355735
pdu_data->profile.lcur,
57365736
pdu_data->profile.lmin,
57375737
pdu_data->profile.lmax,
57385738
pdu_data->profile.cur,
57395739
pdu_data->profile.min,
5740-
pdu_data->profile.max);
5740+
pdu_data->profile.max,
5741+
pdu_data->profile.radio,
5742+
pdu_data->profile.lll,
5743+
pdu_data->profile.ull_high,
5744+
pdu_data->profile.ull_low);
57415745
return;
57425746
#endif /* CONFIG_BT_CTLR_PROFILE_ISR */
57435747

subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "lll_vendor.h"
3131
#include "lll_clock.h"
3232
#include "lll_internal.h"
33+
#include "lll_prof_internal.h"
3334

3435
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
3536
#define LOG_MODULE_NAME bt_ctlr_lll
@@ -78,10 +79,14 @@ ISR_DIRECT_DECLARE(radio_nrf5_isr)
7879
{
7980
DEBUG_RADIO_ISR(1);
8081

82+
lll_prof_enter_radio();
83+
8184
isr_radio();
8285

8386
ISR_DIRECT_PM();
8487

88+
lll_prof_exit_radio();
89+
8590
DEBUG_RADIO_ISR(0);
8691
return 1;
8792
}
@@ -90,6 +95,8 @@ static void rtc0_nrf5_isr(const void *arg)
9095
{
9196
DEBUG_TICKER_ISR(1);
9297

98+
lll_prof_enter_ull_high();
99+
93100
/* On compare0 run ticker worker instance0 */
94101
if (NRF_RTC0->EVENTS_COMPARE[0]) {
95102
NRF_RTC0->EVENTS_COMPARE[0] = 0;
@@ -99,9 +106,15 @@ static void rtc0_nrf5_isr(const void *arg)
99106

100107
mayfly_run(TICKER_USER_ID_ULL_HIGH);
101108

109+
lll_prof_exit_ull_high();
110+
102111
#if !defined(CONFIG_BT_CTLR_LOW_LAT) && \
103112
(CONFIG_BT_CTLR_ULL_HIGH_PRIO == CONFIG_BT_CTLR_ULL_LOW_PRIO)
113+
lll_prof_enter_ull_low();
114+
104115
mayfly_run(TICKER_USER_ID_ULL_LOW);
116+
117+
lll_prof_exit_ull_low();
105118
#endif
106119

107120
DEBUG_TICKER_ISR(0);
@@ -111,8 +124,12 @@ static void swi_lll_nrf5_isr(const void *arg)
111124
{
112125
DEBUG_RADIO_ISR(1);
113126

127+
lll_prof_enter_lll();
128+
114129
mayfly_run(TICKER_USER_ID_LLL);
115130

131+
lll_prof_exit_lll();
132+
116133
DEBUG_RADIO_ISR(0);
117134
}
118135

@@ -122,8 +139,12 @@ static void swi_ull_low_nrf5_isr(const void *arg)
122139
{
123140
DEBUG_TICKER_JOB(1);
124141

142+
lll_prof_enter_ull_low();
143+
125144
mayfly_run(TICKER_USER_ID_ULL_LOW);
126145

146+
lll_prof_exit_ull_low();
147+
127148
DEBUG_TICKER_JOB(0);
128149
}
129150
#endif

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_prof.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818

1919
#include "lll.h"
2020

21+
static inline void sample(uint32_t *timestamp);
22+
static inline void delta(uint32_t timestamp, uint8_t *cputime);
23+
24+
static uint32_t timestamp_radio;
25+
static uint32_t timestamp_lll;
26+
static uint32_t timestamp_ull_high;
27+
static uint32_t timestamp_ull_low;
28+
static uint8_t cputime_radio;
29+
static uint8_t cputime_lll;
30+
static uint8_t cputime_ull_high;
31+
static uint8_t cputime_ull_low;
2132
static uint8_t latency_min = (uint8_t) -1;
2233
static uint8_t latency_max;
2334
static uint8_t latency_prev;
@@ -26,6 +37,46 @@ static uint8_t cputime_max;
2637
static uint8_t cputime_prev;
2738
static uint32_t timestamp_latency;
2839

40+
void lll_prof_enter_radio(void)
41+
{
42+
sample(&timestamp_radio);
43+
}
44+
45+
void lll_prof_exit_radio(void)
46+
{
47+
delta(timestamp_radio, &cputime_radio);
48+
}
49+
50+
void lll_prof_enter_lll(void)
51+
{
52+
sample(&timestamp_lll);
53+
}
54+
55+
void lll_prof_exit_lll(void)
56+
{
57+
delta(timestamp_lll, &cputime_lll);
58+
}
59+
60+
void lll_prof_enter_ull_high(void)
61+
{
62+
sample(&timestamp_ull_high);
63+
}
64+
65+
void lll_prof_exit_ull_high(void)
66+
{
67+
delta(timestamp_ull_high, &cputime_ull_high);
68+
}
69+
70+
void lll_prof_enter_ull_low(void)
71+
{
72+
sample(&timestamp_ull_low);
73+
}
74+
75+
void lll_prof_exit_ull_low(void)
76+
{
77+
delta(timestamp_ull_low, &cputime_ull_low);
78+
}
79+
2980
void lll_prof_latency_capture(void)
3081
{
3182
/* sample the packet timer, use it to calculate ISR latency
@@ -134,9 +185,30 @@ void lll_prof_send(void)
134185
p->cur = cputime;
135186
p->min = cputime_min;
136187
p->max = cputime_max;
188+
p->radio = cputime_radio;
189+
p->lll = cputime_lll;
190+
p->ull_high = cputime_ull_high;
191+
p->ull_low = cputime_ull_low;
137192

138193
ull_rx_put(rx->hdr.link, rx);
139194
ull_rx_sched();
140195
}
141196
}
142197
}
198+
199+
static inline void sample(uint32_t *timestamp)
200+
{
201+
radio_tmr_sample();
202+
*timestamp = radio_tmr_sample_get();
203+
}
204+
205+
static inline void delta(uint32_t timestamp, uint8_t *cputime)
206+
{
207+
uint32_t delta;
208+
209+
radio_tmr_sample();
210+
delta = radio_tmr_sample_get() - timestamp;
211+
if (delta < UINT8_MAX && delta > *cputime) {
212+
*cputime = delta;
213+
}
214+
}

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_prof_internal.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#if defined(CONFIG_BT_CTLR_PROFILE_ISR)
8+
void lll_prof_enter_radio(void);
9+
void lll_prof_exit_radio(void);
10+
void lll_prof_enter_lll(void);
11+
void lll_prof_exit_lll(void);
12+
void lll_prof_enter_ull_high(void);
13+
void lll_prof_exit_ull_high(void);
14+
void lll_prof_enter_ull_low(void);
15+
void lll_prof_exit_ull_low(void);
16+
#else
17+
static inline void lll_prof_enter_radio(void) {}
18+
static inline void lll_prof_exit_radio(void) {}
19+
static inline void lll_prof_enter_lll(void) {}
20+
static inline void lll_prof_exit_lll(void) {}
21+
static inline void lll_prof_enter_ull_high(void) {}
22+
static inline void lll_prof_exit_ull_high(void) {}
23+
static inline void lll_prof_enter_ull_low(void) {}
24+
static inline void lll_prof_exit_ull_low(void) {}
25+
#endif
26+
727
void lll_prof_latency_capture(void);
828
void lll_prof_radio_end_backup(void);
929
void lll_prof_cputime_capture(void);

subsys/bluetooth/controller/ll_sw/pdu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,10 @@ struct profile {
610610
uint8_t cur;
611611
uint8_t min;
612612
uint8_t max;
613+
uint8_t radio;
614+
uint8_t lll;
615+
uint8_t ull_high;
616+
uint8_t ull_low;
613617
} __packed;
614618
#endif /* CONFIG_BT_CTLR_PROFILE_ISR */
615619

0 commit comments

Comments
 (0)