[PATCH v2 4/4] sched/numa: Convert sched_numa_balancing to a static_branch

From: Srikar Dronamraju
Date: Tue Aug 11 2015 - 12:25:12 EST


Variable sched_numa_balancing toggles numa_balancing feature. Hence
moving from a simple read mostly variable to a more apt static_branch.

Suggested-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Signed-off-by: Srikar Dronamraju <srikar@xxxxxxxxxxxxxxxxxx>
---
kernel/sched/core.c | 10 +++++++---
kernel/sched/fair.c | 6 +++---
kernel/sched/sched.h | 6 +-----
3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index d02570b..5f330d5 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2057,12 +2057,16 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
#endif /* CONFIG_NUMA_BALANCING */
}

+DEFINE_STATIC_KEY_FALSE(sched_numa_balancing);
+
#ifdef CONFIG_NUMA_BALANCING
-__read_mostly bool sched_numa_balancing;

void set_numabalancing_state(bool enabled)
{
- sched_numa_balancing = enabled;
+ if (enabled)
+ static_branch_enable(&sched_numa_balancing);
+ else
+ static_branch_disable(&sched_numa_balancing);
}

#ifdef CONFIG_PROC_SYSCTL
@@ -2071,7 +2075,7 @@ int sysctl_numa_balancing(struct ctl_table *table, int write,
{
struct ctl_table t;
int err;
- int state = sched_numa_balancing;
+ int state = static_branch_likely(&sched_numa_balancing);

if (write && !capable(CAP_SYS_ADMIN))
return -EPERM;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index f67f2bc..aab730e 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2069,7 +2069,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
int local = !!(flags & TNF_FAULT_LOCAL);
int priv;

- if (!sched_numa_balancing)
+ if (!static_branch_likely(&sched_numa_balancing))
return;

/* for example, ksmd faulting in a user's mm */
@@ -5524,7 +5524,7 @@ static int migrate_degrades_locality(struct task_struct *p, struct lb_env *env)
unsigned long src_faults, dst_faults;
int src_nid, dst_nid;

- if (!sched_numa_balancing)
+ if (!static_branch_likely(&sched_numa_balancing))
return -1;

if (!p->numa_faults || !(env->sd->flags & SD_NUMA))
@@ -7810,7 +7810,7 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued)
entity_tick(cfs_rq, se, queued);
}

- if (sched_numa_balancing)
+ if (!static_branch_unlikely(&sched_numa_balancing))
task_tick_numa(rq, curr);
}

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 953be0f..72cae5d 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1003,11 +1003,7 @@ extern struct static_key sched_feat_keys[__SCHED_FEAT_NR];
#define sched_feat(x) (sysctl_sched_features & (1UL << __SCHED_FEAT_##x))
#endif /* SCHED_DEBUG && HAVE_JUMP_LABEL */

-#ifdef CONFIG_NUMA_BALANCING
-extern bool sched_numa_balancing;
-#else
-#define sched_numa_balancing (0)
-#endif /* CONFIG_NUMA_BALANCING */
+extern struct static_key_false sched_numa_balancing;

static inline u64 global_rt_period(void)
{
--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/