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

core/msg: yield after thread_flags_wake() in queue_msg() #16899

Merged

Conversation

kaspar030
Copy link
Contributor

@kaspar030 kaspar030 commented Sep 27, 2021

Contribution description

Alternative version of #16751, doesn't require changing thread_yield_higher() semantics.

Without this fix, it is possible that a thread got set to "PENDING"
after being woken up by a message flag, but no scheduling gets
triggered. thread_flag_wake() (called by queue_msg()) does set sched_context_switch_request=1, which in all other cases
in msg.c will be used to conditionally call thread_yield_higher().
This PR adds the missing case in _msg_send().

Testing procedure

Issues/PRs references

#16751

@kaspar030 kaspar030 added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: core Area: RIOT kernel. Handle PRs marked with this with care! CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 27, 2021
@kaspar030
Copy link
Contributor Author

@jia200x could you run your test on this one?

@kaspar030
Copy link
Contributor Author

/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /tmp/dwq.0.3668517265360921/a876dae8bca725c53c4e6673b74d694b/build/tests_gnrc_sixlowpan_frag_minfwd.elf section `.relocate' will not fit in region `rom'
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: region `rom' overflowed by 4 bytes

Ouch. :)

core/msg.c Outdated Show resolved Hide resolved
@benpicco benpicco requested a review from maribu September 28, 2021 08:11
core/msg.c Outdated Show resolved Hide resolved
@kaspar030 kaspar030 added the Process: needs >1 ACK Integration Process: This PR requires more than one ACK label Sep 28, 2021
core/msg.c Outdated Show resolved Hide resolved
@jia200x
Copy link
Member

jia200x commented Sep 28, 2021

@jia200x could you run your test on this one?

Sure! Let's see

@jia200x
Copy link
Member

jia200x commented Sep 28, 2021

tests/gnrc_netif passes, but I get many of these warnings:

RIOT/tests/gnrc_netif/bin/native/tests_gnrc_netif.elf: thread_yield_higher: interrupts are disabled - this should not be

@benpicco
Copy link
Contributor

I think #16754 should fix this

@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 15, 2022
@kaspar030 kaspar030 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 21, 2022
@kaspar030
Copy link
Contributor Author

tests/gnrc_netif passes, but I get many of these warnings:

@jia200x was it just make -Ctests/gnrc_netif all test? Then the warnings are gone. Maybe we tested this before #16754 was in, or with this PR not rebased? (I rebased it now)

@jia200x
Copy link
Member

jia200x commented Apr 21, 2022

tests/gnrc_netif passes, but I get many of these warnings:

@jia200x was it just make -Ctests/gnrc_netif all test? Then the warnings are gone. Maybe we tested this before #16754 was in, or with this PR not rebased? (I rebased it now)

This is triggered when using #16748. I can rebase again and see if the warnings are gone

@kaspar030
Copy link
Contributor Author

This is triggered when using #16748. I can rebase again and see if the warnings are gone

I cloned #16748, rebased to master, merged this PR and ran the tests/gnrc_netif tests on native, and don't see that warning.

@jia200x
Copy link
Member

jia200x commented Apr 21, 2022

I cloned #16748, rebased to master, merged this PR and ran the tests/gnrc_netif tests on native, and don't see that warning.

Then I guess it's fixed

@kaspar030 kaspar030 force-pushed the queue_msg_thread_flags_yield_v2 branch from 0347476 to 0c87335 Compare April 21, 2022 15:28
@kaspar030
Copy link
Contributor Author

@OlegHahm should we backport this?

@kaspar030 kaspar030 enabled auto-merge April 21, 2022 16:28
@OlegHahm
Copy link
Member

To be honest, I'm somewhat reluctant to merge a kernel patch that late in the process. On the other hand a kernel bug is a kernel bug... Under which circumstances will the described bug occur?

@kaspar030
Copy link
Contributor Author

Under which circumstances will the described bug occur?

It occurs if a thread sits waiting for multiple flags including THREAD_FLAG_MSG_WAITING (using thread_flags_wait_*()), then gets sent a message. The thread will end up marked PENDING and in the right runqueue, but if the message was sent from thread context, the task switch is not triggered. probably something else happens soon (any interrupt will do) and the scheduler gets called, but until then, the "highest priority runnable thread is always run" invariant is not honored.

@benpicco benpicco requested a review from jia200x April 28, 2022 09:23
@maribu maribu added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 6, 2022
@kaspar030 kaspar030 merged commit ebdcccb into RIOT-OS:master May 6, 2022
@kaspar030 kaspar030 deleted the queue_msg_thread_flags_yield_v2 branch May 6, 2022 17:04
@chrysn chrysn added this to the Release 2022.07 milestone Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: core Area: RIOT kernel. Handle PRs marked with this with care! CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs >1 ACK Integration Process: This PR requires more than one ACK Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants