Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 219 lines (193 sloc) 6.189 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
29 #include "gdev_sched.h"
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
30 #include "gdev_system.h"
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
31
32 struct gdev_sched_entity *sched_entity_ptr[GDEV_CONTEXT_MAX_COUNT];
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
33 gdev_lock_t global_sched_lock;
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
34
35 /**
36 * initialize the scheduler for the device.
37 */
38 int gdev_init_scheduler(struct gdev_device *gdev)
39 {
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
40 gdev_sched_create_scheduler(gdev);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
41
42 return 0;
43 }
44
45 /**
46 * finalized the scheduler for the device.
47 */
48 void gdev_exit_scheduler(struct gdev_device *gdev)
49 {
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
50 gdev_sched_destroy_scheduler(gdev);
51 }
52
53 /**
54 * create a new scheduling entity.
55 */
56 struct gdev_sched_entity *gdev_sched_entity_create(struct gdev_device *gdev, gdev_ctx_t *ctx)
57 {
58 struct gdev_sched_entity *se;
59
60 if (!(se= MALLOC(sizeof(*se))))
61 return NULL;
62
63 /* set up the scheduling entity. */
64 se->gdev = gdev;
65 se->task = gdev_sched_get_current_task();
66 se->ctx = ctx;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
67 se->prio = gdev_sched_get_static_prio(se->task);
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
68 se->rt_prio = GDEV_PRIO_DEFAULT;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
69 se->launch_instances = 0;
70 se->memcpy_instances = 0;
71 gdev_list_init(&se->list_entry_com, (void*)se);
72 gdev_list_init(&se->list_entry_mem, (void*)se);
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
73 sched_entity_ptr[gdev_ctx_get_cid(ctx)] = se;
74
75 return se;
76 }
77
78 /**
79 * destroy the scheduling entity.
80 */
81 void gdev_sched_entity_destroy(struct gdev_sched_entity *se)
82 {
83 FREE(se);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
84 }
85
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
86 #include "gdev_vsched_credit.c"
87
88 #define GDEV_VSCHED_POLICY_CREDIT
89 #ifdef GDEV_VSCHED_POLICY_CREDIT
90 struct gdev_vsched_policy *gdev_vsched = &gdev_vsched_credit;
91 #endif
92
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
93 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
94 * schedule compute calls.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
95 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
96 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
97 {
ddb9864 gdev: updated (a little) scheduler code
Shinpei Kato authored
98 struct gdev_device *gdev = se->gdev;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
99 struct gdev_sched_entity *p, *tail = NULL;
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
100
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
101 resched:
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
102 /* algorithm-specific virtual device scheduler. */
103 gdev_vsched->schedule(gdev);
104
105 /* local compute scheduler. */
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
106 gdev_lock(&gdev->sched_com_lock);
107 if (gdev->se_com_current && gdev->se_com_current != se) {
108 /* insert the scheduling entity to the priority-ordered list. */
109 gdev_list_for_each (p, &gdev->sched_com_list, list_entry_com) {
110 if (se->prio > p->prio) {
111 gdev_list_add_prev(&se->list_entry_com, &p->list_entry_com);
112 break;
113 }
114 tail = p;
115 }
116 if (gdev_list_empty(&se->list_entry_com)) {
117 if (tail)
118 gdev_list_add_next(&se->list_entry_com, &tail->list_entry_com);
119 else
120 gdev_list_add(&se->list_entry_com, &gdev->sched_com_list);
121 }
122 gdev_unlock(&gdev->sched_com_lock);
123
124 /* now the corresponding task will be suspended until some other tasks
125 will awaken it upon completions of their compute launches. */
126 gdev_sched_sleep();
127
128 goto resched;
129 }
130 else {
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
131 /* now, let's get offloaded to the device! */
132 if (se->launch_instances == 0) {
133 /* record the start time. */
134 gdev_time_stamp(&se->start);
135 }
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
136 se->launch_instances++;
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
137 gdev->se_com_current = se;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
138 gdev_unlock(&gdev->sched_com_lock);
139 }
140 }
141
142 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
143 * schedule the next context of compute.
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
144 * invoked upon the completion of preceding contexts.
145 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
146 void gdev_schedule_compute_post(struct gdev_device *gdev)
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
147 {
148 struct gdev_sched_entity *se, *next;
149
150 gdev_lock(&gdev->sched_com_lock);
151 se = gdev->se_com_current;
152 if (se) {
153 se->launch_instances--;
154 if (se->launch_instances == 0) {
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
155 /* record the end time. */
156 gdev_time_stamp(&se->end);
157 gdev_time_sub(&gdev->credit_com, &se->end, &se->start);
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
158 /* select the next context. */
159 next = gdev_list_container(gdev_list_head(&gdev->sched_com_list));
160 /* remove it from the waiting list. */
161 if (next)
162 gdev_list_del(&next->list_entry_com);
163 /* now this is going to be the current context. */
164 gdev->se_com_current = next;
165 gdev_unlock(&gdev->sched_com_lock);
166 /* wake up the next context! */
167 if (next) {
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
168 /* could be enforced when awakened. */
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
169 gdev_sched_wakeup(next->task);
170 }
171 }
172 else
173 gdev_unlock(&gdev->sched_com_lock);
174 }
175 else
176 gdev_unlock(&gdev->sched_com_lock);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
177 }
178
179 /**
180 * schedule memcpy-copy calls.
181 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
182 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
183 {
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
184 //gdev_schedule_compute(se);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
185 }
186
187 /**
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
188 * schedule the next context of memory copy.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
189 * invoked upon the completion of preceding contexts.
190 */
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
191 void gdev_schedule_memory_post(struct gdev_device *gdev)
192 {
193 //gdev_schedule_compute_post(gdev);
194 }
195
196 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
197 {
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
198 struct gdev_time credit, threshold;
199
200 gdev_time_us(&credit, gdev->period * gdev->com_bw / 100);
201 gdev_time_add(&gdev->credit_com, &gdev->credit_com, &credit);
202 /* when the credit exceeds the threshold, all credits taken away. */
203 gdev_time_us(&threshold, GDEV_CREDIT_INACTIVE_THRESHOLD);
204 if (gdev_time_g(&gdev->credit_com, &threshold))
205 gdev_time_us(&gdev->credit_com, 0);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
206 }
207
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
208 void gdev_replenish_credit_memory(struct gdev_device *gdev)
209 {
210 struct gdev_time credit, threshold;
211
212 gdev_time_us(&credit, gdev->period * gdev->mem_bw / 100);
213 gdev_time_add(&gdev->credit_mem, &gdev->credit_mem, &credit);
214 /* when the credit exceeds the threshold, all credits taken away. */
215 gdev_time_us(&threshold, GDEV_CREDIT_INACTIVE_THRESHOLD);
216 if (gdev_time_g(&gdev->credit_mem, &threshold))
217 gdev_time_us(&gdev->credit_mem, 0);
218 }
Something went wrong with that request. Please try again.