Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 268 lines (230 sloc) 7.238 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"
149
150 #define GDEV_VSCHED_POLICY_CREDIT
151 #ifdef GDEV_VSCHED_POLICY_CREDIT
152 struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_credit;
153 #endif
154
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
155 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
156 * schedule compute calls.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
157 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
158 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
159 {
ddb9864 gdev: updated (a little) scheduler code
Shinpei Kato authored
160 struct gdev_device *gdev = se->gdev;
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
161
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
162 resched:
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
163 /* algorithm-specific virtual device scheduler. */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
164 gdev_vsched->schedule_compute(se);
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
165
166 /* local compute scheduler. */
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
167 gdev_lock(&gdev->sched_com_lock);
168 if (gdev->se_com_current && gdev->se_com_current != se) {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
169 /* enqueue the scheduling entity to the compute queue. */
170 __gdev_enqueue_compute(gdev, se);
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
171 gdev_unlock(&gdev->sched_com_lock);
172
173 /* now the corresponding task will be suspended until some other tasks
174 will awaken it upon completions of their compute launches. */
175 gdev_sched_sleep();
176
177 goto resched;
178 }
179 else {
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
180 /* now, let's get offloaded to the device! */
181 if (se->launch_instances == 0) {
182 /* record the start time. */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
183 gdev_time_stamp(&se->last_tick_com);
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
184 }
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
185 se->launch_instances++;
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
186 gdev->se_com_current = se;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
187 gdev_unlock(&gdev->sched_com_lock);
188 }
189 }
190
191 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
192 * schedule the next context of compute.
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
193 * invoked upon the completion of preceding contexts.
194 */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
195 void gdev_select_next_compute(struct gdev_device *gdev)
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
196 {
197 struct gdev_sched_entity *se, *next;
7a89238 gdev: updated virtual device support
Shinpei Kato authored
198 struct gdev_time now, exec;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
199
200 gdev_lock(&gdev->sched_com_lock);
201 se = gdev->se_com_current;
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
202 if (!se) {
203 gdev_unlock(&gdev->sched_com_lock);
204 GDEV_PRINT("Invalid scheduling entity on Gdev#%d\n", gdev->id);
205 return;
206 }
207
208 /* record the end time (update on multiple launches too). */
209 gdev_time_stamp(&now);
7a89238 gdev: updated virtual device support
Shinpei Kato authored
210 /* account for the execution time. */
211 gdev_time_sub(&exec, &now, &se->last_tick_com);
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
212
213 se->launch_instances--;
214 if (se->launch_instances == 0) {
215 /* select the next device to be scheduled. */
216 gdev = gdev_vsched->select_next_compute(gdev);
217
218 /* select the next context to be scheduled. */
219 next = gdev_list_container(gdev_list_head(&gdev->sched_com_list));
220 /* remove it from the waiting list. */
221 if (next)
222 __gdev_dequeue_compute(next);
223 gdev->se_com_current = NULL; /* null clear once. */
224 gdev_unlock(&gdev->sched_com_lock);
225
226 /* wake up the next context! */
227 if (next) {
228 /* could be enforced when awakened. */
229 gdev_sched_wakeup(next->task);
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
230 }
7a89238 gdev: updated virtual device support
Shinpei Kato authored
231
232 /* accumulate the computation time on the device. */
233 gdev->com_time += gdev_time_to_us(&exec);
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
234 }
235 else
236 gdev_unlock(&gdev->sched_com_lock);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
237 }
238
239 /**
240 * schedule memcpy-copy calls.
241 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
242 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
243 {
244 }
245
246 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
247 * schedule the next context of memory copy.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
248 * invoked upon the completion of preceding contexts.
249 */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
250 void gdev_select_next_memory(struct gdev_device *gdev)
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
251 {
252 }
253
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
254 /**
255 * automatically replenish the credit of compute launches.
256 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
257 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
258 {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
259 gdev_vsched->replenish_compute(gdev);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
260 }
261
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
262 /**
263 * automatically replenish the credit of memory copies.
264 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
265 void gdev_replenish_credit_memory(struct gdev_device *gdev)
266 {
267 }
Something went wrong with that request. Please try again.