summaryrefslogtreecommitdiffstats
path: root/usr.bin/top
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>2007-10-26 08:00:41 +0000
committerjulian <julian@FreeBSD.org>2007-10-26 08:00:41 +0000
commit11e1aa0d189878b719971121400f0678e7ccb2aa (patch)
treee047e33390a9aae820357c54ff8602bc8faad475 /usr.bin/top
parent050649d6404e24b1beaba91f04f9008ad5acd6a5 (diff)
downloadFreeBSD-src-11e1aa0d189878b719971121400f0678e7ccb2aa.zip
FreeBSD-src-11e1aa0d189878b719971121400f0678e7ccb2aa.tar.gz
Introduce a way to make pure kernal threads.
kthread_add() takes the same parameters as the old kthread_create() plus a pointer to a process structure, and adds a kernel thread to that process. kproc_kthread_add() takes the parameters for kthread_add, plus a process name and a pointer to a pointer to a process instead of just a pointer, and if the proc * is NULL, it creates the process to the specifications required, before adding the thread to it. All other old kthread_xxx() calls return, but act on (struct thread *) instead of (struct proc *). One reason to change the name is so that any old kernel modules that are lying around and expect kthread_create() to make a process will not just accidentally link. fix top to show kernel threads by their thread name in -SH mode add a tdnam formatting option to ps to show thread names. make all idle threads actual kthreads and put them into their own idled process. make all interrupt threads kthreads and put them in an interd process (mainly for aesthetic and accounting reasons) rename proc 0 to be 'kernel' and it's swapper thread is now 'swapper' man page fixes to follow.
Diffstat (limited to 'usr.bin/top')
-rw-r--r--usr.bin/top/machine.c112
1 files changed, 64 insertions, 48 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index dadb03d..cc12705 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -737,56 +737,72 @@ format_next_process(caddr_t handle, char *(*get_userid)(int), int flags)
}
if (!(flags & FMT_SHOWARGS)) {
- snprintf(cmdbuf, cmdlengthdelta, "%s", pp->ki_comm);
- }
- else if (pp->ki_args == NULL ||
- (args = kvm_getargv(kd, pp, cmdlengthdelta)) == NULL || !(*args))
- snprintf(cmdbuf, cmdlengthdelta, "[%s]", pp->ki_comm);
- else {
- char *src, *dst, *argbuf;
- char *cmd;
- size_t argbuflen;
- size_t len;
-
- argbuflen = cmdlengthdelta * 4;
- argbuf = (char *)malloc(argbuflen + 1);
- if (argbuf == NULL) {
- warn("malloc(%d)", argbuflen + 1);
- free(cmdbuf);
- return NULL;
+ if (ps.thread && pp->ki_flag & P_HADTHREADS &&
+ pp->ki_ocomm[0]) {
+ snprintf(cmdbuf, cmdlengthdelta, "{%s}", pp->ki_ocomm);
+ } else {
+ snprintf(cmdbuf, cmdlengthdelta, "%s", pp->ki_comm);
}
-
- dst = argbuf;
-
- /* Extract cmd name from argv */
- cmd = strrchr(*args, '/');
- if (cmd == NULL)
- cmd = *args;
- else
- cmd++;
-
- for (; (src = *args++) != NULL; ) {
- if (*src == '\0')
- continue;
- len = (argbuflen - (dst - argbuf) - 1) / 4;
- strvisx(dst, src, strlen(src) < len ? strlen(src) : len,
- VIS_NL | VIS_CSTYLE);
- while (*dst != '\0')
- dst++;
- if ((argbuflen - (dst - argbuf) - 1) / 4 > 0)
- *dst++ = ' '; /* add delimiting space */
+ } else {
+ if (pp->ki_flag & P_SYSTEM ||
+ pp->ki_args == NULL ||
+ (args = kvm_getargv(kd, pp, cmdlengthdelta)) == NULL ||
+ !(*args)) {
+ if (ps.thread && pp->ki_flag & P_HADTHREADS &&
+ pp->ki_ocomm[0]) {
+ snprintf(cmdbuf, cmdlengthdelta,
+ "{%s}", pp->ki_ocomm);
+ } else {
+ snprintf(cmdbuf, cmdlengthdelta,
+ "[%s]", pp->ki_comm);
+ }
+ } else {
+ char *src, *dst, *argbuf;
+ char *cmd;
+ size_t argbuflen;
+ size_t len;
+
+ argbuflen = cmdlengthdelta * 4;
+ argbuf = (char *)malloc(argbuflen + 1);
+ if (argbuf == NULL) {
+ warn("malloc(%d)", argbuflen + 1);
+ free(cmdbuf);
+ return NULL;
+ }
+
+ dst = argbuf;
+
+ /* Extract cmd name from argv */
+ cmd = strrchr(*args, '/');
+ if (cmd == NULL)
+ cmd = *args;
+ else
+ cmd++;
+
+ for (; (src = *args++) != NULL; ) {
+ if (*src == '\0')
+ continue;
+ len = (argbuflen - (dst - argbuf) - 1) / 4;
+ strvisx(dst, src,
+ strlen(src) < len ? strlen(src) : len,
+ VIS_NL | VIS_CSTYLE);
+ while (*dst != '\0')
+ dst++;
+ if ((argbuflen - (dst - argbuf) - 1) / 4 > 0)
+ *dst++ = ' '; /* add delimiting space */
+ }
+ if (dst != argbuf && dst[-1] == ' ')
+ dst--;
+ *dst = '\0';
+
+ if (strcmp(cmd, pp->ki_comm) != 0 )
+ snprintf(cmdbuf, cmdlengthdelta,
+ "%s (%s)",argbuf, pp->ki_comm);
+ else
+ strlcpy(cmdbuf, argbuf, cmdlengthdelta);
+
+ free(argbuf);
}
- if (dst != argbuf && dst[-1] == ' ')
- dst--;
- *dst = '\0';
-
- if (strcmp(cmd, pp->ki_comm) != 0 )
- snprintf(cmdbuf, cmdlengthdelta, "%s (%s)",argbuf, \
- pp->ki_comm);
- else
- strlcpy(cmdbuf, argbuf, cmdlengthdelta);
-
- free(argbuf);
}
if (ps.jail == 0)
OpenPOWER on IntegriCloud