Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 177 lines (156 sloc) 4.727 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];
33
34 /**
35 * initialize the scheduler for the device.
36 */
37 int gdev_init_scheduler(struct gdev_device *gdev)
38 {
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
39 gdev_sched_create_scheduler(gdev);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
40
41 return 0;
42 }
43
44 /**
45 * finalized the scheduler for the device.
46 */
47 void gdev_exit_scheduler(struct gdev_device *gdev)
48 {
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
49 gdev_sched_destroy_scheduler(gdev);
50 }
51
52 /**
53 * create a new scheduling entity.
54 */
55 struct gdev_sched_entity *gdev_sched_entity_create(struct gdev_device *gdev, gdev_ctx_t *ctx)
56 {
57 struct gdev_sched_entity *se;
58
59 if (!(se= MALLOC(sizeof(*se))))
60 return NULL;
61
62 /* set up the scheduling entity. */
63 se->gdev = gdev;
64 se->task = gdev_sched_get_current_task();
65 se->ctx = ctx;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
66 se->prio = gdev_sched_get_static_prio(se->task);
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
67 se->rt_prio = GDEV_PRIO_DEFAULT;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
68 se->launch_instances = 0;
69 se->memcpy_instances = 0;
70 gdev_list_init(&se->list_entry_com, (void*)se);
71 gdev_list_init(&se->list_entry_mem, (void*)se);
b96dab7 gdev: refactored code and cleaned up files
Shinpei Kato authored
72 sched_entity_ptr[gdev_ctx_get_cid(ctx)] = se;
73
74 return se;
75 }
76
77 /**
78 * destroy the scheduling entity.
79 */
80 void gdev_sched_entity_destroy(struct gdev_sched_entity *se)
81 {
82 FREE(se);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
83 }
84
85 /**
86 * schedule kernel-launch calls.
87 */
88 void gdev_schedule_launch(struct gdev_sched_entity *se)
89 {
ddb9864 gdev: updated (a little) scheduler code
Shinpei Kato authored
90 struct gdev_device *gdev = se->gdev;
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
91 struct gdev_sched_entity *p, *tail = NULL;
ddb9864 gdev: updated (a little) scheduler code
Shinpei Kato authored
92
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
93 resched:
94 gdev_lock(&gdev->sched_com_lock);
95 if (gdev->se_com_current && gdev->se_com_current != se) {
96 /* insert the scheduling entity to the priority-ordered list. */
97 gdev_list_for_each (p, &gdev->sched_com_list, list_entry_com) {
98 if (se->prio > p->prio) {
99 gdev_list_add_prev(&se->list_entry_com, &p->list_entry_com);
100 break;
101 }
102 tail = p;
103 }
104 if (gdev_list_empty(&se->list_entry_com)) {
105 if (tail)
106 gdev_list_add_next(&se->list_entry_com, &tail->list_entry_com);
107 else
108 gdev_list_add(&se->list_entry_com, &gdev->sched_com_list);
109 }
110 gdev_unlock(&gdev->sched_com_lock);
111
112 /* now the corresponding task will be suspended until some other tasks
113 will awaken it upon completions of their compute launches. */
114 gdev_sched_sleep();
115
116 goto resched;
117 }
118 else {
119 gdev->se_com_current = se;
120 se->launch_instances++;
121 gdev_unlock(&gdev->sched_com_lock);
122
123 printk("ctx %d excute\n", se->ctx->cid);
124 }
125 }
126
127 /**
128 * schedule next contexts for kernel launch.
129 * invoked upon the completion of preceding contexts.
130 */
131 void gdev_schedule_launch_post(struct gdev_device *gdev)
132 {
133 struct gdev_sched_entity *se, *next;
134
135 gdev_lock(&gdev->sched_com_lock);
136 se = gdev->se_com_current;
137 if (se) {
138 se->launch_instances--;
139 if (se->launch_instances == 0) {
140 /* select the next context. */
141 next = gdev_list_container(gdev_list_head(&gdev->sched_com_list));
142 /* remove it from the waiting list. */
143 if (next)
144 gdev_list_del(&next->list_entry_com);
145 /* now this is going to be the current context. */
146 gdev->se_com_current = next;
147 gdev_unlock(&gdev->sched_com_lock);
148 /* wake up the next context! */
149 if (next) {
150 gdev_sched_wakeup(next->task);
151 }
152 }
153 else
154 gdev_unlock(&gdev->sched_com_lock);
155 }
156 else
157 gdev_unlock(&gdev->sched_com_lock);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
158 }
159
160 /**
161 * schedule memcpy-copy calls.
162 */
163 void gdev_schedule_memcpy(struct gdev_sched_entity *se)
164 {
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
165 //gdev_schedule_launch(se);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
166 }
167
168 /**
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
169 * schedule next contexts for memory copy.
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
170 * invoked upon the completion of preceding contexts.
171 */
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
172 void gdev_schedule_memcpy_post(struct gdev_device *gdev)
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
173 {
5e75425 gdev: added a priority-based scheduler
Shinpei Kato authored
174 //gdev_schedule_launch_post(gdev);
3ddab5e gdev: made QUERY_CHIPSET and QUERY_DEVICE_MEM_SIZE and QUERY_DMA_MEM_…
Shinpei Kato authored
175 }
176
Something went wrong with that request. Please try again.