annotate TaskManager/kernel/ppe/BufferManager.cc @ 46:f154d9d07a42

*** empty log message ***
author gongo
date Fri, 15 Feb 2008 13:09:43 +0900
parents
children 8266445bdac2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
1 #include <stdio.h>
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
2 #include <stdlib.h>
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
3 #include "TaskInfo.h"
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
4
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
5 BufferManager::BufferManager(int num)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
6 :machineNum(num), activeTaskQueue(NULL), waitTaskQueue(NULL) {}
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
7
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
8 BufferManager::~BufferManager(void) { finish(); }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
9
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
10 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
11 BufferManager::init(void)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
12 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
13 tlistImpl = new TaskListInfo;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
14 tqueueImpl = new TaskQueueInfo;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
15 htaskImpl = new HTaskInfo;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
16
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
17 tlistImpl->init(machineNum*2);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
18 tqueueImpl->init(TASK_MAX_SIZE*4);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
19 htaskImpl->init(TASK_MAX_SIZE*2);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
20
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
21 machineTaskList = new TaskListPtr[machineNum];
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
22
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
23 for (int i = 0; i < machineNum; i++) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
24 machineTaskList[i] = tlistImpl->create();
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
25 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
26 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
27
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
28 TaskQueuePtr
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
29 BufferManager::create_taskQueue(HTaskPtr task)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
30 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
31 return tqueueImpl->create(task);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
32 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
33
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
34 HTaskPtr
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
35 BufferManager::create_task(int cmd, int siz, uint64 in_addr, uint64 out_addr)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
36 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
37 return htaskImpl->create(cmd, siz, in_addr, out_addr);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
38 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
39
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
40 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
41 BufferManager::free_taskQueue(TaskQueuePtr q)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
42 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
43 tqueueImpl->free(q);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
44 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
45
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
46 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
47 BufferManager::free_task(HTaskPtr task)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
48 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
49 htaskImpl->free(task);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
50 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
51
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
52 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
53 BufferManager::append_activeTask(HTaskPtr task)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
54 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
55 TaskQueuePtr q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
56
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
57 q = tqueueImpl->create(task);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
58 activeTaskQueue = tqueueImpl->append(activeTaskQueue, q);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
59 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
60
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
61 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
62 BufferManager::finish(void)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
63 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
64 delete tlistImpl;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
65 delete tqueueImpl;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
66 delete htaskImpl;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
67 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
68
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
69 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
70 BufferManager::append_waitTask(HTaskPtr task)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
71 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
72 TaskQueuePtr q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
73
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
74 q = tqueueImpl->create(task);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
75 waitTaskQueue = tqueueImpl->append(waitTaskQueue, q);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
76 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
77
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
78 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
79 BufferManager::check_task_finish(HTaskPtr task)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
80 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
81 notify_wait_taskQueue(task, task->wait_me);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
82 task->post_func();
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
83
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
84 htaskImpl->free(task);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
85 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
86
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
87 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
88 BufferManager::notify_wait_taskQueue(HTaskPtr depend, TaskQueuePtr list)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
89 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
90 TaskQueuePtr p, d;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
91 HTaskPtr task;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
92
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
93 p = list; // wait task list
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
94
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
95 while (p) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
96 task = p->task;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
97 task->wait_i = remove_taskQueue_eq_task(task->wait_i, depend);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
98 if (task->wait_i == NULL) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
99 d = p;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
100 p = p->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
101 append_activeTask(task);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
102 waitTaskQueue = remove_taskQueue(waitTaskQueue, d);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
103 } else {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
104 p = p->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
105 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
106 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
107 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
108
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
109 TaskQueuePtr
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
110 BufferManager::remove_taskQueue_eq_task(TaskQueuePtr list, HTaskPtr task)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
111 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
112 TaskQueuePtr p = list;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
113 TaskQueuePtr p1;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
114
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
115 if (!p) return p;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
116
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
117 if (p->task == task) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
118 list = list->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
119 tqueueImpl->free(p);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
120 } else {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
121 p1 = p->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
122 while (p1 && p1->task && p1->task != task) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
123 p1 = p1->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
124 p = p->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
125 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
126 if (p1) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
127 p->next = p1->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
128 tqueueImpl->free(p1);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
129 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
130 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
131
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
132 return list;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
133 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
134
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
135 TaskQueuePtr
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
136 BufferManager::remove_taskQueue(TaskQueuePtr list, TaskQueuePtr q)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
137 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
138 TaskQueuePtr p = list;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
139 TaskQueuePtr p1;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
140
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
141 if (!p) return p;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
142
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
143 if (p == q) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
144 list = list->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
145 tqueueImpl->free(p);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
146 } else {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
147 p1 = p->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
148 while (p1 && p1 != q) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
149 p1 = p1->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
150 p = p->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
151 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
152 if (p1) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
153 p->next = p1->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
154 tqueueImpl->free(p1);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
155 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
156 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
157
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
158 return list;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
159 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
160
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
161 TaskListPtr
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
162 BufferManager::get_available_taskList(void)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
163 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
164 TaskListPtr list, q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
165
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
166 list = machineTaskList[0];
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
167
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
168 while (list->next) list = list->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
169
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
170 if (list->length < TASK_MAX_SIZE) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
171 return list;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
172 } else {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
173 q = tlistImpl->create();
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
174 machineTaskList[0] = tlistImpl->append(machineTaskList[0], q);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
175 return q;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
176 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
177 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
178
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
179 void
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
180 BufferManager::clear_taskList(void)
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
181 {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
182 TaskListPtr p, p1;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
183
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
184 machineTaskList[0]->length = 0;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
185
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
186 p = machineTaskList[0]->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
187 while (p) {
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
188 p1 = p;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
189 p = p->next;
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
190 tlistImpl->free(p1);
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
191 }
f154d9d07a42 *** empty log message ***
gongo
parents:
diff changeset
192 }