Skip to content
Permalink
Browse files

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>
  • Loading branch information...
jlevon authored and danmcd committed Oct 8, 2018
1 parent 62f6329 commit ab618543cc6fc4bc273c077ef5d247961cdb29d4
Showing with 2,258 additions and 384 deletions.
  1. +3 −1 usr/src/cmd/cmd-inet/lib/ipmgmtd/ipmgmt_persist.c
  2. +3 −1 usr/src/cmd/dtrace/test/tst/common/Makefile
  3. +99 −0 usr/src/cmd/dtrace/test/tst/common/threadname/tst.threadname.c
  4. +26 −0 usr/src/cmd/dtrace/test/tst/common/threadname/tst.threadname.d
  5. +3 −2 usr/src/cmd/halt/Makefile
  6. +5 −0 usr/src/cmd/ldapcachemgr/cachemgr_change.c
  7. +6 −1 usr/src/cmd/ldapcachemgr/cachemgr_discovery.c
  8. +8 −0 usr/src/cmd/ldapcachemgr/cachemgr_getldap.c
  9. +22 −1 usr/src/cmd/mdb/common/mdb/mdb_proc.c
  10. +20 −8 usr/src/cmd/mdb/common/modules/genunix/findstack.c
  11. +11 −6 usr/src/cmd/mdb/common/modules/genunix/genunix.c
  12. +121 −71 usr/src/cmd/mdb/common/modules/genunix/thread.c
  13. +4 −0 usr/src/cmd/mdb/common/modules/genunix/thread.h
  14. +9 −2 usr/src/cmd/nscd/cache.c
  15. +10 −3 usr/src/cmd/nscd/nscd_frontend.c
  16. +7 −2 usr/src/cmd/nscd/nscd_getentctx.c
  17. +6 −1 usr/src/cmd/nscd/nscd_selfcred.c
  18. +4 −0 usr/src/cmd/nscd/nscd_smfmonitor.c
  19. +2 −0 usr/src/cmd/prstat/Makefile.com
  20. +89 −50 usr/src/cmd/prstat/prstat.c
  21. +5 −0 usr/src/cmd/prstat/prstat.h
  22. +73 −2 usr/src/cmd/prstat/prutil.c
  23. +2 −1 usr/src/cmd/prstat/prutil.h
  24. +38 −13 usr/src/cmd/ps/ps.c
  25. +51 −15 usr/src/cmd/ptools/pstack/pstack.c
  26. +19 −0 usr/src/cmd/sgs/elfdump/common/corenote.c
  27. +3 −0 usr/src/cmd/sgs/elfdump/common/elfdump.msg
  28. +2 −0 usr/src/cmd/sgs/elfdump/common/gen_layout_obj.c
  29. +13 −1 usr/src/cmd/sgs/elfdump/common/gen_struct_layout.c
  30. +9 −1 usr/src/cmd/sgs/elfdump/common/struct_layout.h
  31. +9 −0 usr/src/cmd/sgs/elfdump/common/struct_layout_amd64.c
  32. +9 −0 usr/src/cmd/sgs/elfdump/common/struct_layout_i386.c
  33. +10 −0 usr/src/cmd/sgs/elfdump/common/struct_layout_sparc.c
  34. +9 −0 usr/src/cmd/sgs/elfdump/common/struct_layout_sparcv9.c
  35. +3 −3 usr/src/cmd/sgs/libconv/Makefile.com
  36. +3 −2 usr/src/cmd/sgs/libconv/common/corenote.c
  37. +1 −0 usr/src/cmd/sgs/libconv/common/corenote.msg
  38. +12 −1 usr/src/cmd/svc/startd/graph.c
  39. +3 −1 usr/src/cmd/svc/startd/method.c
  40. +13 −3 usr/src/cmd/svc/startd/restarter.c
  41. +4 −1 usr/src/cmd/svc/startd/wait.c
  42. +10 −1 usr/src/head/pthread.h
  43. +4 −0 usr/src/head/thread.h
  44. +3 −1 usr/src/lib/libc/inc/thr_uberdata.h
  45. +11 −1 usr/src/lib/libc/port/mapfile-vers
  46. +56 −5 usr/src/lib/libc/port/threads/pthr_attr.c
  47. +2 −2 usr/src/lib/libc/port/threads/pthread.c
  48. +88 −3 usr/src/lib/libc/port/threads/thr.c
  49. +7 −3 usr/src/lib/libdtrace/common/dt_open.c
  50. +2 −0 usr/src/lib/libfakekernel/common/sys/thread.h
  51. +4 −2 usr/src/lib/libproc/common/Pcontrol.h
  52. +28 −1 usr/src/lib/libproc/common/Pcore.c
  53. +10 −1 usr/src/lib/libproc/common/Pgcore.c
  54. +33 −1 usr/src/lib/libproc/common/Plwpregs.c
  55. +2 −1 usr/src/lib/libproc/common/libproc.h
  56. +2 −1 usr/src/lib/libproc/common/mapfile-vers
  57. +25 −14 usr/src/man/man1/ps.1
  58. +5 −3 usr/src/man/man1m/prstat.1m
  59. +12 −0 usr/src/man/man3c/Makefile
  60. +105 −0 usr/src/man/man3c/pthread_attr_getname_np.3c
  61. +124 −0 usr/src/man/man3c/pthread_getname_np.3c
  62. +124 −0 usr/src/man/man3c/thr_getname.3c
  63. +30 −30 usr/src/man/man3lib/libproc.3lib
  64. +8 −7 usr/src/man/man3proc/Makefile
  65. +2 −1 usr/src/man/man3proc/Paddr_to_ctf.3proc
  66. +2 −1 usr/src/man/man3proc/Paddr_to_loadobj.3proc
  67. +2 −1 usr/src/man/man3proc/Paddr_to_map.3proc
  68. +2 −1 usr/src/man/man3proc/Pasfd.3proc
  69. +2 −1 usr/src/man/man3proc/Pclearfault.3proc
  70. +2 −1 usr/src/man/man3proc/Pclearsig.3proc
  71. +2 −1 usr/src/man/man3proc/Pcontent.3proc
  72. +2 −1 usr/src/man/man3proc/Pcreate.3proc
  73. +2 −1 usr/src/man/man3proc/Pcreate_agent.3proc
  74. +2 −1 usr/src/man/man3proc/Pcreate_error.3proc
  75. +2 −1 usr/src/man/man3proc/Pcred.3proc
  76. +2 −1 usr/src/man/man3proc/Pctlfd.3proc
  77. +2 −1 usr/src/man/man3proc/Pdelbkpt.3proc
  78. +2 −1 usr/src/man/man3proc/Pdelwapt.3proc
  79. +2 −1 usr/src/man/man3proc/Pdestroy_agent.3proc
  80. +2 −1 usr/src/man/man3proc/Penv_iter.3proc
  81. +2 −1 usr/src/man/man3proc/Pexecname.3proc
  82. +2 −1 usr/src/man/man3proc/Pfault.3proc
  83. +2 −1 usr/src/man/man3proc/Pfdinfo_iter.3proc
  84. +2 −1 usr/src/man/man3proc/Pgetareg.3proc
  85. +2 −1 usr/src/man/man3proc/Pgetauxval.3proc
  86. +2 −1 usr/src/man/man3proc/Pgetauxvec.3proc
  87. +2 −1 usr/src/man/man3proc/Pgetenv.3proc
  88. +2 −1 usr/src/man/man3proc/Pgrab.3proc
  89. +2 −1 usr/src/man/man3proc/Pgrab_core.3proc
  90. +2 −1 usr/src/man/man3proc/Pgrab_error.3proc
  91. +2 −1 usr/src/man/man3proc/Pgrab_file.3proc
  92. +2 −1 usr/src/man/man3proc/Pisprocdir.3proc
  93. +2 −1 usr/src/man/man3proc/Pissyscall.3proc
  94. +2 −1 usr/src/man/man3proc/Pldt.3proc
  95. +2 −1 usr/src/man/man3proc/Plmid.3proc
  96. +2 −1 usr/src/man/man3proc/Plookup_by_addr.3proc
  97. +2 −1 usr/src/man/man3proc/Plwp_getasrs.3proc
  98. +95 −0 usr/src/man/man3proc/Plwp_getname.3proc
  99. +2 −1 usr/src/man/man3proc/Plwp_getpsinfo.3proc
  100. +2 −1 usr/src/man/man3proc/Plwp_getregs.3proc
  101. +2 −1 usr/src/man/man3proc/Plwp_getspymaster.3proc
  102. +2 −1 usr/src/man/man3proc/Plwp_getxregs.3proc
  103. +2 −1 usr/src/man/man3proc/Plwp_iter.3proc
  104. +2 −1 usr/src/man/man3proc/Plwp_stack.3proc
  105. +2 −1 usr/src/man/man3proc/Pmapping_iter.3proc
  106. +2 −1 usr/src/man/man3proc/Pobjname.3proc
  107. +2 −1 usr/src/man/man3proc/Pplatform.3proc
  108. +2 −1 usr/src/man/man3proc/Ppltdest.3proc
  109. +2 −1 usr/src/man/man3proc/Ppriv.3proc
  110. +2 −1 usr/src/man/man3proc/Ppsinfo.3proc
  111. +2 −1 usr/src/man/man3proc/Prd_agent.3proc
  112. +2 −1 usr/src/man/man3proc/Pread.3proc
  113. +2 −1 usr/src/man/man3proc/Prelease.3proc
  114. +2 −1 usr/src/man/man3proc/Preopen.3proc
  115. +2 −1 usr/src/man/man3proc/Preset_maps.3proc
  116. +2 −1 usr/src/man/man3proc/Psecflags.3proc
  117. +2 −1 usr/src/man/man3proc/Psetbkpt.3proc
  118. +2 −1 usr/src/man/man3proc/Psetcred.3proc
  119. +2 −1 usr/src/man/man3proc/Psetfault.3proc
  120. +2 −1 usr/src/man/man3proc/Psetflags.3proc
  121. +2 −1 usr/src/man/man3proc/Psetpriv.3proc
  122. +2 −1 usr/src/man/man3proc/Psetrun.3proc
  123. +2 −1 usr/src/man/man3proc/Psetsignal.3proc
  124. +2 −1 usr/src/man/man3proc/Psetsysentry.3proc
  125. +2 −1 usr/src/man/man3proc/Psetwapt.3proc
  126. +2 −1 usr/src/man/man3proc/Psetzoneid.3proc
  127. +2 −1 usr/src/man/man3proc/Psignal.3proc
  128. +2 −1 usr/src/man/man3proc/Pstack_iter.3proc
  129. +2 −1 usr/src/man/man3proc/Pstate.3proc
  130. +2 −1 usr/src/man/man3proc/Pstatus.3proc
  131. +2 −1 usr/src/man/man3proc/Pstopstatus.3proc
  132. +2 −1 usr/src/man/man3proc/Psymbol_iter.3proc
  133. +2 −1 usr/src/man/man3proc/Psync.3proc
  134. +2 −1 usr/src/man/man3proc/Psysentry.3proc
  135. +2 −1 usr/src/man/man3proc/Puname.3proc
  136. +2 −1 usr/src/man/man3proc/Pupdate_maps.3proc
  137. +2 −1 usr/src/man/man3proc/Pupdate_syms.3proc
  138. +2 −1 usr/src/man/man3proc/Pwrite.3proc
  139. +2 −1 usr/src/man/man3proc/Pzonename.3proc
  140. +11 −3 usr/src/man/man4/proc.4
  141. +4 −0 usr/src/pkg/manifests/system-dtrace-tests.mf
  142. +9 −0 usr/src/pkg/manifests/system-library.man3c.inc
  143. +2 −1 usr/src/pkg/manifests/system-library.man3proc.inc
  144. +2 −0 usr/src/pkg/manifests/system-test-libctest.mf
  145. +2 −1 usr/src/test/libc-tests/runfiles/default.run
  146. +2 −2 usr/src/test/libc-tests/tests/threads/Makefile
  147. +278 −0 usr/src/test/libc-tests/tests/threads/thread_name.c
  148. +79 −1 usr/src/uts/common/disp/thread.c
  149. +22 −3 usr/src/uts/common/dtrace/dtrace.c
  150. +17 −2 usr/src/uts/common/exec/elf/elf_notes.c
  151. +3 −2 usr/src/uts/common/fs/proc/prdata.h
  152. +102 −12 usr/src/uts/common/fs/proc/prvnops.c
  153. +4 −3 usr/src/uts/common/sys/dtrace.h
  154. +10 −9 usr/src/uts/common/sys/elf.h
  155. +13 −1 usr/src/uts/common/sys/procfs.h
  156. +11 −0 usr/src/uts/common/sys/thread.h
@@ -21,6 +21,7 @@

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

*errp = 0;
@@ -26,8 +26,8 @@

#
# Copyright (c) 2012 by Delphix. All rights reserved.
# Copyright (c) 2013, Joyent, Inc. All rights reserved.
# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
# Copyright 2018 Joyent, Inc.
#

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

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

CSTD = $(CSTD_GNU99)

nfs/%.o: $(SNOOPDIR)/%.c
$(COMPILE.c) -o $@ $< -I$(SNOOPDIR)
$(POST_PROCESS_O)
@@ -0,0 +1,99 @@
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/

/*
* Copyright 2018 Joyent, Inc.
*/

/*
* All we're doing is constantly modifying a thread name while DTrace is
* watching us, making sure we don't break.
*/

#include <sys/fcntl.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>

#define NR_THREADS (100)
#define RUNTIME (30) /* seconds */

static void
random_ascii(char *buf, size_t bufsize)
{
char table[] = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ,.-#'?!";
size_t len = rand() % bufsize;

bzero(buf, bufsize);

for (size_t i = 0; i < len; i++) {
buf[i] = table[rand() % (sizeof (table) - 1)];
}
}

static void
busy()
{
struct timeval tv1;
struct timeval tv2;

if (gettimeofday(&tv1, NULL) != 0)
abort();

for (;;) {
static volatile int i;
for (i = 0; i < 2000000; i++)
;

if (gettimeofday(&tv2, NULL) != 0)
abort();

/* janky, but we don't care */
if (tv2.tv_sec != tv1.tv_sec)
return;
}
}

static void *
thread(void *arg)
{
char name[PTHREAD_MAX_NAMELEN_NP];

for (size_t i = 0; ; i++) {
random_ascii(name, sizeof (name));

if ((i % 100) == 0) {
if (pthread_setname_np(pthread_self(), NULL) != 0)
abort();
} else {
(void) pthread_setname_np(pthread_self(), name);
}

busy();
}

return (NULL);
}

int
main(int argc, char **argv)
{
pthread_t tids[NR_THREADS];

for (size_t i = 0; i < NR_THREADS; i++) {
if (pthread_create(&tids[i], NULL, thread, NULL) != 0)
exit(EXIT_FAILURE);
}

sleep(RUNTIME);
exit(EXIT_SUCCESS);
}
@@ -0,0 +1,26 @@
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/

/*
* Copyright 2018 Joyent, Inc.
*/

#pragma D option quiet

profile-10ms /pid == $1 && threadname == "unlikely"/
{
surprising++;
}

syscall::rexit:entry /pid == $1/
{
exit(arg0);
}
@@ -21,6 +21,7 @@
# Copyright 2016 Toomas Soome <tsoome@me.com>
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
# Copyright 2018 Joyent, Inc.
#

PROG = halt
@@ -60,10 +61,10 @@ install := TARGET = install
clean := TARGET = clean
clobber := TARGET = clobber
lint := TARGET = lint
lint := LINTFLAGS = -u
lint := LINTFLAGS += -u


all: $(PROG)
all: $(PROG)

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

@@ -21,6 +21,8 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright 2018 Joyent, Inc.
*/

#include <strings.h>
@@ -33,6 +35,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <procfs.h>
#include <pthread.h>
#include "cachemgr.h"

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

(void) pthread_setname_np(pthread_self(), "chg_cleanup_thr");

if (op == NULL) {
waiting = 1;
type = CLEANUP_ALL;
@@ -21,6 +21,8 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright 2018 Joyent, Inc.
*/

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

(void) pthread_setname_np(pthread_self(), "discover");

for (;;) {
find_all_contexts("ldap",
__cache_get_cfghandle,
@@ -20,6 +20,8 @@
*/
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
*
* Copyright 2018 Joyent, Inc.
*/

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

(void) pthread_setname_np(pthread_self(), "getldap_serverinfo");

if (current_admin.debug_level >= DBG_ALL) {
logit("getldap_serverInfo_op()...\n");
}
@@ -2542,6 +2546,8 @@ getldap_refresh()
int sig_done = 0;
int dbg_level;

(void) pthread_setname_np(pthread_self(), "getldap_refresh");

if (current_admin.debug_level >= DBG_ALL) {
logit("getldap_refresh()...\n");
}
@@ -2892,6 +2898,8 @@ remove_server_thread(void *arg)
int up;
rm_svr_t rms;

(void) pthread_setname_np(pthread_self(), "remove_server");

up = contact_server(addr);

rms.addr = addr;
@@ -1303,6 +1303,23 @@ pt_regstatus(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
return (pt_regs(addr, flags, argc, argv));
}

static void
pt_thread_name(mdb_tgt_t *t, mdb_tgt_tid_t tid, char *buf, size_t bufsize)
{
char name[THREAD_NAME_MAX];

buf[0] = '\0';

if (t->t_pshandle == NULL ||
Plwp_getname(t->t_pshandle, tid, name, sizeof (name)) != 0 ||
name[0] == '\0') {
(void) mdb_snprintf(buf, bufsize, "%lu", tid);
return;
}

(void) mdb_snprintf(buf, bufsize, "%lu [%s]", tid, name);
}

static int
pt_findstack(uintptr_t tid, uint_t flags, int argc, const mdb_arg_t *argv)
{
@@ -1311,6 +1328,7 @@ pt_findstack(uintptr_t tid, uint_t flags, int argc, const mdb_arg_t *argv)
int showargs = 0;
int count;
uintptr_t pc, sp;
char name[128];

if (!(flags & DCMD_ADDRSPEC))
return (DCMD_USAGE);
@@ -1334,7 +1352,10 @@ pt_findstack(uintptr_t tid, uint_t flags, int argc, const mdb_arg_t *argv)
#else
sp = gregs.gregs[R_SP];
#endif
mdb_printf("stack pointer for thread %p: %p\n", tid, sp);

pt_thread_name(t, tid, name, sizeof (name));

mdb_printf("stack pointer for thread %s: %p\n", name, sp);
if (pc != 0)
mdb_printf("[ %0?lr %a() ]\n", sp, pc);

0 comments on commit ab61854

Please sign in to comment.
You can’t perform that action at this time.