# HG changeset patch # User kent # Date 1261309613 -32400 # Node ID aef83aed7a072b5e7c5f2634549736a53c781681 # Parent 5b089096921fbdbb905bf7a02109b9c1f27b01ee scheduler test success. diff -r 5b089096921f -r aef83aed7a07 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sun Dec 20 20:46:53 2009 +0900 @@ -0,0 +1,10 @@ +syntax: glob + +*.o +.*.swp +.*.swo +GTAGS +GRTAGS +GSYMS +GPATH + diff -r 5b089096921f -r aef83aed7a07 List.c --- a/List.c Fri Dec 18 21:57:05 2009 +0900 +++ b/List.c Sun Dec 20 20:46:53 2009 +0900 @@ -63,6 +63,19 @@ return t->data; } +void * +_listGetLastData(List *top) +{ + if (!top) return NULL; + return top->prev->data; +} + +void * +_listMoveLasttoFirst(List *top) +{ + if (!top) return NULL; + return top->prev; +} void _listApply(List *top, ApplyFn fn, void *arg) { diff -r 5b089096921f -r aef83aed7a07 TaskManager.cbc --- a/TaskManager.cbc Fri Dec 18 21:57:05 2009 +0900 +++ b/TaskManager.cbc Sun Dec 20 20:46:53 2009 +0900 @@ -67,12 +67,12 @@ /* belows is Interfaces for Users. */ /* it may be replace to code segment. but how? */ -Task *newTask(int task_id) +Task *newTask(TaskTypeID typeid) { static int id=0; // 今は使ってない… 使う? task = allocate(sizeof(Task)); - task->taskclass = taskclasses[task_id]; + task->tasktype = tasktypes[typeid]; task->id = id; task->waiter = NULL; task->waitee = NULL; diff -r 5b089096921f -r aef83aed7a07 TaskManager.h --- a/TaskManager.h Fri Dec 18 21:57:05 2009 +0900 +++ b/TaskManager.h Sun Dec 20 20:46:53 2009 +0900 @@ -4,31 +4,18 @@ #include "List.h" typedef List TaskList; -// inline functionのがいいか - - -typedef __code (*Taskrun)(__code(*)(void*,void*,void*), void*, void*); -typedef __code (*Scheduler)(__code(*)(void*,void*,void*), void*, void*); -//typedef __code (*Scheduler)(Taskrun, void*, void*); -//typedef __code (*Taskrun)(Scheduler, void*, void*); -#define END (NULL) - -enum cpu { - ANY = 0, - MAIN, - SUB, -}; +typedef uint32_t TaskTypeID; /* C++CeriumでのTaskObjectにあたる */ -typedef struct _taskclass { - Taskrun run; +typedef struct _tasktype { + //Taskrun run; char *name; enum cpu cputype; -} TaskClass; +} TaskType; -/* C++CeriumでのHTaskにあたる */ +/* C++CeriumでのHTaskにあたるのかな */ typedef struct _Task { - TaskClass taskclass; + TaskType tasktype; unsigned int id; // is it needed? void *rbuff; @@ -40,7 +27,9 @@ TaskList waitee; // List of tasks keep me waiting :-( } Task; -extern int max_taskclass; /* defined by USERs. */ -extern TaskClass taskclasses[]; /* defined by USERs. */ +/* defined in USERs space. */ +/* but generated by Cerium automatically. */ +extern int max_tasktypes; +extern TaskType taskTypes[]; #endif /* !_TASKMANAGER_H */ diff -r 5b089096921f -r aef83aed7a07 TaskScheduler.cbc --- a/TaskScheduler.cbc Fri Dec 18 21:57:05 2009 +0900 +++ b/TaskScheduler.cbc Sun Dec 20 20:46:53 2009 +0900 @@ -4,6 +4,11 @@ #include "TaskScheduler.h" #include "List.h" +enum { + NOWAIT=0, + WAIT=1, +}; +__code checkNewCode(); typedef List SchedTaskList; #define addSchedTask(a,b) (SchedTaskList*)_listAddFirst((List*)(a),(void*)(b)) @@ -57,10 +62,15 @@ selectCode() { SchedTask *task; - task = _listGetnthData(schedule->runnable, 0); - schedule->running = task; + if (schedule->runnable) { + task = _listGetLastData(schedule->runnable); + schedule->running = task; - goto task->nextcode((void*)schedEntry, task->rbuff, task->wbuff); + goto task->nextcode((void*)schedEntry, task->rbuff, task->wbuff); + } else { + //goto checkNewCode(); + goto checkNewCode(WAIT); + } } __code @@ -76,10 +86,14 @@ schedule->running = NULL; goto exitCode(id); } else { + SchedTaskList list; + /* save the next code segment for the task. */ schedule->running->nextcode = nextcode; schedule->running->rbuff = rbuff; schedule->running->wbuff = wbuff; - goto checkNewCode(); + /* move last task to first to be fair. */ + schedule->runnable = _listMoveLasttoFirst(schedule->runnable); + goto checkNewCode(NOWAIT); } } diff -r 5b089096921f -r aef83aed7a07 test/scheduler/test_sched.cbc --- a/test/scheduler/test_sched.cbc Fri Dec 18 21:57:05 2009 +0900 +++ b/test/scheduler/test_sched.cbc Sun Dec 20 20:46:53 2009 +0900 @@ -7,6 +7,7 @@ #define __DEBUG(f, args...) \ fprintf(stderr, "in %s: "f, __FUNCTION__, ## args) +__code task0(Scheduler scheduler, void *rbuff, void *wbuff); __code task1 (Scheduler scheduler, void *rbuff, void *wbuff); __code task2 (Scheduler scheduler, void *rbuff, void *wbuff); int main (int argc, char **argv); @@ -35,7 +36,11 @@ } } __DEBUG("\n"); - goto task1(scheduler, rbuff, wbuff); + __DEBUG("%p %p\n", rbuff, wbuff); + __DEBUG("%3.2lf %3.2lf %3.2lf\n", in[0],in[1],in[2]); + __DEBUG("%3.2lf %3.2lf %3.2lf\n", out[0],out[1],out[2]); + //goto task1(scheduler, wbuff, rbuff); + goto scheduler(task1, wbuff, rbuff); } __code task1(Scheduler scheduler, void *rbuff, void *wbuff) @@ -45,8 +50,8 @@ double *out = wbuff; double a[NUM][NUM] = { { 1.0, 0.0, 0.0 }, - { 0.0, 1.0, 0.0 }, - { 0.0, 0.0, 1.0 }, + { 0.0, 2.0, 0.0 }, + { 0.0, 0.0, 3.0 }, }; for (i=0; i