annotate TaskManager/kernel/ppe/BufferManager.cc @ 70:178459e03f5c

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