From f73bc872e8b153af6e71d99d7b59d0586e13e44f Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Wed, 28 Jun 2023 04:57:15 +0530 Subject: [PATCH] Bluetooth: Controller: Add LL_ASSERT_OVERHEAD define Add LL_ASSERT_OVERHEAD define to reuse the assertion check related to increase in actual EVENT_OVERHEAD_START_US value. Introduce Kconfig option to permit radio event be skipped when increased prepare callback latencies are measured, instead of assertion. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/Kconfig.ll_sw_split | 7 +++++++ subsys/bluetooth/controller/hal/debug.h | 8 ++++++++ subsys/bluetooth/controller/ll_sw/lll_common.c | 14 +++++++++----- subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c | 5 +++++ .../controller/ll_sw/nordic/lll/lll_adv.c | 4 ++-- .../controller/ll_sw/nordic/lll/lll_adv_aux.c | 4 ++-- .../controller/ll_sw/nordic/lll/lll_adv_iso.c | 4 ++-- .../controller/ll_sw/nordic/lll/lll_adv_sync.c | 4 ++-- .../controller/ll_sw/nordic/lll/lll_central.c | 4 ++-- .../controller/ll_sw/nordic/lll/lll_central_iso.c | 4 ++-- .../controller/ll_sw/nordic/lll/lll_peripheral.c | 4 ++-- .../ll_sw/nordic/lll/lll_peripheral_iso.c | 4 ++-- .../controller/ll_sw/nordic/lll/lll_scan.c | 4 ++-- .../controller/ll_sw/nordic/lll/lll_scan_aux.c | 4 ++-- .../controller/ll_sw/nordic/lll/lll_sync.c | 4 ++-- .../controller/ll_sw/nordic/lll/lll_sync_iso.c | 4 ++-- 16 files changed, 53 insertions(+), 29 deletions(-) diff --git a/subsys/bluetooth/controller/Kconfig.ll_sw_split b/subsys/bluetooth/controller/Kconfig.ll_sw_split index 0342889e3e14bac..c652bf30ef2c6a1 100644 --- a/subsys/bluetooth/controller/Kconfig.ll_sw_split +++ b/subsys/bluetooth/controller/Kconfig.ll_sw_split @@ -466,6 +466,13 @@ config BT_CTLR_SCHED_ADVANCED Disabling this feature will lead to overlapping role in timespace leading to skipped events amongst active roles. +config BT_CTLR_ASSERT_OVERHEAD_START + bool "Assert on Prepare Latency" + default y + help + Assert on increased Radio Event Prepare callback latencies due to + CPU usage overheads in the Controller implementation. + config BT_CTLR_CENTRAL_SPACING int "Central Connection Spacing" depends on BT_CTLR_SCHED_ADVANCED diff --git a/subsys/bluetooth/controller/hal/debug.h b/subsys/bluetooth/controller/hal/debug.h index ba776c480c74073..1d099438b0b6325 100644 --- a/subsys/bluetooth/controller/hal/debug.h +++ b/subsys/bluetooth/controller/hal/debug.h @@ -27,4 +27,12 @@ void bt_ctlr_assert_handle(char *file, uint32_t line); BT_ASSERT_MSG(cond, fmt, ##__VA_ARGS__) #endif +#if defined(CONFIG_BT_CTLR_ASSERT_OVERHEAD_START) +#define LL_ASSERT_OVERHEAD(overhead) \ + LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", \ + __func__, HAL_TICKER_TICKS_TO_US(overhead)); +#else /* !CONFIG_BT_CTLR_ASSERT_OVERHEAD_START */ +#define LL_ASSERT_OVERHEAD(overhead) ARG_UNUSED(overhead) +#endif /* !CONFIG_BT_CTLR_ASSERT_OVERHEAD_START */ + #include "hal/debug_vendor_hal.h" diff --git a/subsys/bluetooth/controller/ll_sw/lll_common.c b/subsys/bluetooth/controller/ll_sw/lll_common.c index a91e933b402974b..4b7f9350c8d879d 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_common.c +++ b/subsys/bluetooth/controller/ll_sw/lll_common.c @@ -38,6 +38,8 @@ int lll_prepare(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, lll_prepare_cb_t prepare_cb, int8_t event_prio, struct lll_prepare_param *prepare_param) { + int err; + #if defined(CONFIG_BT_CTLR_JIT_SCHEDULING) int prio = event_prio; struct lll_hdr *hdr = prepare_param->param; @@ -60,20 +62,22 @@ int lll_prepare(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, prepare_param->prio = prio; #endif /* CONFIG_BT_CTLR_JIT_SCHEDULING */ - return lll_prepare_resolve(is_abort_cb, abort_cb, prepare_cb, - prepare_param, 0, 0); + err = lll_prepare_resolve(is_abort_cb, abort_cb, prepare_cb, + prepare_param, 0, 0); + + return err; } void lll_resume(void *param) { struct lll_event *next; - int ret; + int err; next = param; - ret = lll_prepare_resolve(next->is_abort_cb, next->abort_cb, + err = lll_prepare_resolve(next->is_abort_cb, next->abort_cb, next->prepare_cb, &next->prepare_param, next->is_resume, 1); - LL_ASSERT(!ret || ret == -EINPROGRESS); + LL_ASSERT(!err || err == -EINPROGRESS); } #if defined(CONFIG_BT_CTLR_JIT_SCHEDULING) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c index cfd13e87148bf8b..bc71bbcd5a656f8 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll.c @@ -755,6 +755,11 @@ int lll_prepare_resolve(lll_is_abort_cb_t is_abort_cb, lll_abort_cb_t abort_cb, err = prepare_cb(prepare_param); + if (!IS_ENABLED(CONFIG_BT_CTLR_ASSERT_OVERHEAD_START) && + (err == -ECANCELED)) { + err = 0; + } + #if !defined(CONFIG_BT_CTLR_LOW_LAT) uint32_t ret; diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c index c7e2f799c6bc415..eaf4c65c20c5b0f 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c @@ -1042,8 +1042,8 @@ static int prepare_cb(struct lll_prepare_param *p) ticks_at_event); /* check if preempt to start has changed */ if (overhead) { - LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", - __func__, HAL_TICKER_TICKS_TO_US(overhead)); + LL_ASSERT_OVERHEAD(overhead); + radio_isr_set(isr_abort, lll); radio_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c index 53de22a1a52cf45..dce2707c9b91b40 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_aux.c @@ -324,8 +324,8 @@ static int prepare_cb(struct lll_prepare_param *p) ticks_at_event); /* check if preempt to start has changed */ if (overhead) { - LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", - __func__, HAL_TICKER_TICKS_TO_US(overhead)); + LL_ASSERT_OVERHEAD(overhead); + radio_isr_set(lll_isr_abort, lll); radio_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c index 17634797041dc62..8d1ce888f0fc1de 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c @@ -426,8 +426,8 @@ static int prepare_cb_common(struct lll_prepare_param *p) ticks_at_event); /* check if preempt to start has changed */ if (overhead) { - LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", - __func__, HAL_TICKER_TICKS_TO_US(overhead)); + LL_ASSERT_OVERHEAD(overhead); + radio_isr_set(lll_isr_abort, lll); radio_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c index 288f5d9e7e7b287..f9216a573b60707 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_sync.c @@ -245,8 +245,8 @@ static int prepare_cb(struct lll_prepare_param *p) ticks_at_event); /* check if preempt to start has changed */ if (overhead) { - LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", - __func__, HAL_TICKER_TICKS_TO_US(overhead)); + LL_ASSERT_OVERHEAD(overhead); + radio_isr_set(lll_isr_abort, lll); radio_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central.c index 2fa0b808138e2c8..2985bd3d4e6471c 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central.c @@ -247,8 +247,8 @@ static int prepare_cb(struct lll_prepare_param *p) ticks_at_event); /* check if preempt to start has changed */ if (overhead) { - LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", - __func__, HAL_TICKER_TICKS_TO_US(overhead)); + LL_ASSERT_OVERHEAD(overhead); + radio_isr_set(lll_isr_abort, lll); radio_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c index ff5542b365d8b09..e4c8bf228bc95b0 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_central_iso.c @@ -382,8 +382,8 @@ static int prepare_cb(struct lll_prepare_param *p) overhead = lll_preempt_calc(ull, (TICKER_ID_CONN_ISO_BASE + cig_lll->handle), ticks_at_event); if (overhead) { - LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", - __func__, HAL_TICKER_TICKS_TO_US(overhead)); + LL_ASSERT_OVERHEAD(overhead); + radio_isr_set(lll_isr_abort, cig_lll); radio_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral.c index bc31194ca5bb50b..2148cec6aa762b1 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral.c @@ -329,8 +329,8 @@ static int prepare_cb(struct lll_prepare_param *p) ticks_at_event); /* check if preempt to start has changed */ if (overhead) { - LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", - __func__, HAL_TICKER_TICKS_TO_US(overhead)); + LL_ASSERT_OVERHEAD(overhead); + radio_isr_set(lll_isr_abort, lll); radio_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c index 12c294af0b9b5e3..fd568979b39b60b 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_peripheral_iso.c @@ -359,8 +359,8 @@ static int prepare_cb(struct lll_prepare_param *p) ticks_at_event); /* check if preempt to start has changed */ if (overhead) { - LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", - __func__, HAL_TICKER_TICKS_TO_US(overhead)); + LL_ASSERT_OVERHEAD(overhead); + radio_isr_set(lll_isr_abort, cig_lll); radio_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c index 6ec307a9165585c..242e7c07b92e387 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan.c @@ -482,8 +482,8 @@ static int common_prepare_cb(struct lll_prepare_param *p, bool is_resume) ull_scan_lll_handle_get(lll)), ticks_at_event); if (overhead) { - LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", - __func__, HAL_TICKER_TICKS_TO_US(overhead)); + LL_ASSERT_OVERHEAD(overhead); + radio_isr_set(isr_abort, lll); radio_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c index 5d2f12726ed0053..1df5b4dd65ded8c 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_scan_aux.c @@ -566,8 +566,8 @@ static int prepare_cb(struct lll_prepare_param *p) ull_scan_aux_lll_handle_get(lll_aux)), ticks_at_event); if (overhead) { - LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", - __func__, HAL_TICKER_TICKS_TO_US(overhead)); + LL_ASSERT_OVERHEAD(overhead); + radio_isr_set(isr_done, lll_aux); radio_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync.c index 4b9123b1698e98e..8f0275b8f320a26 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync.c @@ -515,8 +515,8 @@ static int prepare_cb_common(struct lll_prepare_param *p, uint8_t chan_idx) ticks_at_event); /* check if preempt to start has changed */ if (overhead) { - LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", - __func__, HAL_TICKER_TICKS_TO_US(overhead)); + LL_ASSERT_OVERHEAD(overhead); + radio_isr_set(isr_done, lll); radio_disable(); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c index 45a604e3d594111..1173dc38274b635 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c @@ -378,8 +378,8 @@ static int prepare_cb_common(struct lll_prepare_param *p) ticks_at_event); /* check if preempt to start has changed */ if (overhead) { - LL_ASSERT_MSG(false, "%s: Actual EVENT_OVERHEAD_START_US = %u", - __func__, HAL_TICKER_TICKS_TO_US(overhead)); + LL_ASSERT_OVERHEAD(overhead); + radio_isr_set(lll_isr_abort, lll); radio_disable();