-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: build assert if comand buffer is too small #19869
base: main
Are you sure you want to change the base?
Conversation
CI InformationTo view the history of this post, clich the 'edited' button above Inputs:Sources:sdk-nrf: PR head: eb14af132e9e5cf396988e27634cfd4c7e9700f7 more detailssdk-nrf:
Github labels
List of changed files detected by CI (12)
Outputs:ToolchainVersion: 342151af73 Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped;
|
You can find the documentation preview for this PR at this link. Note: This comment is automatically posted by the Documentation Publish GitHub Action. |
7e4cf76
to
7dd9904
Compare
e9664c2
to
5fabd4a
Compare
5fabd4a
to
b1c56cf
Compare
* The SDC controller (currently) does not support Num_HCI_Command_Packets > 1, which means Ncmd | ||
* is always 1. | ||
*/ | ||
BUILD_ASSERT(CONFIG_BT_BUF_ACL_RX_COUNT < CONFIG_BT_BUF_CMD_TX_COUNT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is CONFIG_BT_BUF_ACL_RX_COUNT
the maximum number of HCI ACL packets that can be generated? is this the value used to configure the SoftDevice Controller?
git grep BT_BUF_ACL_RX_COUNT
gives me no reference that convince me that it is used... hmmm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not give me a reference neither when grepping for it, but that is the critical config (or rather the command buffer size aligned with this), when customers are making samples. Checked that the customer sample we were looking at runs into the assert.
I couldn't really find which other configs to base such build assert on otherwise. Do you have some other check in mind? (Can also discuss offline, if you want. :) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cvinayak I've added the runtime modification as we discussed personally. Could you take a look whether the functions name and variable names are good (I tend to not be good at choosing them)? And if the wrapper function should be placed as I did? Also not sure if I can improve the comment above it.
0459e3f
to
c1ceef7
Compare
* approach is to align the communicated host RX Buffer Count to it here. | ||
*/ | ||
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL) | ||
static int sdc_hci_cmd_cb_host_buffer_size_wrapper(void *cmd_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static int sdc_hci_cmd_cb_host_buffer_size_wrapper(void *cmd_params) | |
static int sdc_hci_cmd_cb_host_buffer_size_wrapper(const sdc_hci_cmd_cb_host_buffer_size_t *cmd_params) |
sdc_hci_cmd_cb_host_buffer_size_t ctrl_cmd_params = | ||
*(const sdc_hci_cmd_cb_host_buffer_size_t *)cmd_params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sdc_hci_cmd_cb_host_buffer_size_t ctrl_cmd_params = | |
*(const sdc_hci_cmd_cb_host_buffer_size_t *)cmd_params; | |
sdc_hci_cmd_cb_host_buffer_size_t ctrl_cmd_params = *cmd_params; |
ctrl_cmd_params.host_total_num_acl_data_packets = MIN( | ||
ctrl_cmd_params.host_total_num_acl_data_packets, (CONFIG_BT_BUF_CMD_TX_COUNT - 1)); | ||
|
||
return sdc_hci_cmd_cb_host_buffer_size((const void *)&ctrl_cmd_params); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return sdc_hci_cmd_cb_host_buffer_size((const void *)&ctrl_cmd_params); | |
return sdc_hci_cmd_cb_host_buffer_size(&ctrl_cmd_params); |
* The SDC controller (currently) does not support Num_HCI_Command_Packets > 1, which means Ncmd | ||
* is always 1. | ||
*/ | ||
BUILD_ASSERT(BT_BUF_ACL_RX_COUNT < CONFIG_BT_BUF_CMD_TX_COUNT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move it inside sdc_hci_cmd_cb_host_buffer_size_wrapper, so it all in one place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that, when building Controller-only builds BT_BUF_ACL_RX_COUNT
is always 0! Hence, need to use a count that is allocated in the Controller?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not important how many buffers are allocated inside controller, it still can send out more RX packets than that, if host delays HCI_Host_Number_Of_Completed_Packets. What is important is how many the transport can accept from the controller? Or if transport does not buffer, but just pass-through then checking against 0 here should be fine since it always pass?
* The SDC controller (currently) does not support Num_HCI_Command_Packets > 1, which means Ncmd | ||
* is always 1. | ||
*/ | ||
BUILD_ASSERT(BT_BUF_ACL_RX_COUNT < CONFIG_BT_BUF_CMD_TX_COUNT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that, when building Controller-only builds BT_BUF_ACL_RX_COUNT
is always 0! Hence, need to use a count that is allocated in the Controller?
c1ceef7
to
eba935e
Compare
// not BT_BUF_ACL_RX_COUNT, but what is set in controller. | ||
BUILD_ASSERT(CONFIG_BT_BUF_CMD_TX_COUNT > 2, | ||
"We need at least two HCI command buffers to avoid deadlocks."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// not BT_BUF_ACL_RX_COUNT, but what is set in controller. | |
BUILD_ASSERT(CONFIG_BT_BUF_CMD_TX_COUNT > 2, | |
"We need at least two HCI command buffers to avoid deadlocks."); | |
BUILD_ASSERT(CONFIG_BT_BUF_CMD_TX_COUNT - 1 > 0, | |
"We need at least two HCI command buffers to avoid deadlocks."); |
it's not about controller, right? It's that adjustment that should not become 0 https://github.com/nrfconnect/sdk-nrf/pull/19869/files#diff-813ccd03aac379c4e1f534c16d65b666f48162012fd09e35a1f1ddcf69d88511R22
Also I would still like to place both static assert and dynamic adjustment at the same place in the code. It's harder to find pieces and understated them when they scattered.
Host Number of Completed Packets command does not follow normal flow control of HCI commands and the Controller side HCI drivers that allocates HCI command buffers with K_NO_WAIT can end up running out of command buffers. Host will generate up to acl_pkts number of Host Number of Completed Packets command plus a number of normal HCI commands. Normal HCI commands follow the HCI command flow control using Num_HCI_Command_Packets return in HCI command complete and status. When Controller to Host data flow control is supported, this commit ensures that BT_BUF_CMD_TX_COUNT is greater than or equal to (BT_BUF_ACL_RX_COUNT + Ncmd), where Ncmd is the supported maximum Num_HCI_Command_Packets, for a controller + host, or host-only build. Furthermore this commit restricts the `host_total_num_acl_data_packets` communicated to the controller to how many acknoledgements the controller is able to receive from the host, in a controller-only build. Note: The SDC controller (currently) does not support Num_HCI_Command_Packets > 1, which means Ncmd is always 1. Signed-off-by: Kyra Lengfeld <[email protected]>
This commit extracts the wrapper function in its own file, to avoid bloating the hci_internal file, as well as tests its funcionality in a unit test. Signed-off-by: Kyra Lengfeld <[email protected]>
eba935e
to
eb14af1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at test tags and scripts/ci/tags.yaml, it look good.
Host Number of Completed Packets command does not follow normal flow control of HCI commands and the Controller side HCI drivers that allocates HCI command buffers with K_NO_WAIT can end up running out of command buffers.
Host will generate up to acl_pkts number of Host Number of Completed Packets command plus a number of normal HCI commands.
Normal HCI commands follow the HCI command flow control using Num_HCI_Command_Packets return in HCI command complete and status.
When Controller to Host data flow control is supported, this commit ensures that BT_BUF_CMD_TX_COUNT is greater than or equal to (BT_BUF_ACL_RX_COUNT + Ncmd), where Ncmd is the supported maximum Num_HCI_Command_Packets.
Note: The SDC controller (currently) does not support Num_HCI_Command_Packets > 1, which means Ncmd is always 1.