Merge branches 'stable/irq.fairness' and 'stable/irq.ween_of_nr_irqs' of git://git...
[pandora-kernel.git] / drivers / xen / events.c
index 4591853..02b5a9c 100644 (file)
@@ -694,7 +694,7 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc,
                                      handle_level_irq, name);
 
        xen_irq_info_pirq_init(irq, 0, pirq, 0, vector, 0);
-       ret = set_irq_msi(irq, msidesc);
+       ret = irq_set_msi_desc(irq, msidesc);
        if (ret < 0)
                goto error_irq;
 out:
@@ -818,6 +818,21 @@ static int bind_ipi_to_irq(unsigned int ipi, unsigned int cpu)
        return irq;
 }
 
+static int bind_interdomain_evtchn_to_irq(unsigned int remote_domain,
+                                         unsigned int remote_port)
+{
+       struct evtchn_bind_interdomain bind_interdomain;
+       int err;
+
+       bind_interdomain.remote_dom  = remote_domain;
+       bind_interdomain.remote_port = remote_port;
+
+       err = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain,
+                                         &bind_interdomain);
+
+       return err ? : bind_evtchn_to_irq(bind_interdomain.local_port);
+}
+
 
 int bind_virq_to_irq(unsigned int virq, unsigned int cpu)
 {
@@ -913,6 +928,29 @@ int bind_evtchn_to_irqhandler(unsigned int evtchn,
 }
 EXPORT_SYMBOL_GPL(bind_evtchn_to_irqhandler);
 
+int bind_interdomain_evtchn_to_irqhandler(unsigned int remote_domain,
+                                         unsigned int remote_port,
+                                         irq_handler_t handler,
+                                         unsigned long irqflags,
+                                         const char *devname,
+                                         void *dev_id)
+{
+       int irq, retval;
+
+       irq = bind_interdomain_evtchn_to_irq(remote_domain, remote_port);
+       if (irq < 0)
+               return irq;
+
+       retval = request_irq(irq, handler, irqflags, devname, dev_id);
+       if (retval != 0) {
+               unbind_from_irq(irq);
+               return retval;
+       }
+
+       return irq;
+}
+EXPORT_SYMBOL_GPL(bind_interdomain_evtchn_to_irqhandler);
+
 int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu,
                            irq_handler_t handler,
                            unsigned long irqflags, const char *devname, void *dev_id)
@@ -1052,6 +1090,13 @@ irqreturn_t xen_debug_interrupt(int irq, void *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);
+
+/*
+ * Mask out the i least significant bits of w
+ */
+#define MASK_LSBS(w, i) (w & ((~0UL) << i))
 
 /*
  * Search the CPUs pending events bitmasks.  For each one found, map
@@ -1064,6 +1109,9 @@ static DEFINE_PER_CPU(unsigned, xed_nesting_count);
  */
 static void __xen_evtchn_do_upcall(void)
 {
+       int start_word_idx, start_bit_idx;
+       int word_idx, bit_idx;
+       int i;
        int cpu = get_cpu();
        struct shared_info *s = HYPERVISOR_shared_info;
        struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu);
@@ -1082,17 +1130,57 @@ static void __xen_evtchn_do_upcall(void)
                wmb();
 #endif
                pending_words = xchg(&vcpu_info->evtchn_pending_sel, 0);
-               while (pending_words != 0) {
+
+               start_word_idx = __this_cpu_read(current_word_idx);
+               start_bit_idx = __this_cpu_read(current_bit_idx);
+
+               word_idx = start_word_idx;
+
+               for (i = 0; pending_words != 0; i++) {
                        unsigned long pending_bits;
-                       int word_idx = __ffs(pending_words);
-                       pending_words &= ~(1UL << word_idx);
+                       unsigned long words;
+
+                       words = MASK_LSBS(pending_words, word_idx);
+
+                       /*
+                        * If we masked out all events, wrap to beginning.
+                        */
+                       if (words == 0) {
+                               word_idx = 0;
+                               bit_idx = 0;
+                               continue;
+                       }
+                       word_idx = __ffs(words);
+
+                       pending_bits = 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 */
+                               if (i == 0)
+                                       /* 1st time: start in the middle */
+                                       bit_idx = start_bit_idx;
+                               else
+                                       /* 2nd time: mask bits done already */
+                                       bit_idx &= (1UL << start_bit_idx) - 1;
+                       }
 
-                       while ((pending_bits = active_evtchns(cpu, s, word_idx)) != 0) {
-                               int bit_idx = __ffs(pending_bits);
-                               int port = (word_idx * BITS_PER_LONG) + bit_idx;
-                               int irq = evtchn_to_irq[port];
+                       do {
+                               unsigned long bits;
+                               int port, irq;
                                struct irq_desc *desc;
 
+                               bits = MASK_LSBS(pending_bits, bit_idx);
+
+                               /* If we masked out all events, move on. */
+                               if (bits == 0)
+                                       break;
+
+                               bit_idx = __ffs(bits);
+
+                               /* Process port. */
+                               port = (word_idx * BITS_PER_LONG) + bit_idx;
+                               irq = evtchn_to_irq[port];
+
                                mask_evtchn(port);
                                clear_evtchn(port);
 
@@ -1101,7 +1189,21 @@ static void __xen_evtchn_do_upcall(void)
                                        if (desc)
                                                generic_handle_irq_desc(irq, desc);
                                }
-                       }
+
+                               bit_idx = (bit_idx + 1) % BITS_PER_LONG;
+
+                               /* Next caller starts at last processed + 1 */
+                               __this_cpu_write(current_word_idx,
+                                                bit_idx ? word_idx :
+                                                (word_idx+1) % BITS_PER_LONG);
+                               __this_cpu_write(current_bit_idx, bit_idx);
+                       } while (bit_idx != 0);
+
+                       /* Scan start_l1i twice; all others once. */
+                       if ((word_idx != start_word_idx) || (i != 0))
+                               pending_words &= ~(1UL << word_idx);
+
+                       word_idx = (word_idx + 1) % BITS_PER_LONG;
                }
 
                BUG_ON(!irqs_disabled());