cputhreads.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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(cpumask_t threads)
  37. {
  38. cpumask_t tmp, res;
  39. int i;
  40. res = CPU_MASK_NONE;
  41. for (i = 0; i < NR_CPUS; i += threads_per_core) {
  42. cpus_shift_left(tmp, threads_core_mask, i);
  43. if (cpus_intersects(threads, tmp))
  44. cpu_set(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_map);
  55. }
  56. static inline int cpu_thread_to_core(int cpu)
  57. {
  58. return cpu >> threads_shift;
  59. }
  60. static inline int cpu_thread_in_core(int cpu)
  61. {
  62. return cpu & (threads_per_core - 1);
  63. }
  64. static inline int cpu_first_thread_in_core(int cpu)
  65. {
  66. return cpu & ~(threads_per_core - 1);
  67. }
  68. static inline int cpu_last_thread_in_core(int cpu)
  69. {
  70. return cpu | (threads_per_core - 1);
  71. }
  72. #endif /* _ASM_POWERPC_CPUTHREADS_H */