From 9cabdb3043d17977636e0b2d7295b5aa245fa09e Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Sat, 12 Jul 2014 06:49:46 +0200 Subject: [PATCH 1/3] core/sched: clean up - remove stray spaces - remove TODOs: - MODULE_HWTIMER is not a module anymore - checking for NULL is necessary, at least without API changes: `sched_task_exit` sets `sched_active_thread` to `NULL`, then exits, afterwards `cpu_switch_context_exit` calls `sched_run` --- core/sched.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/sched.c b/core/sched.c index bb717d0e38..ac009d7bb7 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 @@ -114,13 +112,13 @@ void sched_run(void) 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; From 147c2853654efff6c544149290f508d2ac8e7d6e Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Mon, 7 Jul 2014 14:48:07 +0200 Subject: [PATCH 2/3] core/sched: fix pid/tcb & refactor SCHEDSTATISTICS pid and tcb_t were compared instead of pid and pid SCHEDSTATISTICS: - reduce hwtimer_now calls - dont use thread_last_pid anymore - increase readability --- core/sched.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/core/sched.c b/core/sched.c index ac009d7bb7..79ef1c1beb 100644 --- a/core/sched.c +++ b/core/sched.c @@ -59,6 +59,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) { @@ -72,15 +76,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); @@ -92,22 +93,23 @@ 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; + if (sched_active_thread && (my_next_pid != thread_last_pid)) { + thread_last_pid = sched_active_pid; } #endif + sched_active_pid = my_next_pid; DEBUG("scheduler: next task: %s\n", my_active_thread->name); From a585eaf752758753ba18f8839830bf55d4dbb66d Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Sat, 12 Jul 2014 06:53:45 +0200 Subject: [PATCH 3/3] core/sched: remove MODULE_NSS helpers (API CHANGE) remove thread_getlastpid and last_pid from the API, it is unused --- core/include/sched.h | 5 ----- core/include/thread.h | 7 ------- core/sched.c | 6 ------ core/thread.c | 6 ------ 4 files changed, 24 deletions(-) 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 79ef1c1beb..3c02b82cce 100644 --- a/core/sched.c +++ b/core/sched.c @@ -45,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; @@ -104,11 +103,6 @@ void sched_run(void) } #endif -#ifdef MODULE_NSS - if (sched_active_thread && (my_next_pid != thread_last_pid)) { - thread_last_pid = sched_active_pid; - } -#endif sched_active_pid = my_next_pid; DEBUG("scheduler: next task: %s\n", my_active_thread->name); 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) {