summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorPaul Irofti <pirofti@cvs.openbsd.org>2012-04-12 14:59:20 +0000
committerPaul Irofti <pirofti@cvs.openbsd.org>2012-04-12 14:59:20 +0000
commitf63ee3a6ce91574448645ed33a0b6a1364e3afc5 (patch)
treeb8082a6a211be23de65284e8aa21285f859f73c3 /sys/kern
parent22c2bfb88e8c394dc20c81832688dd203d02dd8b (diff)
Add per thread accounting, mainly for usage & friends.
This expands the already bloated FILL_KPROC macro to take an extra parameter that indicates if the callee is a thread or a process. The userland bits are adjusted accordingly and ps(1) and top(1) now display per thread usage times when -H is used. Also pkill(1) had to be adjusted so that duplicates don't pop up. libkvm does basically the same thing as the kernel bits. Okay guenther@.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_sysctl.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index e577f6b1e35..c6b9cf784f3 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.219 2012/04/10 15:50:52 guenther Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.220 2012/04/12 14:59:19 pirofti Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -1458,8 +1458,20 @@ again:
goto err;
}
+ if ((p->p_flag & P_THREAD) == 0) {
+ if (buflen >= elem_size && elem_count > 0) {
+ fill_kproc(p, kproc, 0);
+ error = copyout(kproc, dp, elem_size);
+ if (error)
+ goto err;
+ dp += elem_size;
+ buflen -= elem_size;
+ elem_count--;
+ }
+ needed += elem_size;
+ }
if (buflen >= elem_size && elem_count > 0) {
- fill_kproc(p, kproc);
+ fill_kproc(p, kproc, 1);
error = copyout(kproc, dp, elem_size);
if (error)
goto err;
@@ -1494,7 +1506,7 @@ err:
* Fill in a kproc structure for the specified process.
*/
void
-fill_kproc(struct proc *p, struct kinfo_proc *ki)
+fill_kproc(struct proc *p, struct kinfo_proc *ki, int isthread)
{
struct process *pr = p->p_p;
struct session *s = pr->ps_session;
@@ -1502,7 +1514,7 @@ fill_kproc(struct proc *p, struct kinfo_proc *ki)
struct timeval ut, st;
FILL_KPROC(ki, strlcpy, p, pr, p->p_cred, p->p_ucred, pr->ps_pgrp,
- p, pr, s, p->p_vmspace, pr->ps_limit, p->p_sigacts);
+ p, pr, s, p->p_vmspace, pr->ps_limit, p->p_sigacts, isthread);
/* stuff that's too painful to generalize into the macros */
ki->p_pid = pr->ps_pid;