mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #1376 from LudwigOrtmann/sched_fixup
core/sched fixup and optimize
This commit is contained in:
commit
ad64e62de9
@ -93,11 +93,6 @@ extern volatile int sched_num_threads;
|
|||||||
*/
|
*/
|
||||||
extern volatile int sched_active_pid;
|
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
|
* List of runqueues per priority level
|
||||||
*/
|
*/
|
||||||
|
@ -131,13 +131,6 @@ int thread_wakeup(int pid);
|
|||||||
*/
|
*/
|
||||||
int thread_getpid(void);
|
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
|
* @brief Measures the stack usage of a stack
|
||||||
*
|
*
|
||||||
|
44
core/sched.c
44
core/sched.c
@ -17,8 +17,6 @@
|
|||||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
*
|
*
|
||||||
* @}
|
* @}
|
||||||
*
|
|
||||||
* TODO: setup dependency from SCHEDSTATISTICS to MODULE_HWTIMER
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -47,7 +45,6 @@ volatile tcb_t *sched_threads[MAXTHREADS];
|
|||||||
volatile tcb_t *sched_active_thread;
|
volatile tcb_t *sched_active_thread;
|
||||||
|
|
||||||
volatile int sched_active_pid = -1;
|
volatile int sched_active_pid = -1;
|
||||||
volatile int thread_last_pid = -1;
|
|
||||||
|
|
||||||
clist_node_t *sched_runqueues[SCHED_PRIO_LEVELS];
|
clist_node_t *sched_runqueues[SCHED_PRIO_LEVELS];
|
||||||
static uint32_t runqueue_bitcache = 0;
|
static uint32_t runqueue_bitcache = 0;
|
||||||
@ -61,6 +58,10 @@ void sched_run(void)
|
|||||||
{
|
{
|
||||||
sched_context_switch_request = 0;
|
sched_context_switch_request = 0;
|
||||||
|
|
||||||
|
#ifdef SCHEDSTATISTICS
|
||||||
|
unsigned long time = hwtimer_now();
|
||||||
|
#endif
|
||||||
|
|
||||||
tcb_t *my_active_thread = (tcb_t *)sched_active_thread;
|
tcb_t *my_active_thread = (tcb_t *)sched_active_thread;
|
||||||
|
|
||||||
if (my_active_thread) {
|
if (my_active_thread) {
|
||||||
@ -74,15 +75,12 @@ void sched_run(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SCHEDSTATISTICS
|
#ifdef SCHEDSTATISTICS
|
||||||
unsigned long time = hwtimer_now();
|
if (sched_pidlist[my_active_thread->pid].laststart) {
|
||||||
|
sched_pidlist[my_active_thread->pid].runtime_ticks += time - sched_pidlist[my_active_thread->pid].laststart;
|
||||||
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;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG("\nscheduler: previous task: %s\n", (my_active_thread == NULL) ? "none" : my_active_thread->name);
|
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);
|
DEBUG("scheduler: first in queue: %s\n", ((tcb_t *)next.data)->name);
|
||||||
clist_advance(&(sched_runqueues[nextrq]));
|
clist_advance(&(sched_runqueues[nextrq]));
|
||||||
my_active_thread = (tcb_t *)next.data;
|
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
|
#if SCHEDSTATISTICS
|
||||||
sched_pidlist[my_active_thread->pid].laststart = time;
|
sched_pidlist[my_next_pid].laststart = time;
|
||||||
sched_pidlist[my_active_thread->pid].schedules++;
|
sched_pidlist[my_next_pid].schedules++;
|
||||||
if ((sched_cb) && (sched_active_thread != thread_last_pid)) {
|
if ((sched_cb) && (my_next_pid != sched_active_pid)) {
|
||||||
sched_cb(hwtimer_now(), my_active_thread->pid);
|
sched_cb(time, my_next_pid);
|
||||||
thread_last_pid = my_active_thread->pid;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_NSS
|
sched_active_pid = my_next_pid;
|
||||||
if (sched_active_thread && sched_active_thread != thread_last_pid) {
|
|
||||||
thread_last_pid = sched_active_thread;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DEBUG("scheduler: next task: %s\n", my_active_thread->name);
|
DEBUG("scheduler: next task: %s\n", my_active_thread->name);
|
||||||
|
|
||||||
if (my_active_thread != sched_active_thread) {
|
if (my_active_thread != sched_active_thread) {
|
||||||
if (sched_active_thread != NULL) { /* TODO: necessary? */
|
if (sched_active_thread != NULL) {
|
||||||
if (sched_active_thread->status == STATUS_RUNNING) {
|
if (sched_active_thread->status == STATUS_RUNNING) {
|
||||||
sched_active_thread->status = STATUS_PENDING ;
|
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;
|
sched_active_thread = (volatile tcb_t *) my_active_thread;
|
||||||
|
@ -37,12 +37,6 @@ inline int thread_getpid(void)
|
|||||||
return sched_active_thread->pid;
|
return sched_active_thread->pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int thread_getlastpid(void)
|
|
||||||
{
|
|
||||||
extern int thread_last_pid;
|
|
||||||
return thread_last_pid;
|
|
||||||
}
|
|
||||||
|
|
||||||
int thread_getstatus(int pid)
|
int thread_getstatus(int pid)
|
||||||
{
|
{
|
||||||
if (sched_threads[pid] == NULL) {
|
if (sched_threads[pid] == NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user