Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 195 lines (166 sloc) 6.268 kB
657f7a2 gdev: added "period" in /proc entry
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 static void gdev_vsched_credit_schedule_compute(struct gdev_sched_entity *se)
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
30 {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
31 struct gdev_device *gdev = se->gdev;
32 struct gdev_device *phys = gdev->parent;
33
34 if (!phys)
35 return;
36
37 resched:
38 gdev_lock(&phys->sched_com_lock);
9e10e89 gdev: updated scheduler
Shinpei Kato authored
39
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
40 if (phys->current_com && phys->current_com != gdev) {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
41 /* insert the scheduling entity to its local priority-ordered list. */
42 gdev_lock_nested(&gdev->sched_com_lock);
43 __gdev_enqueue_compute(gdev, se);
44 gdev_unlock_nested(&gdev->sched_com_lock);
45 gdev_unlock(&phys->sched_com_lock);
46
47 /* now the corresponding task will be suspended until some other tasks
48 will awaken it upon completions of their compute launches. */
49 gdev_sched_sleep();
50
51 goto resched;
52 }
53 else {
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
54 phys->current_com = (void *)gdev;
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
55 gdev_unlock(&phys->sched_com_lock);
56 }
57 }
58
59 static struct gdev_device *gdev_vsched_credit_select_next_compute(struct gdev_device *gdev)
60 {
61 struct gdev_device *phys = gdev->parent;
62 struct gdev_device *next;
63
64 if (!phys)
65 return gdev;
66
67 gdev_lock(&phys->sched_com_lock);
68
69 /* if the credit is exhausted, reinsert the device. */
9e10e89 gdev: updated scheduler
Shinpei Kato authored
70 if (gdev_time_lez(&gdev->credit_com)) {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
71 gdev_list_del(&gdev->list_entry_com);
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
72 gdev_list_add_tail(&gdev->list_entry_com, &phys->sched_com_list);
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
73 }
74
75 gdev_list_for_each(next, &phys->sched_com_list, list_entry_com) {
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
76 gdev_lock_nested(&next->sched_com_lock);
77 if (!gdev_list_empty(&next->sched_com_list)) {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
78 gdev_unlock_nested(&next->sched_com_lock);
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
79 goto device_switched;
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
80 }
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
81 gdev_unlock_nested(&next->sched_com_lock);
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
82 }
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
83 next = NULL;
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
84 device_switched:
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
85 phys->current_com = (void*)next; /* could be null */
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
86 gdev_unlock(&phys->sched_com_lock);
87
88 return next;
89 }
90
91 static void gdev_vsched_credit_replenish_compute(struct gdev_device *gdev)
92 {
93 struct gdev_time credit, threshold;
94
95 gdev_time_us(&credit, gdev->period * gdev->com_bw / 100);
96 gdev_time_add(&gdev->credit_com, &gdev->credit_com, &credit);
97 /* when the credit exceeds the threshold, all credits taken away. */
98 gdev_time_us(&threshold, GDEV_CREDIT_INACTIVE_THRESHOLD);
08a0abb gdev: fixed the scheduler
Shinpei Kato authored
99 if (gdev_time_gt(&gdev->credit_com, &threshold))
100 gdev_time_us(&gdev->credit_com, 0);
101 /* when the credit exceeds the threshold in negative, even it. */
102 threshold.neg = 1;
103 if (gdev_time_lt(&gdev->credit_com, &threshold))
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
104 gdev_time_us(&gdev->credit_com, 0);
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
105 }
106
dd4de83 gdev: refactored code
Shinpei Kato authored
107 static void gdev_vsched_credit_schedule_memory(struct gdev_sched_entity *se)
108 {
109 struct gdev_device *gdev = se->gdev;
110 struct gdev_device *phys = gdev->parent;
111
112 if (!phys)
113 return;
114
115 resched:
116 gdev_lock(&phys->sched_mem_lock);
117 if (phys->current_mem && phys->current_mem != gdev) {
118 /* insert the scheduling entity to its local priority-ordered list. */
119 gdev_lock_nested(&gdev->sched_mem_lock);
120 __gdev_enqueue_memory(gdev, se);
121 gdev_unlock_nested(&gdev->sched_mem_lock);
122 gdev_unlock(&phys->sched_mem_lock);
123
124 /* now the corresponding task will be suspended until some other tasks
125 will awaken it upon completions of their memory transfers. */
126 gdev_sched_sleep();
127
128 goto resched;
129 }
130 else {
131 phys->current_mem = (void *)gdev;
132 gdev_unlock(&phys->sched_mem_lock);
133 }
134 }
135
136 static struct gdev_device *gdev_vsched_credit_select_next_memory(struct gdev_device *gdev)
137 {
138 struct gdev_device *phys = gdev->parent;
139 struct gdev_device *next;
140
141 if (!phys)
142 return gdev;
143
144 gdev_lock(&phys->sched_mem_lock);
145
146 /* if the credit is exhausted, reinsert the device. */
9e10e89 gdev: updated scheduler
Shinpei Kato authored
147 if (gdev_time_lez(&gdev->credit_mem)) {
dd4de83 gdev: refactored code
Shinpei Kato authored
148 gdev_list_del(&gdev->list_entry_mem);
149 gdev_list_add_tail(&gdev->list_entry_mem, &phys->sched_mem_list);
150 }
151
152 gdev_list_for_each(next, &phys->sched_mem_list, list_entry_mem) {
153 gdev_lock_nested(&next->sched_mem_lock);
154 if (!gdev_list_empty(&next->sched_mem_list)) {
155 gdev_unlock_nested(&next->sched_mem_lock);
156 goto device_switched;
157 }
158 gdev_unlock_nested(&next->sched_mem_lock);
159 }
160 next = NULL;
161 device_switched:
162 phys->current_mem = (void*)next; /* could be null */
163 gdev_unlock(&phys->sched_mem_lock);
164
165 return next;
166 }
167
168 static void gdev_vsched_credit_replenish_memory(struct gdev_device *gdev)
169 {
170 struct gdev_time credit, threshold;
171
172 gdev_time_us(&credit, gdev->period * gdev->mem_bw / 100);
173 gdev_time_add(&gdev->credit_mem, &gdev->credit_mem, &credit);
174 /* when the credit exceeds the threshold, all credits taken away. */
175 gdev_time_us(&threshold, GDEV_CREDIT_INACTIVE_THRESHOLD);
176 if (gdev_time_gt(&gdev->credit_mem, &threshold))
177 gdev_time_us(&gdev->credit_mem, 0);
178 /* when the credit exceeds the threshold in negative, even it. */
179 threshold.neg = 1;
180 if (gdev_time_lt(&gdev->credit_mem, &threshold))
181 gdev_time_us(&gdev->credit_mem, 0);
182 }
183
162ee89 gdev: added CROD scheduler
Shinpei Kato authored
184 /**
185 * the Xen Credit scheduler implementation.
186 */
187 struct gdev_vsched_policy gdev_vsched_credit = {
010bd64 gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
188 .schedule_compute = gdev_vsched_credit_schedule_compute,
189 .select_next_compute = gdev_vsched_credit_select_next_compute,
190 .replenish_compute = gdev_vsched_credit_replenish_compute,
dd4de83 gdev: refactored code
Shinpei Kato authored
191 .schedule_memory = gdev_vsched_credit_schedule_memory,
192 .select_next_memory = gdev_vsched_credit_select_next_memory,
193 .replenish_memory = gdev_vsched_credit_replenish_memory,
657f7a2 gdev: added "period" in /proc entry
Shinpei Kato authored
194 };
Something went wrong with that request. Please try again.