ce9c4b41f02d14406e6539b788af411890e41d4c
2 * Xen hypercall batching.
4 * Xen allows multiple hypercalls to be issued at once, using the
5 * multicall interface. This allows the cost of trapping into the
6 * hypervisor to be amortized over several calls.
8 * This file implements a simple interface for multicalls. There's a
9 * per-cpu buffer of outstanding multicalls. When you want to queue a
10 * multicall for issuing, you can allocate a multicall slot for the
11 * call and its arguments, along with storage for space which is
12 * pointed to by the arguments (for passing pointers to structures,
13 * etc). When the multicall is actually issued, all the space for the
14 * commands and allocated memory is freed for reuse.
16 * Multicalls are flushed whenever any of the buffers get full, or
17 * when explicitly requested. There's no way to get per-multicall
18 * return results back. It will BUG if any of the multicalls fail.
20 * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007
22 #include <linux/percpu.h>
23 #include <linux/hardirq.h>
25 #include <asm/xen/hypercall.h>
27 #include "multicalls.h"
30 #define MC_ARGS (MC_BATCH * 16 / sizeof(u64))
33 struct multicall_entry entries
[MC_BATCH
];
38 } callbacks
[MC_BATCH
];
39 unsigned mcidx
, argidx
, cbidx
;
42 static DEFINE_PER_CPU(struct mc_buffer
, mc_buffer
);
43 DEFINE_PER_CPU(unsigned long, xen_mc_irq_flags
);
45 void xen_mc_flush(void)
47 struct mc_buffer
*b
= &__get_cpu_var(mc_buffer
);
52 BUG_ON(preemptible());
54 /* Disable interrupts in case someone comes in and queues
55 something in the middle */
56 local_irq_save(flags
);
59 if (HYPERVISOR_multicall(b
->entries
, b
->mcidx
) != 0)
61 for (i
= 0; i
< b
->mcidx
; i
++)
62 if (b
->entries
[i
].result
< 0)
67 BUG_ON(b
->argidx
!= 0);
69 local_irq_restore(flags
);
71 for(i
= 0; i
< b
->cbidx
; i
++) {
72 struct callback
*cb
= &b
->callbacks
[i
];
81 struct multicall_space
__xen_mc_entry(size_t args
)
83 struct mc_buffer
*b
= &__get_cpu_var(mc_buffer
);
84 struct multicall_space ret
;
85 unsigned argspace
= (args
+ sizeof(u64
) - 1) / sizeof(u64
);
87 BUG_ON(preemptible());
88 BUG_ON(argspace
> MC_ARGS
);
90 if (b
->mcidx
== MC_BATCH
||
91 (b
->argidx
+ argspace
) > MC_ARGS
)
94 ret
.mc
= &b
->entries
[b
->mcidx
];
96 ret
.args
= &b
->args
[b
->argidx
];
97 b
->argidx
+= argspace
;
102 void xen_mc_callback(void (*fn
)(void *), void *data
)
104 struct mc_buffer
*b
= &__get_cpu_var(mc_buffer
);
107 if (b
->cbidx
== MC_BATCH
)
110 cb
= &b
->callbacks
[b
->cbidx
++];
This page took 0.034603 seconds and 4 git commands to generate.