[!] sched/event: removed event_tickwait_wait() and added TSTATE_WAIT_EVENT#17244
Conversation
|
Just converting to draft while test logs are pending. |
611f0a4 to
5f775d0
Compare
57cbed7 to
b498f94
Compare
b498f94 to
7d941c5
Compare
7d941c5 to
55fdb23
Compare
406dd90 to
4b2ef05
Compare
|
@acassis I’ve uploaded the test logs for the ARM, RISC-V, and TriCore architectures in the PR description. Please check and let me know if any additional testing is needed. |
Hi @xiaoxiang781216 Do you think this PR can be merged after |
apps/nshlib could, but other need be part of this pr. |
|
Commit messages look good! |
I’ve uploaded a fix for tools/pynuttx/nxgdb and sched_get_stateinfo.c/g_statenames. Could you please help review it? Also, I didn’t find anything in procfs/ that needs to be updated. I believe the new state doesn’t affect procfs/, but could you please help double-check that? test code: ps output
|
eca0575 to
6fe3834
Compare
The latest code call nxsched_get_stateinfo to convert enum to string in all place, and your patch already update nxsched_get_stateinfo, so the problem is fixed.
you are right. |
6fe3834 to
6cf7c0e
Compare
|
I updated PR title with the proper marker Thanks |
…n event
The current event implementation uses semaphores for wait and post
operations. Since semaphores are relatively heavy-weight and intended
for resource-based synchronization, this is suboptimal.
So this patch replaced the semaphore-based mechanism with direct
scheduler operations to improve performance and reduce memory footprint.
This patch also introduce a new task state TSTATE_WAIT_EVENT to indicate
the task is waiting for a event.
BREAKING CHANGE: This commit introduced a new task state TSTATE_WAIT_EVENT
so apps/nshlib/, procfs/ and tools/pynuttx/nxgdb/ are needed to be updated accordingly.
Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
If the thread is blocked waiting on a event, then the
thread must be unblocked from the evnet to handle
the task cancellation.
Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
Implement nxevent_timeout with nxevent_wait_irq to remove code duplication Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
The current event implementation relies on a dedicated wait object,
which introduces several issues:
1. Increases memory usage
2. Complicates the event logic
3. Makes the API design less clean, as it requires a separate
nxevent_tickwait_wait() function
This patch removes the event’s dependency on the wait object
and eliminates the nxevent_tickwait_wait() API accordingly.
BREAKING CHANGE: this commit removed the nxevent_tickwait_wait function
so the related docs should be updated accordingly
Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
This patch add new taskstate entry in tools/pynuttx/nxgdb/thread.py
and in sched_get_stateinfo.c/g_statenames for the new added task
state: TSTATE_WAIT_EVENT
test log is:
nsh> ps
PID PPID GROUP PRI POLICY TYPE NPX STATE EVENT SIGMASK STACK USED FILLED COMMAND
0 0 0 0 FIFO Kthread - Ready 0000000000000000 0001008 0000196 19.4% Idle_Task
1 0 0 192 FIFO Kthread - Waiting Semaphore 0000000000000000 0001984 0000016 0.8% hpwork 0x70000100 0x7000014c
2 0 2 100 FIFO Task - Running 0000000000000000 0002008 0000740 36.8% nsh_main
4 0 0 100 FIFO Kthread - Waiting Event 0000000000000000 0000984 0000012 1.2% event_wait_task
Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
Remove the nxevent_tickwait_wait() description from events.rst,
since this API was removed during the event module refactoring.
Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
22dc06c to
58cb3e2
Compare
|
Please help to check if this PR can be merged @acassis @xiaoxiang781216 |
|
@wangchdo I think now the nuttx-apps need to be updated |
Hi @acassis nuttx-apps is not needed to be updated anymore according to my analysis, and @xiaoxiang781216 has helped to confirm it Please check the conversation i had with @xiaoxiang781216 above for the details of my analysis |



Summary
This PR contains breaking changes for event implementation to improve its performance, safety and make its api cleaner and easier to use
Change summary:
Refactors the event module by removing its dependency on semaphores and separate wait objects, and introduces a new task state TSTATE_WAIT_EVENT to simplify scheduling and improve maintainability.
Details:
1. Remove semaphore dependency
Reason:
- Semaphore objects consume more memory than necessary for event synchronization.
- Semaphore interfaces are relatively complex, involving global locks and logic that exceeds
the needs of the event mechanism.
Benefit:
- Simplifies the event module and reduces runtime and memory overhead.
2. Remove wait object dependency
Reason:
- Wait objects introduce additional memory usage.
- The current design either uses a local wait object in the waiting task (which is unsafe because the posting task also accesses it) or requires users to define global wait objects and call event_tickwait_wait(). This leads to complicated and error-prone usage.
- By removing wait objects, the event module can be implemented more cleanly.
Benefit:
- Simplifies API usage.
- Improves safety and code maintainability.
3. Introduce TSTATE_WAIT_EVENT and move the scheduling list to the event object
Reason:
- Makes the event module implementation more concise.
- Allows the scheduler to handle tasks blocked on events more flexibly in special cases (e.g., task deletion).
Benefit:
- Improves modularity and better integrates event handling with the scheduler.
Impact
This change streamlines the event mechanism by eliminating unnecessary abstractions, reducing memory footprint, and improving the clarity of both the implementation and external API, no impact to other nuttx functions
Testing
ostest including nxevent test cases passed on board arm/fvp-armv8r-aarch32
ostest.log
ostest include nxevent test cases passed on board tricore/a2g-tc397-5v-tft
tricore_a2g-tc397-5v-tft_ostest.log
ostest include nxevent test cases passed on board riscv/rv-virt board
riscv_rv-virt_ostest.log