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

Draft: RFC: Enable granular locks for critical sections instead of a single kernel lock #601

Closed
wants to merge 2 commits into from

Conversation

sudeep-mohanty
Copy link
Contributor

Enable granular locks for critical sections instead of a single kernel lock

Description

This commit updates all critical section APIs, viz., task*_CRITICAL(), to accept a spinlock variable. These spinlocks are defined locally to each of the kernel data structures. This change moves away from the single kernel lock design therefore ensuring lesser contentions for critical section locks. This effectively increases the performance of the SMP kernel.

The idea here is to have granularity in the critical section spinlocks. An example of how this improves performance is as below:

Current Design:
TaskA running on core#0 is in a critical section by calling a blocking function such as uxTaskPriorityGet().
TaskB running on core#1 is performing a queue operation by calling xQueueGenericSend(). TaskB will have to contest for the kernel lock in order to complete the queue operation. This would mean that TaskB will be blocked until TaskA releases the lock.

Proposed Changes:
Under the new scheme with the above scenario, TaskB need not wait for TaskA to complete its operation as both the tasks will be contesting for separate locks which are local to the tasks module and the queue module respectively. This enables many kernel related operations to happen simultaneously across the cores, thereby helping in performance improvements in SMP systems.

Things to be considered

  1. Currently the the task*_CRITICAL() macros are routed to the vTaskEnterCritical() function which ensures atomicity but also has the scope of checking for state change of a task via the function prvCheckForRunStateChange(). Under the proposed design change, the task state change may need a rethink. It could be abstracted out to the port layer.

  2. Critical section nesting would need to be handled by the ports under the new design. This is currently handled by the kernel directly.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Mutex type semaphores should be aquired and released by the same task.
This commit adds an assertion check in xQueueGenericSend wherein the
assertion will fail if a mutex is not given by the owner of the mutex.

Signed-off-by: Sudeep Mohanty <[email protected]>
This commit updates all critical section APIs, viz., task*_CRITICAL(),
to accept a spinlock variable. These spinlocks are defined locally to
each of the kernel data structures. This change moves away from the
single kernel lock design therefore ensuring lesser contentions for
critical section locks. This effectievly increases the performance of
the SMP kernel.
@sudeep-mohanty sudeep-mohanty requested a review from a team as a code owner December 14, 2022 05:01
@sudeep-mohanty
Copy link
Contributor Author

sudeep-mohanty commented Dec 14, 2022

cc: @Dazza0 @zikalino

@Mancent Mancent linked an issue Mar 5, 2023 that may be closed by this pull request
This was linked to issues Mar 25, 2023
Closed
Closed
Closed
@n9wxu
Copy link
Member

n9wxu commented Apr 13, 2023

We must not change the interface to taskENTER_CRITICAL and taskEXIT_CRITICAL. These macros are part of the public interface so this change will break other code.

@sudeep-mohanty
Copy link
Contributor Author

Closing this PR in lie of another fork which introduces the concept of granular locks to SMP FreeRTOS - Dazza0@81d0afb

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

Successfully merging this pull request may close these issues.

H G M https://docs.github.com/articles/keeping-your-account-and-data-secure/
2 participants