cputhreads.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 offline).
  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_shift;
  19. extern cpumask_t threads_core_mask;
  20. #else
  21. #define threads_per_core 1
  22. #define threads_shift 0
  23. #define threads_core_mask (CPU_MASK_CPU0)
  24. #endif
  25. /* cpu_thread_mask_to_cores - Return a cpumask of one per cores
  26. * hit by the argument
  27. *
  28. * @threads: a cpumask of threads
  29. *
  30. * This function returns a cpumask which will have one "cpu" (or thread)
  31. * bit set for each core that has at least one thread set in the argument.
  32. *
  33. * This can typically be used for things like IPI for tlb invalidations
  34. * since those need to be done only once per core/TLB
  35. */
  36. static inline cpumask_t cpu_thread_mask_to_cores(const struct cpumask *threads)
  37. {
  38. cpumask_t tmp, res;
  39. int i;
  40. cpumask_clear(&res);
  41. for (i = 0; i < NR_CPUS; i += threads_per_core) {
  42. cpumask_shift_left(&tmp, &threads_core_mask, i);
  43. if (cpumask_intersects(threads, &tmp))
  44. cpumask_set_cpu(i, &res);
  45. }
  46. return res;
  47. }
  48. static inline int cpu_nr_cores(void)
  49. {
  50. return NR_CPUS >> threads_shift;
  51. }
  52. static inline cpumask_t cpu_online_cores_map(void)
  53. {
  54. return cpu_thread_mask_to_cores(cpu_online_mask);
  55. }
  56. #ifdef CONFIG_SMP
  57. int cpu_core_index_of_thread(int cpu);
  58. int cpu_first_thread_of_core(int core);
  59. #else
  60. static inline int cpu_core_index_of_thread(int cpu) { return cpu; }
  61. static inline int cpu_first_thread_of_core(int core) { return core; }
  62. #endif
  63. static inline int cpu_thread_in_core(int cpu)
  64. {
  65. return cpu & (threads_per_core - 1);
  66. }
  67. static inline int cpu_first_thread_sibling(int cpu)
  68. {
  69. return cpu & ~(threads_per_core - 1);
  70. }
  71. static inline int cpu_last_thread_sibling(int cpu)
  72. {
  73. return cpu | (threads_per_core - 1);
  74. }
  75. #endif /* _ASM_POWERPC_CPUTHREADS_H */