2010-05-29 03:09:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Tilera Corporation. 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
|
|
|
|
* as published by the Free Software Foundation, version 2.
|
|
|
|
*
|
|
|
|
* 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, GOOD TITLE or
|
|
|
|
* NON INFRINGEMENT. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* TILE SMP support routines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/smp.h>
|
2010-06-25 20:41:11 +00:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/io.h>
|
2010-05-29 03:09:12 +00:00
|
|
|
#include <linux/irq.h>
|
2015-03-23 15:21:23 +00:00
|
|
|
#include <linux/irq_work.h>
|
2010-06-25 20:41:11 +00:00
|
|
|
#include <linux/module.h>
|
2010-05-29 03:09:12 +00:00
|
|
|
#include <asm/cacheflush.h>
|
2013-08-09 19:08:57 +00:00
|
|
|
#include <asm/homecache.h>
|
2010-05-29 03:09:12 +00:00
|
|
|
|
2013-08-15 20:29:02 +00:00
|
|
|
/*
|
|
|
|
* We write to width and height with a single store in head_NN.S,
|
|
|
|
* so make the variable aligned to "long".
|
|
|
|
*/
|
2016-11-07 19:19:10 +00:00
|
|
|
HV_Topology smp_topology __ro_after_init __aligned(sizeof(long));
|
2010-06-25 20:41:11 +00:00
|
|
|
EXPORT_SYMBOL(smp_topology);
|
|
|
|
|
|
|
|
#if CHIP_HAS_IPI()
|
|
|
|
static unsigned long __iomem *ipi_mappings[NR_CPUS];
|
|
|
|
#endif
|
2010-05-29 03:09:12 +00:00
|
|
|
|
2015-03-23 15:21:23 +00:00
|
|
|
/* Does messaging work correctly to the local cpu? */
|
|
|
|
bool self_interrupt_ok;
|
2010-05-29 03:09:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Top-level send_IPI*() functions to send messages to other cpus.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Set by smp_send_stop() to avoid recursive panics. */
|
|
|
|
static int stopping_cpus;
|
|
|
|
|
2011-02-28 18:32:14 +00:00
|
|
|
static void __send_IPI_many(HV_Recipient *recip, int nrecip, int tag)
|
|
|
|
{
|
|
|
|
int sent = 0;
|
|
|
|
while (sent < nrecip) {
|
|
|
|
int rc = hv_send_message(recip, nrecip,
|
|
|
|
(HV_VirtAddr)&tag, sizeof(tag));
|
|
|
|
if (rc < 0) {
|
|
|
|
if (!stopping_cpus) /* avoid recursive panic */
|
|
|
|
panic("hv_send_message returned %d", rc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
WARN_ONCE(rc == 0, "hv_send_message() returned zero\n");
|
|
|
|
sent += rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 03:09:12 +00:00
|
|
|
void send_IPI_single(int cpu, int tag)
|
|
|
|
{
|
|
|
|
HV_Recipient recip = {
|
|
|
|
.y = cpu / smp_width,
|
|
|
|
.x = cpu % smp_width,
|
|
|
|
.state = HV_TO_BE_SENT
|
|
|
|
};
|
2011-02-28 18:32:14 +00:00
|
|
|
__send_IPI_many(&recip, 1, tag);
|
2010-05-29 03:09:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void send_IPI_many(const struct cpumask *mask, int tag)
|
|
|
|
{
|
|
|
|
HV_Recipient recip[NR_CPUS];
|
2011-02-28 18:32:14 +00:00
|
|
|
int cpu;
|
2010-05-29 03:09:12 +00:00
|
|
|
int nrecip = 0;
|
|
|
|
int my_cpu = smp_processor_id();
|
|
|
|
for_each_cpu(cpu, mask) {
|
|
|
|
HV_Recipient *r;
|
|
|
|
BUG_ON(cpu == my_cpu);
|
|
|
|
r = &recip[nrecip++];
|
|
|
|
r->y = cpu / smp_width;
|
|
|
|
r->x = cpu % smp_width;
|
|
|
|
r->state = HV_TO_BE_SENT;
|
|
|
|
}
|
2011-02-28 18:32:14 +00:00
|
|
|
__send_IPI_many(recip, nrecip, tag);
|
2010-05-29 03:09:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void send_IPI_allbutself(int tag)
|
|
|
|
{
|
|
|
|
struct cpumask mask;
|
|
|
|
cpumask_copy(&mask, cpu_online_mask);
|
|
|
|
cpumask_clear_cpu(smp_processor_id(), &mask);
|
|
|
|
send_IPI_many(&mask, tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions related to starting/stopping cpus.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Handler to start the current cpu. */
|
|
|
|
static void smp_start_cpu_interrupt(void)
|
|
|
|
{
|
|
|
|
get_irq_regs()->pc = start_cpu_function_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handler to stop the current cpu. */
|
|
|
|
static void smp_stop_cpu_interrupt(void)
|
|
|
|
{
|
2010-11-01 19:24:29 +00:00
|
|
|
arch_local_irq_disable_all();
|
2013-08-07 15:36:54 +00:00
|
|
|
set_cpu_online(smp_processor_id(), 0);
|
2010-05-29 03:09:12 +00:00
|
|
|
for (;;)
|
2012-03-29 19:57:18 +00:00
|
|
|
asm("nap; nop");
|
2010-05-29 03:09:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function calls the 'stop' function on all other CPUs in the system. */
|
|
|
|
void smp_send_stop(void)
|
|
|
|
{
|
|
|
|
stopping_cpus = 1;
|
|
|
|
send_IPI_allbutself(MSG_TAG_STOP_CPU);
|
|
|
|
}
|
|
|
|
|
2012-03-29 19:59:11 +00:00
|
|
|
/* On panic, just wait; we may get an smp_send_stop() later on. */
|
|
|
|
void panic_smp_self_stop(void)
|
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
asm("nap; nop");
|
|
|
|
}
|
2010-05-29 03:09:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Dispatch code called from hv_message_intr() for HV_MSG_TILE hv messages.
|
|
|
|
*/
|
|
|
|
void evaluate_message(int tag)
|
|
|
|
{
|
|
|
|
switch (tag) {
|
|
|
|
case MSG_TAG_START_CPU: /* Start up a cpu */
|
|
|
|
smp_start_cpu_interrupt();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_TAG_STOP_CPU: /* Sent to shut down slave CPU's */
|
|
|
|
smp_stop_cpu_interrupt();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_TAG_CALL_FUNCTION_MANY: /* Call function on cpumask */
|
|
|
|
generic_smp_call_function_interrupt();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_TAG_CALL_FUNCTION_SINGLE: /* Call function on one other CPU */
|
|
|
|
generic_smp_call_function_single_interrupt();
|
|
|
|
break;
|
|
|
|
|
2015-03-23 15:21:23 +00:00
|
|
|
case MSG_TAG_IRQ_WORK: /* Invoke IRQ work */
|
|
|
|
irq_work_run();
|
|
|
|
break;
|
|
|
|
|
2010-05-29 03:09:12 +00:00
|
|
|
default:
|
|
|
|
panic("Unknown IPI message tag %d", tag);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* flush_icache_range() code uses smp_call_function().
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ipi_flush {
|
|
|
|
unsigned long start;
|
|
|
|
unsigned long end;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ipi_flush_icache_range(void *info)
|
|
|
|
{
|
|
|
|
struct ipi_flush *flush = (struct ipi_flush *) info;
|
|
|
|
__flush_icache_range(flush->start, flush->end);
|
|
|
|
}
|
|
|
|
|
|
|
|
void flush_icache_range(unsigned long start, unsigned long end)
|
|
|
|
{
|
|
|
|
struct ipi_flush flush = { start, end };
|
2013-08-09 19:08:57 +00:00
|
|
|
|
|
|
|
/* If invoked with irqs disabled, we can not issue IPIs. */
|
|
|
|
if (irqs_disabled())
|
|
|
|
flush_remote(0, HV_FLUSH_EVICT_L1I, NULL, 0, 0, 0,
|
|
|
|
NULL, NULL, 0);
|
|
|
|
else {
|
|
|
|
preempt_disable();
|
|
|
|
on_each_cpu(ipi_flush_icache_range, &flush, 1);
|
|
|
|
preempt_enable();
|
|
|
|
}
|
2010-05-29 03:09:12 +00:00
|
|
|
}
|
2014-08-29 22:19:09 +00:00
|
|
|
EXPORT_SYMBOL(flush_icache_range);
|
2010-05-29 03:09:12 +00:00
|
|
|
|
|
|
|
|
2015-03-23 15:21:23 +00:00
|
|
|
#ifdef CONFIG_IRQ_WORK
|
|
|
|
void arch_irq_work_raise(void)
|
|
|
|
{
|
|
|
|
if (arch_irq_work_has_interrupt())
|
|
|
|
send_IPI_single(smp_processor_id(), MSG_TAG_IRQ_WORK);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-06-25 20:41:11 +00:00
|
|
|
/* Called when smp_send_reschedule() triggers IRQ_RESCHEDULE. */
|
|
|
|
static irqreturn_t handle_reschedule_ipi(int irq, void *token)
|
2010-05-29 03:09:12 +00:00
|
|
|
{
|
tile: Replace __get_cpu_var uses
__get_cpu_var() is used for multiple purposes in the kernel source. One of
them is address calculation via the form &__get_cpu_var(x). This calculates
the address for the instance of the percpu variable of the current processor
based on an offset.
Other use cases are for storing and retrieving data from the current
processors percpu area. __get_cpu_var() can be used as an lvalue when
writing data or on the right side of an assignment.
__get_cpu_var() is defined as :
#define __get_cpu_var(var) (*this_cpu_ptr(&(var)))
__get_cpu_var() always only does an address determination. However, store
and retrieve operations could use a segment prefix (or global register on
other platforms) to avoid the address calculation.
this_cpu_write() and this_cpu_read() can directly take an offset into a
percpu area and use optimized assembly code to read and write per cpu
variables.
This patch converts __get_cpu_var into either an explicit address
calculation using this_cpu_ptr() or into a use of this_cpu operations that
use the offset. Thereby address calculations are avoided and less registers
are used when code is generated.
At the end of the patch set all uses of __get_cpu_var have been removed so
the macro is removed too.
The patch set includes passes over all arches as well. Once these operations
are used throughout then specialized macros can be defined in non -x86
arches as well in order to optimize per cpu access by f.e. using a global
register that may be set to the per cpu base.
Transformations done to __get_cpu_var()
1. Determine the address of the percpu instance of the current processor.
DEFINE_PER_CPU(int, y);
int *x = &__get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(&y);
2. Same as #1 but this time an array structure is involved.
DEFINE_PER_CPU(int, y[20]);
int *x = __get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(y);
3. Retrieve the content of the current processors instance of a per cpu
variable.
DEFINE_PER_CPU(int, y);
int x = __get_cpu_var(y)
Converts to
int x = __this_cpu_read(y);
4. Retrieve the content of a percpu struct
DEFINE_PER_CPU(struct mystruct, y);
struct mystruct x = __get_cpu_var(y);
Converts to
memcpy(&x, this_cpu_ptr(&y), sizeof(x));
5. Assignment to a per cpu variable
DEFINE_PER_CPU(int, y)
__get_cpu_var(y) = x;
Converts to
__this_cpu_write(y, x);
6. Increment/Decrement etc of a per cpu variable
DEFINE_PER_CPU(int, y);
__get_cpu_var(y)++
Converts to
__this_cpu_inc(y)
Acked-by: Chris Metcalf <cmetcalf@tilera.com>
Signed-off-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
2014-08-17 17:30:50 +00:00
|
|
|
__this_cpu_inc(irq_stat.irq_resched_count);
|
2011-04-05 15:23:39 +00:00
|
|
|
scheduler_ipi();
|
2010-05-29 03:09:12 +00:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2010-06-25 20:41:11 +00:00
|
|
|
static struct irqaction resched_action = {
|
|
|
|
.handler = handle_reschedule_ipi,
|
|
|
|
.name = "resched",
|
|
|
|
.dev_id = handle_reschedule_ipi /* unique token */,
|
|
|
|
};
|
|
|
|
|
|
|
|
void __init ipi_init(void)
|
|
|
|
{
|
2015-03-23 15:21:23 +00:00
|
|
|
int cpu = smp_processor_id();
|
|
|
|
HV_Recipient recip = { .y = cpu_y(cpu), .x = cpu_x(cpu),
|
|
|
|
.state = HV_TO_BE_SENT };
|
|
|
|
int tag = MSG_TAG_CALL_FUNCTION_SINGLE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test if we can message ourselves for arch_irq_work_raise.
|
|
|
|
* This functionality is only available in the Tilera hypervisor
|
|
|
|
* in versions 4.3.4 and following.
|
|
|
|
*/
|
|
|
|
if (hv_send_message(&recip, 1, (HV_VirtAddr)&tag, sizeof(tag)) == 1)
|
|
|
|
self_interrupt_ok = true;
|
|
|
|
else
|
|
|
|
pr_warn("Older hypervisor: disabling fast irq_work_raise\n");
|
|
|
|
|
2010-06-25 20:41:11 +00:00
|
|
|
#if CHIP_HAS_IPI()
|
|
|
|
/* Map IPI trigger MMIO addresses. */
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
HV_Coord tile;
|
|
|
|
HV_PTE pte;
|
|
|
|
unsigned long offset;
|
|
|
|
|
|
|
|
tile.x = cpu_x(cpu);
|
|
|
|
tile.y = cpu_y(cpu);
|
2010-10-14 20:23:03 +00:00
|
|
|
if (hv_get_ipi_pte(tile, KERNEL_PL, &pte) != 0)
|
2010-06-25 20:41:11 +00:00
|
|
|
panic("Failed to initialize IPI for cpu %d\n", cpu);
|
|
|
|
|
2012-03-29 17:58:43 +00:00
|
|
|
offset = PFN_PHYS(pte_pfn(pte));
|
2010-06-25 20:41:11 +00:00
|
|
|
ipi_mappings[cpu] = ioremap_prot(offset, PAGE_SIZE, pte);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Bind handle_reschedule_ipi() to IRQ_RESCHEDULE. */
|
|
|
|
tile_irq_activate(IRQ_RESCHEDULE, TILE_IRQ_PERCPU);
|
|
|
|
BUG_ON(setup_irq(IRQ_RESCHEDULE, &resched_action));
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CHIP_HAS_IPI()
|
|
|
|
|
|
|
|
void smp_send_reschedule(int cpu)
|
|
|
|
{
|
|
|
|
WARN_ON(cpu_is_offline(cpu));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We just want to do an MMIO store. The traditional writeq()
|
|
|
|
* functions aren't really correct here, since they're always
|
|
|
|
* directed at the PCI shim. For now, just do a raw store,
|
|
|
|
* casting away the __iomem attribute.
|
|
|
|
*/
|
|
|
|
((unsigned long __force *)ipi_mappings[cpu])[IRQ_RESCHEDULE] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2010-05-29 03:09:12 +00:00
|
|
|
void smp_send_reschedule(int cpu)
|
|
|
|
{
|
|
|
|
HV_Coord coord;
|
|
|
|
|
|
|
|
WARN_ON(cpu_is_offline(cpu));
|
2010-06-25 20:41:11 +00:00
|
|
|
|
|
|
|
coord.y = cpu_y(cpu);
|
|
|
|
coord.x = cpu_x(cpu);
|
2010-05-29 03:09:12 +00:00
|
|
|
hv_trigger_ipi(coord, IRQ_RESCHEDULE);
|
|
|
|
}
|
2010-06-25 20:41:11 +00:00
|
|
|
|
|
|
|
#endif /* CHIP_HAS_IPI() */
|