2 * arch/s390/kernel/smp.c
4 * Copyright IBM Corp. 1999, 2009
5 * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
6 * Martin Schwidefsky (schwidefsky@de.ibm.com)
7 * Heiko Carstens (heiko.carstens@de.ibm.com)
9 * based on other smp stuff by
10 * (c) 1995 Alan Cox, CymruNET Ltd <alan@cymru.net>
11 * (c) 1998 Ingo Molnar
13 * We work with logical cpu numbering everywhere we can. The only
14 * functions using the real cpu address (got from STAP) are the sigp
15 * functions. For all other functions we use the identity mapping.
16 * That means that cpu_number_map[i] == i for every cpu. cpu_number_map is
17 * used e.g. to find the idle task belonging to a logical cpu. Every array
18 * in the kernel is sorted by the logical cpu number and not by the physical
19 * one which is causing all the confusion with __cpu_logical_map and
20 * cpu_number_map in other architectures.
23 #define KMSG_COMPONENT "cpu"
24 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
26 #include <linux/module.h>
27 #include <linux/init.h>
29 #include <linux/err.h>
30 #include <linux/spinlock.h>
31 #include <linux/kernel_stat.h>
32 #include <linux/delay.h>
33 #include <linux/cache.h>
34 #include <linux/interrupt.h>
35 #include <linux/irqflags.h>
36 #include <linux/cpu.h>
37 #include <linux/timex.h>
38 #include <linux/bootmem.h>
40 #include <asm/setup.h>
42 #include <asm/pgalloc.h>
44 #include <asm/s390_ext.h>
45 #include <asm/cpcmd.h>
46 #include <asm/tlbflush.h>
47 #include <asm/timer.h>
48 #include <asm/lowcore.h>
50 #include <asm/cputime.h>
55 /* logical cpu to cpu address */
56 unsigned short __cpu_logical_map[NR_CPUS];
58 static struct task_struct *current_set[NR_CPUS];
60 static u8 smp_cpu_type;
61 static int smp_use_sigp_detection;
68 DEFINE_MUTEX(smp_cpu_state_mutex);
69 int smp_cpu_polarization[NR_CPUS];
70 static int smp_cpu_state[NR_CPUS];
71 static int cpu_management;
73 static DEFINE_PER_CPU(struct cpu, cpu_devices);
75 static void smp_ext_bitcall(int, int);
77 static int raw_cpu_stopped(int cpu)
81 switch (raw_sigp_ps(&status, 0, cpu, sigp_sense)) {
82 case sigp_status_stored:
83 /* Check for stopped and check stop state */
93 static inline int cpu_stopped(int cpu)
95 return raw_cpu_stopped(cpu_logical_map(cpu));
98 void smp_switch_to_ipl_cpu(void (*func)(void *), void *data)
100 struct _lowcore *lc, *current_lc;
101 struct stack_frame *sf;
102 struct pt_regs *regs;
105 if (smp_processor_id() == 0)
107 __load_psw_mask(PSW_BASE_BITS | PSW_DEFAULT_KEY);
108 /* Disable lowcore protection */
109 __ctl_clear_bit(0, 28);
110 current_lc = lowcore_ptr[smp_processor_id()];
114 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
115 lc->restart_psw.addr = PSW_ADDR_AMODE | (unsigned long) smp_restart_cpu;
117 smp_switch_to_cpu(func, data, 0, stap(), __cpu_logical_map[0]);
118 while (sigp(0, sigp_stop_and_store_status) == sigp_busy)
120 sp = lc->panic_stack;
121 sp -= sizeof(struct pt_regs);
122 regs = (struct pt_regs *) sp;
123 memcpy(®s->gprs, ¤t_lc->gpregs_save_area, sizeof(regs->gprs));
124 memcpy(®s->psw, ¤t_lc->st_status_fixed_logout, sizeof(psw_t));
125 sp -= STACK_FRAME_OVERHEAD;
126 sf = (struct stack_frame *) sp;
127 sf->back_chain = regs->gprs[15];
128 smp_switch_to_cpu(func, data, sp, stap(), __cpu_logical_map[0]);
131 void smp_send_stop(void)
135 /* Disable all interrupts/machine checks */
136 __load_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK);
137 trace_hardirqs_off();
139 /* stop all processors */
140 for_each_online_cpu(cpu) {
141 if (cpu == smp_processor_id())
144 rc = sigp(cpu, sigp_stop);
145 } while (rc == sigp_busy);
147 while (!cpu_stopped(cpu))
153 * This is the main routine where commands issued by other
157 static void do_ext_call_interrupt(__u16 code)
162 * handle bit signal external calls
164 * For the ec_schedule signal we have to do nothing. All the work
165 * is done automatically when we return from the interrupt.
167 bits = xchg(&S390_lowcore.ext_call_fast, 0);
169 if (test_bit(ec_call_function, &bits))
170 generic_smp_call_function_interrupt();
172 if (test_bit(ec_call_function_single, &bits))
173 generic_smp_call_function_single_interrupt();
177 * Send an external call sigp to another cpu and return without waiting
178 * for its completion.
180 static void smp_ext_bitcall(int cpu, int sig)
183 * Set signaling bit in lowcore of target cpu and kick it
185 set_bit(sig, (unsigned long *) &lowcore_ptr[cpu]->ext_call_fast);
186 while (sigp(cpu, sigp_emergency_signal) == sigp_busy)
190 void arch_send_call_function_ipi_mask(const struct cpumask *mask)
194 for_each_cpu(cpu, mask)
195 smp_ext_bitcall(cpu, ec_call_function);
198 void arch_send_call_function_single_ipi(int cpu)
200 smp_ext_bitcall(cpu, ec_call_function_single);
205 * this function sends a 'purge tlb' signal to another CPU.
207 static void smp_ptlb_callback(void *info)
212 void smp_ptlb_all(void)
214 on_each_cpu(smp_ptlb_callback, NULL, 1);
216 EXPORT_SYMBOL(smp_ptlb_all);
217 #endif /* ! CONFIG_64BIT */
220 * this function sends a 'reschedule' IPI to another CPU.
221 * it goes straight through and wastes no time serializing
222 * anything. Worst case is that we lose a reschedule ...
224 void smp_send_reschedule(int cpu)
226 smp_ext_bitcall(cpu, ec_schedule);
230 * parameter area for the set/clear control bit callbacks
232 struct ec_creg_mask_parms {
233 unsigned long orvals[16];
234 unsigned long andvals[16];
238 * callback for setting/clearing control bits
240 static void smp_ctl_bit_callback(void *info)
242 struct ec_creg_mask_parms *pp = info;
243 unsigned long cregs[16];
246 __ctl_store(cregs, 0, 15);
247 for (i = 0; i <= 15; i++)
248 cregs[i] = (cregs[i] & pp->andvals[i]) | pp->orvals[i];
249 __ctl_load(cregs, 0, 15);
253 * Set a bit in a control register of all cpus
255 void smp_ctl_set_bit(int cr, int bit)
257 struct ec_creg_mask_parms parms;
259 memset(&parms.orvals, 0, sizeof(parms.orvals));
260 memset(&parms.andvals, 0xff, sizeof(parms.andvals));
261 parms.orvals[cr] = 1 << bit;
262 on_each_cpu(smp_ctl_bit_callback, &parms, 1);
264 EXPORT_SYMBOL(smp_ctl_set_bit);
267 * Clear a bit in a control register of all cpus
269 void smp_ctl_clear_bit(int cr, int bit)
271 struct ec_creg_mask_parms parms;
273 memset(&parms.orvals, 0, sizeof(parms.orvals));
274 memset(&parms.andvals, 0xff, sizeof(parms.andvals));
275 parms.andvals[cr] = ~(1L << bit);
276 on_each_cpu(smp_ctl_bit_callback, &parms, 1);
278 EXPORT_SYMBOL(smp_ctl_clear_bit);
280 #ifdef CONFIG_ZFCPDUMP
282 static void __init smp_get_save_area(unsigned int cpu, unsigned int phy_cpu)
284 if (ipl_info.type != IPL_TYPE_FCP_DUMP)
286 if (cpu >= NR_CPUS) {
287 pr_warning("CPU %i exceeds the maximum %i and is excluded from "
288 "the dump\n", cpu, NR_CPUS - 1);
291 zfcpdump_save_areas[cpu] = kmalloc(sizeof(struct save_area), GFP_KERNEL);
292 while (raw_sigp(phy_cpu, sigp_stop_and_store_status) == sigp_busy)
294 memcpy(zfcpdump_save_areas[cpu],
295 (void *)(unsigned long) store_prefix() + SAVE_AREA_BASE,
296 sizeof(struct save_area));
299 struct save_area *zfcpdump_save_areas[NR_CPUS + 1];
300 EXPORT_SYMBOL_GPL(zfcpdump_save_areas);
304 static inline void smp_get_save_area(unsigned int cpu, unsigned int phy_cpu) { }
306 #endif /* CONFIG_ZFCPDUMP */
308 static int cpu_known(int cpu_id)
312 for_each_present_cpu(cpu) {
313 if (__cpu_logical_map[cpu] == cpu_id)
319 static int smp_rescan_cpus_sigp(cpumask_t avail)
321 int cpu_id, logical_cpu;
323 logical_cpu = cpumask_first(&avail);
324 if (logical_cpu >= nr_cpu_ids)
326 for (cpu_id = 0; cpu_id <= MAX_CPU_ADDRESS; cpu_id++) {
327 if (cpu_known(cpu_id))
329 __cpu_logical_map[logical_cpu] = cpu_id;
330 smp_cpu_polarization[logical_cpu] = POLARIZATION_UNKNWN;
331 if (!cpu_stopped(logical_cpu))
333 cpu_set(logical_cpu, cpu_present_map);
334 smp_cpu_state[logical_cpu] = CPU_STATE_CONFIGURED;
335 logical_cpu = cpumask_next(logical_cpu, &avail);
336 if (logical_cpu >= nr_cpu_ids)
342 static int smp_rescan_cpus_sclp(cpumask_t avail)
344 struct sclp_cpu_info *info;
345 int cpu_id, logical_cpu, cpu;
348 logical_cpu = cpumask_first(&avail);
349 if (logical_cpu >= nr_cpu_ids)
351 info = kmalloc(sizeof(*info), GFP_KERNEL);
354 rc = sclp_get_cpu_info(info);
357 for (cpu = 0; cpu < info->combined; cpu++) {
358 if (info->has_cpu_type && info->cpu[cpu].type != smp_cpu_type)
360 cpu_id = info->cpu[cpu].address;
361 if (cpu_known(cpu_id))
363 __cpu_logical_map[logical_cpu] = cpu_id;
364 smp_cpu_polarization[logical_cpu] = POLARIZATION_UNKNWN;
365 cpu_set(logical_cpu, cpu_present_map);
366 if (cpu >= info->configured)
367 smp_cpu_state[logical_cpu] = CPU_STATE_STANDBY;
369 smp_cpu_state[logical_cpu] = CPU_STATE_CONFIGURED;
370 logical_cpu = cpumask_next(logical_cpu, &avail);
371 if (logical_cpu >= nr_cpu_ids)
379 static int __smp_rescan_cpus(void)
383 cpus_xor(avail, cpu_possible_map, cpu_present_map);
384 if (smp_use_sigp_detection)
385 return smp_rescan_cpus_sigp(avail);
387 return smp_rescan_cpus_sclp(avail);
390 static void __init smp_detect_cpus(void)
392 unsigned int cpu, c_cpus, s_cpus;
393 struct sclp_cpu_info *info;
394 u16 boot_cpu_addr, cpu_addr;
398 boot_cpu_addr = __cpu_logical_map[0];
399 info = kmalloc(sizeof(*info), GFP_KERNEL);
401 panic("smp_detect_cpus failed to allocate memory\n");
402 /* Use sigp detection algorithm if sclp doesn't work. */
403 if (sclp_get_cpu_info(info)) {
404 smp_use_sigp_detection = 1;
405 for (cpu = 0; cpu <= MAX_CPU_ADDRESS; cpu++) {
406 if (cpu == boot_cpu_addr)
408 if (!raw_cpu_stopped(cpu))
410 smp_get_save_area(c_cpus, cpu);
416 if (info->has_cpu_type) {
417 for (cpu = 0; cpu < info->combined; cpu++) {
418 if (info->cpu[cpu].address == boot_cpu_addr) {
419 smp_cpu_type = info->cpu[cpu].type;
425 for (cpu = 0; cpu < info->combined; cpu++) {
426 if (info->has_cpu_type && info->cpu[cpu].type != smp_cpu_type)
428 cpu_addr = info->cpu[cpu].address;
429 if (cpu_addr == boot_cpu_addr)
431 if (!raw_cpu_stopped(cpu_addr)) {
435 smp_get_save_area(c_cpus, cpu_addr);
440 pr_info("%d configured CPUs, %d standby CPUs\n", c_cpus, s_cpus);
447 * Activate a secondary processor.
449 int __cpuinit start_secondary(void *cpuvoid)
454 /* Enable TOD clock interrupts on the secondary cpu. */
456 /* Enable cpu timer interrupts on the secondary cpu. */
458 /* Enable pfault pseudo page faults on this cpu. */
461 /* call cpu notifiers */
462 notify_cpu_starting(smp_processor_id());
463 /* Mark this cpu as online */
465 cpu_set(smp_processor_id(), cpu_online_map);
467 /* Switch on interrupts */
469 /* Print info about this processor */
471 /* cpu_idle will call schedule for us */
476 static void __init smp_create_idle(unsigned int cpu)
478 struct task_struct *p;
481 * don't care about the psw and regs settings since we'll never
482 * reschedule the forked task.
486 panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
487 current_set[cpu] = p;
490 static int __cpuinit smp_alloc_lowcore(int cpu)
492 unsigned long async_stack, panic_stack;
493 struct _lowcore *lowcore;
495 lowcore = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, LC_ORDER);
498 async_stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
499 panic_stack = __get_free_page(GFP_KERNEL);
500 if (!panic_stack || !async_stack)
502 memcpy(lowcore, &S390_lowcore, 512);
503 memset((char *)lowcore + 512, 0, sizeof(*lowcore) - 512);
504 lowcore->async_stack = async_stack + ASYNC_SIZE;
505 lowcore->panic_stack = panic_stack + PAGE_SIZE;
508 if (MACHINE_HAS_IEEE) {
509 unsigned long save_area;
511 save_area = get_zeroed_page(GFP_KERNEL);
514 lowcore->extended_save_area_addr = (u32) save_area;
517 if (vdso_alloc_per_cpu(cpu, lowcore))
520 lowcore_ptr[cpu] = lowcore;
524 free_page(panic_stack);
525 free_pages(async_stack, ASYNC_ORDER);
526 free_pages((unsigned long) lowcore, LC_ORDER);
530 static void smp_free_lowcore(int cpu)
532 struct _lowcore *lowcore;
534 lowcore = lowcore_ptr[cpu];
536 if (MACHINE_HAS_IEEE)
537 free_page((unsigned long) lowcore->extended_save_area_addr);
539 vdso_free_per_cpu(cpu, lowcore);
541 free_page(lowcore->panic_stack - PAGE_SIZE);
542 free_pages(lowcore->async_stack - ASYNC_SIZE, ASYNC_ORDER);
543 free_pages((unsigned long) lowcore, LC_ORDER);
544 lowcore_ptr[cpu] = NULL;
547 /* Upping and downing of CPUs */
548 int __cpuinit __cpu_up(unsigned int cpu)
550 struct _lowcore *cpu_lowcore;
551 struct task_struct *idle;
552 struct stack_frame *sf;
556 if (smp_cpu_state[cpu] != CPU_STATE_CONFIGURED)
558 if (smp_alloc_lowcore(cpu))
561 ccode = sigp(cpu, sigp_initial_cpu_reset);
562 if (ccode == sigp_busy)
564 if (ccode == sigp_not_operational)
566 } while (ccode == sigp_busy);
568 lowcore = (u32)(unsigned long)lowcore_ptr[cpu];
569 while (sigp_p(lowcore, cpu, sigp_set_prefix) == sigp_busy)
572 idle = current_set[cpu];
573 cpu_lowcore = lowcore_ptr[cpu];
574 cpu_lowcore->kernel_stack = (unsigned long)
575 task_stack_page(idle) + THREAD_SIZE;
576 cpu_lowcore->thread_info = (unsigned long) task_thread_info(idle);
577 sf = (struct stack_frame *) (cpu_lowcore->kernel_stack
578 - sizeof(struct pt_regs)
579 - sizeof(struct stack_frame));
580 memset(sf, 0, sizeof(struct stack_frame));
581 sf->gprs[9] = (unsigned long) sf;
582 cpu_lowcore->save_area[15] = (unsigned long) sf;
583 __ctl_store(cpu_lowcore->cregs_save_area, 0, 15);
586 : : "a" (&cpu_lowcore->access_regs_save_area) : "memory");
587 cpu_lowcore->percpu_offset = __per_cpu_offset[cpu];
588 cpu_lowcore->current_task = (unsigned long) idle;
589 cpu_lowcore->cpu_nr = cpu;
590 cpu_lowcore->kernel_asce = S390_lowcore.kernel_asce;
591 cpu_lowcore->machine_flags = S390_lowcore.machine_flags;
592 cpu_lowcore->ftrace_func = S390_lowcore.ftrace_func;
595 while (sigp(cpu, sigp_restart) == sigp_busy)
598 while (!cpu_online(cpu))
603 smp_free_lowcore(cpu);
607 static int __init setup_possible_cpus(char *s)
611 pcpus = simple_strtoul(s, NULL, 0);
612 init_cpu_possible(cpumask_of(0));
613 for (cpu = 1; cpu < pcpus && cpu < nr_cpu_ids; cpu++)
614 set_cpu_possible(cpu, true);
617 early_param("possible_cpus", setup_possible_cpus);
619 #ifdef CONFIG_HOTPLUG_CPU
621 int __cpu_disable(void)
623 struct ec_creg_mask_parms cr_parms;
624 int cpu = smp_processor_id();
626 cpu_clear(cpu, cpu_online_map);
628 /* Disable pfault pseudo page faults on this cpu. */
631 memset(&cr_parms.orvals, 0, sizeof(cr_parms.orvals));
632 memset(&cr_parms.andvals, 0xff, sizeof(cr_parms.andvals));
634 /* disable all external interrupts */
635 cr_parms.orvals[0] = 0;
636 cr_parms.andvals[0] = ~(1 << 15 | 1 << 14 | 1 << 13 | 1 << 12 |
637 1 << 11 | 1 << 10 | 1 << 6 | 1 << 4);
638 /* disable all I/O interrupts */
639 cr_parms.orvals[6] = 0;
640 cr_parms.andvals[6] = ~(1 << 31 | 1 << 30 | 1 << 29 | 1 << 28 |
641 1 << 27 | 1 << 26 | 1 << 25 | 1 << 24);
642 /* disable most machine checks */
643 cr_parms.orvals[14] = 0;
644 cr_parms.andvals[14] = ~(1 << 28 | 1 << 27 | 1 << 26 |
647 smp_ctl_bit_callback(&cr_parms);
652 void __cpu_die(unsigned int cpu)
654 /* Wait until target cpu is down */
655 while (!cpu_stopped(cpu))
657 while (sigp_p(0, cpu, sigp_set_prefix) == sigp_busy)
659 smp_free_lowcore(cpu);
660 pr_info("Processor %d stopped\n", cpu);
666 while (sigp(smp_processor_id(), sigp_stop) == sigp_busy)
671 #endif /* CONFIG_HOTPLUG_CPU */
673 void __init smp_prepare_cpus(unsigned int max_cpus)
676 unsigned long save_area = 0;
678 unsigned long async_stack, panic_stack;
679 struct _lowcore *lowcore;
684 /* request the 0x1201 emergency signal external interrupt */
685 if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0)
686 panic("Couldn't request external interrupt 0x1201");
689 /* Reallocate current lowcore, but keep its contents. */
690 lowcore = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, LC_ORDER);
691 panic_stack = __get_free_page(GFP_KERNEL);
692 async_stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
693 BUG_ON(!lowcore || !panic_stack || !async_stack);
695 if (MACHINE_HAS_IEEE)
696 save_area = get_zeroed_page(GFP_KERNEL);
699 local_mcck_disable();
700 lowcore_ptr[smp_processor_id()] = lowcore;
701 *lowcore = S390_lowcore;
702 lowcore->panic_stack = panic_stack + PAGE_SIZE;
703 lowcore->async_stack = async_stack + ASYNC_SIZE;
705 if (MACHINE_HAS_IEEE)
706 lowcore->extended_save_area_addr = (u32) save_area;
708 set_prefix((u32)(unsigned long) lowcore);
712 if (vdso_alloc_per_cpu(smp_processor_id(), &S390_lowcore))
715 for_each_possible_cpu(cpu)
716 if (cpu != smp_processor_id())
717 smp_create_idle(cpu);
720 void __init smp_prepare_boot_cpu(void)
722 BUG_ON(smp_processor_id() != 0);
724 current_thread_info()->cpu = 0;
725 cpu_set(0, cpu_present_map);
726 cpu_set(0, cpu_online_map);
727 S390_lowcore.percpu_offset = __per_cpu_offset[0];
728 current_set[0] = current;
729 smp_cpu_state[0] = CPU_STATE_CONFIGURED;
730 smp_cpu_polarization[0] = POLARIZATION_UNKNWN;
733 void __init smp_cpus_done(unsigned int max_cpus)
737 void __init smp_setup_processor_id(void)
739 S390_lowcore.cpu_nr = 0;
740 __cpu_logical_map[0] = stap();
744 * the frequency of the profiling timer can be changed
745 * by writing a multiplier value into /proc/profile.
747 * usually you want to run this on all CPUs ;)
749 int setup_profiling_timer(unsigned int multiplier)
754 #ifdef CONFIG_HOTPLUG_CPU
755 static ssize_t cpu_configure_show(struct sys_device *dev,
756 struct sysdev_attribute *attr, char *buf)
760 mutex_lock(&smp_cpu_state_mutex);
761 count = sprintf(buf, "%d\n", smp_cpu_state[dev->id]);
762 mutex_unlock(&smp_cpu_state_mutex);
766 static ssize_t cpu_configure_store(struct sys_device *dev,
767 struct sysdev_attribute *attr,
768 const char *buf, size_t count)
774 if (sscanf(buf, "%d %c", &val, &delim) != 1)
776 if (val != 0 && val != 1)
780 mutex_lock(&smp_cpu_state_mutex);
782 /* disallow configuration changes of online cpus and cpu 0 */
783 if (cpu_online(cpu) || cpu == 0)
788 if (smp_cpu_state[cpu] == CPU_STATE_CONFIGURED) {
789 rc = sclp_cpu_deconfigure(__cpu_logical_map[cpu]);
791 smp_cpu_state[cpu] = CPU_STATE_STANDBY;
792 smp_cpu_polarization[cpu] = POLARIZATION_UNKNWN;
797 if (smp_cpu_state[cpu] == CPU_STATE_STANDBY) {
798 rc = sclp_cpu_configure(__cpu_logical_map[cpu]);
800 smp_cpu_state[cpu] = CPU_STATE_CONFIGURED;
801 smp_cpu_polarization[cpu] = POLARIZATION_UNKNWN;
809 mutex_unlock(&smp_cpu_state_mutex);
811 return rc ? rc : count;
813 static SYSDEV_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store);
814 #endif /* CONFIG_HOTPLUG_CPU */
816 static ssize_t cpu_polarization_show(struct sys_device *dev,
817 struct sysdev_attribute *attr, char *buf)
822 mutex_lock(&smp_cpu_state_mutex);
823 switch (smp_cpu_polarization[cpu]) {
824 case POLARIZATION_HRZ:
825 count = sprintf(buf, "horizontal\n");
827 case POLARIZATION_VL:
828 count = sprintf(buf, "vertical:low\n");
830 case POLARIZATION_VM:
831 count = sprintf(buf, "vertical:medium\n");
833 case POLARIZATION_VH:
834 count = sprintf(buf, "vertical:high\n");
837 count = sprintf(buf, "unknown\n");
840 mutex_unlock(&smp_cpu_state_mutex);
843 static SYSDEV_ATTR(polarization, 0444, cpu_polarization_show, NULL);
845 static ssize_t show_cpu_address(struct sys_device *dev,
846 struct sysdev_attribute *attr, char *buf)
848 return sprintf(buf, "%d\n", __cpu_logical_map[dev->id]);
850 static SYSDEV_ATTR(address, 0444, show_cpu_address, NULL);
853 static struct attribute *cpu_common_attrs[] = {
854 #ifdef CONFIG_HOTPLUG_CPU
855 &attr_configure.attr,
858 &attr_polarization.attr,
862 static struct attribute_group cpu_common_attr_group = {
863 .attrs = cpu_common_attrs,
866 static ssize_t show_capability(struct sys_device *dev,
867 struct sysdev_attribute *attr, char *buf)
869 unsigned int capability;
872 rc = get_cpu_capability(&capability);
875 return sprintf(buf, "%u\n", capability);
877 static SYSDEV_ATTR(capability, 0444, show_capability, NULL);
879 static ssize_t show_idle_count(struct sys_device *dev,
880 struct sysdev_attribute *attr, char *buf)
882 struct s390_idle_data *idle;
883 unsigned long long idle_count;
884 unsigned int sequence;
886 idle = &per_cpu(s390_idle, dev->id);
888 sequence = idle->sequence;
892 idle_count = idle->idle_count;
893 if (idle->idle_enter)
896 if (idle->sequence != sequence)
898 return sprintf(buf, "%llu\n", idle_count);
900 static SYSDEV_ATTR(idle_count, 0444, show_idle_count, NULL);
902 static ssize_t show_idle_time(struct sys_device *dev,
903 struct sysdev_attribute *attr, char *buf)
905 struct s390_idle_data *idle;
906 unsigned long long now, idle_time, idle_enter;
907 unsigned int sequence;
909 idle = &per_cpu(s390_idle, dev->id);
912 sequence = idle->sequence;
916 idle_time = idle->idle_time;
917 idle_enter = idle->idle_enter;
918 if (idle_enter != 0ULL && idle_enter < now)
919 idle_time += now - idle_enter;
921 if (idle->sequence != sequence)
923 return sprintf(buf, "%llu\n", idle_time >> 12);
925 static SYSDEV_ATTR(idle_time_us, 0444, show_idle_time, NULL);
927 static struct attribute *cpu_online_attrs[] = {
928 &attr_capability.attr,
929 &attr_idle_count.attr,
930 &attr_idle_time_us.attr,
934 static struct attribute_group cpu_online_attr_group = {
935 .attrs = cpu_online_attrs,
938 static int __cpuinit smp_cpu_notify(struct notifier_block *self,
939 unsigned long action, void *hcpu)
941 unsigned int cpu = (unsigned int)(long)hcpu;
942 struct cpu *c = &per_cpu(cpu_devices, cpu);
943 struct sys_device *s = &c->sysdev;
944 struct s390_idle_data *idle;
948 case CPU_ONLINE_FROZEN:
949 idle = &per_cpu(s390_idle, cpu);
950 memset(idle, 0, sizeof(struct s390_idle_data));
951 if (sysfs_create_group(&s->kobj, &cpu_online_attr_group))
955 case CPU_DEAD_FROZEN:
956 sysfs_remove_group(&s->kobj, &cpu_online_attr_group);
962 static struct notifier_block __cpuinitdata smp_cpu_nb = {
963 .notifier_call = smp_cpu_notify,
966 static int __devinit smp_add_present_cpu(int cpu)
968 struct cpu *c = &per_cpu(cpu_devices, cpu);
969 struct sys_device *s = &c->sysdev;
973 rc = register_cpu(c, cpu);
976 rc = sysfs_create_group(&s->kobj, &cpu_common_attr_group);
979 if (!cpu_online(cpu))
981 rc = sysfs_create_group(&s->kobj, &cpu_online_attr_group);
984 sysfs_remove_group(&s->kobj, &cpu_common_attr_group);
986 #ifdef CONFIG_HOTPLUG_CPU
993 #ifdef CONFIG_HOTPLUG_CPU
995 int __ref smp_rescan_cpus(void)
1002 mutex_lock(&smp_cpu_state_mutex);
1003 newcpus = cpu_present_map;
1004 rc = __smp_rescan_cpus();
1007 cpus_andnot(newcpus, cpu_present_map, newcpus);
1008 for_each_cpu_mask(cpu, newcpus) {
1009 rc = smp_add_present_cpu(cpu);
1011 cpu_clear(cpu, cpu_present_map);
1015 mutex_unlock(&smp_cpu_state_mutex);
1017 if (!cpus_empty(newcpus))
1018 topology_schedule_update();
1022 static ssize_t __ref rescan_store(struct sysdev_class *class, const char *buf,
1027 rc = smp_rescan_cpus();
1028 return rc ? rc : count;
1030 static SYSDEV_CLASS_ATTR(rescan, 0200, NULL, rescan_store);
1031 #endif /* CONFIG_HOTPLUG_CPU */
1033 static ssize_t dispatching_show(struct sysdev_class *class, char *buf)
1037 mutex_lock(&smp_cpu_state_mutex);
1038 count = sprintf(buf, "%d\n", cpu_management);
1039 mutex_unlock(&smp_cpu_state_mutex);
1043 static ssize_t dispatching_store(struct sysdev_class *dev, const char *buf,
1049 if (sscanf(buf, "%d %c", &val, &delim) != 1)
1051 if (val != 0 && val != 1)
1055 mutex_lock(&smp_cpu_state_mutex);
1056 if (cpu_management == val)
1058 rc = topology_set_cpu_management(val);
1060 cpu_management = val;
1062 mutex_unlock(&smp_cpu_state_mutex);
1064 return rc ? rc : count;
1066 static SYSDEV_CLASS_ATTR(dispatching, 0644, dispatching_show,
1069 static int __init topology_init(void)
1074 register_cpu_notifier(&smp_cpu_nb);
1076 #ifdef CONFIG_HOTPLUG_CPU
1077 rc = sysdev_class_create_file(&cpu_sysdev_class, &attr_rescan);
1081 rc = sysdev_class_create_file(&cpu_sysdev_class, &attr_dispatching);
1084 for_each_present_cpu(cpu) {
1085 rc = smp_add_present_cpu(cpu);
1091 subsys_initcall(topology_init);