comparison TaskManager/kernel/ppe/TaskManagerImpl.cc @ 42:aa11038dbdc1

*** empty log message ***
author gongo
date Thu, 14 Feb 2008 18:27:37 +0900
parents 0c9341da4522
children f154d9d07a42
comparison
equal deleted inserted replaced
41:68fb5bfee6b7 42:aa11038dbdc1
1 #include <stdio.h> 1 #include <stdio.h>
2 #include "TaskManagerImpl.h" 2 #include "TaskManagerImpl.h"
3
4 #include "ppe_spe.h"
3 5
4 void 6 void
5 noaction(void) 7 noaction(void)
6 { 8 {
7 } 9 }
8 10
9 TaskManagerImpl::TaskManagerImpl(int num) 11 TaskManagerImpl::TaskManagerImpl(int num)
10 { 12 {
11 machineNum = num; 13 machineNum = num;
14 }
15
16 void
17 TaskManagerImpl::init(void)
18 {
19 mailManager = new MailManager();
20 mailManager->init_pool_mailQueue(20);
21
22 scheduler = new MainScheduler();
23 scheduler->init();
24 scheduler->set_mailManager(mailManager);
12 } 25 }
13 26
14 HTaskPtr 27 HTaskPtr
15 TaskManagerImpl::create_task(int cmd, int size, 28 TaskManagerImpl::create_task(int cmd, int size,
16 unsigned long long in_addr, 29 unsigned long long in_addr,
53 taskInfo->append_activeTask(task); 66 taskInfo->append_activeTask(task);
54 } else { 67 } else {
55 taskInfo->append_waitTask(task); 68 taskInfo->append_waitTask(task);
56 } 69 }
57 } 70 }
71
72 TaskListPtr
73 TaskManagerImpl::set_task(void)
74 {
75 // ここ...直すかな
76 TaskListPtr list;
77 TaskQueuePtr queue;
78 TaskQueuePtr d;
79 HTaskPtr htask;
80 TaskPtr task;
81
82 queue = taskInfo->activeTaskQueue;
83 if (queue == NULL) {
84 return NULL;
85 }
86
87 taskInfo->clear_taskList();
88
89 while (queue) {
90 list = taskInfo->get_available_taskList();
91 htask = queue->task;
92 d = queue;
93 queue = queue->next;
94
95 task = &list->tasks[list->length++];
96 task->command = htask->command;
97 task->in_addr = htask->in_addr;
98 task->out_addr = htask->out_addr;
99 task->in_size = htask->in_size;
100 task->self = htask;
101
102 taskInfo->free_taskQueue(d);
103 }
104
105 taskInfo->activeTaskQueue = NULL;
106
107 return list;
108 }
109
110
111 // ../spe/main.cpp
112 extern MailQueuePtr spe_main(MailManager*, MailQueuePtr);
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
126 list_mail = mailManager->create_mail((unsigned int)list);
127 in_mail_list = append_mailQueue(in_mail_list, list_mail);
128
129 do {
130 sentinel = mailManager->create_mail(MY_SPE_COMMAND_EXIT);
131 in_mail_list = append_mailQueue(in_mail_list, sentinel);
132
133 // 返って来た mail_list には、spe からの mail がある
134 scheduler->send_mailList(in_mail_list);
135 scheduler->run();
136 out_mail_list = scheduler->recv_mailList();
137 in_mail_list = mail_check(out_mail_list);
138 } while (in_mail_list);
139 }
140
141 /**
142 * PPE Scheduler からのメールをチェックする
143 */
144 MailQueuePtr
145 TaskManagerImpl::mail_check(MailQueuePtr mail_list)
146 {
147 MailQueuePtr q = mail_list;
148 MailQueuePtr d;
149 MailQueuePtr ret = NULL;
150 unsigned int data;
151 TaskListPtr next_list;
152
153 while (q) {
154 data = q->data;
155
156 if (data == MY_SPE_STATUS_READY) {
157 #ifdef _PPE_DEBUG
158 printf("[FIFO] finish\n");
159 #endif
160 next_list = set_task();
161 if (next_list != NULL) {
162 d = mailManager->create_mail((unsigned int)next_list);
163 ret = append_mailQueue(ret, d);
164 }
165 } else {
166 #ifdef _PPE_DEBUG
167 printf("[PPE] recv from : 0x%x\n", data);
168 #endif
169 taskInfo->check_task_finish((HTaskPtr)data);
170 }
171
172 d = q;
173 q = q->next;
174
175 mailManager->free_mailQueue(d);
176 }
177
178 return ret;
179 }