diff --git a/core/include/sched.h b/core/include/sched.h index ec7904bbd3..e024765cf3 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -93,11 +93,6 @@ extern volatile int sched_num_threads; */ extern volatile int sched_active_pid; -/** - * Process ID of the thread that was active before the current one - */ -extern volatile int last_pid; - /** * List of runqueues per priority level */ diff --git a/core/include/thread.h b/core/include/thread.h index 17bdefb5f7..e4097afc65 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -131,13 +131,6 @@ int thread_wakeup(int pid); */ int thread_getpid(void); -/** - * @brief Returns the process ID of the thread running before the current one - * - * @return obviously you are not a golfer. - */ -int thread_getlastpid(void); - /** * @brief Measures the stack usage of a stack * diff --git a/core/sched.c b/core/sched.c index bb717d0e38..3c02b82cce 100644 --- a/core/sched.c +++ b/core/sched.c @@ -17,8 +17,6 @@ * @author Kaspar Schleiser * * @} - * - * TODO: setup dependency from SCHEDSTATISTICS to MODULE_HWTIMER */ #include @@ -47,7 +45,6 @@ volatile tcb_t *sched_threads[MAXTHREADS]; volatile tcb_t *sched_active_thread; volatile int sched_active_pid = -1; -volatile int thread_last_pid = -1; clist_node_t *sched_runqueues[SCHED_PRIO_LEVELS]; static uint32_t runqueue_bitcache = 0; @@ -61,6 +58,10 @@ void sched_run(void) { sched_context_switch_request = 0; +#ifdef SCHEDSTATISTICS + unsigned long time = hwtimer_now(); +#endif + tcb_t *my_active_thread = (tcb_t *)sched_active_thread; if (my_active_thread) { @@ -74,15 +75,12 @@ void sched_run(void) } #endif - } - #ifdef SCHEDSTATISTICS - unsigned long time = hwtimer_now(); - - if (my_active_thread && (sched_pidlist[my_active_thread->pid].laststart)) { - sched_pidlist[my_active_thread->pid].runtime_ticks += time - sched_pidlist[my_active_thread->pid].laststart; - } + if (sched_pidlist[my_active_thread->pid].laststart) { + sched_pidlist[my_active_thread->pid].runtime_ticks += time - sched_pidlist[my_active_thread->pid].laststart; + } #endif + } DEBUG("\nscheduler: previous task: %s\n", (my_active_thread == NULL) ? "none" : my_active_thread->name); @@ -94,33 +92,29 @@ void sched_run(void) DEBUG("scheduler: first in queue: %s\n", ((tcb_t *)next.data)->name); clist_advance(&(sched_runqueues[nextrq])); my_active_thread = (tcb_t *)next.data; - sched_active_pid = (volatile int) my_active_thread->pid; + + int my_next_pid = my_active_thread->pid; #if SCHEDSTATISTICS - sched_pidlist[my_active_thread->pid].laststart = time; - sched_pidlist[my_active_thread->pid].schedules++; - if ((sched_cb) && (sched_active_thread != thread_last_pid)) { - sched_cb(hwtimer_now(), my_active_thread->pid); - thread_last_pid = my_active_thread->pid; + sched_pidlist[my_next_pid].laststart = time; + sched_pidlist[my_next_pid].schedules++; + if ((sched_cb) && (my_next_pid != sched_active_pid)) { + sched_cb(time, my_next_pid); } #endif -#ifdef MODULE_NSS - if (sched_active_thread && sched_active_thread != thread_last_pid) { - thread_last_pid = sched_active_thread; - } -#endif + sched_active_pid = my_next_pid; DEBUG("scheduler: next task: %s\n", my_active_thread->name); if (my_active_thread != sched_active_thread) { - if (sched_active_thread != NULL) { /* TODO: necessary? */ - if (sched_active_thread->status == STATUS_RUNNING) { - sched_active_thread->status = STATUS_PENDING ; + if (sched_active_thread != NULL) { + if (sched_active_thread->status == STATUS_RUNNING) { + sched_active_thread->status = STATUS_PENDING; } } - sched_set_status((tcb_t *)my_active_thread, STATUS_RUNNING); + sched_set_status((tcb_t *)my_active_thread, STATUS_RUNNING); } sched_active_thread = (volatile tcb_t *) my_active_thread; diff --git a/core/thread.c b/core/thread.c index 0b88cd31b2..fc76188b9f 100644 --- a/core/thread.c +++ b/core/thread.c @@ -37,12 +37,6 @@ inline int thread_getpid(void) return sched_active_thread->pid; } -int thread_getlastpid(void) -{ - extern int thread_last_pid; - return thread_last_pid; -} - int thread_getstatus(int pid) { if (sched_threads[pid] == NULL) {