Skip to content

Commit

Permalink
workqueue: make get_work_pool_id() cheaper
Browse files Browse the repository at this point in the history
get_work_pool_id() currently first obtains pool using get_work_pool()
and then return pool->id.  For an off-queue work item, this involves
obtaining pool ID from worker->data, performing idr_find() to find the
matching pool and then returning its pool->id which of course is the
same as the one which went into idr_find().

Just open code WORK_STRUCT_CWQ case and directly return pool ID from
work->data.

tj: The original patch dropped on-queue work item handling and renamed
    the function to offq_work_pool_id().  There isn't much benefit in
    doing so.  Handling it only requires a single if() and we need at
    least BUG_ON(), which is also a branch, even if we drop on-queue
    handling.  Open code WORK_STRUCT_CWQ case and keep the function in
    line with get_work_pool().  Rewrote the description.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
  • Loading branch information
Lai Jiangshan authored and Tejun Heo committed Feb 7, 2013
1 parent e19e397 commit 54d5b7d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,13 @@ static struct worker_pool *get_work_pool(struct work_struct *work)
*/
static int get_work_pool_id(struct work_struct *work)
{
struct worker_pool *pool = get_work_pool(work);
unsigned long data = atomic_long_read(&work->data);

if (data & WORK_STRUCT_CWQ)
return ((struct cpu_workqueue_struct *)
(data & WORK_STRUCT_WQ_DATA_MASK))->pool->id;

return pool ? pool->id : WORK_OFFQ_POOL_NONE;
return data >> WORK_OFFQ_POOL_SHIFT;
}

static void mark_work_canceling(struct work_struct *work)
Expand Down

0 comments on commit 54d5b7d

Please sign in to comment.