Skip to content

Commit 09451b1

Browse files
committed
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 <[email protected]>
1 parent b6906ec commit 09451b1

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

subsys/bluetooth/controller/hci/hci.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8609,11 +8609,13 @@ static void encode_control(struct node_rx_pdu *node_rx,
86098609

86108610
#if defined(CONFIG_BT_CTLR_PROFILE_ISR)
86118611
case NODE_RX_TYPE_PROFILE:
8612-
LOG_INF("l: %u, %u, %u; t: %u, %u, %u; cpu: %u, %u, %u, %u.",
8612+
LOG_INF("l: %u, %u, %u; t: %u, %u, %u; cpu: %u (%u), %u (%u), %u (%u), %u (%u).",
86138613
pdu_data->profile.lcur, pdu_data->profile.lmin, pdu_data->profile.lmax,
86148614
pdu_data->profile.cur, pdu_data->profile.min, pdu_data->profile.max,
8615-
pdu_data->profile.radio, pdu_data->profile.lll, pdu_data->profile.ull_high,
8616-
pdu_data->profile.ull_low);
8615+
pdu_data->profile.radio, pdu_data->profile.radio_ticks,
8616+
pdu_data->profile.lll, pdu_data->profile.lll_ticks,
8617+
pdu_data->profile.ull_high, pdu_data->profile.ull_high_ticks,
8618+
pdu_data->profile.ull_low, pdu_data->profile.ull_low_ticks);
86178619
return;
86188620
#endif /* CONFIG_BT_CTLR_PROFILE_ISR */
86198621

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include "util/memq.h"
1717

18+
#include "ticker/ticker.h"
19+
1820
#include "pdu_df.h"
1921
#include "pdu_vendor.h"
2022
#include "pdu.h"
@@ -23,7 +25,9 @@
2325

2426
static int send(struct node_rx_pdu *rx);
2527
static inline void sample(uint32_t *timestamp);
28+
static inline void sample_ticks(uint32_t *timestamp_ticks);
2629
static inline void delta(uint32_t timestamp, uint16_t *cputime);
30+
static inline void delta_ticks(uint32_t timestamp_ticks, uint8_t *cputime_ticks);
2731

2832
static uint32_t timestamp_radio;
2933
static uint32_t timestamp_lll;
@@ -41,44 +45,61 @@ static uint16_t cputime_max;
4145
static uint16_t cputime_prev;
4246
static uint32_t timestamp_latency;
4347

48+
static uint32_t timestamp_ticks_radio;
49+
static uint32_t timestamp_ticks_lll;
50+
static uint32_t timestamp_ticks_ull_high;
51+
static uint32_t timestamp_ticks_ull_low;
52+
static uint8_t cputime_ticks_radio;
53+
static uint8_t cputime_ticks_lll;
54+
static uint8_t cputime_ticks_ull_high;
55+
static uint8_t cputime_ticks_ull_low;
56+
4457
void lll_prof_enter_radio(void)
4558
{
4659
sample(&timestamp_radio);
60+
sample_ticks(&timestamp_ticks_radio);
4761
}
4862

4963
void lll_prof_exit_radio(void)
5064
{
5165
delta(timestamp_radio, &cputime_radio);
66+
delta_ticks(timestamp_ticks_radio, &cputime_ticks_radio);
5267
}
5368

5469
void lll_prof_enter_lll(void)
5570
{
5671
sample(&timestamp_lll);
72+
sample_ticks(&timestamp_ticks_lll);
5773
}
5874

5975
void lll_prof_exit_lll(void)
6076
{
6177
delta(timestamp_lll, &cputime_lll);
78+
delta_ticks(timestamp_ticks_lll, &cputime_ticks_lll);
6279
}
6380

6481
void lll_prof_enter_ull_high(void)
6582
{
6683
sample(&timestamp_ull_high);
84+
sample_ticks(&timestamp_ticks_ull_high);
6785
}
6886

6987
void lll_prof_exit_ull_high(void)
7088
{
7189
delta(timestamp_ull_high, &cputime_ull_high);
90+
delta_ticks(timestamp_ticks_ull_high, &cputime_ticks_ull_high);
7291
}
7392

7493
void lll_prof_enter_ull_low(void)
7594
{
7695
sample(&timestamp_ull_low);
96+
sample_ticks(&timestamp_ticks_ull_low);
7797
}
7898

7999
void lll_prof_exit_ull_low(void)
80100
{
81101
delta(timestamp_ull_low, &cputime_ull_low);
102+
delta_ticks(timestamp_ticks_ull_low, &cputime_ticks_ull_low);
82103
}
83104

84105
void lll_prof_latency_capture(void)
@@ -236,6 +257,10 @@ static int send(struct node_rx_pdu *rx)
236257
p->lll = cputime_lll;
237258
p->ull_high = cputime_ull_high;
238259
p->ull_low = cputime_ull_low;
260+
p->radio_ticks = cputime_ticks_radio;
261+
p->lll_ticks = cputime_ticks_lll;
262+
p->ull_high_ticks = cputime_ticks_ull_high;
263+
p->ull_low_ticks = cputime_ticks_ull_low;
239264

240265
ull_rx_put_sched(rx->hdr.link, rx);
241266

@@ -248,6 +273,11 @@ static inline void sample(uint32_t *timestamp)
248273
*timestamp = radio_tmr_sample_get();
249274
}
250275

276+
static inline void sample_ticks(uint32_t *timestamp_ticks)
277+
{
278+
*timestamp_ticks = ticker_ticks_now_get();
279+
}
280+
251281
static inline void delta(uint32_t timestamp, uint16_t *cputime)
252282
{
253283
uint32_t delta;
@@ -258,3 +288,13 @@ static inline void delta(uint32_t timestamp, uint16_t *cputime)
258288
*cputime = delta;
259289
}
260290
}
291+
292+
static inline void delta_ticks(uint32_t timestamp_ticks, uint8_t *cputime_ticks)
293+
{
294+
uint32_t delta;
295+
296+
delta = ticker_ticks_now_get() - timestamp_ticks;
297+
if (delta < UINT8_MAX && delta > *cputime_ticks) {
298+
*cputime_ticks = delta;
299+
}
300+
}

subsys/bluetooth/controller/ll_sw/pdu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,10 @@ struct profile {
941941
uint16_t lll;
942942
uint16_t ull_high;
943943
uint16_t ull_low;
944+
uint8_t radio_ticks;
945+
uint8_t lll_ticks;
946+
uint8_t ull_high_ticks;
947+
uint8_t ull_low_ticks;
944948
} __packed;
945949
#endif /* CONFIG_BT_CTLR_PROFILE_ISR */
946950

0 commit comments

Comments
 (0)