mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-21 19:53:59 +08:00
7ebed39ff7
Before: total: 2 errors, 2 warnings, 138 lines checked After: total: 0 errors, 2 warnings, 138 lines checked No code changed: arch/x86/xen/multicalls.o: text data bss dec hex filename 887 2832 0 3719 e87 multicalls.o.before 887 2832 0 3719 e87 multicalls.o.after md5: cf6d72d9db6dc5a3ebe01eec9f05e95f multicalls.o.before.asm cf6d72d9db6dc5a3ebe01eec9f05e95f multicalls.o.after.asm Signed-off-by: Paolo Ciarrocchi <paolo.ciarrocchi@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
139 lines
3.2 KiB
C
139 lines
3.2 KiB
C
/*
|
|
* Xen hypercall batching.
|
|
*
|
|
* Xen allows multiple hypercalls to be issued at once, using the
|
|
* multicall interface. This allows the cost of trapping into the
|
|
* hypervisor to be amortized over several calls.
|
|
*
|
|
* This file implements a simple interface for multicalls. There's a
|
|
* per-cpu buffer of outstanding multicalls. When you want to queue a
|
|
* multicall for issuing, you can allocate a multicall slot for the
|
|
* call and its arguments, along with storage for space which is
|
|
* pointed to by the arguments (for passing pointers to structures,
|
|
* etc). When the multicall is actually issued, all the space for the
|
|
* commands and allocated memory is freed for reuse.
|
|
*
|
|
* Multicalls are flushed whenever any of the buffers get full, or
|
|
* when explicitly requested. There's no way to get per-multicall
|
|
* return results back. It will BUG if any of the multicalls fail.
|
|
*
|
|
* Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007
|
|
*/
|
|
#include <linux/percpu.h>
|
|
#include <linux/hardirq.h>
|
|
|
|
#include <asm/xen/hypercall.h>
|
|
|
|
#include "multicalls.h"
|
|
|
|
#define MC_DEBUG 1
|
|
|
|
#define MC_BATCH 32
|
|
#define MC_ARGS (MC_BATCH * 16 / sizeof(u64))
|
|
|
|
struct mc_buffer {
|
|
struct multicall_entry entries[MC_BATCH];
|
|
#if MC_DEBUG
|
|
struct multicall_entry debug[MC_BATCH];
|
|
#endif
|
|
u64 args[MC_ARGS];
|
|
struct callback {
|
|
void (*fn)(void *);
|
|
void *data;
|
|
} callbacks[MC_BATCH];
|
|
unsigned mcidx, argidx, cbidx;
|
|
};
|
|
|
|
static DEFINE_PER_CPU(struct mc_buffer, mc_buffer);
|
|
DEFINE_PER_CPU(unsigned long, xen_mc_irq_flags);
|
|
|
|
void xen_mc_flush(void)
|
|
{
|
|
struct mc_buffer *b = &__get_cpu_var(mc_buffer);
|
|
int ret = 0;
|
|
unsigned long flags;
|
|
int i;
|
|
|
|
BUG_ON(preemptible());
|
|
|
|
/* Disable interrupts in case someone comes in and queues
|
|
something in the middle */
|
|
local_irq_save(flags);
|
|
|
|
if (b->mcidx) {
|
|
#if MC_DEBUG
|
|
memcpy(b->debug, b->entries,
|
|
b->mcidx * sizeof(struct multicall_entry));
|
|
#endif
|
|
|
|
if (HYPERVISOR_multicall(b->entries, b->mcidx) != 0)
|
|
BUG();
|
|
for (i = 0; i < b->mcidx; i++)
|
|
if (b->entries[i].result < 0)
|
|
ret++;
|
|
|
|
#if MC_DEBUG
|
|
if (ret) {
|
|
printk(KERN_ERR "%d multicall(s) failed: cpu %d\n",
|
|
ret, smp_processor_id());
|
|
for (i = 0; i < b->mcidx; i++) {
|
|
printk(" call %2d/%d: op=%lu arg=[%lx] result=%ld\n",
|
|
i+1, b->mcidx,
|
|
b->debug[i].op,
|
|
b->debug[i].args[0],
|
|
b->entries[i].result);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
b->mcidx = 0;
|
|
b->argidx = 0;
|
|
} else
|
|
BUG_ON(b->argidx != 0);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
for (i = 0; i < b->cbidx; i++) {
|
|
struct callback *cb = &b->callbacks[i];
|
|
|
|
(*cb->fn)(cb->data);
|
|
}
|
|
b->cbidx = 0;
|
|
|
|
BUG_ON(ret);
|
|
}
|
|
|
|
struct multicall_space __xen_mc_entry(size_t args)
|
|
{
|
|
struct mc_buffer *b = &__get_cpu_var(mc_buffer);
|
|
struct multicall_space ret;
|
|
unsigned argspace = (args + sizeof(u64) - 1) / sizeof(u64);
|
|
|
|
BUG_ON(preemptible());
|
|
BUG_ON(argspace > MC_ARGS);
|
|
|
|
if (b->mcidx == MC_BATCH ||
|
|
(b->argidx + argspace) > MC_ARGS)
|
|
xen_mc_flush();
|
|
|
|
ret.mc = &b->entries[b->mcidx];
|
|
b->mcidx++;
|
|
ret.args = &b->args[b->argidx];
|
|
b->argidx += argspace;
|
|
|
|
return ret;
|
|
}
|
|
|
|
void xen_mc_callback(void (*fn)(void *), void *data)
|
|
{
|
|
struct mc_buffer *b = &__get_cpu_var(mc_buffer);
|
|
struct callback *cb;
|
|
|
|
if (b->cbidx == MC_BATCH)
|
|
xen_mc_flush();
|
|
|
|
cb = &b->callbacks[b->cbidx++];
|
|
cb->fn = fn;
|
|
cb->data = data;
|
|
}
|