Skip to content

sched/event: Fix uninitialized need_switch flag issue in event_post()#17272

Merged
anchao merged 2 commits into
apache:masterfrom
wangchdo:fix_event_post_issue
Nov 4, 2025
Merged

sched/event: Fix uninitialized need_switch flag issue in event_post()#17272
anchao merged 2 commits into
apache:masterfrom
wangchdo:fix_event_post_issue

Conversation

@wangchdo
Copy link
Copy Markdown
Contributor

@wangchdo wangchdo commented Nov 3, 2025

Summary

The `need_switch` flag was not initialized in `event_post()`. Since it is
a local variable, it could contain a random non-zero value, leading to
incorrect behavior.

In addition, this patch also fixes an issue where the event clearing
operation in `event_post()` may not  be performed correctly.

The root cause of this issue is that during the restructuring of the commit log for #17244 based on @jerpelea’s feedback, I inadvertently used an outdated implementation of event_post from my local history and failed to re-run the tests afterward.
I’ll take this as a valuable lesson — from now on, whenever I amend a commit, I’ll make sure to re-run the tests to ensure no new issues are introduced.

Impact

Fix an issue in the event_post implementation. This change has no impact on other NuttX functions.

Testing

ostest including event tests passed on board a2g-tc397-5v-tft:

NuttShell (NSH)
nsh> 
nsh> uname -a
NuttX 0.0.0 d89827a7ff Nov  4 2025 10:01:25 tricore a2g-tc397-5v-tft
nsh> 
nsh> ostest

(...)

user_main: nxevent test

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       28dfc    28dfc
ordblks         6        6
mxordblk    1f8c8    1f8c8
uordblks     553c     553c
fordblks    238c0    238c0

Final memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       28dfc    28dfc
ordblks         1        6
mxordblk    24238    1f8c8
uordblks     4bc4     553c
fordblks    24238    238c0
user_main: Exiting
ostest_main: Exiting with status 0
nsh> 

ostest including event tests passed on board fvp-armv8r-aarch32:

NuttShell (NSH)
nsh> [ 0] Idle_Task: nx_start: CPU0: Beginning Idle Loop
nsh> uname -a
NuttX 0.0.0 d89827a7ff-dirty Nov  4 2025 10:08:03 arm fvp-armv8r-aarch32
nsh> 
nsh> 
nsh> ostest

(...)

user_main: nxevent test
[ 4] ostest: nxtask_activate: ostest pid=86,TCB=0x20011958
[86] ostest: nx_pthread_exit: exit_value=0
[86] ostest: pthread_completejoin: pid=86 exit_value=0
[86] ostest: nxtask_exit: ostest pid=86,TCB=0x20011958
[ 4] ostest: pthread_destroyjoin: pjoin=0x20011a40
[ 4] ostest: pthread_join: Returning 0
[ 4] ostest: nxtask_activate: ostest pid=87,TCB=0x20011958
[ 4] ostest: nxtask_activate: ostest pid=88,TCB=0x20011a98
[87] ostest: nx_pthread_exit: exit_value=0
[87] ostest: pthread_completejoin: pid=87 exit_value=0
[87] ostest: nxtask_exit: ostest pid=87,TCB=0x20011958
[88] ostest: nx_pthread_exit: exit_value=0
[88] ostest: pthread_completejoin: pid=88 exit_value=0
[88] ostest: nxtask_exit: ostest pid=88,TCB=0x20011a98
[ 4] ostest: pthread_destroyjoin: pjoin=0x20011a40
[ 4] ostest: pthread_join: Returning 0
[ 4] ostest: pthread_destroyjoin: pjoin=0x20011a50
[ 4] ostest: pthread_join: Returning 0

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena     7ff9d1c  7ff9d1c
ordblks         5        5
mxordblk  7febee8  7febee8
uordblks     b634     b634
fordblks  7fee6e8  7fee6e8

Final memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena     7ff9d1c  7ff9d1c
ordblks         1        5
mxordblk  7ff0868  7febee8
uordblks     94b4     b634
fordblks  7ff0868  7fee6e8
user_main: Exiting
[ 4] ostest: nxtask_exit: ostest pid=4,TCB=0x2000d368
ostest_main: Exiting with status 0
stdio_test: Standard I/O Check: fprintf to stderr
[ 3] ostest: nxtask_exit: ostest pid=3,TCB=0x2000af40
nsh> 

@github-actions github-actions Bot added Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Nov 3, 2025
anchao
anchao previously approved these changes Nov 3, 2025
jerpelea
jerpelea previously approved these changes Nov 3, 2025
Comment thread sched/event/event_post.c Outdated
    The `need_switch` flag was not initialized in `event_post()`. Since it is
    a local variable, it could contain a random non-zero value, leading to
    incorrect behavior.
    In addition, this patch also fixes an issue where the event clearing
    operation in `event_post()` was not performed correctly.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
acassis
acassis previously approved these changes Nov 3, 2025
xiaoxiang781216
xiaoxiang781216 previously approved these changes Nov 3, 2025
@cederom
Copy link
Copy Markdown
Contributor

cederom commented Nov 3, 2025

Thanks @wangchdo :-) No worries, things like this happen, good that you found them quickly and proposed a fix :-) This is very important to give more focus to breaking changes, mark breaking changes, and ask for better testing from the community :-)

Please provide logs in text format not pictures :-)

CI failed, restarted :-)

@wangchdo
Copy link
Copy Markdown
Contributor Author

wangchdo commented Nov 4, 2025

Thanks @wangchdo :-) No worries, things like this happen, good that you found them quickly and proposed a fix :-) This is very important to give more focus to breaking changes, mark breaking changes, and ask for better testing from the community :-)

Please provide logs in text format not pictures :-)

CI failed, restarted :-)

Hi @cederom

I’ve uploaded the text logs.

Besides, I suspect the CI failure might be related to that I updated the pcduino-a10 board’s defconfig to include CONFIG_SCHED_EVENTS=y.

image

I enabled this CONFIG_SCHED_EVENTS option because I wanted the CI to run tests for the sched/event module in a real board, and the pcduino-a10 board is included in the CI test set.

Do you know how I can fix this CI failure issue? I think maybe the CI does not allow changing defconfig directly...

cc @acassis @xiaoxiang781216

@wangchdo wangchdo requested a review from acassis November 4, 2025 01:06
@cederom
Copy link
Copy Markdown
Contributor

cederom commented Nov 4, 2025

I mean use > or ```` marks to paste logs directly into the PR so they are clearly visible, do not upload pictures or files, thanks :-)

Like this:

- Ready to Boot Primary CPU
- Boot from EL2
- Boot from EL1
- Boot to C runtime for OS Initialize
[    0.002000] bcm2711_mbox_sendreq: Unknown response code: 00000000
[    0.215000] bcm2711_waitresponse: Got error: -110
[    0.219000] mmcsd_sendcmdpoll: ERROR: Wait for response to cmd: 00008101 failed: -110
[    0.227000] bcm2711_recvshort: Error: -110

NuttShell (NSH) NuttX-10.4.0
nsh> uname -a
NuttX 10.4.0 89e841fed4 Nov  4 2025 01:30:07 arm64 raspberrypi-4b
nsh> ?
help usage:  help [-v] [<cmd>]

    .           cp          expr        mkdir       rm          uname
    [           cmp         false       mkfatfs     rmdir       umount
    ?           dirname     fdinfo      mkrd        set         unset
    alias       df          free        mount       sleep       uptime
    unalias     dmesg       help        mv          source      usleep
    basename    echo        hexdump     pidof       test        watch
    break       env         kill        printf      time        xd
    cat         exec        pkill       ps          true        wait
    cd          exit        ls          pwd         truncate

Builtin Apps:
    dd          getprime    nsh         ostest      sdstress    sh
nsh> cat /sd/test.txt
nsh: cat: open failed: 2
nsh> echo "NUTTX ON SANDISK ENDURANCE TEST" >> /sd/test.txt
nsh> cat /sd/test.txt
NUTTX ON SANDISK ENDURANCE TEST

See: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax

   Enable the event module on pcduino-a10 and smartl-c906 boards
   to allow event tests to be executed on both ARM and RISC-V
   architectures.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
@wangchdo
Copy link
Copy Markdown
Contributor Author

wangchdo commented Nov 4, 2025

I mean use > or ```` marks to paste logs directly into the PR so they are clearly visible, do not upload pictures or files, thanks :-)

Like this:

- Ready to Boot Primary CPU
- Boot from EL2
- Boot from EL1
- Boot to C runtime for OS Initialize
[    0.002000] bcm2711_mbox_sendreq: Unknown response code: 00000000
[    0.215000] bcm2711_waitresponse: Got error: -110
[    0.219000] mmcsd_sendcmdpoll: ERROR: Wait for response to cmd: 00008101 failed: -110
[    0.227000] bcm2711_recvshort: Error: -110

NuttShell (NSH) NuttX-10.4.0
nsh> uname -a
NuttX 10.4.0 89e841fed4 Nov  4 2025 01:30:07 arm64 raspberrypi-4b
nsh> ?
help usage:  help [-v] [<cmd>]

    .           cp          expr        mkdir       rm          uname
    [           cmp         false       mkfatfs     rmdir       umount
    ?           dirname     fdinfo      mkrd        set         unset
    alias       df          free        mount       sleep       uptime
    unalias     dmesg       help        mv          source      usleep
    basename    echo        hexdump     pidof       test        watch
    break       env         kill        printf      time        xd
    cat         exec        pkill       ps          true        wait
    cd          exit        ls          pwd         truncate

Builtin Apps:
    dd          getprime    nsh         ostest      sdstress    sh
nsh> cat /sd/test.txt
nsh: cat: open failed: 2
nsh> echo "NUTTX ON SANDISK ENDURANCE TEST" >> /sd/test.txt
nsh> cat /sd/test.txt
NUTTX ON SANDISK ENDURANCE TEST

See: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax

Hi @cederom
Thank you for the clarification! I’ve uploaded the text log directly instead of the full log files. Since the complete ostest log is quite large, I only included the sections related to my update. Is that OK?

@cederom
Copy link
Copy Markdown
Contributor

cederom commented Nov 4, 2025

Yes thank you @wangchdo this is it :-) You can mark something like that:

NuttShell (NSH) NuttX-10.4.0
nsh> uname -a
NuttX 10.4.0 89e841fed4 Nov  4 2025 01:33:33 arm64 raspberrypi-4b <--- I ALWAYS SHOW MY NUTTX BUILD COMMIT HASH AND TARGET FOR REFERENCE

(..) <--- THIS MEANS I SKIPPED SOME STUFF THAT IS NOT IMPORTANT

user_main: nxevent test <--- THIS IS VERY IMPORTANT :-)

End of test memory usage:
VARIABLE  BEFORE   AFTER
======== ======== ========
arena       28dfc    28dfc
ordblks         6        6
mxordblk    1f8c8    1f8c8
uordblks     553c     553c
fordblks    238c0    238c0

(..)

user_main: Exiting
ostest_main: Exiting with status 0 <--- EXIT STATUS 0 MEANS ALL OKAY!

@wangchdo
Copy link
Copy Markdown
Contributor Author

wangchdo commented Nov 4, 2025

I think I’ve fixed the CI issue. The problem was caused by my previous manual update of the defconfig. This time, I used make menuconfig to enable EVENT, then ran make savedefconfig, and uploaded the updated defconfg file — it’s working fine now.

@wangchdo
Copy link
Copy Markdown
Contributor Author

wangchdo commented Nov 4, 2025

I fixed CI issue, please help to check again @acassis @anchao @jerpelea @xiaoxiang781216

Copy link
Copy Markdown
Contributor

@anchao anchao left a comment

Choose a reason for hiding this comment

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

LGTM

@anchao anchao merged commit 26af1fa into apache:master Nov 4, 2025
40 checks passed
@wangchdo wangchdo deleted the fix_event_post_issue branch November 4, 2025 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Board: arm Board: risc-v Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants