Path: blob/master/arch/powerpc/include/asm/cputhreads.h
15117 views
#ifndef _ASM_POWERPC_CPUTHREADS_H1#define _ASM_POWERPC_CPUTHREADS_H23#include <linux/cpumask.h>45/*6* Mapping of threads to cores7*8* Note: This implementation is limited to a power of 2 number of9* threads per core and the same number for each core in the system10* (though it would work if some processors had less threads as long11* as the CPU numbers are still allocated, just not brought offline).12*13* However, the API allows for a different implementation in the future14* if needed, as long as you only use the functions and not the variables15* directly.16*/1718#ifdef CONFIG_SMP19extern int threads_per_core;20extern int threads_shift;21extern cpumask_t threads_core_mask;22#else23#define threads_per_core 124#define threads_shift 025#define threads_core_mask (CPU_MASK_CPU0)26#endif2728/* cpu_thread_mask_to_cores - Return a cpumask of one per cores29* hit by the argument30*31* @threads: a cpumask of threads32*33* This function returns a cpumask which will have one "cpu" (or thread)34* bit set for each core that has at least one thread set in the argument.35*36* This can typically be used for things like IPI for tlb invalidations37* since those need to be done only once per core/TLB38*/39static inline cpumask_t cpu_thread_mask_to_cores(const struct cpumask *threads)40{41cpumask_t tmp, res;42int i;4344cpumask_clear(&res);45for (i = 0; i < NR_CPUS; i += threads_per_core) {46cpumask_shift_left(&tmp, &threads_core_mask, i);47if (cpumask_intersects(threads, &tmp))48cpumask_set_cpu(i, &res);49}50return res;51}5253static inline int cpu_nr_cores(void)54{55return NR_CPUS >> threads_shift;56}5758static inline cpumask_t cpu_online_cores_map(void)59{60return cpu_thread_mask_to_cores(cpu_online_mask);61}6263#ifdef CONFIG_SMP64int cpu_core_index_of_thread(int cpu);65int cpu_first_thread_of_core(int core);66#else67static inline int cpu_core_index_of_thread(int cpu) { return cpu; }68static inline int cpu_first_thread_of_core(int core) { return core; }69#endif7071static inline int cpu_thread_in_core(int cpu)72{73return cpu & (threads_per_core - 1);74}7576static inline int cpu_first_thread_sibling(int cpu)77{78return cpu & ~(threads_per_core - 1);79}8081static inline int cpu_last_thread_sibling(int cpu)82{83return cpu | (threads_per_core - 1);84}85868788#endif /* _ASM_POWERPC_CPUTHREADS_H */89909192