[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC PATCH 1/3] Xen: generalized event channel operations.
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- drivers/xen/events.c | 110 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 76 insertions(+), 34 deletions(-) diff --git a/drivers/xen/events.c b/drivers/xen/events.c index 7595581..835101f 100644 --- a/drivers/xen/events.c +++ b/drivers/xen/events.c @@ -51,6 +51,23 @@ #include <xen/interface/hvm/hvm_op.h> #include <xen/interface/hvm/params.h> +/* N-level event channel, starting from 2 */ +static unsigned int evtchn_level = 2; + +struct evtchn_ops { + unsigned long (*active_evtchns)(unsigned int, + struct shared_info*, unsigned int); + void (*clear_evtchn)(int); + void (*set_evtchn)(int); + int (*test_evtchn)(int); + void (*mask_evtchn)(int); + void (*unmask_evtchn)(int); + int (*is_masked)(int); + void (*xen_evtchn_do_upcall)(void); + irqreturn_t (*xen_debug_interrupt)(int, void*); +}; +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. @@ -285,9 +302,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] & @@ -309,6 +326,7 @@ static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu) info_for_irq(irq)->cpu = cpu; } + static void init_evtchn_cpu_bindings(void) { int i; @@ -327,25 +345,24 @@ 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]); } - /** * notify_remote_via_irq - send event to remote end of event channel via irq * @irq: irq of event channel to send event to @@ -363,13 +380,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 +538,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 +584,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 +607,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) @@ -1164,7 +1181,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 __xen_debug_interrupt_l2(int irq, void *dev_id) { struct shared_info *sh = HYPERVISOR_shared_info; int cpu = smp_processor_id(); @@ -1245,6 +1262,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->xen_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 +1285,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 __xen_evtchn_do_upcall_l2(void) { int start_word_idx, start_bit_idx; int word_idx, bit_idx; @@ -1308,7 +1330,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 +1399,7 @@ void xen_evtchn_do_upcall(struct pt_regs *regs) exit_idle(); irq_enter(); - __xen_evtchn_do_upcall(); + eops->xen_evtchn_do_upcall(); irq_exit(); set_irq_regs(old_regs); @@ -1385,7 +1407,7 @@ void xen_evtchn_do_upcall(struct pt_regs *regs) void xen_hvm_evtchn_do_upcall(void) { - __xen_evtchn_do_upcall(); + eops->xen_evtchn_do_upcall(); } EXPORT_SYMBOL_GPL(xen_hvm_evtchn_do_upcall); @@ -1459,15 +1481,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->is_masked(evtchn); + eops->set_evtchn(evtchn); if (!masked) - unmask_evtchn(evtchn); + eops->unmask_evtchn(evtchn); return 1; } @@ -1477,7 +1498,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 +1506,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 +1516,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 +1525,24 @@ static void mask_ack_dynirq(struct irq_data *data) ack_dynirq(data); } +static inline int __is_masked_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->is_masked(evtchn); + eops->set_evtchn(evtchn); if (!masked) - unmask_evtchn(evtchn); + eops->unmask_evtchn(evtchn); ret = 1; } @@ -1616,7 +1642,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 +1650,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 +1659,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; } @@ -1684,7 +1710,7 @@ void xen_irq_resume(void) /* New event-channel space is not 'live' yet. */ for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++) - mask_evtchn(evtchn); + eops->mask_evtchn(evtchn); /* No IRQ <-> event-channel mappings. */ list_for_each_entry(info, &xen_irq_list_head, list) @@ -1783,12 +1809,28 @@ 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, + .is_masked = __is_masked_l2, + .xen_evtchn_do_upcall = __xen_evtchn_do_upcall_l2, + .xen_debug_interrupt = __xen_debug_interrupt_l2, +}; + void __init xen_init_IRQ(void) { int i, rc; + evtchn_level = 2; + eops = &evtchn_ops_l2; + + /* Setup 2-level event channel */ evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq), - GFP_KERNEL); + GFP_KERNEL); BUG_ON(!evtchn_to_irq); for (i = 0; i < NR_EVENT_CHANNELS; i++) evtchn_to_irq[i] = -1; @@ -1797,7 +1839,7 @@ void __init xen_init_IRQ(void) /* No event channels are 'live' right now. */ for (i = 0; i < NR_EVENT_CHANNELS; i++) - mask_evtchn(i); + eops->mask_evtchn(i); pirq_needs_eoi = pirq_needs_eoi_flag; -- 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 |