Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 14 → Rev 29

/shark/trunk/kernel/modules/posix.c
20,11 → 20,11
 
/**
------------
CVS : $Id: posix.c,v 1.2 2002-10-28 07:55:54 pj Exp $
CVS : $Id: posix.c,v 1.3 2002-11-11 08:32:06 pj Exp $
 
File: $File$
Revision: $Revision: 1.2 $
Last update: $Date: 2002-10-28 07:55:54 $
Revision: $Revision: 1.3 $
Last update: $Date: 2002-11-11 08:32:06 $
------------
 
This file contains the scheduling module compatible with POSIX
66,7 → 66,6
 
/*+ Status used in the level +*/
#define POSIX_READY MODULE_STATUS_BASE
#define POSIX_DELAY MODULE_STATUS_BASE+1
 
/*+ the level redefinition for the Round Robin level +*/
typedef struct {
73,8 → 72,10
level_des l; /*+ the standard level descriptor +*/
 
int nact[MAX_PROC]; /*+ number of pending activations +*/
int priority[MAX_PROC]; /*+ priority of each task +*/
 
QQUEUE *ready; /*+ the ready queue array +*/
IQUEUE *ready; /*+ the ready queue array +*/
 
int slice; /*+ the level's time slice +*/
 
94,30 → 95,10
 
switch (status) {
case POSIX_READY: return "POSIX_Ready";
case POSIX_DELAY: return "POSIX_Delay";
default : return "POSIX_Unknown";
}
}
 
/*+ this function is called when a task finish his delay +*/
static void POSIX_timer_delay(void *par)
{
PID p = (PID) par;
POSIX_level_des *lev;
 
lev = (POSIX_level_des *)level_table[proc_table[p].task_level];
 
proc_table[p].status = POSIX_READY;
qq_insertlast(p,&lev->ready[proc_table[p].priority]);
 
proc_table[p].delay_timer = NIL; /* Paranoia */
 
// kern_printf(" DELAY TIMER %d ", p);
 
event_need_reschedule();
}
 
 
static int POSIX_level_accept_task_model(LEVEL l, TASK_MODEL *m)
{
if (m->pclass == NRT_PCLASS || m->pclass == (NRT_PCLASS | l))
141,9 → 122,9
for (p=0; p<MAX_PROC; p++)
if (proc_table[p].task_level == l && proc_table[p].status != POSIX_READY
&& proc_table[p].status != FREE )
kern_printf("Pid: %d\t Name: %20s Prio: %3ld Status: %s\n",
kern_printf("Pid: %d\t Name: %20s Prio: %3d Status: %s\n",
p,proc_table[p].name,
proc_table[p].priority,
lev->priority[p],
POSIX_status_to_a(proc_table[p].status));
 
}
164,7 → 145,7
prio = lev->maxpriority;
 
for (;;) {
p = qq_queryfirst(&lev->ready[prio]);
p = iq_query_first(&lev->ready[prio]);
if (p == NIL) {
if (prio) {
prio--;
177,8 → 158,8
if ((proc_table[p].control & CONTROL_CAP) &&
(proc_table[p].avail_time <= 0)) {
proc_table[p].avail_time += proc_table[p].wcet;
qq_extract(p,&lev->ready[prio]);
qq_insertlast(p,&lev->ready[prio]);
iq_extract(p,&lev->ready[prio]);
iq_insertlast(p,&lev->ready[prio]);
}
else
return p;
208,7 → 189,7
proc_table[exec_shadow].task_level == l) {
/* We inherit the scheduling properties if the scheduling level
*is* the same */
proc_table[p].priority = proc_table[exec_shadow].priority;
lev->priority[p] = lev->priority[exec_shadow];
proc_table[p].avail_time = proc_table[exec_shadow].avail_time;
proc_table[p].wcet = proc_table[exec_shadow].wcet;
219,7 → 200,7
lev->nact[p] = (lev->nact[exec_shadow] == -1) ? -1 : 0;
}
else {
proc_table[p].priority = nrt->weight;
lev->priority[p] = nrt->weight;
if (nrt->slice) {
proc_table[p].avail_time = nrt->slice;
254,14 → 235,6
return 0; /* if the task p is chosen, it is always eligible */
}
 
#ifdef __TEST1__
extern int testactive;
extern struct timespec s_stime[];
extern TIME s_curr[];
extern TIME s_PID[];
extern int useds;
#endif
 
static void POSIX_task_dispatch(LEVEL l, PID p, int nostop)
{
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]);
269,18 → 242,7
/* the task state is set EXE by the scheduler()
we extract the task from the ready queue
NB: we can't assume that p is the first task in the queue!!! */
qq_extract(p, &lev->ready[proc_table[p].priority]);
 
 
#ifdef __TEST1__
if (testactive)
{
TIMESPEC_ASSIGN(&s_stime[useds],&schedule_time);
s_curr[useds] = proc_table[p].avail_time;
s_PID[useds] = p;
useds++;
}
#endif
iq_extract(p, &lev->ready[lev->priority[p]]);
}
 
static void POSIX_task_epilogue(LEVEL l, PID p)
289,7 → 251,7
 
if (lev->yielding) {
lev->yielding = 0;
qq_insertlast(p,&lev->ready[proc_table[p].priority]);
iq_insertlast(p,&lev->ready[lev->priority[p]]);
}
/* check if the slice is finished and insert the task in the coPOSIXect
qqueue position */
296,10 → 258,10
else if (proc_table[p].control & CONTROL_CAP &&
proc_table[p].avail_time <= 0) {
proc_table[p].avail_time += proc_table[p].wcet;
qq_insertlast(p,&lev->ready[proc_table[p].priority]);
iq_insertlast(p,&lev->ready[lev->priority[p]]);
}
else
qq_insertfirst(p,&lev->ready[proc_table[p].priority]);
iq_insertfirst(p,&lev->ready[lev->priority[p]]);
 
proc_table[p].status = POSIX_READY;
}
320,7 → 282,7
 
/* Insert task in the correct position */
proc_table[p].status = POSIX_READY;
qq_insertlast(p,&lev->ready[proc_table[p].priority]);
iq_insertlast(p,&lev->ready[lev->priority[p]]);
}
 
static void POSIX_task_insert(LEVEL l, PID p)
332,7 → 294,7
 
/* Insert task in the coPOSIXect position */
proc_table[p].status = POSIX_READY;
qq_insertlast(p,&lev->ready[proc_table[p].priority]);
iq_insertlast(p,&lev->ready[lev->priority[p]]);
}
 
static void POSIX_task_extract(LEVEL l, PID p)
355,7 → 317,7
/* continue!!!! */
ll_gettime(TIME_EXACT, &proc_table[p].request_time);
lev->nact[p]--;
qq_insertfirst(p,&lev->ready[proc_table[p].priority]);
iq_insertfirst(p,&lev->ready[lev->priority[p]]);
proc_table[p].status = POSIX_READY;
}
else
370,7 → 332,7
 
/* then, we insert the task in the free queue */
proc_table[p].status = FREE;
q_insert(p,&freedesc);
iq_priority_insert(p,&freedesc);
}
 
static void POSIX_task_sleep(LEVEL l, PID p)
380,23 → 342,8
proc_table[p].status = SLEEP;
}
 
static void POSIX_task_delay(LEVEL l, PID p, TIME usdelay)
{
// POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]);
struct timespec wakeuptime;
 
/* equal to POSIX_task_endcycle */
proc_table[p].status = POSIX_DELAY;
 
/* we need to delete this event if we kill the task while it is sleeping */
ll_gettime(TIME_EXACT,&wakeuptime);
ADDUSEC2TIMESPEC(usdelay,&wakeuptime);
proc_table[p].delay_timer = kern_event_post(&wakeuptime,
POSIX_timer_delay,
(void *)p);
}
 
 
static int POSIX_guest_create(LEVEL l, PID p, TASK_MODEL *m)
{ kern_raise(XINVALID_GUEST,exec_shadow); return 0; }
 
427,12 → 374,7
static void POSIX_guest_sleep(LEVEL l, PID p)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
static void POSIX_guest_delay(LEVEL l, PID p,DWORD tickdelay)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
 
 
 
/* Registration functions */
 
/*+ This init function install the "main" task +*/
518,7 → 460,6
lev->l.task_endcycle = POSIX_task_endcycle;
lev->l.task_end = POSIX_task_end;
lev->l.task_sleep = POSIX_task_sleep;
lev->l.task_delay = POSIX_task_delay;
 
lev->l.guest_create = POSIX_guest_create;
lev->l.guest_detach = POSIX_guest_detach;
530,7 → 471,6
lev->l.guest_endcycle = POSIX_guest_endcycle;
lev->l.guest_end = POSIX_guest_end;
lev->l.guest_sleep = POSIX_guest_sleep;
lev->l.guest_delay = POSIX_guest_delay;
 
/* fill the POSIX descriptor part */
for (i = 0; i < MAX_PROC; i++)
538,10 → 478,10
 
lev->maxpriority = prioritylevels -1;
 
lev->ready = (QQUEUE *)kern_alloc(sizeof(QQUEUE) * prioritylevels);
lev->ready = (IQUEUE *)kern_alloc(sizeof(IQUEUE) * prioritylevels);
 
for (x = 0; x < prioritylevels; x++)
qq_init(&lev->ready[x]);
iq_init(&lev->ready[x], &freedesc, 0);
 
if (slice < POSIX_MINIMUM_SLICE) slice = POSIX_MINIMUM_SLICE;
if (slice > POSIX_MAXIMUM_SLICE) slice = POSIX_MAXIMUM_SLICE;
614,7 → 554,7
else
*policy = NRT_FIFO_POLICY;
 
*priority = proc_table[p].priority;
*priority = ((POSIX_level_des *)(level_table[l]))->priority[p];
 
return 0;
}
644,14 → 584,14
else
return EINVAL;
 
if (proc_table[p].priority != priority) {
if (lev->priority[p] != priority) {
if (proc_table[p].status == POSIX_READY) {
qq_extract(p,&lev->ready[proc_table[p].priority]);
proc_table[p].priority = priority;
qq_insertlast(p,&lev->ready[priority]);
iq_extract(p,&lev->ready[lev->priority[p]]);
lev->priority[p] = priority;
iq_insertlast(p,&lev->ready[priority]);
}
else
proc_table[p].priority = priority;
lev->priority[p] = priority;
}
 
return 0;