Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 1 | #ifndef _ASM_POWERPC_CPUTHREADS_H |
| 2 | #define _ASM_POWERPC_CPUTHREADS_H |
| 3 | |
chenhui zhao | 6becef7 | 2015-11-20 17:14:02 +0800 | [diff] [blame] | 4 | #ifndef __ASSEMBLY__ |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 5 | #include <linux/cpumask.h> |
| 6 | |
| 7 | /* |
| 8 | * Mapping of threads to cores |
Benjamin Herrenschmidt | fcce810 | 2009-07-23 23:15:10 +0000 | [diff] [blame] | 9 | * |
| 10 | * Note: This implementation is limited to a power of 2 number of |
| 11 | * threads per core and the same number for each core in the system |
| 12 | * (though it would work if some processors had less threads as long |
Anshuman Khandual | 933b90a | 2012-05-14 05:32:00 +0000 | [diff] [blame] | 13 | * as the CPU numbers are still allocated, just not brought online). |
Benjamin Herrenschmidt | fcce810 | 2009-07-23 23:15:10 +0000 | [diff] [blame] | 14 | * |
| 15 | * However, the API allows for a different implementation in the future |
| 16 | * if needed, as long as you only use the functions and not the variables |
| 17 | * directly. |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #ifdef CONFIG_SMP |
| 21 | extern int threads_per_core; |
Michael Ellerman | 5853aef | 2014-05-23 18:15:27 +1000 | [diff] [blame] | 22 | extern int threads_per_subcore; |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 23 | extern int threads_shift; |
| 24 | extern cpumask_t threads_core_mask; |
| 25 | #else |
| 26 | #define threads_per_core 1 |
Michael Ellerman | 5853aef | 2014-05-23 18:15:27 +1000 | [diff] [blame] | 27 | #define threads_per_subcore 1 |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 28 | #define threads_shift 0 |
Rusty Russell | 87313df | 2015-03-10 12:28:29 +1030 | [diff] [blame] | 29 | #define threads_core_mask (*get_cpu_mask(0)) |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 30 | #endif |
| 31 | |
| 32 | /* cpu_thread_mask_to_cores - Return a cpumask of one per cores |
| 33 | * hit by the argument |
| 34 | * |
Shreyas B. Prabhu | e602ffb | 2015-04-20 10:32:56 +0530 | [diff] [blame] | 35 | * @threads: a cpumask of online threads |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 36 | * |
Shreyas B. Prabhu | e602ffb | 2015-04-20 10:32:56 +0530 | [diff] [blame] | 37 | * This function returns a cpumask which will have one online cpu's |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 38 | * bit set for each core that has at least one thread set in the argument. |
| 39 | * |
| 40 | * This can typically be used for things like IPI for tlb invalidations |
| 41 | * since those need to be done only once per core/TLB |
| 42 | */ |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 43 | static inline cpumask_t cpu_thread_mask_to_cores(const struct cpumask *threads) |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 44 | { |
| 45 | cpumask_t tmp, res; |
Shreyas B. Prabhu | e602ffb | 2015-04-20 10:32:56 +0530 | [diff] [blame] | 46 | int i, cpu; |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 47 | |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 48 | cpumask_clear(&res); |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 49 | for (i = 0; i < NR_CPUS; i += threads_per_core) { |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 50 | cpumask_shift_left(&tmp, &threads_core_mask, i); |
Shreyas B. Prabhu | e602ffb | 2015-04-20 10:32:56 +0530 | [diff] [blame] | 51 | if (cpumask_intersects(threads, &tmp)) { |
| 52 | cpu = cpumask_next_and(-1, &tmp, cpu_online_mask); |
| 53 | if (cpu < nr_cpu_ids) |
| 54 | cpumask_set_cpu(cpu, &res); |
| 55 | } |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 56 | } |
| 57 | return res; |
| 58 | } |
| 59 | |
| 60 | static inline int cpu_nr_cores(void) |
| 61 | { |
Jan Stancek | d52356e | 2015-03-31 18:11:46 +0200 | [diff] [blame] | 62 | return nr_cpu_ids >> threads_shift; |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static inline cpumask_t cpu_online_cores_map(void) |
| 66 | { |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 67 | return cpu_thread_mask_to_cores(cpu_online_mask); |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 68 | } |
| 69 | |
Vaidyanathan Srinivasan | 99d8670 | 2010-10-06 08:36:59 +0000 | [diff] [blame] | 70 | #ifdef CONFIG_SMP |
| 71 | int cpu_core_index_of_thread(int cpu); |
| 72 | int cpu_first_thread_of_core(int core); |
| 73 | #else |
| 74 | static inline int cpu_core_index_of_thread(int cpu) { return cpu; } |
| 75 | static inline int cpu_first_thread_of_core(int core) { return core; } |
| 76 | #endif |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 77 | |
| 78 | static inline int cpu_thread_in_core(int cpu) |
| 79 | { |
| 80 | return cpu & (threads_per_core - 1); |
| 81 | } |
| 82 | |
Michael Ellerman | 5853aef | 2014-05-23 18:15:27 +1000 | [diff] [blame] | 83 | static inline int cpu_thread_in_subcore(int cpu) |
| 84 | { |
| 85 | return cpu & (threads_per_subcore - 1); |
| 86 | } |
| 87 | |
Vaidyanathan Srinivasan | 99d8670 | 2010-10-06 08:36:59 +0000 | [diff] [blame] | 88 | static inline int cpu_first_thread_sibling(int cpu) |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 89 | { |
| 90 | return cpu & ~(threads_per_core - 1); |
| 91 | } |
| 92 | |
Vaidyanathan Srinivasan | 99d8670 | 2010-10-06 08:36:59 +0000 | [diff] [blame] | 93 | static inline int cpu_last_thread_sibling(int cpu) |
Benjamin Herrenschmidt | fcce810 | 2009-07-23 23:15:10 +0000 | [diff] [blame] | 94 | { |
| 95 | return cpu | (threads_per_core - 1); |
| 96 | } |
| 97 | |
chenhui zhao | ebb9d30 | 2015-12-24 08:39:57 +0800 | [diff] [blame] | 98 | static inline u32 get_tensr(void) |
| 99 | { |
| 100 | #ifdef CONFIG_BOOKE |
| 101 | if (cpu_has_feature(CPU_FTR_SMT)) |
| 102 | return mfspr(SPRN_TENSR); |
| 103 | #endif |
| 104 | return 1; |
| 105 | } |
Benjamin Herrenschmidt | fcce810 | 2009-07-23 23:15:10 +0000 | [diff] [blame] | 106 | |
chenhui zhao | 6becef7 | 2015-11-20 17:14:02 +0800 | [diff] [blame] | 107 | void book3e_start_thread(int thread, unsigned long addr); |
chenhui zhao | d17799f | 2015-11-20 17:13:59 +0800 | [diff] [blame] | 108 | void book3e_stop_thread(int thread); |
Benjamin Herrenschmidt | fcce810 | 2009-07-23 23:15:10 +0000 | [diff] [blame] | 109 | |
chenhui zhao | 6becef7 | 2015-11-20 17:14:02 +0800 | [diff] [blame] | 110 | #endif /* __ASSEMBLY__ */ |
| 111 | |
| 112 | #define INVALID_THREAD_HWID 0x0fff |
| 113 | |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 114 | #endif /* _ASM_POWERPC_CPUTHREADS_H */ |
| 115 | |