2008-07-24 04:28:58 +08:00
|
|
|
/*
|
|
|
|
* Split spinlock implementation out into its own file, so it can be
|
|
|
|
* compiled in a FTRACE-compatible way.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel_stat.h>
|
|
|
|
#include <linux/spinlock.h>
|
2008-08-21 08:02:19 +08:00
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#include <linux/log2.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/gfp.h>
|
2013-06-05 22:44:47 +08:00
|
|
|
#include <linux/slab.h>
|
2008-07-24 04:28:58 +08:00
|
|
|
|
|
|
|
#include <asm/paravirt.h>
|
|
|
|
|
|
|
|
#include <xen/interface/xen.h>
|
|
|
|
#include <xen/events.h>
|
|
|
|
|
|
|
|
#include "xen-ops.h"
|
2008-08-21 08:02:19 +08:00
|
|
|
#include "debugfs.h"
|
|
|
|
|
2015-04-25 02:56:40 +08:00
|
|
|
static DEFINE_PER_CPU(int, lock_kicker_irq) = -1;
|
|
|
|
static DEFINE_PER_CPU(char *, irq_name);
|
|
|
|
static bool xen_pvspin = true;
|
|
|
|
|
|
|
|
#include <asm/qspinlock.h>
|
|
|
|
|
|
|
|
static void xen_qlock_kick(int cpu)
|
|
|
|
{
|
2016-04-22 20:05:31 +08:00
|
|
|
int irq = per_cpu(lock_kicker_irq, cpu);
|
|
|
|
|
|
|
|
/* Don't kick if the target's kicker interrupt is not initialized. */
|
|
|
|
if (irq == -1)
|
|
|
|
return;
|
|
|
|
|
2015-04-25 02:56:40 +08:00
|
|
|
xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Halt the current CPU & release it back to the host
|
|
|
|
*/
|
|
|
|
static void xen_qlock_wait(u8 *byte, u8 val)
|
|
|
|
{
|
|
|
|
int irq = __this_cpu_read(lock_kicker_irq);
|
|
|
|
|
|
|
|
/* If kicker interrupts not initialized yet, just spin */
|
|
|
|
if (irq == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* clear pending */
|
|
|
|
xen_clear_irq_pending(irq);
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We check the byte value after clearing pending IRQ to make sure
|
|
|
|
* that we won't miss a wakeup event because of the clearing.
|
|
|
|
*
|
|
|
|
* The sync_clear_bit() call in xen_clear_irq_pending() is atomic.
|
|
|
|
* So it is effectively a memory barrier for x86.
|
|
|
|
*/
|
|
|
|
if (READ_ONCE(*byte) != val)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If an interrupt happens here, it will leave the wakeup irq
|
|
|
|
* pending, which will cause xen_poll_irq() to return
|
|
|
|
* immediately.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Block until irq becomes pending (or perhaps a spurious wakeup) */
|
|
|
|
xen_poll_irq(irq);
|
|
|
|
}
|
|
|
|
|
2008-07-24 04:28:58 +08:00
|
|
|
static irqreturn_t dummy_handler(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
BUG();
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
x86: delete __cpuinit usage from all x86 files
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
are flagged as __cpuinit -- so if we remove the __cpuinit from
arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
content into no-ops as early as possible, since that will get rid
of these warnings. In any case, they are temporary and harmless.
This removes all the arch/x86 uses of the __cpuinit macros from
all C files. x86 only had the one __CPUINIT used in assembly files,
and it wasn't paired off with a .previous or a __FINIT, so we can
delete it directly w/o any corresponding additional change there.
[1] https://lkml.org/lkml/2013/5/20/589
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Acked-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: H. Peter Anvin <hpa@linux.intel.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
2013-06-19 06:23:59 +08:00
|
|
|
void xen_init_lock_cpu(int cpu)
|
2008-07-24 04:28:58 +08:00
|
|
|
{
|
|
|
|
int irq;
|
2013-06-05 22:44:47 +08:00
|
|
|
char *name;
|
2008-07-24 04:28:58 +08:00
|
|
|
|
2013-08-27 02:28:06 +08:00
|
|
|
if (!xen_pvspin)
|
|
|
|
return;
|
|
|
|
|
2013-05-06 20:33:15 +08:00
|
|
|
WARN(per_cpu(lock_kicker_irq, cpu) >= 0, "spinlock on CPU%d exists on IRQ%d!\n",
|
2013-04-17 02:33:20 +08:00
|
|
|
cpu, per_cpu(lock_kicker_irq, cpu));
|
|
|
|
|
2008-07-24 04:28:58 +08:00
|
|
|
name = kasprintf(GFP_KERNEL, "spinlock%d", cpu);
|
|
|
|
irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR,
|
|
|
|
cpu,
|
|
|
|
dummy_handler,
|
2013-09-07 14:46:49 +08:00
|
|
|
IRQF_PERCPU|IRQF_NOBALANCING,
|
2008-07-24 04:28:58 +08:00
|
|
|
name,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (irq >= 0) {
|
|
|
|
disable_irq(irq); /* make sure it's never delivered */
|
|
|
|
per_cpu(lock_kicker_irq, cpu) = irq;
|
2013-06-05 22:44:47 +08:00
|
|
|
per_cpu(irq_name, cpu) = name;
|
2008-07-24 04:28:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
printk("cpu %d spinlock event irq %d\n", cpu, irq);
|
|
|
|
}
|
|
|
|
|
2008-08-22 18:52:15 +08:00
|
|
|
void xen_uninit_lock_cpu(int cpu)
|
|
|
|
{
|
2013-08-27 02:28:06 +08:00
|
|
|
if (!xen_pvspin)
|
|
|
|
return;
|
|
|
|
|
2008-08-22 18:52:15 +08:00
|
|
|
unbind_from_irqhandler(per_cpu(lock_kicker_irq, cpu), NULL);
|
2013-04-17 02:33:20 +08:00
|
|
|
per_cpu(lock_kicker_irq, cpu) = -1;
|
2013-06-05 22:44:47 +08:00
|
|
|
kfree(per_cpu(irq_name, cpu));
|
|
|
|
per_cpu(irq_name, cpu) = NULL;
|
2008-08-22 18:52:15 +08:00
|
|
|
}
|
|
|
|
|
2016-11-15 23:47:06 +08:00
|
|
|
PV_CALLEE_SAVE_REGS_THUNK(xen_vcpu_stolen);
|
|
|
|
|
2013-09-13 10:29:44 +08:00
|
|
|
/*
|
|
|
|
* Our init of PV spinlocks is split in two init functions due to us
|
|
|
|
* using paravirt patching and jump labels patching and having to do
|
|
|
|
* all of this before SMP code is invoked.
|
|
|
|
*
|
|
|
|
* The paravirt patching needs to be done _before_ the alternative asm code
|
|
|
|
* is started, otherwise we would not patch the core kernel code.
|
|
|
|
*/
|
2008-07-24 04:28:58 +08:00
|
|
|
void __init xen_init_spinlocks(void)
|
|
|
|
{
|
2013-04-17 02:34:45 +08:00
|
|
|
|
2013-08-09 22:21:54 +08:00
|
|
|
if (!xen_pvspin) {
|
|
|
|
printk(KERN_DEBUG "xen: PV spinlocks disabled\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-04-05 02:48:04 +08:00
|
|
|
printk(KERN_DEBUG "xen: PV spinlocks enabled\n");
|
2016-05-19 02:43:02 +08:00
|
|
|
|
2015-04-25 02:56:40 +08:00
|
|
|
__pv_init_lock_hash();
|
|
|
|
pv_lock_ops.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath;
|
|
|
|
pv_lock_ops.queued_spin_unlock = PV_CALLEE_SAVE(__pv_queued_spin_unlock);
|
|
|
|
pv_lock_ops.wait = xen_qlock_wait;
|
|
|
|
pv_lock_ops.kick = xen_qlock_kick;
|
2016-11-15 23:47:06 +08:00
|
|
|
pv_lock_ops.vcpu_is_preempted = PV_CALLEE_SAVE(xen_vcpu_stolen);
|
2008-07-24 04:28:58 +08:00
|
|
|
}
|
2008-08-21 08:02:19 +08:00
|
|
|
|
2013-08-09 22:21:54 +08:00
|
|
|
static __init int xen_parse_nopvspin(char *arg)
|
|
|
|
{
|
|
|
|
xen_pvspin = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("xen_nopvspin", xen_parse_nopvspin);
|
|
|
|
|