Skip to content

Commit 3e96f19

Browse files
committed
libzpool: set thread names
Arrange for the thread/task name to be set when new threads are created. This makes them visible in the process table etc. pthread_setname_np() is generally available in glibc, musl and FreeBSD, so no test is required. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Sponsored-by: https://despairlabs.com/sponsor/ Closes openzfs#16140 (cherry picked from commit 4429ad9)
1 parent 22f1912 commit 3e96f19

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

include/sys/zfs_context.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ typedef pthread_t kthread_t;
228228

229229
#define thread_create_named(name, stk, stksize, func, arg, len, \
230230
pp, state, pri) \
231-
zk_thread_create(func, arg, stksize, state)
231+
zk_thread_create(name, func, arg, stksize, state)
232232
#define thread_create(stk, stksize, func, arg, len, pp, state, pri) \
233-
zk_thread_create(func, arg, stksize, state)
233+
zk_thread_create(#func, func, arg, stksize, state)
234234
#define thread_exit() pthread_exit(NULL)
235235
#define thread_join(t) pthread_join((pthread_t)(t), NULL)
236236

@@ -246,8 +246,8 @@ extern struct proc p0;
246246

247247
#define PS_NONE -1
248248

249-
extern kthread_t *zk_thread_create(void (*func)(void *), void *arg,
250-
size_t stksize, int state);
249+
extern kthread_t *zk_thread_create(const char *name, void (*func)(void *),
250+
void *arg, size_t stksize, int state);
251251

252252
#define issig(why) (FALSE)
253253
#define ISSIG(thr, why) (FALSE)

lib/libzpool/kernel.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ zk_thread_wrapper(void *arg)
9292
}
9393

9494
kthread_t *
95-
zk_thread_create(void (*func)(void *), void *arg, size_t stksize, int state)
95+
zk_thread_create(const char *name, void (*func)(void *), void *arg,
96+
size_t stksize, int state)
9697
{
9798
pthread_attr_t attr;
9899
pthread_t tid;
@@ -140,6 +141,8 @@ zk_thread_create(void (*func)(void *), void *arg, size_t stksize, int state)
140141
VERIFY0(pthread_create(&tid, &attr, zk_thread_wrapper, ztw));
141142
VERIFY0(pthread_attr_destroy(&attr));
142143

144+
pthread_setname_np(tid, name);
145+
143146
return ((void *)(uintptr_t)tid);
144147
}
145148

lib/libzpool/taskq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ taskq_create(const char *name, int nthreads, pri_t pri,
295295
}
296296

297297
for (t = 0; t < nthreads; t++)
298-
VERIFY((tq->tq_threadlist[t] = thread_create(NULL, 0,
299-
taskq_thread, tq, 0, &p0, TS_RUN, pri)) != NULL);
298+
VERIFY((tq->tq_threadlist[t] = thread_create_named(tq->tq_name,
299+
NULL, 0, taskq_thread, tq, 0, &p0, TS_RUN, pri)) != NULL);
300300

301301
return (tq);
302302
}

0 commit comments

Comments
 (0)