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