annotate Scheduler/scheduler.c @ 33:3946f8d26710 draft default tip

add benchmarck/binary-trees
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 09 Apr 2013 16:41:30 +0900
parents e3b6e2eef223
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdlib.h>
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
3 #include "types.h"
28
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
5 #define MAX_USER_TASK 100
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
6 #define MAX_SYSTEM_TASK 2
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
7 #define MAX_TASK_OBJECT MAX_USER_TASK + MAX_SYSTEM_TASK
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
8 #define DEFAULT_ALIGNMENT 16
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
9 #define MAX_GLOBAL_AREA 32
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
10 #define MAX_MAINMEM_AREA 32
28
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
13 typedef int (*task_object_run)();
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
14 typedef struct task_object task_object;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
15 typedef struct main_scheduler main_scheduler;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
16 typedef struct task_manager_impl task_manager_impl;
28
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 typedef struct task_manager task_manager;
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
18
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
19 struct task_object
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
20 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
21 memaddr location;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
22 memaddr end;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
23 uint32 entry_offset;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
24
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
25 task_object_run run;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
26 void (*load)();
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
27 void (*wait)();
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
28 };
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
29
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
30 task_object task_list[MAX_TASK_OBJECT];
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
32 struct main_scheduler
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
33 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
34 int id;
32
e3b6e2eef223 hg move scheduler.cbc to scheduler.c
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
35 task_manager_impl *m_impl;
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
36 main_scheduler *scheduler;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
37 void* global_list[MAX_GLOBAL_AREA];
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
38 memaddr main_mem_list[MAX_MAINMEM_AREA];
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
39
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
40 void (*init)(); // init_scheduler function.
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
41 void (*set_manager)(); // set_manager function.
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
42 void (*init_impl)(); // Reference to Scheduler::init_impl method.
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
43 void (*main_mem_alloc)();
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
44 void (*mail_write_from_host)();
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
45 void (*mail_read_from_host)();
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
46 void (*has_mail_from_host)();
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
47 };
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
48
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
49 /* task_manager_impl is FifoTaskManagerImpl now. */
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
50 struct task_manager_impl
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
51 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
52 main_scheduler *scheduler;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
53 int machine_num;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
54 void (*init)();
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
55 void* (*create_task)();
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
56 void* (*allocate)();
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
57 };
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
58
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
59 struct task_manager
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
60 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
61 int machine_num;
28
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 void (*init)();
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
63 task_manager_impl *m_impl;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
64 void (*allocate)();
28
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 };
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
67 int null_run()
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
68 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
69 printf("null_run\n");
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
70 return 0;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
71 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
72
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
73 void null_load()
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
74 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
75 printf("null_load\n");
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
76 return;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
77 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
78 void init_scheduler(task_manager_impl *m)
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
79 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
80 main_scheduler *scheduler = m->scheduler;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
81
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
82 int i = 0;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
83 for (i=0; i<MAX_TASK_OBJECT; i++)
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
84 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
85 task_list[i].run = null_run;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
86 task_list[i].load = null_load;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
87 task_list[i].wait = null_load;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
88 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
89
33
3946f8d26710 add benchmarck/binary-trees
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
90 scheduler->set_manager(m,scheduler);
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
91
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
92 for (i=0; i<MAX_GLOBAL_AREA; i++) {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
93 scheduler->global_list[i] = NULL;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
94 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
95
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
96 for (i=0; i<MAX_MAINMEM_AREA; i++) {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
97 scheduler->main_mem_list[i] = (memaddr)NULL;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
98 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
99
33
3946f8d26710 add benchmarck/binary-trees
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
100
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
101 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
102
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
103 void set_manager(task_manager_impl *impl, main_scheduler *scheduler)
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
104 {
32
e3b6e2eef223 hg move scheduler.cbc to scheduler.c
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
105 scheduler->m_impl = impl;
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
106 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
107
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
108 main_scheduler *create_main_scheduler()
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
109 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
110 main_scheduler *scheduler = malloc(sizeof(main_scheduler));
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
111 scheduler->init = init_scheduler;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
112 scheduler->set_manager = set_manager;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
113 return scheduler;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
114 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
115
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
116 /* Reference to FifoTaskManagerImpl::init */
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
117 void init_impl(task_manager_impl *m_impl)
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
118 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
119 m_impl->scheduler = create_main_scheduler();
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
120 main_scheduler *scheduler = m_impl->scheduler;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
121 scheduler->init(m_impl);
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
122 scheduler->id = 0;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
123 // m_impl->set_scheduler(main_scheduler);
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
124 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
125
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
126 void* create_task(task_manager *manager)
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
127 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
128
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
129 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
130
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
131 /* Reference to TaskManagerImpl::allocate */
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
132 void* memory_allocate(int size, int alignment)
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
133 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
134 void *buff = 0;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
135 if (size == 0) return 0;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
136 posix_memalign(&buff, DEFAULT_ALIGNMENT, size);
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
137 if (buff == 0)
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
138 printf("Can't allocate memory\n");
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
139 return buff;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
140 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
141
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
142 task_manager_impl* create_impl(int num)
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
143 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
144 task_manager_impl *impl = malloc(sizeof(task_manager_impl));
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
145 #ifdef __CERIUM_PARALLEL__
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
146 if (num == 0) num = 1;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
147 #else
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
148 num = 0;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
149 #endif
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
150 impl->machine_num = num;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
151 impl->init = init_impl;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
152 impl->allocate = memory_allocate;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
153 impl->create_task = create_task;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
154 return impl;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
155 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
156
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
157 void init_task_manager(task_manager *manager)
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
158 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
159 manager->m_impl = create_impl(manager->machine_num);
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
160 task_manager_impl *m_impl = manager->m_impl;
32
e3b6e2eef223 hg move scheduler.cbc to scheduler.c
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 31
diff changeset
161 m_impl->init(m_impl);
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
162 // m_impl->systask_init();
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
163 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
164
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
165 void allocate_task_manager(task_manager *manager, int size)
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
166 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
167 manager->m_impl->allocate(size);
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
168 }
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
169
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
170 task_manager* create_manager(int num)
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
171 {
28
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 task_manager* manager = malloc(sizeof(task_manager));
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
173 manager->machine_num = num;
28
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 manager->init = init_task_manager;
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
175 manager->allocate = allocate_task_manager;
28
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 return manager;
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 }
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
179 void free_manager(task_manager *manager)
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
180 {
28
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 free(manager);
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 }
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
184 int main(int argc, char* argv[])
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
185 {
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
186 int machine_num = 1;
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
187 task_manager *manager = create_manager(machine_num);
28
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 manager->init(manager);
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190
31
babfb86f3770 modified Scheduler/scheduler.cbc
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
191 // free_manager(manager);
28
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 return 0;
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 }
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198
ac2555eeeb17 add Scheduler
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199