Mercurial > hg > Members > nobuyasu > CbC
changeset 31:babfb86f3770 draft
modified Scheduler/scheduler.cbc
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 09 Oct 2012 15:55:44 +0900 |
parents | 95c0fc4ce55c |
children | e3b6e2eef223 |
files | Scheduler/Makefile Scheduler/scheduler.cbc |
diffstat | 2 files changed, 174 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/Scheduler/Makefile Mon Oct 08 20:52:08 2012 +0900 +++ b/Scheduler/Makefile Tue Oct 09 15:55:44 2012 +0900 @@ -1,4 +1,5 @@ CC = cbc-gcc-4.6.0 +#CC = gcc #CFLAGS = -O3 CFLAGS = -O0 -g3 PROG = scheduler
--- a/Scheduler/scheduler.cbc Mon Oct 08 20:52:08 2012 +0900 +++ b/Scheduler/scheduler.cbc Tue Oct 09 15:55:44 2012 +0900 @@ -1,41 +1,199 @@ #include <stdio.h> #include <stdlib.h> +#include "types.h" -void init_task_manager() { - printf("function init\n"); -} - - - +#define MAX_USER_TASK 100 +#define MAX_SYSTEM_TASK 2 +#define MAX_TASK_OBJECT MAX_USER_TASK + MAX_SYSTEM_TASK +#define DEFAULT_ALIGNMENT 16 +#define MAX_GLOBAL_AREA 32 +#define MAX_MAINMEM_AREA 32 +typedef int (*task_object_run)(); +typedef struct task_object task_object; +typedef struct main_scheduler main_scheduler; +typedef struct task_manager_impl task_manager_impl; typedef struct task_manager task_manager; -struct task_manager { - int machineNum; + +struct task_object +{ + memaddr location; + memaddr end; + uint32 entry_offset; + + task_object_run run; + void (*load)(); + void (*wait)(); +}; + +task_object task_list[MAX_TASK_OBJECT]; + +struct main_scheduler +{ + int id; + task_manager_impl *manager; + main_scheduler *scheduler; + void* global_list[MAX_GLOBAL_AREA]; + memaddr main_mem_list[MAX_MAINMEM_AREA]; + + void (*init)(); // init_scheduler function. + void (*set_manager)(); // set_manager function. + void (*init_impl)(); // Reference to Scheduler::init_impl method. + void (*main_mem_alloc)(); + void (*mail_write_from_host)(); + void (*mail_read_from_host)(); + void (*has_mail_from_host)(); +}; + +/* task_manager_impl is FifoTaskManagerImpl now. */ +struct task_manager_impl +{ + main_scheduler *scheduler; + int machine_num; + void (*init)(); + void* (*create_task)(); + void* (*allocate)(); +}; + +struct task_manager +{ + int machine_num; void (*init)(); + task_manager_impl *m_impl; + void (*allocate)(); }; -task_manager* create_manager() { +int null_run() +{ + printf("null_run\n"); + return 0; +} + +void null_load() +{ + printf("null_load\n"); + return; +} +void init_scheduler(task_manager_impl *m) +{ + main_scheduler *scheduler = m->scheduler; + + int i = 0; + for (i=0; i<MAX_TASK_OBJECT; i++) + { + task_list[i].run = null_run; + task_list[i].load = null_load; + task_list[i].wait = null_load; + } + + scheduler->set_manager(m); + + for (i=0; i<MAX_GLOBAL_AREA; i++) { + scheduler->global_list[i] = NULL; + } + + for (i=0; i<MAX_MAINMEM_AREA; i++) { + scheduler->main_mem_list[i] = (memaddr)NULL; + } + +} + +void set_manager(task_manager_impl *impl, main_scheduler *scheduler) +{ + scheduler->manager = impl; +} + +main_scheduler *create_main_scheduler() +{ + main_scheduler *scheduler = malloc(sizeof(main_scheduler)); + scheduler->init = init_scheduler; + scheduler->set_manager = set_manager; + return scheduler; +} + +/* Reference to FifoTaskManagerImpl::init */ +void init_impl(task_manager_impl *m_impl) +{ + m_impl->scheduler = create_main_scheduler(); + main_scheduler *scheduler = m_impl->scheduler; + scheduler->init(m_impl); + scheduler->id = 0; +// m_impl->set_scheduler(main_scheduler); + + +} + +void* create_task(task_manager *manager) +{ + +} + +/* Reference to TaskManagerImpl::allocate */ +void* memory_allocate(int size, int alignment) +{ + void *buff = 0; + if (size == 0) return 0; + posix_memalign(&buff, DEFAULT_ALIGNMENT, size); + if (buff == 0) + printf("Can't allocate memory\n"); + return buff; +} + +task_manager_impl* create_impl(int num) +{ + task_manager_impl *impl = malloc(sizeof(task_manager_impl)); +#ifdef __CERIUM_PARALLEL__ + if (num == 0) num = 1; +#else + num = 0; +#endif + impl->machine_num = num; + impl->init = init_impl; + impl->allocate = memory_allocate; + impl->create_task = create_task; + return impl; +} + +void init_task_manager(task_manager *manager) +{ + manager->m_impl = create_impl(manager->machine_num); + task_manager_impl *m_impl = manager->m_impl; + m_impl->init(manager->machine_num); +// m_impl->systask_init(); +} + +void allocate_task_manager(task_manager *manager, int size) +{ + manager->m_impl->allocate(size); +} + +task_manager* create_manager(int num) +{ task_manager* manager = malloc(sizeof(task_manager)); - manager->machineNum = 1; + manager->machine_num = num; manager->init = init_task_manager; + manager->allocate = allocate_task_manager; return manager; } -void free_manager(task_manager *manager) { +void free_manager(task_manager *manager) +{ + free(manager); } -int main(int argc, char* argv[]) { - - task_manager *manager = create_manager(); +int main(int argc, char* argv[]) +{ + int machine_num = 1; + task_manager *manager = create_manager(machine_num); manager->init(manager); - free_manager(manager); +// free_manager(manager); return 0; }