[PATCH 1/4] cpumask: Rename cpumask_any_and_distribute

From: Qais Yousef
Date: Tue Apr 14 2020 - 11:07:01 EST


The function is actually an alias of cpumask_any_and(), except that the
new function does the randomization and the old implementation didn't.

Rename the new function to cpumask_any_and() so that old users can take
advantage of its 'enhanced' randomness.

Signed-off-by: Qais Yousef <qais.yousef@xxxxxxx>
CC: Juri Lelli <juri.lelli@xxxxxxxxxx>
CC: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
CC: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
CC: Steven Rostedt <rostedt@xxxxxxxxxxx>
CC: Ben Segall <bsegall@xxxxxxxxxx>
CC: Mel Gorman <mgorman@xxxxxxx>
CC: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
CC: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
CC: Yury Norov <yury.norov@xxxxxxxxx>
CC: Paul Turner <pjt@xxxxxxxxxx>
CC: Alexey Dobriyan <adobriyan@xxxxxxxxx>
CC: Josh Don <joshdon@xxxxxxxxxx>
CC: Pavan Kondeti <pkondeti@xxxxxxxxxxxxxx>
CC: linux-kernel@xxxxxxxxxxxxxxx
---
include/linux/cpumask.h | 17 ++++-------------
kernel/sched/core.c | 2 +-
lib/cpumask.c | 14 ++++++--------
3 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index f0d895d6ac39..e4d6d140a67c 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -194,8 +194,9 @@ static inline unsigned int cpumask_local_spread(unsigned int i, int node)
return 0;
}

-static inline int cpumask_any_and_distribute(const struct cpumask *src1p,
- const struct cpumask *src2p) {
+static inline int cpumask_any_and(const struct cpumask *src1p,
+ const struct cpumask *src2p)
+{
return cpumask_next_and(-1, src1p, src2p);
}

@@ -250,8 +251,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
unsigned int cpumask_local_spread(unsigned int i, int node);
-int cpumask_any_and_distribute(const struct cpumask *src1p,
- const struct cpumask *src2p);
+int cpumask_any_and(const struct cpumask *src1p, const struct cpumask *src2p);

/**
* for_each_cpu - iterate over every cpu in a mask
@@ -617,15 +617,6 @@ static inline void cpumask_copy(struct cpumask *dstp,
*/
#define cpumask_first_and(src1p, src2p) cpumask_next_and(-1, (src1p), (src2p))

-/**
- * cpumask_any_and - pick a "random" cpu from *mask1 & *mask2
- * @mask1: the first input cpumask
- * @mask2: the second input cpumask
- *
- * Returns >= nr_cpu_ids if no cpus set.
- */
-#define cpumask_any_and(mask1, mask2) cpumask_first_and((mask1), (mask2))
-
/**
* cpumask_of - the cpumask containing just a given cpu
* @cpu: the cpu (<= nr_cpu_ids)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index c1f923d647ee..7942ebc83e6e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1655,7 +1655,7 @@ static int __set_cpus_allowed_ptr(struct task_struct *p,
* for groups of tasks (ie. cpuset), so that load balancing is not
* immediately required to distribute the tasks within their new mask.
*/
- dest_cpu = cpumask_any_and_distribute(cpu_valid_mask, new_mask);
+ dest_cpu = cpumask_any_and(cpu_valid_mask, new_mask);
if (dest_cpu >= nr_cpu_ids) {
ret = -EINVAL;
goto out;
diff --git a/lib/cpumask.c b/lib/cpumask.c
index fb22fb266f93..b527a153b023 100644
--- a/lib/cpumask.c
+++ b/lib/cpumask.c
@@ -236,15 +236,13 @@ EXPORT_SYMBOL(cpumask_local_spread);
static DEFINE_PER_CPU(int, distribute_cpu_mask_prev);

/**
- * Returns an arbitrary cpu within srcp1 & srcp2.
+ * cpumask_any_and - pick a "random" cpu from *mask1 & *mask2
+ * @mask1: the first input cpumask
+ * @mask2: the second input cpumask
*
- * Iterated calls using the same srcp1 and srcp2 will be distributed within
- * their intersection.
- *
- * Returns >= nr_cpu_ids if the intersection is empty.
+ * Returns >= nr_cpu_ids if no cpus set.
*/
-int cpumask_any_and_distribute(const struct cpumask *src1p,
- const struct cpumask *src2p)
+int cpumask_any_and(const struct cpumask *src1p, const struct cpumask *src2p)
{
int next, prev;

@@ -260,4 +258,4 @@ int cpumask_any_and_distribute(const struct cpumask *src1p,

return next;
}
-EXPORT_SYMBOL(cpumask_any_and_distribute);
+EXPORT_SYMBOL(cpumask_any_and);
--
2.17.1