Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 1 | /* |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 2 | * Copyright IBM Corp. 2007 |
| 3 | * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com> |
| 4 | */ |
| 5 | |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 6 | #define KMSG_COMPONENT "cpu" |
| 7 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 8 | |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 9 | #include <linux/workqueue.h> |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame^] | 10 | #include <linux/bootmem.h> |
| 11 | #include <linux/cpuset.h> |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/delay.h> |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 17 | #include <linux/cpu.h> |
| 18 | #include <linux/smp.h> |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame^] | 19 | #include <linux/mm.h> |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 20 | |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 21 | #define PTF_HORIZONTAL (0UL) |
| 22 | #define PTF_VERTICAL (1UL) |
| 23 | #define PTF_CHECK (2UL) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 24 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 25 | struct mask_info { |
| 26 | struct mask_info *next; |
Heiko Carstens | 10d3858 | 2010-05-17 10:00:12 +0200 | [diff] [blame] | 27 | unsigned char id; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 28 | cpumask_t mask; |
| 29 | }; |
| 30 | |
Heiko Carstens | c9af3fa | 2010-10-25 16:10:43 +0200 | [diff] [blame] | 31 | static int topology_enabled = 1; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 32 | static void topology_work_fn(struct work_struct *work); |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 33 | static struct sysinfo_15_1_x *tl_info; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 34 | static struct timer_list topology_timer; |
| 35 | static void set_topology_timer(void); |
| 36 | static DECLARE_WORK(topology_work, topology_work_fn); |
Heiko Carstens | 74af283 | 2008-11-14 18:18:07 +0100 | [diff] [blame] | 37 | /* topology_lock protects the core linked list */ |
| 38 | static DEFINE_SPINLOCK(topology_lock); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 39 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 40 | static struct mask_info core_info; |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 41 | cpumask_t cpu_core_map[NR_CPUS]; |
Heiko Carstens | 10d3858 | 2010-05-17 10:00:12 +0200 | [diff] [blame] | 42 | unsigned char cpu_core_id[NR_CPUS]; |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 43 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 44 | static struct mask_info book_info; |
| 45 | cpumask_t cpu_book_map[NR_CPUS]; |
| 46 | unsigned char cpu_book_id[NR_CPUS]; |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame^] | 47 | |
| 48 | /* smp_cpu_state_mutex must be held when accessing this array */ |
| 49 | int cpu_polarization[NR_CPUS]; |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 50 | |
| 51 | static cpumask_t cpu_group_map(struct mask_info *info, unsigned int cpu) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 52 | { |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 53 | cpumask_t mask; |
| 54 | |
KOSAKI Motohiro | 0f1959f | 2011-05-23 10:24:36 +0200 | [diff] [blame] | 55 | cpumask_clear(&mask); |
Heiko Carstens | 0b52783 | 2010-10-29 16:50:38 +0200 | [diff] [blame] | 56 | if (!topology_enabled || !MACHINE_HAS_TOPOLOGY) { |
| 57 | cpumask_copy(&mask, cpumask_of(cpu)); |
| 58 | return mask; |
| 59 | } |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 60 | while (info) { |
KOSAKI Motohiro | 0f1959f | 2011-05-23 10:24:36 +0200 | [diff] [blame] | 61 | if (cpumask_test_cpu(cpu, &info->mask)) { |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 62 | mask = info->mask; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 63 | break; |
| 64 | } |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 65 | info = info->next; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 66 | } |
KOSAKI Motohiro | 0f1959f | 2011-05-23 10:24:36 +0200 | [diff] [blame] | 67 | if (cpumask_empty(&mask)) |
| 68 | cpumask_copy(&mask, cpumask_of(cpu)); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 69 | return mask; |
| 70 | } |
| 71 | |
Heiko Carstens | f6bf1a8 | 2011-11-14 11:19:08 +0100 | [diff] [blame] | 72 | static struct mask_info *add_cpus_to_mask(struct topology_cpu *tl_cpu, |
| 73 | struct mask_info *book, |
| 74 | struct mask_info *core, |
| 75 | int z10) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 76 | { |
| 77 | unsigned int cpu; |
| 78 | |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 79 | for (cpu = find_first_bit(&tl_cpu->mask[0], TOPOLOGY_CPU_BITS); |
| 80 | cpu < TOPOLOGY_CPU_BITS; |
| 81 | cpu = find_next_bit(&tl_cpu->mask[0], TOPOLOGY_CPU_BITS, cpu + 1)) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 82 | { |
| 83 | unsigned int rcpu, lcpu; |
| 84 | |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 85 | rcpu = TOPOLOGY_CPU_BITS - 1 - cpu + tl_cpu->origin; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 86 | for_each_present_cpu(lcpu) { |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 87 | if (cpu_logical_map(lcpu) != rcpu) |
| 88 | continue; |
KOSAKI Motohiro | 0f1959f | 2011-05-23 10:24:36 +0200 | [diff] [blame] | 89 | cpumask_set_cpu(lcpu, &book->mask); |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 90 | cpu_book_id[lcpu] = book->id; |
KOSAKI Motohiro | 0f1959f | 2011-05-23 10:24:36 +0200 | [diff] [blame] | 91 | cpumask_set_cpu(lcpu, &core->mask); |
Heiko Carstens | f6bf1a8 | 2011-11-14 11:19:08 +0100 | [diff] [blame] | 92 | if (z10) { |
| 93 | cpu_core_id[lcpu] = rcpu; |
| 94 | core = core->next; |
| 95 | } else { |
| 96 | cpu_core_id[lcpu] = core->id; |
| 97 | } |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame^] | 98 | cpu_set_polarization(lcpu, tl_cpu->pp); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 99 | } |
| 100 | } |
Heiko Carstens | f6bf1a8 | 2011-11-14 11:19:08 +0100 | [diff] [blame] | 101 | return core; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 102 | } |
| 103 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 104 | static void clear_masks(void) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 105 | { |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 106 | struct mask_info *info; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 107 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 108 | info = &core_info; |
| 109 | while (info) { |
KOSAKI Motohiro | 0f1959f | 2011-05-23 10:24:36 +0200 | [diff] [blame] | 110 | cpumask_clear(&info->mask); |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 111 | info = info->next; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 112 | } |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 113 | info = &book_info; |
| 114 | while (info) { |
KOSAKI Motohiro | 0f1959f | 2011-05-23 10:24:36 +0200 | [diff] [blame] | 115 | cpumask_clear(&info->mask); |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 116 | info = info->next; |
| 117 | } |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 120 | static union topology_entry *next_tle(union topology_entry *tle) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 121 | { |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 122 | if (!tle->nl) |
| 123 | return (union topology_entry *)((struct topology_cpu *)tle + 1); |
| 124 | return (union topology_entry *)((struct topology_container *)tle + 1); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 125 | } |
| 126 | |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 127 | static void tl_to_cores(struct sysinfo_15_1_x *info) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 128 | { |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 129 | struct mask_info *core = &core_info; |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame^] | 130 | struct mask_info *book = &book_info; |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 131 | union topology_entry *tle, *end; |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame^] | 132 | struct cpuid cpu_id; |
Heiko Carstens | f6bf1a8 | 2011-11-14 11:19:08 +0100 | [diff] [blame] | 133 | int z10 = 0; |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 134 | |
Heiko Carstens | f6bf1a8 | 2011-11-14 11:19:08 +0100 | [diff] [blame] | 135 | get_cpu_id(&cpu_id); |
| 136 | z10 = cpu_id.machine == 0x2097 || cpu_id.machine == 0x2098; |
Heiko Carstens | 74af283 | 2008-11-14 18:18:07 +0100 | [diff] [blame] | 137 | spin_lock_irq(&topology_lock); |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 138 | clear_masks(); |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 139 | tle = info->tle; |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 140 | end = (union topology_entry *)((unsigned long)info + info->length); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 141 | while (tle < end) { |
Heiko Carstens | f6bf1a8 | 2011-11-14 11:19:08 +0100 | [diff] [blame] | 142 | if (z10) { |
| 143 | switch (tle->nl) { |
| 144 | case 1: |
| 145 | book = book->next; |
| 146 | book->id = tle->container.id; |
| 147 | break; |
| 148 | case 0: |
| 149 | core = add_cpus_to_mask(&tle->cpu, book, core, z10); |
| 150 | break; |
| 151 | default: |
| 152 | clear_masks(); |
| 153 | goto out; |
| 154 | } |
| 155 | tle = next_tle(tle); |
| 156 | continue; |
| 157 | } |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 158 | switch (tle->nl) { |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 159 | case 2: |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 160 | book = book->next; |
| 161 | book->id = tle->container.id; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 162 | break; |
| 163 | case 1: |
| 164 | core = core->next; |
Heiko Carstens | 10d3858 | 2010-05-17 10:00:12 +0200 | [diff] [blame] | 165 | core->id = tle->container.id; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 166 | break; |
| 167 | case 0: |
Heiko Carstens | f6bf1a8 | 2011-11-14 11:19:08 +0100 | [diff] [blame] | 168 | add_cpus_to_mask(&tle->cpu, book, core, z10); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 169 | break; |
| 170 | default: |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 171 | clear_masks(); |
Julia Lawall | d7015c1 | 2010-04-09 13:42:58 +0200 | [diff] [blame] | 172 | goto out; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 173 | } |
| 174 | tle = next_tle(tle); |
| 175 | } |
Julia Lawall | d7015c1 | 2010-04-09 13:42:58 +0200 | [diff] [blame] | 176 | out: |
Heiko Carstens | 74af283 | 2008-11-14 18:18:07 +0100 | [diff] [blame] | 177 | spin_unlock_irq(&topology_lock); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 180 | static void topology_update_polarization_simple(void) |
| 181 | { |
| 182 | int cpu; |
| 183 | |
| 184 | mutex_lock(&smp_cpu_state_mutex); |
Heiko Carstens | 5439050 | 2008-12-25 13:37:57 +0100 | [diff] [blame] | 185 | for_each_possible_cpu(cpu) |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame^] | 186 | cpu_set_polarization(cpu, POLARIZATION_HRZ); |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 187 | mutex_unlock(&smp_cpu_state_mutex); |
| 188 | } |
| 189 | |
| 190 | static int ptf(unsigned long fc) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 191 | { |
| 192 | int rc; |
| 193 | |
| 194 | asm volatile( |
| 195 | " .insn rre,0xb9a20000,%1,%1\n" |
| 196 | " ipm %0\n" |
| 197 | " srl %0,28\n" |
| 198 | : "=d" (rc) |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 199 | : "d" (fc) : "cc"); |
| 200 | return rc; |
| 201 | } |
| 202 | |
| 203 | int topology_set_cpu_management(int fc) |
| 204 | { |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame^] | 205 | int cpu, rc; |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 206 | |
Heiko Carstens | 9186d7a | 2010-10-25 16:10:52 +0200 | [diff] [blame] | 207 | if (!MACHINE_HAS_TOPOLOGY) |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 208 | return -EOPNOTSUPP; |
| 209 | if (fc) |
| 210 | rc = ptf(PTF_VERTICAL); |
| 211 | else |
| 212 | rc = ptf(PTF_HORIZONTAL); |
| 213 | if (rc) |
| 214 | return -EBUSY; |
Heiko Carstens | 5439050 | 2008-12-25 13:37:57 +0100 | [diff] [blame] | 215 | for_each_possible_cpu(cpu) |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame^] | 216 | cpu_set_polarization(cpu, POLARIZATION_UNKNOWN); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 217 | return rc; |
| 218 | } |
| 219 | |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 220 | static void update_cpu_core_map(void) |
| 221 | { |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 222 | unsigned long flags; |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 223 | int cpu; |
| 224 | |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 225 | spin_lock_irqsave(&topology_lock, flags); |
| 226 | for_each_possible_cpu(cpu) { |
| 227 | cpu_core_map[cpu] = cpu_group_map(&core_info, cpu); |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 228 | cpu_book_map[cpu] = cpu_group_map(&book_info, cpu); |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 229 | } |
| 230 | spin_unlock_irqrestore(&topology_lock, flags); |
| 231 | } |
| 232 | |
Heiko Carstens | 96f4a70 | 2010-10-25 16:10:54 +0200 | [diff] [blame] | 233 | void store_topology(struct sysinfo_15_1_x *info) |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 234 | { |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 235 | int rc; |
| 236 | |
| 237 | rc = stsi(info, 15, 1, 3); |
| 238 | if (rc != -ENOSYS) |
| 239 | return; |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 240 | stsi(info, 15, 1, 2); |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 241 | } |
| 242 | |
Heiko Carstens | ee79d1b | 2008-12-09 18:49:50 +0100 | [diff] [blame] | 243 | int arch_update_cpu_topology(void) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 244 | { |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 245 | struct sysinfo_15_1_x *info = tl_info; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 246 | struct sys_device *sysdev; |
| 247 | int cpu; |
| 248 | |
Heiko Carstens | 9186d7a | 2010-10-25 16:10:52 +0200 | [diff] [blame] | 249 | if (!MACHINE_HAS_TOPOLOGY) { |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 250 | update_cpu_core_map(); |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 251 | topology_update_polarization_simple(); |
Heiko Carstens | ee79d1b | 2008-12-09 18:49:50 +0100 | [diff] [blame] | 252 | return 0; |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 253 | } |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 254 | store_topology(info); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 255 | tl_to_cores(info); |
Heiko Carstens | d00aa4e | 2008-04-30 13:38:40 +0200 | [diff] [blame] | 256 | update_cpu_core_map(); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 257 | for_each_online_cpu(cpu) { |
| 258 | sysdev = get_cpu_sysdev(cpu); |
| 259 | kobject_uevent(&sysdev->kobj, KOBJ_CHANGE); |
| 260 | } |
Heiko Carstens | ee79d1b | 2008-12-09 18:49:50 +0100 | [diff] [blame] | 261 | return 1; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 262 | } |
| 263 | |
Heiko Carstens | fd781fa | 2008-04-30 13:38:41 +0200 | [diff] [blame] | 264 | static void topology_work_fn(struct work_struct *work) |
| 265 | { |
Heiko Carstens | f414f5f | 2008-12-25 13:37:59 +0100 | [diff] [blame] | 266 | rebuild_sched_domains(); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 269 | void topology_schedule_update(void) |
| 270 | { |
| 271 | schedule_work(&topology_work); |
| 272 | } |
| 273 | |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 274 | static void topology_timer_fn(unsigned long ignored) |
| 275 | { |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 276 | if (ptf(PTF_CHECK)) |
| 277 | topology_schedule_update(); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 278 | set_topology_timer(); |
| 279 | } |
| 280 | |
| 281 | static void set_topology_timer(void) |
| 282 | { |
| 283 | topology_timer.function = topology_timer_fn; |
| 284 | topology_timer.data = 0; |
| 285 | topology_timer.expires = jiffies + 60 * HZ; |
| 286 | add_timer(&topology_timer); |
| 287 | } |
| 288 | |
Heiko Carstens | 2b1a61f | 2008-12-25 13:39:23 +0100 | [diff] [blame] | 289 | static int __init early_parse_topology(char *p) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 290 | { |
Heiko Carstens | c9af3fa | 2010-10-25 16:10:43 +0200 | [diff] [blame] | 291 | if (strncmp(p, "off", 3)) |
Heiko Carstens | 2b1a61f | 2008-12-25 13:39:23 +0100 | [diff] [blame] | 292 | return 0; |
Heiko Carstens | c9af3fa | 2010-10-25 16:10:43 +0200 | [diff] [blame] | 293 | topology_enabled = 0; |
Heiko Carstens | 2b1a61f | 2008-12-25 13:39:23 +0100 | [diff] [blame] | 294 | return 0; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 295 | } |
Heiko Carstens | 2b1a61f | 2008-12-25 13:39:23 +0100 | [diff] [blame] | 296 | early_param("topology", early_parse_topology); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 297 | |
Sebastian Ott | caa04f6 | 2011-10-30 15:16:06 +0100 | [diff] [blame] | 298 | static void __init alloc_masks(struct sysinfo_15_1_x *info, |
| 299 | struct mask_info *mask, int offset) |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 300 | { |
| 301 | int i, nr_masks; |
| 302 | |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 303 | nr_masks = info->mag[TOPOLOGY_NR_MAG - offset]; |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 304 | for (i = 0; i < info->mnest - offset; i++) |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 305 | nr_masks *= info->mag[TOPOLOGY_NR_MAG - offset - 1 - i]; |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 306 | nr_masks = max(nr_masks, 1); |
| 307 | for (i = 0; i < nr_masks; i++) { |
| 308 | mask->next = alloc_bootmem(sizeof(struct mask_info)); |
| 309 | mask = mask->next; |
| 310 | } |
| 311 | } |
| 312 | |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 313 | void __init s390_init_cpu_topology(void) |
| 314 | { |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 315 | struct sysinfo_15_1_x *info; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 316 | int i; |
| 317 | |
Heiko Carstens | 9186d7a | 2010-10-25 16:10:52 +0200 | [diff] [blame] | 318 | if (!MACHINE_HAS_TOPOLOGY) |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 319 | return; |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 320 | tl_info = alloc_bootmem_pages(PAGE_SIZE); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 321 | info = tl_info; |
Heiko Carstens | 4cb14bc | 2010-08-31 10:28:18 +0200 | [diff] [blame] | 322 | store_topology(info); |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 323 | pr_info("The CPU configuration topology of the machine is:"); |
Heiko Carstens | c30f91b | 2010-10-25 16:10:53 +0200 | [diff] [blame] | 324 | for (i = 0; i < TOPOLOGY_NR_MAG; i++) |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame^] | 325 | printk(KERN_CONT " %d", info->mag[i]); |
| 326 | printk(KERN_CONT " / %d\n", info->mnest); |
Heiko Carstens | f6bf1a8 | 2011-11-14 11:19:08 +0100 | [diff] [blame] | 327 | alloc_masks(info, &core_info, 1); |
Heiko Carstens | f6bf1a8 | 2011-11-14 11:19:08 +0100 | [diff] [blame] | 328 | alloc_masks(info, &book_info, 2); |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 329 | } |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame^] | 330 | |
| 331 | static int cpu_management; |
| 332 | |
| 333 | static ssize_t dispatching_show(struct sysdev_class *class, |
| 334 | struct sysdev_class_attribute *attr, |
| 335 | char *buf) |
| 336 | { |
| 337 | ssize_t count; |
| 338 | |
| 339 | mutex_lock(&smp_cpu_state_mutex); |
| 340 | count = sprintf(buf, "%d\n", cpu_management); |
| 341 | mutex_unlock(&smp_cpu_state_mutex); |
| 342 | return count; |
| 343 | } |
| 344 | |
| 345 | static ssize_t dispatching_store(struct sysdev_class *dev, |
| 346 | struct sysdev_class_attribute *attr, |
| 347 | const char *buf, |
| 348 | size_t count) |
| 349 | { |
| 350 | int val, rc; |
| 351 | char delim; |
| 352 | |
| 353 | if (sscanf(buf, "%d %c", &val, &delim) != 1) |
| 354 | return -EINVAL; |
| 355 | if (val != 0 && val != 1) |
| 356 | return -EINVAL; |
| 357 | rc = 0; |
| 358 | get_online_cpus(); |
| 359 | mutex_lock(&smp_cpu_state_mutex); |
| 360 | if (cpu_management == val) |
| 361 | goto out; |
| 362 | rc = topology_set_cpu_management(val); |
| 363 | if (!rc) |
| 364 | cpu_management = val; |
| 365 | out: |
| 366 | mutex_unlock(&smp_cpu_state_mutex); |
| 367 | put_online_cpus(); |
| 368 | return rc ? rc : count; |
| 369 | } |
| 370 | static SYSDEV_CLASS_ATTR(dispatching, 0644, dispatching_show, |
| 371 | dispatching_store); |
| 372 | |
| 373 | static ssize_t cpu_polarization_show(struct sys_device *dev, |
| 374 | struct sysdev_attribute *attr, char *buf) |
| 375 | { |
| 376 | int cpu = dev->id; |
| 377 | ssize_t count; |
| 378 | |
| 379 | mutex_lock(&smp_cpu_state_mutex); |
| 380 | switch (cpu_read_polarization(cpu)) { |
| 381 | case POLARIZATION_HRZ: |
| 382 | count = sprintf(buf, "horizontal\n"); |
| 383 | break; |
| 384 | case POLARIZATION_VL: |
| 385 | count = sprintf(buf, "vertical:low\n"); |
| 386 | break; |
| 387 | case POLARIZATION_VM: |
| 388 | count = sprintf(buf, "vertical:medium\n"); |
| 389 | break; |
| 390 | case POLARIZATION_VH: |
| 391 | count = sprintf(buf, "vertical:high\n"); |
| 392 | break; |
| 393 | default: |
| 394 | count = sprintf(buf, "unknown\n"); |
| 395 | break; |
| 396 | } |
| 397 | mutex_unlock(&smp_cpu_state_mutex); |
| 398 | return count; |
| 399 | } |
| 400 | static SYSDEV_ATTR(polarization, 0444, cpu_polarization_show, NULL); |
| 401 | |
| 402 | static struct attribute *topology_cpu_attrs[] = { |
| 403 | &attr_polarization.attr, |
| 404 | NULL, |
| 405 | }; |
| 406 | |
| 407 | static struct attribute_group topology_cpu_attr_group = { |
| 408 | .attrs = topology_cpu_attrs, |
| 409 | }; |
| 410 | |
| 411 | int topology_cpu_init(struct cpu *cpu) |
| 412 | { |
| 413 | return sysfs_create_group(&cpu->sysdev.kobj, &topology_cpu_attr_group); |
| 414 | } |
| 415 | |
| 416 | static int __init topology_init(void) |
| 417 | { |
| 418 | if (!MACHINE_HAS_TOPOLOGY) { |
| 419 | topology_update_polarization_simple(); |
| 420 | goto out; |
| 421 | } |
| 422 | init_timer_deferrable(&topology_timer); |
| 423 | set_topology_timer(); |
| 424 | out: |
| 425 | update_cpu_core_map(); |
| 426 | return sysdev_class_create_file(&cpu_sysdev_class, &attr_dispatching); |
| 427 | } |
| 428 | device_initcall(topology_init); |