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:
commit
916d960b1a
@ -89,7 +89,8 @@ void thread_print_stack(void)
|
||||
__asm__("mov %0, sp" : "=r"(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;
|
||||
s += 5;
|
||||
|
||||
|
@ -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.
|
||||
* 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
|
||||
* getting correct values elsewhere (since it is a debugging tool and in the
|
||||
* 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)
|
||||
{
|
||||
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;
|
||||
|
||||
printf("Printing current stack of thread %" PRIkernel_pid "\n", thread_getpid());
|
||||
|
@ -226,7 +226,7 @@ char *thread_stack_init(thread_task_func_t task_func,
|
||||
void thread_stack_print(void)
|
||||
{
|
||||
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",
|
||||
thread_getpid());
|
||||
|
@ -115,25 +115,27 @@ char *thread_stack_init(thread_task_func_t task_func,
|
||||
void thread_print_stack(void)
|
||||
{
|
||||
int count = 0;
|
||||
uint32_t *sp = (uint32_t *) ((sched_active_thread) ? sched_active_thread->sp : NULL);
|
||||
|
||||
if (sp == NULL) {
|
||||
thread_t *active_thread = thread_get_active();
|
||||
if (!active_thread) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t *sp = (uint32_t *)active_thread->sp;
|
||||
|
||||
printf("printing the current stack of thread %" PRIkernel_pid "\n",
|
||||
thread_getpid());
|
||||
|
||||
#ifdef DEVELHELP
|
||||
printf("thread name: %s\n", sched_active_thread->name);
|
||||
printf("stack start: 0x%08x\n", (unsigned int)(sched_active_thread->stack_start));
|
||||
printf("stack end : 0x%08x\n", (unsigned int)(sched_active_thread->stack_start + sched_active_thread->stack_size));
|
||||
printf("thread name: %s\n", active_thread->name);
|
||||
printf("stack start: 0x%08x\n", (unsigned)(active_thread->stack_start));
|
||||
printf("stack end : 0x%08x\n",
|
||||
(unsigned)(active_thread->stack_start + active_thread->stack_size));
|
||||
#endif
|
||||
|
||||
printf(" address: data:\n");
|
||||
|
||||
do {
|
||||
printf(" 0x%08x: 0x%08x\n", (unsigned int) sp, (unsigned int) *sp);
|
||||
printf(" 0x%08x: 0x%08x\n", (unsigned)sp, (unsigned)*sp);
|
||||
sp++;
|
||||
count++;
|
||||
} while (*sp != STACK_MARKER);
|
||||
|
@ -105,7 +105,7 @@ void *_sbrk_r(struct _reent *r, ptrdiff_t incr)
|
||||
*/
|
||||
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)
|
||||
{
|
||||
(void) ptr;
|
||||
return sched_active_pid;
|
||||
(void)ptr;
|
||||
return thread_getpid();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,8 +132,8 @@ pid_t _getpid_r(struct _reent *ptr)
|
||||
__attribute__ ((weak))
|
||||
int _kill_r(struct _reent *r, pid_t pid, int sig)
|
||||
{
|
||||
(void) pid;
|
||||
(void) sig;
|
||||
(void)pid;
|
||||
(void)sig;
|
||||
r->_errno = ESRCH; /* not implemented yet */
|
||||
return -1;
|
||||
}
|
||||
@ -331,8 +331,8 @@ int _isatty_r(struct _reent *r, int fd)
|
||||
__attribute__ ((weak))
|
||||
int _kill(pid_t pid, int sig)
|
||||
{
|
||||
(void) pid;
|
||||
(void) sig;
|
||||
(void)pid;
|
||||
(void)sig;
|
||||
errno = ESRCH; /* not implemented yet */
|
||||
return -1;
|
||||
}
|
||||
|
@ -56,11 +56,11 @@ static struct fp64ctx *oldfpctx; /* fpu context of last task that executed
|
||||
* | |
|
||||
* ---------------
|
||||
* | 16 byte pad |
|
||||
* --------------- <--- sched_active_thread->sp
|
||||
* --------------- <--- thread_get_active()->sp
|
||||
*/
|
||||
|
||||
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 */
|
||||
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)
|
||||
{
|
||||
uintptr_t *sp = (void *)sched_active_thread->sp;
|
||||
uintptr_t *sp = (void *)thread_get_active()->sp;
|
||||
|
||||
printf("Stack trace:\n");
|
||||
while (*sp != STACK_END_PAINT) {
|
||||
@ -132,7 +132,7 @@ void cpu_switch_context_exit(void)
|
||||
|
||||
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();
|
||||
|
||||
@ -273,8 +273,8 @@ _mips_handle_exception(struct gpctx *ctx, int exception)
|
||||
* Note we cannot use the current sp value as
|
||||
* the prologue of this function has adjusted it
|
||||
*/
|
||||
sched_active_thread->sp = (char *)(ctx->sp
|
||||
- sizeof(struct gpctx) - PADDING);
|
||||
thread_t *t = thread_get_active();
|
||||
t->sp = (char *)(ctx->sp - sizeof(struct gpctx) - PADDING);
|
||||
|
||||
#ifdef MIPS_DSP
|
||||
_dsp_save(&dsp_ctx);
|
||||
@ -289,7 +289,8 @@ _mips_handle_exception(struct gpctx *ctx, int exception)
|
||||
|
||||
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
|
||||
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;
|
||||
#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
|
||||
|
@ -50,7 +50,7 @@ void thread_yield_higher(void)
|
||||
|
||||
__save_context();
|
||||
|
||||
/* have sched_active_thread point to the next thread */
|
||||
/* have thread_get_active() point to the next thread */
|
||||
sched_run();
|
||||
|
||||
__restore_context();
|
||||
|
@ -67,7 +67,7 @@ static inline void __attribute__((always_inline)) __save_context(void)
|
||||
__asm__("push r5");
|
||||
__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)
|
||||
{
|
||||
__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 r5");
|
||||
|
@ -298,9 +298,9 @@ void native_isr_entry(int sig, siginfo_t *info, void *context)
|
||||
if (context == NULL) {
|
||||
errx(EXIT_FAILURE, "native_isr_entry: context is null - unhandled");
|
||||
}
|
||||
if (sched_active_thread == NULL) {
|
||||
if (thread_get_active() == NULL) {
|
||||
_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--;
|
||||
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_flags = 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");
|
||||
/* disable interrupts in context */
|
||||
|
@ -142,12 +142,12 @@ void isr_cpu_switch_context_exit(void)
|
||||
ucontext_t *ctx;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
DEBUG("isr_cpu_switch_context_exit: calling setcontext(%" PRIkernel_pid ")\n\n", sched_active_pid);
|
||||
ctx = (ucontext_t *)(sched_active_thread->sp);
|
||||
DEBUG("isr_cpu_switch_context_exit: calling setcontext(%" PRIkernel_pid ")\n\n", thread_getpid());
|
||||
ctx = (ucontext_t *)(thread_get_active()->sp);
|
||||
|
||||
native_interrupts_enabled = 1;
|
||||
_native_mod_ctx_leave_sigh(ctx);
|
||||
@ -195,8 +195,9 @@ void isr_thread_yield(void)
|
||||
}
|
||||
|
||||
sched_run();
|
||||
ucontext_t *ctx = (ucontext_t *)(sched_active_thread->sp);
|
||||
DEBUG("isr_thread_yield: switching to(%" PRIkernel_pid ")\n\n", sched_active_pid);
|
||||
ucontext_t *ctx = (ucontext_t *)(thread_get_active()->sp);
|
||||
DEBUG("isr_thread_yield: switching to(%" PRIkernel_pid ")\n\n",
|
||||
thread_getpid());
|
||||
|
||||
native_interrupts_enabled = 1;
|
||||
_native_mod_ctx_leave_sigh(ctx);
|
||||
@ -211,7 +212,7 @@ void thread_yield_higher(void)
|
||||
sched_context_switch_request = 1;
|
||||
|
||||
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;
|
||||
if (!native_interrupts_enabled) {
|
||||
warnx("thread_yield_higher: interrupts are disabled - this should not be");
|
||||
|
@ -125,11 +125,11 @@ void _native_syscall_leave(void)
|
||||
&& (_native_in_isr == 0)
|
||||
&& (_native_in_syscall == 0)
|
||||
&& (native_interrupts_enabled == 1)
|
||||
&& (sched_active_thread != NULL)
|
||||
&& (thread_get_active() != NULL)
|
||||
)
|
||||
{
|
||||
_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_size = SIGSTKSZ;
|
||||
native_isr_context.uc_stack.ss_flags = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user