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