Skip to content

Commit ab61854

Browse files
John LevonDan McDonald
John Levon
authored and
Dan McDonald
committed
8158 Want named threads API
9857 proc manpages should have LIBRARY section Reviewed by: Andy Fiddaman <andy@omniosce.org> Reviewed by: Gordon Ross <gwr@nexenta.com> Approved by: Dan McDonald <danmcd@joyent.com>
1 parent 62f6329 commit ab61854

File tree

156 files changed

+2258
-384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+2258
-384
lines changed

Diff for: usr/src/cmd/cmd-inet/lib/ipmgmtd/ipmgmt_persist.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
/*
2323
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24+
* Copyright 2018 Joyent, Inc.
2425
* Copyright 2016 Argo Technologie SA.
2526
* Copyright (c) 2016-2017, Chris Fraire <cfraire@me.com>.
2627
*/
@@ -457,6 +458,7 @@ ipmgmt_db_walk(db_wfunc_t *db_walk_func, void *db_warg, ipadm_db_op_t db_op)
457458
(void) pthread_attr_init(&attr);
458459
(void) pthread_attr_setdetachstate(&attr,
459460
PTHREAD_CREATE_DETACHED);
461+
(void) pthread_attr_setname_np(&attr, "db_restore");
460462
err = pthread_create(&tid, &attr, ipmgmt_db_restore_thread,
461463
NULL);
462464
(void) pthread_attr_destroy(&attr);
@@ -1124,7 +1126,7 @@ ipmgmt_aobjmap_init(void *arg, nvlist_t *db_nvl, char *buf, size_t buflen,
11241126
{
11251127
nvpair_t *nvp = NULL;
11261128
char *name, *strval = NULL;
1127-
ipmgmt_aobjmap_t node;
1129+
ipmgmt_aobjmap_t node;
11281130
struct sockaddr_in6 *in6;
11291131

11301132
*errp = 0;

Diff for: usr/src/cmd/dtrace/test/tst/common/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
#
2828
# Copyright (c) 2012 by Delphix. All rights reserved.
29-
# Copyright (c) 2013, Joyent, Inc. All rights reserved.
3029
# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
30+
# Copyright 2018 Joyent, Inc.
3131
#
3232

3333
#
@@ -57,6 +57,8 @@ sysevent/tst.post_chan.exe := LDLIBS += -lsysevent
5757

5858
ustack/tst.bigstack.exe := COPTFLAG += -xO1
5959

60+
CSTD = $(CSTD_GNU99)
61+
6062
nfs/%.o: $(SNOOPDIR)/%.c
6163
$(COMPILE.c) -o $@ $< -I$(SNOOPDIR)
6264
$(POST_PROCESS_O)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* This file and its contents are supplied under the terms of the
3+
* Common Development and Distribution License ("CDDL"), version 1.0.
4+
* You may only use this file in accordance with the terms of version
5+
* 1.0 of the CDDL.
6+
*
7+
* A full copy of the text of the CDDL should have accompanied this
8+
* source. A copy of the CDDL is also available via the Internet at
9+
* http://www.illumos.org/license/CDDL.
10+
*/
11+
12+
/*
13+
* Copyright 2018 Joyent, Inc.
14+
*/
15+
16+
/*
17+
* All we're doing is constantly modifying a thread name while DTrace is
18+
* watching us, making sure we don't break.
19+
*/
20+
21+
#include <sys/fcntl.h>
22+
#include <pthread.h>
23+
#include <stdlib.h>
24+
#include <stdio.h>
25+
26+
#define NR_THREADS (100)
27+
#define RUNTIME (30) /* seconds */
28+
29+
static void
30+
random_ascii(char *buf, size_t bufsize)
31+
{
32+
char table[] = "abcdefghijklmnopqrstuvwxyz"
33+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ,.-#'?!";
34+
size_t len = rand() % bufsize;
35+
36+
bzero(buf, bufsize);
37+
38+
for (size_t i = 0; i < len; i++) {
39+
buf[i] = table[rand() % (sizeof (table) - 1)];
40+
}
41+
}
42+
43+
static void
44+
busy()
45+
{
46+
struct timeval tv1;
47+
struct timeval tv2;
48+
49+
if (gettimeofday(&tv1, NULL) != 0)
50+
abort();
51+
52+
for (;;) {
53+
static volatile int i;
54+
for (i = 0; i < 2000000; i++)
55+
;
56+
57+
if (gettimeofday(&tv2, NULL) != 0)
58+
abort();
59+
60+
/* janky, but we don't care */
61+
if (tv2.tv_sec != tv1.tv_sec)
62+
return;
63+
}
64+
}
65+
66+
static void *
67+
thread(void *arg)
68+
{
69+
char name[PTHREAD_MAX_NAMELEN_NP];
70+
71+
for (size_t i = 0; ; i++) {
72+
random_ascii(name, sizeof (name));
73+
74+
if ((i % 100) == 0) {
75+
if (pthread_setname_np(pthread_self(), NULL) != 0)
76+
abort();
77+
} else {
78+
(void) pthread_setname_np(pthread_self(), name);
79+
}
80+
81+
busy();
82+
}
83+
84+
return (NULL);
85+
}
86+
87+
int
88+
main(int argc, char **argv)
89+
{
90+
pthread_t tids[NR_THREADS];
91+
92+
for (size_t i = 0; i < NR_THREADS; i++) {
93+
if (pthread_create(&tids[i], NULL, thread, NULL) != 0)
94+
exit(EXIT_FAILURE);
95+
}
96+
97+
sleep(RUNTIME);
98+
exit(EXIT_SUCCESS);
99+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* This file and its contents are supplied under the terms of the
3+
* Common Development and Distribution License ("CDDL"), version 1.0.
4+
* You may only use this file in accordance with the terms of version
5+
* 1.0 of the CDDL.
6+
*
7+
* A full copy of the text of the CDDL should have accompanied this
8+
* source. A copy of the CDDL is also available via the Internet at
9+
* http://www.illumos.org/license/CDDL.
10+
*/
11+
12+
/*
13+
* Copyright 2018 Joyent, Inc.
14+
*/
15+
16+
#pragma D option quiet
17+
18+
profile-10ms /pid == $1 && threadname == "unlikely"/
19+
{
20+
surprising++;
21+
}
22+
23+
syscall::rexit:entry /pid == $1/
24+
{
25+
exit(arg0);
26+
}

Diff for: usr/src/cmd/halt/Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# Copyright 2016 Toomas Soome <tsoome@me.com>
2222
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
2323
# Use is subject to license terms.
24+
# Copyright 2018 Joyent, Inc.
2425
#
2526

2627
PROG = halt
@@ -60,10 +61,10 @@ install := TARGET = install
6061
clean := TARGET = clean
6162
clobber := TARGET = clobber
6263
lint := TARGET = lint
63-
lint := LINTFLAGS = -u
64+
lint := LINTFLAGS += -u
6465

6566

66-
all: $(PROG)
67+
all: $(PROG)
6768

6869
install: all $(ROOTUSRSBINPROG) $(ROOTLINKS) $(ROOTSYMLINKS) $(SUBDIRS)
6970

Diff for: usr/src/cmd/ldapcachemgr/cachemgr_change.c

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
/*
2222
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2323
* Use is subject to license terms.
24+
*
25+
* Copyright 2018 Joyent, Inc.
2426
*/
2527

2628
#include <strings.h>
@@ -33,6 +35,7 @@
3335
#include <sys/stat.h>
3436
#include <fcntl.h>
3537
#include <procfs.h>
38+
#include <pthread.h>
3639
#include "cachemgr.h"
3740

3841
extern admin_t current_admin;
@@ -535,6 +538,8 @@ chg_cleanup_waiting_threads(void *arg)
535538
pid_t pid;
536539
int always = 1, waiting;
537540

541+
(void) pthread_setname_np(pthread_self(), "chg_cleanup_thr");
542+
538543
if (op == NULL) {
539544
waiting = 1;
540545
type = CLEANUP_ALL;

Diff for: usr/src/cmd/ldapcachemgr/cachemgr_discovery.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
/*
2222
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2323
* Use is subject to license terms.
24+
*
25+
* Copyright 2018 Joyent, Inc.
2426
*/
2527

2628
#ifdef SLP
@@ -539,9 +541,12 @@ static void find_all_contexts(const char *type,
539541
* parameter 'r' should be a pointer to an unsigned int containing
540542
* the requested interval at which the network should be queried.
541543
*/
542-
void discover(void *r) {
544+
void
545+
discover(void *r) {
543546
unsigned short reqrefresh = *((unsigned int *)r);
544547

548+
(void) pthread_setname_np(pthread_self(), "discover");
549+
545550
for (;;) {
546551
find_all_contexts("ldap",
547552
__cache_get_cfghandle,

Diff for: usr/src/cmd/ldapcachemgr/cachemgr_getldap.c

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
/*
2222
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23+
*
24+
* Copyright 2018 Joyent, Inc.
2325
*/
2426

2527
#include <assert.h>
@@ -1631,6 +1633,8 @@ getldap_serverInfo_op(info_op_t op, char *input, char **output)
16311633
static time_t prev_refresh = 0, next_refresh = 0;
16321634
ns_server_status_t changed = 0;
16331635

1636+
(void) pthread_setname_np(pthread_self(), "getldap_serverinfo");
1637+
16341638
if (current_admin.debug_level >= DBG_ALL) {
16351639
logit("getldap_serverInfo_op()...\n");
16361640
}
@@ -2542,6 +2546,8 @@ getldap_refresh()
25422546
int sig_done = 0;
25432547
int dbg_level;
25442548

2549+
(void) pthread_setname_np(pthread_self(), "getldap_refresh");
2550+
25452551
if (current_admin.debug_level >= DBG_ALL) {
25462552
logit("getldap_refresh()...\n");
25472553
}
@@ -2892,6 +2898,8 @@ remove_server_thread(void *arg)
28922898
int up;
28932899
rm_svr_t rms;
28942900

2901+
(void) pthread_setname_np(pthread_self(), "remove_server");
2902+
28952903
up = contact_server(addr);
28962904

28972905
rms.addr = addr;

Diff for: usr/src/cmd/mdb/common/mdb/mdb_proc.c

+22-1
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,23 @@ pt_regstatus(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
13031303
return (pt_regs(addr, flags, argc, argv));
13041304
}
13051305

1306+
static void
1307+
pt_thread_name(mdb_tgt_t *t, mdb_tgt_tid_t tid, char *buf, size_t bufsize)
1308+
{
1309+
char name[THREAD_NAME_MAX];
1310+
1311+
buf[0] = '\0';
1312+
1313+
if (t->t_pshandle == NULL ||
1314+
Plwp_getname(t->t_pshandle, tid, name, sizeof (name)) != 0 ||
1315+
name[0] == '\0') {
1316+
(void) mdb_snprintf(buf, bufsize, "%lu", tid);
1317+
return;
1318+
}
1319+
1320+
(void) mdb_snprintf(buf, bufsize, "%lu [%s]", tid, name);
1321+
}
1322+
13061323
static int
13071324
pt_findstack(uintptr_t tid, uint_t flags, int argc, const mdb_arg_t *argv)
13081325
{
@@ -1311,6 +1328,7 @@ pt_findstack(uintptr_t tid, uint_t flags, int argc, const mdb_arg_t *argv)
13111328
int showargs = 0;
13121329
int count;
13131330
uintptr_t pc, sp;
1331+
char name[128];
13141332

13151333
if (!(flags & DCMD_ADDRSPEC))
13161334
return (DCMD_USAGE);
@@ -1334,7 +1352,10 @@ pt_findstack(uintptr_t tid, uint_t flags, int argc, const mdb_arg_t *argv)
13341352
#else
13351353
sp = gregs.gregs[R_SP];
13361354
#endif
1337-
mdb_printf("stack pointer for thread %p: %p\n", tid, sp);
1355+
1356+
pt_thread_name(t, tid, name, sizeof (name));
1357+
1358+
mdb_printf("stack pointer for thread %s: %p\n", name, sp);
13381359
if (pc != 0)
13391360
mdb_printf("[ %0?lr %a() ]\n", sp, pc);
13401361

0 commit comments

Comments
 (0)