diff options
author | Peter Zijlstra <peterz@infradead.org> | 2017-12-21 04:01:24 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2018-03-09 01:59:16 -0500 |
commit | a22e47a4e3f5a9e50a827c5d94705ace3b1eac0b (patch) | |
tree | 907cfb61b5233db6935d234e9de615796d137acf | |
parent | 8f111bc357aa811e0bb5fdfe34c4c9efdafc15b9 (diff) |
sched/core: Convert nohz_flags to atomic_t
Using atomic_t allows us to use the more flexible bitops provided
there. Also its smaller.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | kernel/sched/core.c | 6 | ||||
-rw-r--r-- | kernel/sched/fair.c | 23 | ||||
-rw-r--r-- | kernel/sched/sched.h | 11 |
3 files changed, 24 insertions, 16 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 4f5eeb63ab5b..96ad1c003d74 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -583,7 +583,7 @@ static inline bool got_nohz_idle_kick(void) | |||
583 | { | 583 | { |
584 | int cpu = smp_processor_id(); | 584 | int cpu = smp_processor_id(); |
585 | 585 | ||
586 | if (!test_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu))) | 586 | if (!(atomic_read(nohz_flags(cpu)) & NOHZ_BALANCE_KICK)) |
587 | return false; | 587 | return false; |
588 | 588 | ||
589 | if (idle_cpu(cpu) && !need_resched()) | 589 | if (idle_cpu(cpu) && !need_resched()) |
@@ -593,7 +593,7 @@ static inline bool got_nohz_idle_kick(void) | |||
593 | * We can't run Idle Load Balance on this CPU for this time so we | 593 | * We can't run Idle Load Balance on this CPU for this time so we |
594 | * cancel it and clear NOHZ_BALANCE_KICK | 594 | * cancel it and clear NOHZ_BALANCE_KICK |
595 | */ | 595 | */ |
596 | clear_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu)); | 596 | atomic_andnot(NOHZ_BALANCE_KICK, nohz_flags(cpu)); |
597 | return false; | 597 | return false; |
598 | } | 598 | } |
599 | 599 | ||
@@ -6074,7 +6074,7 @@ void __init sched_init(void) | |||
6074 | rq_attach_root(rq, &def_root_domain); | 6074 | rq_attach_root(rq, &def_root_domain); |
6075 | #ifdef CONFIG_NO_HZ_COMMON | 6075 | #ifdef CONFIG_NO_HZ_COMMON |
6076 | rq->last_load_update_tick = jiffies; | 6076 | rq->last_load_update_tick = jiffies; |
6077 | rq->nohz_flags = 0; | 6077 | atomic_set(&rq->nohz_flags, 0); |
6078 | #endif | 6078 | #endif |
6079 | #endif /* CONFIG_SMP */ | 6079 | #endif /* CONFIG_SMP */ |
6080 | hrtick_rq_init(rq); | 6080 | hrtick_rq_init(rq); |
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 097db34d5ba2..5d150478dd58 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c | |||
@@ -9072,6 +9072,7 @@ static inline int find_new_ilb(void) | |||
9072 | */ | 9072 | */ |
9073 | static void nohz_balancer_kick(void) | 9073 | static void nohz_balancer_kick(void) |
9074 | { | 9074 | { |
9075 | unsigned int flags; | ||
9075 | int ilb_cpu; | 9076 | int ilb_cpu; |
9076 | 9077 | ||
9077 | nohz.next_balance++; | 9078 | nohz.next_balance++; |
@@ -9081,7 +9082,8 @@ static void nohz_balancer_kick(void) | |||
9081 | if (ilb_cpu >= nr_cpu_ids) | 9082 | if (ilb_cpu >= nr_cpu_ids) |
9082 | return; | 9083 | return; |
9083 | 9084 | ||
9084 | if (test_and_set_bit(NOHZ_BALANCE_KICK, nohz_flags(ilb_cpu))) | 9085 | flags = atomic_fetch_or(NOHZ_BALANCE_KICK, nohz_flags(ilb_cpu)); |
9086 | if (flags & NOHZ_BALANCE_KICK) | ||
9085 | return; | 9087 | return; |
9086 | /* | 9088 | /* |
9087 | * Use smp_send_reschedule() instead of resched_cpu(). | 9089 | * Use smp_send_reschedule() instead of resched_cpu(). |
@@ -9095,7 +9097,9 @@ static void nohz_balancer_kick(void) | |||
9095 | 9097 | ||
9096 | void nohz_balance_exit_idle(unsigned int cpu) | 9098 | void nohz_balance_exit_idle(unsigned int cpu) |
9097 | { | 9099 | { |
9098 | if (unlikely(test_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu)))) { | 9100 | unsigned int flags = atomic_read(nohz_flags(cpu)); |
9101 | |||
9102 | if (unlikely(flags & NOHZ_TICK_STOPPED)) { | ||
9099 | /* | 9103 | /* |
9100 | * Completely isolated CPUs don't ever set, so we must test. | 9104 | * Completely isolated CPUs don't ever set, so we must test. |
9101 | */ | 9105 | */ |
@@ -9103,7 +9107,8 @@ void nohz_balance_exit_idle(unsigned int cpu) | |||
9103 | cpumask_clear_cpu(cpu, nohz.idle_cpus_mask); | 9107 | cpumask_clear_cpu(cpu, nohz.idle_cpus_mask); |
9104 | atomic_dec(&nohz.nr_cpus); | 9108 | atomic_dec(&nohz.nr_cpus); |
9105 | } | 9109 | } |
9106 | clear_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu)); | 9110 | |
9111 | atomic_andnot(NOHZ_TICK_STOPPED, nohz_flags(cpu)); | ||
9107 | } | 9112 | } |
9108 | } | 9113 | } |
9109 | 9114 | ||
@@ -9155,7 +9160,7 @@ void nohz_balance_enter_idle(int cpu) | |||
9155 | if (!housekeeping_cpu(cpu, HK_FLAG_SCHED)) | 9160 | if (!housekeeping_cpu(cpu, HK_FLAG_SCHED)) |
9156 | return; | 9161 | return; |
9157 | 9162 | ||
9158 | if (test_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu))) | 9163 | if (atomic_read(nohz_flags(cpu)) & NOHZ_TICK_STOPPED) |
9159 | return; | 9164 | return; |
9160 | 9165 | ||
9161 | /* If we're a completely isolated CPU, we don't play: */ | 9166 | /* If we're a completely isolated CPU, we don't play: */ |
@@ -9164,7 +9169,7 @@ void nohz_balance_enter_idle(int cpu) | |||
9164 | 9169 | ||
9165 | cpumask_set_cpu(cpu, nohz.idle_cpus_mask); | 9170 | cpumask_set_cpu(cpu, nohz.idle_cpus_mask); |
9166 | atomic_inc(&nohz.nr_cpus); | 9171 | atomic_inc(&nohz.nr_cpus); |
9167 | set_bit(NOHZ_TICK_STOPPED, nohz_flags(cpu)); | 9172 | atomic_or(NOHZ_TICK_STOPPED, nohz_flags(cpu)); |
9168 | } | 9173 | } |
9169 | #endif | 9174 | #endif |
9170 | 9175 | ||
@@ -9302,8 +9307,10 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) | |||
9302 | unsigned long next_balance = jiffies + 60*HZ; | 9307 | unsigned long next_balance = jiffies + 60*HZ; |
9303 | int update_next_balance = 0; | 9308 | int update_next_balance = 0; |
9304 | 9309 | ||
9305 | if (idle != CPU_IDLE || | 9310 | if (!(atomic_read(nohz_flags(this_cpu)) & NOHZ_BALANCE_KICK)) |
9306 | !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu))) | 9311 | return; |
9312 | |||
9313 | if (idle != CPU_IDLE) | ||
9307 | goto end; | 9314 | goto end; |
9308 | 9315 | ||
9309 | for_each_cpu(balance_cpu, nohz.idle_cpus_mask) { | 9316 | for_each_cpu(balance_cpu, nohz.idle_cpus_mask) { |
@@ -9349,7 +9356,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) | |||
9349 | if (likely(update_next_balance)) | 9356 | if (likely(update_next_balance)) |
9350 | nohz.next_balance = next_balance; | 9357 | nohz.next_balance = next_balance; |
9351 | end: | 9358 | end: |
9352 | clear_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)); | 9359 | atomic_andnot(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)); |
9353 | } | 9360 | } |
9354 | 9361 | ||
9355 | /* | 9362 | /* |
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 23ba4dd76ac4..d98e761b962f 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h | |||
@@ -763,7 +763,7 @@ struct rq { | |||
763 | #ifdef CONFIG_SMP | 763 | #ifdef CONFIG_SMP |
764 | unsigned long last_load_update_tick; | 764 | unsigned long last_load_update_tick; |
765 | #endif /* CONFIG_SMP */ | 765 | #endif /* CONFIG_SMP */ |
766 | unsigned long nohz_flags; | 766 | atomic_t nohz_flags; |
767 | #endif /* CONFIG_NO_HZ_COMMON */ | 767 | #endif /* CONFIG_NO_HZ_COMMON */ |
768 | 768 | ||
769 | /* capture load from *all* tasks on this CPU: */ | 769 | /* capture load from *all* tasks on this CPU: */ |
@@ -2034,10 +2034,11 @@ extern void cfs_bandwidth_usage_inc(void); | |||
2034 | extern void cfs_bandwidth_usage_dec(void); | 2034 | extern void cfs_bandwidth_usage_dec(void); |
2035 | 2035 | ||
2036 | #ifdef CONFIG_NO_HZ_COMMON | 2036 | #ifdef CONFIG_NO_HZ_COMMON |
2037 | enum rq_nohz_flag_bits { | 2037 | #define NOHZ_TICK_STOPPED_BIT 0 |
2038 | NOHZ_TICK_STOPPED, | 2038 | #define NOHZ_BALANCE_KICK_BIT 1 |
2039 | NOHZ_BALANCE_KICK, | 2039 | |
2040 | }; | 2040 | #define NOHZ_TICK_STOPPED BIT(NOHZ_TICK_STOPPED_BIT) |
2041 | #define NOHZ_BALANCE_KICK BIT(NOHZ_BALANCE_KICK_BIT) | ||
2041 | 2042 | ||
2042 | #define nohz_flags(cpu) (&cpu_rq(cpu)->nohz_flags) | 2043 | #define nohz_flags(cpu) (&cpu_rq(cpu)->nohz_flags) |
2043 | 2044 | ||