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: ascs: Handle ASE control point operations in separate thread #59775

Merged

Conversation

MariuszSkamra
Copy link
Collaborator

This adds handling of ASE control point operations in separate thread
so that the notifications of ASE state changes are sent from non-BTRX
thread. This ensures bt_gatt_notify_cb to be blocking waiting for
available buffers to send the notifications.

@MariuszSkamra MariuszSkamra marked this pull request as draft June 27, 2023 11:47
@Thalley
Copy link
Collaborator

Thalley commented Jun 27, 2023

@MariuszSkamra Before I dive too deep into the implementation of this, what is the advantage of using a new thread for this compared to the system workqueue thread?

@@ -2905,4 +2993,7 @@ void bt_ascs_cleanup(void)
unicast_server_cb = NULL;
}
}

K_THREAD_DEFINE(ascs, CONFIG_BT_ASCS_STACK_SIZE, ascs_thread, NULL, NULL, NULL,
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if we can get this working without the need for a separate thread (thinking memory constraints)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I decided to make use of the System Workqueue thread

@larsgk
Copy link
Contributor

larsgk commented Jul 4, 2023

This adds handling of ASE control point operations in separate thread so that the notifications of ASE state changes are sent from non-BTRX thread. This ensures bt_gatt_notify_cb to be blocking waiting for available buffers to send the notifications.

Being slightly cautious adding to the memory budget, I am wondering if this can be done without a separate thread. Also, do we have some real life tests/observations where this causes a clear issue (sans thread)?

@MariuszSkamra MariuszSkamra removed the DNM This PR should not be merged (Do Not Merge) label Jul 6, 2023
@MariuszSkamra MariuszSkamra requested a review from larsgk July 6, 2023 09:18
@MariuszSkamra MariuszSkamra marked this pull request as ready for review July 6, 2023 09:30
@zephyrbot zephyrbot requested a review from hermabe July 6, 2023 09:31
Thalley
Thalley previously approved these changes Jul 10, 2023
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.

Changes are sound, and none of my comments are blocking

subsys/bluetooth/audio/ascs.c Outdated Show resolved Hide resolved
subsys/bluetooth/audio/ascs.c Show resolved Hide resolved
subsys/bluetooth/audio/ascs.c Outdated Show resolved Hide resolved
Comment on lines 526 to 534
err = k_work_submit(&ase->state_transition_work);
if (err < 0) {
return err;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should log this?

If this indeed fails, then we can't really recover from it, can we?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll add a log, but I'm not sure about how to recover if this one fails.

k_work_submit API defines below errors that might be returned:

 * @retval -EBUSY
 * * if work submission was rejected because the work item is cancelling; or
 * * @p queue is draining; or
 * * @p queue is plugged.
 * @retval -EINVAL if @p queue is null and the work item has never been run.
 * @retval -ENODEV if @p queue has not been started.

I think that in case of System Workqueue, EINVAL and ENODEV if returned indicate some failure in the system. Not sure about EBUSY

Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed. We can't really do much besides logging this as an LOG_ERR; I don't think we can do anything to recover from it

larsgk
larsgk previously approved these changes Jul 11, 2023
@carlescufi
Copy link
Member

@MariuszSkamra please rebase

The `ops` variable is unused, thus can be removed.

Signed-off-by: Mariusz Skamra <[email protected]>
This adds handling of ASE control point operations in separate thread
so that the notifications of ASE state changes are sent from non-BT
thread. This ensures bt_gatt_notify_cb to be blocking waiting for
available buffers to send the notifications.

Signed-off-by: Mariusz Skamra <[email protected]>
@fabiobaltieri fabiobaltieri merged commit 9fa4543 into zephyrproject-rtos:main Jul 18, 2023
19 checks passed
@MariuszSkamra MariuszSkamra deleted the ascs_notifications branch July 18, 2023 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants