Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 1 | #include "sched.h" |
| 2 | |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 3 | /* |
| 4 | * stop-task scheduling class. |
| 5 | * |
| 6 | * The stop task is the highest priority task in the system, it preempts |
| 7 | * everything and will be preempted by nothing. |
| 8 | * |
| 9 | * See kernel/stop_machine.c |
| 10 | */ |
| 11 | |
| 12 | #ifdef CONFIG_SMP |
| 13 | static int |
Peter Zijlstra | ac66f54 | 2013-10-07 11:29:16 +0100 | [diff] [blame] | 14 | select_task_rq_stop(struct task_struct *p, int cpu, int sd_flag, int flags) |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 15 | { |
| 16 | return task_cpu(p); /* stop tasks as never migrate */ |
| 17 | } |
| 18 | #endif /* CONFIG_SMP */ |
| 19 | |
| 20 | static void |
| 21 | check_preempt_curr_stop(struct rq *rq, struct task_struct *p, int flags) |
| 22 | { |
Peter Zijlstra | 1e5a740 | 2010-10-31 12:37:04 +0100 | [diff] [blame] | 23 | /* we're never preempted */ |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | static struct task_struct *pick_next_task_stop(struct rq *rq) |
| 27 | { |
| 28 | struct task_struct *stop = rq->stop; |
| 29 | |
Mike Galbraith | 8f61896 | 2012-08-04 05:44:14 +0200 | [diff] [blame] | 30 | if (stop && stop->on_rq) { |
Frederic Weisbecker | 78becc2 | 2013-04-12 01:51:02 +0200 | [diff] [blame] | 31 | stop->se.exec_start = rq_clock_task(rq); |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 32 | return stop; |
Mike Galbraith | 8f61896 | 2012-08-04 05:44:14 +0200 | [diff] [blame] | 33 | } |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 34 | |
| 35 | return NULL; |
| 36 | } |
| 37 | |
| 38 | static void |
| 39 | enqueue_task_stop(struct rq *rq, struct task_struct *p, int flags) |
| 40 | { |
Paul Turner | 953bfcd | 2011-07-21 09:43:27 -0700 | [diff] [blame] | 41 | inc_nr_running(rq); |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static void |
| 45 | dequeue_task_stop(struct rq *rq, struct task_struct *p, int flags) |
| 46 | { |
Paul Turner | 953bfcd | 2011-07-21 09:43:27 -0700 | [diff] [blame] | 47 | dec_nr_running(rq); |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void yield_task_stop(struct rq *rq) |
| 51 | { |
| 52 | BUG(); /* the stop task should never yield, its pointless. */ |
| 53 | } |
| 54 | |
| 55 | static void put_prev_task_stop(struct rq *rq, struct task_struct *prev) |
| 56 | { |
Mike Galbraith | 8f61896 | 2012-08-04 05:44:14 +0200 | [diff] [blame] | 57 | struct task_struct *curr = rq->curr; |
| 58 | u64 delta_exec; |
| 59 | |
Frederic Weisbecker | 78becc2 | 2013-04-12 01:51:02 +0200 | [diff] [blame] | 60 | delta_exec = rq_clock_task(rq) - curr->se.exec_start; |
Mike Galbraith | 8f61896 | 2012-08-04 05:44:14 +0200 | [diff] [blame] | 61 | if (unlikely((s64)delta_exec < 0)) |
| 62 | delta_exec = 0; |
| 63 | |
| 64 | schedstat_set(curr->se.statistics.exec_max, |
| 65 | max(curr->se.statistics.exec_max, delta_exec)); |
| 66 | |
| 67 | curr->se.sum_exec_runtime += delta_exec; |
| 68 | account_group_exec_runtime(curr, delta_exec); |
| 69 | |
Frederic Weisbecker | 78becc2 | 2013-04-12 01:51:02 +0200 | [diff] [blame] | 70 | curr->se.exec_start = rq_clock_task(rq); |
Mike Galbraith | 8f61896 | 2012-08-04 05:44:14 +0200 | [diff] [blame] | 71 | cpuacct_charge(curr, delta_exec); |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static void task_tick_stop(struct rq *rq, struct task_struct *curr, int queued) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | static void set_curr_task_stop(struct rq *rq) |
| 79 | { |
Mike Galbraith | 8f61896 | 2012-08-04 05:44:14 +0200 | [diff] [blame] | 80 | struct task_struct *stop = rq->stop; |
| 81 | |
Frederic Weisbecker | 78becc2 | 2013-04-12 01:51:02 +0200 | [diff] [blame] | 82 | stop->se.exec_start = rq_clock_task(rq); |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Peter Zijlstra | da7a735 | 2011-01-17 17:03:27 +0100 | [diff] [blame] | 85 | static void switched_to_stop(struct rq *rq, struct task_struct *p) |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 86 | { |
| 87 | BUG(); /* its impossible to change to this class */ |
| 88 | } |
| 89 | |
Peter Zijlstra | da7a735 | 2011-01-17 17:03:27 +0100 | [diff] [blame] | 90 | static void |
| 91 | prio_changed_stop(struct rq *rq, struct task_struct *p, int oldprio) |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 92 | { |
| 93 | BUG(); /* how!?, what priority? */ |
| 94 | } |
| 95 | |
| 96 | static unsigned int |
| 97 | get_rr_interval_stop(struct rq *rq, struct task_struct *task) |
| 98 | { |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | /* |
| 103 | * Simple, special scheduling class for the per-CPU stop tasks: |
| 104 | */ |
Peter Zijlstra | 029632f | 2011-10-25 10:00:11 +0200 | [diff] [blame] | 105 | const struct sched_class stop_sched_class = { |
Dario Faggioli | aab03e0 | 2013-11-28 11:14:43 +0100 | [diff] [blame] | 106 | .next = &dl_sched_class, |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 107 | |
| 108 | .enqueue_task = enqueue_task_stop, |
| 109 | .dequeue_task = dequeue_task_stop, |
| 110 | .yield_task = yield_task_stop, |
| 111 | |
| 112 | .check_preempt_curr = check_preempt_curr_stop, |
| 113 | |
| 114 | .pick_next_task = pick_next_task_stop, |
| 115 | .put_prev_task = put_prev_task_stop, |
| 116 | |
| 117 | #ifdef CONFIG_SMP |
| 118 | .select_task_rq = select_task_rq_stop, |
| 119 | #endif |
| 120 | |
| 121 | .set_curr_task = set_curr_task_stop, |
| 122 | .task_tick = task_tick_stop, |
| 123 | |
| 124 | .get_rr_interval = get_rr_interval_stop, |
| 125 | |
| 126 | .prio_changed = prio_changed_stop, |
| 127 | .switched_to = switched_to_stop, |
Peter Zijlstra | 34f971f | 2010-09-22 13:53:15 +0200 | [diff] [blame] | 128 | }; |