Skip to content

Commit 8bf8959

Browse files
committed
workqueue: Set worker->desc to workqueue name by default
Work functions can use set_worker_desc() to improve the visibility of what the worker task is doing. Currently, the desc field is unset at the beginning of each execution and there is a separate field to track the field is set during the current execution. Instead of leaving empty till desc is set, worker->desc can be used to remember the last workqueue the worker worked on by default and users that use set_worker_desc() can override it to something more informative as necessary. This simplifies desc handling and helps tracking the last workqueue that the worker exected on to improve visibility. Signed-off-by: Tejun Heo <[email protected]>
1 parent a2d812a commit 8bf8959

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

kernel/workqueue.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,12 @@ __acquires(&pool->lock)
20882088
worker->current_pwq = pwq;
20892089
work_color = get_work_color(work);
20902090

2091+
/*
2092+
* Record wq name for cmdline and debug reporting, may get
2093+
* overridden through set_worker_desc().
2094+
*/
2095+
strscpy(worker->desc, pwq->wq->name, WORKER_DESC_LEN);
2096+
20912097
list_del_init(&work->entry);
20922098

20932099
/*
@@ -2183,7 +2189,6 @@ __acquires(&pool->lock)
21832189
worker->current_work = NULL;
21842190
worker->current_func = NULL;
21852191
worker->current_pwq = NULL;
2186-
worker->desc_valid = false;
21872192
pwq_dec_nr_in_flight(pwq, work_color);
21882193
}
21892194

@@ -4346,7 +4351,6 @@ void set_worker_desc(const char *fmt, ...)
43464351
va_start(args, fmt);
43474352
vsnprintf(worker->desc, sizeof(worker->desc), fmt, args);
43484353
va_end(args);
4349-
worker->desc_valid = true;
43504354
}
43514355
}
43524356

@@ -4370,7 +4374,6 @@ void print_worker_info(const char *log_lvl, struct task_struct *task)
43704374
char desc[WORKER_DESC_LEN] = { };
43714375
struct pool_workqueue *pwq = NULL;
43724376
struct workqueue_struct *wq = NULL;
4373-
bool desc_valid = false;
43744377
struct worker *worker;
43754378

43764379
if (!(task->flags & PF_WQ_WORKER))
@@ -4383,22 +4386,18 @@ void print_worker_info(const char *log_lvl, struct task_struct *task)
43834386
worker = kthread_probe_data(task);
43844387

43854388
/*
4386-
* Carefully copy the associated workqueue's workfn and name. Keep
4387-
* the original last '\0' in case the original contains garbage.
4389+
* Carefully copy the associated workqueue's workfn, name and desc.
4390+
* Keep the original last '\0' in case the original is garbage.
43884391
*/
43894392
probe_kernel_read(&fn, &worker->current_func, sizeof(fn));
43904393
probe_kernel_read(&pwq, &worker->current_pwq, sizeof(pwq));
43914394
probe_kernel_read(&wq, &pwq->wq, sizeof(wq));
43924395
probe_kernel_read(name, wq->name, sizeof(name) - 1);
4393-
4394-
/* copy worker description */
4395-
probe_kernel_read(&desc_valid, &worker->desc_valid, sizeof(desc_valid));
4396-
if (desc_valid)
4397-
probe_kernel_read(desc, worker->desc, sizeof(desc) - 1);
4396+
probe_kernel_read(desc, worker->desc, sizeof(desc) - 1);
43984397

43994398
if (fn || name[0] || desc[0]) {
44004399
printk("%sWorkqueue: %s %pf", log_lvl, name, fn);
4401-
if (desc[0])
4400+
if (strcmp(name, desc))
44024401
pr_cont(" (%s)", desc);
44034402
pr_cont("\n");
44044403
}

kernel/workqueue_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ struct worker {
3131
struct work_struct *current_work; /* L: work being processed */
3232
work_func_t current_func; /* L: current_work's fn */
3333
struct pool_workqueue *current_pwq; /* L: current_work's pwq */
34-
bool desc_valid; /* ->desc is valid */
3534
struct list_head scheduled; /* L: scheduled works */
3635

3736
/* 64 bytes boundary on 64bit, 32 on 32bit */

0 commit comments

Comments
 (0)