aboutsummaryrefslogtreecommitdiffstats
path: root/litmus/budget.c
diff options
context:
space:
mode:
Diffstat (limited to 'litmus/budget.c')
-rw-r--r--litmus/budget.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/litmus/budget.c b/litmus/budget.c
index 310e9a3d4172..84f3f22770b1 100644
--- a/litmus/budget.c
+++ b/litmus/budget.c
@@ -4,13 +4,8 @@
4 4
5#include <litmus/litmus.h> 5#include <litmus/litmus.h>
6#include <litmus/preempt.h> 6#include <litmus/preempt.h>
7 7#include <litmus/budget.h>
8struct enforcement_timer { 8#include <litmus/sched_trace.h>
9 /* The enforcement timer is used to accurately police
10 * slice budgets. */
11 struct hrtimer timer;
12 int armed;
13};
14 9
15DEFINE_PER_CPU(struct enforcement_timer, budget_timer); 10DEFINE_PER_CPU(struct enforcement_timer, budget_timer);
16 11
@@ -32,7 +27,7 @@ static enum hrtimer_restart on_enforcement_timeout(struct hrtimer *timer)
32} 27}
33 28
34/* assumes called with IRQs off */ 29/* assumes called with IRQs off */
35static void cancel_enforcement_timer(struct enforcement_timer* et) 30void cancel_enforcement_timer(struct enforcement_timer* et)
36{ 31{
37 int ret; 32 int ret;
38 33
@@ -54,11 +49,10 @@ static void cancel_enforcement_timer(struct enforcement_timer* et)
54} 49}
55 50
56/* assumes called with IRQs off */ 51/* assumes called with IRQs off */
57static void arm_enforcement_timer(struct enforcement_timer* et, 52void arm_enforcement_timer(struct enforcement_timer* et,
58 struct task_struct* t) 53 struct task_struct* t)
59{ 54{
60 lt_t when_to_fire; 55 lt_t when_to_fire;
61 TRACE_TASK(t, "arming enforcement timer.\n");
62 56
63 /* Calling this when there is no budget left for the task 57 /* Calling this when there is no budget left for the task
64 * makes no sense, unless the task is non-preemptive. */ 58 * makes no sense, unless the task is non-preemptive. */
@@ -67,8 +61,11 @@ static void arm_enforcement_timer(struct enforcement_timer* et,
67 /* __hrtimer_start_range_ns() cancels the timer 61 /* __hrtimer_start_range_ns() cancels the timer
68 * anyway, so we don't have to check whether it is still armed */ 62 * anyway, so we don't have to check whether it is still armed */
69 63
70 if (likely(!is_np(t))) { 64 if (likely(!is_user_np(t))) {
71 when_to_fire = litmus_clock() + budget_remaining(t); 65 when_to_fire = litmus_clock() + budget_remaining(t);
66 TRACE_TASK(t, "arming enforcement timer for %llu.\n",
67 when_to_fire);
68
72 __hrtimer_start_range_ns(&et->timer, 69 __hrtimer_start_range_ns(&et->timer,
73 ns_to_ktime(when_to_fire), 70 ns_to_ktime(when_to_fire),
74 0 /* delta */, 71 0 /* delta */,
@@ -94,6 +91,11 @@ void update_enforcement_timer(struct task_struct* t)
94 } 91 }
95} 92}
96 93
94void init_enforcement_timer(struct enforcement_timer *et)
95{
96 hrtimer_init(&et->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
97 et->timer.function = on_enforcement_timeout;
98}
97 99
98static int __init init_budget_enforcement(void) 100static int __init init_budget_enforcement(void)
99{ 101{
@@ -102,8 +104,7 @@ static int __init init_budget_enforcement(void)
102 104
103 for (cpu = 0; cpu < NR_CPUS; cpu++) { 105 for (cpu = 0; cpu < NR_CPUS; cpu++) {
104 et = &per_cpu(budget_timer, cpu); 106 et = &per_cpu(budget_timer, cpu);
105 hrtimer_init(&et->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); 107 init_enforcement_timer(et);
106 et->timer.function = on_enforcement_timeout;
107 } 108 }
108 return 0; 109 return 0;
109} 110}