History

workqueue: Use variable name irq_flags for saving local irq flags

Using the generic term `flags` for irq flags is conventional but can be confusing as there's quite a bit of code dealing with work flags which involves some subtleties. Let's use a more explicit name `irq_flags` for local irq flags. No functional changes.

Tejun Heo committed 2 years ago

Commit c26e2f21 parent cdc6e4b1 file · +38 −38Browse files

Showing the changes to kernel/workqueue.c (1 of 1 file). Show all

Unified · Split

kernel/workqueue.c+38−38
@@ -2029,7 +2029,7 @@ out_put: · 2028 unmodified lines
2029 * try_to_grab_pending - steal work item from worklist and disable irq2029 * try_to_grab_pending - steal work item from worklist and disable irq
2030 * @work: work item to steal2030 * @work: work item to steal
2031 * @is_dwork: @work is a delayed_work2031 * @is_dwork: @work is a delayed_work
2032 * @flags: place to store irq state2032 * @irq_flags: place to store irq state
2033 *2033 *
2034 * Try to grab PENDING bit of @work. This function can handle @work in any2034 * Try to grab PENDING bit of @work. This function can handle @work in any
2035 * stable state - idle, on timer or on worklist.2035 * stable state - idle, on timer or on worklist.
@@ -2051,17 +2051,17 @@ out_put: · 15 unmodified lines
2051 * irqsafe, ensures that we return -EAGAIN for finite short period of time.2051 * irqsafe, ensures that we return -EAGAIN for finite short period of time.
2052 *2052 *
2053 * On successful return, >= 0, irq is disabled and the caller is2053 * On successful return, >= 0, irq is disabled and the caller is
2054 * responsible for releasing it using local_irq_restore(*@flags).2054 * responsible for releasing it using local_irq_restore(*@irq_flags).
2055 *2055 *
2056 * This function is safe to call from any context including IRQ handler.2056 * This function is safe to call from any context including IRQ handler.
2057 */2057 */
2058static int try_to_grab_pending(struct work_struct *work, bool is_dwork,2058static int try_to_grab_pending(struct work_struct *work, bool is_dwork,
2059 unsigned long *flags)2059 unsigned long *irq_flags)
2060{2060{
2061 struct worker_pool *pool;2061 struct worker_pool *pool;
2062 struct pool_workqueue *pwq;2062 struct pool_workqueue *pwq;
2063 2063
2064 local_irq_save(*flags);2064 local_irq_save(*irq_flags);
2065 2065
2066 /* try to steal the timer if it exists */2066 /* try to steal the timer if it exists */
2067 if (is_dwork) {2067 if (is_dwork) {
@@ -2136,7 +2136,7 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork, · 68 unmodified lines
2136 raw_spin_unlock(&pool->lock);2136 raw_spin_unlock(&pool->lock);
2137fail:2137fail:
2138 rcu_read_unlock();2138 rcu_read_unlock();
2139 local_irq_restore(*flags);2139 local_irq_restore(*irq_flags);
2140 if (work_is_canceling(work))2140 if (work_is_canceling(work))
2141 return -ENOENT;2141 return -ENOENT;
2142 cpu_relax();2142 cpu_relax();
@@ -2344,16 +2344,16 @@ bool queue_work_on(int cpu, struct workqueue_struct *wq, · 201 unmodified lines
2344 struct work_struct *work)2344 struct work_struct *work)
2345{2345{
2346 bool ret = false;2346 bool ret = false;
2347 unsigned long flags;2347 unsigned long irq_flags;
2348 2348
2349 local_irq_save(flags);2349 local_irq_save(irq_flags);
2350 2350
2351 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {2351 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
2352 __queue_work(cpu, wq, work);2352 __queue_work(cpu, wq, work);
2353 ret = true;2353 ret = true;
2354 }2354 }
2355 2355
2356 local_irq_restore(flags);2356 local_irq_restore(irq_flags);
2357 return ret;2357 return ret;
2358}2358}
2359EXPORT_SYMBOL(queue_work_on);2359EXPORT_SYMBOL(queue_work_on);
@@ -2410,7 +2410,7 @@ static int select_numa_node_cpu(int node) · 50 unmodified lines
2410bool queue_work_node(int node, struct workqueue_struct *wq,2410bool queue_work_node(int node, struct workqueue_struct *wq,
2411 struct work_struct *work)2411 struct work_struct *work)
2412{2412{
2413 unsigned long flags;2413 unsigned long irq_flags;
2414 bool ret = false;2414 bool ret = false;
2415 2415
2416 /*2416 /*
@@ -2424,7 +2424,7 @@ bool queue_work_node(int node, struct workqueue_struct *wq, · 7 unmodified lines
2424 */2424 */
2425 WARN_ON_ONCE(!(wq->flags & WQ_UNBOUND));2425 WARN_ON_ONCE(!(wq->flags & WQ_UNBOUND));
2426 2426
2427 local_irq_save(flags);2427 local_irq_save(irq_flags);
2428 2428
2429 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {2429 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
2430 int cpu = select_numa_node_cpu(node);2430 int cpu = select_numa_node_cpu(node);
@@ -2433,7 +2433,7 @@ bool queue_work_node(int node, struct workqueue_struct *wq, · 2 unmodified lines
2433 ret = true;2433 ret = true;
2434 }2434 }
2435 2435
2436 local_irq_restore(flags);2436 local_irq_restore(irq_flags);
2437 return ret;2437 return ret;
2438}2438}
2439EXPORT_SYMBOL_GPL(queue_work_node);2439EXPORT_SYMBOL_GPL(queue_work_node);
@@ -2503,17 +2503,17 @@ bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq, · 63 unmodified lines
2503{2503{
2504 struct work_struct *work = &dwork->work;2504 struct work_struct *work = &dwork->work;
2505 bool ret = false;2505 bool ret = false;
2506 unsigned long flags;2506 unsigned long irq_flags;
2507 2507
2508 /* read the comment in __queue_work() */2508 /* read the comment in __queue_work() */
2509 local_irq_save(flags);2509 local_irq_save(irq_flags);
2510 2510
2511 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {2511 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
2512 __queue_delayed_work(cpu, wq, dwork, delay);2512 __queue_delayed_work(cpu, wq, dwork, delay);
2513 ret = true;2513 ret = true;
2514 }2514 }
2515 2515
2516 local_irq_restore(flags);2516 local_irq_restore(irq_flags);
2517 return ret;2517 return ret;
2518}2518}
2519EXPORT_SYMBOL(queue_delayed_work_on);2519EXPORT_SYMBOL(queue_delayed_work_on);
@@ -2539,16 +2539,16 @@ EXPORT_SYMBOL(queue_delayed_work_on); · 19 unmodified lines
2539bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,2539bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq,
2540 struct delayed_work *dwork, unsigned long delay)2540 struct delayed_work *dwork, unsigned long delay)
2541{2541{
2542 unsigned long flags;2542 unsigned long irq_flags;
2543 int ret;2543 int ret;
2544 2544
2545 do {2545 do {
2546 ret = try_to_grab_pending(&dwork->work, true, &flags);2546 ret = try_to_grab_pending(&dwork->work, true, &irq_flags);
2547 } while (unlikely(ret == -EAGAIN));2547 } while (unlikely(ret == -EAGAIN));
2548 2548
2549 if (likely(ret >= 0)) {2549 if (likely(ret >= 0)) {
2550 __queue_delayed_work(cpu, wq, dwork, delay);2550 __queue_delayed_work(cpu, wq, dwork, delay);
2551 local_irq_restore(flags);2551 local_irq_restore(irq_flags);
2552 }2552 }
2553 2553
2554 /* -ENOENT from try_to_grab_pending() becomes %true */2554 /* -ENOENT from try_to_grab_pending() becomes %true */
@@ -4105,18 +4105,18 @@ EXPORT_SYMBOL(flush_rcu_work); · 1550 unmodified lines
4105 4105
4106static bool __cancel_work(struct work_struct *work, bool is_dwork)4106static bool __cancel_work(struct work_struct *work, bool is_dwork)
4107{4107{
4108 unsigned long flags;4108 unsigned long irq_flags;
4109 int ret;4109 int ret;
4110 4110
4111 do {4111 do {
4112 ret = try_to_grab_pending(work, is_dwork, &flags);4112 ret = try_to_grab_pending(work, is_dwork, &irq_flags);
4113 } while (unlikely(ret == -EAGAIN));4113 } while (unlikely(ret == -EAGAIN));
4114 4114
4115 if (unlikely(ret < 0))4115 if (unlikely(ret < 0))
4116 return false;4116 return false;
4117 4117
4118 set_work_pool_and_clear_pending(work, get_work_pool_id(work));4118 set_work_pool_and_clear_pending(work, get_work_pool_id(work));
4119 local_irq_restore(flags);4119 local_irq_restore(irq_flags);
4120 return ret;4120 return ret;
4121}4121}
4122 4122
@@ -4137,11 +4137,11 @@ static int cwt_wakefn(wait_queue_entry_t *wait, unsigned mode, int sync, void *k · 14 unmodified lines
4137static bool __cancel_work_sync(struct work_struct *work, bool is_dwork)4137static bool __cancel_work_sync(struct work_struct *work, bool is_dwork)
4138{4138{
4139 static DECLARE_WAIT_QUEUE_HEAD(cancel_waitq);4139 static DECLARE_WAIT_QUEUE_HEAD(cancel_waitq);
4140 unsigned long flags;4140 unsigned long irq_flags;
4141 int ret;4141 int ret;
4142 4142
4143 do {4143 do {
4144 ret = try_to_grab_pending(work, is_dwork, &flags);4144 ret = try_to_grab_pending(work, is_dwork, &irq_flags);
4145 /*4145 /*
4146 * If someone else is already canceling, wait for it to4146 * If someone else is already canceling, wait for it to
4147 * finish. flush_work() doesn't work for PREEMPT_NONE4147 * finish. flush_work() doesn't work for PREEMPT_NONE
@@ -4175,7 +4175,7 @@ static bool __cancel_work_sync(struct work_struct *work, bool is_dwork) · 27 unmodified lines
4175 4175
4176 /* tell other tasks trying to grab @work to back off */4176 /* tell other tasks trying to grab @work to back off */
4177 mark_work_canceling(work);4177 mark_work_canceling(work);
4178 local_irq_restore(flags);4178 local_irq_restore(irq_flags);
4179 4179
4180 /*4180 /*
4181 * Skip __flush_work() during early boot when we know that @work isn't4181 * Skip __flush_work() during early boot when we know that @work isn't
@@ -5381,15 +5381,15 @@ static void wq_adjust_max_active(struct workqueue_struct *wq) · 1199 unmodified lines
5381 5381
5382 activated = false;5382 activated = false;
5383 for_each_pwq(pwq, wq) {5383 for_each_pwq(pwq, wq) {
5384 unsigned long flags;5384 unsigned long irq_flags;
5385 5385
5386 /* can be called during early boot w/ irq disabled */5386 /* can be called during early boot w/ irq disabled */
5387 raw_spin_lock_irqsave(&pwq->pool->lock, flags);5387 raw_spin_lock_irqsave(&pwq->pool->lock, irq_flags);
5388 if (pwq_activate_first_inactive(pwq, true)) {5388 if (pwq_activate_first_inactive(pwq, true)) {
5389 activated = true;5389 activated = true;
5390 kick_pool(pwq->pool);5390 kick_pool(pwq->pool);
5391 }5391 }
5392 raw_spin_unlock_irqrestore(&pwq->pool->lock, flags);5392 raw_spin_unlock_irqrestore(&pwq->pool->lock, irq_flags);
5393 }5393 }
5394 } while (activated);5394 } while (activated);
5395}5395}
@@ -5762,7 +5762,7 @@ EXPORT_SYMBOL_GPL(workqueue_congested); · 366 unmodified lines
5762unsigned int work_busy(struct work_struct *work)5762unsigned int work_busy(struct work_struct *work)
5763{5763{
5764 struct worker_pool *pool;5764 struct worker_pool *pool;
5765 unsigned long flags;5765 unsigned long irq_flags;
5766 unsigned int ret = 0;5766 unsigned int ret = 0;
5767 5767
5768 if (work_pending(work))5768 if (work_pending(work))
@@ -5771,10 +5771,10 @@ unsigned int work_busy(struct work_struct *work) · 2 unmodified lines
5771 rcu_read_lock();5771 rcu_read_lock();
5772 pool = get_work_pool(work);5772 pool = get_work_pool(work);
5773 if (pool) {5773 if (pool) {
5774 raw_spin_lock_irqsave(&pool->lock, flags);5774 raw_spin_lock_irqsave(&pool->lock, irq_flags);
5775 if (find_worker_executing_work(pool, work))5775 if (find_worker_executing_work(pool, work))
5776 ret |= WORK_BUSY_RUNNING;5776 ret |= WORK_BUSY_RUNNING;
5777 raw_spin_unlock_irqrestore(&pool->lock, flags);5777 raw_spin_unlock_irqrestore(&pool->lock, irq_flags);
5778 }5778 }
5779 rcu_read_unlock();5779 rcu_read_unlock();
5780 5780
@@ -6006,7 +6006,7 @@ void show_one_workqueue(struct workqueue_struct *wq) · 225 unmodified lines
6006{6006{
6007 struct pool_workqueue *pwq;6007 struct pool_workqueue *pwq;
6008 bool idle = true;6008 bool idle = true;
6009 unsigned long flags;6009 unsigned long irq_flags;
6010 6010
6011 for_each_pwq(pwq, wq) {6011 for_each_pwq(pwq, wq) {
6012 if (!pwq_is_empty(pwq)) {6012 if (!pwq_is_empty(pwq)) {
@@ -6020,7 +6020,7 @@ void show_one_workqueue(struct workqueue_struct *wq) · 7 unmodified lines
6020 pr_info("workqueue %s: flags=0x%x\n", wq->name, wq->flags);6020 pr_info("workqueue %s: flags=0x%x\n", wq->name, wq->flags);
6021 6021
6022 for_each_pwq(pwq, wq) {6022 for_each_pwq(pwq, wq) {
6023 raw_spin_lock_irqsave(&pwq->pool->lock, flags);6023 raw_spin_lock_irqsave(&pwq->pool->lock, irq_flags);
6024 if (!pwq_is_empty(pwq)) {6024 if (!pwq_is_empty(pwq)) {
6025 /*6025 /*
6026 * Defer printing to avoid deadlocks in console6026 * Defer printing to avoid deadlocks in console
@@ -6031,7 +6031,7 @@ void show_one_workqueue(struct workqueue_struct *wq) · 4 unmodified lines
6031 show_pwq(pwq);6031 show_pwq(pwq);
6032 printk_deferred_exit();6032 printk_deferred_exit();
6033 }6033 }
6034 raw_spin_unlock_irqrestore(&pwq->pool->lock, flags);6034 raw_spin_unlock_irqrestore(&pwq->pool->lock, irq_flags);
6035 /*6035 /*
6036 * We could be printing a lot from atomic context, e.g.6036 * We could be printing a lot from atomic context, e.g.
6037 * sysrq-t -> show_all_workqueues(). Avoid triggering6037 * sysrq-t -> show_all_workqueues(). Avoid triggering
@@ -6050,10 +6050,10 @@ static void show_one_worker_pool(struct worker_pool *pool) · 12 unmodified lines
6050{6050{
6051 struct worker *worker;6051 struct worker *worker;
6052 bool first = true;6052 bool first = true;
6053 unsigned long flags;6053 unsigned long irq_flags;
6054 unsigned long hung = 0;6054 unsigned long hung = 0;
6055 6055
6056 raw_spin_lock_irqsave(&pool->lock, flags);6056 raw_spin_lock_irqsave(&pool->lock, irq_flags);
6057 if (pool->nr_workers == pool->nr_idle)6057 if (pool->nr_workers == pool->nr_idle)
6058 goto next_pool;6058 goto next_pool;
6059 6059
@@ -6081,7 +6081,7 @@ static void show_one_worker_pool(struct worker_pool *pool) · 21 unmodified lines
6081 pr_cont("\n");6081 pr_cont("\n");
6082 printk_deferred_exit();6082 printk_deferred_exit();
6083next_pool:6083next_pool:
6084 raw_spin_unlock_irqrestore(&pool->lock, flags);6084 raw_spin_unlock_irqrestore(&pool->lock, irq_flags);
6085 /*6085 /*
6086 * We could be printing a lot from atomic context, e.g.6086 * We could be printing a lot from atomic context, e.g.
6087 * sysrq-t -> show_all_workqueues(). Avoid triggering6087 * sysrq-t -> show_all_workqueues(). Avoid triggering
@@ -7212,10 +7212,10 @@ static DEFINE_PER_CPU(unsigned long, wq_watchdog_touched_cpu) = INITIAL_JIFFIES; · 1124 unmodified lines
7212static void show_cpu_pool_hog(struct worker_pool *pool)7212static void show_cpu_pool_hog(struct worker_pool *pool)
7213{7213{
7214 struct worker *worker;7214 struct worker *worker;
7215 unsigned long flags;7215 unsigned long irq_flags;
7216 int bkt;7216 int bkt;
7217 7217
7218 raw_spin_lock_irqsave(&pool->lock, flags);7218 raw_spin_lock_irqsave(&pool->lock, irq_flags);
7219 7219
7220 hash_for_each(pool->busy_hash, bkt, worker, hentry) {7220 hash_for_each(pool->busy_hash, bkt, worker, hentry) {
7221 if (task_is_running(worker->task)) {7221 if (task_is_running(worker->task)) {
@@ -7233,7 +7233,7 @@ static void show_cpu_pool_hog(struct worker_pool *pool) · 11 unmodified lines
7233 }7233 }
7234 }7234 }
7235 7235
7236 raw_spin_unlock_irqrestore(&pool->lock, flags);7236 raw_spin_unlock_irqrestore(&pool->lock, irq_flags);
7237}7237}
7238 7238
7239static void show_cpu_pools_hogs(void)7239static void show_cpu_pools_hogs(void)