Skip to content

Commit af6c5d5

Browse files
committed
Merge branch 'for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
Pull workqueue updates from Tejun Heo: - make kworkers report the workqueue it is executing or has executed most recently in /proc/PID/comm (so they show up in ps/top) - CONFIG_SMP shuffle to move stuff which isn't necessary for UP builds inside CONFIG_SMP. * 'for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq: workqueue: move function definitions within CONFIG_SMP block workqueue: Make sure struct worker is accessible for wq_worker_comm() workqueue: Show the latest workqueue name in /proc/PID/{comm,stat,status} proc: Consolidate task->comm formatting into proc_task_name() workqueue: Set worker->desc to workqueue name by default workqueue: Make worker_attach/detach_pool() update worker->pool workqueue: Replace pool->attach_mutex with global wq_pool_attach_mutex
2 parents 9f25a8d + 66448bc commit af6c5d5

File tree

6 files changed

+119
-64
lines changed

6 files changed

+119
-64
lines changed

fs/proc/array.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,29 @@
9696
#include <asm/processor.h>
9797
#include "internal.h"
9898

99-
static inline void task_name(struct seq_file *m, struct task_struct *p)
99+
void proc_task_name(struct seq_file *m, struct task_struct *p, bool escape)
100100
{
101101
char *buf;
102102
size_t size;
103-
char tcomm[sizeof(p->comm)];
103+
char tcomm[64];
104104
int ret;
105105

106-
get_task_comm(tcomm, p);
107-
108-
seq_puts(m, "Name:\t");
106+
if (p->flags & PF_WQ_WORKER)
107+
wq_worker_comm(tcomm, sizeof(tcomm), p);
108+
else
109+
__get_task_comm(tcomm, sizeof(tcomm), p);
109110

110111
size = seq_get_buf(m, &buf);
111-
ret = string_escape_str(tcomm, buf, size, ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\");
112-
seq_commit(m, ret < size ? ret : -1);
112+
if (escape) {
113+
ret = string_escape_str(tcomm, buf, size,
114+
ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\");
115+
if (ret >= size)
116+
ret = -1;
117+
} else {
118+
ret = strscpy(buf, tcomm, size);
119+
}
113120

114-
seq_putc(m, '\n');
121+
seq_commit(m, ret);
115122
}
116123

117124
/*
@@ -390,7 +397,10 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
390397
{
391398
struct mm_struct *mm = get_task_mm(task);
392399

393-
task_name(m, task);
400+
seq_puts(m, "Name:\t");
401+
proc_task_name(m, task, true);
402+
seq_putc(m, '\n');
403+
394404
task_state(m, ns, pid, task);
395405

396406
if (mm) {
@@ -425,7 +435,6 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
425435
u64 cutime, cstime, utime, stime;
426436
u64 cgtime, gtime;
427437
unsigned long rsslim = 0;
428-
char tcomm[sizeof(task->comm)];
429438
unsigned long flags;
430439

431440
state = *get_task_state(task);
@@ -452,8 +461,6 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
452461
}
453462
}
454463

455-
get_task_comm(tcomm, task);
456-
457464
sigemptyset(&sigign);
458465
sigemptyset(&sigcatch);
459466
cutime = cstime = utime = stime = 0;
@@ -520,7 +527,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
520527

521528
seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns));
522529
seq_puts(m, " (");
523-
seq_puts(m, tcomm);
530+
proc_task_name(m, task, false);
524531
seq_puts(m, ") ");
525532
seq_putc(m, state);
526533
seq_put_decimal_ll(m, " ", ppid);

fs/proc/base.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,9 +1563,8 @@ static int comm_show(struct seq_file *m, void *v)
15631563
if (!p)
15641564
return -ESRCH;
15651565

1566-
task_lock(p);
1567-
seq_printf(m, "%s\n", p->comm);
1568-
task_unlock(p);
1566+
proc_task_name(m, p, false);
1567+
seq_putc(m, '\n');
15691568

15701569
put_task_struct(p);
15711570

fs/proc/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ unsigned name_to_int(const struct qstr *qstr);
136136
*/
137137
extern const struct file_operations proc_tid_children_operations;
138138

139+
extern void proc_task_name(struct seq_file *m, struct task_struct *p,
140+
bool escape);
139141
extern int proc_tid_stat(struct seq_file *, struct pid_namespace *,
140142
struct pid *, struct task_struct *);
141143
extern int proc_tgid_stat(struct seq_file *, struct pid_namespace *,

include/linux/workqueue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ extern unsigned int work_busy(struct work_struct *work);
494494
extern __printf(1, 2) void set_worker_desc(const char *fmt, ...);
495495
extern void print_worker_info(const char *log_lvl, struct task_struct *task);
496496
extern void show_workqueue_state(void);
497+
extern void wq_worker_comm(char *buf, size_t size, struct task_struct *task);
497498

498499
/**
499500
* queue_work - queue work on a workqueue

0 commit comments

Comments
 (0)