Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Dec 2016 15:04:22 +0000 (UTC)
From:      Eric van Gyzen <vangyzen@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r309676 - in head: bin/ps lib/libkvm sys/compat/freebsd32 sys/kern sys/sys usr.bin/procstat usr.bin/top
Message-ID:  <201612071504.uB7F4MCi020382@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: vangyzen
Date: Wed Dec  7 15:04:22 2016
New Revision: 309676
URL: https://svnweb.freebsd.org/changeset/base/309676

Log:
  Export the whole thread name in kinfo_proc
  
  kinfo_proc::ki_tdname is three characters shorter than
  thread::td_name.  Add a ki_moretdname field for these three
  extra characters.  Add the new field to kinfo_proc32, as well.
  Update all in-tree consumers to read the new field and assemble
  the full name, except for lldb's HostThreadFreeBSD.cpp, which
  I will handle separately.  Bump __FreeBSD_version.
  
  Reviewed by:	kib
  MFC after:	1 week
  Relnotes:	yes
  Sponsored by:	Dell EMC
  Differential Revision:	https://reviews.freebsd.org/D8722

Modified:
  head/bin/ps/print.c
  head/lib/libkvm/kvm_proc.c
  head/sys/compat/freebsd32/freebsd32.h
  head/sys/kern/kern_proc.c
  head/sys/sys/param.h
  head/sys/sys/user.h
  head/usr.bin/procstat/procstat.c
  head/usr.bin/procstat/procstat.h
  head/usr.bin/procstat/procstat_cs.c
  head/usr.bin/procstat/procstat_kstack.c
  head/usr.bin/procstat/procstat_threads.c
  head/usr.bin/top/machine.c

Modified: head/bin/ps/print.c
==============================================================================
--- head/bin/ps/print.c	Wed Dec  7 14:35:05 2016	(r309675)
+++ head/bin/ps/print.c	Wed Dec  7 15:04:22 2016	(r309676)
@@ -120,11 +120,12 @@ command(KINFO *k, VARENT *ve)
 	if (cflag) {
 		/* If it is the last field, then don't pad */
 		if (STAILQ_NEXT(ve, next_ve) == NULL) {
-			asprintf(&str, "%s%s%s%s",
+			asprintf(&str, "%s%s%s%s%s",
 			    k->ki_d.prefix ? k->ki_d.prefix : "",
 			    k->ki_p->ki_comm,
 			    (showthreads && k->ki_p->ki_numthreads > 1) ? "/" : "",
-			    (showthreads && k->ki_p->ki_numthreads > 1) ? k->ki_p->ki_tdname : "");
+			    (showthreads && k->ki_p->ki_numthreads > 1) ? k->ki_p->ki_tdname : "",
+			    (showthreads && k->ki_p->ki_numthreads > 1) ? k->ki_p->ki_moretdname : "");
 		} else
 			str = strdup(k->ki_p->ki_comm);
 
@@ -172,14 +173,16 @@ ucomm(KINFO *k, VARENT *ve)
 	char *str;
 
 	if (STAILQ_NEXT(ve, next_ve) == NULL) {	/* last field, don't pad */
-		asprintf(&str, "%s%s%s%s",
+		asprintf(&str, "%s%s%s%s%s",
 		    k->ki_d.prefix ? k->ki_d.prefix : "",
 		    k->ki_p->ki_comm,
 		    (showthreads && k->ki_p->ki_numthreads > 1) ? "/" : "",
-		    (showthreads && k->ki_p->ki_numthreads > 1) ? k->ki_p->ki_tdname : "");
+		    (showthreads && k->ki_p->ki_numthreads > 1) ? k->ki_p->ki_tdname : "",
+		    (showthreads && k->ki_p->ki_numthreads > 1) ? k->ki_p->ki_moretdname : "");
 	} else {
 		if (showthreads && k->ki_p->ki_numthreads > 1)
-			asprintf(&str, "%s/%s", k->ki_p->ki_comm, k->ki_p->ki_tdname);
+			asprintf(&str, "%s/%s%s", k->ki_p->ki_comm,
+			    k->ki_p->ki_tdname, k->ki_p->ki_moretdname);
 		else
 			str = strdup(k->ki_p->ki_comm);
 	}
@@ -192,7 +195,8 @@ tdnam(KINFO *k, VARENT *ve __unused)
 	char *str;
 
 	if (showthreads && k->ki_p->ki_numthreads > 1)
-		str = strdup(k->ki_p->ki_tdname);
+		asprintf(&str, "%s%s", k->ki_p->ki_tdname,
+		    k->ki_p->ki_moretdname);
 	else
 		str = strdup("      ");
 

Modified: head/lib/libkvm/kvm_proc.c
==============================================================================
--- head/lib/libkvm/kvm_proc.c	Wed Dec  7 14:35:05 2016	(r309675)
+++ head/lib/libkvm/kvm_proc.c	Wed Dec  7 15:04:22 2016	(r309676)
@@ -426,8 +426,6 @@ nopgrp:
 			kp->ki_pri.pri_native = mtd.td_base_pri;
 			kp->ki_lastcpu = mtd.td_lastcpu;
 			kp->ki_wchan = mtd.td_wchan;
-			if (mtd.td_name[0] != 0)
-				strlcpy(kp->ki_tdname, mtd.td_name, MAXCOMLEN);
 			kp->ki_oncpu = mtd.td_oncpu;
 			if (mtd.td_name[0] != '\0')
 				strlcpy(kp->ki_tdname, mtd.td_name, sizeof(kp->ki_tdname));

Modified: head/sys/compat/freebsd32/freebsd32.h
==============================================================================
--- head/sys/compat/freebsd32/freebsd32.h	Wed Dec  7 14:35:05 2016	(r309675)
+++ head/sys/compat/freebsd32/freebsd32.h	Wed Dec  7 15:04:22 2016	(r309676)
@@ -315,7 +315,8 @@ struct kinfo_proc32 {
 	char	ki_comm[COMMLEN+1];
 	char	ki_emul[KI_EMULNAMELEN+1];
 	char	ki_loginclass[LOGINCLASSLEN+1];
-	char	ki_sparestrings[50];
+	char	ki_moretdname[MAXCOMLEN-TDNAMLEN+1];
+	char	ki_sparestrings[46];
 	int	ki_spareints[KI_NSPARE_INT];
 	int	ki_oncpu;
 	int	ki_lastcpu;

Modified: head/sys/kern/kern_proc.c
==============================================================================
--- head/sys/kern/kern_proc.c	Wed Dec  7 14:35:05 2016	(r309675)
+++ head/sys/kern/kern_proc.c	Wed Dec  7 15:04:22 2016	(r309676)
@@ -1020,7 +1020,14 @@ fill_kinfo_thread(struct thread *td, str
 		strlcpy(kp->ki_wmesg, td->td_wmesg, sizeof(kp->ki_wmesg));
 	else
 		bzero(kp->ki_wmesg, sizeof(kp->ki_wmesg));
-	strlcpy(kp->ki_tdname, td->td_name, sizeof(kp->ki_tdname));
+	if (strlcpy(kp->ki_tdname, td->td_name, sizeof(kp->ki_tdname)) >=
+	    sizeof(kp->ki_tdname)) {
+		strlcpy(kp->ki_moretdname,
+		    td->td_name + sizeof(kp->ki_tdname) - 1,
+		    sizeof(kp->ki_moretdname));
+	} else {
+		bzero(kp->ki_moretdname, sizeof(kp->ki_moretdname));
+	}
 	if (TD_ON_LOCK(td)) {
 		kp->ki_kiflag |= KI_LOCKBLOCK;
 		strlcpy(kp->ki_lockname, td->td_lockname,
@@ -1265,6 +1272,7 @@ freebsd32_kinfo_proc_out(const struct ki
 	bcopy(ki->ki_comm, ki32->ki_comm, COMMLEN + 1);
 	bcopy(ki->ki_emul, ki32->ki_emul, KI_EMULNAMELEN + 1);
 	bcopy(ki->ki_loginclass, ki32->ki_loginclass, LOGINCLASSLEN + 1);
+	bcopy(ki->ki_moretdname, ki32->ki_moretdname, MAXCOMLEN - TDNAMLEN + 1);
 	CP(*ki, *ki32, ki_tracer);
 	CP(*ki, *ki32, ki_flag2);
 	CP(*ki, *ki32, ki_fibnum);

Modified: head/sys/sys/param.h
==============================================================================
--- head/sys/sys/param.h	Wed Dec  7 14:35:05 2016	(r309675)
+++ head/sys/sys/param.h	Wed Dec  7 15:04:22 2016	(r309676)
@@ -58,7 +58,7 @@
  *		in the range 5 to 9.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 1200017	/* Master, propagated to newvers */
+#define __FreeBSD_version 1200018	/* Master, propagated to newvers */
 
 /*
  * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,

Modified: head/sys/sys/user.h
==============================================================================
--- head/sys/sys/user.h	Wed Dec  7 14:35:05 2016	(r309675)
+++ head/sys/sys/user.h	Wed Dec  7 15:04:22 2016	(r309676)
@@ -180,12 +180,13 @@ struct kinfo_proc {
 	char	ki_comm[COMMLEN+1];	/* command name */
 	char	ki_emul[KI_EMULNAMELEN+1];  /* emulation name */
 	char	ki_loginclass[LOGINCLASSLEN+1]; /* login class */
+	char	ki_moretdname[MAXCOMLEN-TDNAMLEN+1];	/* more thread name */
 	/*
 	 * When adding new variables, take space for char-strings from the
 	 * front of ki_sparestrings, and ints from the end of ki_spareints.
 	 * That way the spare room from both arrays will remain contiguous.
 	 */
-	char	ki_sparestrings[50];	/* spare string space */
+	char	ki_sparestrings[46];	/* spare string space */
 	int	ki_spareints[KI_NSPARE_INT];	/* spare room for growth */
 	int	ki_oncpu;		/* Which cpu we are on */
 	int	ki_lastcpu;		/* Last cpu we were on */

Modified: head/usr.bin/procstat/procstat.c
==============================================================================
--- head/usr.bin/procstat/procstat.c	Wed Dec  7 14:35:05 2016	(r309675)
+++ head/usr.bin/procstat/procstat.c	Wed Dec  7 15:04:22 2016	(r309676)
@@ -35,6 +35,7 @@
 #include <libprocstat.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sysexits.h>
 #include <unistd.h>
 
@@ -126,6 +127,21 @@ kinfo_proc_sort(struct kinfo_proc *kipp,
 	qsort(kipp, count, sizeof(*kipp), kinfo_proc_compare);
 }
 
+const char *
+kinfo_proc_thread_name(const struct kinfo_proc *kipp)
+{
+	static char name[MAXCOMLEN+1];
+
+	strlcpy(name, kipp->ki_tdname, sizeof(name));
+	strlcat(name, kipp->ki_moretdname, sizeof(name));
+	if (name[0] == '\0' || strcmp(kipp->ki_comm, name) == 0) {
+		name[0] = '-';
+		name[1] = '\0';
+	}
+
+	return (name);
+}
+
 int
 main(int argc, char *argv[])
 {

Modified: head/usr.bin/procstat/procstat.h
==============================================================================
--- head/usr.bin/procstat/procstat.h	Wed Dec  7 14:35:05 2016	(r309675)
+++ head/usr.bin/procstat/procstat.h	Wed Dec  7 15:04:22 2016	(r309676)
@@ -38,6 +38,7 @@ extern int	hflag, nflag, Cflag, Hflag;
 
 struct kinfo_proc;
 void	kinfo_proc_sort(struct kinfo_proc *kipp, int count);
+const char *	kinfo_proc_thread_name(const struct kinfo_proc *kipp);
 
 void	procstat_args(struct procstat *prstat, struct kinfo_proc *kipp);
 void	procstat_auxv(struct procstat *prstat, struct kinfo_proc *kipp);

Modified: head/usr.bin/procstat/procstat_cs.c
==============================================================================
--- head/usr.bin/procstat/procstat_cs.c	Wed Dec  7 14:35:05 2016	(r309675)
+++ head/usr.bin/procstat/procstat_cs.c	Wed Dec  7 15:04:22 2016	(r309676)
@@ -53,7 +53,7 @@ procstat_cs(struct procstat *procstat, s
 	int once, twice, lastcpu, cpu;
 
 	if (!hflag)
-		xo_emit("{T:/%5s %6s %-16s %-16s %2s %4s %-7s}\n", "PID",
+		xo_emit("{T:/%5s %6s %-19s %-19s %2s %4s %-7s}\n", "PID",
 		    "TID", "COMM", "TDNAME", "CPU", "CSID", "CPU MASK");
 
 	kip = procstat_getprocs(procstat, KERN_PROC_PID | KERN_PROC_INC_THREAD,
@@ -65,11 +65,10 @@ procstat_cs(struct procstat *procstat, s
 		kipp = &kip[i];
 		xo_emit("{k:process_id/%5d/%d} ", kipp->ki_pid);
 		xo_emit("{:thread_id/%6d/%d} ", kipp->ki_tid);
-		xo_emit("{:command/%-16s/%s} ", strlen(kipp->ki_comm) ?
+		xo_emit("{:command/%-19s/%s} ", strlen(kipp->ki_comm) ?
 		    kipp->ki_comm : "-");
-		xo_emit("{:thread_name/%-16s/%s} ", (strlen(kipp->ki_tdname) &&
-		    (strcmp(kipp->ki_comm, kipp->ki_tdname) != 0)) ?
-		    kipp->ki_tdname : "-");
+		xo_emit("{:thread_name/%-19s/%s} ",
+                    kinfo_proc_thread_name(kipp));
 		if (kipp->ki_oncpu != 255)
 			xo_emit("{:cpu/%3d/%d} ", kipp->ki_oncpu);
 		else if (kipp->ki_lastcpu != 255)

Modified: head/usr.bin/procstat/procstat_kstack.c
==============================================================================
--- head/usr.bin/procstat/procstat_kstack.c	Wed Dec  7 14:35:05 2016	(r309675)
+++ head/usr.bin/procstat/procstat_kstack.c	Wed Dec  7 15:04:22 2016	(r309676)
@@ -171,7 +171,7 @@ procstat_kstack(struct procstat *procsta
 	unsigned int kip_count, kstk_count;
 
 	if (!hflag)
-		xo_emit("{T:/%5s %6s %-16s %-16s %-29s}\n", "PID", "TID", "COMM",
+		xo_emit("{T:/%5s %6s %-19s %-19s %-29s}\n", "PID", "TID", "COMM",
 		    "TDNAME", "KSTACK");
 
 	kkstp = kkstp_free = procstat_getkstack(procstat, kipp, &kstk_count);
@@ -208,10 +208,9 @@ procstat_kstack(struct procstat *procsta
 
 		xo_emit("{k:process_id/%5d/%d} ", kipp->ki_pid);
 		xo_emit("{:thread_id/%6d/%d} ", kkstp->kkst_tid);
-		xo_emit("{:command/%-16s/%s} ", kipp->ki_comm);
-		xo_emit("{:thread_name/%-16s/%s} ", (strlen(kipp->ki_tdname) &&
-		    (strcmp(kipp->ki_comm, kipp->ki_tdname) != 0)) ?
-		    kipp->ki_tdname : "-");
+		xo_emit("{:command/%-19s/%s} ", kipp->ki_comm);
+		xo_emit("{:thread_name/%-19s/%s} ",
+                    kinfo_proc_thread_name(kipp));
 
 		switch (kkstp->kkst_state) {
 		case KKST_STATE_RUNNING:

Modified: head/usr.bin/procstat/procstat_threads.c
==============================================================================
--- head/usr.bin/procstat/procstat_threads.c	Wed Dec  7 14:35:05 2016	(r309675)
+++ head/usr.bin/procstat/procstat_threads.c	Wed Dec  7 15:04:22 2016	(r309676)
@@ -49,7 +49,7 @@ procstat_threads(struct procstat *procst
 	char *threadid;
 
 	if (!hflag)
-		xo_emit("{T:/%5s %6s %-16s %-16s %2s %4s %-7s %-9s}\n", "PID",
+		xo_emit("{T:/%5s %6s %-19s %-19s %2s %4s %-7s %-9s}\n", "PID",
 		    "TID", "COMM", "TDNAME", "CPU", "PRI", "STATE", "WCHAN");
 
 	xo_emit("{ek:process_id/%d}", kipp->ki_pid);
@@ -71,11 +71,10 @@ procstat_threads(struct procstat *procst
 		xo_open_container(threadid);
 		xo_emit("{dk:process_id/%5d/%d} ", kipp->ki_pid);
 		xo_emit("{:thread_id/%6d/%d} ", kipp->ki_tid);
-		xo_emit("{d:command/%-16s/%s} ", strlen(kipp->ki_comm) ?
+		xo_emit("{d:command/%-19s/%s} ", strlen(kipp->ki_comm) ?
 		    kipp->ki_comm : "-");
-		xo_emit("{:thread_name/%-16s/%s} ", (strlen(kipp->ki_tdname) &&
-		    (strcmp(kipp->ki_comm, kipp->ki_tdname) != 0)) ?
-		    kipp->ki_tdname : "-");
+		xo_emit("{:thread_name/%-19s/%s} ",
+		    kinfo_proc_thread_name(kipp));
 		if (kipp->ki_oncpu != 255)
 			xo_emit("{:cpu/%3d/%d} ", kipp->ki_oncpu);
 		else if (kipp->ki_lastcpu != 255)

Modified: head/usr.bin/top/machine.c
==============================================================================
--- head/usr.bin/top/machine.c	Wed Dec  7 14:35:05 2016	(r309675)
+++ head/usr.bin/top/machine.c	Wed Dec  7 15:04:22 2016	(r309676)
@@ -991,8 +991,8 @@ format_next_process(caddr_t handle, char
 	if (!(flags & FMT_SHOWARGS)) {
 		if (ps.thread && pp->ki_flag & P_HADTHREADS &&
 		    pp->ki_tdname[0]) {
-			snprintf(cmdbuf, cmdlen, "%s{%s}", pp->ki_comm,
-			    pp->ki_tdname);
+			snprintf(cmdbuf, cmdlen, "%s{%s%s}", pp->ki_comm,
+			    pp->ki_tdname, pp->ki_moretdname);
 		} else {
 			snprintf(cmdbuf, cmdlen, "%s", pp->ki_comm);
 		}
@@ -1004,7 +1004,8 @@ format_next_process(caddr_t handle, char
 			if (ps.thread && pp->ki_flag & P_HADTHREADS &&
 		    	    pp->ki_tdname[0]) {
 				snprintf(cmdbuf, cmdlen,
-				    "[%s{%s}]", pp->ki_comm, pp->ki_tdname);
+				    "[%s{%s%s}]", pp->ki_comm, pp->ki_tdname,
+				    pp->ki_moretdname);
 			} else {
 				snprintf(cmdbuf, cmdlen,
 				    "[%s]", pp->ki_comm);
@@ -1052,8 +1053,9 @@ format_next_process(caddr_t handle, char
 				if (ps.thread && pp->ki_flag & P_HADTHREADS &&
 				    pp->ki_tdname[0])
 					snprintf(cmdbuf, cmdlen,
-					    "%s (%s){%s}", argbuf, pp->ki_comm,
-					    pp->ki_tdname);
+					    "%s (%s){%s%s}", argbuf,
+					    pp->ki_comm, pp->ki_tdname,
+					    pp->ki_moretdname);
 				else
 					snprintf(cmdbuf, cmdlen,
 					    "%s (%s)", argbuf, pp->ki_comm);
@@ -1061,7 +1063,8 @@ format_next_process(caddr_t handle, char
 				if (ps.thread && pp->ki_flag & P_HADTHREADS &&
 				    pp->ki_tdname[0])
 					snprintf(cmdbuf, cmdlen,
-					    "%s{%s}", argbuf, pp->ki_tdname);
+					    "%s{%s%s}", argbuf, pp->ki_tdname,
+					    pp->ki_moretdname);
 				else
 					strlcpy(cmdbuf, argbuf, cmdlen);
 			}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201612071504.uB7F4MCi020382>