
If we're running a kernel compiled with SMP_ON_UP=y and the hardware only supports UP operation there isn't any smp_cross_call function assigned. Unfortunately, we call smp_cross_call() unconditionally in arch_irq_work_raise() and crash the kernel on UP devices. Check to make sure we're running on an SMP device before calling smp_cross_call() here. Unable to handle kernel NULL pointer dereference at virtual address 00000000 pgd = c0004000 [00000000] *pgd=00000000 Internal error: Oops: 80000005 [#1] SMP ARM Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.12.0-rc6-00018-g8d45144-dirty #16 task: de05b440 ti: de05c000 task.ti: de05c000 PC is at 0x0 LR is at arch_irq_work_raise+0x3c/0x48 pc : [<00000000>] lr : [<c0019590>] psr: 60000193 sp : de05dd60 ip : 00000001 fp : 00000000 r10: c085e2f0 r9 : de05c000 r8 : c07be0a4 r7 : de05c000 r6 : de05c000 r5 : c07c5778 r4 : c0824554 r3 : 00000000 r2 : 00000000 r1 : 00000006 r0 : c0529a58 Flags: nZCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment kernel Control: 10c5387d Table: 80004019 DAC: 00000017 Process swapper/0 (pid: 1, stack limit = 0xde05c248) Stack: (0xde05dd60 to 0xde05e000) dd60: c07b9dbc c00cb2dc 00000001 c08242c0 c08242c0 60000113 c07be0a8 c00b0590 dd80: de05c000 c085e2f0 c08242c0 c08242c0 c1414c28 c00b07cc de05b440 c1414c28 dda0: c08242c0 c00b0af8 c0862bb0 c0862db0 c1414cd8 de05c028 c0824840 de05ddb8 ddc0: 00000000 00000009 00000001 00000024 c07be0a8 c07be0a4 de05c000 c085e2f0 dde0: 00000000 c004a4b0 00000010 de00d2dc 00000054 00000100 00000024 00000000 de00: de05c028 0000000a ffff8ae7 00200040 00000016 de05c000 60000193 de05c000 de20: 00000054 00000000 00000000 00000000 00000000 c004a704 00000000 de05c008 de40: c07ba254 c004aa1c c07c5778 c0014b70 fa200000 00000054 de05de80 c0861244 de60: 00000000 c0008634 de05b440 c051c778 20000113 ffffffffde05deb4
c051d0a4 de80: 00000001 00000001 00000000 de05b440c082afac
de057ac0 de057ac0 de0443c0 dea0: 00000000 00000000 00000000 00000000 c082afbc de05dec8 c009f2a0 c051c778 dec0: 20000113 ffffffff 00000000 c016edb0 00000000 000002b0 de057ac0 de057ac0 dee0: 00000000 c016ee40 c0875e50 de05df2e de057ac0 00000000 00000013 00000000 df00: 00000000 c016f054 de043600 de0443c0 c008eb38 de004ec0 c0875e50 c008eb44 df20: 00000012 00000000 00000000 3931f0f8 00000000 00000000 00000014 c0822e84 df40: 00000000 c008ed2c 00000000 00000000 00000000 c07b7490 c07b7490 c075ab3c df60: 00000000 c00701ac 00000002 00000000 c0070160 dffadb73 7bf8edb4 00000000 df80: c051092c 00000000 00000000 00000000 00000000 00000000 00000000 c0510934 dfa0: de05aa40 00000000 c051092c c0013ce8 00000000 00000000 00000000 00000000 dfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 dfe0: 00000000 00000000 00000000 00000000 00000013 00000000 07efffe5 4dfac6f5 [<c0019590>] (arch_irq_work_raise+0x3c/0x48) from [<c00cb2dc>] (irq_work_queue+0xe4/0xf8) [<c00cb2dc>] (irq_work_queue+0xe4/0xf8) from [<c00b0590>] (rcu_accelerate_cbs+0x1d4/0x1d8) [<c00b0590>] (rcu_accelerate_cbs+0x1d4/0x1d8) from [<c00b07cc>] (rcu_start_gp+0x34/0x48) [<c00b07cc>] (rcu_start_gp+0x34/0x48) from [<c00b0af8>] (rcu_process_callbacks+0x318/0x608) [<c00b0af8>] (rcu_process_callbacks+0x318/0x608) from [<c004a4b0>] (__do_softirq+0x114/0x2a0) [<c004a4b0>] (__do_softirq+0x114/0x2a0) from [<c004a704>] (do_softirq+0x6c/0x74) [<c004a704>] (do_softirq+0x6c/0x74) from [<c004aa1c>] (irq_exit+0xac/0x100) [<c004aa1c>] (irq_exit+0xac/0x100) from [<c0014b70>] (handle_IRQ+0x54/0xb4) [<c0014b70>] (handle_IRQ+0x54/0xb4) from [<c0008634>] (omap3_intc_handle_irq+0x60/0x74) [<c0008634>] (omap3_intc_handle_irq+0x60/0x74) from [<c051d0a4>] (__irq_svc+0x44/0x5c) Exception stack(0xde05de80 to 0xde05dec8) de80: 00000001 00000001 00000000 de05b440c082afac
de057ac0 de057ac0 de0443c0 dea0: 00000000 00000000 00000000 00000000 c082afbc de05dec8 c009f2a0 c051c778 dec0: 20000113 ffffffff [<c051d0a4>] (__irq_svc+0x44/0x5c) from [<c051c778>] (_raw_spin_unlock_irq+0x28/0x2c) [<c051c778>] (_raw_spin_unlock_irq+0x28/0x2c) from [<c016edb0>] (proc_alloc_inum+0x30/0xa8) [<c016edb0>] (proc_alloc_inum+0x30/0xa8) from [<c016ee40>] (proc_register+0x18/0x130) [<c016ee40>] (proc_register+0x18/0x130) from [<c016f054>] (proc_mkdir_data+0x44/0x6c) [<c016f054>] (proc_mkdir_data+0x44/0x6c) from [<c008eb44>] (register_irq_proc+0x6c/0x128) [<c008eb44>] (register_irq_proc+0x6c/0x128) from [<c008ed2c>] (init_irq_proc+0x74/0xb0) [<c008ed2c>] (init_irq_proc+0x74/0xb0) from [<c075ab3c>] (kernel_init_freeable+0x84/0x1c8) [<c075ab3c>] (kernel_init_freeable+0x84/0x1c8) from [<c0510934>] (kernel_init+0x8/0x150) [<c0510934>] (kernel_init+0x8/0x150) from [<c0013ce8>] (ret_from_fork+0x14/0x2c) Code: bad PC value Fixes:bf18525fd7
"ARM: 7872/1: Support arch_irq_work_raise() via self IPIs" Reported-by: Olof Johansson <olof@lixom.net> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Tested-by: Olof Johansson <olof@lixom.net> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
679 lines
15 KiB
C
679 lines
15 KiB
C
/*
|
|
* linux/arch/arm/kernel/smp.c
|
|
*
|
|
* Copyright (C) 2002 ARM Limited, All Rights Reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
#include <linux/module.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/init.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/cache.h>
|
|
#include <linux/profile.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/err.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/irq.h>
|
|
#include <linux/percpu.h>
|
|
#include <linux/clockchips.h>
|
|
#include <linux/completion.h>
|
|
#include <linux/cpufreq.h>
|
|
#include <linux/irq_work.h>
|
|
|
|
#include <linux/atomic.h>
|
|
#include <asm/smp.h>
|
|
#include <asm/cacheflush.h>
|
|
#include <asm/cpu.h>
|
|
#include <asm/cputype.h>
|
|
#include <asm/exception.h>
|
|
#include <asm/idmap.h>
|
|
#include <asm/topology.h>
|
|
#include <asm/mmu_context.h>
|
|
#include <asm/pgtable.h>
|
|
#include <asm/pgalloc.h>
|
|
#include <asm/processor.h>
|
|
#include <asm/sections.h>
|
|
#include <asm/tlbflush.h>
|
|
#include <asm/ptrace.h>
|
|
#include <asm/smp_plat.h>
|
|
#include <asm/virt.h>
|
|
#include <asm/mach/arch.h>
|
|
#include <asm/mpu.h>
|
|
|
|
/*
|
|
* as from 2.5, kernels no longer have an init_tasks structure
|
|
* so we need some other way of telling a new secondary core
|
|
* where to place its SVC stack
|
|
*/
|
|
struct secondary_data secondary_data;
|
|
|
|
/*
|
|
* control for which core is the next to come out of the secondary
|
|
* boot "holding pen"
|
|
*/
|
|
volatile int pen_release = -1;
|
|
|
|
enum ipi_msg_type {
|
|
IPI_WAKEUP,
|
|
IPI_TIMER,
|
|
IPI_RESCHEDULE,
|
|
IPI_CALL_FUNC,
|
|
IPI_CALL_FUNC_SINGLE,
|
|
IPI_CPU_STOP,
|
|
IPI_IRQ_WORK,
|
|
};
|
|
|
|
static DECLARE_COMPLETION(cpu_running);
|
|
|
|
static struct smp_operations smp_ops;
|
|
|
|
void __init smp_set_ops(struct smp_operations *ops)
|
|
{
|
|
if (ops)
|
|
smp_ops = *ops;
|
|
};
|
|
|
|
static unsigned long get_arch_pgd(pgd_t *pgd)
|
|
{
|
|
phys_addr_t pgdir = virt_to_phys(pgd);
|
|
BUG_ON(pgdir & ARCH_PGD_MASK);
|
|
return pgdir >> ARCH_PGD_SHIFT;
|
|
}
|
|
|
|
int __cpu_up(unsigned int cpu, struct task_struct *idle)
|
|
{
|
|
int ret;
|
|
|
|
/*
|
|
* We need to tell the secondary core where to find
|
|
* its stack and the page tables.
|
|
*/
|
|
secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
|
|
#ifdef CONFIG_ARM_MPU
|
|
secondary_data.mpu_rgn_szr = mpu_rgn_info.rgns[MPU_RAM_REGION].drsr;
|
|
#endif
|
|
|
|
#ifdef CONFIG_MMU
|
|
secondary_data.pgdir = get_arch_pgd(idmap_pgd);
|
|
secondary_data.swapper_pg_dir = get_arch_pgd(swapper_pg_dir);
|
|
#endif
|
|
__cpuc_flush_dcache_area(&secondary_data, sizeof(secondary_data));
|
|
outer_clean_range(__pa(&secondary_data), __pa(&secondary_data + 1));
|
|
|
|
/*
|
|
* Now bring the CPU into our world.
|
|
*/
|
|
ret = boot_secondary(cpu, idle);
|
|
if (ret == 0) {
|
|
/*
|
|
* CPU was successfully started, wait for it
|
|
* to come online or time out.
|
|
*/
|
|
wait_for_completion_timeout(&cpu_running,
|
|
msecs_to_jiffies(1000));
|
|
|
|
if (!cpu_online(cpu)) {
|
|
pr_crit("CPU%u: failed to come online\n", cpu);
|
|
ret = -EIO;
|
|
}
|
|
} else {
|
|
pr_err("CPU%u: failed to boot: %d\n", cpu, ret);
|
|
}
|
|
|
|
|
|
memset(&secondary_data, 0, sizeof(secondary_data));
|
|
return ret;
|
|
}
|
|
|
|
/* platform specific SMP operations */
|
|
void __init smp_init_cpus(void)
|
|
{
|
|
if (smp_ops.smp_init_cpus)
|
|
smp_ops.smp_init_cpus();
|
|
}
|
|
|
|
int boot_secondary(unsigned int cpu, struct task_struct *idle)
|
|
{
|
|
if (smp_ops.smp_boot_secondary)
|
|
return smp_ops.smp_boot_secondary(cpu, idle);
|
|
return -ENOSYS;
|
|
}
|
|
|
|
int platform_can_cpu_hotplug(void)
|
|
{
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
if (smp_ops.cpu_kill)
|
|
return 1;
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
static int platform_cpu_kill(unsigned int cpu)
|
|
{
|
|
if (smp_ops.cpu_kill)
|
|
return smp_ops.cpu_kill(cpu);
|
|
return 1;
|
|
}
|
|
|
|
static int platform_cpu_disable(unsigned int cpu)
|
|
{
|
|
if (smp_ops.cpu_disable)
|
|
return smp_ops.cpu_disable(cpu);
|
|
|
|
/*
|
|
* By default, allow disabling all CPUs except the first one,
|
|
* since this is special on a lot of platforms, e.g. because
|
|
* of clock tick interrupts.
|
|
*/
|
|
return cpu == 0 ? -EPERM : 0;
|
|
}
|
|
/*
|
|
* __cpu_disable runs on the processor to be shutdown.
|
|
*/
|
|
int __cpu_disable(void)
|
|
{
|
|
unsigned int cpu = smp_processor_id();
|
|
int ret;
|
|
|
|
ret = platform_cpu_disable(cpu);
|
|
if (ret)
|
|
return ret;
|
|
|
|
/*
|
|
* Take this CPU offline. Once we clear this, we can't return,
|
|
* and we must not schedule until we're ready to give up the cpu.
|
|
*/
|
|
set_cpu_online(cpu, false);
|
|
|
|
/*
|
|
* OK - migrate IRQs away from this CPU
|
|
*/
|
|
migrate_irqs();
|
|
|
|
/*
|
|
* Flush user cache and TLB mappings, and then remove this CPU
|
|
* from the vm mask set of all processes.
|
|
*
|
|
* Caches are flushed to the Level of Unification Inner Shareable
|
|
* to write-back dirty lines to unified caches shared by all CPUs.
|
|
*/
|
|
flush_cache_louis();
|
|
local_flush_tlb_all();
|
|
|
|
clear_tasks_mm_cpumask(cpu);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static DECLARE_COMPLETION(cpu_died);
|
|
|
|
/*
|
|
* called on the thread which is asking for a CPU to be shutdown -
|
|
* waits until shutdown has completed, or it is timed out.
|
|
*/
|
|
void __cpu_die(unsigned int cpu)
|
|
{
|
|
if (!wait_for_completion_timeout(&cpu_died, msecs_to_jiffies(5000))) {
|
|
pr_err("CPU%u: cpu didn't die\n", cpu);
|
|
return;
|
|
}
|
|
printk(KERN_NOTICE "CPU%u: shutdown\n", cpu);
|
|
|
|
/*
|
|
* platform_cpu_kill() is generally expected to do the powering off
|
|
* and/or cutting of clocks to the dying CPU. Optionally, this may
|
|
* be done by the CPU which is dying in preference to supporting
|
|
* this call, but that means there is _no_ synchronisation between
|
|
* the requesting CPU and the dying CPU actually losing power.
|
|
*/
|
|
if (!platform_cpu_kill(cpu))
|
|
printk("CPU%u: unable to kill\n", cpu);
|
|
}
|
|
|
|
/*
|
|
* Called from the idle thread for the CPU which has been shutdown.
|
|
*
|
|
* Note that we disable IRQs here, but do not re-enable them
|
|
* before returning to the caller. This is also the behaviour
|
|
* of the other hotplug-cpu capable cores, so presumably coming
|
|
* out of idle fixes this.
|
|
*/
|
|
void __ref cpu_die(void)
|
|
{
|
|
unsigned int cpu = smp_processor_id();
|
|
|
|
idle_task_exit();
|
|
|
|
local_irq_disable();
|
|
|
|
/*
|
|
* Flush the data out of the L1 cache for this CPU. This must be
|
|
* before the completion to ensure that data is safely written out
|
|
* before platform_cpu_kill() gets called - which may disable
|
|
* *this* CPU and power down its cache.
|
|
*/
|
|
flush_cache_louis();
|
|
|
|
/*
|
|
* Tell __cpu_die() that this CPU is now safe to dispose of. Once
|
|
* this returns, power and/or clocks can be removed at any point
|
|
* from this CPU and its cache by platform_cpu_kill().
|
|
*/
|
|
complete(&cpu_died);
|
|
|
|
/*
|
|
* Ensure that the cache lines associated with that completion are
|
|
* written out. This covers the case where _this_ CPU is doing the
|
|
* powering down, to ensure that the completion is visible to the
|
|
* CPU waiting for this one.
|
|
*/
|
|
flush_cache_louis();
|
|
|
|
/*
|
|
* The actual CPU shutdown procedure is at least platform (if not
|
|
* CPU) specific. This may remove power, or it may simply spin.
|
|
*
|
|
* Platforms are generally expected *NOT* to return from this call,
|
|
* although there are some which do because they have no way to
|
|
* power down the CPU. These platforms are the _only_ reason we
|
|
* have a return path which uses the fragment of assembly below.
|
|
*
|
|
* The return path should not be used for platforms which can
|
|
* power off the CPU.
|
|
*/
|
|
if (smp_ops.cpu_die)
|
|
smp_ops.cpu_die(cpu);
|
|
|
|
/*
|
|
* Do not return to the idle loop - jump back to the secondary
|
|
* cpu initialisation. There's some initialisation which needs
|
|
* to be repeated to undo the effects of taking the CPU offline.
|
|
*/
|
|
__asm__("mov sp, %0\n"
|
|
" mov fp, #0\n"
|
|
" b secondary_start_kernel"
|
|
:
|
|
: "r" (task_stack_page(current) + THREAD_SIZE - 8));
|
|
}
|
|
#endif /* CONFIG_HOTPLUG_CPU */
|
|
|
|
/*
|
|
* Called by both boot and secondaries to move global data into
|
|
* per-processor storage.
|
|
*/
|
|
static void smp_store_cpu_info(unsigned int cpuid)
|
|
{
|
|
struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid);
|
|
|
|
cpu_info->loops_per_jiffy = loops_per_jiffy;
|
|
cpu_info->cpuid = read_cpuid_id();
|
|
|
|
store_cpu_topology(cpuid);
|
|
}
|
|
|
|
/*
|
|
* This is the secondary CPU boot entry. We're using this CPUs
|
|
* idle thread stack, but a set of temporary page tables.
|
|
*/
|
|
asmlinkage void secondary_start_kernel(void)
|
|
{
|
|
struct mm_struct *mm = &init_mm;
|
|
unsigned int cpu;
|
|
|
|
/*
|
|
* The identity mapping is uncached (strongly ordered), so
|
|
* switch away from it before attempting any exclusive accesses.
|
|
*/
|
|
cpu_switch_mm(mm->pgd, mm);
|
|
local_flush_bp_all();
|
|
enter_lazy_tlb(mm, current);
|
|
local_flush_tlb_all();
|
|
|
|
/*
|
|
* All kernel threads share the same mm context; grab a
|
|
* reference and switch to it.
|
|
*/
|
|
cpu = smp_processor_id();
|
|
atomic_inc(&mm->mm_count);
|
|
current->active_mm = mm;
|
|
cpumask_set_cpu(cpu, mm_cpumask(mm));
|
|
|
|
cpu_init();
|
|
|
|
printk("CPU%u: Booted secondary processor\n", cpu);
|
|
|
|
preempt_disable();
|
|
trace_hardirqs_off();
|
|
|
|
/*
|
|
* Give the platform a chance to do its own initialisation.
|
|
*/
|
|
if (smp_ops.smp_secondary_init)
|
|
smp_ops.smp_secondary_init(cpu);
|
|
|
|
notify_cpu_starting(cpu);
|
|
|
|
calibrate_delay();
|
|
|
|
smp_store_cpu_info(cpu);
|
|
|
|
/*
|
|
* OK, now it's safe to let the boot CPU continue. Wait for
|
|
* the CPU migration code to notice that the CPU is online
|
|
* before we continue - which happens after __cpu_up returns.
|
|
*/
|
|
set_cpu_online(cpu, true);
|
|
complete(&cpu_running);
|
|
|
|
local_irq_enable();
|
|
local_fiq_enable();
|
|
|
|
/*
|
|
* OK, it's off to the idle thread for us
|
|
*/
|
|
cpu_startup_entry(CPUHP_ONLINE);
|
|
}
|
|
|
|
void __init smp_cpus_done(unsigned int max_cpus)
|
|
{
|
|
printk(KERN_INFO "SMP: Total of %d processors activated.\n",
|
|
num_online_cpus());
|
|
|
|
hyp_mode_check();
|
|
}
|
|
|
|
void __init smp_prepare_boot_cpu(void)
|
|
{
|
|
set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
|
|
}
|
|
|
|
void __init smp_prepare_cpus(unsigned int max_cpus)
|
|
{
|
|
unsigned int ncores = num_possible_cpus();
|
|
|
|
init_cpu_topology();
|
|
|
|
smp_store_cpu_info(smp_processor_id());
|
|
|
|
/*
|
|
* are we trying to boot more cores than exist?
|
|
*/
|
|
if (max_cpus > ncores)
|
|
max_cpus = ncores;
|
|
if (ncores > 1 && max_cpus) {
|
|
/*
|
|
* Initialise the present map, which describes the set of CPUs
|
|
* actually populated at the present time. A platform should
|
|
* re-initialize the map in the platforms smp_prepare_cpus()
|
|
* if present != possible (e.g. physical hotplug).
|
|
*/
|
|
init_cpu_present(cpu_possible_mask);
|
|
|
|
/*
|
|
* Initialise the SCU if there are more than one CPU
|
|
* and let them know where to start.
|
|
*/
|
|
if (smp_ops.smp_prepare_cpus)
|
|
smp_ops.smp_prepare_cpus(max_cpus);
|
|
}
|
|
}
|
|
|
|
static void (*smp_cross_call)(const struct cpumask *, unsigned int);
|
|
|
|
void __init set_smp_cross_call(void (*fn)(const struct cpumask *, unsigned int))
|
|
{
|
|
if (!smp_cross_call)
|
|
smp_cross_call = fn;
|
|
}
|
|
|
|
void arch_send_call_function_ipi_mask(const struct cpumask *mask)
|
|
{
|
|
smp_cross_call(mask, IPI_CALL_FUNC);
|
|
}
|
|
|
|
void arch_send_wakeup_ipi_mask(const struct cpumask *mask)
|
|
{
|
|
smp_cross_call(mask, IPI_WAKEUP);
|
|
}
|
|
|
|
void arch_send_call_function_single_ipi(int cpu)
|
|
{
|
|
smp_cross_call(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
|
|
}
|
|
|
|
#ifdef CONFIG_IRQ_WORK
|
|
void arch_irq_work_raise(void)
|
|
{
|
|
if (is_smp())
|
|
smp_cross_call(cpumask_of(smp_processor_id()), IPI_IRQ_WORK);
|
|
}
|
|
#endif
|
|
|
|
static const char *ipi_types[NR_IPI] = {
|
|
#define S(x,s) [x] = s
|
|
S(IPI_WAKEUP, "CPU wakeup interrupts"),
|
|
S(IPI_TIMER, "Timer broadcast interrupts"),
|
|
S(IPI_RESCHEDULE, "Rescheduling interrupts"),
|
|
S(IPI_CALL_FUNC, "Function call interrupts"),
|
|
S(IPI_CALL_FUNC_SINGLE, "Single function call interrupts"),
|
|
S(IPI_CPU_STOP, "CPU stop interrupts"),
|
|
S(IPI_IRQ_WORK, "IRQ work interrupts"),
|
|
};
|
|
|
|
void show_ipi_list(struct seq_file *p, int prec)
|
|
{
|
|
unsigned int cpu, i;
|
|
|
|
for (i = 0; i < NR_IPI; i++) {
|
|
seq_printf(p, "%*s%u: ", prec - 1, "IPI", i);
|
|
|
|
for_each_online_cpu(cpu)
|
|
seq_printf(p, "%10u ",
|
|
__get_irq_stat(cpu, ipi_irqs[i]));
|
|
|
|
seq_printf(p, " %s\n", ipi_types[i]);
|
|
}
|
|
}
|
|
|
|
u64 smp_irq_stat_cpu(unsigned int cpu)
|
|
{
|
|
u64 sum = 0;
|
|
int i;
|
|
|
|
for (i = 0; i < NR_IPI; i++)
|
|
sum += __get_irq_stat(cpu, ipi_irqs[i]);
|
|
|
|
return sum;
|
|
}
|
|
|
|
#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
|
|
void tick_broadcast(const struct cpumask *mask)
|
|
{
|
|
smp_cross_call(mask, IPI_TIMER);
|
|
}
|
|
#endif
|
|
|
|
static DEFINE_RAW_SPINLOCK(stop_lock);
|
|
|
|
/*
|
|
* ipi_cpu_stop - handle IPI from smp_send_stop()
|
|
*/
|
|
static void ipi_cpu_stop(unsigned int cpu)
|
|
{
|
|
if (system_state == SYSTEM_BOOTING ||
|
|
system_state == SYSTEM_RUNNING) {
|
|
raw_spin_lock(&stop_lock);
|
|
printk(KERN_CRIT "CPU%u: stopping\n", cpu);
|
|
dump_stack();
|
|
raw_spin_unlock(&stop_lock);
|
|
}
|
|
|
|
set_cpu_online(cpu, false);
|
|
|
|
local_fiq_disable();
|
|
local_irq_disable();
|
|
|
|
while (1)
|
|
cpu_relax();
|
|
}
|
|
|
|
/*
|
|
* Main handler for inter-processor interrupts
|
|
*/
|
|
asmlinkage void __exception_irq_entry do_IPI(int ipinr, struct pt_regs *regs)
|
|
{
|
|
handle_IPI(ipinr, regs);
|
|
}
|
|
|
|
void handle_IPI(int ipinr, struct pt_regs *regs)
|
|
{
|
|
unsigned int cpu = smp_processor_id();
|
|
struct pt_regs *old_regs = set_irq_regs(regs);
|
|
|
|
if (ipinr < NR_IPI)
|
|
__inc_irq_stat(cpu, ipi_irqs[ipinr]);
|
|
|
|
switch (ipinr) {
|
|
case IPI_WAKEUP:
|
|
break;
|
|
|
|
#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
|
|
case IPI_TIMER:
|
|
irq_enter();
|
|
tick_receive_broadcast();
|
|
irq_exit();
|
|
break;
|
|
#endif
|
|
|
|
case IPI_RESCHEDULE:
|
|
scheduler_ipi();
|
|
break;
|
|
|
|
case IPI_CALL_FUNC:
|
|
irq_enter();
|
|
generic_smp_call_function_interrupt();
|
|
irq_exit();
|
|
break;
|
|
|
|
case IPI_CALL_FUNC_SINGLE:
|
|
irq_enter();
|
|
generic_smp_call_function_single_interrupt();
|
|
irq_exit();
|
|
break;
|
|
|
|
case IPI_CPU_STOP:
|
|
irq_enter();
|
|
ipi_cpu_stop(cpu);
|
|
irq_exit();
|
|
break;
|
|
|
|
#ifdef CONFIG_IRQ_WORK
|
|
case IPI_IRQ_WORK:
|
|
irq_enter();
|
|
irq_work_run();
|
|
irq_exit();
|
|
break;
|
|
#endif
|
|
|
|
default:
|
|
printk(KERN_CRIT "CPU%u: Unknown IPI message 0x%x\n",
|
|
cpu, ipinr);
|
|
break;
|
|
}
|
|
set_irq_regs(old_regs);
|
|
}
|
|
|
|
void smp_send_reschedule(int cpu)
|
|
{
|
|
smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
|
|
}
|
|
|
|
void smp_send_stop(void)
|
|
{
|
|
unsigned long timeout;
|
|
struct cpumask mask;
|
|
|
|
cpumask_copy(&mask, cpu_online_mask);
|
|
cpumask_clear_cpu(smp_processor_id(), &mask);
|
|
if (!cpumask_empty(&mask))
|
|
smp_cross_call(&mask, IPI_CPU_STOP);
|
|
|
|
/* Wait up to one second for other CPUs to stop */
|
|
timeout = USEC_PER_SEC;
|
|
while (num_online_cpus() > 1 && timeout--)
|
|
udelay(1);
|
|
|
|
if (num_online_cpus() > 1)
|
|
pr_warning("SMP: failed to stop secondary CPUs\n");
|
|
}
|
|
|
|
/*
|
|
* not supported here
|
|
*/
|
|
int setup_profiling_timer(unsigned int multiplier)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
#ifdef CONFIG_CPU_FREQ
|
|
|
|
static DEFINE_PER_CPU(unsigned long, l_p_j_ref);
|
|
static DEFINE_PER_CPU(unsigned long, l_p_j_ref_freq);
|
|
static unsigned long global_l_p_j_ref;
|
|
static unsigned long global_l_p_j_ref_freq;
|
|
|
|
static int cpufreq_callback(struct notifier_block *nb,
|
|
unsigned long val, void *data)
|
|
{
|
|
struct cpufreq_freqs *freq = data;
|
|
int cpu = freq->cpu;
|
|
|
|
if (freq->flags & CPUFREQ_CONST_LOOPS)
|
|
return NOTIFY_OK;
|
|
|
|
if (!per_cpu(l_p_j_ref, cpu)) {
|
|
per_cpu(l_p_j_ref, cpu) =
|
|
per_cpu(cpu_data, cpu).loops_per_jiffy;
|
|
per_cpu(l_p_j_ref_freq, cpu) = freq->old;
|
|
if (!global_l_p_j_ref) {
|
|
global_l_p_j_ref = loops_per_jiffy;
|
|
global_l_p_j_ref_freq = freq->old;
|
|
}
|
|
}
|
|
|
|
if ((val == CPUFREQ_PRECHANGE && freq->old < freq->new) ||
|
|
(val == CPUFREQ_POSTCHANGE && freq->old > freq->new) ||
|
|
(val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) {
|
|
loops_per_jiffy = cpufreq_scale(global_l_p_j_ref,
|
|
global_l_p_j_ref_freq,
|
|
freq->new);
|
|
per_cpu(cpu_data, cpu).loops_per_jiffy =
|
|
cpufreq_scale(per_cpu(l_p_j_ref, cpu),
|
|
per_cpu(l_p_j_ref_freq, cpu),
|
|
freq->new);
|
|
}
|
|
return NOTIFY_OK;
|
|
}
|
|
|
|
static struct notifier_block cpufreq_notifier = {
|
|
.notifier_call = cpufreq_callback,
|
|
};
|
|
|
|
static int __init register_cpufreq_notifier(void)
|
|
{
|
|
return cpufreq_register_notifier(&cpufreq_notifier,
|
|
CPUFREQ_TRANSITION_NOTIFIER);
|
|
}
|
|
core_initcall(register_cpufreq_notifier);
|
|
|
|
#endif
|