aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2015-08-09 07:18:46 -0400
committerBjoern Brandenburg <bbb@mpi-sws.org>2015-08-09 06:21:17 -0400
commit013e33ea81d54ce418543a4a29a733504cb7b896 (patch)
tree7456d05aa4f2a2621980cee84fcfd09a65f2331e
parent5014e7011964ff46b2d73cf91a05ed9eed5a8fa2 (diff)
Extend task_struct with rt_param
This patch adds the PCB extensions required for LITMUS^RT.
-rw-r--r--include/linux/sched.h5
-rw-r--r--include/litmus/rt_param.h285
2 files changed, 290 insertions, 0 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 26a2e6122734..067a2383ee68 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -125,6 +125,8 @@ struct sched_attr {
125 u64 sched_period; 125 u64 sched_period;
126}; 126};
127 127
128#include <litmus/rt_param.h>
129
128struct futex_pi_state; 130struct futex_pi_state;
129struct robust_list_head; 131struct robust_list_head;
130struct bio_list; 132struct bio_list;
@@ -1671,6 +1673,9 @@ struct task_struct {
1671 int nr_dirtied_pause; 1673 int nr_dirtied_pause;
1672 unsigned long dirty_paused_when; /* start of a write-and-pause period */ 1674 unsigned long dirty_paused_when; /* start of a write-and-pause period */
1673 1675
1676 /* LITMUS RT parameters and state */
1677 struct rt_param rt_param;
1678
1674#ifdef CONFIG_LATENCYTOP 1679#ifdef CONFIG_LATENCYTOP
1675 int latency_record_count; 1680 int latency_record_count;
1676 struct latency_record latency_record[LT_SAVECOUNT]; 1681 struct latency_record latency_record[LT_SAVECOUNT];
diff --git a/include/litmus/rt_param.h b/include/litmus/rt_param.h
new file mode 100644
index 000000000000..ce76faa9c6d7
--- /dev/null
+++ b/include/litmus/rt_param.h
@@ -0,0 +1,285 @@
1/*
2 * Definition of the scheduler plugin interface.
3 *
4 */
5#ifndef _LINUX_RT_PARAM_H_
6#define _LINUX_RT_PARAM_H_
7
8/* Litmus time type. */
9typedef unsigned long long lt_t;
10
11static inline int lt_after(lt_t a, lt_t b)
12{
13 return ((long long) b) - ((long long) a) < 0;
14}
15#define lt_before(a, b) lt_after(b, a)
16
17static inline int lt_after_eq(lt_t a, lt_t b)
18{
19 return ((long long) a) - ((long long) b) >= 0;
20}
21#define lt_before_eq(a, b) lt_after_eq(b, a)
22
23/* different types of clients */
24typedef enum {
25 RT_CLASS_HARD,
26 RT_CLASS_SOFT,
27 RT_CLASS_BEST_EFFORT
28} task_class_t;
29
30typedef enum {
31 NO_ENFORCEMENT, /* job may overrun unhindered */
32 QUANTUM_ENFORCEMENT, /* budgets are only checked on quantum boundaries */
33 PRECISE_ENFORCEMENT /* budgets are enforced with hrtimers */
34} budget_policy_t;
35
36/* Release behaviors for jobs. PERIODIC and EARLY jobs
37 must end by calling sys_complete_job() (or equivalent)
38 to set up their next release and deadline. */
39typedef enum {
40 /* Jobs are released sporadically (provided job precedence
41 constraints are met). */
42 TASK_SPORADIC,
43
44 /* Jobs are released periodically (provided job precedence
45 constraints are met). */
46 TASK_PERIODIC,
47
48 /* Jobs are released immediately after meeting precedence
49 constraints. Beware this can peg your CPUs if used in
50 the wrong applications. Only supported by EDF schedulers. */
51 TASK_EARLY
52} release_policy_t;
53
54/* We use the common priority interpretation "lower index == higher priority",
55 * which is commonly used in fixed-priority schedulability analysis papers.
56 * So, a numerically lower priority value implies higher scheduling priority,
57 * with priority 1 being the highest priority. Priority 0 is reserved for
58 * priority boosting. LITMUS_MAX_PRIORITY denotes the maximum priority value
59 * range.
60 */
61
62#define LITMUS_MAX_PRIORITY 512
63#define LITMUS_HIGHEST_PRIORITY 1
64#define LITMUS_LOWEST_PRIORITY (LITMUS_MAX_PRIORITY - 1)
65
66/* Provide generic comparison macros for userspace,
67 * in case that we change this later. */
68#define litmus_higher_fixed_prio(a, b) (a < b)
69#define litmus_lower_fixed_prio(a, b) (a > b)
70#define litmus_is_valid_fixed_prio(p) \
71 ((p) >= LITMUS_HIGHEST_PRIORITY && \
72 (p) <= LITMUS_LOWEST_PRIORITY)
73
74struct rt_task {
75 lt_t exec_cost;
76 lt_t period;
77 lt_t relative_deadline;
78 lt_t phase;
79 unsigned int cpu;
80 unsigned int priority;
81 task_class_t cls;
82 budget_policy_t budget_policy; /* ignored by pfair */
83 release_policy_t release_policy;
84};
85
86union np_flag {
87 uint64_t raw;
88 struct {
89 /* Is the task currently in a non-preemptive section? */
90 uint64_t flag:31;
91 /* Should the task call into the scheduler? */
92 uint64_t preempt:1;
93 } np;
94};
95
96/* The definition of the data that is shared between the kernel and real-time
97 * tasks via a shared page (see litmus/ctrldev.c).
98 *
99 * WARNING: User space can write to this, so don't trust
100 * the correctness of the fields!
101 *
102 * This servees two purposes: to enable efficient signaling
103 * of non-preemptive sections (user->kernel) and
104 * delayed preemptions (kernel->user), and to export
105 * some real-time relevant statistics such as preemption and
106 * migration data to user space. We can't use a device to export
107 * statistics because we want to avoid system call overhead when
108 * determining preemption/migration overheads).
109 */
110struct control_page {
111 /* This flag is used by userspace to communicate non-preempive
112 * sections. */
113 volatile union np_flag sched;
114
115 volatile uint64_t irq_count; /* Incremented by the kernel each time an IRQ is
116 * handled. */
117
118 /* Locking overhead tracing: userspace records here the time stamp
119 * and IRQ counter prior to starting the system call. */
120 uint64_t ts_syscall_start; /* Feather-Trace cycles */
121 uint64_t irq_syscall_start; /* Snapshot of irq_count when the syscall
122 * started. */
123
124 /* to be extended */
125};
126
127/* Expected offsets within the control page. */
128
129#define LITMUS_CP_OFFSET_SCHED 0
130#define LITMUS_CP_OFFSET_IRQ_COUNT 8
131#define LITMUS_CP_OFFSET_TS_SC_START 16
132#define LITMUS_CP_OFFSET_IRQ_SC_START 24
133
134/* don't export internal data structures to user space (liblitmus) */
135#ifdef __KERNEL__
136
137struct _rt_domain;
138struct bheap_node;
139struct release_heap;
140
141struct rt_job {
142 /* Time instant the the job was or will be released. */
143 lt_t release;
144
145 /* What is the current deadline? */
146 lt_t deadline;
147
148 /* How much service has this job received so far? */
149 lt_t exec_time;
150
151 /* By how much did the prior job miss its deadline by?
152 * Value differs from tardiness in that lateness may
153 * be negative (when job finishes before its deadline).
154 */
155 long long lateness;
156
157 /* Which job is this. This is used to let user space
158 * specify which job to wait for, which is important if jobs
159 * overrun. If we just call sys_sleep_next_period() then we
160 * will unintentionally miss jobs after an overrun.
161 *
162 * Increase this sequence number when a job is released.
163 */
164 unsigned int job_no;
165};
166
167struct pfair_param;
168
169/* RT task parameters for scheduling extensions
170 * These parameters are inherited during clone and therefore must
171 * be explicitly set up before the task set is launched.
172 */
173struct rt_param {
174 /* Generic flags available for plugin-internal use. */
175 unsigned int flags:8;
176
177 /* do we need to check for srp blocking? */
178 unsigned int srp_non_recurse:1;
179
180 /* is the task present? (true if it can be scheduled) */
181 unsigned int present:1;
182
183 /* has the task completed? */
184 unsigned int completed:1;
185
186#ifdef CONFIG_LITMUS_LOCKING
187 /* Is the task being priority-boosted by a locking protocol? */
188 unsigned int priority_boosted:1;
189 /* If so, when did this start? */
190 lt_t boost_start_time;
191
192 /* How many LITMUS^RT locks does the task currently hold/wait for? */
193 unsigned int num_locks_held;
194 /* How many PCP/SRP locks does the task currently hold/wait for? */
195 unsigned int num_local_locks_held;
196#endif
197
198 /* user controlled parameters */
199 struct rt_task task_params;
200
201 /* timing parameters */
202 struct rt_job job_params;
203
204 /* Should the next job be released at some time other than
205 * just period time units after the last release?
206 */
207 unsigned int sporadic_release:1;
208 lt_t sporadic_release_time;
209
210
211 /* task representing the current "inherited" task
212 * priority, assigned by inherit_priority and
213 * return priority in the scheduler plugins.
214 * could point to self if PI does not result in
215 * an increased task priority.
216 */
217 struct task_struct* inh_task;
218
219#ifdef CONFIG_NP_SECTION
220 /* For the FMLP under PSN-EDF, it is required to make the task
221 * non-preemptive from kernel space. In order not to interfere with
222 * user space, this counter indicates the kernel space np setting.
223 * kernel_np > 0 => task is non-preemptive
224 */
225 unsigned int kernel_np;
226#endif
227
228 /* This field can be used by plugins to store where the task
229 * is currently scheduled. It is the responsibility of the
230 * plugin to avoid race conditions.
231 *
232 * This used by GSN-EDF and PFAIR.
233 */
234 volatile int scheduled_on;
235
236 /* Is the stack of the task currently in use? This is updated by
237 * the LITMUS core.
238 *
239 * Be careful to avoid deadlocks!
240 */
241 volatile int stack_in_use;
242
243 /* This field can be used by plugins to store where the task
244 * is currently linked. It is the responsibility of the plugin
245 * to avoid race conditions.
246 *
247 * Used by GSN-EDF.
248 */
249 volatile int linked_on;
250
251 /* PFAIR/PD^2 state. Allocated on demand. */
252 struct pfair_param* pfair;
253
254 /* Fields saved before BE->RT transition.
255 */
256 int old_policy;
257 int old_prio;
258
259 /* ready queue for this task */
260 struct _rt_domain* domain;
261
262 /* heap element for this task
263 *
264 * Warning: Don't statically allocate this node. The heap
265 * implementation swaps these between tasks, thus after
266 * dequeuing from a heap you may end up with a different node
267 * then the one you had when enqueuing the task. For the same
268 * reason, don't obtain and store references to this node
269 * other than this pointer (which is updated by the heap
270 * implementation).
271 */
272 struct bheap_node* heap_node;
273 struct release_heap* rel_heap;
274
275 /* Used by rt_domain to queue task in release list.
276 */
277 struct list_head list;
278
279 /* Pointer to the page shared between userspace and kernel. */
280 struct control_page * ctrl_page;
281};
282
283#endif
284
285#endif