OSDN Git Service

Merge branches 'fixes' and 'ioremap' into for-linus
[uclinux-h8/linux.git] / kernel / workqueue.c
index 72c1adb..5243d4b 100644 (file)
@@ -337,8 +337,6 @@ struct workqueue_struct *system_freezable_power_efficient_wq __read_mostly;
 EXPORT_SYMBOL_GPL(system_freezable_power_efficient_wq);
 
 static int worker_thread(void *__worker);
-static void copy_workqueue_attrs(struct workqueue_attrs *to,
-                                const struct workqueue_attrs *from);
 static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
 
 #define CREATE_TRACE_POINTS
@@ -990,7 +988,7 @@ static struct worker *find_worker_executing_work(struct worker_pool *pool,
  * move_linked_works - move linked works to a list
  * @work: start of series of works to be scheduled
  * @head: target list to append @work to
- * @nextp: out paramter for nested worklist walking
+ * @nextp: out parameter for nested worklist walking
  *
  * Schedule linked works starting from @work to @head.  Work series to
  * be scheduled starts at @work and includes any consecutive work with
@@ -2961,36 +2959,6 @@ int schedule_on_each_cpu(work_func_t func)
 }
 
 /**
- * flush_scheduled_work - ensure that any scheduled work has run to completion.
- *
- * Forces execution of the kernel-global workqueue and blocks until its
- * completion.
- *
- * Think twice before calling this function!  It's very easy to get into
- * trouble if you don't take great care.  Either of the following situations
- * will lead to deadlock:
- *
- *     One of the work items currently on the workqueue needs to acquire
- *     a lock held by your code or its caller.
- *
- *     Your code is running in the context of a work routine.
- *
- * They will be detected by lockdep when they occur, but the first might not
- * occur very often.  It depends on what work items are on the workqueue and
- * what locks they need, which you have no control over.
- *
- * In most situations flushing the entire workqueue is overkill; you merely
- * need to know that a particular work item isn't queued and isn't running.
- * In such cases you should use cancel_delayed_work_sync() or
- * cancel_work_sync() instead.
- */
-void flush_scheduled_work(void)
-{
-       flush_workqueue(system_wq);
-}
-EXPORT_SYMBOL(flush_scheduled_work);
-
-/**
  * execute_in_process_context - reliably execute the routine with user context
  * @fn:                the function to execute
  * @ew:                guaranteed storage for the execute work structure (must
@@ -3095,7 +3063,7 @@ static bool wqattrs_equal(const struct workqueue_attrs *a,
  * init_worker_pool - initialize a newly zalloc'd worker_pool
  * @pool: worker_pool to initialize
  *
- * Initiailize a newly zalloc'd @pool.  It also allocates @pool->attrs.
+ * Initialize a newly zalloc'd @pool.  It also allocates @pool->attrs.
  *
  * Return: 0 on success, -errno on failure.  Even on failure, all fields
  * inside @pool proper are initialized and put_unbound_pool() can be called
@@ -4446,7 +4414,7 @@ static void rebind_workers(struct worker_pool *pool)
        /*
         * Restore CPU affinity of all workers.  As all idle workers should
         * be on the run-queue of the associated CPU before any local
-        * wake-ups for concurrency management happen, restore CPU affinty
+        * wake-ups for concurrency management happen, restore CPU affinity
         * of all workers first and then clear UNBOUND.  As we're called
         * from CPU_ONLINE, the following shouldn't fail.
         */
@@ -4939,13 +4907,13 @@ static struct workqueue_attrs *wq_sysfs_prep_attrs(struct workqueue_struct *wq)
 {
        struct workqueue_attrs *attrs;
 
+       lockdep_assert_held(&wq_pool_mutex);
+
        attrs = alloc_workqueue_attrs(GFP_KERNEL);
        if (!attrs)
                return NULL;
 
-       mutex_lock(&wq->mutex);
        copy_workqueue_attrs(attrs, wq->unbound_attrs);
-       mutex_unlock(&wq->mutex);
        return attrs;
 }
 
@@ -4954,18 +4922,22 @@ static ssize_t wq_nice_store(struct device *dev, struct device_attribute *attr,
 {
        struct workqueue_struct *wq = dev_to_wq(dev);
        struct workqueue_attrs *attrs;
-       int ret;
+       int ret = -ENOMEM;
+
+       apply_wqattrs_lock();
 
        attrs = wq_sysfs_prep_attrs(wq);
        if (!attrs)
-               return -ENOMEM;
+               goto out_unlock;
 
        if (sscanf(buf, "%d", &attrs->nice) == 1 &&
            attrs->nice >= MIN_NICE && attrs->nice <= MAX_NICE)
-               ret = apply_workqueue_attrs(wq, attrs);
+               ret = apply_workqueue_attrs_locked(wq, attrs);
        else
                ret = -EINVAL;
 
+out_unlock:
+       apply_wqattrs_unlock();
        free_workqueue_attrs(attrs);
        return ret ?: count;
 }
@@ -4989,16 +4961,20 @@ static ssize_t wq_cpumask_store(struct device *dev,
 {
        struct workqueue_struct *wq = dev_to_wq(dev);
        struct workqueue_attrs *attrs;
-       int ret;
+       int ret = -ENOMEM;
+
+       apply_wqattrs_lock();
 
        attrs = wq_sysfs_prep_attrs(wq);
        if (!attrs)
-               return -ENOMEM;
+               goto out_unlock;
 
        ret = cpumask_parse(buf, attrs->cpumask);
        if (!ret)
-               ret = apply_workqueue_attrs(wq, attrs);
+               ret = apply_workqueue_attrs_locked(wq, attrs);
 
+out_unlock:
+       apply_wqattrs_unlock();
        free_workqueue_attrs(attrs);
        return ret ?: count;
 }
@@ -5022,18 +4998,22 @@ static ssize_t wq_numa_store(struct device *dev, struct device_attribute *attr,
 {
        struct workqueue_struct *wq = dev_to_wq(dev);
        struct workqueue_attrs *attrs;
-       int v, ret;
+       int v, ret = -ENOMEM;
+
+       apply_wqattrs_lock();
 
        attrs = wq_sysfs_prep_attrs(wq);
        if (!attrs)
-               return -ENOMEM;
+               goto out_unlock;
 
        ret = -EINVAL;
        if (sscanf(buf, "%d", &v) == 1) {
                attrs->no_numa = !v;
-               ret = apply_workqueue_attrs(wq, attrs);
+               ret = apply_workqueue_attrs_locked(wq, attrs);
        }
 
+out_unlock:
+       apply_wqattrs_unlock();
        free_workqueue_attrs(attrs);
        return ret ?: count;
 }
@@ -5125,7 +5105,7 @@ int workqueue_sysfs_register(struct workqueue_struct *wq)
        int ret;
 
        /*
-        * Adjusting max_active or creating new pwqs by applyting
+        * Adjusting max_active or creating new pwqs by applying
         * attributes breaks ordering guarantee.  Disallow exposing ordered
         * workqueues.
         */