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

cpu/native: fix thread_yield_higher() with IRQs disabled #16754

Merged
merged 2 commits into from
Aug 25, 2021

Conversation

kaspar030
Copy link
Contributor

@kaspar030 kaspar030 commented Aug 18, 2021

Contribution description

This PR allows thread_yield_higher() to be called with IRQs disabled, on native. In that case, a deferred yield is executed once interrupts are re-enabled.

That's the behavior on Cortex-M. IMO it would be nice to be able to depend on it.

A test is added for verifying this behavior.
The test verifies this behavior on all platforms though, and should thus be run on them.
Should some platform not behave right, I suggest limiting the test to the working platforms, until this is sorted out.

At least msp430 and avr8 don't behave as required for this test, so I've marked it native only for now.

Testing procedure

As this was warned on and forbidden before, nothing should break. CI tests should be sufficient.

Issues/PRs references

The fix in #16751 could profit from this.

@kaspar030 kaspar030 added Platform: native Platform: This PR/issue effects the native platform Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Aug 18, 2021
@github-actions github-actions bot added Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: tests Area: tests and testing framework labels Aug 18, 2021
@benpicco benpicco added CI: run tests If set, CI server will run tests on hardware for the labeled PR 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 Aug 18, 2021
@@ -1,3 +1,5 @@
include ../Makefile.tests_common

BOARD_WHITELIST := native
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not

Suggested change
BOARD_WHITELIST := native
FEATURES_BLACKLIST += arch_avr8 arch_msp430

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm, I'm not sure about the others. but yes, that's nicer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, I've also added esp, mips and riscv, until they're confirmed to work.

Copy link
Contributor

Choose a reason for hiding this comment

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

don't we have esp on CI?
I have esp on my desk, I can do the test just now.

Copy link
Contributor

Choose a reason for hiding this comment

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

esp8266

/home/benpicco/dev/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyUSB3" -b "115200" --no-reconnect --noprefix --no-repeat-command-on-empty-line 
Twisted not available, please install it if you want to use pyterm's JSON capabilities
Connect to serial port /dev/ttyUSB3
Welcome to pyterm!
Type '/exit' to exit.
READY
s
START
main(): This is RIOT! (Version: 2021.10-devel-380-ge4b3a)
1. post yield
2. second thread scheduled
3. post irq enable

works

esp32

/home/benpicco/dev/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyUSB3" -b "115200" --no-reconnect --noprefix --no-repeat-command-on-empty-line 
Twisted not available, please install it if you want to use pyterm's JSON capabilities
Connect to serial port /dev/ttyUSB3
Welcome to pyterm!
Type '/exit' to exit.
READY
s
START
main(): This is RIOT! (Version: 2021.10-devel-380-ge4b3a)
1. post yield
2. second thread scheduled
3. post irq enable

works

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't esp need to be whiteliseted now @kaspar030 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @benpicco! I've removed the esp blacklist.

@riot-hil-bot
Copy link

HiL Test Results

200 tests passed
16 tests failed
0 tests skipped

  frdm-k22f
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  nucleo-f091rc
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  nucleo-f303re
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  nucleo-f767zi
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  nucleo-l152re
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  arduino-mega2560
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: build fail
  nucleo-l432kc
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  saml10-xpro
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  saml11-xpro
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  samr21-xpro
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  nrf52dk
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: flash fail
  tests/deferred_yield_higher: pass
  remote-revb
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: flash fail
  nucleo-f207zg
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: flash fail
  nucleo-l073rz
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  slstk3401a
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  nucleo-g474re
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  nucleo-f411re
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  nucleo-f103rb
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  frdm-kw41z
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  esp32-wroom-32
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: build fail
  z1
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: build fail
  arduino-due
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: pass
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  slstk3400a
  tests/thread_msg_block_wo_queue: pass
  tests/thread_msg_block_w_queue: pass
  tests/thread_basic: pass
  tests/pthread_barrier: fail
  tests/pthread: pass
  tests/malloc_thread_safety: pass
  tests/event_thread_shared: pass
  tests/event_threads: pass
  tests/deferred_yield_higher: pass
  frdm-k64f
  tests/thread_msg_block_wo_queue: flash fail
  tests/thread_msg_block_w_queue: flash fail
  tests/thread_basic: flash fail
  tests/pthread_barrier: flash fail
  tests/pthread: flash fail
  tests/malloc_thread_safety: flash fail
  tests/event_thread_shared: flash fail
  tests/event_threads: flash fail
  tests/deferred_yield_higher: flash fail

@MrKevinWeiss
Copy link
Contributor

@riot-hil-bot is just trying things out. It wanted some real world test case. More info at the VMA.

@fjmolinas
Copy link
Contributor

@riot-hil-bot is just trying things out. It wanted some real world test case. More info at the VMA.

If you are looking for some input, if the posted results could link to the test logs (when failed) that would be awesome!

@fjmolinas
Copy link
Contributor

@MrKevinWeiss only failure I find weird is slstk3400a: tests/pthread_barrier: fail do you have the logs, just to verify it's unrelated.

@fjmolinas fjmolinas 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 Aug 23, 2021
@fjmolinas
Copy link
Contributor

Please squash!

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

ACK.

This makes native behave like Cortex-M, which flags PENDSV, which then
gets triggered once IRQs are re-enabled.
This test verifies that a thread can call `thread_yield_higher()` with IRQs
disabled, and that the actual context switch is deferred until IRQs are
re-enabled.
@kaspar030 kaspar030 force-pushed the native_deferred_yield_higher branch from 0dfe049 to fe1d998 Compare August 24, 2021 07:50
@kaspar030 kaspar030 removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Aug 24, 2021
@kaspar030 kaspar030 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Aug 24, 2021
@kaspar030 kaspar030 merged commit da140c2 into RIOT-OS:master Aug 25, 2021
@kaspar030 kaspar030 deleted the native_deferred_yield_higher branch August 25, 2021 19:59
@benpicco benpicco added this to the Release 2021.10 milestone Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: native Platform: This PR/issue effects the native platform Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants