aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/litmus/budget.h30
-rw-r--r--litmus/budget.c19
-rw-r--r--litmus/rt_domain.c20
-rw-r--r--litmus/sched_mc.c92
4 files changed, 59 insertions, 102 deletions
diff --git a/include/litmus/budget.h b/include/litmus/budget.h
index 062df818de45..ff18d89e8630 100644
--- a/include/litmus/budget.h
+++ b/include/litmus/budget.h
@@ -1,15 +1,35 @@
1#ifndef _LITMUS_BUDGET_H_ 1#ifndef _LITMUS_BUDGET_H_
2#define _LITMUS_BUDGET_H_ 2#define _LITMUS_BUDGET_H_
3 3
4/* Update the per-processor enforcement timer (arm/reproram/cancel) for 4/**
5 * the next task. */ 5 * update_enforcement_timer() - Update per-processor enforcement timer for
6 * the next scheduled task.
7 *
8 * If @t is not NULL and has a precisely enforced budget, the timer will be
9 * armed to trigger a reschedule when the budget is exhausted. Otherwise,
10 * the timer will be cancelled.
11*/
6void update_enforcement_timer(struct task_struct* t); 12void update_enforcement_timer(struct task_struct* t);
7 13
8void prepare_for_next_server(struct task_struct* t,int forced); 14/* True if a task's server has progressed farther than the task
9 15 * itself. This happens when budget enforcement has caused a task to be
10#define job_behind(t)\ 16 * booted off until the next period.
17 */
18#define behind_server(t)\
11 (lt_before((t)->rt_param.job_params.real_release, get_release(t))) 19 (lt_before((t)->rt_param.job_params.real_release, get_release(t)))
12 20
21/**
22 * server_release() - Prepare the task server parameters for the next period.
23 * The server for @t is what is actually executed from the schedulers
24 * perspective.
25 */
13void server_release(struct task_struct *t); 26void server_release(struct task_struct *t);
27
28/**
29 * task_release() - Prepare actual task parameters for the next period.
30 * The actual task parameters for @t, real_deadline and real_release, are
31 * the deadline and release from the tasks perspective. We only record these
32 * so that we can write them to feather trace.
33 */
14void task_release(struct task_struct *t); 34void task_release(struct task_struct *t);
15#endif 35#endif
diff --git a/litmus/budget.c b/litmus/budget.c
index b2239ff1c45c..93945e0911a7 100644
--- a/litmus/budget.c
+++ b/litmus/budget.c
@@ -64,7 +64,7 @@ static void arm_enforcement_timer(struct enforcement_timer* et,
64 64
65 /* Calling this when there is no budget left for the task 65 /* Calling this when there is no budget left for the task
66 * makes no sense, unless the task is non-preemptive. */ 66 * makes no sense, unless the task is non-preemptive. */
67 /* BUG_ON(budget_exhausted(t) && (!is_np(t))); */ 67 BUG_ON(budget_exhausted(t) && (!is_np(t)));
68 68
69 /* __hrtimer_start_range_ns() cancels the timer 69 /* __hrtimer_start_range_ns() cancels the timer
70 * anyway, so we don't have to check whether it is still armed */ 70 * anyway, so we don't have to check whether it is still armed */
@@ -115,9 +115,6 @@ void task_release(struct task_struct *t)
115 t->rt_param.job_params.real_release = t->rt_param.job_params.real_deadline; 115 t->rt_param.job_params.real_release = t->rt_param.job_params.real_deadline;
116 t->rt_param.job_params.real_deadline += get_rt_period(t); 116 t->rt_param.job_params.real_deadline += get_rt_period(t);
117 t->rt_param.job_params.job_no++; 117 t->rt_param.job_params.job_no++;
118 TRACE_TASK(t, "Releasing task, rr=%llu rd=%llu\n",
119 t->rt_param.job_params.real_release,
120 t->rt_param.job_params.real_deadline);
121 sched_trace_task_release(t); 118 sched_trace_task_release(t);
122} 119}
123 120
@@ -127,22 +124,8 @@ void server_release(struct task_struct *t)
127 t->rt_param.job_params.exec_time = 0; 124 t->rt_param.job_params.exec_time = 0;
128 t->rt_param.job_params.release = t->rt_param.job_params.deadline; 125 t->rt_param.job_params.release = t->rt_param.job_params.deadline;
129 t->rt_param.job_params.deadline += get_rt_period(t); 126 t->rt_param.job_params.deadline += get_rt_period(t);
130 TRACE_TASK(t, "Releasing server, r=%llu d=%llu\n",
131 t->rt_param.job_params.release,
132 t->rt_param.job_params.deadline);
133 /* don't confuse linux */ 127 /* don't confuse linux */
134 t->rt.time_slice = 1; 128 t->rt.time_slice = 1;
135} 129}
136 130
137void prepare_for_next_server(struct task_struct *t, int forced)
138{
139 if (forced || job_behind(t)) {
140 server_release(t);
141 }
142
143 if (!forced) {
144 task_release(t);
145 }
146}
147
148module_init(init_budget_enforcement); 131module_init(init_budget_enforcement);
diff --git a/litmus/rt_domain.c b/litmus/rt_domain.c
index e6ccf04cecf0..5296665b5ddd 100644
--- a/litmus/rt_domain.c
+++ b/litmus/rt_domain.c
@@ -254,7 +254,6 @@ static void setup_release(rt_domain_t *_rt)
254 list_for_each_safe(pos, safe, &list) { 254 list_for_each_safe(pos, safe, &list) {
255 /* pick task of work list */ 255 /* pick task of work list */
256 t = list_entry(pos, struct task_struct, rt_param.list); 256 t = list_entry(pos, struct task_struct, rt_param.list);
257 /* sched_trace_task_release(t); */
258 list_del_init(pos); 257 list_del_init(pos);
259 258
260 /* put into release heap while holding release_lock */ 259 /* put into release heap while holding release_lock */
@@ -405,24 +404,19 @@ static void pd_requeue(domain_t *dom, struct task_struct *task)
405{ 404{
406 rt_domain_t *domain = (rt_domain_t*)dom->data; 405 rt_domain_t *domain = (rt_domain_t*)dom->data;
407 406
408 BUG_ON(!task || !is_realtime(task));
409 TRACE_TASK(task, "Requeueing\n"); 407 TRACE_TASK(task, "Requeueing\n");
408 BUG_ON(!task || !is_realtime(task));
410 BUG_ON(is_queued(task)); 409 BUG_ON(is_queued(task));
411 BUG_ON(get_task_domain(task) != dom); 410 BUG_ON(get_task_domain(task) != dom);
412 411
413 if (is_queued(task)) {
414 VTRACE_TASK(task, "Queued, skipping\n");
415 return;
416 }
417
418 if (is_released(task, litmus_clock())) { 412 if (is_released(task, litmus_clock())) {
419 __add_ready(domain, task); 413 __add_ready(domain, task);
420 VTRACE("going, rt: adding %s/%d (%llu, %llu) rel=%llu to ready queue at %llu\n", 414 VTRACE("rt: adding %s/%d (%llu, %llu) rel=%llu to ready queue at %llu\n",
421 task->comm, task->pid, get_exec_cost(task), get_rt_period(task), 415 task->comm, task->pid, get_exec_cost(task), get_rt_period(task),
422 get_release(task), litmus_clock()); 416 get_release(task), litmus_clock());
423 } else { 417 } else {
424 /* task has to wait for next release */ 418 /* task has to wait for next release */
425 VTRACE_TASK(task, "not going, add release(), rel=%llu\n", get_release(task)); 419 VTRACE_TASK(task, "add release(), rel=%llu\n", get_release(task));
426 add_release(domain, task); 420 add_release(domain, task);
427 } 421 }
428 422
@@ -434,9 +428,8 @@ static void pd_requeue(domain_t *dom, struct task_struct *task)
434 */ 428 */
435static struct task_struct* pd_take_ready(domain_t *dom) 429static struct task_struct* pd_take_ready(domain_t *dom)
436{ 430{
437 struct task_struct *t = __take_ready((rt_domain_t*)dom->data); 431 return __take_ready((rt_domain_t*)dom->data);
438 return t; 432 }
439}
440 433
441/* pd_peek_ready - returns the head of the rt_domain ready queue 434/* pd_peek_ready - returns the head of the rt_domain ready queue
442 * 435 *
@@ -444,8 +437,7 @@ static struct task_struct* pd_take_ready(domain_t *dom)
444 */ 437 */
445static struct task_struct* pd_peek_ready(domain_t *dom) 438static struct task_struct* pd_peek_ready(domain_t *dom)
446{ 439{
447 struct task_struct *t = __peek_ready((rt_domain_t*)dom->data); 440 return __next_ready((rt_domain_t*)dom->data);
448 return t;
449} 441}
450 442
451static void pd_remove(domain_t *dom, struct task_struct *task) 443static void pd_remove(domain_t *dom, struct task_struct *task)
diff --git a/litmus/sched_mc.c b/litmus/sched_mc.c
index 84fdc304b434..f3ace9fe560a 100644
--- a/litmus/sched_mc.c
+++ b/litmus/sched_mc.c
@@ -61,8 +61,6 @@ DEFINE_PER_CPU(struct cpu_entry, cpus);
61static int interrupt_cpu; 61static int interrupt_cpu;
62#endif 62#endif
63 63
64#define FTRACE_CPU 6
65
66#define domain_data(dom) (container_of(dom, struct domain_data, domain)) 64#define domain_data(dom) (container_of(dom, struct domain_data, domain))
67#define is_global(dom) (domain_data(dom)->heap) 65#define is_global(dom) (domain_data(dom)->heap)
68#define is_global_task(t) (is_global(get_task_domain(t))) 66#define is_global_task(t) (is_global(get_task_domain(t)))
@@ -151,11 +149,9 @@ static void fix_crit_position(struct crit_entry *ce)
151 if (is_global(ce->domain)) { 149 if (is_global(ce->domain)) {
152 if (CS_ACTIVATE == ce->state) { 150 if (CS_ACTIVATE == ce->state) {
153 ce->state = CS_ACTIVE; 151 ce->state = CS_ACTIVE;
154 TRACE_CRIT_ENTRY(ce, "CS_ACTIVE\n");
155 update_crit_position(ce); 152 update_crit_position(ce);
156 } else if (CS_REMOVE == ce->state) { 153 } else if (CS_REMOVE == ce->state) {
157 ce->state = CS_REMOVED; 154 ce->state = CS_REMOVED;
158 TRACE_CRIT_ENTRY(ce, "CS_REMOVED\n");
159 update_crit_position(ce); 155 update_crit_position(ce);
160 } 156 }
161 } 157 }
@@ -389,7 +385,6 @@ static void link_task_to_cpu(struct cpu_entry *entry, struct task_struct *task)
389 for (; i < entry_level(entry) + 1; i++) { 385 for (; i < entry_level(entry) + 1; i++) {
390 ce = &entry->crit_entries[i]; 386 ce = &entry->crit_entries[i];
391 if (!can_use(ce)) { 387 if (!can_use(ce)) {
392 TRACE_CRIT_ENTRY(ce, "CS_ACTIVATE\n");
393 ce->state = CS_ACTIVATE; 388 ce->state = CS_ACTIVATE;
394 } 389 }
395 } 390 }
@@ -462,7 +457,6 @@ static void update_crit_levels(struct cpu_entry *entry)
462 */ 457 */
463 readmit[i] = (!global_preempted) ? ce->linked : NULL; 458 readmit[i] = (!global_preempted) ? ce->linked : NULL;
464 459
465 TRACE_CRIT_ENTRY(ce, "CS_REMOVE\n");
466 ce->state = CS_REMOVE; 460 ce->state = CS_REMOVE;
467 if (ce->linked) 461 if (ce->linked)
468 link_task_to_crit(ce, NULL); 462 link_task_to_crit(ce, NULL);
@@ -479,22 +473,6 @@ static void update_crit_levels(struct cpu_entry *entry)
479 } 473 }
480} 474}
481 475
482static inline int cache_next(struct domain *dom)
483{
484 struct task_struct *t;
485 t = dom->peek_ready(dom);
486 return 1;
487 /* if (t && tsk_mc_crit(t) != CRIT_LEVEL_A && budget_exhausted(t)) { */
488 /* TRACE_TASK(t, "Cached and moved to release\n"); */
489 /* prepare_for_next_server(t, 1); */
490 /* dom->take_ready(dom); */
491 /* dom->requeue(dom, t); */
492 /* return 0; */
493 /* } else { */
494 /* return 1; */
495 /* } */
496}
497
498/** 476/**
499 * check_for_preempt() - Causes a preemption if higher-priority tasks are ready. 477 * check_for_preempt() - Causes a preemption if higher-priority tasks are ready.
500 * Caller must hold domain lock. 478 * Caller must hold domain lock.
@@ -513,10 +491,8 @@ static void check_for_preempt(struct domain *dom)
513 entry = crit_cpu(ce); 491 entry = crit_cpu(ce);
514 recheck = 1; 492 recheck = 1;
515 493
516 /* Dodge exhausted tasks */ 494 /* Cache next task */
517 if (!cache_next(dom)) { 495 dom->peek_ready(dom);
518 continue;
519 }
520 496
521 raw_spin_lock(&entry->lock); 497 raw_spin_lock(&entry->lock);
522 if (!can_use(ce)) 498 if (!can_use(ce))
@@ -535,8 +511,11 @@ static void check_for_preempt(struct domain *dom)
535 } else /* Partitioned */ { 511 } else /* Partitioned */ {
536 ce = domain_data(dom)->crit_entry; 512 ce = domain_data(dom)->crit_entry;
537 entry = crit_cpu(ce); 513 entry = crit_cpu(ce);
514
515 /* Cache next task */
516 dom->peek_ready(dom);
517
538 raw_spin_lock(&entry->lock); 518 raw_spin_lock(&entry->lock);
539 while (!cache_next(dom));
540 if (can_use(ce) && dom->preempt_needed(dom, ce->linked)) { 519 if (can_use(ce) && dom->preempt_needed(dom, ce->linked)) {
541 preempt(dom, ce); 520 preempt(dom, ce);
542 update_crit_levels(entry); 521 update_crit_levels(entry);
@@ -552,7 +531,7 @@ static void check_for_preempt(struct domain *dom)
552 */ 531 */
553static void remove_from_all(struct task_struct* task) 532static void remove_from_all(struct task_struct* task)
554{ 533{
555 int update = 0, old; 534 int update = 0;
556 struct cpu_entry *entry; 535 struct cpu_entry *entry;
557 struct crit_entry *ce; 536 struct crit_entry *ce;
558 struct domain *dom = get_task_domain(task); 537 struct domain *dom = get_task_domain(task);
@@ -601,43 +580,38 @@ static void remove_from_all(struct task_struct* task)
601 */ 580 */
602static void job_completion(struct task_struct *task, int forced) 581static void job_completion(struct task_struct *task, int forced)
603{ 582{
604 lt_t now; 583 int behind;
605 int ghost = is_ghost(task); 584 TRACE_MC_TASK(task, "Completed\n");
606 int behind = tsk_mc_crit(task) != CRIT_LEVEL_A && job_behind(task);
607 TRACE_MC_TASK(task, "Completed, ghost %d, forced %d, behind %d\n",
608 ghost, forced, behind);
609
610 /* if (!is_ghost(task)) { */
611 /* and no more forced!!! */
612 if (!ghost && !forced)
613 sched_trace_task_completion(task, forced);
614 /* } */
615 BUG_ON(!task);
616 585
617 /* Logically stop the task execution */ 586 /* Logically stop the task execution */
618 set_rt_flags(task, RT_F_SLEEP); 587 set_rt_flags(task, RT_F_SLEEP);
619 remove_from_all(task); 588 remove_from_all(task);
620 589
621 now = litmus_clock(); 590 /* Level-A tasks cannot ever get behind */
622 591 behind = tsk_mc_crit(task) != CRIT_LEVEL_A && behind_server(task);
623 592
624 if (!forced && !ghost) { 593 if (!forced && !is_ghost(task)) {
594 /* Task voluntarily ceased execution. Move on to next period */
625 task_release(task); 595 task_release(task);
626 } 596 sched_trace_task_completion(task, forced);
627 597
628 if (!forced && !ghost) { 598 /* Convert to ghost job */
629 tsk_mc_data(task)->mc_job.ghost_budget = 599 tsk_mc_data(task)->mc_job.ghost_budget = budget_remaining(task);
630 budget_remaining(task);
631 tsk_mc_data(task)->mc_job.is_ghost = 1; 600 tsk_mc_data(task)->mc_job.is_ghost = 1;
632 } 601 }
633 602
634 if (forced || behind || tsk_mc_data(task)->mc_job.ghost_budget == 0) { 603 /* If the task has no ghost budget, convert back from ghost.
635 TRACE_MC_TASK(task, "making not a ghost\n"); 604 * If the task is behind, undo ghost conversion so that it
605 * can catch up.
606 */
607 if (behind || tsk_mc_data(task)->mc_job.ghost_budget == 0) {
608 TRACE_MC_TASK(task, "Not a ghost task\n");
636 tsk_mc_data(task)->mc_job.is_ghost = 0; 609 tsk_mc_data(task)->mc_job.is_ghost = 0;
637 tsk_mc_data(task)->mc_job.ghost_budget = 0; 610 tsk_mc_data(task)->mc_job.ghost_budget = 0;
638 } 611 }
639 612
640 if (forced || (!behind && !is_ghost(task))) { 613 /* If server has run out of budget, wait until next release */
614 if (budget_exhausted(task)) {
641 server_release(task); 615 server_release(task);
642 } 616 }
643 617
@@ -812,13 +786,8 @@ static void mc_task_new(struct task_struct *t, int on_rq, int running)
812 tsk_mc_data(t)->mc_job.is_ghost = 0; 786 tsk_mc_data(t)->mc_job.is_ghost = 0;
813 if (running) { 787 if (running) {
814 BUG_ON(entry->scheduled); 788 BUG_ON(entry->scheduled);
815 if (entry->cpu != FTRACE_CPU) { 789 entry->scheduled = t;
816 entry->scheduled = t; 790 tsk_rt(t)->scheduled_on = entry->cpu;
817 tsk_rt(t)->scheduled_on = entry->cpu;
818 } else {
819 t->rt_param.scheduled_on = NO_CPU;
820 preempt_if_preemptable(NULL, entry->cpu);
821 }
822 } else { 791 } else {
823 t->rt_param.scheduled_on = NO_CPU; 792 t->rt_param.scheduled_on = NO_CPU;
824 } 793 }
@@ -928,9 +897,6 @@ static struct task_struct* mc_schedule(struct task_struct* prev)
928 int i, out_of_time, sleep, preempt, exists, blocks, global, lower; 897 int i, out_of_time, sleep, preempt, exists, blocks, global, lower;
929 struct task_struct *dtask = NULL, *ready_task = NULL, *next = NULL; 898 struct task_struct *dtask = NULL, *ready_task = NULL, *next = NULL;
930 899
931 if (entry->cpu == FTRACE_CPU)
932 return NULL;
933
934 local_irq_save(flags); 900 local_irq_save(flags);
935 901
936 /* Litmus gave up because it couldn't access the stack of the CPU 902 /* Litmus gave up because it couldn't access the stack of the CPU
@@ -1005,7 +971,6 @@ static struct task_struct* mc_schedule(struct task_struct* prev)
1005 raw_spin_lock(dom->lock); 971 raw_spin_lock(dom->lock);
1006 972
1007 /* Peek at task here to avoid lock use */ 973 /* Peek at task here to avoid lock use */
1008 while (!cache_next(dom));
1009 dtask = dom->peek_ready(dom); 974 dtask = dom->peek_ready(dom);
1010 975
1011 raw_spin_lock(&entry->lock); 976 raw_spin_lock(&entry->lock);
@@ -1100,7 +1065,6 @@ static long mc_activate_plugin(void)
1100 struct domain_data *dom_data; 1065 struct domain_data *dom_data;
1101 struct domain *dom; 1066 struct domain *dom;
1102 struct domain_data *our_domains[NR_CPUS]; 1067 struct domain_data *our_domains[NR_CPUS];
1103 struct event_group *event_group;
1104 int cpu, n = 0; 1068 int cpu, n = 0;
1105 long ret; 1069 long ret;
1106 1070
@@ -1196,9 +1160,7 @@ static void init_global_domain(struct domain_data *dom_data, enum crit_level lev
1196 ce = &entry->crit_entries[level]; 1160 ce = &entry->crit_entries[level];
1197 init_crit_entry(ce, level, dom_data, node); 1161 init_crit_entry(ce, level, dom_data, node);
1198 bheap_node_init(&ce->node, ce); 1162 bheap_node_init(&ce->node, ce);
1199 1163 bheap_insert(cpu_lower_prio, heap, node);
1200 if (cpu != FTRACE_CPU)
1201 bheap_insert(cpu_lower_prio, heap, node);
1202 } 1164 }
1203} 1165}
1204 1166