OSDN Git Service

arch: remove tile port
[tomoyo/tomoyo-test1.git] / kernel / workqueue.c
index 43d18cb..bb9a519 100644 (file)
@@ -48,6 +48,7 @@
 #include <linux/moduleparam.h>
 #include <linux/uaccess.h>
 #include <linux/sched/isolation.h>
+#include <linux/nmi.h>
 
 #include "workqueue_internal.h"
 
@@ -2135,7 +2136,7 @@ __acquires(&pool->lock)
         * stop_machine. At the same time, report a quiescent RCU state so
         * the same condition doesn't freeze RCU.
         */
-       cond_resched_rcu_qs();
+       cond_resched();
 
        spin_lock_irq(&pool->lock);
 
@@ -3806,6 +3807,7 @@ int apply_workqueue_attrs(struct workqueue_struct *wq,
 
        return ret;
 }
+EXPORT_SYMBOL_GPL(apply_workqueue_attrs);
 
 /**
  * wq_update_unbound_numa - update NUMA affinity of a wq for CPU hot[un]plug
@@ -3939,6 +3941,37 @@ static int wq_clamp_max_active(int max_active, unsigned int flags,
        return clamp_val(max_active, 1, lim);
 }
 
+/*
+ * Workqueues which may be used during memory reclaim should have a rescuer
+ * to guarantee forward progress.
+ */
+static int init_rescuer(struct workqueue_struct *wq)
+{
+       struct worker *rescuer;
+       int ret;
+
+       if (!(wq->flags & WQ_MEM_RECLAIM))
+               return 0;
+
+       rescuer = alloc_worker(NUMA_NO_NODE);
+       if (!rescuer)
+               return -ENOMEM;
+
+       rescuer->rescue_wq = wq;
+       rescuer->task = kthread_create(rescuer_thread, rescuer, "%s", wq->name);
+       ret = PTR_ERR_OR_ZERO(rescuer->task);
+       if (ret) {
+               kfree(rescuer);
+               return ret;
+       }
+
+       wq->rescuer = rescuer;
+       kthread_bind_mask(rescuer->task, cpu_possible_mask);
+       wake_up_process(rescuer->task);
+
+       return 0;
+}
+
 struct workqueue_struct *__alloc_workqueue_key(const char *fmt,
                                               unsigned int flags,
                                               int max_active,
@@ -4001,29 +4034,8 @@ struct workqueue_struct *__alloc_workqueue_key(const char *fmt,
        if (alloc_and_link_pwqs(wq) < 0)
                goto err_free_wq;
 
-       /*
-        * Workqueues which may be used during memory reclaim should
-        * have a rescuer to guarantee forward progress.
-        */
-       if (flags & WQ_MEM_RECLAIM) {
-               struct worker *rescuer;
-
-               rescuer = alloc_worker(NUMA_NO_NODE);
-               if (!rescuer)
-                       goto err_destroy;
-
-               rescuer->rescue_wq = wq;
-               rescuer->task = kthread_create(rescuer_thread, rescuer, "%s",
-                                              wq->name);
-               if (IS_ERR(rescuer->task)) {
-                       kfree(rescuer);
-                       goto err_destroy;
-               }
-
-               wq->rescuer = rescuer;
-               kthread_bind_mask(rescuer->task, cpu_possible_mask);
-               wake_up_process(rescuer->task);
-       }
+       if (wq_online && init_rescuer(wq) < 0)
+               goto err_destroy;
 
        if ((wq->flags & WQ_SYSFS) && workqueue_sysfs_register(wq))
                goto err_destroy;
@@ -4168,6 +4180,22 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active)
 EXPORT_SYMBOL_GPL(workqueue_set_max_active);
 
 /**
+ * current_work - retrieve %current task's work struct
+ *
+ * Determine if %current task is a workqueue worker and what it's working on.
+ * Useful to find out the context that the %current task is running in.
+ *
+ * Return: work struct if %current task is a workqueue worker, %NULL otherwise.
+ */
+struct work_struct *current_work(void)
+{
+       struct worker *worker = current_wq_worker();
+
+       return worker ? worker->current_work : NULL;
+}
+EXPORT_SYMBOL(current_work);
+
+/**
  * current_is_workqueue_rescuer - is %current workqueue rescuer?
  *
  * Determine whether %current is a workqueue rescuer.  Can be used from
@@ -4463,6 +4491,12 @@ void show_workqueue_state(void)
                        if (pwq->nr_active || !list_empty(&pwq->delayed_works))
                                show_pwq(pwq);
                        spin_unlock_irqrestore(&pwq->pool->lock, flags);
+                       /*
+                        * We could be printing a lot from atomic context, e.g.
+                        * sysrq-t -> show_workqueue_state(). Avoid triggering
+                        * hard lockup.
+                        */
+                       touch_nmi_watchdog();
                }
        }
 
@@ -4490,6 +4524,12 @@ void show_workqueue_state(void)
                pr_cont("\n");
        next_pool:
                spin_unlock_irqrestore(&pool->lock, flags);
+               /*
+                * We could be printing a lot from atomic context, e.g.
+                * sysrq-t -> show_workqueue_state(). Avoid triggering
+                * hard lockup.
+                */
+               touch_nmi_watchdog();
        }
 
        rcu_read_unlock_sched();
@@ -5629,6 +5669,8 @@ int __init workqueue_init(void)
         * archs such as power and arm64.  As per-cpu pools created
         * previously could be missing node hint and unbound pools NUMA
         * affinity, fix them up.
+        *
+        * Also, while iterating workqueues, create rescuers if requested.
         */
        wq_numa_init();
 
@@ -5640,8 +5682,12 @@ int __init workqueue_init(void)
                }
        }
 
-       list_for_each_entry(wq, &workqueues, list)
+       list_for_each_entry(wq, &workqueues, list) {
                wq_update_unbound_numa(wq, smp_processor_id(), true);
+               WARN(init_rescuer(wq),
+                    "workqueue: failed to create early rescuer for %s",
+                    wq->name);
+       }
 
        mutex_unlock(&wq_pool_mutex);