Re: [PATCH v4 21/36] Hexagon: Add SMP support

From: realmz paranoid
Date: Tue Sep 20 2011 - 22:10:42 EST


On Thu, Sep 15, 2011 at 2:19 AM, Richard Kuo <rkuo@xxxxxxxxxxxxxx> wrote:
> Signed-off-by: Richard Kuo <rkuo@xxxxxxxxxxxxxx>
> Signed-off-by: Linas Vepstas <linas@xxxxxxxxxxxxxx>
> Acked-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> Âarch/hexagon/include/asm/smp.h | Â 44 +++++++
> Âarch/hexagon/kernel/smp.c   Â| Â280 ++++++++++++++++++++++++++++++++++++++++
> Âarch/hexagon/kernel/topology.c | Â 52 ++++++++
> Â3 files changed, 376 insertions(+), 0 deletions(-)
> Âcreate mode 100644 arch/hexagon/include/asm/smp.h
> Âcreate mode 100644 arch/hexagon/kernel/smp.c
> Âcreate mode 100644 arch/hexagon/kernel/topology.c
>
> diff --git a/arch/hexagon/include/asm/smp.h b/arch/hexagon/include/asm/smp.h
> new file mode 100644
> index 0000000..87c869a
> --- /dev/null
> +++ b/arch/hexagon/include/asm/smp.h
> @@ -0,0 +1,44 @@
> +/*
> + * SMP definitions for the Hexagon architecture
> + *
> + * Copyright (c) 2010-2011, Code Aurora Forum. 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 and
> + * only version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ÂSee the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */
> +
> +#ifndef __ASM_SMP_H
> +#define __ASM_SMP_H
> +
> +#include <linux/cpumask.h>
> +
> +#define raw_smp_processor_id() (current_thread_info()->cpu)
> +
> +enum ipi_message_type {
> + Â Â Â IPI_NOP = 0,
> + Â Â Â IPI_RESCHEDULE = 1,
> + Â Â Â IPI_CALL_FUNC,
> + Â Â Â IPI_CALL_FUNC_SINGLE,
> + Â Â Â IPI_CPU_STOP,
> + Â Â Â IPI_TIMER,
> +};
> +
> +extern void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg);
> +extern void smp_start_cpus(void);
> +extern void arch_send_call_function_single_ipi(int cpu);
> +extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
> +
> +extern void smp_vm_unmask_irq(void *info);
> +
> +#endif
> diff --git a/arch/hexagon/kernel/smp.c b/arch/hexagon/kernel/smp.c
> new file mode 100644
> index 0000000..96bf6c2
> --- /dev/null
> +++ b/arch/hexagon/kernel/smp.c
> @@ -0,0 +1,280 @@
> +/*
> + * SMP support for Hexagon
> + *
> + * Copyright (c) 2010-2011, Code Aurora Forum. 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 and
> + * only version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ÂSee the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */
> +
> +#include <linux/err.h>
> +#include <linux/errno.h>
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/interrupt.h>
> +#include <linux/module.h>
> +#include <linux/percpu.h>
> +#include <linux/sched.h>
> +#include <linux/smp.h>
> +#include <linux/spinlock.h>
> +
> +#include <asm/system.h> Â/* Âxchg Â*/
> +#include <asm/time.h> Â Â/* Âtimer_interrupt Â*/
> +#include <asm/hexagon_vm.h>
> +
> +#define BASE_IPI_IRQ 26
> +
> +/*
> + * cpu_possible_map needs to be filled out prior to setup_per_cpu_areas
> + * (which is prior to any of our smp_prepare_cpu crap), in order to set
> + * up the... Âper_cpu areas.
> + */
> +
> +struct ipi_data {
> + Â Â Â unsigned long bits;
> +};
> +
> +static DEFINE_PER_CPU(struct ipi_data, ipi_data);
> +
> +static inline void __handle_ipi(unsigned long *ops, struct ipi_data *ipi,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â int cpu)
> +{
> + Â Â Â unsigned long msg = 0;
> + Â Â Â do {
> + Â Â Â Â Â Â Â msg = find_next_bit(ops, BITS_PER_LONG, msg+1);
> +
> + Â Â Â Â Â Â Â switch (msg) {
> +
> + Â Â Â Â Â Â Â case IPI_TIMER:
> + Â Â Â Â Â Â Â Â Â Â Â ipi_timer();
> + Â Â Â Â Â Â Â Â Â Â Â break;
> +
> + Â Â Â Â Â Â Â case IPI_CALL_FUNC:
> + Â Â Â Â Â Â Â Â Â Â Â generic_smp_call_function_interrupt();
> + Â Â Â Â Â Â Â Â Â Â Â break;
> +
> + Â Â Â Â Â Â Â case IPI_CALL_FUNC_SINGLE:
> + Â Â Â Â Â Â Â Â Â Â Â generic_smp_call_function_single_interrupt();
> + Â Â Â Â Â Â Â Â Â Â Â break;
> +
> + Â Â Â Â Â Â Â case IPI_CPU_STOP:
> + Â Â Â Â Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â Â Â Â Â* call vmstop()
> + Â Â Â Â Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â Â Â Â Â __vmstop();
> + Â Â Â Â Â Â Â Â Â Â Â break;
> +
> + Â Â Â Â Â Â Â case IPI_RESCHEDULE:
> + Â Â Â Â Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â Â Â Â Â* need to revisit our exit path; see comments for
> + Â Â Â Â Â Â Â Â Â Â Â Â* scheduler_ipi()
> + Â Â Â Â Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â Â Â Â Â scheduler_ipi();
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â }
> + Â Â Â } while (msg < BITS_PER_LONG);
> +}
> +
> +/* ÂUsed for IPI call from other CPU's to unmask int Â*/
> +void smp_vm_unmask_irq(void *info)
> +{
> + Â Â Â __vmintop_locen((long) info);
> +}
> +
> +
> +/*
> + * This is based on Alpha's IPI stuff.
> + * Supposed to take (int, void*) as args now.
> + * Specifically, first arg is irq, second is the irq_desc.
> + */
> +
> +irqreturn_t handle_ipi(int irq, void *desc)
> +{
> + Â Â Â int cpu = smp_processor_id();
> + Â Â Â struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
> + Â Â Â unsigned long ops;
> +
> + Â Â Â while ((ops = xchg(&ipi->bits, 0)) != 0)
> + Â Â Â Â Â Â Â __handle_ipi(&ops, ipi, cpu);
> + Â Â Â return IRQ_HANDLED;
> +}
> +
> +void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg)
> +{
> + Â Â Â unsigned long flags;
> + Â Â Â unsigned long cpu;
> + Â Â Â unsigned long retval;
> +
> + Â Â Â local_irq_save(flags);
> +
> + Â Â Â for_each_cpu(cpu, cpumask) {
> + Â Â Â Â Â Â Â struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
> +
> + Â Â Â Â Â Â Â set_bit(msg, &ipi->bits);
> + Â Â Â Â Â Â Â /* ÂPossible barrier here Â*/
> + Â Â Â Â Â Â Â retval = __vmintop_post(BASE_IPI_IRQ+cpu);
> +
> + Â Â Â Â Â Â Â if (retval != 0) {
> + Â Â Â Â Â Â Â Â Â Â Â printk(KERN_ERR "interrupt %ld not configured?\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â BASE_IPI_IRQ+cpu);
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> +
> + Â Â Â local_irq_restore(flags);
> +}
> +
> +static struct irqaction ipi_intdesc = {
> + Â Â Â .handler = handle_ipi,
> + Â Â Â .flags = IRQF_DISABLED | IRQF_TRIGGER_RISING,
> + Â Â Â .name = "ipi_handler"
> +};
> +
> +void __init smp_prepare_boot_cpu(void)
> +{
> +}
> +
> +/*
> + * interrupts should already be disabled from the VM
> + * SP should already be correct; need to set THREADINFO_REG
> + * to point to current thread info
> + */
> +
> +void __cpuinit start_secondary(void)
> +{
> + Â Â Â unsigned int cpu;
> + Â Â Â unsigned long thread_ptr;
> +
> + Â Â Â /* ÂCalculate thread_info pointer from stack pointer Â*/
> + Â Â Â __asm__ __volatile__(
> + Â Â Â Â Â Â Â "%0 = SP;\n"
> + Â Â Â Â Â Â Â : "=r" (thread_ptr)
> + Â Â Â );
> +
> + Â Â Â thread_ptr = thread_ptr & ~(THREAD_SIZE-1);
> +
> + Â Â Â __asm__ __volatile__(
> + Â Â Â Â Â Â Â QUOTED_THREADINFO_REG " = %0;\n"
> + Â Â Â Â Â Â Â :
> + Â Â Â Â Â Â Â : "r" (thread_ptr)
> + Â Â Â );
> +
> + Â Â Â /* ÂSet the memory struct Â*/
> + Â Â Â atomic_inc(&init_mm.mm_count);
> + Â Â Â current->active_mm = &init_mm;
> +
> + Â Â Â cpu = smp_processor_id();
> +
> + Â Â Â setup_irq(BASE_IPI_IRQ + cpu, &ipi_intdesc);
> +
> + Â Â Â /* ÂRegister the clock_event dummy Â*/
> + Â Â Â setup_percpu_clockdev();
> +
> + Â Â Â printk(KERN_INFO "%s cpu %d\n", __func__, current_thread_info()->cpu);
> +
> + Â Â Â set_cpu_online(cpu, true);
> + Â Â Â while (!cpumask_test_cpu(cpu, cpu_active_mask))
> + Â Â Â Â Â Â Â cpu_relax();
> + Â Â Â local_irq_enable();
> +
> + Â Â Â cpu_idle();
> +}
> +
> +
> +/*
> + * called once for each present cpu
> + * apparently starts up the CPU and then
> + * maintains control until "cpu_online(cpu)" is set.
> + */
> +
__cpu_up only called once?

> +int __cpuinit __cpu_up(unsigned int cpu)
> +{
> + Â Â Â struct task_struct *idle;
> + Â Â Â struct thread_info *thread;
> + Â Â Â void *stack_start;
> +
> + Â Â Â /* ÂCreate new init task for the CPU Â*/
> + Â Â Â idle = fork_idle(cpu);
> + Â Â Â if (IS_ERR(idle))
> + Â Â Â Â Â Â Â panic(KERN_ERR "fork_idle failed\n");
> +
> + Â Â Â thread = (struct thread_info *)idle->stack;
> + Â Â Â thread->cpu = cpu;
> +
> + Â Â Â /* ÂBoot to the head. Â*/
> + Â Â Â stack_start = Â((void *) thread) + THREAD_SIZE;
> + Â Â Â __vmstart(start_secondary, stack_start);
> +
> + Â Â Â while (!cpu_isset(cpu, cpu_online_map))
> + Â Â Â Â Â Â Â barrier();
> +
> + Â Â Â return 0;
> +}
> +
> +void __init smp_cpus_done(unsigned int max_cpus)
> +{
> +}
> +
> +void __init smp_prepare_cpus(unsigned int max_cpus)
> +{
> + Â Â Â int i;
> +
> + Â Â Â /*
> + Â Â Â Â* should eventually have some sort of machine
> + Â Â Â Â* descriptor that has this stuff
> + Â Â Â Â*/
> +
> + Â Â Â /* ÂRight now, let's just fake it. */
> + Â Â Â for (i = 0; i < max_cpus; i++)
> + Â Â Â Â Â Â Â cpu_set(i, cpu_present_map);
> +
> + Â Â Â /* ÂAlso need to register the interrupts for IPI Â*/
> + Â Â Â if (max_cpus > 1)
> + Â Â Â Â Â Â Â setup_irq(BASE_IPI_IRQ, &ipi_intdesc);
> +}
> +
> +void smp_send_reschedule(int cpu)
> +{
> + Â Â Â send_ipi(cpumask_of(cpu), IPI_RESCHEDULE);
> +}
> +
> +void smp_send_stop(void)
> +{
> + Â Â Â struct cpumask targets;
> + Â Â Â cpumask_copy(&targets, cpu_online_mask);
> + Â Â Â cpumask_clear_cpu(smp_processor_id(), &targets);
> + Â Â Â send_ipi(&targets, IPI_CPU_STOP);
> +}
> +
> +void arch_send_call_function_single_ipi(int cpu)
> +{
> + Â Â Â send_ipi(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
> +}
> +
> +void arch_send_call_function_ipi_mask(const struct cpumask *mask)
> +{
> + Â Â Â send_ipi(mask, IPI_CALL_FUNC);
> +}
> +
> +int setup_profiling_timer(unsigned int multiplier)
> +{
> + Â Â Â return -EINVAL;
> +}
> +
> +void smp_start_cpus(void)
> +{
> + Â Â Â int i;
> +
> + Â Â Â for (i = 0; i < NR_CPUS; i++)
> + Â Â Â Â Â Â Â cpu_set(i, cpu_possible_map);
> +}
> diff --git a/arch/hexagon/kernel/topology.c b/arch/hexagon/kernel/topology.c
> new file mode 100644
> index 0000000..ba44751
> --- /dev/null
> +++ b/arch/hexagon/kernel/topology.c
> @@ -0,0 +1,52 @@
> +/*
> + * CPU topology for Hexagon
> + *
> + * Copyright (c) 2010-2011, Code Aurora Forum. 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 and
> + * only version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ÂSee the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */
> +
> +#include <linux/cpu.h>
> +#include <linux/cpumask.h>
> +#include <linux/init.h>
> +#include <linux/node.h>
> +#include <linux/nodemask.h>
> +#include <linux/percpu.h>
> +
> +/* ÂSwiped from MIPS. Â*/
> +
> +static DEFINE_PER_CPU(struct cpu, cpu_devices);
> +
> +static int __init topology_init(void)
> +{
> + Â Â Â int i, ret;
> +
> + Â Â Â for_each_present_cpu(i) {
> +
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* register_cpu takes a per_cpu pointer and
> + Â Â Â Â Â Â Â Â* just points it at another per_cpu struct...
> + Â Â Â Â Â Â Â Â*/
> +
> + Â Â Â Â Â Â Â ret = register_cpu(&per_cpu(cpu_devices, i), i);
> + Â Â Â Â Â Â Â if (ret)
> + Â Â Â Â Â Â Â Â Â Â Â printk(KERN_WARNING "topology_init: register_cpu %d "
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"failed (%d)\n", i, ret);
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +subsys_initcall(topology_init);
> --
> 1.7.1
>
>
> --
>
> Sent by an employee of the Qualcomm Innovation Center, Inc.
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/