@@ -125,6 +125,7 @@ enum wq_internal_consts {
125
125
HIGHPRI_NICE_LEVEL = MIN_NICE ,
126
126
127
127
WQ_NAME_LEN = 32 ,
128
+ WORKER_ID_LEN = 10 + WQ_NAME_LEN , /* "kworker/R-" + WQ_NAME_LEN */
128
129
};
129
130
130
131
/*
@@ -2742,6 +2743,26 @@ static void worker_detach_from_pool(struct worker *worker)
2742
2743
complete (detach_completion );
2743
2744
}
2744
2745
2746
+ static int format_worker_id (char * buf , size_t size , struct worker * worker ,
2747
+ struct worker_pool * pool )
2748
+ {
2749
+ if (worker -> rescue_wq )
2750
+ return scnprintf (buf , size , "kworker/R-%s" ,
2751
+ worker -> rescue_wq -> name );
2752
+
2753
+ if (pool ) {
2754
+ if (pool -> cpu >= 0 )
2755
+ return scnprintf (buf , size , "kworker/%d:%d%s" ,
2756
+ pool -> cpu , worker -> id ,
2757
+ pool -> attrs -> nice < 0 ? "H" : "" );
2758
+ else
2759
+ return scnprintf (buf , size , "kworker/u%d:%d" ,
2760
+ pool -> id , worker -> id );
2761
+ } else {
2762
+ return scnprintf (buf , size , "kworker/dying" );
2763
+ }
2764
+ }
2765
+
2745
2766
/**
2746
2767
* create_worker - create a new workqueue worker
2747
2768
* @pool: pool the new worker will belong to
@@ -2758,7 +2779,6 @@ static struct worker *create_worker(struct worker_pool *pool)
2758
2779
{
2759
2780
struct worker * worker ;
2760
2781
int id ;
2761
- char id_buf [23 ];
2762
2782
2763
2783
/* ID is needed to determine kthread name */
2764
2784
id = ida_alloc (& pool -> worker_ida , GFP_KERNEL );
@@ -2777,17 +2797,14 @@ static struct worker *create_worker(struct worker_pool *pool)
2777
2797
worker -> id = id ;
2778
2798
2779
2799
if (!(pool -> flags & POOL_BH )) {
2780
- if (pool -> cpu >= 0 )
2781
- snprintf (id_buf , sizeof (id_buf ), "%d:%d%s" , pool -> cpu , id ,
2782
- pool -> attrs -> nice < 0 ? "H" : "" );
2783
- else
2784
- snprintf (id_buf , sizeof (id_buf ), "u%d:%d" , pool -> id , id );
2800
+ char id_buf [WORKER_ID_LEN ];
2785
2801
2802
+ format_worker_id (id_buf , sizeof (id_buf ), worker , pool );
2786
2803
worker -> task = kthread_create_on_node (worker_thread , worker ,
2787
- pool -> node , "kworker/ %s" , id_buf );
2804
+ pool -> node , "%s" , id_buf );
2788
2805
if (IS_ERR (worker -> task )) {
2789
2806
if (PTR_ERR (worker -> task ) == - EINTR ) {
2790
- pr_err ("workqueue: Interrupted when creating a worker thread \"kworker/ %s\"\n" ,
2807
+ pr_err ("workqueue: Interrupted when creating a worker thread \"%s\"\n" ,
2791
2808
id_buf );
2792
2809
} else {
2793
2810
pr_err_once ("workqueue: Failed to create a worker thread: %pe" ,
@@ -3350,7 +3367,6 @@ static int worker_thread(void *__worker)
3350
3367
raw_spin_unlock_irq (& pool -> lock );
3351
3368
set_pf_worker (false);
3352
3369
3353
- set_task_comm (worker -> task , "kworker/dying" );
3354
3370
ida_free (& pool -> worker_ida , worker -> id );
3355
3371
worker_detach_from_pool (worker );
3356
3372
WARN_ON_ONCE (!list_empty (& worker -> entry ));
@@ -5542,6 +5558,7 @@ static int wq_clamp_max_active(int max_active, unsigned int flags,
5542
5558
static int init_rescuer (struct workqueue_struct * wq )
5543
5559
{
5544
5560
struct worker * rescuer ;
5561
+ char id_buf [WORKER_ID_LEN ];
5545
5562
int ret ;
5546
5563
5547
5564
if (!(wq -> flags & WQ_MEM_RECLAIM ))
@@ -5555,7 +5572,9 @@ static int init_rescuer(struct workqueue_struct *wq)
5555
5572
}
5556
5573
5557
5574
rescuer -> rescue_wq = wq ;
5558
- rescuer -> task = kthread_create (rescuer_thread , rescuer , "kworker/R-%s" , wq -> name );
5575
+ format_worker_id (id_buf , sizeof (id_buf ), rescuer , NULL );
5576
+
5577
+ rescuer -> task = kthread_create (rescuer_thread , rescuer , "%s" , id_buf );
5559
5578
if (IS_ERR (rescuer -> task )) {
5560
5579
ret = PTR_ERR (rescuer -> task );
5561
5580
pr_err ("workqueue: Failed to create a rescuer kthread for wq \"%s\": %pe" ,
@@ -6384,19 +6403,15 @@ void show_freezable_workqueues(void)
6384
6403
/* used to show worker information through /proc/PID/{comm,stat,status} */
6385
6404
void wq_worker_comm (char * buf , size_t size , struct task_struct * task )
6386
6405
{
6387
- int off ;
6388
-
6389
- /* always show the actual comm */
6390
- off = strscpy (buf , task -> comm , size );
6391
- if (off < 0 )
6392
- return ;
6393
-
6394
6406
/* stabilize PF_WQ_WORKER and worker pool association */
6395
6407
mutex_lock (& wq_pool_attach_mutex );
6396
6408
6397
6409
if (task -> flags & PF_WQ_WORKER ) {
6398
6410
struct worker * worker = kthread_data (task );
6399
6411
struct worker_pool * pool = worker -> pool ;
6412
+ int off ;
6413
+
6414
+ off = format_worker_id (buf , size , worker , pool );
6400
6415
6401
6416
if (pool ) {
6402
6417
raw_spin_lock_irq (& pool -> lock );
@@ -6415,6 +6430,8 @@ void wq_worker_comm(char *buf, size_t size, struct task_struct *task)
6415
6430
}
6416
6431
raw_spin_unlock_irq (& pool -> lock );
6417
6432
}
6433
+ } else {
6434
+ strscpy (buf , task -> comm , size );
6418
6435
}
6419
6436
6420
6437
mutex_unlock (& wq_pool_attach_mutex );
0 commit comments