|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC PATCH V2 3/8] xen: generalized event channel operations
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
drivers/xen/events.c | 133 ++++++++++++++++++++++++++++++++++----------------
drivers/xen/evtchn.c | 14 +++---
2 files changed, 98 insertions(+), 49 deletions(-)
diff --git a/drivers/xen/events.c b/drivers/xen/events.c
index dadeea4..6c1917e 100644
--- a/drivers/xen/events.c
+++ b/drivers/xen/events.c
@@ -51,6 +51,27 @@
#include <xen/interface/hvm/hvm_op.h>
#include <xen/interface/hvm/params.h>
+/* N-level event channel, starting from 2 */
+unsigned int evtchn_level = 2;
+EXPORT_SYMBOL_GPL(evtchn_level);
+unsigned int nr_event_channels;
+EXPORT_SYMBOL_GPL(nr_event_channels);
+
+struct evtchn_ops {
+ unsigned long (*active_evtchns) (unsigned int cpu,
+ struct shared_info *sh,
+ unsigned int idx);
+ void (*clear_evtchn) (int port);
+ void (*set_evtchn) (int port);
+ int (*test_evtchn) (int port);
+ void (*mask_evtchn) (int port);
+ void (*unmask_evtchn) (int port);
+ int (*test_and_set_mask)(int port);
+ void (*do_upcall) (void);
+ irqreturn_t (*debug_interrupt) (int irq, void *dev_id);
+};
+static struct evtchn_ops *eops;
+
/*
* This lock protects updates to the following mapping and reference-count
* arrays. The lock does not need to be acquired to read the mapping tables.
@@ -113,7 +134,7 @@ static int *evtchn_to_irq;
static unsigned long *pirq_eoi_map;
static bool (*pirq_needs_eoi)(unsigned irq);
-static DEFINE_PER_CPU(unsigned long [NR_EVENT_CHANNELS/BITS_PER_LONG],
+static DEFINE_PER_CPU(unsigned long [NR_EVENT_CHANNELS_L2/BITS_PER_LONG],
cpu_evtchn_mask);
/* Xen will never allocate port zero for any purpose. */
@@ -285,9 +306,9 @@ static bool pirq_needs_eoi_flag(unsigned irq)
return info->u.pirq.flags & PIRQ_NEEDS_EOI;
}
-static inline unsigned long active_evtchns(unsigned int cpu,
- struct shared_info *sh,
- unsigned int idx)
+static inline unsigned long active_evtchns_l2(unsigned int cpu,
+ struct shared_info *sh,
+ unsigned int idx)
{
return sh->evtchn_pending[idx] &
per_cpu(cpu_evtchn_mask, cpu)[idx] &
@@ -327,19 +348,19 @@ static void init_evtchn_cpu_bindings(void)
(i == 0) ? ~0 : 0, sizeof(*per_cpu(cpu_evtchn_mask, i)));
}
-static inline void clear_evtchn(int port)
+static inline void clear_evtchn_l2(int port)
{
struct shared_info *s = HYPERVISOR_shared_info;
sync_clear_bit(port, &s->evtchn_pending[0]);
}
-static inline void set_evtchn(int port)
+static inline void set_evtchn_l2(int port)
{
struct shared_info *s = HYPERVISOR_shared_info;
sync_set_bit(port, &s->evtchn_pending[0]);
}
-static inline int test_evtchn(int port)
+static inline int test_evtchn_l2(int port)
{
struct shared_info *s = HYPERVISOR_shared_info;
return sync_test_bit(port, &s->evtchn_pending[0]);
@@ -363,13 +384,13 @@ void notify_remote_via_irq(int irq)
}
EXPORT_SYMBOL_GPL(notify_remote_via_irq);
-static void mask_evtchn(int port)
+static void mask_evtchn_l2(int port)
{
struct shared_info *s = HYPERVISOR_shared_info;
sync_set_bit(port, &s->evtchn_mask[0]);
}
-static void unmask_evtchn(int port)
+static void unmask_evtchn_l2(int port)
{
struct shared_info *s = HYPERVISOR_shared_info;
unsigned int cpu = get_cpu();
@@ -521,7 +542,7 @@ static void eoi_pirq(struct irq_data *data)
irq_move_irq(data);
if (VALID_EVTCHN(evtchn))
- clear_evtchn(evtchn);
+ eops->clear_evtchn(evtchn);
if (pirq_needs_eoi(data->irq)) {
rc = HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi);
@@ -567,7 +588,7 @@ static unsigned int __startup_pirq(unsigned int irq)
info->evtchn = evtchn;
out:
- unmask_evtchn(evtchn);
+ eops->unmask_evtchn(evtchn);
eoi_pirq(irq_get_irq_data(irq));
return 0;
@@ -590,7 +611,7 @@ static void shutdown_pirq(struct irq_data *data)
if (!VALID_EVTCHN(evtchn))
return;
- mask_evtchn(evtchn);
+ eops->mask_evtchn(evtchn);
close.port = evtchn;
if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
@@ -896,7 +917,7 @@ static int find_virq(unsigned int virq, unsigned int cpu)
int port, rc = -ENOENT;
memset(&status, 0, sizeof(status));
- for (port = 0; port <= NR_EVENT_CHANNELS; port++) {
+ for (port = 0; port <= nr_event_channels; port++) {
status.dom = DOMID_SELF;
status.port = port;
rc = HYPERVISOR_event_channel_op(EVTCHNOP_status, &status);
@@ -1121,7 +1142,7 @@ int evtchn_get(unsigned int evtchn)
struct irq_info *info;
int err = -ENOENT;
- if (evtchn >= NR_EVENT_CHANNELS)
+ if (evtchn >= nr_event_channels)
return -EINVAL;
mutex_lock(&irq_mapping_update_lock);
@@ -1164,7 +1185,7 @@ void xen_send_IPI_one(unsigned int cpu, enum ipi_vector
vector)
notify_remote_via_irq(irq);
}
-irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
+static irqreturn_t debug_interrupt_l2(int irq, void *dev_id)
{
struct shared_info *sh = HYPERVISOR_shared_info;
int cpu = smp_processor_id();
@@ -1210,7 +1231,7 @@ irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
i % 8 == 0 ? "\n " : " ");
printk("\nlocal cpu%d mask:\n ", cpu);
- for (i = (NR_EVENT_CHANNELS/BITS_PER_LONG)-1; i >= 0; i--)
+ for (i = (NR_EVENT_CHANNELS_L2/BITS_PER_LONG)-1; i >= 0; i--)
printk("%0*lx%s", (int)(sizeof(cpu_evtchn[0])*2),
cpu_evtchn[i],
i % 8 == 0 ? "\n " : " ");
@@ -1225,7 +1246,7 @@ irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
}
printk("\npending list:\n");
- for (i = 0; i < NR_EVENT_CHANNELS; i++) {
+ for (i = 0; i < NR_EVENT_CHANNELS_L2; i++) {
if (sync_test_bit(i, sh->evtchn_pending)) {
int word_idx = i / BITS_PER_LONG;
printk(" %d: event %d -> irq %d%s%s%s\n",
@@ -1245,6 +1266,11 @@ irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
return IRQ_HANDLED;
}
+irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
+{
+ return eops->debug_interrupt(irq, dev_id);
+}
+
static DEFINE_PER_CPU(unsigned, xed_nesting_count);
static DEFINE_PER_CPU(unsigned int, current_word_idx);
static DEFINE_PER_CPU(unsigned int, current_bit_idx);
@@ -1263,7 +1289,7 @@ static DEFINE_PER_CPU(unsigned int, current_bit_idx);
* a bitset of words which contain pending event bits. The second
* level is a bitset of pending events themselves.
*/
-static void __xen_evtchn_do_upcall(void)
+static void do_upcall_l2(void)
{
int start_word_idx, start_bit_idx;
int word_idx, bit_idx;
@@ -1308,7 +1334,7 @@ static void __xen_evtchn_do_upcall(void)
}
word_idx = __ffs(words);
- pending_bits = active_evtchns(cpu, s, word_idx);
+ pending_bits = eops->active_evtchns(cpu, s, word_idx);
bit_idx = 0; /* usually scan entire word from start */
if (word_idx == start_word_idx) {
/* We scan the starting word in two parts */
@@ -1377,7 +1403,7 @@ void xen_evtchn_do_upcall(struct pt_regs *regs)
exit_idle();
irq_enter();
- __xen_evtchn_do_upcall();
+ eops->do_upcall();
irq_exit();
set_irq_regs(old_regs);
@@ -1385,7 +1411,7 @@ void xen_evtchn_do_upcall(struct pt_regs *regs)
void xen_hvm_evtchn_do_upcall(void)
{
- __xen_evtchn_do_upcall();
+ eops->do_upcall();
}
EXPORT_SYMBOL_GPL(xen_hvm_evtchn_do_upcall);
@@ -1459,15 +1485,14 @@ static int set_affinity_irq(struct irq_data *data,
const struct cpumask *dest,
int resend_irq_on_evtchn(unsigned int irq)
{
int masked, evtchn = evtchn_from_irq(irq);
- struct shared_info *s = HYPERVISOR_shared_info;
if (!VALID_EVTCHN(evtchn))
return 1;
- masked = sync_test_and_set_bit(evtchn, s->evtchn_mask);
- sync_set_bit(evtchn, s->evtchn_pending);
+ masked = eops->test_and_set_mask(evtchn);
+ eops->set_evtchn(evtchn);
if (!masked)
- unmask_evtchn(evtchn);
+ eops->unmask_evtchn(evtchn);
return 1;
}
@@ -1477,7 +1502,7 @@ static void enable_dynirq(struct irq_data *data)
int evtchn = evtchn_from_irq(data->irq);
if (VALID_EVTCHN(evtchn))
- unmask_evtchn(evtchn);
+ eops->unmask_evtchn(evtchn);
}
static void disable_dynirq(struct irq_data *data)
@@ -1485,7 +1510,7 @@ static void disable_dynirq(struct irq_data *data)
int evtchn = evtchn_from_irq(data->irq);
if (VALID_EVTCHN(evtchn))
- mask_evtchn(evtchn);
+ eops->mask_evtchn(evtchn);
}
static void ack_dynirq(struct irq_data *data)
@@ -1495,7 +1520,7 @@ static void ack_dynirq(struct irq_data *data)
irq_move_irq(data);
if (VALID_EVTCHN(evtchn))
- clear_evtchn(evtchn);
+ eops->clear_evtchn(evtchn);
}
static void mask_ack_dynirq(struct irq_data *data)
@@ -1504,19 +1529,24 @@ static void mask_ack_dynirq(struct irq_data *data)
ack_dynirq(data);
}
+static inline int test_and_set_mask_l2(int chn)
+{
+ struct shared_info *sh = HYPERVISOR_shared_info;
+ return sync_test_and_set_bit(chn, sh->evtchn_mask);
+}
+
static int retrigger_dynirq(struct irq_data *data)
{
int evtchn = evtchn_from_irq(data->irq);
- struct shared_info *sh = HYPERVISOR_shared_info;
int ret = 0;
if (VALID_EVTCHN(evtchn)) {
int masked;
- masked = sync_test_and_set_bit(evtchn, sh->evtchn_mask);
- sync_set_bit(evtchn, sh->evtchn_pending);
+ masked = eops->test_and_set_mask(evtchn);
+ eops->set_evtchn(evtchn);
if (!masked)
- unmask_evtchn(evtchn);
+ eops->unmask_evtchn(evtchn);
ret = 1;
}
@@ -1616,7 +1646,7 @@ void xen_clear_irq_pending(int irq)
int evtchn = evtchn_from_irq(irq);
if (VALID_EVTCHN(evtchn))
- clear_evtchn(evtchn);
+ eops->clear_evtchn(evtchn);
}
EXPORT_SYMBOL(xen_clear_irq_pending);
void xen_set_irq_pending(int irq)
@@ -1624,7 +1654,7 @@ void xen_set_irq_pending(int irq)
int evtchn = evtchn_from_irq(irq);
if (VALID_EVTCHN(evtchn))
- set_evtchn(evtchn);
+ eops->set_evtchn(evtchn);
}
bool xen_test_irq_pending(int irq)
@@ -1633,7 +1663,7 @@ bool xen_test_irq_pending(int irq)
bool ret = false;
if (VALID_EVTCHN(evtchn))
- ret = test_evtchn(evtchn);
+ ret = eops->test_evtchn(evtchn);
return ret;
}
@@ -1683,14 +1713,14 @@ void xen_irq_resume(void)
init_evtchn_cpu_bindings();
/* New event-channel space is not 'live' yet. */
- for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++)
- mask_evtchn(evtchn);
+ for (evtchn = 0; evtchn < nr_event_channels; evtchn++)
+ eops->mask_evtchn(evtchn);
/* No IRQ <-> event-channel mappings. */
list_for_each_entry(info, &xen_irq_list_head, list)
info->evtchn = 0; /* zap event-channel binding */
- for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++)
+ for (evtchn = 0; evtchn < nr_event_channels; evtchn++)
evtchn_to_irq[evtchn] = -1;
for_each_possible_cpu(cpu) {
@@ -1783,21 +1813,38 @@ void xen_callback_vector(void)
void xen_callback_vector(void) {}
#endif
+static struct evtchn_ops evtchn_ops_l2 __read_mostly = {
+ .active_evtchns = active_evtchns_l2,
+ .clear_evtchn = clear_evtchn_l2,
+ .set_evtchn = set_evtchn_l2,
+ .test_evtchn = test_evtchn_l2,
+ .mask_evtchn = mask_evtchn_l2,
+ .unmask_evtchn = unmask_evtchn_l2,
+ .test_and_set_mask = test_and_set_mask_l2,
+ .do_upcall = do_upcall_l2,
+ .debug_interrupt = debug_interrupt_l2,
+};
+
void __init xen_init_IRQ(void)
{
int i, rc;
- evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq),
- GFP_KERNEL);
+ evtchn_level = 2;
+ nr_event_channels = NR_EVENT_CHANNELS_L2;
+ eops = &evtchn_ops_l2;
+
+ /* Setup 2-level event channel */
+ evtchn_to_irq = kcalloc(nr_event_channels, sizeof(*evtchn_to_irq),
+ GFP_KERNEL);
BUG_ON(!evtchn_to_irq);
- for (i = 0; i < NR_EVENT_CHANNELS; i++)
+ for (i = 0; i < nr_event_channels; i++)
evtchn_to_irq[i] = -1;
init_evtchn_cpu_bindings();
/* No event channels are 'live' right now. */
- for (i = 0; i < NR_EVENT_CHANNELS; i++)
- mask_evtchn(i);
+ for (i = 0; i < nr_event_channels; i++)
+ eops->mask_evtchn(i);
pirq_needs_eoi = pirq_needs_eoi_flag;
diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c
index b1f60a0..975e970 100644
--- a/drivers/xen/evtchn.c
+++ b/drivers/xen/evtchn.c
@@ -53,6 +53,8 @@
#include <xen/evtchn.h>
#include <asm/xen/hypervisor.h>
+extern unsigned int nr_event_channels;
+
struct per_user_data {
struct mutex bind_mutex; /* serialize bind/unbind operations */
@@ -232,7 +234,7 @@ static ssize_t evtchn_write(struct file *file, const char
__user *buf,
for (i = 0; i < (count/sizeof(evtchn_port_t)); i++) {
unsigned port = kbuf[i];
- if (port < NR_EVENT_CHANNELS &&
+ if (port < nr_event_channels &&
get_port_user(port) == u &&
!get_port_enabled(port)) {
set_port_enabled(port, true);
@@ -364,7 +366,7 @@ static long evtchn_ioctl(struct file *file,
break;
rc = -EINVAL;
- if (unbind.port >= NR_EVENT_CHANNELS)
+ if (unbind.port >= nr_event_channels)
break;
spin_lock_irq(&port_user_lock);
@@ -392,7 +394,7 @@ static long evtchn_ioctl(struct file *file,
if (copy_from_user(¬ify, uarg, sizeof(notify)))
break;
- if (notify.port >= NR_EVENT_CHANNELS) {
+ if (notify.port >= nr_event_channels) {
rc = -EINVAL;
} else if (get_port_user(notify.port) != u) {
rc = -ENOTCONN;
@@ -482,7 +484,7 @@ static int evtchn_release(struct inode *inode, struct file
*filp)
free_page((unsigned long)u->ring);
- for (i = 0; i < NR_EVENT_CHANNELS; i++) {
+ for (i = 0; i < nr_event_channels; i++) {
if (get_port_user(i) != u)
continue;
@@ -491,7 +493,7 @@ static int evtchn_release(struct inode *inode, struct file
*filp)
spin_unlock_irq(&port_user_lock);
- for (i = 0; i < NR_EVENT_CHANNELS; i++) {
+ for (i = 0; i < nr_event_channels; i++) {
if (get_port_user(i) != u)
continue;
@@ -528,7 +530,7 @@ static int __init evtchn_init(void)
if (!xen_domain())
return -ENODEV;
- port_user = kcalloc(NR_EVENT_CHANNELS, sizeof(*port_user), GFP_KERNEL);
+ port_user = kcalloc(nr_event_channels, sizeof(*port_user), GFP_KERNEL);
if (port_user == NULL)
return -ENOMEM;
--
1.7.10.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |