diff options
author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2014-06-14 06:42:30 -0400 |
---|---|---|
committer | Namhoon Kim <namhoonk@cs.unc.edu> | 2014-11-03 21:58:03 -0500 |
commit | a88daa29933e6c2b1b3b4d616450a35137e59723 (patch) | |
tree | 3eff9f6fff8c76725026c7eb70206ceed7fa6420 /include | |
parent | 1d65b6286a0f6c13495eefbb41bd1cac3d420cc3 (diff) |
Add basic generic reservation-based scheduling infrastructure
Diffstat (limited to 'include')
-rw-r--r-- | include/litmus/polling_reservations.h | 37 | ||||
-rw-r--r-- | include/litmus/reservation.h | 189 |
2 files changed, 226 insertions, 0 deletions
diff --git a/include/litmus/polling_reservations.h b/include/litmus/polling_reservations.h new file mode 100644 index 000000000000..9958a92b8aeb --- /dev/null +++ b/include/litmus/polling_reservations.h | |||
@@ -0,0 +1,37 @@ | |||
1 | #ifndef LITMUS_POLLING_RESERVATIONS_H | ||
2 | #define LITMUS_POLLING_RESERVATIONS_H | ||
3 | |||
4 | #include <litmus/reservation.h> | ||
5 | |||
6 | struct polling_reservation { | ||
7 | /* extend basic reservation */ | ||
8 | struct reservation res; | ||
9 | |||
10 | lt_t max_budget; | ||
11 | lt_t period; | ||
12 | lt_t deadline; | ||
13 | lt_t offset; | ||
14 | }; | ||
15 | |||
16 | void polling_reservation_init(struct polling_reservation *pres, int use_edf_prio, | ||
17 | int use_periodic_polling, lt_t budget, lt_t period, lt_t deadline, lt_t offset); | ||
18 | |||
19 | struct lt_interval { | ||
20 | lt_t start; | ||
21 | lt_t end; | ||
22 | }; | ||
23 | |||
24 | struct table_driven_reservation { | ||
25 | /* extend basic reservation */ | ||
26 | struct reservation res; | ||
27 | |||
28 | lt_t major_cycle; | ||
29 | unsigned int next_interval; | ||
30 | unsigned int num_intervals; | ||
31 | struct lt_interval *intervals; | ||
32 | }; | ||
33 | |||
34 | void table_driven_reservation_init(struct table_driven_reservation *tdres, | ||
35 | lt_t major_cycle, struct lt_interval *intervals, unsigned int num_intervals); | ||
36 | |||
37 | #endif | ||
diff --git a/include/litmus/reservation.h b/include/litmus/reservation.h new file mode 100644 index 000000000000..d8d6ce37dc47 --- /dev/null +++ b/include/litmus/reservation.h | |||
@@ -0,0 +1,189 @@ | |||
1 | #ifndef LITMUS_RESERVATION_H | ||
2 | #define LITMUS_RESERVATION_H | ||
3 | |||
4 | #include <linux/list.h> | ||
5 | #include <linux/hrtimer.h> | ||
6 | |||
7 | struct reservation_client; | ||
8 | struct reservation_environment; | ||
9 | struct reservation; | ||
10 | |||
11 | typedef enum { | ||
12 | /* reservation has no clients, is not consuming budget */ | ||
13 | RESERVATION_INACTIVE = 0, | ||
14 | |||
15 | /* reservation has clients, consumes budget when scheduled */ | ||
16 | RESERVATION_ACTIVE, | ||
17 | |||
18 | /* reservation has no clients, but may be consuming budget */ | ||
19 | RESERVATION_ACTIVE_IDLE, | ||
20 | |||
21 | /* Reservation has no budget and waits for | ||
22 | * replenishment. May or may not have clients. */ | ||
23 | RESERVATION_DEPLETED, | ||
24 | } reservation_state_t; | ||
25 | |||
26 | |||
27 | /* ************************************************************************** */ | ||
28 | |||
29 | /* Select which task to dispatch. If NULL is returned, it means there is nothing | ||
30 | * to schedule right now and background work can be scheduled. */ | ||
31 | typedef struct task_struct * (*dispatch_t) ( | ||
32 | struct reservation_client *client | ||
33 | ); | ||
34 | |||
35 | /* Something that can be managed in a reservation and that can yield | ||
36 | * a process for dispatching. */ | ||
37 | struct reservation_client { | ||
38 | struct list_head list; | ||
39 | dispatch_t dispatch; | ||
40 | }; | ||
41 | |||
42 | |||
43 | /* ************************************************************************** */ | ||
44 | |||
45 | /* Called by reservations to request state change. */ | ||
46 | typedef void (*reservation_change_state_t) ( | ||
47 | struct reservation_environment* env, | ||
48 | struct reservation *res, | ||
49 | reservation_state_t new_state | ||
50 | ); | ||
51 | |||
52 | /* The framework within wich reservations operate. */ | ||
53 | struct reservation_environment { | ||
54 | lt_t time_zero; | ||
55 | lt_t current_time; | ||
56 | |||
57 | /* services invoked by reservations */ | ||
58 | reservation_change_state_t change_state; | ||
59 | }; | ||
60 | |||
61 | |||
62 | /* ************************************************************************** */ | ||
63 | |||
64 | /* A new client is added or an existing client resumes. */ | ||
65 | typedef void (*client_arrives_t) ( | ||
66 | struct reservation *reservation, | ||
67 | struct reservation_client *client | ||
68 | ); | ||
69 | |||
70 | /* A client suspends or terminates. */ | ||
71 | typedef void (*client_departs_t) ( | ||
72 | struct reservation *reservation, | ||
73 | struct reservation_client *client, | ||
74 | int did_signal_job_completion | ||
75 | ); | ||
76 | |||
77 | /* A previously requested replenishment has occurred. */ | ||
78 | typedef void (*on_replenishment_timer_t) ( | ||
79 | struct reservation *reservation | ||
80 | ); | ||
81 | |||
82 | /* Update the reservation's budget to reflect execution or idling. */ | ||
83 | typedef void (*drain_budget_t) ( | ||
84 | struct reservation *reservation, | ||
85 | lt_t how_much | ||
86 | ); | ||
87 | |||
88 | /* Select a ready task from one of the clients for scheduling. */ | ||
89 | typedef struct task_struct* (*dispatch_client_t) ( | ||
90 | struct reservation *reservation, | ||
91 | lt_t *time_slice /* May be used to force rescheduling after | ||
92 | some amount of time. 0 => no limit */ | ||
93 | ); | ||
94 | |||
95 | |||
96 | struct reservation_ops { | ||
97 | dispatch_client_t dispatch_client; | ||
98 | |||
99 | client_arrives_t client_arrives; | ||
100 | client_departs_t client_departs; | ||
101 | |||
102 | on_replenishment_timer_t replenish; | ||
103 | drain_budget_t drain_budget; | ||
104 | }; | ||
105 | |||
106 | struct reservation { | ||
107 | /* used to queue in environment */ | ||
108 | struct list_head list; | ||
109 | |||
110 | reservation_state_t state; | ||
111 | unsigned int id; | ||
112 | |||
113 | /* exact meaning defined by impl. */ | ||
114 | lt_t priority; | ||
115 | lt_t cur_budget; | ||
116 | lt_t next_replenishment; | ||
117 | |||
118 | /* interaction with framework */ | ||
119 | struct reservation_environment *env; | ||
120 | struct reservation_ops *ops; | ||
121 | |||
122 | struct list_head clients; | ||
123 | }; | ||
124 | |||
125 | void reservation_init(struct reservation *res); | ||
126 | |||
127 | /* Default implementations */ | ||
128 | |||
129 | /* simply select the first client in the list, set *for_at_most to zero */ | ||
130 | struct task_struct* default_dispatch_client( | ||
131 | struct reservation *res, | ||
132 | lt_t *for_at_most | ||
133 | ); | ||
134 | |||
135 | /* "connector" reservation client to hook up tasks with reservations */ | ||
136 | struct task_client { | ||
137 | struct reservation_client client; | ||
138 | struct reservation* reservation; | ||
139 | struct task_struct *task; | ||
140 | }; | ||
141 | |||
142 | void task_client_init(struct task_client *tc, struct task_struct *task, | ||
143 | struct reservation *reservation); | ||
144 | |||
145 | #define SUP_RESCHEDULE_NOW (0) | ||
146 | #define SUP_NO_SCHEDULER_UPDATE (ULLONG_MAX) | ||
147 | |||
148 | /* A simple uniprocessor (SUP) flat (i.e., non-hierarchical) reservation | ||
149 | * environment. | ||
150 | */ | ||
151 | struct sup_reservation_environment { | ||
152 | struct reservation_environment env; | ||
153 | |||
154 | /* ordered by priority */ | ||
155 | struct list_head active_reservations; | ||
156 | |||
157 | /* ordered by next_replenishment */ | ||
158 | struct list_head depleted_reservations; | ||
159 | |||
160 | /* unordered */ | ||
161 | struct list_head inactive_reservations; | ||
162 | |||
163 | /* - SUP_RESCHEDULE_NOW means call sup_dispatch() now | ||
164 | * - SUP_NO_SCHEDULER_UPDATE means nothing to do | ||
165 | * any other value means program a timer for the given time | ||
166 | */ | ||
167 | lt_t next_scheduler_update; | ||
168 | /* set to true if a call to sup_dispatch() is imminent */ | ||
169 | bool will_schedule; | ||
170 | }; | ||
171 | |||
172 | /* Contract: | ||
173 | * - before calling into sup_ code, or any reservation methods, | ||
174 | * update the time with sup_update_time(); and | ||
175 | * - after calling into sup_ code, or any reservation methods, | ||
176 | * check next_scheduler_update and program timer or trigger | ||
177 | * scheduler invocation accordingly. | ||
178 | */ | ||
179 | |||
180 | void sup_init(struct sup_reservation_environment* sup_env); | ||
181 | void sup_add_new_reservation(struct sup_reservation_environment* sup_env, | ||
182 | struct reservation* new_res); | ||
183 | void sup_update_time(struct sup_reservation_environment* sup_env, lt_t now); | ||
184 | struct task_struct* sup_dispatch(struct sup_reservation_environment* sup_env); | ||
185 | |||
186 | struct reservation* sup_find_by_id(struct sup_reservation_environment* sup_env, | ||
187 | unsigned int id); | ||
188 | |||
189 | #endif | ||