kernel/arch: inspect prio/sched_locked together for preemptibility

These two fields in the thread structure control the preemptibility of a
thread.

sched_locked is decremented when the scheduler gets locked, which means
that the scheduler is locked for values 0xff to 0x01, since it can be
locked recursively. A thread is coop if its priority is negative, thus
if the prio field value is 0x80 to 0xff when looked at as an unsigned
value.

By putting them end-to-end, this means that a thread is non-preemptible
if the bundled value is greater than or equal to 0x0080. This is the
only thing the interrupt exit code has to check to decide to try a
reschedule or not.

Change-Id: I902d36c14859d0d7a951a6aa1bea164613821aca
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
This commit is contained in:
Benjamin Walsh 2016-12-21 16:00:35 -05:00 committed by Anas Nashif
commit 168695c7ef
10 changed files with 80 additions and 77 deletions

View file

@ -65,6 +65,11 @@
#endif
/* end - execution flags */
/* lowest value of _thread_base.preempt at which a thread is non-preemptible */
#define _NON_PREEMPT_THRESHOLD 0x0080
/* highest value of _thread_base.preempt at which a thread is preemptible */
#define _PREEMPT_THRESHOLD (_NON_PREEMPT_THRESHOLD - 1)
#include <kernel_arch_data.h>
@ -91,11 +96,32 @@ struct _thread_base {
/* thread state */
uint8_t thread_state;
/* scheduler lock count */
volatile uint8_t sched_locked;
/* thread priority used to sort linked list */
int8_t prio;
/*
* scheduler lock count and thread priority
*
* These two fields control the preemptibility of a thread.
*
* When the scheduler is locked, sched_locked is decremented, which
* means that the scheduler is locked for values from 0xff to 0x01. A
* thread is coop if its prio is negative, thus 0x80 to 0xff when
* looked at the value as unsigned.
*
* By putting them end-to-end, this means that a thread is
* non-preemptible if the bundled value is greater than or equal to
* 0x0080.
*/
union {
struct {
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint8_t sched_locked;
volatile int8_t prio;
#else /* LITTLE and PDP */
volatile int8_t prio;
uint8_t sched_locked;
#endif
};
uint16_t preempt;
};
/* data returned by APIs */
void *swap_data;