Skip to content

Commit 0e369d7

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched/core: Replace sd_busy/nr_busy_cpus with sched_domain_shared
Move the nr_busy_cpus thing from its hacky sd->parent->groups->sgc location into the much more natural sched_domain_shared location. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 24fc7ed commit 0e369d7

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

include/linux/sched.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ struct sched_group;
10691069

10701070
struct sched_domain_shared {
10711071
atomic_t ref;
1072+
atomic_t nr_busy_cpus;
10721073
};
10731074

10741075
struct sched_domain {

kernel/sched/core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5981,28 +5981,28 @@ static void destroy_sched_domains(struct sched_domain *sd)
59815981
DEFINE_PER_CPU(struct sched_domain *, sd_llc);
59825982
DEFINE_PER_CPU(int, sd_llc_size);
59835983
DEFINE_PER_CPU(int, sd_llc_id);
5984+
DEFINE_PER_CPU(struct sched_domain_shared *, sd_llc_shared);
59845985
DEFINE_PER_CPU(struct sched_domain *, sd_numa);
5985-
DEFINE_PER_CPU(struct sched_domain *, sd_busy);
59865986
DEFINE_PER_CPU(struct sched_domain *, sd_asym);
59875987

59885988
static void update_top_cache_domain(int cpu)
59895989
{
5990+
struct sched_domain_shared *sds = NULL;
59905991
struct sched_domain *sd;
5991-
struct sched_domain *busy_sd = NULL;
59925992
int id = cpu;
59935993
int size = 1;
59945994

59955995
sd = highest_flag_domain(cpu, SD_SHARE_PKG_RESOURCES);
59965996
if (sd) {
59975997
id = cpumask_first(sched_domain_span(sd));
59985998
size = cpumask_weight(sched_domain_span(sd));
5999-
busy_sd = sd->parent; /* sd_busy */
5999+
sds = sd->shared;
60006000
}
6001-
rcu_assign_pointer(per_cpu(sd_busy, cpu), busy_sd);
60026001

60036002
rcu_assign_pointer(per_cpu(sd_llc, cpu), sd);
60046003
per_cpu(sd_llc_size, cpu) = size;
60056004
per_cpu(sd_llc_id, cpu) = id;
6005+
rcu_assign_pointer(per_cpu(sd_llc_shared, cpu), sds);
60066006

60076007
sd = lowest_flag_domain(cpu, SD_NUMA);
60086008
rcu_assign_pointer(per_cpu(sd_numa, cpu), sd);
@@ -6299,7 +6299,6 @@ static void init_sched_groups_capacity(int cpu, struct sched_domain *sd)
62996299
return;
63006300

63016301
update_group_capacity(sd, cpu);
6302-
atomic_set(&sg->sgc->nr_busy_cpus, sg->group_weight);
63036302
}
63046303

63056304
/*
@@ -6546,6 +6545,7 @@ sd_init(struct sched_domain_topology_level *tl,
65466545
if (sd->flags & SD_SHARE_PKG_RESOURCES) {
65476546
sd->shared = *per_cpu_ptr(sdd->sds, sd_id);
65486547
atomic_inc(&sd->shared->ref);
6548+
atomic_set(&sd->shared->nr_busy_cpus, sd_weight);
65496549
}
65506550

65516551
sd->private = sdd;

kernel/sched/fair.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8008,13 +8008,13 @@ static inline void set_cpu_sd_state_busy(void)
80088008
int cpu = smp_processor_id();
80098009

80108010
rcu_read_lock();
8011-
sd = rcu_dereference(per_cpu(sd_busy, cpu));
8011+
sd = rcu_dereference(per_cpu(sd_llc, cpu));
80128012

80138013
if (!sd || !sd->nohz_idle)
80148014
goto unlock;
80158015
sd->nohz_idle = 0;
80168016

8017-
atomic_inc(&sd->groups->sgc->nr_busy_cpus);
8017+
atomic_inc(&sd->shared->nr_busy_cpus);
80188018
unlock:
80198019
rcu_read_unlock();
80208020
}
@@ -8025,13 +8025,13 @@ void set_cpu_sd_state_idle(void)
80258025
int cpu = smp_processor_id();
80268026

80278027
rcu_read_lock();
8028-
sd = rcu_dereference(per_cpu(sd_busy, cpu));
8028+
sd = rcu_dereference(per_cpu(sd_llc, cpu));
80298029

80308030
if (!sd || sd->nohz_idle)
80318031
goto unlock;
80328032
sd->nohz_idle = 1;
80338033

8034-
atomic_dec(&sd->groups->sgc->nr_busy_cpus);
8034+
atomic_dec(&sd->shared->nr_busy_cpus);
80358035
unlock:
80368036
rcu_read_unlock();
80378037
}
@@ -8258,8 +8258,8 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
82588258
static inline bool nohz_kick_needed(struct rq *rq)
82598259
{
82608260
unsigned long now = jiffies;
8261+
struct sched_domain_shared *sds;
82618262
struct sched_domain *sd;
8262-
struct sched_group_capacity *sgc;
82638263
int nr_busy, cpu = rq->cpu;
82648264
bool kick = false;
82658265

@@ -8287,11 +8287,13 @@ static inline bool nohz_kick_needed(struct rq *rq)
82878287
return true;
82888288

82898289
rcu_read_lock();
8290-
sd = rcu_dereference(per_cpu(sd_busy, cpu));
8291-
if (sd) {
8292-
sgc = sd->groups->sgc;
8293-
nr_busy = atomic_read(&sgc->nr_busy_cpus);
8294-
8290+
sds = rcu_dereference(per_cpu(sd_llc_shared, cpu));
8291+
if (sds) {
8292+
/*
8293+
* XXX: write a coherent comment on why we do this.
8294+
* See also: http://lkml.kernel.org/r/[email protected]
8295+
*/
8296+
nr_busy = atomic_read(&sds->nr_busy_cpus);
82958297
if (nr_busy > 1) {
82968298
kick = true;
82978299
goto unlock;

kernel/sched/sched.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -858,8 +858,8 @@ static inline struct sched_domain *lowest_flag_domain(int cpu, int flag)
858858
DECLARE_PER_CPU(struct sched_domain *, sd_llc);
859859
DECLARE_PER_CPU(int, sd_llc_size);
860860
DECLARE_PER_CPU(int, sd_llc_id);
861+
DECLARE_PER_CPU(struct sched_domain_shared *, sd_llc_shared);
861862
DECLARE_PER_CPU(struct sched_domain *, sd_numa);
862-
DECLARE_PER_CPU(struct sched_domain *, sd_busy);
863863
DECLARE_PER_CPU(struct sched_domain *, sd_asym);
864864

865865
struct sched_group_capacity {
@@ -871,10 +871,6 @@ struct sched_group_capacity {
871871
unsigned int capacity;
872872
unsigned long next_update;
873873
int imbalance; /* XXX unrelated to capacity but shared group state */
874-
/*
875-
* Number of busy cpus in this group.
876-
*/
877-
atomic_t nr_busy_cpus;
878874

879875
unsigned long cpumask[0]; /* iteration mask */
880876
};

0 commit comments

Comments
 (0)