anjiahao1 opened a new pull request, #22258:
URL: https://github.com/apache/nuttx/pull/22258
## Summary
running_task() is not stable in the stack monitor hooks:
nxsched_remove_readytorun() can change the task it returns while the
instrumentation hook is running.
Use g_running_tasks[this_cpu()] instead, which is the task actually
running on the current CPU.
## Impact
* Is new feature added? NO
* Impact on user: NO
* Impact on build: NO
* Impact on hardware: NO
* Impact on documentation: NO
* Impact on security: NO
* Impact on compatibility: NO
## Testing
Build host: Linux x86_64 (Ubuntu 24.04), GCC 13.3.0, CMake 3.28.3
Target: sim, CMake build
The change was built with stack recording enabled
(sim:nsh with CONFIG_SCHED_STACK_RECORD=16 added):
```
cmake -S . -B build -DBOARD_CONFIG=sim:nsh -DNUTTX_APPS_DIR=...
cmake --build build -j10
```
The resulting image boots, and the scheduler instrumentation path is
active:
```
nsh> ps
TID PID PPID PRI POLICY TYPE NPX STATE EVENT SIGMASK
STACK COMMAND
0 0 0 0 FIFO Kthread - Ready ...
1 0 0 224 FIFO Kthread - Waiting Semaphore ...
7 7 4 100 FIFO Task - Running ...
nsh> poweroff
```
## PR verification
* [x] This PR introduces only one functional change.
* [x] I have updated all required description fields above.
* [x] My PR adheres to Contributing Guidelines and Documentation.
* [ ] My PR is still work in progress (not ready for review).
* [x] My PR is ready for review and can be safely merged into a codebase.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]