As discussed in #2725, this commit renames a number of stacksize constants to
better convey their intended usage. In addition, constants for thread priority
are given a `THREAD_` prefix. Changes are:
* KERNEL_CONF_STACKSIZE_PRINTF renamed to THREAD_EXTRA_STACKSIZE_PRINTF
* KERNEL_CONF_STACKSIZE_DEFAULT renamed to THREAD_STACKSIZE_DEFAULT
* KERNEL_CONF_STACKSIZE_IDLE renamed to THREAD_STACKSIZE_IDLE
* KERNEL_CONF_STACKSIZE_MAIN renamed to THREAD_STACKSIZE_MAIN
* Move thread stacksizes from kernel.h to thread.h, since the prefix changed
* PRIORITY_MIN renamed to THREAD_PRIORITY_MIN
* PRIORITY_IDLE renamed to THREAD_PRIORITY_IDLE
* PRIORITY_MAIN renamed to THREAD_PRIORITY_MAIN
* Move thread priorities from kernel.h to thread.h since the prefix has changed
* MINIMUM_STACK_SIZE renamed to THREAD_STACKSIZE_MINIMUM for consistency
- Move generic implementation of atomic_set_return to core/atomic.c
- Generic implementation of atomic compare and swap in core/atomic.c
- atomic_cas is used to implement atomic counters in core/include/atomic.h
- atomic_int_t is an atomic integer type
- ATOMIC_INIT can be used as an initializer for atomic_int_t
- ATOMIC_VALUE gets a reference to the value of an atomic integer
The ucontext->x86_fxsave is initialize as 512 bytes of zeros, but it
is not a valid value to be set onto FPU registers, causing a General
Protection Fault:
Interrupt 0x0d (General Protection Fault) while handling 0x07 (Device not available)
EAX=0012f4c0 ECX=001336e4 EDX=001334ac EBX=001336e0
ESP=00123784 EBP=001237c8 ESI=00000200 EDI=00000000
Error code=00000000
CR0=80010031 CR2=00000000 CR3=0012d000 CR4=000001e0
EIP=0000:80010031 EFLAGS=0012d000
<stack trace>
00000000
???
</stack trace>
Halting.
So lets copy the initial state of FPU registers before FPU is used
and set it as the initial state of FPU to new threads(coroutine).
Fixes#1708.
Currently involuntary preemption causes the current thread not only to
yield for a higher prioritized thread, but all other threads of its own
priority class, too.
This PR adds the function `thread_yield_higher()`, which will yield the
current thread in favor of higher prioritized functions, but not for
threads of its own priority class.
Boards now need to implement `thread_yield_higher()` instead of
`thread_yield()`, but `COREIF_NG` boards are not affected in any way.
`thread_yield()` retains its old meaning: yield for every thread that
has the same or a higher priority.
This PR does not touch the occurrences of `thread_yield()` in the periph
drivers, because the author of this PR did not look into the logic of
the various driver implementations.
Instead of using differing integer types use kernel_pid_t for process
identifier. This type is introduced in a new header file to avoid
circular dependencies.
Finding read-before-writes statically is quite difficult. In native we
can use valgrind, but on boards without an MMU we are out of luck.
x86 has an MMU, let's use it.
If `-DDEBUG_READ_BEFORE_WRITE` was set, then pages on the heap get
initialized upon first use. If the page was read before written, then a
debug message with the virtual and physical address of the memory
location is printed, as well as the address of the offending instruction.