blob: 30c8533b8d4e0930debf730c669d1791c47baec6 [file] [log] [blame]
Heiko Carstensdbd70fb2008-04-17 07:46:12 +02001/*
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02002 * Copyright IBM Corp. 2007, 2011
Heiko Carstensdbd70fb2008-04-17 07:46:12 +02003 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
4 */
5
Martin Schwidefsky395d31d2008-12-25 13:39:50 +01006#define KMSG_COMPONENT "cpu"
7#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
8
Heiko Carstensdbd70fb2008-04-17 07:46:12 +02009#include <linux/workqueue.h>
Heiko Carstens83a24e32011-12-27 11:27:09 +010010#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 Carstensdbd70fb2008-04-17 07:46:12 +020017#include <linux/cpu.h>
18#include <linux/smp.h>
Heiko Carstens83a24e32011-12-27 11:27:09 +010019#include <linux/mm.h>
Heiko Carstens78609132012-09-03 14:11:32 +020020#include <asm/sysinfo.h>
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020021
Heiko Carstensc10fde02008-04-17 07:46:13 +020022#define PTF_HORIZONTAL (0UL)
23#define PTF_VERTICAL (1UL)
24#define PTF_CHECK (2UL)
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020025
Heiko Carstens4cb14bc2010-08-31 10:28:18 +020026struct mask_info {
27 struct mask_info *next;
Heiko Carstens10d38582010-05-17 10:00:12 +020028 unsigned char id;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020029 cpumask_t mask;
30};
31
Heiko Carstensc9af3fa2010-10-25 16:10:43 +020032static int topology_enabled = 1;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020033static void topology_work_fn(struct work_struct *work);
Heiko Carstensc30f91b2010-10-25 16:10:53 +020034static struct sysinfo_15_1_x *tl_info;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020035static void set_topology_timer(void);
36static DECLARE_WORK(topology_work, topology_work_fn);
Heiko Carstens74af2832008-11-14 18:18:07 +010037/* topology_lock protects the core linked list */
38static DEFINE_SPINLOCK(topology_lock);
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020039
Heiko Carstens4cb14bc2010-08-31 10:28:18 +020040static struct mask_info core_info;
Heiko Carstensd00aa4e2008-04-30 13:38:40 +020041cpumask_t cpu_core_map[NR_CPUS];
Heiko Carstens10d38582010-05-17 10:00:12 +020042unsigned char cpu_core_id[NR_CPUS];
Heiko Carstensd00aa4e2008-04-30 13:38:40 +020043
Heiko Carstens4cb14bc2010-08-31 10:28:18 +020044static struct mask_info book_info;
45cpumask_t cpu_book_map[NR_CPUS];
46unsigned char cpu_book_id[NR_CPUS];
Heiko Carstens83a24e32011-12-27 11:27:09 +010047
Heiko Carstens4cb14bc2010-08-31 10:28:18 +020048static cpumask_t cpu_group_map(struct mask_info *info, unsigned int cpu)
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020049{
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020050 cpumask_t mask;
51
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +020052 cpumask_clear(&mask);
Heiko Carstens0b527832010-10-29 16:50:38 +020053 if (!topology_enabled || !MACHINE_HAS_TOPOLOGY) {
54 cpumask_copy(&mask, cpumask_of(cpu));
55 return mask;
56 }
Heiko Carstens4cb14bc2010-08-31 10:28:18 +020057 while (info) {
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +020058 if (cpumask_test_cpu(cpu, &info->mask)) {
Heiko Carstens4cb14bc2010-08-31 10:28:18 +020059 mask = info->mask;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020060 break;
61 }
Heiko Carstens4cb14bc2010-08-31 10:28:18 +020062 info = info->next;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020063 }
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +020064 if (cpumask_empty(&mask))
65 cpumask_copy(&mask, cpumask_of(cpu));
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020066 return mask;
67}
68
Heiko Carstensf6bf1a82011-11-14 11:19:08 +010069static struct mask_info *add_cpus_to_mask(struct topology_cpu *tl_cpu,
70 struct mask_info *book,
71 struct mask_info *core,
Heiko Carstens4baeb962011-12-27 11:27:12 +010072 int one_core_per_cpu)
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020073{
74 unsigned int cpu;
75
Heiko Carstensc30f91b2010-10-25 16:10:53 +020076 for (cpu = find_first_bit(&tl_cpu->mask[0], TOPOLOGY_CPU_BITS);
77 cpu < TOPOLOGY_CPU_BITS;
78 cpu = find_next_bit(&tl_cpu->mask[0], TOPOLOGY_CPU_BITS, cpu + 1))
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020079 {
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040080 unsigned int rcpu;
81 int lcpu;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020082
Heiko Carstensc30f91b2010-10-25 16:10:53 +020083 rcpu = TOPOLOGY_CPU_BITS - 1 - cpu + tl_cpu->origin;
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040084 lcpu = smp_find_processor_id(rcpu);
85 if (lcpu >= 0) {
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +020086 cpumask_set_cpu(lcpu, &book->mask);
Heiko Carstens4cb14bc2010-08-31 10:28:18 +020087 cpu_book_id[lcpu] = book->id;
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +020088 cpumask_set_cpu(lcpu, &core->mask);
Heiko Carstens4baeb962011-12-27 11:27:12 +010089 if (one_core_per_cpu) {
Heiko Carstensf6bf1a82011-11-14 11:19:08 +010090 cpu_core_id[lcpu] = rcpu;
91 core = core->next;
92 } else {
93 cpu_core_id[lcpu] = core->id;
94 }
Heiko Carstens50ab9a92012-09-04 17:36:16 +020095 smp_cpu_set_polarization(lcpu, tl_cpu->pp);
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020096 }
97 }
Heiko Carstensf6bf1a82011-11-14 11:19:08 +010098 return core;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020099}
100
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200101static void clear_masks(void)
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200102{
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200103 struct mask_info *info;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200104
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200105 info = &core_info;
106 while (info) {
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +0200107 cpumask_clear(&info->mask);
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200108 info = info->next;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200109 }
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200110 info = &book_info;
111 while (info) {
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +0200112 cpumask_clear(&info->mask);
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200113 info = info->next;
114 }
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200115}
116
Heiko Carstensc30f91b2010-10-25 16:10:53 +0200117static union topology_entry *next_tle(union topology_entry *tle)
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200118{
Heiko Carstensc30f91b2010-10-25 16:10:53 +0200119 if (!tle->nl)
120 return (union topology_entry *)((struct topology_cpu *)tle + 1);
121 return (union topology_entry *)((struct topology_container *)tle + 1);
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200122}
123
Heiko Carstens4baeb962011-12-27 11:27:12 +0100124static void __tl_to_cores_generic(struct sysinfo_15_1_x *info)
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200125{
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200126 struct mask_info *core = &core_info;
Heiko Carstens83a24e32011-12-27 11:27:09 +0100127 struct mask_info *book = &book_info;
Heiko Carstensc30f91b2010-10-25 16:10:53 +0200128 union topology_entry *tle, *end;
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200129
Heiko Carstensc10fde02008-04-17 07:46:13 +0200130 tle = info->tle;
Heiko Carstensc30f91b2010-10-25 16:10:53 +0200131 end = (union topology_entry *)((unsigned long)info + info->length);
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200132 while (tle < end) {
133 switch (tle->nl) {
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200134 case 2:
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200135 book = book->next;
136 book->id = tle->container.id;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200137 break;
138 case 1:
139 core = core->next;
Heiko Carstens10d38582010-05-17 10:00:12 +0200140 core->id = tle->container.id;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200141 break;
142 case 0:
Heiko Carstens4baeb962011-12-27 11:27:12 +0100143 add_cpus_to_mask(&tle->cpu, book, core, 0);
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200144 break;
145 default:
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200146 clear_masks();
Heiko Carstens4baeb962011-12-27 11:27:12 +0100147 return;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200148 }
149 tle = next_tle(tle);
150 }
Heiko Carstens4baeb962011-12-27 11:27:12 +0100151}
152
153static void __tl_to_cores_z10(struct sysinfo_15_1_x *info)
154{
155 struct mask_info *core = &core_info;
156 struct mask_info *book = &book_info;
157 union topology_entry *tle, *end;
158
159 tle = info->tle;
160 end = (union topology_entry *)((unsigned long)info + info->length);
161 while (tle < end) {
162 switch (tle->nl) {
163 case 1:
164 book = book->next;
165 book->id = tle->container.id;
166 break;
167 case 0:
168 core = add_cpus_to_mask(&tle->cpu, book, core, 1);
169 break;
170 default:
171 clear_masks();
172 return;
173 }
174 tle = next_tle(tle);
175 }
176}
177
178static void tl_to_cores(struct sysinfo_15_1_x *info)
179{
180 struct cpuid cpu_id;
181
182 get_cpu_id(&cpu_id);
183 spin_lock_irq(&topology_lock);
184 clear_masks();
185 switch (cpu_id.machine) {
186 case 0x2097:
187 case 0x2098:
188 __tl_to_cores_z10(info);
189 break;
190 default:
191 __tl_to_cores_generic(info);
192 }
Heiko Carstens74af2832008-11-14 18:18:07 +0100193 spin_unlock_irq(&topology_lock);
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200194}
195
Heiko Carstensc10fde02008-04-17 07:46:13 +0200196static void topology_update_polarization_simple(void)
197{
198 int cpu;
199
200 mutex_lock(&smp_cpu_state_mutex);
Heiko Carstens54390502008-12-25 13:37:57 +0100201 for_each_possible_cpu(cpu)
Heiko Carstens50ab9a92012-09-04 17:36:16 +0200202 smp_cpu_set_polarization(cpu, POLARIZATION_HRZ);
Heiko Carstensc10fde02008-04-17 07:46:13 +0200203 mutex_unlock(&smp_cpu_state_mutex);
204}
205
206static int ptf(unsigned long fc)
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200207{
208 int rc;
209
210 asm volatile(
211 " .insn rre,0xb9a20000,%1,%1\n"
212 " ipm %0\n"
213 " srl %0,28\n"
214 : "=d" (rc)
Heiko Carstensc10fde02008-04-17 07:46:13 +0200215 : "d" (fc) : "cc");
216 return rc;
217}
218
219int topology_set_cpu_management(int fc)
220{
Heiko Carstens83a24e32011-12-27 11:27:09 +0100221 int cpu, rc;
Heiko Carstensc10fde02008-04-17 07:46:13 +0200222
Heiko Carstens9186d7a2010-10-25 16:10:52 +0200223 if (!MACHINE_HAS_TOPOLOGY)
Heiko Carstensc10fde02008-04-17 07:46:13 +0200224 return -EOPNOTSUPP;
225 if (fc)
226 rc = ptf(PTF_VERTICAL);
227 else
228 rc = ptf(PTF_HORIZONTAL);
229 if (rc)
230 return -EBUSY;
Heiko Carstens54390502008-12-25 13:37:57 +0100231 for_each_possible_cpu(cpu)
Heiko Carstens50ab9a92012-09-04 17:36:16 +0200232 smp_cpu_set_polarization(cpu, POLARIZATION_UNKNOWN);
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200233 return rc;
234}
235
Heiko Carstensd00aa4e2008-04-30 13:38:40 +0200236static void update_cpu_core_map(void)
237{
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200238 unsigned long flags;
Heiko Carstensd00aa4e2008-04-30 13:38:40 +0200239 int cpu;
240
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200241 spin_lock_irqsave(&topology_lock, flags);
242 for_each_possible_cpu(cpu) {
243 cpu_core_map[cpu] = cpu_group_map(&core_info, cpu);
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200244 cpu_book_map[cpu] = cpu_group_map(&book_info, cpu);
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200245 }
246 spin_unlock_irqrestore(&topology_lock, flags);
247}
248
Heiko Carstens96f4a702010-10-25 16:10:54 +0200249void store_topology(struct sysinfo_15_1_x *info)
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200250{
Heiko Carstensfade4dc2012-09-04 14:26:03 +0200251 if (topology_max_mnest >= 3)
252 stsi(info, 15, 1, 3);
253 else
254 stsi(info, 15, 1, 2);
Heiko Carstensd00aa4e2008-04-30 13:38:40 +0200255}
256
Heiko Carstensee79d1b2008-12-09 18:49:50 +0100257int arch_update_cpu_topology(void)
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200258{
Heiko Carstensc30f91b2010-10-25 16:10:53 +0200259 struct sysinfo_15_1_x *info = tl_info;
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800260 struct device *dev;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200261 int cpu;
262
Heiko Carstens9186d7a2010-10-25 16:10:52 +0200263 if (!MACHINE_HAS_TOPOLOGY) {
Heiko Carstensd00aa4e2008-04-30 13:38:40 +0200264 update_cpu_core_map();
Heiko Carstensc10fde02008-04-17 07:46:13 +0200265 topology_update_polarization_simple();
Heiko Carstensee79d1b2008-12-09 18:49:50 +0100266 return 0;
Heiko Carstensc10fde02008-04-17 07:46:13 +0200267 }
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200268 store_topology(info);
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200269 tl_to_cores(info);
Heiko Carstensd00aa4e2008-04-30 13:38:40 +0200270 update_cpu_core_map();
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200271 for_each_online_cpu(cpu) {
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800272 dev = get_cpu_device(cpu);
273 kobject_uevent(&dev->kobj, KOBJ_CHANGE);
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200274 }
Heiko Carstensee79d1b2008-12-09 18:49:50 +0100275 return 1;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200276}
277
Heiko Carstensfd781fa2008-04-30 13:38:41 +0200278static void topology_work_fn(struct work_struct *work)
279{
Heiko Carstensf414f5f2008-12-25 13:37:59 +0100280 rebuild_sched_domains();
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200281}
282
Heiko Carstensc10fde02008-04-17 07:46:13 +0200283void topology_schedule_update(void)
284{
285 schedule_work(&topology_work);
286}
287
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200288static void topology_timer_fn(unsigned long ignored)
289{
Heiko Carstensc10fde02008-04-17 07:46:13 +0200290 if (ptf(PTF_CHECK))
291 topology_schedule_update();
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200292 set_topology_timer();
293}
294
Heiko Carstensd68bddb2011-12-27 11:27:16 +0100295static struct timer_list topology_timer =
296 TIMER_DEFERRED_INITIALIZER(topology_timer_fn, 0, 0);
297
298static atomic_t topology_poll = ATOMIC_INIT(0);
299
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200300static void set_topology_timer(void)
301{
Heiko Carstensd68bddb2011-12-27 11:27:16 +0100302 if (atomic_add_unless(&topology_poll, -1, 0))
303 mod_timer(&topology_timer, jiffies + HZ / 10);
304 else
305 mod_timer(&topology_timer, jiffies + HZ * 60);
306}
307
308void topology_expect_change(void)
309{
310 if (!MACHINE_HAS_TOPOLOGY)
311 return;
312 /* This is racy, but it doesn't matter since it is just a heuristic.
313 * Worst case is that we poll in a higher frequency for a bit longer.
314 */
315 if (atomic_read(&topology_poll) > 60)
316 return;
317 atomic_add(60, &topology_poll);
318 set_topology_timer();
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200319}
320
Heiko Carstens2b1a61f2008-12-25 13:39:23 +0100321static int __init early_parse_topology(char *p)
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200322{
Heiko Carstensc9af3fa2010-10-25 16:10:43 +0200323 if (strncmp(p, "off", 3))
Heiko Carstens2b1a61f2008-12-25 13:39:23 +0100324 return 0;
Heiko Carstensc9af3fa2010-10-25 16:10:43 +0200325 topology_enabled = 0;
Heiko Carstens2b1a61f2008-12-25 13:39:23 +0100326 return 0;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200327}
Heiko Carstens2b1a61f2008-12-25 13:39:23 +0100328early_param("topology", early_parse_topology);
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200329
Sebastian Ottcaa04f62011-10-30 15:16:06 +0100330static void __init alloc_masks(struct sysinfo_15_1_x *info,
331 struct mask_info *mask, int offset)
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200332{
333 int i, nr_masks;
334
Heiko Carstensc30f91b2010-10-25 16:10:53 +0200335 nr_masks = info->mag[TOPOLOGY_NR_MAG - offset];
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200336 for (i = 0; i < info->mnest - offset; i++)
Heiko Carstensc30f91b2010-10-25 16:10:53 +0200337 nr_masks *= info->mag[TOPOLOGY_NR_MAG - offset - 1 - i];
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200338 nr_masks = max(nr_masks, 1);
339 for (i = 0; i < nr_masks; i++) {
340 mask->next = alloc_bootmem(sizeof(struct mask_info));
341 mask = mask->next;
342 }
343}
344
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200345void __init s390_init_cpu_topology(void)
346{
Heiko Carstensc30f91b2010-10-25 16:10:53 +0200347 struct sysinfo_15_1_x *info;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200348 int i;
349
Heiko Carstens9186d7a2010-10-25 16:10:52 +0200350 if (!MACHINE_HAS_TOPOLOGY)
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200351 return;
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200352 tl_info = alloc_bootmem_pages(PAGE_SIZE);
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200353 info = tl_info;
Heiko Carstens4cb14bc2010-08-31 10:28:18 +0200354 store_topology(info);
Martin Schwidefsky395d31d2008-12-25 13:39:50 +0100355 pr_info("The CPU configuration topology of the machine is:");
Heiko Carstensc30f91b2010-10-25 16:10:53 +0200356 for (i = 0; i < TOPOLOGY_NR_MAG; i++)
Heiko Carstens83a24e32011-12-27 11:27:09 +0100357 printk(KERN_CONT " %d", info->mag[i]);
358 printk(KERN_CONT " / %d\n", info->mnest);
Heiko Carstensf6bf1a82011-11-14 11:19:08 +0100359 alloc_masks(info, &core_info, 1);
Heiko Carstensf6bf1a82011-11-14 11:19:08 +0100360 alloc_masks(info, &book_info, 2);
Heiko Carstensdbd70fb2008-04-17 07:46:12 +0200361}
Heiko Carstens83a24e32011-12-27 11:27:09 +0100362
363static int cpu_management;
364
Linus Torvalds72f31882012-01-09 08:11:13 -0800365static ssize_t dispatching_show(struct device *dev,
366 struct device_attribute *attr,
Heiko Carstens83a24e32011-12-27 11:27:09 +0100367 char *buf)
368{
369 ssize_t count;
370
371 mutex_lock(&smp_cpu_state_mutex);
372 count = sprintf(buf, "%d\n", cpu_management);
373 mutex_unlock(&smp_cpu_state_mutex);
374 return count;
375}
376
Linus Torvalds72f31882012-01-09 08:11:13 -0800377static ssize_t dispatching_store(struct device *dev,
378 struct device_attribute *attr,
Heiko Carstens83a24e32011-12-27 11:27:09 +0100379 const char *buf,
380 size_t count)
381{
382 int val, rc;
383 char delim;
384
385 if (sscanf(buf, "%d %c", &val, &delim) != 1)
386 return -EINVAL;
387 if (val != 0 && val != 1)
388 return -EINVAL;
389 rc = 0;
390 get_online_cpus();
391 mutex_lock(&smp_cpu_state_mutex);
392 if (cpu_management == val)
393 goto out;
394 rc = topology_set_cpu_management(val);
Heiko Carstensd68bddb2011-12-27 11:27:16 +0100395 if (rc)
396 goto out;
397 cpu_management = val;
398 topology_expect_change();
Heiko Carstens83a24e32011-12-27 11:27:09 +0100399out:
400 mutex_unlock(&smp_cpu_state_mutex);
401 put_online_cpus();
402 return rc ? rc : count;
403}
Linus Torvalds72f31882012-01-09 08:11:13 -0800404static DEVICE_ATTR(dispatching, 0644, dispatching_show,
Heiko Carstens83a24e32011-12-27 11:27:09 +0100405 dispatching_store);
406
Linus Torvalds72f31882012-01-09 08:11:13 -0800407static ssize_t cpu_polarization_show(struct device *dev,
408 struct device_attribute *attr, char *buf)
Heiko Carstens83a24e32011-12-27 11:27:09 +0100409{
410 int cpu = dev->id;
411 ssize_t count;
412
413 mutex_lock(&smp_cpu_state_mutex);
Heiko Carstens50ab9a92012-09-04 17:36:16 +0200414 switch (smp_cpu_get_polarization(cpu)) {
Heiko Carstens83a24e32011-12-27 11:27:09 +0100415 case POLARIZATION_HRZ:
416 count = sprintf(buf, "horizontal\n");
417 break;
418 case POLARIZATION_VL:
419 count = sprintf(buf, "vertical:low\n");
420 break;
421 case POLARIZATION_VM:
422 count = sprintf(buf, "vertical:medium\n");
423 break;
424 case POLARIZATION_VH:
425 count = sprintf(buf, "vertical:high\n");
426 break;
427 default:
428 count = sprintf(buf, "unknown\n");
429 break;
430 }
431 mutex_unlock(&smp_cpu_state_mutex);
432 return count;
433}
Linus Torvalds72f31882012-01-09 08:11:13 -0800434static DEVICE_ATTR(polarization, 0444, cpu_polarization_show, NULL);
Heiko Carstens83a24e32011-12-27 11:27:09 +0100435
436static struct attribute *topology_cpu_attrs[] = {
Linus Torvalds72f31882012-01-09 08:11:13 -0800437 &dev_attr_polarization.attr,
Heiko Carstens83a24e32011-12-27 11:27:09 +0100438 NULL,
439};
440
441static struct attribute_group topology_cpu_attr_group = {
442 .attrs = topology_cpu_attrs,
443};
444
445int topology_cpu_init(struct cpu *cpu)
446{
Linus Torvalds72f31882012-01-09 08:11:13 -0800447 return sysfs_create_group(&cpu->dev.kobj, &topology_cpu_attr_group);
Heiko Carstens83a24e32011-12-27 11:27:09 +0100448}
449
450static int __init topology_init(void)
451{
452 if (!MACHINE_HAS_TOPOLOGY) {
453 topology_update_polarization_simple();
454 goto out;
455 }
Heiko Carstens83a24e32011-12-27 11:27:09 +0100456 set_topology_timer();
457out:
458 update_cpu_core_map();
Linus Torvalds72f31882012-01-09 08:11:13 -0800459 return device_create_file(cpu_subsys.dev_root, &dev_attr_dispatching);
Heiko Carstens83a24e32011-12-27 11:27:09 +0100460}
461device_initcall(topology_init);