powerpc/eeh: Single kthread to handle events
authorGavin Shan <shangw@linux.vnet.ibm.com>
Thu, 20 Jun 2013 05:21:00 +0000 (13:21 +0800)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Thu, 20 Jun 2013 07:06:01 +0000 (17:06 +1000)
We possiblly have multiple kthreads running for multiple EEH errors
(events) and use one spinlock to make the process of handling those
EEH events serialized. That's unnecessary and the patch creates only
one kthread, which is started during EEH core initialization time in
eeh_init(). A new semaphore introduced to count the number of existing
EEH events in the queue and the kthread waiting on the semaphore.

Signed-off-by: Gavin Shan <shangw@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/include/asm/eeh_event.h
arch/powerpc/kernel/eeh.c
arch/powerpc/kernel/eeh_event.c

index de67d830151be7f9cf3067a2a5768eeb48fed6af..de92c86221e7508df8a13d5ba44e18618a7f9fbd 100644 (file)
@@ -31,6 +31,7 @@ struct eeh_event {
        struct eeh_pe           *pe;    /* EEH PE               */
 };
 
+int eeh_event_init(void);
 int eeh_send_failure_event(struct eeh_pe *pe);
 void eeh_handle_event(struct eeh_pe *pe);
 
index 7d169d35b5b06b9cc6a7575e833f1cc37edf7fda..777ecc06af19f5595105d1cd3e410c28ae4c1bf2 100644 (file)
@@ -704,6 +704,11 @@ int __init eeh_init(void)
 
        raw_spin_lock_init(&confirm_error_lock);
 
+       /* Initialize EEH event */
+       ret = eeh_event_init();
+       if (ret)
+               return ret;
+
        /* Enable EEH for all adapters */
        if (eeh_probe_mode_devtree()) {
                list_for_each_entry_safe(hose, tmp,
index 185bedd926df7258bef7070d97c68f577bf91298..62e532ddfb68617bf8b206556523c1688913c11d 100644 (file)
 
 #include <linux/delay.h>
 #include <linux/list.h>
-#include <linux/mutex.h>
 #include <linux/sched.h>
+#include <linux/semaphore.h>
 #include <linux/pci.h>
 #include <linux/slab.h>
-#include <linux/workqueue.h>
 #include <linux/kthread.h>
 #include <asm/eeh_event.h>
 #include <asm/ppc-pci.h>
  *  work-queue, where a worker thread can drive recovery.
  */
 
-/* EEH event workqueue setup. */
 static DEFINE_SPINLOCK(eeh_eventlist_lock);
+static struct semaphore eeh_eventlist_sem;
 LIST_HEAD(eeh_eventlist);
-static void eeh_thread_launcher(struct work_struct *);
-DECLARE_WORK(eeh_event_wq, eeh_thread_launcher);
-
-/* Serialize reset sequences for a given pci device */
-DEFINE_MUTEX(eeh_event_mutex);
 
 /**
  * eeh_event_handler - Dispatch EEH events.
@@ -60,55 +54,62 @@ static int eeh_event_handler(void * dummy)
        struct eeh_event *event;
        struct eeh_pe *pe;
 
-       spin_lock_irqsave(&eeh_eventlist_lock, flags);
-       event = NULL;
-
-       /* Unqueue the event, get ready to process. */
-       if (!list_empty(&eeh_eventlist)) {
-               event = list_entry(eeh_eventlist.next, struct eeh_event, list);
-               list_del(&event->list);
-       }
-       spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
-
-       if (event == NULL)
-               return 0;
-
-       /* Serialize processing of EEH events */
-       mutex_lock(&eeh_event_mutex);
-       pe = event->pe;
-       eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
-       pr_info("EEH: Detected PCI bus error on PHB#%d-PE#%x\n",
-               pe->phb->global_number, pe->addr);
-
-       set_current_state(TASK_INTERRUPTIBLE);  /* Don't add to load average */
-       eeh_handle_event(pe);
-       eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
-
-       kfree(event);
-       mutex_unlock(&eeh_event_mutex);
-
-       /* If there are no new errors after an hour, clear the counter. */
-       if (pe && pe->freeze_count > 0) {
-               msleep_interruptible(3600*1000);
-               if (pe->freeze_count > 0)
-                       pe->freeze_count--;
-
+       while (!kthread_should_stop()) {
+               down(&eeh_eventlist_sem);
+
+               /* Fetch EEH event from the queue */
+               spin_lock_irqsave(&eeh_eventlist_lock, flags);
+               event = NULL;
+               if (!list_empty(&eeh_eventlist)) {
+                       event = list_entry(eeh_eventlist.next,
+                                          struct eeh_event, list);
+                       list_del(&event->list);
+               }
+               spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
+               if (!event)
+                       continue;
+
+               /* We might have event without binding PE */
+               pe = event->pe;
+               if (pe) {
+                       eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
+                       pr_info("EEH: Detected PCI bus error on PHB#%d-PE#%x\n",
+                                pe->phb->global_number, pe->addr);
+                       eeh_handle_event(pe);
+                       eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
+               } else {
+                       eeh_handle_event(NULL);
+               }
+
+               kfree(event);
        }
 
        return 0;
 }
 
 /**
- * eeh_thread_launcher - Start kernel thread to handle EEH events
- * @dummy - unused
+ * eeh_event_init - Start kernel thread to handle EEH events
  *
  * This routine is called to start the kernel thread for processing
  * EEH event.
  */
-static void eeh_thread_launcher(struct work_struct *dummy)
+int eeh_event_init(void)
 {
-       if (IS_ERR(kthread_run(eeh_event_handler, NULL, "eehd")))
-               printk(KERN_ERR "Failed to start EEH daemon\n");
+       struct task_struct *t;
+       int ret = 0;
+
+       /* Initialize semaphore */
+       sema_init(&eeh_eventlist_sem, 0);
+
+       t = kthread_run(eeh_event_handler, NULL, "eehd");
+       if (IS_ERR(t)) {
+               ret = PTR_ERR(t);
+               pr_err("%s: Failed to start EEH daemon (%d)\n",
+                       __func__, ret);
+               return ret;
+       }
+
+       return 0;
 }
 
 /**
@@ -136,7 +137,8 @@ int eeh_send_failure_event(struct eeh_pe *pe)
        list_add(&event->list, &eeh_eventlist);
        spin_unlock_irqrestore(&eeh_eventlist_lock, flags);
 
-       schedule_work(&eeh_event_wq);
+       /* For EEH deamon to knick in */
+       up(&eeh_eventlist_sem);
 
        return 0;
 }