1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
Commit Graph

132 Commits

Author SHA1 Message Date
Sören Tempel
80116651c2 core: Treat stack overflows as an unrecoverable error
Presently, RIOT just emits a warning when a stack overflow is
encountered but still resumes execution. In my view, execution should be
aborted as the detection of a stack overflows via the heuristic provided
by the scheduler is an unrecoverable error.

I ran into this while performing automated tests of a RIOT application
where a stack overflow occurred but I only noticed this after inspecting
the application output more closely.

Similar to SSP failures, I added crash_code for stack overflows.
2022-08-12 05:26:22 +02:00
Marian Buschsieweke
d53cd19142
core/sched.c: fix undefined behavior on 8-bit/16-bit
An `1 << x` with `x >= 15` is undefined behavior on 8-bit / 16-bit
machines (which typically have `sizeof(int) == 2`).

Using `1UL << x` is safe for `x <= 31`, which is large enough to make
use of the full 32 bits in `runqueue_bitcache`.

In addition, a `static_assert()` is added to enforce that
`SCHED_PRIO_LEVELS` is never set to anything larger than 32.
2022-09-09 21:55:17 +02:00
2ba85c1bc8 core: add support for test_utils_print_stack_usage
- activate THREAD_CREATE_STACKTEST also if test_utils_print_stack_usage
  is used

- make thread_measure_stack_free() available unconditionally

- if DEVELHELP is active, call test_utils_print_stack_usage() on any
  thread exit

- if DEVELHELP is active, call test_utils_print_stack_usage() after main
  for the idle thread, if that is used
2022-03-29 21:49:35 +02:00
benpicco
5a57dec71a
Merge pull request #17093 from maribu/core/change_prio
core/sched: add sched_change_priority()
2022-01-28 20:01:20 +01:00
Marian Buschsieweke
b9c07f9622
core/sched: silence -Wcast-align 2021-12-03 10:12:34 +01:00
Martine Lenders
f08989a3c8
core: make SCHED_TEST_STACK boolean and default to 1 with DEVELHELP 2021-11-05 09:27:00 +01:00
Hauke Petersen
3d7d797a57
core/sched: add sched_change_priority() function
Co-authored-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
2021-11-02 20:44:32 +01:00
Karl Fessel
671a7edca1 core/sched: uncrustify sched_cb declaration
this is a change out of this PR scope to reduce
the number of uncrustify complains for future edits
2021-08-09 14:22:07 +02:00
Karl Fessel
9f00528a58 core/sched: add runq_callback hook and runq inspection functions 2021-05-10 15:01:58 +02:00
Bas Stottelaar
cc2e6b08d1 core/*: ENABLE_DEBUG not needed for inttypes.h 2020-11-02 21:49:39 +01:00
Bas Stottelaar
e675b6379e core/*: realign ENABLE_DEBUG 2020-10-23 00:45:56 +02:00
77735e7e10
Merge pull request #14709 from bergzand/pr/sched/return_thread 2020-09-03 10:18:47 +02:00
495644adc0
sched: return the new thread on sched_run 2020-09-02 13:32:14 +02:00
f68f19a73f
Merge pull request #14722 from bergzand/pr/sched/runqueue_clz
sched: Reverse runqueue order when CLZ is available
2020-09-01 22:57:30 +02:00
dd45eaa472
sched: simplify MODULE_CORE_IDLE_THREAD conditional 2020-08-25 14:00:01 +02:00
764b3102e4
sched: Early exit when scheduling same thread after sleep 2020-08-25 13:59:58 +02:00
Keith Packard
531050ada2 picolibc: Enable TLS support [v4]
Allocate and initialize a thread-local block for each thread at the
top of the stack.

Set the tls base when switching to a new thread.

Add tdata/tbss linker instructions to cortex_m and risc-v scripts.

Signed-off-by: Keith Packard <keithp@keithp.com>

---

v2:
	Squash fixes

v3:
	Replace tabs with spaces

v4:
	Add tbss to fe310 linker script
2020-08-24 08:26:16 -07:00
e6fd3630eb
sched: Remove extra mpu_enable during context switch 2020-08-19 20:13:28 +02:00
ab1d0b6f98
sched: Reverse runqueue order when CLZ is available
This commit reverses the runqueue_cache bit order when the architecture
has a CLZ (count leading zeros) instruction. When the architecture
supports CLZ, it is faster to determine the most significant set bit of
a word than to determine the least significant bit set. Unfortunately
when the instruction is not available, it is more efficient to determine
the least significant bit set.

Reversing the bit order shaves off another 4 cycles on the same54-xpro.
From 147 to 143 ticks when testing with tests/bench_sched_nop.
Architectures where no CLZ instruction is available are not affected.
2020-08-06 20:39:14 +02:00
Marian Buschsieweke
57264c5059
core: Access internal vars via helper funcs
Replace accesses to `sched_active_thread`, `sched_active_pid`, and
`sched_threads` with `thread_get_active()`, `thread_get_active_pid()`, and
`thread_get_unchecked()` where sensible.
2020-08-06 16:47:33 +02:00
Martine Lenders
b1bf8ab981
Merge pull request #14565 from bergzand/pr/sched/fix_retrigger
sched: Prevent retriggering the scheduler interrupt during idle sleep
2020-07-28 22:11:25 +02:00
Benjamin Valentin
4d34cee72f core: add comments to symbols used by OpenOCD
OpenOCD makes assumptions about those symbol names / enum entries,
so add a note about it as a comment.
2020-07-27 16:14:42 +02:00
2d74651237
sched: Clear context_switch_request after potential idle sleep
An interrupt serviced during the idle sleep can re-request a context
switch while the scheduler is already going to switch contexts after the
idle sleep. Thi sched_context_switch_request should thus be cleared
after the idle sleep and not before where it could be modified during
the idle sleep and get out of sync.
2020-07-21 11:27:08 +02:00
e1b810b613
core/sched: tiny logic optimization in idle case
In the case that the no_thread_idle feature is active, the
runqueue_bitcache is checked twice in the case no thread is available to
schedule. This changes the inner while loop to a do-while loop to save
one check from the initial loop iteration, saving a cycle or so in the
idle case.
2020-07-20 23:26:47 +02:00
d199865a12 core: sched: correctly unschedule when there's no idle thread 2020-06-25 16:02:29 +02:00
e3f6c0f340 core: make idle thread optional 2020-06-25 16:02:28 +02:00
8efe5960aa core: uncrustify 2020-03-30 17:02:08 +02:00
f99bc894de core: make some formatting uncrustify friendly (or ignore) 2020-03-30 17:00:32 +02:00
Sören Tempel
59676a1f5e Make sure the mpu_noexec_ram regions has the lowest priority
From the ARMv7-M ARM section B3.5.3:

	Where there is an overlap between two regions, the register with
	the highest region number takes priority.

We want to make sure the mpu_noexec_ram region has the lowest
priority to allow the mpu_stack_guard region to overwrite the first N
bytes of it.

This change fixes using mpu_noexec_ram and mpu_stack_guard together.
2020-03-10 11:16:22 +01:00
fenghe
d6227cbc4d core/sched: remove duplicate include of irq.h 2019-10-31 01:28:32 +08:00
Francisco Molina
1caf6610cb sys: add schedstatistics module 2019-09-13 11:37:44 +02:00
Francisco Molina
fc58ebbd97 core/sched: separate sched_cb from schedstatistics 2019-09-10 17:08:21 +02:00
francisco
3d62fa05b8 core/schedstatistics: refactor
- add init_schedstatistics function to be called after
  auto_init, that way xtimer_is init is called before
  the first call to xtimer_now
- register schedstatics code as a callback to be executed
  on each sched_run()
2019-09-10 17:07:54 +02:00
Kees Bakker
2a0a36945c core: make use of ARRAY_SIZE macro 2019-08-06 19:43:54 +02:00
Martine Lenders
db20a057ae core: rename thread_state_t to thread_status_t
This way it can't come to name collisions on `native` with Mac OSX'
threading library [1].

[1]: https://opensource.apple.com/source/xnu/xnu-792/osfmk/mach/thread_status.h.auto.html
2019-05-11 12:25:07 +02:00
Marian Buschsieweke
435f798a2b
core/sched: Fixed typo 2019-03-21 22:00:37 +01:00
Marian Buschsieweke
4c3e92f183
core: Made thread state an enum
- Introduced enum type `thread_state_t` to replace preprocessor macros
- Moved thread states to `sched.h` for two reasons:
  a) Because of the interdependencies of `sched.h` and `thread.h` keeping it in
     `thread.h` would result in ugly code.
  b) Theses thread states are defined from the schedulers point of view, so it
     actually makes senses to have it defined there
2019-02-13 13:31:52 +01:00
Joakim Nohlgård
5b68bbb2cf core: Rename typedef schedstat -> schedstat_t
To follow naming conventions
2018-10-26 09:10:21 +02:00
Joakim Nohlgård
ab05acbf89 core: Mark openocd info variables read-only 2018-08-25 14:44:45 +02:00
smlng
e017f8a5f1 core: fix format errors in debug output 2018-01-17 15:25:11 +01:00
smlng
e7136e2dde schedstats: revert #6975, use 32Bit again 2017-06-08 14:33:47 +02:00
Vincent Dupont
6d5b95517d ps: fix schedstatistics
Fix xtimer_now() usage and fix columns alignment in ps command when
module schedstatistics is used.
2017-05-16 10:33:42 +02:00
smlng
0d4855c256 core: fix osx compile issue 2017-02-01 09:06:48 +01:00
Oleg Hahm
c5abb08316 Merge pull request #4058 from daniel-k/pr/gdb_threads_openocd
cortex_m: Add debug symbols for OpenOCD/GDB thread support
2017-01-25 17:49:42 +01:00
daniel-k
9d403d95ce cortex_m: Add debug symbols for OpenOCD/GDB thread support 2017-01-16 20:50:35 +01:00
Joakim Nohlgård
0ba6c9f3a4 core/sched: Use xtimer ticks for sched statistics 2016-11-28 11:00:42 +01:00
Ian Martin
28a7ddc9a8 core: save the stack_start in the thread context for mpu_stack_guard 2016-10-24 12:36:15 -04:00
25a6ef5273 core: sched: mark sched_run() as used 2016-08-29 13:30:17 +02:00
d86c141842 core, tests: adapt to changed clist function names 2016-07-18 16:20:40 +02:00
f9f6adb48d core: clist: make singly linked 2016-03-30 00:27:49 +02:00