5
|
1 #include <stdio.h>
|
3
|
2 #include "TaskManagerImpl.h"
|
46
|
3 #include "types.h"
|
|
4 #include "error.h"
|
42
|
5
|
3
|
6 void
|
|
7 noaction(void)
|
|
8 {
|
|
9 }
|
|
10
|
46
|
11 TaskManagerImpl::TaskManagerImpl(int num) : machineNum(num) {}
|
3
|
12
|
42
|
13 void
|
|
14 TaskManagerImpl::init(void)
|
|
15 {
|
|
16 mailManager = new MailManager();
|
|
17 mailManager->init_pool_mailQueue(20);
|
|
18
|
|
19 scheduler = new MainScheduler();
|
|
20 scheduler->init();
|
|
21 scheduler->set_mailManager(mailManager);
|
|
22 }
|
|
23
|
3
|
24 HTaskPtr
|
|
25 TaskManagerImpl::create_task(int cmd, int size,
|
|
26 unsigned long long in_addr,
|
|
27 unsigned long long out_addr,
|
|
28 void (*func)(void))
|
|
29 {
|
|
30 HTaskPtr new_task;
|
|
31
|
46
|
32 new_task = taskInfo->create_task(cmd, size, in_addr, out_addr);
|
3
|
33
|
|
34 if (func == NULL) {
|
|
35 new_task->post_func = noaction;
|
|
36 } else {
|
|
37 new_task->post_func = func;
|
|
38 }
|
|
39
|
|
40 return new_task;
|
|
41 }
|
|
42
|
|
43 /**
|
|
44 * task の依存関係を設定
|
|
45 * master task が終わってから、slave task を実行するように
|
|
46 */
|
|
47 void
|
|
48 TaskManagerImpl::set_task_depend(HTaskPtr master, HTaskPtr slave)
|
|
49 {
|
|
50 TaskQueuePtr m, s;
|
|
51
|
46
|
52 m = taskInfo->create_taskQueue(master);
|
|
53 s = taskInfo->create_taskQueue(slave);
|
3
|
54
|
46
|
55 master->wait_me = TaskQueueInfo::append(master->wait_me, s);
|
|
56 slave->wait_i = TaskQueueInfo::append(slave->wait_i, m);
|
3
|
57 }
|
|
58
|
|
59 void
|
18
|
60 TaskManagerImpl::spawn_task(HTaskPtr task)
|
3
|
61 {
|
|
62 if (task->wait_i == NULL) {
|
|
63 taskInfo->append_activeTask(task);
|
|
64 } else {
|
|
65 taskInfo->append_waitTask(task);
|
|
66 }
|
|
67 }
|
42
|
68
|
|
69 TaskListPtr
|
|
70 TaskManagerImpl::set_task(void)
|
|
71 {
|
|
72 // ここ...直すかな
|
|
73 TaskListPtr list;
|
|
74 TaskQueuePtr queue;
|
|
75 TaskQueuePtr d;
|
|
76 HTaskPtr htask;
|
|
77 TaskPtr task;
|
|
78
|
|
79 queue = taskInfo->activeTaskQueue;
|
|
80 if (queue == NULL) {
|
|
81 return NULL;
|
|
82 }
|
|
83
|
|
84 taskInfo->clear_taskList();
|
|
85
|
|
86 while (queue) {
|
|
87 list = taskInfo->get_available_taskList();
|
|
88 htask = queue->task;
|
|
89 d = queue;
|
|
90 queue = queue->next;
|
|
91
|
|
92 task = &list->tasks[list->length++];
|
|
93 task->command = htask->command;
|
|
94 task->in_addr = htask->in_addr;
|
|
95 task->out_addr = htask->out_addr;
|
|
96 task->in_size = htask->in_size;
|
|
97 task->self = htask;
|
|
98
|
|
99 taskInfo->free_taskQueue(d);
|
46
|
100 }
|
42
|
101
|
|
102 taskInfo->activeTaskQueue = NULL;
|
|
103
|
|
104 return list;
|
|
105 }
|
|
106
|
|
107 void
|
|
108 TaskManagerImpl::run(void)
|
|
109 {
|
|
110 TaskListPtr list;
|
|
111 MailQueuePtr list_mail; // task list
|
|
112 MailQueuePtr sentinel; // 番兵
|
|
113 MailQueuePtr in_mail_list = NULL;
|
|
114 MailQueuePtr out_mail_list = NULL;
|
|
115
|
|
116 // 暫定
|
|
117 list = set_task();
|
|
118
|
|
119 list_mail = mailManager->create_mail((unsigned int)list);
|
|
120 in_mail_list = append_mailQueue(in_mail_list, list_mail);
|
|
121
|
|
122 do {
|
|
123 sentinel = mailManager->create_mail(MY_SPE_COMMAND_EXIT);
|
|
124 in_mail_list = append_mailQueue(in_mail_list, sentinel);
|
|
125
|
|
126 scheduler->send_mailList(in_mail_list);
|
|
127 scheduler->run();
|
|
128 out_mail_list = scheduler->recv_mailList();
|
46
|
129
|
|
130 // out_mail_list には、ppe scheduler からの mail がある
|
42
|
131 in_mail_list = mail_check(out_mail_list);
|
|
132 } while (in_mail_list);
|
|
133 }
|
|
134
|
|
135 /**
|
|
136 * PPE Scheduler からのメールをチェックする
|
|
137 */
|
|
138 MailQueuePtr
|
|
139 TaskManagerImpl::mail_check(MailQueuePtr mail_list)
|
|
140 {
|
|
141 MailQueuePtr q = mail_list;
|
|
142 MailQueuePtr d;
|
|
143 MailQueuePtr ret = NULL;
|
|
144 unsigned int data;
|
|
145 TaskListPtr next_list;
|
|
146
|
|
147 while (q) {
|
|
148 data = q->data;
|
|
149
|
|
150 if (data == MY_SPE_STATUS_READY) {
|
46
|
151 __debug_ppe("[FIFO] finish\n");
|
42
|
152 next_list = set_task();
|
|
153 if (next_list != NULL) {
|
|
154 d = mailManager->create_mail((unsigned int)next_list);
|
|
155 ret = append_mailQueue(ret, d);
|
|
156 }
|
|
157 } else {
|
46
|
158 __debug_ppe("[PPE] recv from : 0x%x\n", data);
|
42
|
159 taskInfo->check_task_finish((HTaskPtr)data);
|
|
160 }
|
|
161
|
|
162 d = q;
|
|
163 q = q->next;
|
|
164
|
|
165 mailManager->free_mailQueue(d);
|
|
166 }
|
|
167
|
|
168 return ret;
|
|
169 }
|