Merge pull request #725 from kaspar030/optimize_thread_status_usage

core: sched: thread: optimize thread status field usage
dev/timer
René Kijewski 10 years ago
commit 83988b2d03

@ -27,22 +27,24 @@
#include "cib.h"
#include "msg.h"
/* uneven means has to be on runqueue */
#define STATUS_NOT_FOUND (0x0000) /**< invalid status, may be used as
* return value to signal an error
*/
#define STATUS_ON_RUNQUEUE (0x0001) /**< scheduled to run */
#define STATUS_RUNNING (0x0002 + STATUS_ON_RUNQUEUE) /**< currently running */
#define STATUS_PENDING (0x0004 + STATUS_ON_RUNQUEUE) /**< waiting to be scheduled to run */
#define STATUS_STOPPED (0x0008) /**< has terminated */
#define STATUS_SLEEPING (0x0010) /**< sleeping */
#define STATUS_MUTEX_BLOCKED (0x0020) /**< waiting for a locked mutex */
#define STATUS_RECEIVE_BLOCKED (0x0040) /**< waiting for a message */
#define STATUS_SEND_BLOCKED (0x0080) /**< waiting for message to be
* delivered */
#define STATUS_REPLY_BLOCKED (0x0100) /**< waiting for a message response */
#define STATUS_TIMER_WAITING (0x0200) /**< waiting for a timer to fire
* (deprecated) */
/* thread status list */
/* blocked states: */
#define STATUS_STOPPED 0 /**< has terminated */
#define STATUS_SLEEPING 1 /**< sleeping */
#define STATUS_MUTEX_BLOCKED 2 /**< waiting for a locked mutex */
#define STATUS_RECEIVE_BLOCKED 3 /**< waiting for a message */
#define STATUS_SEND_BLOCKED 4 /**< waiting for message to be
* delivered */
#define STATUS_REPLY_BLOCKED 5 /**< waiting for a message response */
#define STATUS_TIMER_WAITING 6 /**< waiting for a timer to fire */
#define STATUS_ON_RUNQUEUE 7 /**< */
/* these have to be on a run queue: */
#define STATUS_RUNNING 7 /**< currently running */
#define STATUS_PENDING 8 /**< waiting to be scheduled to run */
typedef struct tcb_t {
char *sp;

@ -26,6 +26,8 @@
#include "kernel.h"
#include "tcb.h"
#define STATUS_NOT_FOUND (-1)
/** Minimum stack size */
#ifndef MINIMUM_STACK_SIZE
#define MINIMUM_STACK_SIZE (sizeof(tcb_t))
@ -53,7 +55,7 @@ int thread_create(char *stack, int stacksize, char priority, int flags, void (*f
* @brief returns the status of a process.
* @return STATUS_NOT_FOUND if pid is unknown
*/
unsigned int thread_getstatus(int pid);
int thread_getstatus(int pid);
/**
* @brief returns the name of a process.

@ -150,15 +150,15 @@ void sched_register_cb(void (*callback)(uint32_t, uint32_t))
void sched_set_status(tcb_t *process, unsigned int status)
{
if (status & STATUS_ON_RUNQUEUE) {
if (!(process->status & STATUS_ON_RUNQUEUE)) {
if (status >= STATUS_ON_RUNQUEUE) {
if (!(process->status >= STATUS_ON_RUNQUEUE)) {
DEBUG("adding process %s to runqueue %u.\n", process->name, process->priority);
clist_add(&runqueues[process->priority], &(process->rq_entry));
runqueue_bitcache |= 1 << process->priority;
}
}
else {
if (process->status & STATUS_ON_RUNQUEUE) {
if (process->status >= STATUS_ON_RUNQUEUE) {
DEBUG("removing process %s from runqueue %u.\n", process->name, process->priority);
clist_remove(&runqueues[process->priority], &(process->rq_entry));

@ -43,7 +43,7 @@ int thread_getlastpid()
return last_pid;
}
unsigned int thread_getstatus(int pid)
int thread_getstatus(int pid)
{
if (sched_threads[pid] == NULL) {
return STATUS_NOT_FOUND;

@ -20,17 +20,18 @@
#include "thread.h"
#include "hwtimer.h"
#include "sched.h"
#include "tcb.h"
/* list of states copied from tcb.h */
const char *state_names[] = {
"running",
"pending",
"stopped",
"sleeping",
"bl mutex",
"bl rx",
"bl send",
"bl reply"
[STATUS_RUNNING] = "running",
[STATUS_PENDING] = "pending",
[STATUS_STOPPED] = "stopped",
[STATUS_SLEEPING] = "sleeping",
[STATUS_MUTEX_BLOCKED] = "bl mutex",
[STATUS_RECEIVE_BLOCKED] = "bl rx",
[STATUS_SEND_BLOCKED] = "bl send",
[STATUS_REPLY_BLOCKED] = "bl reply"
};
/**
@ -49,11 +50,10 @@ void thread_print_all(void)
tcb_t *p = (tcb_t *)sched_threads[i];
if (p != NULL) {
int state = p->status; // copy state
int statebit = number_of_highest_bit(state >> 1); // get state index
const char *sname = state_names[statebit]; // get state name
const char *queued = queued_name + (state & BIT0); // get queued flag
int stacksz = p->stack_size; // get stack size
int state = p->status; // copy state
const char *sname = state_names[state]; // get state name
const char *queued = &queued_name[(int)(state >= STATUS_ON_RUNQUEUE)]; // get queued flag
int stacksz = p->stack_size; // get stack size
double runtime_ticks = 0 / 0.0;
int switches = -1;
#if SCHEDSTATISTICS

Loading…
Cancel
Save