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

Merge pull request #14774 from maribu/cpu_sched_active

cpu: Use thread_getpid() and thread_get_active() instead of sched_active_*
This commit is contained in:
benpicco 2020-08-17 15:21:46 +02:00 committed by GitHub
commit 916d960b1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 45 additions and 40 deletions

View File

@ -89,7 +89,8 @@ void thread_print_stack(void)
__asm__("mov %0, sp" : "=r"(stack)); __asm__("mov %0, sp" : "=r"(stack));
register unsigned int *s = (unsigned int *)stack; register unsigned int *s = (unsigned int *)stack;
printf("task: %X SP: %X\n", (unsigned int) sched_active_thread, (unsigned int) stack); printf("task: %" PRIkernel_pid " SP: %X\n", thread_getpid(),
(uintptr_t)stack);
register int i = 0; register int i = 0;
s += 5; s += 5;

View File

@ -168,7 +168,7 @@ char *thread_stack_init(thread_task_func_t task_func, void *arg,
/** /**
* @brief thread_stack_print prints the stack to stdout. * @brief thread_stack_print prints the stack to stdout.
* It depends on getting the correct values for stack_start, stack_size and sp * It depends on getting the correct values for stack_start, stack_size and sp
* from sched_active_thread. * of the active thread.
* Maybe it would be good to change that to way that is less dependent on * Maybe it would be good to change that to way that is less dependent on
* getting correct values elsewhere (since it is a debugging tool and in the * getting correct values elsewhere (since it is a debugging tool and in the
* presence of bugs the data may be corrupted). * presence of bugs the data may be corrupted).
@ -176,7 +176,7 @@ char *thread_stack_init(thread_task_func_t task_func, void *arg,
void thread_stack_print(void) void thread_stack_print(void)
{ {
uint8_t found_marker = 1; uint8_t found_marker = 1;
uint8_t *sp = (uint8_t *)sched_active_thread->sp; uint8_t *sp = (uint8_t *)thread_get_active()->sp;
uint16_t size = 0; uint16_t size = 0;
printf("Printing current stack of thread %" PRIkernel_pid "\n", thread_getpid()); printf("Printing current stack of thread %" PRIkernel_pid "\n", thread_getpid());

View File

@ -226,7 +226,7 @@ char *thread_stack_init(thread_task_func_t task_func,
void thread_stack_print(void) void thread_stack_print(void)
{ {
int count = 0; int count = 0;
uint32_t *sp = (uint32_t *)sched_active_thread->sp; uint32_t *sp = (uint32_t *)thread_get_active()->sp;
printf("printing the current stack of thread %" PRIkernel_pid "\n", printf("printing the current stack of thread %" PRIkernel_pid "\n",
thread_getpid()); thread_getpid());

View File

@ -115,25 +115,27 @@ char *thread_stack_init(thread_task_func_t task_func,
void thread_print_stack(void) void thread_print_stack(void)
{ {
int count = 0; int count = 0;
uint32_t *sp = (uint32_t *) ((sched_active_thread) ? sched_active_thread->sp : NULL); thread_t *active_thread = thread_get_active();
if (!active_thread) {
if (sp == NULL) {
return; return;
} }
uint32_t *sp = (uint32_t *)active_thread->sp;
printf("printing the current stack of thread %" PRIkernel_pid "\n", printf("printing the current stack of thread %" PRIkernel_pid "\n",
thread_getpid()); thread_getpid());
#ifdef DEVELHELP #ifdef DEVELHELP
printf("thread name: %s\n", sched_active_thread->name); printf("thread name: %s\n", active_thread->name);
printf("stack start: 0x%08x\n", (unsigned int)(sched_active_thread->stack_start)); printf("stack start: 0x%08x\n", (unsigned)(active_thread->stack_start));
printf("stack end : 0x%08x\n", (unsigned int)(sched_active_thread->stack_start + sched_active_thread->stack_size)); printf("stack end : 0x%08x\n",
(unsigned)(active_thread->stack_start + active_thread->stack_size));
#endif #endif
printf(" address: data:\n"); printf(" address: data:\n");
do { do {
printf(" 0x%08x: 0x%08x\n", (unsigned int) sp, (unsigned int) *sp); printf(" 0x%08x: 0x%08x\n", (unsigned)sp, (unsigned)*sp);
sp++; sp++;
count++; count++;
} while (*sp != STACK_MARKER); } while (*sp != STACK_MARKER);

View File

@ -105,7 +105,7 @@ void *_sbrk_r(struct _reent *r, ptrdiff_t incr)
*/ */
pid_t _getpid(void) pid_t _getpid(void)
{ {
return sched_active_pid; return thread_getpid();
} }
/** /**
@ -115,8 +115,8 @@ pid_t _getpid(void)
*/ */
pid_t _getpid_r(struct _reent *ptr) pid_t _getpid_r(struct _reent *ptr)
{ {
(void) ptr; (void)ptr;
return sched_active_pid; return thread_getpid();
} }
/** /**
@ -132,8 +132,8 @@ pid_t _getpid_r(struct _reent *ptr)
__attribute__ ((weak)) __attribute__ ((weak))
int _kill_r(struct _reent *r, pid_t pid, int sig) int _kill_r(struct _reent *r, pid_t pid, int sig)
{ {
(void) pid; (void)pid;
(void) sig; (void)sig;
r->_errno = ESRCH; /* not implemented yet */ r->_errno = ESRCH; /* not implemented yet */
return -1; return -1;
} }
@ -331,8 +331,8 @@ int _isatty_r(struct _reent *r, int fd)
__attribute__ ((weak)) __attribute__ ((weak))
int _kill(pid_t pid, int sig) int _kill(pid_t pid, int sig)
{ {
(void) pid; (void)pid;
(void) sig; (void)sig;
errno = ESRCH; /* not implemented yet */ errno = ESRCH; /* not implemented yet */
return -1; return -1;
} }

View File

@ -56,11 +56,11 @@ static struct fp64ctx *oldfpctx; /* fpu context of last task that executed
* | | * | |
* --------------- * ---------------
* | 16 byte pad | * | 16 byte pad |
* --------------- <--- sched_active_thread->sp * --------------- <--- thread_get_active()->sp
*/ */
char *thread_stack_init(thread_task_func_t task_func, void *arg, char *thread_stack_init(thread_task_func_t task_func, void *arg,
void *stack_start, int stack_size) void *stack_start, int stack_size)
{ {
/* make sure it is aligned to 8 bytes this is a requirement of the O32 ABI */ /* make sure it is aligned to 8 bytes this is a requirement of the O32 ABI */
uintptr_t *p = (uintptr_t *)(((long)(stack_start) + stack_size) & ~7); uintptr_t *p = (uintptr_t *)(((long)(stack_start) + stack_size) & ~7);
@ -107,7 +107,7 @@ char *thread_stack_init(thread_task_func_t task_func, void *arg,
void thread_stack_print(void) void thread_stack_print(void)
{ {
uintptr_t *sp = (void *)sched_active_thread->sp; uintptr_t *sp = (void *)thread_get_active()->sp;
printf("Stack trace:\n"); printf("Stack trace:\n");
while (*sp != STACK_END_PAINT) { while (*sp != STACK_END_PAINT) {
@ -132,7 +132,7 @@ void cpu_switch_context_exit(void)
sched_run(); sched_run();
__asm volatile ("lw $sp, 0(%0)" : : "r" (&sched_active_thread->sp)); __asm volatile ("lw $sp, 0(%0)" : : "r" (&thread_get_active()->sp));
__exception_restore(); __exception_restore();
@ -273,8 +273,8 @@ _mips_handle_exception(struct gpctx *ctx, int exception)
* Note we cannot use the current sp value as * Note we cannot use the current sp value as
* the prologue of this function has adjusted it * the prologue of this function has adjusted it
*/ */
sched_active_thread->sp = (char *)(ctx->sp thread_t *t = thread_get_active();
- sizeof(struct gpctx) - PADDING); t->sp = (char *)(ctx->sp - sizeof(struct gpctx) - PADDING);
#ifdef MIPS_DSP #ifdef MIPS_DSP
_dsp_save(&dsp_ctx); _dsp_save(&dsp_ctx);
@ -289,7 +289,8 @@ _mips_handle_exception(struct gpctx *ctx, int exception)
sched_run(); sched_run();
new_ctx = (struct gpctx *)((unsigned int)sched_active_thread->sp + PADDING); t = thread_get_active();
new_ctx = (struct gpctx *)((unsigned int)t->sp + PADDING);
#ifdef MIPS_HARD_FLOAT #ifdef MIPS_HARD_FLOAT
currentfpctx = (struct fp64ctx *)exctx_find(LINKCTX_TYPE_FP64, new_ctx); currentfpctx = (struct fp64ctx *)exctx_find(LINKCTX_TYPE_FP64, new_ctx);
@ -337,7 +338,7 @@ _mips_handle_exception(struct gpctx *ctx, int exception)
new_ctx->status &= ~SR_CU1; new_ctx->status &= ~SR_CU1;
#endif #endif
__asm volatile ("lw $sp, 0(%0)" : : "r" (&sched_active_thread->sp)); __asm volatile ("lw $sp, 0(%0)" : : "r" (&thread_get_active()->sp));
/* /*
* Jump straight to the exception restore code * Jump straight to the exception restore code

View File

@ -50,7 +50,7 @@ void thread_yield_higher(void)
__save_context(); __save_context();
/* have sched_active_thread point to the next thread */ /* have thread_get_active() point to the next thread */
sched_run(); sched_run();
__restore_context(); __restore_context();

View File

@ -67,7 +67,7 @@ static inline void __attribute__((always_inline)) __save_context(void)
__asm__("push r5"); __asm__("push r5");
__asm__("push r4"); __asm__("push r4");
__asm__("mov.w r1,%0" : "=r"(sched_active_thread->sp)); __asm__("mov.w r1,%0" : "=r"(thread_get_active()->sp));
} }
/** /**
@ -75,7 +75,7 @@ static inline void __attribute__((always_inline)) __save_context(void)
*/ */
static inline void __attribute__((always_inline)) __restore_context(void) static inline void __attribute__((always_inline)) __restore_context(void)
{ {
__asm__("mov.w %0,r1" : : "m"(sched_active_thread->sp)); __asm__("mov.w %0,r1" : : "m"(thread_get_active()->sp));
__asm__("pop r4"); __asm__("pop r4");
__asm__("pop r5"); __asm__("pop r5");

View File

@ -298,9 +298,9 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
if (context == NULL) { if (context == NULL) {
errx(EXIT_FAILURE, "native_isr_entry: context is null - unhandled"); errx(EXIT_FAILURE, "native_isr_entry: context is null - unhandled");
} }
if (sched_active_thread == NULL) { if (thread_get_active() == NULL) {
_native_in_isr++; _native_in_isr++;
warnx("native_isr_entry: sched_active_thread is null - unhandled"); warnx("native_isr_entry: thread_get_active() is null - unhandled");
_native_in_isr--; _native_in_isr--;
return; return;
} }
@ -325,7 +325,7 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
native_isr_context.uc_stack.ss_size = sizeof(__isr_stack); native_isr_context.uc_stack.ss_size = sizeof(__isr_stack);
native_isr_context.uc_stack.ss_flags = 0; native_isr_context.uc_stack.ss_flags = 0;
makecontext(&native_isr_context, native_irq_handler, 0); makecontext(&native_isr_context, native_irq_handler, 0);
_native_cur_ctx = (ucontext_t *)sched_active_thread->sp; _native_cur_ctx = (ucontext_t *)thread_get_active()->sp;
DEBUG("\n\n\t\tnative_isr_entry: return to _native_sig_leave_tramp\n\n"); DEBUG("\n\n\t\tnative_isr_entry: return to _native_sig_leave_tramp\n\n");
/* disable interrupts in context */ /* disable interrupts in context */

View File

@ -142,12 +142,12 @@ void isr_cpu_switch_context_exit(void)
ucontext_t *ctx; ucontext_t *ctx;
DEBUG("isr_cpu_switch_context_exit\n"); DEBUG("isr_cpu_switch_context_exit\n");
if ((sched_context_switch_request == 1) || (sched_active_thread == NULL)) { if ((sched_context_switch_request == 1) || (thread_get_active() == NULL)) {
sched_run(); sched_run();
} }
DEBUG("isr_cpu_switch_context_exit: calling setcontext(%" PRIkernel_pid ")\n\n", sched_active_pid); DEBUG("isr_cpu_switch_context_exit: calling setcontext(%" PRIkernel_pid ")\n\n", thread_getpid());
ctx = (ucontext_t *)(sched_active_thread->sp); ctx = (ucontext_t *)(thread_get_active()->sp);
native_interrupts_enabled = 1; native_interrupts_enabled = 1;
_native_mod_ctx_leave_sigh(ctx); _native_mod_ctx_leave_sigh(ctx);
@ -195,8 +195,9 @@ void isr_thread_yield(void)
} }
sched_run(); sched_run();
ucontext_t *ctx = (ucontext_t *)(sched_active_thread->sp); ucontext_t *ctx = (ucontext_t *)(thread_get_active()->sp);
DEBUG("isr_thread_yield: switching to(%" PRIkernel_pid ")\n\n", sched_active_pid); DEBUG("isr_thread_yield: switching to(%" PRIkernel_pid ")\n\n",
thread_getpid());
native_interrupts_enabled = 1; native_interrupts_enabled = 1;
_native_mod_ctx_leave_sigh(ctx); _native_mod_ctx_leave_sigh(ctx);
@ -211,7 +212,7 @@ void thread_yield_higher(void)
sched_context_switch_request = 1; sched_context_switch_request = 1;
if (_native_in_isr == 0) { if (_native_in_isr == 0) {
ucontext_t *ctx = (ucontext_t *)(sched_active_thread->sp); ucontext_t *ctx = (ucontext_t *)(thread_get_active()->sp);
_native_in_isr = 1; _native_in_isr = 1;
if (!native_interrupts_enabled) { if (!native_interrupts_enabled) {
warnx("thread_yield_higher: interrupts are disabled - this should not be"); warnx("thread_yield_higher: interrupts are disabled - this should not be");

View File

@ -125,11 +125,11 @@ void _native_syscall_leave(void)
&& (_native_in_isr == 0) && (_native_in_isr == 0)
&& (_native_in_syscall == 0) && (_native_in_syscall == 0)
&& (native_interrupts_enabled == 1) && (native_interrupts_enabled == 1)
&& (sched_active_thread != NULL) && (thread_get_active() != NULL)
) )
{ {
_native_in_isr = 1; _native_in_isr = 1;
_native_cur_ctx = (ucontext_t *)sched_active_thread->sp; _native_cur_ctx = (ucontext_t *)thread_get_active()->sp;
native_isr_context.uc_stack.ss_sp = __isr_stack; native_isr_context.uc_stack.ss_sp = __isr_stack;
native_isr_context.uc_stack.ss_size = SIGSTKSZ; native_isr_context.uc_stack.ss_size = SIGSTKSZ;
native_isr_context.uc_stack.ss_flags = 0; native_isr_context.uc_stack.ss_flags = 0;