@@ -125,6 +125,7 @@ enum wq_internal_consts {
125125 HIGHPRI_NICE_LEVEL = MIN_NICE ,
126126
127127 WQ_NAME_LEN = 32 ,
128+ WORKER_ID_LEN = 10 + WQ_NAME_LEN , /* "kworker/R-" + WQ_NAME_LEN */
128129};
129130
130131/*
@@ -2742,6 +2743,26 @@ static void worker_detach_from_pool(struct worker *worker)
27422743 complete (detach_completion );
27432744}
27442745
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+
27452766/**
27462767 * create_worker - create a new workqueue worker
27472768 * @pool: pool the new worker will belong to
@@ -2758,7 +2779,6 @@ static struct worker *create_worker(struct worker_pool *pool)
27582779{
27592780 struct worker * worker ;
27602781 int id ;
2761- char id_buf [23 ];
27622782
27632783 /* ID is needed to determine kthread name */
27642784 id = ida_alloc (& pool -> worker_ida , GFP_KERNEL );
@@ -2777,17 +2797,14 @@ static struct worker *create_worker(struct worker_pool *pool)
27772797 worker -> id = id ;
27782798
27792799 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 ];
27852801
2802+ format_worker_id (id_buf , sizeof (id_buf ), worker , pool );
27862803 worker -> task = kthread_create_on_node (worker_thread , worker ,
2787- pool -> node , "kworker/ %s" , id_buf );
2804+ pool -> node , "%s" , id_buf );
27882805 if (IS_ERR (worker -> task )) {
27892806 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" ,
27912808 id_buf );
27922809 } else {
27932810 pr_err_once ("workqueue: Failed to create a worker thread: %pe" ,
@@ -3350,7 +3367,6 @@ static int worker_thread(void *__worker)
33503367 raw_spin_unlock_irq (& pool -> lock );
33513368 set_pf_worker (false);
33523369
3353- set_task_comm (worker -> task , "kworker/dying" );
33543370 ida_free (& pool -> worker_ida , worker -> id );
33553371 worker_detach_from_pool (worker );
33563372 WARN_ON_ONCE (!list_empty (& worker -> entry ));
@@ -5542,6 +5558,7 @@ static int wq_clamp_max_active(int max_active, unsigned int flags,
55425558static int init_rescuer (struct workqueue_struct * wq )
55435559{
55445560 struct worker * rescuer ;
5561+ char id_buf [WORKER_ID_LEN ];
55455562 int ret ;
55465563
55475564 if (!(wq -> flags & WQ_MEM_RECLAIM ))
@@ -5555,7 +5572,9 @@ static int init_rescuer(struct workqueue_struct *wq)
55555572 }
55565573
55575574 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 );
55595578 if (IS_ERR (rescuer -> task )) {
55605579 ret = PTR_ERR (rescuer -> task );
55615580 pr_err ("workqueue: Failed to create a rescuer kthread for wq \"%s\": %pe" ,
@@ -6384,19 +6403,15 @@ void show_freezable_workqueues(void)
63846403/* used to show worker information through /proc/PID/{comm,stat,status} */
63856404void wq_worker_comm (char * buf , size_t size , struct task_struct * task )
63866405{
6387- int off ;
6388-
6389- /* always show the actual comm */
6390- off = strscpy (buf , task -> comm , size );
6391- if (off < 0 )
6392- return ;
6393-
63946406 /* stabilize PF_WQ_WORKER and worker pool association */
63956407 mutex_lock (& wq_pool_attach_mutex );
63966408
63976409 if (task -> flags & PF_WQ_WORKER ) {
63986410 struct worker * worker = kthread_data (task );
63996411 struct worker_pool * pool = worker -> pool ;
6412+ int off ;
6413+
6414+ off = format_worker_id (buf , size , worker , pool );
64006415
64016416 if (pool ) {
64026417 raw_spin_lock_irq (& pool -> lock );
@@ -6415,6 +6430,8 @@ void wq_worker_comm(char *buf, size_t size, struct task_struct *task)
64156430 }
64166431 raw_spin_unlock_irq (& pool -> lock );
64176432 }
6433+ } else {
6434+ strscpy (buf , task -> comm , size );
64186435 }
64196436
64206437 mutex_unlock (& wq_pool_attach_mutex );
0 commit comments