From: bernie Date: Fri, 15 Aug 2008 19:34:39 +0000 (+0000) Subject: preempt: much closer X-Git-Tag: 2.0.0~292 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=57da5b0bdc06a8a69c740616f145cb9fe28f8c9f;p=bertos.git preempt: much closer git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1642 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/app/demo/demo.mk b/app/demo/demo.mk index 941e28a6..a66e0f89 100644 --- a/app/demo/demo.mk +++ b/app/demo/demo.mk @@ -19,6 +19,7 @@ TRG += demo # FIXME: we want to use g++ for C source too CC = g++ +CXX = g++ demo_CXXSRC = \ bertos/emul/emul.cpp \ diff --git a/bertos/kern/preempt.c b/bertos/kern/preempt.c index dfa343d7..ab3fc7a8 100644 --- a/bertos/kern/preempt.c +++ b/bertos/kern/preempt.c @@ -92,10 +92,12 @@ void proc_preempt(void) ATOMIC(LIST_ASSERT_VALID(&ProcReadyList)); + TRACEMSG("hello1"); IRQ_DISABLE; /* Poll on the ready queue for the first ready process */ while (!(CurrentProcess = (struct Process *)list_remHead(&ProcReadyList))) { + TRACEMSG("hello2"); /* * Make sure we physically reenable interrupts here, no matter what * the current task status is. This is important because if we @@ -109,11 +111,13 @@ void proc_preempt(void) * are reloaded. */ IRQ_ENABLE; - CPU_IDLE; + //FIXME: calls Qt stuff from sighandler! CPU_IDLE; MEMORY_BARRIER; IRQ_DISABLE; + TRACEMSG("hello3"); } IRQ_ENABLE; + TRACEMSG("hello4"); } void proc_preempt_timer(void) @@ -121,12 +125,20 @@ void proc_preempt_timer(void) // TODO: check Quantum alarm(1); - ATOMIC(SCHED_ENQUEUE(CurrentProcess)); - proc_schedule(); + + if (CurrentProcess) + { + TRACEMSG("preempting %p:%s", CurrentProcess, CurrentProcess->monitor.name); + ATOMIC(SCHED_ENQUEUE(CurrentProcess)); + proc_schedule(); + } } void proc_schedule(void) { + TRACE; + + // Will invoke proc_preempt() in interrupt context kill(0, SIGUSR1); } @@ -137,21 +149,27 @@ void proc_yield(void) proc_schedule(); } +void proc_entry(void (*user_entry)(void)) +{ + user_entry(); + proc_exit(); +} + /* signal handler */ void irq_entry(int signum) { Process *old_process; - TRACEMSG("storing %p:%s", CurrentProcess, CurrentProcess->monitor.name); - CurrentProcess->leaving = false; - getcontext(&CurrentProcess->context); +// TRACEMSG("storing %p:%s", CurrentProcess, CurrentProcess->monitor.name); +// CurrentProcess->leaving = false; +// getcontext(&CurrentProcess->context); /* We get here in two ways: directly, and after setcontext() below */ - if (CurrentProcess->leaving) - { - TRACEMSG("leaving to %p:%s", CurrentProcess, CurrentProcess->monitor.name); - return; - } +// if (CurrentProcess->leaving) +// { +// TRACEMSG("leaving to %p:%s", CurrentProcess, CurrentProcess->monitor.name); +// return; +// } old_process = CurrentProcess; @@ -159,9 +177,13 @@ void irq_entry(int signum) if (old_process != CurrentProcess) { - TRACEMSG("launching %p:%s", CurrentProcess, CurrentProcess->monitor.name); - CurrentProcess->leaving = true; - setcontext(&CurrentProcess->context); + TRACEMSG("switching from %p:%s to %p:%s", + old_process, old_process->monitor.name, + CurrentProcess, CurrentProcess->monitor.name); + swapcontext(&old_process->context, &CurrentProcess->context); +// TRACEMSG("launching %p:%s", CurrentProcess, CurrentProcess->monitor.name); +// CurrentProcess->leaving = true; +// setcontext(&CurrentProcess->context); /* not reached */ } diff --git a/bertos/kern/proc.c b/bertos/kern/proc.c index afe9e34a..3f254892 100644 --- a/bertos/kern/proc.c +++ b/bertos/kern/proc.c @@ -52,9 +52,6 @@ #include /* memset() */ -#if CONFIG_KERN_PREEMPT -#include "preempt.h" -#endif /* * The scheduer tracks ready processes by enqueuing them in the @@ -209,7 +206,7 @@ struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(voi proc->context.uc_stack.ss_sp = stack_base; proc->context.uc_stack.ss_size = stack_size; proc->context.uc_link = NULL; - makecontext(&proc->context, entry, 0); + makecontext(&proc->context, (void (*)(void))proc_entry, 1, entry); #else // !CONFIG_KERN_PREEMPT /* Initialize process stack frame */ @@ -248,7 +245,7 @@ void proc_rename(struct Process *proc, const char *name) */ void proc_exit(void) { - TRACE; + TRACEMSG("%p:%s", CurrentProcess, CurrentProcess->monitor.name); #if CONFIG_KERN_MONITOR monitor_remove(CurrentProcess); diff --git a/bertos/kern/proc_p.h b/bertos/kern/proc_p.h index a98f9428..fbac38fc 100644 --- a/bertos/kern/proc_p.h +++ b/bertos/kern/proc_p.h @@ -122,6 +122,11 @@ extern REGISTER List ProcReadyList; /** Schedule to another process *without* adding the current to the ready list. */ void proc_schedule(void); +#if CONFIG_KERN_PREEMPT +void proc_entry(void (*user_entry)(void)); +void preempt_init(void); +#endif + #if CONFIG_KERN_MONITOR /** Initialize the monitor */ void monitor_init(void);