Mercurial > hg > Game > Cerium
view TaskManager/kernel/schedule/Scheduler.h @ 619:278db3ca751d draft
RenewTask removal
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 15 Nov 2009 02:02:30 +0900 |
parents | 184d6d3f0cd9 |
children | 64e05530e333 |
line wrap: on
line source
#ifndef INCLUDED_SCHEDULER #define INCLUDED_SCHEDULER #include "stdlib.h" #include "base.h" #include "TaskList.h" #include "ListData.h" #include "DmaManager.h" #include "SchedTaskBase.h" #include "SchedTaskList.h" #include "MemList.h" #include "MemHash.h" #include "TaskManagerImpl.h" #define MAX_USER_TASK 32 #define MAX_SYSTEM_TASK 2 #define MAX_TASK_OBJECT MAX_USER_TASK + MAX_SYSTEM_TASK #define MAX_GLOBAL_AREA 32 #define MAX_MAINMEM_AREA 32 class SchedTaskBase; class SchedTask; class SchedTaskList; class TaskManager; typedef int (*TaskObjectRun)(SchedTask* smanager, void* r, void *w); class Scheduler { public: virtual ~Scheduler(); BASE_NEW_DELETE(Scheduler); /* variables */ int id; MemHash *hash; // double buffering TaskListPtr buff_taskList[2]; int buffFlag_taskList; /* GlobalMemoryList */ void* globalList[MAX_GLOBAL_AREA]; /* MainMemory Allocate Command List */ void* mainMemList[MAX_MAINMEM_AREA]; /* Code Area */ MemList *code_segment_pool; // Task Object Table // this is named TaskObjectRun but it is not an object. // It is a pointer to an object creation function // 大きいので、SPEには置かない方が本当は良い... typedef struct { TaskObjectRun run; memaddr location; // location address in a.out memaddr end; uint32 entry_offset; // offset for create(); MemorySegment *segment; void (*load)(Scheduler *,int); void (*wait)(Scheduler *,int); } TaskObject, *TaskObjectPtr; DmaManager* connector; TaskManagerImpl* manager; // Pipeline Stage SchedTaskBase* task1; SchedTaskBase* task2; SchedTaskBase* task3; /* functions */ void init(); void run(); virtual void init_impl() {}; void finish(); TaskListPtr get_curListBuf(); TaskListPtr get_renewListBuf(); void set_backupTaskList(TaskListPtr cur_taskList); void set_backupTaskListIndex(int cur_index); SchedTaskList* get_nextRenewTaskList(); TaskListPtr get_backupTaskList(); int get_backupTaskListIndex(); /* GlobalMemory */ void* global_alloc(int id, int size); void* global_get(int id); void global_set(int id, void *addr); void global_free(int id); MemList* createMemList(int size, int count); virtual void *allocate(int size) { return NULL; }; void free_(void *p) { free(p); } virtual void mainMem_alloc(int id, int size) {}; virtual void mainMem_wait() {}; void *mainMem_get(int id); MemorySegment * get_segment(memaddr addr, MemList *m); MemorySegment * get_segment(memaddr addr, MemList *m, int size); void allocate_code_segment(int size, int count); virtual uint32 get_tag(); void put_segment(MemorySegment *s); void wait_segment(MemorySegment *s); /* DMA Transfer */ void dma_load(void *buf, uint32 addr, uint32 size, uint32 mask); void dma_store(void *buf,uint32 addr, uint32 size, uint32 mask); void dma_wait(uint32 mask); void show_dma_wait() { connector->show_dma_wait(id); }; void show_dma_wait(int id) { connector->show_dma_wait(id); }; void mail_write(uint32 data); uint32 mail_read(); void dma_loadList(ListDataPtr list, void *, uint32 mask); void dma_storeList(ListDataPtr list, void *, uint32 mask); /* manager */ void set_manager(TaskManagerImpl *m) { manager = m; } // user HTaskPtr create_task(int cmd) { return manager->create_task(cmd); } void set_task_depend(HTaskPtr master, HTaskPtr slave) { manager->set_task_depend(master, slave) ; } void spawn_task(HTaskPtr t) { manager->spawn_task(t); } void set_task_cpu(HTaskPtr t, CPU_TYPE cpu) { manager->set_task_cpu(t,cpu); } void* allocate(int size,int align) { return manager->allocate(size,align); } int get_random() { return random(); } Scheduler *get_scheduler() { return this; } }; extern void register_task(int cmd, TaskObjectRun run); extern void register_dynamic_task(int cmd, memaddr start, int size, TaskObjectRun run, int entry_offset); struct tbl { unsigned int vma; unsigned int size; unsigned int file_offset; unsigned int buf; }; #endif #define SchedConstructor(str) \ str() {} \ BASE_NEW_DELETE(str) \ #define SchedDefineTask(str) SchedDefineTask1(str,run) \ #define SchedDefineTask1(str,run) \ static int run(SchedTask *smanager, void *rbuf, void *wbuf); \ extern "C" { \ int runTask_##str(SchedTask *smanager, void *rbuf, void *wbuf) \ { \ return run(smanager, rbuf, wbuf); \ } \ } #define SchedExternTask(str) \ extern "C" { \ extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf) ; \ } #define SchedRegisterTask(cmd, str) \ register_task(cmd, runTask_##str); #define SchedRegister(str) \ register_task(str, runTask_##str); #define SchedDefineDynamicTask(str,segment) \ SchedDefineTask(str) #ifndef NO_OVERLAY #define SchedExternDynamicTask(str,segment) \ extern "C" { \ extern unsigned long long _EAR_; \ extern struct tbl _ovly_table[]; \ extern int runTask_##str(SchedTask *manager, void *rbuf, void *wbuf) ; \ } #else #define SchedExternDynamicTask(str,segment) SchedExternTask(str) #endif #ifndef NO_OVERLAY #define SchedRegisterDynamicTask(cmd, str, segment) \ register_dynamic_task(cmd, _EAR_+_ovly_table[segment].file_offset, \ _ovly_table[segment].size, \ runTask_##str, \ runTask_##str##_offset); #define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment) #else #define SchedRegisterDynamicTask(cmd, str, segment) SchedRegisterTask(cmd, str) #define SchedRegisterDynamic(str, segment) SchedRegisterDynamicTask(str, str, segment) #endif /* end */