diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2009-12-17 21:23:36 -0500 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-29 17:05:45 -0400 |
commit | 4b38febbd59fd33542a343991262119eb9860f5e (patch) | |
tree | 1af88a0d354abe344c2c2869631f76a1806d75c3 /include/litmus/litmus.h | |
parent | 22763c5cf3690a681551162c15d34d935308c8d7 (diff) |
[ported from 2008.3] Core LITMUS^RT infrastructure
Port 2008.3 Core LITMUS^RT infrastructure to Linux 2.6.32
litmus_sched_class implements 4 new methods:
- prio_changed:
void
- switched_to:
void
- get_rr_interval:
return infinity (i.e., 0)
- select_task_rq:
return current cpu
Diffstat (limited to 'include/litmus/litmus.h')
-rw-r--r-- | include/litmus/litmus.h | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/include/litmus/litmus.h b/include/litmus/litmus.h new file mode 100644 index 000000000000..380fcb8acb33 --- /dev/null +++ b/include/litmus/litmus.h | |||
@@ -0,0 +1,177 @@ | |||
1 | /* | ||
2 | * Constant definitions related to | ||
3 | * scheduling policy. | ||
4 | */ | ||
5 | |||
6 | #ifndef _LINUX_LITMUS_H_ | ||
7 | #define _LINUX_LITMUS_H_ | ||
8 | |||
9 | #include <linux/jiffies.h> | ||
10 | #include <litmus/sched_trace.h> | ||
11 | |||
12 | extern atomic_t release_master_cpu; | ||
13 | |||
14 | extern atomic_t __log_seq_no; | ||
15 | |||
16 | #define TRACE(fmt, args...) \ | ||
17 | sched_trace_log_message("%d P%d: " fmt, atomic_add_return(1, &__log_seq_no), \ | ||
18 | raw_smp_processor_id(), ## args) | ||
19 | |||
20 | #define TRACE_TASK(t, fmt, args...) \ | ||
21 | TRACE("(%s/%d) " fmt, (t)->comm, (t)->pid, ##args) | ||
22 | |||
23 | #define TRACE_CUR(fmt, args...) \ | ||
24 | TRACE_TASK(current, fmt, ## args) | ||
25 | |||
26 | #define TRACE_BUG_ON(cond) \ | ||
27 | do { if (cond) TRACE("BUG_ON(%s) at %s:%d " \ | ||
28 | "called from %p current=%s/%d state=%d " \ | ||
29 | "flags=%x partition=%d cpu=%d rtflags=%d"\ | ||
30 | " job=%u knp=%d timeslice=%u\n", \ | ||
31 | #cond, __FILE__, __LINE__, __builtin_return_address(0), current->comm, \ | ||
32 | current->pid, current->state, current->flags, \ | ||
33 | get_partition(current), smp_processor_id(), get_rt_flags(current), \ | ||
34 | current->rt_param.job_params.job_no, current->rt_param.kernel_np, \ | ||
35 | current->rt.time_slice\ | ||
36 | ); } while(0); | ||
37 | |||
38 | |||
39 | /* in_list - is a given list_head queued on some list? | ||
40 | */ | ||
41 | static inline int in_list(struct list_head* list) | ||
42 | { | ||
43 | return !( /* case 1: deleted */ | ||
44 | (list->next == LIST_POISON1 && | ||
45 | list->prev == LIST_POISON2) | ||
46 | || | ||
47 | /* case 2: initialized */ | ||
48 | (list->next == list && | ||
49 | list->prev == list) | ||
50 | ); | ||
51 | } | ||
52 | |||
53 | #define NO_CPU 0xffffffff | ||
54 | |||
55 | void litmus_fork(struct task_struct *tsk); | ||
56 | void litmus_exec(void); | ||
57 | /* clean up real-time state of a task */ | ||
58 | void exit_litmus(struct task_struct *dead_tsk); | ||
59 | |||
60 | long litmus_admit_task(struct task_struct *tsk); | ||
61 | void litmus_exit_task(struct task_struct *tsk); | ||
62 | |||
63 | #define is_realtime(t) ((t)->policy == SCHED_LITMUS) | ||
64 | #define rt_transition_pending(t) \ | ||
65 | ((t)->rt_param.transition_pending) | ||
66 | |||
67 | #define tsk_rt(t) (&(t)->rt_param) | ||
68 | |||
69 | /* Realtime utility macros */ | ||
70 | #define get_rt_flags(t) (tsk_rt(t)->flags) | ||
71 | #define set_rt_flags(t,f) (tsk_rt(t)->flags=(f)) | ||
72 | #define get_exec_cost(t) (tsk_rt(t)->task_params.exec_cost) | ||
73 | #define get_exec_time(t) (tsk_rt(t)->job_params.exec_time) | ||
74 | #define get_rt_period(t) (tsk_rt(t)->task_params.period) | ||
75 | #define get_rt_phase(t) (tsk_rt(t)->task_params.phase) | ||
76 | #define get_partition(t) (tsk_rt(t)->task_params.cpu) | ||
77 | #define get_deadline(t) (tsk_rt(t)->job_params.deadline) | ||
78 | #define get_release(t) (tsk_rt(t)->job_params.release) | ||
79 | #define get_class(t) (tsk_rt(t)->task_params.cls) | ||
80 | |||
81 | inline static int budget_exhausted(struct task_struct* t) | ||
82 | { | ||
83 | return get_exec_time(t) >= get_exec_cost(t); | ||
84 | } | ||
85 | |||
86 | |||
87 | #define is_hrt(t) \ | ||
88 | (tsk_rt(t)->task_params.class == RT_CLASS_HARD) | ||
89 | #define is_srt(t) \ | ||
90 | (tsk_rt(t)->task_params.class == RT_CLASS_SOFT) | ||
91 | #define is_be(t) \ | ||
92 | (tsk_rt(t)->task_params.class == RT_CLASS_BEST_EFFORT) | ||
93 | |||
94 | /* Our notion of time within LITMUS: kernel monotonic time. */ | ||
95 | static inline lt_t litmus_clock(void) | ||
96 | { | ||
97 | return ktime_to_ns(ktime_get()); | ||
98 | } | ||
99 | |||
100 | /* A macro to convert from nanoseconds to ktime_t. */ | ||
101 | #define ns_to_ktime(t) ktime_add_ns(ktime_set(0, 0), t) | ||
102 | |||
103 | #define get_domain(t) (tsk_rt(t)->domain) | ||
104 | |||
105 | /* Honor the flag in the preempt_count variable that is set | ||
106 | * when scheduling is in progress. | ||
107 | */ | ||
108 | #define is_running(t) \ | ||
109 | ((t)->state == TASK_RUNNING || \ | ||
110 | task_thread_info(t)->preempt_count & PREEMPT_ACTIVE) | ||
111 | |||
112 | #define is_blocked(t) \ | ||
113 | (!is_running(t)) | ||
114 | #define is_released(t, now) \ | ||
115 | (lt_before_eq(get_release(t), now)) | ||
116 | #define is_tardy(t, now) \ | ||
117 | (lt_before_eq(tsk_rt(t)->job_params.deadline, now)) | ||
118 | |||
119 | /* real-time comparison macros */ | ||
120 | #define earlier_deadline(a, b) (lt_before(\ | ||
121 | (a)->rt_param.job_params.deadline,\ | ||
122 | (b)->rt_param.job_params.deadline)) | ||
123 | #define earlier_release(a, b) (lt_before(\ | ||
124 | (a)->rt_param.job_params.release,\ | ||
125 | (b)->rt_param.job_params.release)) | ||
126 | |||
127 | #define make_np(t) do {t->rt_param.kernel_np++;} while(0); | ||
128 | #define take_np(t) do {t->rt_param.kernel_np--;} while(0); | ||
129 | |||
130 | #ifdef CONFIG_SRP | ||
131 | void srp_ceiling_block(void); | ||
132 | #else | ||
133 | #define srp_ceiling_block() /* nothing */ | ||
134 | #endif | ||
135 | |||
136 | #define heap2task(hn) ((struct task_struct*) hn->value) | ||
137 | |||
138 | static inline int is_np(struct task_struct *t) | ||
139 | { | ||
140 | return tsk_rt(t)->kernel_np; | ||
141 | } | ||
142 | |||
143 | #define request_exit_np(t) | ||
144 | |||
145 | static inline int is_present(struct task_struct* t) | ||
146 | { | ||
147 | return t && tsk_rt(t)->present; | ||
148 | } | ||
149 | |||
150 | |||
151 | /* make the unit explicit */ | ||
152 | typedef unsigned long quanta_t; | ||
153 | |||
154 | enum round { | ||
155 | FLOOR, | ||
156 | CEIL | ||
157 | }; | ||
158 | |||
159 | |||
160 | /* Tick period is used to convert ns-specified execution | ||
161 | * costs and periods into tick-based equivalents. | ||
162 | */ | ||
163 | extern ktime_t tick_period; | ||
164 | |||
165 | static inline quanta_t time2quanta(lt_t time, enum round round) | ||
166 | { | ||
167 | s64 quantum_length = ktime_to_ns(tick_period); | ||
168 | |||
169 | if (do_div(time, quantum_length) && round == CEIL) | ||
170 | time++; | ||
171 | return (quanta_t) time; | ||
172 | } | ||
173 | |||
174 | /* By how much is cpu staggered behind CPU 0? */ | ||
175 | u64 cpu_stagger_offset(int cpu); | ||
176 | |||
177 | #endif | ||