Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 195 lines (166 sloc) 6.323 kb
58d228f gdev: added "period" in /proc entry
Shinpei Kato authored
1 /*
fdb72d9 @shinpei0208 fixed license text everywhere
authored
2 * Copyright (C) Shinpei Kato
58d228f gdev: added "period" in /proc entry
Shinpei Kato authored
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
943bcbe @shinpei0208 fixed license text everywhere
authored
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
58d228f gdev: added "period" in /proc entry
Shinpei Kato authored
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
d964e7e 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)
58d228f gdev: added "period" in /proc entry
Shinpei Kato authored
30 {
d964e7e gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
31 struct gdev_device *gdev = se->gdev;
9e8b646 @yukke0826 gdev: Fix and adjust user-space scheduling.
yukke0826 authored
32 struct gdev_device *phys = gdev_phys_get(gdev);
d964e7e gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
33
34 if (!phys)
35 return;
36
37 resched:
38 gdev_lock(&phys->sched_com_lock);
30bc41b gdev: updated scheduler
Shinpei Kato authored
39
9e8b646 @yukke0826 gdev: Fix and adjust user-space scheduling.
yukke0826 authored
40 if (gdev_current_com_get(phys) && gdev_current_com_get(phys) != gdev) {
d964e7e 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 {
9e8b646 @yukke0826 gdev: Fix and adjust user-space scheduling.
yukke0826 authored
54 gdev_current_com_set(phys, (void*)gdev);
d964e7e 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 {
9e8b646 @yukke0826 gdev: Fix and adjust user-space scheduling.
yukke0826 authored
61 struct gdev_device *phys = gdev_phys_get(gdev);
d964e7e gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
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. */
30bc41b gdev: updated scheduler
Shinpei Kato authored
70 if (gdev_time_lez(&gdev->credit_com)) {
d964e7e gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
71 gdev_list_del(&gdev->list_entry_com);
0f65017 gdev: fixed the scheduler
Shinpei Kato authored
72 gdev_list_add_tail(&gdev->list_entry_com, &phys->sched_com_list);
d964e7e 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) {
0f65017 gdev: fixed the scheduler
Shinpei Kato authored
76 gdev_lock_nested(&next->sched_com_lock);
77 if (!gdev_list_empty(&next->sched_com_list)) {
d964e7e gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
78 gdev_unlock_nested(&next->sched_com_lock);
0f65017 gdev: fixed the scheduler
Shinpei Kato authored
79 goto device_switched;
d964e7e gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
80 }
0f65017 gdev: fixed the scheduler
Shinpei Kato authored
81 gdev_unlock_nested(&next->sched_com_lock);
d964e7e gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
82 }
0f65017 gdev: fixed the scheduler
Shinpei Kato authored
83 next = NULL;
d964e7e gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
84 device_switched:
9e8b646 @yukke0826 gdev: Fix and adjust user-space scheduling.
yukke0826 authored
85 gdev_current_com_set(phys, (void*)next); /* could be null */
d964e7e 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);
0f65017 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))
d964e7e gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
104 gdev_time_us(&gdev->credit_com, 0);
58d228f gdev: added "period" in /proc entry
Shinpei Kato authored
105 }
106
5709200 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;
9e8b646 @yukke0826 gdev: Fix and adjust user-space scheduling.
yukke0826 authored
110 struct gdev_device *phys = gdev_phys_get(gdev);
5709200 gdev: refactored code
Shinpei Kato authored
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 {
9e8b646 @yukke0826 gdev: Fix and adjust user-space scheduling.
yukke0826 authored
138 struct gdev_device *phys = gdev_phys_get(gdev);
5709200 gdev: refactored code
Shinpei Kato authored
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. */
30bc41b gdev: updated scheduler
Shinpei Kato authored
147 if (gdev_time_lez(&gdev->credit_mem)) {
5709200 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
2397243 gdev: added CROD scheduler
Shinpei Kato authored
184 /**
185 * the Xen Credit scheduler implementation.
186 */
187 struct gdev_vsched_policy gdev_vsched_credit = {
d964e7e 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,
5709200 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,
58d228f gdev: added "period" in /proc entry
Shinpei Kato authored
194 };
Something went wrong with that request. Please try again.