cpumask.c (597473720f4dc69749542bfcfed4a927a43d935e) cpumask.c (46a87b3851f0d6eb05e6d83d5c5a30df0eca8f76)
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/slab.h>
3#include <linux/kernel.h>
4#include <linux/bitops.h>
5#include <linux/cpumask.h>
6#include <linux/export.h>
7#include <linux/memblock.h>
8#include <linux/numa.h>

--- 218 unchanged lines hidden (view full) ---

227
228 if (i-- == 0)
229 return cpu;
230 }
231 }
232 BUG();
233}
234EXPORT_SYMBOL(cpumask_local_spread);
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/slab.h>
3#include <linux/kernel.h>
4#include <linux/bitops.h>
5#include <linux/cpumask.h>
6#include <linux/export.h>
7#include <linux/memblock.h>
8#include <linux/numa.h>

--- 218 unchanged lines hidden (view full) ---

227
228 if (i-- == 0)
229 return cpu;
230 }
231 }
232 BUG();
233}
234EXPORT_SYMBOL(cpumask_local_spread);
235
236static DEFINE_PER_CPU(int, distribute_cpu_mask_prev);
237
238/**
239 * Returns an arbitrary cpu within srcp1 & srcp2.
240 *
241 * Iterated calls using the same srcp1 and srcp2 will be distributed within
242 * their intersection.
243 *
244 * Returns >= nr_cpu_ids if the intersection is empty.
245 */
246int cpumask_any_and_distribute(const struct cpumask *src1p,
247 const struct cpumask *src2p)
248{
249 int next, prev;
250
251 /* NOTE: our first selection will skip 0. */
252 prev = __this_cpu_read(distribute_cpu_mask_prev);
253
254 next = cpumask_next_and(prev, src1p, src2p);
255 if (next >= nr_cpu_ids)
256 next = cpumask_first_and(src1p, src2p);
257
258 if (next < nr_cpu_ids)
259 __this_cpu_write(distribute_cpu_mask_prev, next);
260
261 return next;
262}
263EXPORT_SYMBOL(cpumask_any_and_distribute);