mirror of
https://github.com/team-infusion-developers/android_kernel_samsung_msm8976.git
synced 2024-11-01 02:21:16 +00:00
3cc608b4c0
commit c743f0a5c50f2fcbc628526279cfa24f3dabe182 upstream. More users for for_each_cpu_wrap() have appeared. Promote the construct to generic cpumask interface. The implementation is slightly modified to reduce arguments. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Lauro Ramos Venancio <lvenanci@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: lwang@redhat.com Link: http://lkml.kernel.org/r/20170414122005.o35me2h5nowqkxbv@hirez.programming.kicks-ass.net Signed-off-by: Ingo Molnar <mingo@kernel.org> [bwh: Backported to 3.16: there's no old version of the function to delete] Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
198 lines
5.1 KiB
C
198 lines
5.1 KiB
C
#include <linux/slab.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/bitops.h>
|
|
#include <linux/cpumask.h>
|
|
#include <linux/export.h>
|
|
#include <linux/bootmem.h>
|
|
|
|
int __first_cpu(const cpumask_t *srcp)
|
|
{
|
|
return min_t(int, NR_CPUS, find_first_bit(srcp->bits, NR_CPUS));
|
|
}
|
|
EXPORT_SYMBOL(__first_cpu);
|
|
|
|
int __next_cpu(int n, const cpumask_t *srcp)
|
|
{
|
|
return min_t(int, NR_CPUS, find_next_bit(srcp->bits, NR_CPUS, n+1));
|
|
}
|
|
EXPORT_SYMBOL(__next_cpu);
|
|
|
|
#if NR_CPUS > 64
|
|
int __next_cpu_nr(int n, const cpumask_t *srcp)
|
|
{
|
|
return min_t(int, nr_cpu_ids,
|
|
find_next_bit(srcp->bits, nr_cpu_ids, n+1));
|
|
}
|
|
EXPORT_SYMBOL(__next_cpu_nr);
|
|
#endif
|
|
|
|
/**
|
|
* cpumask_next_and - get the next cpu in *src1p & *src2p
|
|
* @n: the cpu prior to the place to search (ie. return will be > @n)
|
|
* @src1p: the first cpumask pointer
|
|
* @src2p: the second cpumask pointer
|
|
*
|
|
* Returns >= nr_cpu_ids if no further cpus set in both.
|
|
*/
|
|
int cpumask_next_and(int n, const struct cpumask *src1p,
|
|
const struct cpumask *src2p)
|
|
{
|
|
while ((n = cpumask_next(n, src1p)) < nr_cpu_ids)
|
|
if (cpumask_test_cpu(n, src2p))
|
|
break;
|
|
return n;
|
|
}
|
|
EXPORT_SYMBOL(cpumask_next_and);
|
|
|
|
/**
|
|
* cpumask_any_but - return a "random" in a cpumask, but not this one.
|
|
* @mask: the cpumask to search
|
|
* @cpu: the cpu to ignore.
|
|
*
|
|
* Often used to find any cpu but smp_processor_id() in a mask.
|
|
* Returns >= nr_cpu_ids if no cpus set.
|
|
*/
|
|
int cpumask_any_but(const struct cpumask *mask, unsigned int cpu)
|
|
{
|
|
unsigned int i;
|
|
|
|
cpumask_check(cpu);
|
|
for_each_cpu(i, mask)
|
|
if (i != cpu)
|
|
break;
|
|
return i;
|
|
}
|
|
|
|
/**
|
|
* cpumask_next_wrap - helper to implement for_each_cpu_wrap
|
|
* @n: the cpu prior to the place to search
|
|
* @mask: the cpumask pointer
|
|
* @start: the start point of the iteration
|
|
* @wrap: assume @n crossing @start terminates the iteration
|
|
*
|
|
* Returns >= nr_cpu_ids on completion
|
|
*
|
|
* Note: the @wrap argument is required for the start condition when
|
|
* we cannot assume @start is set in @mask.
|
|
*/
|
|
int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap)
|
|
{
|
|
int next;
|
|
|
|
again:
|
|
next = cpumask_next(n, mask);
|
|
|
|
if (wrap && n < start && next >= start) {
|
|
return nr_cpumask_bits;
|
|
|
|
} else if (next >= nr_cpumask_bits) {
|
|
wrap = true;
|
|
n = -1;
|
|
goto again;
|
|
}
|
|
|
|
return next;
|
|
}
|
|
EXPORT_SYMBOL(cpumask_next_wrap);
|
|
|
|
/* These are not inline because of header tangles. */
|
|
#ifdef CONFIG_CPUMASK_OFFSTACK
|
|
/**
|
|
* alloc_cpumask_var_node - allocate a struct cpumask on a given node
|
|
* @mask: pointer to cpumask_var_t where the cpumask is returned
|
|
* @flags: GFP_ flags
|
|
*
|
|
* Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is
|
|
* a nop returning a constant 1 (in <linux/cpumask.h>)
|
|
* Returns TRUE if memory allocation succeeded, FALSE otherwise.
|
|
*
|
|
* In addition, mask will be NULL if this fails. Note that gcc is
|
|
* usually smart enough to know that mask can never be NULL if
|
|
* CONFIG_CPUMASK_OFFSTACK=n, so does code elimination in that case
|
|
* too.
|
|
*/
|
|
bool alloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)
|
|
{
|
|
*mask = kmalloc_node(cpumask_size(), flags, node);
|
|
|
|
#ifdef CONFIG_DEBUG_PER_CPU_MAPS
|
|
if (!*mask) {
|
|
printk(KERN_ERR "=> alloc_cpumask_var: failed!\n");
|
|
dump_stack();
|
|
}
|
|
#endif
|
|
/* FIXME: Bandaid to save us from old primitives which go to NR_CPUS. */
|
|
if (*mask) {
|
|
unsigned char *ptr = (unsigned char *)cpumask_bits(*mask);
|
|
unsigned int tail;
|
|
tail = BITS_TO_LONGS(NR_CPUS - nr_cpumask_bits) * sizeof(long);
|
|
memset(ptr + cpumask_size() - tail, 0, tail);
|
|
}
|
|
|
|
return *mask != NULL;
|
|
}
|
|
EXPORT_SYMBOL(alloc_cpumask_var_node);
|
|
|
|
bool zalloc_cpumask_var_node(cpumask_var_t *mask, gfp_t flags, int node)
|
|
{
|
|
return alloc_cpumask_var_node(mask, flags | __GFP_ZERO, node);
|
|
}
|
|
EXPORT_SYMBOL(zalloc_cpumask_var_node);
|
|
|
|
/**
|
|
* alloc_cpumask_var - allocate a struct cpumask
|
|
* @mask: pointer to cpumask_var_t where the cpumask is returned
|
|
* @flags: GFP_ flags
|
|
*
|
|
* Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is
|
|
* a nop returning a constant 1 (in <linux/cpumask.h>).
|
|
*
|
|
* See alloc_cpumask_var_node.
|
|
*/
|
|
bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
|
|
{
|
|
return alloc_cpumask_var_node(mask, flags, NUMA_NO_NODE);
|
|
}
|
|
EXPORT_SYMBOL(alloc_cpumask_var);
|
|
|
|
bool zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags)
|
|
{
|
|
return alloc_cpumask_var(mask, flags | __GFP_ZERO);
|
|
}
|
|
EXPORT_SYMBOL(zalloc_cpumask_var);
|
|
|
|
/**
|
|
* alloc_bootmem_cpumask_var - allocate a struct cpumask from the bootmem arena.
|
|
* @mask: pointer to cpumask_var_t where the cpumask is returned
|
|
*
|
|
* Only defined when CONFIG_CPUMASK_OFFSTACK=y, otherwise is
|
|
* a nop (in <linux/cpumask.h>).
|
|
* Either returns an allocated (zero-filled) cpumask, or causes the
|
|
* system to panic.
|
|
*/
|
|
void __init alloc_bootmem_cpumask_var(cpumask_var_t *mask)
|
|
{
|
|
*mask = alloc_bootmem(cpumask_size());
|
|
}
|
|
|
|
/**
|
|
* free_cpumask_var - frees memory allocated for a struct cpumask.
|
|
* @mask: cpumask to free
|
|
*
|
|
* This is safe on a NULL mask.
|
|
*/
|
|
void free_cpumask_var(cpumask_var_t mask)
|
|
{
|
|
kfree(mask);
|
|
}
|
|
EXPORT_SYMBOL(free_cpumask_var);
|
|
|
|
/**
|
|
* free_bootmem_cpumask_var - frees result of alloc_bootmem_cpumask_var
|
|
* @mask: cpumask to free
|
|
*/
|
|
void __init free_bootmem_cpumask_var(cpumask_var_t mask)
|
|
{
|
|
free_bootmem(__pa(mask), cpumask_size());
|
|
}
|
|
#endif
|