Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 444 lines (381 sloc) 12.746 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"
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
183
9e10e89 gdev: updated scheduler
Shinpei Kato authored
184 #define GDEV_VSCHED_POLICY_BAND
185 //#define GDEV_VSCHED_POLICY_CREDIT
186 //#define GDEV_VSCHED_POLICY_FIFO
162ee89 gdev: added CROD scheduler
Shinpei Kato authored
187
9e10e89 gdev: updated scheduler
Shinpei Kato authored
188 #if defined(GDEV_VSCHED_POLICY_BAND)
189 struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_band;
190 #elif defined(GDEV_VSCHED_POLICY_CREDIT)
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
191 struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_credit;
9e10e89 gdev: updated scheduler
Shinpei Kato authored
192 #elif defined(GDEV_VSCHED_POLICY_FIFO)
193 struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_fifo;
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
194 #endif
195
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
196 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
197 * schedule compute calls.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
198 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
199 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
200 {
ddb9864 gdev: updated (a little) scheduler code
Shinpei Kato authored
201 struct gdev_device *gdev = se->gdev;
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
202
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
203 resched:
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
204 /* algorithm-specific virtual device scheduler. */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
205 gdev_vsched->schedule_compute(se);
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
206
207 /* local compute scheduler. */
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
208 gdev_lock(&gdev->sched_com_lock);
a2b5971 gdev: added gdev_global_{lock,unlock}()
Shinpei Kato authored
209 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
210 /* enqueue the scheduling entity to the compute queue. */
211 __gdev_enqueue_compute(gdev, se);
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
212 gdev_unlock(&gdev->sched_com_lock);
213
214 /* now the corresponding task will be suspended until some other tasks
215 will awaken it upon completions of their compute launches. */
216 gdev_sched_sleep();
217
218 goto resched;
219 }
220 else {
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
221 /* now, let's get offloaded to the device! */
222 if (se->launch_instances == 0) {
223 /* record the start time. */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
224 gdev_time_stamp(&se->last_tick_com);
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
225 }
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
226 se->launch_instances++;
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
227 gdev->current_com = (void*)se;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
228 gdev_unlock(&gdev->sched_com_lock);
229 }
a67ac73 gdev: fixed global locking mechanim
Shinpei Kato authored
230
04dac51 gdev: minor fixes
Shinpei Kato authored
231 /* this function call will block any new contexts to be created during
232 the busy period on the GPU. */
a67ac73 gdev: fixed global locking mechanim
Shinpei Kato authored
233 gdev_access_start(gdev);
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
234 }
235
236 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
237 * schedule the next context of compute.
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
238 * invoked upon the completion of preceding contexts.
239 */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
240 void gdev_select_next_compute(struct gdev_device *gdev)
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
241 {
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
242 struct gdev_sched_entity *se;
243 struct gdev_device *next;
7a89238 gdev: updated virtual device support
Shinpei Kato authored
244 struct gdev_time now, exec;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
245
04dac51 gdev: minor fixes
Shinpei Kato authored
246 /* now new contexts are allowed to be created as the GPU is idling. */
a67ac73 gdev: fixed global locking mechanim
Shinpei Kato authored
247 gdev_access_end(gdev);
248
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
249 gdev_lock(&gdev->sched_com_lock);
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
250 se = (struct gdev_sched_entity *)gdev->current_com;
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
251 if (!se) {
252 gdev_unlock(&gdev->sched_com_lock);
253 GDEV_PRINT("Invalid scheduling entity on Gdev#%d\n", gdev->id);
254 return;
255 }
256
257 /* record the end time (update on multiple launches too). */
258 gdev_time_stamp(&now);
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
259 /* aquire the execution time. */
7a89238 gdev: updated virtual device support
Shinpei Kato authored
260 gdev_time_sub(&exec, &now, &se->last_tick_com);
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
261
262 se->launch_instances--;
263 if (se->launch_instances == 0) {
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
264 /* account for the credit. */
265 gdev_time_sub(&gdev->credit_com, &gdev->credit_com, &exec);
266 /* accumulate the computation time. */
267 gdev->com_time += gdev_time_to_us(&exec);
268
269 /* select the next context to be scheduled.
270 now don't reference the previous entity by se. */
271 se = gdev_list_container(gdev_list_head(&gdev->sched_com_list));
272 /* setting the next entity here prevents lower-priority contexts
273 arriving in gdev_schedule_compute() from being dispatched onto
274 the device. note that se = NULL could happen. */
275 gdev->current_com = (void*)se;
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
276 gdev_unlock(&gdev->sched_com_lock);
277
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
278 /* select the next device to be scheduled. */
279 next = gdev_vsched->select_next_compute(gdev);
280 if (!next)
281 return;
282
283 gdev_lock(&next->sched_com_lock);
284 /* if the virtual device needs to be switched, change the next
285 scheduling entity to be scheduled also needs to be changed. */
34f54dc commit for debug
Shinpei Kato authored
286 if (next != gdev) {
287 gdev->current_com = NULL;
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
288 se = gdev_list_container(gdev_list_head(&next->sched_com_list));
34f54dc commit for debug
Shinpei Kato authored
289 }
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
290
291 /* now remove the scheduling entity from the waiting list, and wake
292 up the corresponding task. */
293 if (se) {
294 __gdev_dequeue_compute(se);
295 gdev_unlock(&next->sched_com_lock);
296
9e10e89 gdev: updated scheduler
Shinpei Kato authored
297 if (gdev_sched_wakeup(se->task) < 0) {
a2b5971 gdev: added gdev_global_{lock,unlock}()
Shinpei Kato authored
298 GDEV_PRINT("Failed to wake up context %d\n", se->ctx->cid);
a486bdf gdev: improved and fixed the Band scheduler!!!!!
Shinpei Kato authored
299 GDEV_PRINT("Perhaps context %d is already up\n", se->ctx->cid);
a2b5971 gdev: added gdev_global_{lock,unlock}()
Shinpei Kato authored
300 }
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
301 }
302 else
303 gdev_unlock(&next->sched_com_lock);
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
304 }
305 else
306 gdev_unlock(&gdev->sched_com_lock);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
307 }
308
309 /**
dd4de83 gdev: refactored code
Shinpei Kato authored
310 * automatically replenish the credit of compute launches.
311 */
312 void gdev_replenish_credit_compute(struct gdev_device *gdev)
313 {
314 gdev_vsched->replenish_compute(gdev);
315 }
316
317 /**
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
318 * schedule memcpy-copy calls.
319 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
320 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
321 {
dd4de83 gdev: refactored code
Shinpei Kato authored
322 struct gdev_device *gdev = se->gdev;
323
9e10e89 gdev: updated scheduler
Shinpei Kato authored
324 #ifndef GDEV_SCHED_MRQ
325 gdev_schedule_compute(se);
326 return;
327 #endif
328
dd4de83 gdev: refactored code
Shinpei Kato authored
329 resched:
330 /* algorithm-specific virtual device scheduler. */
331 gdev_vsched->schedule_memory(se);
332
333 /* local memory scheduler. */
334 gdev_lock(&gdev->sched_mem_lock);
335 if ((gdev->current_mem && gdev->current_mem != se) || se->memcpy_instances >= GDEV_INSTANCES_LIMIT) {
336 /* enqueue the scheduling entity to the memory queue. */
337 __gdev_enqueue_memory(gdev, se);
338 gdev_unlock(&gdev->sched_mem_lock);
339
340 /* now the corresponding task will be suspended until some other tasks
341 will awaken it upon completions of their memory transfers. */
342 gdev_sched_sleep();
343
344 goto resched;
345 }
346 else {
347 /* now, let's get offloaded to the device! */
348 if (se->memcpy_instances == 0) {
349 /* record the start time. */
350 gdev_time_stamp(&se->last_tick_mem);
351 }
352 se->memcpy_instances++;
353 gdev->current_mem = (void*)se;
354 gdev_unlock(&gdev->sched_mem_lock);
355 }
a67ac73 gdev: fixed global locking mechanim
Shinpei Kato authored
356
357 gdev_access_start(gdev);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
358 }
359
360 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
361 * schedule the next context of memory copy.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
362 * invoked upon the completion of preceding contexts.
363 */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
364 void gdev_select_next_memory(struct gdev_device *gdev)
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
365 {
dd4de83 gdev: refactored code
Shinpei Kato authored
366 struct gdev_sched_entity *se;
367 struct gdev_device *next;
368 struct gdev_time now, exec;
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
369
9e10e89 gdev: updated scheduler
Shinpei Kato authored
370 #ifndef GDEV_SCHED_MRQ
371 gdev_select_next_compute(gdev);
372 return;
373 #endif
374
a67ac73 gdev: fixed global locking mechanim
Shinpei Kato authored
375 gdev_access_end(gdev);
376
dd4de83 gdev: refactored code
Shinpei Kato authored
377 gdev_lock(&gdev->sched_mem_lock);
378 se = (struct gdev_sched_entity *)gdev->current_mem;
379 if (!se) {
380 gdev_unlock(&gdev->sched_mem_lock);
381 GDEV_PRINT("Invalid scheduling entity on Gdev#%d\n", gdev->id);
382 return;
383 }
384
385 /* record the end time (update on multiple launches too). */
386 gdev_time_stamp(&now);
387 /* aquire the execution time. */
388 gdev_time_sub(&exec, &now, &se->last_tick_mem);
389
390 se->memcpy_instances--;
391 if (se->memcpy_instances == 0) {
392 /* account for the credit. */
393 gdev_time_sub(&gdev->credit_mem, &gdev->credit_mem, &exec);
394 /* accumulate the memory transfer time. */
395 gdev->mem_time += gdev_time_to_us(&exec);
396
397 /* select the next context to be scheduled.
398 now don't reference the previous entity by se. */
399 se = gdev_list_container(gdev_list_head(&gdev->sched_mem_list));
400 /* setting the next entity here prevents lower-priority contexts
401 arriving in gdev_schedule_memory() from being dispatched onto
402 the device. note that se = NULL could happen. */
403 gdev->current_mem = (void*)se;
404 gdev_unlock(&gdev->sched_mem_lock);
405
406 /* select the next device to be scheduled. */
407 next = gdev_vsched->select_next_memory(gdev);
408 if (!next)
409 return;
410
411 gdev_lock(&next->sched_mem_lock);
412 /* if the virtual device needs to be switched, change the next
413 scheduling entity to be scheduled also needs to be changed. */
414 if (next != gdev)
415 se = gdev_list_container(gdev_list_head(&next->sched_mem_list));
416
417 /* now remove the scheduling entity from the waiting list, and wake
418 up the corresponding task. */
419 if (se) {
420 __gdev_dequeue_memory(se);
421 gdev_unlock(&next->sched_mem_lock);
422
423 while (gdev_sched_wakeup(se->task) < 0) {
424 GDEV_PRINT("Failed to wake up context %d\n", se->ctx->cid);
425 }
426 }
427 else
428 gdev_unlock(&next->sched_mem_lock);
429 }
430 else
431 gdev_unlock(&gdev->sched_mem_lock);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
432 }
433
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
434 /**
435 * automatically replenish the credit of memory copies.
436 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
437 void gdev_replenish_credit_memory(struct gdev_device *gdev)
438 {
9e10e89 gdev: updated scheduler
Shinpei Kato authored
439 #ifdef GDEV_SCHED_MRQ
dd4de83 gdev: refactored code
Shinpei Kato authored
440 gdev_vsched->replenish_memory(gdev);
9e10e89 gdev: updated scheduler
Shinpei Kato authored
441 #endif
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
442 }
c42144d gdev: refactored code
Shinpei Kato authored
443
Something went wrong with that request. Please try again.