Skip to content

Commit 4c63803

Browse files
committed
workqueue: Replace pwq_activate_inactive_work() with [__]pwq_activate_work()
To prepare for unbound nr_active handling improvements, move work activation part of pwq_activate_inactive_work() into __pwq_activate_work() and add pwq_activate_work() which tests WORK_STRUCT_INACTIVE and updates nr_active. pwq_activate_first_inactive() and try_to_grab_pending() are updated to use pwq_activate_work(). The latter conversion is functionally identical. For the former, this conversion adds an unnecessary WORK_STRUCT_INACTIVE testing. This is temporary and will be removed by the next patch. Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: Lai Jiangshan <jiangshanlai@gmail.com>
1 parent afa87ce commit 4c63803

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

kernel/workqueue.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,24 +1465,44 @@ static bool pwq_is_empty(struct pool_workqueue *pwq)
14651465
return !pwq->nr_active && list_empty(&pwq->inactive_works);
14661466
}
14671467

1468-
static void pwq_activate_inactive_work(struct work_struct *work)
1468+
static void __pwq_activate_work(struct pool_workqueue *pwq,
1469+
struct work_struct *work)
14691470
{
1470-
struct pool_workqueue *pwq = get_work_pwq(work);
1471-
14721471
trace_workqueue_activate_work(work);
14731472
if (list_empty(&pwq->pool->worklist))
14741473
pwq->pool->watchdog_ts = jiffies;
14751474
move_linked_works(work, &pwq->pool->worklist, NULL);
14761475
__clear_bit(WORK_STRUCT_INACTIVE_BIT, work_data_bits(work));
1476+
}
1477+
1478+
/**
1479+
* pwq_activate_work - Activate a work item if inactive
1480+
* @pwq: pool_workqueue @work belongs to
1481+
* @work: work item to activate
1482+
*
1483+
* Returns %true if activated. %false if already active.
1484+
*/
1485+
static bool pwq_activate_work(struct pool_workqueue *pwq,
1486+
struct work_struct *work)
1487+
{
1488+
struct worker_pool *pool = pwq->pool;
1489+
1490+
lockdep_assert_held(&pool->lock);
1491+
1492+
if (!(*work_data_bits(work) & WORK_STRUCT_INACTIVE))
1493+
return false;
1494+
14771495
pwq->nr_active++;
1496+
__pwq_activate_work(pwq, work);
1497+
return true;
14781498
}
14791499

14801500
static void pwq_activate_first_inactive(struct pool_workqueue *pwq)
14811501
{
14821502
struct work_struct *work = list_first_entry(&pwq->inactive_works,
14831503
struct work_struct, entry);
14841504

1485-
pwq_activate_inactive_work(work);
1505+
pwq_activate_work(pwq, work);
14861506
}
14871507

14881508
/**
@@ -1620,8 +1640,7 @@ static int try_to_grab_pending(struct work_struct *work, bool is_dwork,
16201640
* management later on and cause stall. Make sure the work
16211641
* item is activated before grabbing.
16221642
*/
1623-
if (*work_data_bits(work) & WORK_STRUCT_INACTIVE)
1624-
pwq_activate_inactive_work(work);
1643+
pwq_activate_work(pwq, work);
16251644

16261645
list_del_init(&work->entry);
16271646
pwq_dec_nr_in_flight(pwq, *work_data_bits(work));

0 commit comments

Comments
 (0)