Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 448 lines (385 sloc) 12.909 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
c42144d gdev: refactored code
Shinpei Kato authored
33 struct gdev_sched_entity *sched_entity_ptr[GDEV_CONTEXT_MAX_COUNT] = {
34 [0 ... GDEV_CONTEXT_MAX_COUNT-1] = NULL
35 };
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
36
37 /**
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
38 * initialize the local scheduler for the device.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
39 */
40 int gdev_init_scheduler(struct gdev_device *gdev)
41 {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
42 struct gdev_device *phys = gdev->parent;
43
04dac51 gdev: minor fixes
Shinpei Kato authored
44 /* create scheduler threads. OS runtime and user-space runtime behave
45 differently on this function call. */
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
46 gdev_sched_create_scheduler(gdev);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
47
04dac51 gdev: minor fixes
Shinpei Kato authored
48 /* set up virtual GPU schedulers, if required. */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
49 if (phys) {
50 gdev_lock(&phys->sched_com_lock);
51 gdev_list_init(&gdev->list_entry_com, (void*)gdev);
52 gdev_list_add(&gdev->list_entry_com, &phys->sched_com_list);
53 gdev_unlock(&phys->sched_com_lock);
54 gdev_replenish_credit_compute(gdev);
55
56 gdev_lock(&phys->sched_mem_lock);
57 gdev_list_init(&gdev->list_entry_mem, (void*)gdev);
58 gdev_list_add(&gdev->list_entry_mem, &phys->sched_mem_list);
59 gdev_unlock(&phys->sched_mem_lock);
60 gdev_replenish_credit_memory(gdev);
61 }
62
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
63 return 0;
64 }
65
66 /**
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
67 * finalized the local scheduler for the device.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
68 */
69 void gdev_exit_scheduler(struct gdev_device *gdev)
70 {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
71 struct gdev_device *phys = gdev->parent;
72
73 if (phys) {
74 gdev_lock(&phys->sched_com_lock);
75 if (!gdev_list_empty(&gdev->list_entry_com))
76 gdev_list_del(&gdev->list_entry_com);
77 gdev_unlock(&phys->sched_com_lock);
78
79 gdev_lock(&phys->sched_mem_lock);
80 if (!gdev_list_empty(&gdev->list_entry_mem))
81 gdev_list_del(&gdev->list_entry_mem);
82 gdev_unlock(&phys->sched_mem_lock);
83 }
84
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
85 gdev_sched_destroy_scheduler(gdev);
86 }
87
88 /**
89 * create a new scheduling entity.
90 */
91 struct gdev_sched_entity *gdev_sched_entity_create(struct gdev_device *gdev, gdev_ctx_t *ctx)
92 {
93 struct gdev_sched_entity *se;
94
95 if (!(se= MALLOC(sizeof(*se))))
96 return NULL;
97
98 /* set up the scheduling entity. */
99 se->gdev = gdev;
100 se->task = gdev_sched_get_current_task();
101 se->ctx = ctx;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
102 se->prio = gdev_sched_get_static_prio(se->task);
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
103 se->rt_prio = GDEV_PRIO_DEFAULT;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
104 se->launch_instances = 0;
105 se->memcpy_instances = 0;
106 gdev_list_init(&se->list_entry_com, (void*)se);
107 gdev_list_init(&se->list_entry_mem, (void*)se);
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
108 gdev_time_us(&se->last_tick_com, 0);
109 gdev_time_us(&se->last_tick_mem, 0);
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
110 sched_entity_ptr[gdev_ctx_get_cid(ctx)] = se;
111
112 return se;
113 }
114
115 /**
116 * destroy the scheduling entity.
117 */
118 void gdev_sched_entity_destroy(struct gdev_sched_entity *se)
119 {
120 FREE(se);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
121 }
122
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
123 /**
124 * insert the scheduling entity to the priority-ordered compute list.
125 * gdev->sched_com_lock must be locked.
126 */
127 static void __gdev_enqueue_compute(struct gdev_device *gdev, struct gdev_sched_entity *se)
128 {
129 struct gdev_sched_entity *p;
130
131 gdev_list_for_each (p, &gdev->sched_com_list, list_entry_com) {
132 if (se->prio > p->prio) {
133 gdev_list_add_prev(&se->list_entry_com, &p->list_entry_com);
134 break;
135 }
136 }
137 if (gdev_list_empty(&se->list_entry_com))
138 gdev_list_add_tail(&se->list_entry_com, &gdev->sched_com_list);
139 }
140
141 /**
142 * delete the scheduling entity from the priority-ordered compute list.
143 * gdev->sched_com_lock must be locked.
144 */
145 static void __gdev_dequeue_compute(struct gdev_sched_entity *se)
146 {
147 gdev_list_del(&se->list_entry_com);
148 }
149
150 /**
dd4de83 gdev: refactored code
Shinpei Kato authored
151 * insert the scheduling entity to the priority-ordered memory list.
152 * gdev->sched_mem_lock must be locked.
153 */
154 static void __gdev_enqueue_memory(struct gdev_device *gdev, struct gdev_sched_entity *se)
155 {
156 struct gdev_sched_entity *p;
157
158 gdev_list_for_each (p, &gdev->sched_mem_list, list_entry_mem) {
159 if (se->prio > p->prio) {
160 gdev_list_add_prev(&se->list_entry_mem, &p->list_entry_mem);
161 break;
162 }
163 }
164 if (gdev_list_empty(&se->list_entry_mem))
165 gdev_list_add_tail(&se->list_entry_mem, &gdev->sched_mem_list);
166 }
167
168 /**
169 * delete the scheduling entity from the priority-ordered memory list.
170 * gdev->sched_mem_lock must be locked.
171 */
172 static void __gdev_dequeue_memory(struct gdev_sched_entity *se)
173 {
174 gdev_list_del(&se->list_entry_mem);
175 }
176
177 /**
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
178 * scheduling policy files.
179 */
9e10e89 gdev: updated scheduler
Shinpei Kato authored
180 #include "gdev_vsched_band.c"
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
181 #include "gdev_vsched_credit.c"
9e10e89 gdev: updated scheduler
Shinpei Kato authored
182 #include "gdev_vsched_fifo.c"
8966edb gdev: added the null virtual device scheduler
Shinpei Kato authored
183 #include "gdev_vsched_null.c"
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
184
9e10e89 gdev: updated scheduler
Shinpei Kato authored
185 #define GDEV_VSCHED_POLICY_BAND
186 //#define GDEV_VSCHED_POLICY_CREDIT
187 //#define GDEV_VSCHED_POLICY_FIFO
8966edb gdev: added the null virtual device scheduler
Shinpei Kato authored
188 //#define GDEV_VSCHED_POLICY_NULL
162ee89 gdev: added CROD scheduler
Shinpei Kato authored
189
9e10e89 gdev: updated scheduler
Shinpei Kato authored
190 #if defined(GDEV_VSCHED_POLICY_BAND)
191 struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_band;
192 #elif defined(GDEV_VSCHED_POLICY_CREDIT)
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
193 struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_credit;
9e10e89 gdev: updated scheduler
Shinpei Kato authored
194 #elif defined(GDEV_VSCHED_POLICY_FIFO)
195 struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_fifo;
8966edb gdev: added the null virtual device scheduler
Shinpei Kato authored
196 #elif defined(GDEV_VSCHED_POLICY_NULL)
197 struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_null;
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
198 #endif
199
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
200 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
201 * schedule compute calls.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
202 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
203 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
204 {
ddb9864 gdev: updated (a little) scheduler code
Shinpei Kato authored
205 struct gdev_device *gdev = se->gdev;
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
206
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
207 resched:
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
208 /* algorithm-specific virtual device scheduler. */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
209 gdev_vsched->schedule_compute(se);
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
210
211 /* local compute scheduler. */
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
212 gdev_lock(&gdev->sched_com_lock);
a2b5971 gdev: added gdev_global_{lock,unlock}()
Shinpei Kato authored
213 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
214 /* enqueue the scheduling entity to the compute queue. */
215 __gdev_enqueue_compute(gdev, se);
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
216 gdev_unlock(&gdev->sched_com_lock);
217
218 /* now the corresponding task will be suspended until some other tasks
219 will awaken it upon completions of their compute launches. */
220 gdev_sched_sleep();
221
222 goto resched;
223 }
224 else {
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
225 /* now, let's get offloaded to the device! */
226 if (se->launch_instances == 0) {
227 /* record the start time. */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
228 gdev_time_stamp(&se->last_tick_com);
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
229 }
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
230 se->launch_instances++;
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
231 gdev->current_com = (void*)se;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
232 gdev_unlock(&gdev->sched_com_lock);
233 }
a67ac73 gdev: fixed global locking mechanim
Shinpei Kato authored
234
04dac51 gdev: minor fixes
Shinpei Kato authored
235 /* this function call will block any new contexts to be created during
236 the busy period on the GPU. */
a67ac73 gdev: fixed global locking mechanim
Shinpei Kato authored
237 gdev_access_start(gdev);
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
238 }
239
240 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
241 * schedule the next context of compute.
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
242 * invoked upon the completion of preceding contexts.
243 */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
244 void gdev_select_next_compute(struct gdev_device *gdev)
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
245 {
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
246 struct gdev_sched_entity *se;
247 struct gdev_device *next;
7a89238 gdev: updated virtual device support
Shinpei Kato authored
248 struct gdev_time now, exec;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
249
04dac51 gdev: minor fixes
Shinpei Kato authored
250 /* now new contexts are allowed to be created as the GPU is idling. */
a67ac73 gdev: fixed global locking mechanim
Shinpei Kato authored
251 gdev_access_end(gdev);
252
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
253 gdev_lock(&gdev->sched_com_lock);
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
254 se = (struct gdev_sched_entity *)gdev->current_com;
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
255 if (!se) {
256 gdev_unlock(&gdev->sched_com_lock);
257 GDEV_PRINT("Invalid scheduling entity on Gdev#%d\n", gdev->id);
258 return;
259 }
260
261 /* record the end time (update on multiple launches too). */
262 gdev_time_stamp(&now);
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
263 /* aquire the execution time. */
7a89238 gdev: updated virtual device support
Shinpei Kato authored
264 gdev_time_sub(&exec, &now, &se->last_tick_com);
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
265
266 se->launch_instances--;
267 if (se->launch_instances == 0) {
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
268 /* account for the credit. */
269 gdev_time_sub(&gdev->credit_com, &gdev->credit_com, &exec);
270 /* accumulate the computation time. */
271 gdev->com_time += gdev_time_to_us(&exec);
272
273 /* select the next context to be scheduled.
274 now don't reference the previous entity by se. */
275 se = gdev_list_container(gdev_list_head(&gdev->sched_com_list));
276 /* setting the next entity here prevents lower-priority contexts
277 arriving in gdev_schedule_compute() from being dispatched onto
278 the device. note that se = NULL could happen. */
279 gdev->current_com = (void*)se;
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
280 gdev_unlock(&gdev->sched_com_lock);
281
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
282 /* select the next device to be scheduled. */
283 next = gdev_vsched->select_next_compute(gdev);
284 if (!next)
285 return;
286
287 gdev_lock(&next->sched_com_lock);
288 /* if the virtual device needs to be switched, change the next
289 scheduling entity to be scheduled also needs to be changed. */
34f54dc commit for debug
Shinpei Kato authored
290 if (next != gdev) {
291 gdev->current_com = NULL;
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
292 se = gdev_list_container(gdev_list_head(&next->sched_com_list));
34f54dc commit for debug
Shinpei Kato authored
293 }
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
294
295 /* now remove the scheduling entity from the waiting list, and wake
296 up the corresponding task. */
297 if (se) {
298 __gdev_dequeue_compute(se);
299 gdev_unlock(&next->sched_com_lock);
300
9e10e89 gdev: updated scheduler
Shinpei Kato authored
301 if (gdev_sched_wakeup(se->task) < 0) {
a2b5971 gdev: added gdev_global_{lock,unlock}()
Shinpei Kato authored
302 GDEV_PRINT("Failed to wake up context %d\n", se->ctx->cid);
a486bdf gdev: improved and fixed the Band scheduler!!!!!
Shinpei Kato authored
303 GDEV_PRINT("Perhaps context %d is already up\n", se->ctx->cid);
a2b5971 gdev: added gdev_global_{lock,unlock}()
Shinpei Kato authored
304 }
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
305 }
306 else
307 gdev_unlock(&next->sched_com_lock);
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
308 }
309 else
310 gdev_unlock(&gdev->sched_com_lock);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
311 }
312
313 /**
dd4de83 gdev: refactored code
Shinpei Kato authored
314 * automatically replenish the credit of compute launches.
315 */
316 void gdev_replenish_credit_compute(struct gdev_device *gdev)
317 {
318 gdev_vsched->replenish_compute(gdev);
319 }
320
321 /**
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
322 * schedule memcpy-copy calls.
323 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
324 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
325 {
dd4de83 gdev: refactored code
Shinpei Kato authored
326 struct gdev_device *gdev = se->gdev;
327
9e10e89 gdev: updated scheduler
Shinpei Kato authored
328 #ifndef GDEV_SCHED_MRQ
329 gdev_schedule_compute(se);
330 return;
331 #endif
332
dd4de83 gdev: refactored code
Shinpei Kato authored
333 resched:
334 /* algorithm-specific virtual device scheduler. */
335 gdev_vsched->schedule_memory(se);
336
337 /* local memory scheduler. */
338 gdev_lock(&gdev->sched_mem_lock);
339 if ((gdev->current_mem && gdev->current_mem != se) || se->memcpy_instances >= GDEV_INSTANCES_LIMIT) {
340 /* enqueue the scheduling entity to the memory queue. */
341 __gdev_enqueue_memory(gdev, se);
342 gdev_unlock(&gdev->sched_mem_lock);
343
344 /* now the corresponding task will be suspended until some other tasks
345 will awaken it upon completions of their memory transfers. */
346 gdev_sched_sleep();
347
348 goto resched;
349 }
350 else {
351 /* now, let's get offloaded to the device! */
352 if (se->memcpy_instances == 0) {
353 /* record the start time. */
354 gdev_time_stamp(&se->last_tick_mem);
355 }
356 se->memcpy_instances++;
357 gdev->current_mem = (void*)se;
358 gdev_unlock(&gdev->sched_mem_lock);
359 }
a67ac73 gdev: fixed global locking mechanim
Shinpei Kato authored
360
361 gdev_access_start(gdev);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
362 }
363
364 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
365 * schedule the next context of memory copy.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
366 * invoked upon the completion of preceding contexts.
367 */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
368 void gdev_select_next_memory(struct gdev_device *gdev)
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
369 {
dd4de83 gdev: refactored code
Shinpei Kato authored
370 struct gdev_sched_entity *se;
371 struct gdev_device *next;
372 struct gdev_time now, exec;
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
373
9e10e89 gdev: updated scheduler
Shinpei Kato authored
374 #ifndef GDEV_SCHED_MRQ
375 gdev_select_next_compute(gdev);
376 return;
377 #endif
378
a67ac73 gdev: fixed global locking mechanim
Shinpei Kato authored
379 gdev_access_end(gdev);
380
dd4de83 gdev: refactored code
Shinpei Kato authored
381 gdev_lock(&gdev->sched_mem_lock);
382 se = (struct gdev_sched_entity *)gdev->current_mem;
383 if (!se) {
384 gdev_unlock(&gdev->sched_mem_lock);
385 GDEV_PRINT("Invalid scheduling entity on Gdev#%d\n", gdev->id);
386 return;
387 }
388
389 /* record the end time (update on multiple launches too). */
390 gdev_time_stamp(&now);
391 /* aquire the execution time. */
392 gdev_time_sub(&exec, &now, &se->last_tick_mem);
393
394 se->memcpy_instances--;
395 if (se->memcpy_instances == 0) {
396 /* account for the credit. */
397 gdev_time_sub(&gdev->credit_mem, &gdev->credit_mem, &exec);
398 /* accumulate the memory transfer time. */
399 gdev->mem_time += gdev_time_to_us(&exec);
400
401 /* select the next context to be scheduled.
402 now don't reference the previous entity by se. */
403 se = gdev_list_container(gdev_list_head(&gdev->sched_mem_list));
404 /* setting the next entity here prevents lower-priority contexts
405 arriving in gdev_schedule_memory() from being dispatched onto
406 the device. note that se = NULL could happen. */
407 gdev->current_mem = (void*)se;
408 gdev_unlock(&gdev->sched_mem_lock);
409
410 /* select the next device to be scheduled. */
411 next = gdev_vsched->select_next_memory(gdev);
412 if (!next)
413 return;
414
415 gdev_lock(&next->sched_mem_lock);
416 /* if the virtual device needs to be switched, change the next
417 scheduling entity to be scheduled also needs to be changed. */
418 if (next != gdev)
419 se = gdev_list_container(gdev_list_head(&next->sched_mem_list));
420
421 /* now remove the scheduling entity from the waiting list, and wake
422 up the corresponding task. */
423 if (se) {
424 __gdev_dequeue_memory(se);
425 gdev_unlock(&next->sched_mem_lock);
426
427 while (gdev_sched_wakeup(se->task) < 0) {
428 GDEV_PRINT("Failed to wake up context %d\n", se->ctx->cid);
429 }
430 }
431 else
432 gdev_unlock(&next->sched_mem_lock);
433 }
434 else
435 gdev_unlock(&gdev->sched_mem_lock);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
436 }
437
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
438 /**
439 * automatically replenish the credit of memory copies.
440 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
441 void gdev_replenish_credit_memory(struct gdev_device *gdev)
442 {
9e10e89 gdev: updated scheduler
Shinpei Kato authored
443 #ifdef GDEV_SCHED_MRQ
dd4de83 gdev: refactored code
Shinpei Kato authored
444 gdev_vsched->replenish_memory(gdev);
9e10e89 gdev: updated scheduler
Shinpei Kato authored
445 #endif
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
446 }
c42144d gdev: refactored code
Shinpei Kato authored
447
Something went wrong with that request. Please try again.