Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: Controller: ISO Sync Receiver with ticks_slot_window #75760

Closed

Conversation

cvinayak
Copy link
Contributor

@cvinayak cvinayak commented Jul 11, 2024

Add implementation for ISO Sync Receiver to use ticks slot
window feature.

Added implementation to have ISO Sync Receiver resume its
subevents after being aborted by other overlapping events.

Introduce BT_CTLR_PERIPHERAL_RESERVE_MAX Kconfig option so
that disabling this option will use minimum time reservation
and exercise the peripheral connection event continuation
using is_abort_cb mechanism.

Add implementation for Extended Advertising Auxiliary PDUs
to use ticks slot window feature.

May fix #56201.

Copy link
Collaborator

@Thalley Thalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds a lot of new code that is very hard to read due to the additional Kconfig options (#if defined generally makes things harder to read).

Additionally the general lack of documentation for internal functions and their behavior and the long functions make it nearly impossible to actually understand what is going on.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always get sad when I see more Kconfig options for the LL :( It's already way too hard to configure, and we keep adding more and more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Kconfig's have been added incrementally, atleast trying to keep existing features not being disturbed too much. Most internal once should get hidden under the Advanced Features but some of them are being be used outside. But hopefully will make them defaults in the future when the options form matured options in default builds of samples. Least or seldom used Kconfigs can be delete there after.

Comment on lines +429 to +436
depends on BT_BROADCASTER && BT_CTLR_ADV_EXT
select BT_TICKER_EXT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reasoning behind selecting BT_TICKER_EXT rather than depending on it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will fix this to be depends on

Comment on lines +543 to +555
config BT_CTLR_SYNC_ISO_SLOT_WINDOW_JITTER
bool "Wrap ISO Synchronized Receiver event around overlapping roles"
depends on BT_CTLR_SYNC_ISO && !BT_CTLR_SYNC_ISO_RESERVE_MAX
select BT_TICKER_EXT
help
Wrap ISO Synchronized Receiver event around overlapping roles using
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may just be unaware, but what are roles in this context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roles / states are defined in BT Spec LINK LAYER STATES section, for example central peripheral are the two roles in connection state.

@@ -742,8 +759,22 @@ config BT_CTLR_CENTRAL_RESERVE_MAX
Note, currently this value is only used to space multiple central
connections and not for actual ticker time reservations.

config BT_CTLR_PERIPHERAL_RESERVE_MAX
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be placed next to BT_CTLR_PERIPHERAL_ISO_EARLY_CIG_START to group the BT_CTLR_PERIPHERAL* configs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that is peripheral ISO related. Where as this new one is related to normal peripheral ACL scheduling.

Comment on lines 69 to 80
struct {
uint8_t initiated:1;
uint8_t cancelled:1;
uint8_t forced:1;
};

struct {
uint8_t initiated:1;
uint8_t cancelled:1;
uint8_t forced:1;
} central;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between these 2 structs now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnamed struct is now used by a common code block and hence did not want to have a named reference as central or peripheral.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to put that in a comment, as that is non-obvious. Looks more like a merge conflict gone wrong :P

Comment on lines 733 to 805
payload_offset = (lll->latency_event * lll->bn) +
(lll->bn_curr - 1U);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are adding multiplying 2 uint8_ts and adding it to another uint8 and store the result in a uint8 without any checks for overflow.

This looks dangerous to me, and suggest to either store the result in a uint16 and check the result, or add an assert for the other values to ensure that we don't get an overflow here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressing here: #75638

@@ -699,10 +769,15 @@ static void isr_rx(void *param)
lll->bn_curr = 1U;
lll->irc_curr++;

payload_offset = (lll->latency_event * lll->bn);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto: Nothing to prevent an overflow here.

This is, IMO, a general issue in the controller as values are rarely checked.

Comment on lines 1239 to 1309
if (latency_event--) {
goto isr_rx_done_latency_event;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reasoning behind using goto here instead of a while (latency_event--)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was a quick hack... will fix this

Comment on lines +1395 to +1417
/* Pick the ticker expiry latency, to calculate ticks_at_expire
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* Pick the ticker expiry latency, to calculate ticks_at_expire
*/
/* Pick the ticker expiry latency, to calculate ticks_at_expire */

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you've still (mis?)configured your editor to use 80 instead of 100 line length with autoformatting.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, it doesn't look like these new Kconfig options are ever tested

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I will add modified bsim tests to cover the enhancements, the bap_broadcast_sink variant with XO clock drifts to have ACL connection in a sink drift over the BIG sync events, and measure SDU drops.

Copy link
Contributor Author

@cvinayak cvinayak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing, valuable inputs, and as always it takes me some time to refine the implementation, hope you retain your patience :-)

Comment on lines +429 to +436
depends on BT_BROADCASTER && BT_CTLR_ADV_EXT
select BT_TICKER_EXT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will fix this to be depends on

Comment on lines +543 to +555
config BT_CTLR_SYNC_ISO_SLOT_WINDOW_JITTER
bool "Wrap ISO Synchronized Receiver event around overlapping roles"
depends on BT_CTLR_SYNC_ISO && !BT_CTLR_SYNC_ISO_RESERVE_MAX
select BT_TICKER_EXT
help
Wrap ISO Synchronized Receiver event around overlapping roles using
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roles / states are defined in BT Spec LINK LAYER STATES section, for example central peripheral are the two roles in connection state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Kconfig's have been added incrementally, atleast trying to keep existing features not being disturbed too much. Most internal once should get hidden under the Advanced Features but some of them are being be used outside. But hopefully will make them defaults in the future when the options form matured options in default builds of samples. Least or seldom used Kconfigs can be delete there after.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I will add modified bsim tests to cover the enhancements, the bap_broadcast_sink variant with XO clock drifts to have ACL connection in a sink drift over the BIG sync events, and measure SDU drops.

@@ -742,8 +759,22 @@ config BT_CTLR_CENTRAL_RESERVE_MAX
Note, currently this value is only used to space multiple central
connections and not for actual ticker time reservations.

config BT_CTLR_PERIPHERAL_RESERVE_MAX
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that is peripheral ISO related. Where as this new one is related to normal peripheral ACL scheduling.

Comment on lines 69 to 80
struct {
uint8_t initiated:1;
uint8_t cancelled:1;
uint8_t forced:1;
};

struct {
uint8_t initiated:1;
uint8_t cancelled:1;
uint8_t forced:1;
} central;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnamed struct is now used by a common code block and hence did not want to have a named reference as central or peripheral.

Comment on lines +318 to +343
drift_us %= lll->sub_interval;
drift_us = lll->sub_interval - drift_us;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am trying to calculate a remaining sub_interval of a remainder (modulus) of sub_interval of drift_us... now you see I am not good at explaining :-(...

Comment on lines 452 to 525
static int is_abort_cb(void *next, void *curr, lll_prepare_cb_t *resume_cb)
{
#if defined(CONFIG_BT_CTLR_SYNC_ISO_SLOT_WINDOW_JITTER)
if (!next) {
*resume_cb = resume_prepare_cb;

return -EAGAIN;
}
#endif /* CONFIG_BT_CTLR_SYNC_ISO_SLOT_WINDOW_JITTER */

return -ECANCELED;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok... it is not documented...i agree... i should...
0 - pre-emptee succeeds to continue radio use, and pre-emptor is informed
-EAGAIN - pre-emptee looses and requests a resumption later, and pre-emptor will be scheduled
-ECANCELED - pre-emptee looses and be aborted, and pre-emptor will be scheduled

Comment on lines 1239 to 1309
if (latency_event--) {
goto isr_rx_done_latency_event;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was a quick hack... will fix this

@cvinayak cvinayak marked this pull request as draft July 17, 2024 10:35
@cvinayak cvinayak force-pushed the github_iso_recv_slot_window branch 3 times, most recently from 760de75 to 0ada552 Compare July 21, 2024 01:56
@jhedberg jhedberg assigned cvinayak and unassigned jhedberg and jori-nordic Jul 22, 2024
@cvinayak cvinayak force-pushed the github_iso_recv_slot_window branch from 0ada552 to f9ac084 Compare August 5, 2024 01:26
@cvinayak
Copy link
Contributor Author

cvinayak commented Aug 5, 2024

rebased to ensure CI is passing, keeping this PR draft and will be sending smaller PRs with considerations to already provided review comments here.

Simplify ticker reschedule_in_window implementation.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Remove ticks_elapsed use in reschedule_in_window as it has
already been used in the bottom half processing.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Introduce ticker reschedule with jitter so that role like
BIG can start after overlapping ACL and receive subsequent
subevents.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Add implementation for ISO Sync Receiver to use ticks slot
window feature.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Add implementation to support resumption of cancelled
prepare.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Added implementation to have ISO Sync Receiver resume its
subevents after being aborted by other overlapping events.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Introduce BT_CTLR_PERIPHERAL_RESERVE_MAX Kconfig option so
that disabling this option will use minimum time reservation
and exercise the peripheral connection event continuation
using is_abort_cb mechanism.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Fix BT_CTLR_SCAN_AUX_SYNC_RESERVE_MIN such that event is not
aborted when near supervision timeout conditions.

Relates to commit ddf0499 ("Bluetooth: Controller: Add
abort fairness in overlapping Periodic Sync").

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Fix incorrect elapsed events value when event prepare are
aborted in the pipeline. This caused premature supervision
timeouts.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
Add implementation for Extended Advertising Auxiliary PDUs
to use ticks slot window feature.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
@Thalley
Copy link
Collaborator

Thalley commented Sep 25, 2024

@cvinayak what was the reason for closing this?

@cvinayak
Copy link
Contributor Author

This PR contained a mix of some fundamental changes to nRF specific Low Level scheduling (for which I will need new bsim tests, only tested using manual bsim samples); and, commits that fix/improve inter-operability with Sony Xperia and Samsung S24 phones. The fix/improvement commits are now in #77921 (which is also draft, as I need to complete handling of is_abort_cb mechanism for CIG events).

Also, I would like #78894 to be merged ahead.

To summarize the order:

  1. Bluetooth: Controller: Implement PAST Support #78894
  2. Bluetooth: Controller: Fix CIS payload count under skipped events #78096
  3. Bluetooth: Controller: Fix elapsed events calculation, peripheral and periodic sync with better abort support #77921
  4. Bluetooth: Controller: ISO Broadcast/Receive interleaved packing support  #67231 or remaining commits of Bluetooth: Controller: ISO Sync Receiver with ticks_slot_window #75760 (both are enhancements)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bluetooth: controller: Possibility to have an active CIS and extended advertising at the same time
5 participants