diff options
author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2015-08-09 07:18:48 -0400 |
---|---|---|
committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2015-08-09 06:21:18 -0400 |
commit | 8e048c798adaabef530a1526f7ce8c6c3cd3475e (patch) | |
tree | 5a96b3eaeaafecec1bf08ba71a9d0084d39d46eb /litmus/fp_common.c | |
parent | bd175e94795774908317a861a883761b75750e35 (diff) |
Add LITMUS^RT core implementation
This patch adds the core of LITMUS^RT:
- library functionality (heaps, rt_domain, prioritization, etc.)
- budget enforcement logic
- job management
- system call backends
- virtual devices (control page, etc.)
- scheduler plugin API (and dummy plugin)
This code compiles, but is not yet integrated with the rest of Linux.
Diffstat (limited to 'litmus/fp_common.c')
-rw-r--r-- | litmus/fp_common.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/litmus/fp_common.c b/litmus/fp_common.c new file mode 100644 index 000000000000..964a4729deff --- /dev/null +++ b/litmus/fp_common.c | |||
@@ -0,0 +1,119 @@ | |||
1 | /* | ||
2 | * litmus/fp_common.c | ||
3 | * | ||
4 | * Common functions for fixed-priority scheduler. | ||
5 | */ | ||
6 | |||
7 | #include <linux/percpu.h> | ||
8 | #include <linux/sched.h> | ||
9 | #include <linux/list.h> | ||
10 | |||
11 | #include <litmus/litmus.h> | ||
12 | #include <litmus/sched_plugin.h> | ||
13 | #include <litmus/sched_trace.h> | ||
14 | |||
15 | #include <litmus/fp_common.h> | ||
16 | |||
17 | /* fp_higher_prio - returns true if first has a higher static priority | ||
18 | * than second. Ties are broken by PID. | ||
19 | * | ||
20 | * both first and second may be NULL | ||
21 | */ | ||
22 | int fp_higher_prio(struct task_struct* first, | ||
23 | struct task_struct* second) | ||
24 | { | ||
25 | struct task_struct *first_task = first; | ||
26 | struct task_struct *second_task = second; | ||
27 | |||
28 | /* There is no point in comparing a task to itself. */ | ||
29 | if (unlikely(first && first == second)) { | ||
30 | TRACE_TASK(first, | ||
31 | "WARNING: pointless FP priority comparison.\n"); | ||
32 | return 0; | ||
33 | } | ||
34 | |||
35 | |||
36 | /* check for NULL tasks */ | ||
37 | if (!first || !second) | ||
38 | return first && !second; | ||
39 | |||
40 | if (!is_realtime(second_task)) | ||
41 | return 1; | ||
42 | |||
43 | #ifdef CONFIG_LITMUS_LOCKING | ||
44 | |||
45 | /* Check for inherited priorities. Change task | ||
46 | * used for comparison in such a case. | ||
47 | */ | ||
48 | if (unlikely(first->rt_param.inh_task)) | ||
49 | first_task = first->rt_param.inh_task; | ||
50 | if (unlikely(second->rt_param.inh_task)) | ||
51 | second_task = second->rt_param.inh_task; | ||
52 | |||
53 | /* Check for priority boosting. Tie-break by start of boosting. | ||
54 | */ | ||
55 | if (unlikely(is_priority_boosted(first_task))) { | ||
56 | /* first_task is boosted, how about second_task? */ | ||
57 | if (is_priority_boosted(second_task)) | ||
58 | /* break by priority point */ | ||
59 | return lt_before(get_boost_start(first_task), | ||
60 | get_boost_start(second_task)); | ||
61 | else | ||
62 | /* priority boosting wins. */ | ||
63 | return 1; | ||
64 | } else if (unlikely(is_priority_boosted(second_task))) | ||
65 | /* second_task is boosted, first is not*/ | ||
66 | return 0; | ||
67 | |||
68 | #endif | ||
69 | |||
70 | /* Comparisons to itself are not expected; priority inheritance | ||
71 | * should also not cause this to happen. */ | ||
72 | BUG_ON(first_task == second_task); | ||
73 | |||
74 | if (get_priority(first_task) < get_priority(second_task)) | ||
75 | return 1; | ||
76 | else if (get_priority(first_task) == get_priority(second_task)) | ||
77 | /* Break by PID. */ | ||
78 | return first_task->pid < second_task->pid; | ||
79 | else | ||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | int fp_ready_order(struct bheap_node* a, struct bheap_node* b) | ||
84 | { | ||
85 | return fp_higher_prio(bheap2task(a), bheap2task(b)); | ||
86 | } | ||
87 | |||
88 | void fp_domain_init(rt_domain_t* rt, check_resched_needed_t resched, | ||
89 | release_jobs_t release) | ||
90 | { | ||
91 | rt_domain_init(rt, fp_ready_order, resched, release); | ||
92 | } | ||
93 | |||
94 | /* need_to_preempt - check whether the task t needs to be preempted | ||
95 | */ | ||
96 | int fp_preemption_needed(struct fp_prio_queue *q, struct task_struct *t) | ||
97 | { | ||
98 | struct task_struct *pending; | ||
99 | |||
100 | pending = fp_prio_peek(q); | ||
101 | |||
102 | if (!pending) | ||
103 | return 0; | ||
104 | if (!t) | ||
105 | return 1; | ||
106 | |||
107 | /* make sure to get non-rt stuff out of the way */ | ||
108 | return !is_realtime(t) || fp_higher_prio(pending, t); | ||
109 | } | ||
110 | |||
111 | void fp_prio_queue_init(struct fp_prio_queue* q) | ||
112 | { | ||
113 | int i; | ||
114 | |||
115 | for (i = 0; i < FP_PRIO_BIT_WORDS; i++) | ||
116 | q->bitmask[i] = 0; | ||
117 | for (i = 0; i < LITMUS_MAX_PRIORITY; i++) | ||
118 | bheap_init(&q->queue[i]); | ||
119 | } | ||