-
Notifications
You must be signed in to change notification settings - Fork 8k
subsys: portability: cmsis_rtos_v2: Fix dynamic thread stack reuse #85557
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
subsys: portability: cmsis_rtos_v2: Fix dynamic thread stack reuse #85557
Conversation
Hello @ArunmaniAlagarsamy2710, and thank you very much for your first pull request to the Zephyr project! |
c1eafa2
to
6b095b2
Compare
__ASSERT(!k_is_in_isr(), ""); | ||
tid = osThreadGetId(); | ||
|
||
#if CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_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.
thread_num_dynamic
and CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT
are always defined, so you can probably write:
if (CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT != 0) {
atomic_dec((atomic_t *)&thread_num_dynamic);
}
|
||
#if CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT | ||
atomic_dec((atomic_t *)&thread_num_dynamic); | ||
#endif |
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.
This code decrements thread_num_dynamic
even if the current thread is not a dynamic thread. I assume, this is not what we expect.
6b095b2
to
450734a
Compare
if (thread_num_dynamic) { | ||
atomic_dec((atomic_t *)&thread_num_dynamic); | ||
} | ||
} |
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.
Won't work if a static thread ends before a dynamic thread.
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.
BTW, the code that allocate the stack won't work:
this_thread_num_dynamic =
atomic_inc((atomic_t *)&thread_num_dynamic);
stack = cv2_thread_stack_pool[this_thread_num_dynamic];
cfa400d
to
7fd2ce7
Compare
Decrease the atomic variable thread_num_dynamic when a thread terminates and exits. Previously, once the maximum thread count was reached, no new threads could be created even after existing threads terminated. This fix ensures that thread stacks can be reused by osThreadNew, even after the specified number of threads (CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT) has been reached. Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com>
7fd2ce7
to
91f527c
Compare
Rebased to resolve the conflict |
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 don't have any knowledge of the Cmsis modules, so my comments are only very generic.
tid = osThreadGetId(); | ||
|
||
decrement_thread_counter(tid); | ||
k_thread_abort((k_tid_t)&tid->z_thread); |
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 feel you have to abort the thread before to release the stack, no?
stack_status[stack_idx].is_in_use = true; | ||
break; | ||
} | ||
} |
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 didn't dive in the detail of this algorithm, but it seems weird we use the value of num_dynamic_stack
to find a free resource.
[EDIT: Ok, I think it works, but the loop is unusual. Why not just: ARRAY_FOR_EACH(stack_status, i)
?]
} | ||
|
||
atomic_dec((atomic_t *)&thread_num); | ||
return 0; |
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.
These changes about thread_num
and num_dynamic_cb
. Don't seems directly related to dynamic threads. I believe it makes sense to place that in a separated commit. Then, it will be easier to explain why you need to change it.
(style note: when the loop are simple, call the loop indexes i
and j
. Every developers understand i
and j
are loop indexes).
|
||
struct stack_usage_info { | ||
bool is_in_use; | ||
} stack_status[CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_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.
This declaration is closely related to cmsis_rtos_thread_stack_pool
. So, I suggest:
- place it just after
cmsis_rtos_thread_stack_pool
in theif CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT != 0
block (even if this condition looks useless, I agree). - I wonder if declaring a struct with only one member is not just increasing complexity for free.
stack_usage_info
vsstack_status
vsis_in_use
. Having several names for the same purpose make code more complex.- change the name to outline the link with
cmsis_rtos_thread_stack_pool
. eg. cmsis_rtos_thread_stack_in_use.
Therefore, I would use bool cmsis_rtos_thread_stack_in_use[CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT]
.
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Zephyr CMSIS implementation has some limitations with dynamically allocated resources[1]. This patch allocates the CMSIS resources statically. Thus: - this allows to workaround the limitation of the current CMSIS implementation until we fix them properly - it is possible to get rid of the dependencies to CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT and CMSIS_V2_THREAD_MAX_COUNT. [1]: zephyrproject-rtos/zephyr#85557 Upstream-status: Inappropriate [Zephyr specific workaround for stack allocation] Signed-off-by: Arunmani Alagarsamy <arunmani.a@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Decrease the atomic variable thread_num_dynamic when a thread terminates and exits. Previously, once the maximum thread count was reached, no new threads could be created even after existing threads terminated.
This fix ensures that thread stacks can be reused by osThreadNew, even after the specified number of threads (CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT) has been reached.