cputhreads.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * Note: This implementation is limited to a power of 2 number of
  8. * threads per core and the same number for each core in the system
  9. * (though it would work if some processors had less threads as long
  10. * as the CPU numbers are still allocated, just not brought online).
  11. *
  12. * However, the API allows for a different implementation in the future
  13. * if needed, as long as you only use the functions and not the variables
  14. * directly.
  15. */
  16. #ifdef CONFIG_SMP
  17. extern int threads_per_core;
  18. extern int threads_per_subcore;
  19. extern int threads_shift;
  20. extern cpumask_t threads_core_mask;
  21. #else
  22. #define threads_per_core 1
  23. #define threads_per_subcore 1
  24. #define threads_shift 0
  25. #define threads_core_mask (CPU_MASK_CPU0)
  26. #endif
  27. /* cpu_thread_mask_to_cores - Return a cpumask of one per cores
  28. * hit by the argument
  29. *
  30. * @threads: a cpumask of threads
  31. *
  32. * This function returns a cpumask which will have one "cpu" (or thread)
  33. * bit set for each core that has at least one thread set in the argument.
  34. *
  35. * This can typically be used for things like IPI for tlb invalidations
  36. * since those need to be done only once per core/TLB
  37. */
  38. static inline cpumask_t cpu_thread_mask_to_cores(const struct cpumask *threads)
  39. {
  40. cpumask_t tmp, res;
  41. int i;
  42. cpumask_clear(&res);
  43. for (i = 0; i < NR_CPUS; i += threads_per_core) {
  44. cpumask_shift_left(&tmp, &threads_core_mask, i);
  45. if (cpumask_intersects(threads, &tmp))
  46. cpumask_set_cpu(i, &res);
  47. }
  48. return res;
  49. }
  50. static inline int cpu_nr_cores(void)
  51. {
  52. return nr_cpu_ids >> threads_shift;
  53. }
  54. static inline cpumask_t cpu_online_cores_map(void)
  55. {
  56. return cpu_thread_mask_to_cores(cpu_online_mask);
  57. }
  58. #ifdef CONFIG_SMP
  59. int cpu_core_index_of_thread(int cpu);
  60. int cpu_first_thread_of_core(int core);
  61. #else
  62. static inline int cpu_core_index_of_thread(int cpu) { return cpu; }
  63. static inline int cpu_first_thread_of_core(int core) { return core; }
  64. #endif
  65. static inline int cpu_thread_in_core(int cpu)
  66. {
  67. return cpu & (threads_per_core - 1);
  68. }
  69. static inline int cpu_thread_in_subcore(int cpu)
  70. {
  71. return cpu & (threads_per_subcore - 1);
  72. }
  73. static inline int cpu_first_thread_sibling(int cpu)
  74. {
  75. return cpu & ~(threads_per_core - 1);
  76. }
  77. static inline int cpu_last_thread_sibling(int cpu)
  78. {
  79. return cpu | (threads_per_core - 1);
  80. }
  81. #endif /* _ASM_POWERPC_CPUTHREADS_H */