Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 297 lines (255 sloc) 8.417 kB
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
1 /*
2 * Copyright 2012 Shinpei Kato
3 *
4 * University of California, Santa Cruz
5 * Systems Research Lab.
6 *
7 * All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
18 * Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 */
28
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
29 #include "gdev_device.h"
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
30 #include "gdev_sched.h"
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
31 #include "gdev_system.h"
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
32
33 struct gdev_sched_entity *sched_entity_ptr[GDEV_CONTEXT_MAX_COUNT];
34
35 /**
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
36 * initialize the local scheduler for the device.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
37 */
38 int gdev_init_scheduler(struct gdev_device *gdev)
39 {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
40 struct gdev_device *phys = gdev->parent;
41
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
42 gdev_sched_create_scheduler(gdev);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
43
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
44 if (phys) {
45 gdev_lock(&phys->sched_com_lock);
46 gdev_list_init(&gdev->list_entry_com, (void*)gdev);
47 gdev_list_add(&gdev->list_entry_com, &phys->sched_com_list);
48 gdev_unlock(&phys->sched_com_lock);
49 gdev_replenish_credit_compute(gdev);
50
51 gdev_lock(&phys->sched_mem_lock);
52 gdev_list_init(&gdev->list_entry_mem, (void*)gdev);
53 gdev_list_add(&gdev->list_entry_mem, &phys->sched_mem_list);
54 gdev_unlock(&phys->sched_mem_lock);
55 gdev_replenish_credit_memory(gdev);
56 }
57
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
58 return 0;
59 }
60
61 /**
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
62 * finalized the local scheduler for the device.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
63 */
64 void gdev_exit_scheduler(struct gdev_device *gdev)
65 {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
66 struct gdev_device *phys = gdev->parent;
67
68 if (phys) {
69 gdev_lock(&phys->sched_com_lock);
70 if (!gdev_list_empty(&gdev->list_entry_com))
71 gdev_list_del(&gdev->list_entry_com);
72 gdev_unlock(&phys->sched_com_lock);
73
74 gdev_lock(&phys->sched_mem_lock);
75 if (!gdev_list_empty(&gdev->list_entry_mem))
76 gdev_list_del(&gdev->list_entry_mem);
77 gdev_unlock(&phys->sched_mem_lock);
78 }
79
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
80 gdev_sched_destroy_scheduler(gdev);
81 }
82
83 /**
84 * create a new scheduling entity.
85 */
86 struct gdev_sched_entity *gdev_sched_entity_create(struct gdev_device *gdev, gdev_ctx_t *ctx)
87 {
88 struct gdev_sched_entity *se;
89
90 if (!(se= MALLOC(sizeof(*se))))
91 return NULL;
92
93 /* set up the scheduling entity. */
94 se->gdev = gdev;
95 se->task = gdev_sched_get_current_task();
96 se->ctx = ctx;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
97 se->prio = gdev_sched_get_static_prio(se->task);
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
98 se->rt_prio = GDEV_PRIO_DEFAULT;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
99 se->launch_instances = 0;
100 se->memcpy_instances = 0;
101 gdev_list_init(&se->list_entry_com, (void*)se);
102 gdev_list_init(&se->list_entry_mem, (void*)se);
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
103 gdev_time_us(&se->last_tick_com, 0);
104 gdev_time_us(&se->last_tick_mem, 0);
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
105 sched_entity_ptr[gdev_ctx_get_cid(ctx)] = se;
106
107 return se;
108 }
109
110 /**
111 * destroy the scheduling entity.
112 */
113 void gdev_sched_entity_destroy(struct gdev_sched_entity *se)
114 {
115 FREE(se);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
116 }
117
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
118 /**
119 * insert the scheduling entity to the priority-ordered compute list.
120 * gdev->sched_com_lock must be locked.
121 */
122 static void __gdev_enqueue_compute(struct gdev_device *gdev, struct gdev_sched_entity *se)
123 {
124 struct gdev_sched_entity *p;
125
126 gdev_list_for_each (p, &gdev->sched_com_list, list_entry_com) {
127 if (se->prio > p->prio) {
128 gdev_list_add_prev(&se->list_entry_com, &p->list_entry_com);
129 break;
130 }
131 }
132 if (gdev_list_empty(&se->list_entry_com))
133 gdev_list_add_tail(&se->list_entry_com, &gdev->sched_com_list);
134 }
135
136 /**
137 * delete the scheduling entity from the priority-ordered compute list.
138 * gdev->sched_com_lock must be locked.
139 */
140 static void __gdev_dequeue_compute(struct gdev_sched_entity *se)
141 {
142 gdev_list_del(&se->list_entry_com);
143 }
144
145 /**
146 * scheduling policy files.
147 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
148 #include "gdev_vsched_credit.c"
162ee89 gdev: added CROD scheduler
Shinpei Kato authored
149 #include "gdev_vsched_crod.c"
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
150
a2b5971 gdev: added gdev_global_{lock,unlock}()
Shinpei Kato authored
151 #define GDEV_VSCHED_POLICY_CREDIT
152 //#define GDEV_VSCHED_POLICY_CROD
162ee89 gdev: added CROD scheduler
Shinpei Kato authored
153
154 #if defined(GDEV_VSCHED_POLICY_CREDIT)
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
155 struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_credit;
162ee89 gdev: added CROD scheduler
Shinpei Kato authored
156 #elif defined(GDEV_VSCHED_POLICY_CROD)
157 struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_crod;
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
158 #endif
159
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
160 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
161 * schedule compute calls.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
162 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
163 void gdev_schedule_compute(struct gdev_sched_entity *se)
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
164 {
ddb9864 gdev: updated (a little) scheduler code
Shinpei Kato authored
165 struct gdev_device *gdev = se->gdev;
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
166
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
167 resched:
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
168 /* algorithm-specific virtual device scheduler. */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
169 gdev_vsched->schedule_compute(se);
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
170
171 /* local compute scheduler. */
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
172 gdev_lock(&gdev->sched_com_lock);
a2b5971 gdev: added gdev_global_{lock,unlock}()
Shinpei Kato authored
173 if ((gdev->current_com && gdev->current_com != se) || se->launch_instances >= GDEV_INSTANCES_LIMIT) {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
174 /* enqueue the scheduling entity to the compute queue. */
175 __gdev_enqueue_compute(gdev, se);
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
176 gdev_unlock(&gdev->sched_com_lock);
177
178 /* now the corresponding task will be suspended until some other tasks
179 will awaken it upon completions of their compute launches. */
180 gdev_sched_sleep();
181
182 goto resched;
183 }
184 else {
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
185 /* now, let's get offloaded to the device! */
186 if (se->launch_instances == 0) {
187 /* record the start time. */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
188 gdev_time_stamp(&se->last_tick_com);
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
189 }
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
190 se->launch_instances++;
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
191 gdev->current_com = (void*)se;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
192 gdev_unlock(&gdev->sched_com_lock);
193 }
194 }
195
196 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
197 * schedule the next context of compute.
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
198 * invoked upon the completion of preceding contexts.
199 */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
200 void gdev_select_next_compute(struct gdev_device *gdev)
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
201 {
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
202 struct gdev_sched_entity *se;
203 struct gdev_device *next;
7a89238 gdev: updated virtual device support
Shinpei Kato authored
204 struct gdev_time now, exec;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
205
206 gdev_lock(&gdev->sched_com_lock);
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
207 se = (struct gdev_sched_entity *)gdev->current_com;
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
208 if (!se) {
209 gdev_unlock(&gdev->sched_com_lock);
210 GDEV_PRINT("Invalid scheduling entity on Gdev#%d\n", gdev->id);
211 return;
212 }
213
214 /* record the end time (update on multiple launches too). */
215 gdev_time_stamp(&now);
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
216 /* aquire the execution time. */
7a89238 gdev: updated virtual device support
Shinpei Kato authored
217 gdev_time_sub(&exec, &now, &se->last_tick_com);
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
218
219 se->launch_instances--;
a2b5971 gdev: added gdev_global_{lock,unlock}()
Shinpei Kato authored
220 printk("Gdev#%d instances %d\n", gdev->id, se->launch_instances);
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
221 if (se->launch_instances == 0) {
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
222 /* account for the credit. */
223 gdev_time_sub(&gdev->credit_com, &gdev->credit_com, &exec);
224 /* accumulate the computation time. */
225 gdev->com_time += gdev_time_to_us(&exec);
226
227 /* select the next context to be scheduled.
228 now don't reference the previous entity by se. */
229 se = gdev_list_container(gdev_list_head(&gdev->sched_com_list));
230 /* setting the next entity here prevents lower-priority contexts
231 arriving in gdev_schedule_compute() from being dispatched onto
232 the device. note that se = NULL could happen. */
233 gdev->current_com = (void*)se;
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
234 gdev_unlock(&gdev->sched_com_lock);
235
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
236 printk("gdev%d->credit_com = %s%lu\n", gdev->id,
237 gdev->credit_com.neg ? "-" : "",
238 gdev_time_to_us(&gdev->credit_com));
7a89238 gdev: updated virtual device support
Shinpei Kato authored
239
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
240 /* select the next device to be scheduled. */
241 next = gdev_vsched->select_next_compute(gdev);
242 if (!next)
243 return;
244
245 gdev_lock(&next->sched_com_lock);
246 /* if the virtual device needs to be switched, change the next
247 scheduling entity to be scheduled also needs to be changed. */
248 if (next != gdev)
249 se = gdev_list_container(gdev_list_head(&next->sched_com_list));
250
251 /* now remove the scheduling entity from the waiting list, and wake
252 up the corresponding task. */
253 if (se) {
254 __gdev_dequeue_compute(se);
255 gdev_unlock(&next->sched_com_lock);
256
a2b5971 gdev: added gdev_global_{lock,unlock}()
Shinpei Kato authored
257 while (gdev_sched_wakeup(se->task) < 0) {
258 GDEV_PRINT("Failed to wake up context %d\n", se->ctx->cid);
259 }
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
260 }
261 else
262 gdev_unlock(&next->sched_com_lock);
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
263 }
264 else
265 gdev_unlock(&gdev->sched_com_lock);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
266 }
267
268 /**
269 * schedule memcpy-copy calls.
270 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
271 void gdev_schedule_memory(struct gdev_sched_entity *se)
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
272 {
273 }
274
275 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
276 * schedule the next context of memory copy.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
277 * invoked upon the completion of preceding contexts.
278 */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
279 void gdev_select_next_memory(struct gdev_device *gdev)
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
280 {
281 }
282
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
283 /**
284 * automatically replenish the credit of compute launches.
285 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
286 void gdev_replenish_credit_compute(struct gdev_device *gdev)
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
287 {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
288 gdev_vsched->replenish_compute(gdev);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
289 }
290
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
291 /**
292 * automatically replenish the credit of memory copies.
293 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
294 void gdev_replenish_credit_memory(struct gdev_device *gdev)
295 {
296 }
Something went wrong with that request. Please try again.