cputhreads.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef _ASM_POWERPC_CPUTHREADS_H
  2. #define _ASM_POWERPC_CPUTHREADS_H
  3. #include <linux/cpumask.h>
  4. /*
  5. * Mapping of threads to cores
  6. */
  7. #ifdef CONFIG_SMP
  8. extern int threads_per_core;
  9. extern int threads_shift;
  10. extern cpumask_t threads_core_mask;
  11. #else
  12. #define threads_per_core 1
  13. #define threads_shift 0
  14. #define threads_core_mask (CPU_MASK_CPU0)
  15. #endif
  16. /* cpu_thread_mask_to_cores - Return a cpumask of one per cores
  17. * hit by the argument
  18. *
  19. * @threads: a cpumask of threads
  20. *
  21. * This function returns a cpumask which will have one "cpu" (or thread)
  22. * bit set for each core that has at least one thread set in the argument.
  23. *
  24. * This can typically be used for things like IPI for tlb invalidations
  25. * since those need to be done only once per core/TLB
  26. */
  27. static inline cpumask_t cpu_thread_mask_to_cores(cpumask_t threads)
  28. {
  29. cpumask_t tmp, res;
  30. int i;
  31. res = CPU_MASK_NONE;
  32. for (i = 0; i < NR_CPUS; i += threads_per_core) {
  33. cpus_shift_left(tmp, threads_core_mask, i);
  34. if (cpus_intersects(threads, tmp))
  35. cpu_set(i, res);
  36. }
  37. return res;
  38. }
  39. static inline int cpu_nr_cores(void)
  40. {
  41. return NR_CPUS >> threads_shift;
  42. }
  43. static inline cpumask_t cpu_online_cores_map(void)
  44. {
  45. return cpu_thread_mask_to_cores(cpu_online_map);
  46. }
  47. static inline int cpu_thread_to_core(int cpu)
  48. {
  49. return cpu >> threads_shift;
  50. }
  51. static inline int cpu_thread_in_core(int cpu)
  52. {
  53. return cpu & (threads_per_core - 1);
  54. }
  55. static inline int cpu_first_thread_in_core(int cpu)
  56. {
  57. return cpu & ~(threads_per_core - 1);
  58. }
  59. #endif /* _ASM_POWERPC_CPUTHREADS_H */