]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge remote-tracking branch 'workqueues/for-next'
authorThierry Reding <treding@nvidia.com>
Thu, 24 Oct 2013 12:58:53 +0000 (14:58 +0200)
committerThierry Reding <treding@nvidia.com>
Thu, 24 Oct 2013 12:58:53 +0000 (14:58 +0200)
1  2 
kernel/workqueue.c

diff --combined kernel/workqueue.c
index 987293d03ebcf0e6bf1c6b81e8a4e68c7965e903,6b71a21c3a4e45cb56cee2c3d47fabbb1193dba2..98a937eb9f7add1f03f0d16403cee0b9c50319d7
@@@ -305,6 -305,9 +305,9 @@@ static DEFINE_HASHTABLE(unbound_pool_ha
  /* I: attributes used when instantiating standard unbound pools on demand */
  static struct workqueue_attrs *unbound_std_wq_attrs[NR_STD_WORKER_POOLS];
  
+ /* I: attributes used when instantiating ordered pools on demand */
+ static struct workqueue_attrs *ordered_wq_attrs[NR_STD_WORKER_POOLS];
  struct workqueue_struct *system_wq __read_mostly;
  EXPORT_SYMBOL(system_wq);
  struct workqueue_struct *system_highpri_wq __read_mostly;
@@@ -518,14 -521,21 +521,21 @@@ static inline void debug_work_activate(
  static inline void debug_work_deactivate(struct work_struct *work) { }
  #endif
  
- /* allocate ID and assign it to @pool */
+ /**
+  * worker_pool_assign_id - allocate ID and assing it to @pool
+  * @pool: the pool pointer of interest
+  *
+  * Returns 0 if ID in [0, WORK_OFFQ_POOL_NONE) is allocated and assigned
+  * successfully, -errno on failure.
+  */
  static int worker_pool_assign_id(struct worker_pool *pool)
  {
        int ret;
  
        lockdep_assert_held(&wq_pool_mutex);
  
-       ret = idr_alloc(&worker_pool_idr, pool, 0, 0, GFP_KERNEL);
+       ret = idr_alloc(&worker_pool_idr, pool, 0, WORK_OFFQ_POOL_NONE,
+                       GFP_KERNEL);
        if (ret >= 0) {
                pool->id = ret;
                return 0;
   * This must be called either with pwq_lock held or sched RCU read locked.
   * If the pwq needs to be used beyond the locking in effect, the caller is
   * responsible for guaranteeing that the pwq stays online.
 + *
 + * Return: The unbound pool_workqueue for @node.
   */
  static struct pool_workqueue *unbound_pwq_by_node(struct workqueue_struct *wq,
                                                  int node)
@@@ -641,6 -649,8 +651,6 @@@ static struct pool_workqueue *get_work_
   * get_work_pool - return the worker_pool a given work was associated with
   * @work: the work item of interest
   *
 - * Return the worker_pool @work was last associated with.  %NULL if none.
 - *
   * Pools are created and destroyed under wq_pool_mutex, and allows read
   * access under sched-RCU read lock.  As such, this function should be
   * called under wq_pool_mutex or with preemption disabled.
   * mentioned locking is in effect.  If the returned pool needs to be used
   * beyond the critical section, the caller is responsible for ensuring the
   * returned pool is and stays online.
 + *
 + * Return: The worker_pool @work was last associated with.  %NULL if none.
   */
  static struct worker_pool *get_work_pool(struct work_struct *work)
  {
   * get_work_pool_id - return the worker pool ID a given work is associated with
   * @work: the work item of interest
   *
 - * Return the worker_pool ID @work was last associated with.
 + * Return: The worker_pool ID @work was last associated with.
   * %WORK_OFFQ_POOL_NONE if none.
   */
  static int get_work_pool_id(struct work_struct *work)
@@@ -833,7 -841,7 +843,7 @@@ void wq_worker_waking_up(struct task_st
   * CONTEXT:
   * spin_lock_irq(rq->lock)
   *
 - * RETURNS:
 + * Return:
   * Worker task on @cpu to wake up, %NULL if none.
   */
  struct task_struct *wq_worker_sleeping(struct task_struct *task, int cpu)
@@@ -968,8 -976,8 +978,8 @@@ static inline void worker_clr_flags(str
   * CONTEXT:
   * spin_lock_irq(pool->lock).
   *
 - * RETURNS:
 - * Pointer to worker which is executing @work if found, NULL
 + * Return:
 + * Pointer to worker which is executing @work if found, %NULL
   * otherwise.
   */
  static struct worker *find_worker_executing_work(struct worker_pool *pool,
@@@ -1157,16 -1165,14 +1167,16 @@@ out_put
   * @flags: place to store irq state
   *
   * Try to grab PENDING bit of @work.  This function can handle @work in any
 - * stable state - idle, on timer or on worklist.  Return values are
 + * stable state - idle, on timer or on worklist.
   *
 + * Return:
   *  1         if @work was pending and we successfully stole PENDING
   *  0         if @work was idle and we claimed PENDING
   *  -EAGAIN   if PENDING couldn't be grabbed at the moment, safe to busy-retry
   *  -ENOENT   if someone else is canceling @work, this state may persist
   *            for arbitrarily long
   *
 + * Note:
   * On >= 0 return, the caller owns @work's PENDING bit.  To avoid getting
   * interrupted while holding PENDING and @work off queue, irq must be
   * disabled on entry.  This, combined with delayed_work->timer being
@@@ -1320,7 -1326,7 +1330,7 @@@ static void __queue_work(int cpu, struc
  
        debug_work_activate(work);
  
-       /* if dying, only works from the same workqueue are allowed */
+       /* if draining, only works from the same workqueue are allowed */
        if (unlikely(wq->flags & __WQ_DRAINING) &&
            WARN_ON_ONCE(!is_chained_work(wq)))
                return;
@@@ -1408,10 -1414,10 +1418,10 @@@ retry
   * @wq: workqueue to use
   * @work: work to queue
   *
 - * Returns %false if @work was already on a queue, %true otherwise.
 - *
   * We queue the work to a specific CPU, the caller must ensure it
   * can't go away.
 + *
 + * Return: %false if @work was already on a queue, %true otherwise.
   */
  bool queue_work_on(int cpu, struct workqueue_struct *wq,
                   struct work_struct *work)
@@@ -1481,7 -1487,7 +1491,7 @@@ static void __queue_delayed_work(int cp
   * @dwork: work to queue
   * @delay: number of jiffies to wait before queueing
   *
 - * Returns %false if @work was already on a queue, %true otherwise.  If
 + * Return: %false if @work was already on a queue, %true otherwise.  If
   * @delay is zero and @dwork is idle, it will be scheduled for immediate
   * execution.
   */
@@@ -1517,7 -1523,7 +1527,7 @@@ EXPORT_SYMBOL(queue_delayed_work_on)
   * zero, @work is guaranteed to be scheduled immediately regardless of its
   * current state.
   *
 - * Returns %false if @dwork was idle and queued, %true if @dwork was
 + * Return: %false if @dwork was idle and queued, %true if @dwork was
   * pending and its timer was modified.
   *
   * This function is safe to call from any context including IRQ handler.
@@@ -1632,7 -1638,7 +1642,7 @@@ static void worker_leave_idle(struct wo
   * Might sleep.  Called without any lock but returns with pool->lock
   * held.
   *
 - * RETURNS:
 + * Return:
   * %true if the associated pool is online (@worker is successfully
   * bound), %false if offline.
   */
@@@ -1693,7 -1699,7 +1703,7 @@@ static struct worker *alloc_worker(void
   * CONTEXT:
   * Might sleep.  Does GFP_KERNEL allocations.
   *
 - * RETURNS:
 + * Return:
   * Pointer to the newly created worker.
   */
  static struct worker *create_worker(struct worker_pool *pool)
@@@ -1793,8 -1799,6 +1803,8 @@@ static void start_worker(struct worker 
   * @pool: the target pool
   *
   * Grab the managership of @pool and create and start a new worker for it.
 + *
 + * Return: 0 on success. A negative error code otherwise.
   */
  static int create_and_start_worker(struct worker_pool *pool)
  {
@@@ -1939,7 -1943,7 +1949,7 @@@ static void pool_mayday_timeout(unsigne
   * multiple times.  Does GFP_KERNEL allocations.  Called only from
   * manager.
   *
 - * RETURNS:
 + * Return:
   * %false if no action was taken and pool->lock stayed locked, %true
   * otherwise.
   */
@@@ -1996,7 -2000,7 +2006,7 @@@ restart
   * spin_lock_irq(pool->lock) which may be released and regrabbed
   * multiple times.  Called only from manager.
   *
 - * RETURNS:
 + * Return:
   * %false if no action was taken and pool->lock stayed locked, %true
   * otherwise.
   */
@@@ -2039,7 -2043,7 +2049,7 @@@ static bool maybe_destroy_workers(struc
   * spin_lock_irq(pool->lock) which may be released and regrabbed
   * multiple times.  Does GFP_KERNEL allocations.
   *
 - * RETURNS:
 + * Return:
   * %false if the pool don't need management and the caller can safely start
   * processing works, %true indicates that the function released pool->lock
   * and reacquired it to perform some management function and that the
@@@ -2265,8 -2269,6 +2275,8 @@@ static void process_scheduled_works(str
   * work items regardless of their specific target workqueue.  The only
   * exception is work items which belong to workqueues with a rescuer which
   * will be explained in rescuer_thread().
 + *
 + * Return: 0
   */
  static int worker_thread(void *__worker)
  {
@@@ -2365,8 -2367,6 +2375,8 @@@ sleep
   * those works so that forward progress can be guaranteed.
   *
   * This should happen rarely.
 + *
 + * Return: 0
   */
  static int rescuer_thread(void *__rescuer)
  {
@@@ -2539,7 -2539,7 +2549,7 @@@ static void insert_wq_barrier(struct po
   * CONTEXT:
   * mutex_lock(wq->mutex).
   *
 - * RETURNS:
 + * Return:
   * %true if @flush_color >= 0 and there's something to flush.  %false
   * otherwise.
   */
@@@ -2860,7 -2860,7 +2870,7 @@@ static bool __flush_work(struct work_st
   * Wait until @work has finished execution.  @work is guaranteed to be idle
   * on return if it hasn't been requeued since flush started.
   *
 - * RETURNS:
 + * Return:
   * %true if flush_work() waited for the work to finish execution,
   * %false if it was already idle.
   */
@@@ -2912,7 -2912,7 +2922,7 @@@ static bool __cancel_work_timer(struct 
   * The caller must ensure that the workqueue on which @work was last
   * queued can't be destroyed before this function returns.
   *
 - * RETURNS:
 + * Return:
   * %true if @work was pending, %false otherwise.
   */
  bool cancel_work_sync(struct work_struct *work)
@@@ -2929,7 -2929,7 +2939,7 @@@ EXPORT_SYMBOL_GPL(cancel_work_sync)
   * immediate execution.  Like flush_work(), this function only
   * considers the last queueing instance of @dwork.
   *
 - * RETURNS:
 + * Return:
   * %true if flush_work() waited for the work to finish execution,
   * %false if it was already idle.
   */
@@@ -2947,15 -2947,11 +2957,15 @@@ EXPORT_SYMBOL(flush_delayed_work)
   * cancel_delayed_work - cancel a delayed work
   * @dwork: delayed_work to cancel
   *
 - * Kill off a pending delayed_work.  Returns %true if @dwork was pending
 - * and canceled; %false if wasn't pending.  Note that the work callback
 - * function may still be running on return, unless it returns %true and the
 - * work doesn't re-arm itself.  Explicitly flush or use
 - * cancel_delayed_work_sync() to wait on it.
 + * Kill off a pending delayed_work.
 + *
 + * Return: %true if @dwork was pending and canceled; %false if it wasn't
 + * pending.
 + *
 + * Note:
 + * The work callback function may still be running on return, unless
 + * it returns %true and the work doesn't re-arm itself.  Explicitly flush or
 + * use cancel_delayed_work_sync() to wait on it.
   *
   * This function is safe to call from any context including IRQ handler.
   */
@@@ -2984,7 -2980,7 +2994,7 @@@ EXPORT_SYMBOL(cancel_delayed_work)
   *
   * This is cancel_work_sync() for delayed works.
   *
 - * RETURNS:
 + * Return:
   * %true if @dwork was pending, %false otherwise.
   */
  bool cancel_delayed_work_sync(struct delayed_work *dwork)
@@@ -3001,7 -2997,7 +3011,7 @@@ EXPORT_SYMBOL(cancel_delayed_work_sync)
   * system workqueue and blocks until all CPUs have completed.
   * schedule_on_each_cpu() is very slow.
   *
 - * RETURNS:
 + * Return:
   * 0 on success, -errno on failure.
   */
  int schedule_on_each_cpu(work_func_t func)
@@@ -3069,7 -3065,7 +3079,7 @@@ EXPORT_SYMBOL(flush_scheduled_work)
   * Executes the function immediately if process context is available,
   * otherwise schedules the function for delayed execution.
   *
 - * Returns:   0 - function was executed
 + * Return   0 - function was executed
   *            1 - function was scheduled for execution
   */
  int execute_in_process_context(work_func_t fn, struct execute_work *ew)
@@@ -3329,7 -3325,7 +3339,7 @@@ static void wq_device_release(struct de
   * apply_workqueue_attrs() may race against userland updating the
   * attributes.
   *
 - * Returns 0 on success, -errno on failure.
 + * Return: 0 on success, -errno on failure.
   */
  int workqueue_sysfs_register(struct workqueue_struct *wq)
  {
@@@ -3422,9 -3418,7 +3432,9 @@@ void free_workqueue_attrs(struct workqu
   * @gfp_mask: allocation mask to use
   *
   * Allocate a new workqueue_attrs, initialize with default settings and
 - * return it.  Returns NULL on failure.
 + * return it.
 + *
 + * Return: The allocated new workqueue_attr on success. %NULL on failure.
   */
  struct workqueue_attrs *alloc_workqueue_attrs(gfp_t gfp_mask)
  {
@@@ -3483,8 -3477,7 +3493,8 @@@ static bool wqattrs_equal(const struct 
   * @pool: worker_pool to initialize
   *
   * Initiailize a newly zalloc'd @pool.  It also allocates @pool->attrs.
 - * Returns 0 on success, -errno on failure.  Even on failure, all fields
 + *
 + * Return: 0 on success, -errno on failure.  Even on failure, all fields
   * inside @pool proper are initialized and put_unbound_pool() can be called
   * on @pool safely to release it.
   */
@@@ -3591,12 -3584,9 +3601,12 @@@ static void put_unbound_pool(struct wor
   * Obtain a worker_pool which has the same attributes as @attrs, bump the
   * reference count and return it.  If there already is a matching
   * worker_pool, it will be used; otherwise, this function attempts to
 - * create a new one.  On failure, returns NULL.
 + * create a new one.
   *
   * Should be called with wq_pool_mutex held.
 + *
 + * Return: On success, a worker_pool with the same attributes as @attrs.
 + * On failure, %NULL.
   */
  static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs)
  {
@@@ -3832,7 -3822,9 +3842,7 @@@ static void free_unbound_pwq(struct poo
   *
   * Calculate the cpumask a workqueue with @attrs should use on @node.  If
   * @cpu_going_down is >= 0, that cpu is considered offline during
 - * calculation.  The result is stored in @cpumask.  This function returns
 - * %true if the resulting @cpumask is different from @attrs->cpumask,
 - * %false if equal.
 + * calculation.  The result is stored in @cpumask.
   *
   * If NUMA affinity is not enabled, @attrs->cpumask is always used.  If
   * enabled and @node has online CPUs requested by @attrs, the returned
   *
   * The caller is responsible for ensuring that the cpumask of @node stays
   * stable.
 + *
 + * Return: %true if the resulting @cpumask is different from @attrs->cpumask,
 + * %false if equal.
   */
  static bool wq_calc_node_cpumask(const struct workqueue_attrs *attrs, int node,
                                 int cpu_going_down, cpumask_t *cpumask)
@@@ -3897,9 -3886,8 +3907,9 @@@ static struct pool_workqueue *numa_pwq_
   * items finish.  Note that a work item which repeatedly requeues itself
   * back-to-back will stay on its current pwq.
   *
 - * Performs GFP_KERNEL allocations.  Returns 0 on success and -errno on
 - * failure.
 + * Performs GFP_KERNEL allocations.
 + *
 + * Return: 0 on success and -errno on failure.
   */
  int apply_workqueue_attrs(struct workqueue_struct *wq,
                          const struct workqueue_attrs *attrs)
@@@ -4106,7 -4094,7 +4116,7 @@@ out_unlock
  static int alloc_and_link_pwqs(struct workqueue_struct *wq)
  {
        bool highpri = wq->flags & WQ_HIGHPRI;
-       int cpu;
+       int cpu, ret;
  
        if (!(wq->flags & WQ_UNBOUND)) {
                wq->cpu_pwqs = alloc_percpu(struct pool_workqueue);
                        mutex_unlock(&wq->mutex);
                }
                return 0;
+       } else if (wq->flags & __WQ_ORDERED) {
+               ret = apply_workqueue_attrs(wq, ordered_wq_attrs[highpri]);
+               /* there should only be single pwq for ordering guarantee */
+               WARN(!ret && (wq->pwqs.next != &wq->dfl_pwq->pwqs_node ||
+                             wq->pwqs.prev != &wq->dfl_pwq->pwqs_node),
+                    "ordering guarantee broken for workqueue %s\n", wq->name);
+               return ret;
        } else {
                return apply_workqueue_attrs(wq, unbound_std_wq_attrs[highpri]);
        }
@@@ -4367,8 -4362,6 +4384,8 @@@ EXPORT_SYMBOL_GPL(workqueue_set_max_act
   *
   * Determine whether %current is a workqueue rescuer.  Can be used from
   * work functions to determine whether it's being run off the rescuer task.
 + *
 + * Return: %true if %current is a workqueue rescuer. %false otherwise.
   */
  bool current_is_workqueue_rescuer(void)
  {
   * workqueue being congested on one CPU doesn't mean the workqueue is also
   * contested on other CPUs / NUMA nodes.
   *
 - * RETURNS:
 + * Return:
   * %true if congested, %false otherwise.
   */
  bool workqueue_congested(int cpu, struct workqueue_struct *wq)
@@@ -4425,7 -4418,7 +4442,7 @@@ EXPORT_SYMBOL_GPL(workqueue_congested)
   * synchronization around this function and the test result is
   * unreliable and only useful as advisory hints or for debugging.
   *
 - * RETURNS:
 + * Return:
   * OR'd bitmask of WORK_BUSY_* bits.
   */
  unsigned int work_busy(struct work_struct *work)
@@@ -4803,10 -4796,9 +4820,10 @@@ static void work_for_cpu_fn(struct work
   * @fn: the function to run
   * @arg: the function arg
   *
 - * This will return the value @fn returns.
   * It is up to the caller to ensure that the cpu doesn't go offline.
   * The caller must not hold any locks which would prevent @fn from completing.
 + *
 + * Return: The value @fn returns.
   */
  long work_on_cpu(int cpu, long (*fn)(void *), void *arg)
  {
@@@ -4878,7 -4870,7 +4895,7 @@@ void freeze_workqueues_begin(void
   * CONTEXT:
   * Grabs and releases wq_pool_mutex.
   *
 - * RETURNS:
 + * Return:
   * %true if some freezable workqueues are still busy.  %false if freezing
   * is complete.
   */
@@@ -5009,10 -5001,6 +5026,6 @@@ static int __init init_workqueues(void
        int std_nice[NR_STD_WORKER_POOLS] = { 0, HIGHPRI_NICE_LEVEL };
        int i, cpu;
  
-       /* make sure we have enough bits for OFFQ pool ID */
-       BUILD_BUG_ON((1LU << (BITS_PER_LONG - WORK_OFFQ_POOL_SHIFT)) <
-                    WORK_CPU_END * NR_STD_WORKER_POOLS);
        WARN_ON(__alignof__(struct pool_workqueue) < __alignof__(long long));
  
        pwq_cache = KMEM_CACHE(pool_workqueue, SLAB_PANIC);
                }
        }
  
-       /* create default unbound wq attrs */
+       /* create default unbound and ordered wq attrs */
        for (i = 0; i < NR_STD_WORKER_POOLS; i++) {
                struct workqueue_attrs *attrs;
  
                BUG_ON(!(attrs = alloc_workqueue_attrs(GFP_KERNEL)));
                attrs->nice = std_nice[i];
                unbound_std_wq_attrs[i] = attrs;
+               /*
+                * An ordered wq should have only one pwq as ordering is
+                * guaranteed by max_active which is enforced by pwqs.
+                * Turn off NUMA so that dfl_pwq is used for all nodes.
+                */
+               BUG_ON(!(attrs = alloc_workqueue_attrs(GFP_KERNEL)));
+               attrs->nice = std_nice[i];
+               attrs->no_numa = true;
+               ordered_wq_attrs[i] = attrs;
        }
  
        system_wq = alloc_workqueue("events", 0, 0);