Merge branch 'linus' into irq/core
authorThomas Gleixner <tglx@linutronix.de>
Tue, 13 Mar 2012 15:34:48 +0000 (16:34 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Tue, 13 Mar 2012 15:35:16 +0000 (16:35 +0100)
Reason: Get upstream fixes integrated before further modifications.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1  2 
include/linux/sched.h
kernel/irq/chip.c
kernel/irq/internals.h
kernel/irq/manage.c

diff --combined include/linux/sched.h
@@@ -1319,11 -1319,6 +1319,11 @@@ struct task_struct 
        unsigned sched_reset_on_fork:1;
        unsigned sched_contributes_to_load:1;
  
 +#ifdef CONFIG_GENERIC_HARDIRQS
 +      /* IRQ handler threads */
 +      unsigned irq_thread:1;
 +#endif
 +
        pid_t pid;
        pid_t tgid;
  
   * mempolicy */
        spinlock_t alloc_lock;
  
 -#ifdef CONFIG_GENERIC_HARDIRQS
 -      /* IRQ handler threads */
 -      struct irqaction *irqaction;
 -#endif
 -
        /* Protection of the PI data structures: */
        raw_spinlock_t pi_lock;
  
@@@ -1777,7 -1777,6 +1777,6 @@@ extern void thread_group_times(struct t
  /*
   * Per process flags
   */
- #define PF_STARTING   0x00000002      /* being created */
  #define PF_EXITING    0x00000004      /* getting shut down */
  #define PF_EXITPIDONE 0x00000008      /* pi exit done on shut down */
  #define PF_VCPU               0x00000010      /* I'm a virtual CPU */
@@@ -2371,7 -2370,7 +2370,7 @@@ static inline int thread_group_empty(st
   * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring
   * subscriptions and synchronises with wait4().  Also used in procfs.  Also
   * pins the final release of task.io_context.  Also protects ->cpuset and
-  * ->cgroup.subsys[].
+  * ->cgroup.subsys[]. And ->vfork_done.
   *
   * Nests both inside and outside of read_lock(&tasklist_lock).
   * It must not be nested with write_lock_irq(&tasklist_lock),
diff --combined kernel/irq/chip.c
@@@ -61,7 -61,8 +61,7 @@@ int irq_set_irq_type(unsigned int irq, 
                return -EINVAL;
  
        type &= IRQ_TYPE_SENSE_MASK;
 -      if (type != IRQ_TYPE_NONE)
 -              ret = __irq_set_trigger(desc, irq, type);
 +      ret = __irq_set_trigger(desc, irq, type);
        irq_put_desc_busunlock(desc, flags);
        return ret;
  }
@@@ -156,19 -157,22 +156,22 @@@ static void irq_state_set_masked(struc
        irqd_set(&desc->irq_data, IRQD_IRQ_MASKED);
  }
  
- int irq_startup(struct irq_desc *desc)
+ int irq_startup(struct irq_desc *desc, bool resend)
  {
+       int ret = 0;
        irq_state_clr_disabled(desc);
        desc->depth = 0;
  
        if (desc->irq_data.chip->irq_startup) {
-               int ret = desc->irq_data.chip->irq_startup(&desc->irq_data);
+               ret = desc->irq_data.chip->irq_startup(&desc->irq_data);
                irq_state_clr_masked(desc);
-               return ret;
+       } else {
+               irq_enable(desc);
        }
-       irq_enable(desc);
-       return 0;
+       if (resend)
+               check_irq_resend(desc, desc->irq_data.irq);
+       return ret;
  }
  
  void irq_shutdown(struct irq_desc *desc)
@@@ -329,6 -333,24 +332,24 @@@ out_unlock
  }
  EXPORT_SYMBOL_GPL(handle_simple_irq);
  
+ /*
+  * Called unconditionally from handle_level_irq() and only for oneshot
+  * interrupts from handle_fasteoi_irq()
+  */
+ static void cond_unmask_irq(struct irq_desc *desc)
+ {
+       /*
+        * We need to unmask in the following cases:
+        * - Standard level irq (IRQF_ONESHOT is not set)
+        * - Oneshot irq which did not wake the thread (caused by a
+        *   spurious interrupt or a primary handler handling it
+        *   completely).
+        */
+       if (!irqd_irq_disabled(&desc->irq_data) &&
+           irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot)
+               unmask_irq(desc);
+ }
  /**
   *    handle_level_irq - Level type irq handler
   *    @irq:   the interrupt number
@@@ -361,8 -383,8 +382,8 @@@ handle_level_irq(unsigned int irq, stru
  
        handle_irq_event(desc);
  
-       if (!irqd_irq_disabled(&desc->irq_data) && !(desc->istate & IRQS_ONESHOT))
-               unmask_irq(desc);
+       cond_unmask_irq(desc);
  out_unlock:
        raw_spin_unlock(&desc->lock);
  }
@@@ -416,6 -438,9 +437,9 @@@ handle_fasteoi_irq(unsigned int irq, st
        preflow_handler(desc);
        handle_irq_event(desc);
  
+       if (desc->istate & IRQS_ONESHOT)
+               cond_unmask_irq(desc);
  out_eoi:
        desc->irq_data.chip->irq_eoi(&desc->irq_data);
  out_unlock:
@@@ -624,7 -649,7 +648,7 @@@ __irq_set_handler(unsigned int irq, irq
                irq_settings_set_noprobe(desc);
                irq_settings_set_norequest(desc);
                irq_settings_set_nothread(desc);
-               irq_startup(desc);
+               irq_startup(desc, true);
        }
  out:
        irq_put_desc_busunlock(desc, flags);
diff --combined kernel/irq/internals.h
@@@ -20,12 -20,14 +20,12 @@@ extern bool noirqdebug
  /*
   * Bits used by threaded handlers:
   * IRQTF_RUNTHREAD - signals that the interrupt handler thread should run
 - * IRQTF_DIED      - handler thread died
   * IRQTF_WARNED    - warning "IRQ_WAKE_THREAD w/o thread_fn" has been printed
   * IRQTF_AFFINITY  - irq thread is requested to adjust affinity
   * IRQTF_FORCED_THREAD  - irq action is force threaded
   */
  enum {
        IRQTF_RUNTHREAD,
 -      IRQTF_DIED,
        IRQTF_WARNED,
        IRQTF_AFFINITY,
        IRQTF_FORCED_THREAD,
@@@ -65,7 -67,7 +65,7 @@@ extern int __irq_set_trigger(struct irq
  extern void __disable_irq(struct irq_desc *desc, unsigned int irq, bool susp);
  extern void __enable_irq(struct irq_desc *desc, unsigned int irq, bool resume);
  
- extern int irq_startup(struct irq_desc *desc);
+ extern int irq_startup(struct irq_desc *desc, bool resend);
  extern void irq_shutdown(struct irq_desc *desc);
  extern void irq_enable(struct irq_desc *desc);
  extern void irq_disable(struct irq_desc *desc);
diff --combined kernel/irq/manage.c
@@@ -773,14 -773,14 +773,14 @@@ static int irq_thread(void *data
                        struct irqaction *action);
        int wake;
  
 -      if (force_irqthreads & test_bit(IRQTF_FORCED_THREAD,
 +      if (force_irqthreads && test_bit(IRQTF_FORCED_THREAD,
                                        &action->thread_flags))
                handler_fn = irq_forced_thread_fn;
        else
                handler_fn = irq_thread_fn;
  
        sched_setscheduler(current, SCHED_FIFO, &param);
 -      current->irqaction = action;
 +      current->irq_thread = 1;
  
        while (!irq_wait_for_interrupt(action)) {
  
        irq_finalize_oneshot(desc, action, true);
  
        /*
 -       * Clear irqaction. Otherwise exit_irq_thread() would make
 +       * Clear irq_thread. Otherwise exit_irq_thread() would make
         * fuzz about an active irq thread going into nirvana.
         */
 -      current->irqaction = NULL;
 +      current->irq_thread = 0;
        return 0;
  }
  
@@@ -832,21 -832,27 +832,21 @@@ void exit_irq_thread(void
  {
        struct task_struct *tsk = current;
        struct irq_desc *desc;
 +      struct irqaction *action;
  
 -      if (!tsk->irqaction)
 +      if (!tsk->irq_thread)
                return;
  
 +      action = kthread_data(tsk);
 +
        printk(KERN_ERR
               "exiting task \"%s\" (%d) is an active IRQ thread (irq %d)\n",
 -             tsk->comm ? tsk->comm : "", tsk->pid, tsk->irqaction->irq);
 -
 -      desc = irq_to_desc(tsk->irqaction->irq);
 +             tsk->comm ? tsk->comm : "", tsk->pid, action->irq);
  
 -      /*
 -       * Prevent a stale desc->threads_oneshot. Must be called
 -       * before setting the IRQTF_DIED flag.
 -       */
 -      irq_finalize_oneshot(desc, tsk->irqaction, true);
 +      desc = irq_to_desc(action->irq);
  
 -      /*
 -       * Set the THREAD DIED flag to prevent further wakeups of the
 -       * soon to be gone threaded handler.
 -       */
 -      set_bit(IRQTF_DIED, &tsk->irqaction->flags);
 +      /* Prevent a stale desc->threads_oneshot */
 +      irq_finalize_oneshot(desc, action, true);
  }
  
  static void irq_setup_forced_threading(struct irqaction *new)
@@@ -979,6 -985,11 +979,11 @@@ __setup_irq(unsigned int irq, struct ir
  
                /* add new interrupt at end of irq queue */
                do {
+                       /*
+                        * Or all existing action->thread_mask bits,
+                        * so we can find the next zero bit for this
+                        * new action.
+                        */
                        thread_mask |= old->thread_mask;
                        old_ptr = &old->next;
                        old = *old_ptr;
        }
  
        /*
-        * Setup the thread mask for this irqaction. Unlikely to have
-        * 32 resp 64 irqs sharing one line, but who knows.
+        * Setup the thread mask for this irqaction for ONESHOT. For
+        * !ONESHOT irqs the thread mask is 0 so we can avoid a
+        * conditional in irq_wake_thread().
         */
-       if (new->flags & IRQF_ONESHOT && thread_mask == ~0UL) {
-               ret = -EBUSY;
-               goto out_mask;
+       if (new->flags & IRQF_ONESHOT) {
+               /*
+                * Unlikely to have 32 resp 64 irqs sharing one line,
+                * but who knows.
+                */
+               if (thread_mask == ~0UL) {
+                       ret = -EBUSY;
+                       goto out_mask;
+               }
+               /*
+                * The thread_mask for the action is or'ed to
+                * desc->thread_active to indicate that the
+                * IRQF_ONESHOT thread handler has been woken, but not
+                * yet finished. The bit is cleared when a thread
+                * completes. When all threads of a shared interrupt
+                * line have completed desc->threads_active becomes
+                * zero and the interrupt line is unmasked. See
+                * handle.c:irq_wake_thread() for further information.
+                *
+                * If no thread is woken by primary (hard irq context)
+                * interrupt handlers, then desc->threads_active is
+                * also checked for zero to unmask the irq line in the
+                * affected hard irq flow handlers
+                * (handle_[fasteoi|level]_irq).
+                *
+                * The new action gets the first zero bit of
+                * thread_mask assigned. See the loop above which or's
+                * all existing action->thread_mask bits.
+                */
+               new->thread_mask = 1 << ffz(thread_mask);
        }
-       new->thread_mask = 1 << ffz(thread_mask);
  
        if (!shared) {
                init_waitqueue_head(&desc->wait_for_threads);
                        desc->istate |= IRQS_ONESHOT;
  
                if (irq_settings_can_autoenable(desc))
-                       irq_startup(desc);
+                       irq_startup(desc, true);
                else
                        /* Undo nested disables: */
                        desc->depth = 1;
@@@ -1097,7 -1135,8 +1129,7 @@@ out_thread
                struct task_struct *t = new->thread;
  
                new->thread = NULL;
 -              if (likely(!test_bit(IRQTF_DIED, &new->thread_flags)))
 -                      kthread_stop(t);
 +              kthread_stop(t);
                put_task_struct(t);
        }
  out_mput:
@@@ -1207,7 -1246,8 +1239,7 @@@ static struct irqaction *__free_irq(uns
  #endif
  
        if (action->thread) {
 -              if (!test_bit(IRQTF_DIED, &action->thread_flags))
 -                      kthread_stop(action->thread);
 +              kthread_stop(action->thread);
                put_task_struct(action->thread);
        }