summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/ps/ps.16
-rw-r--r--sys/kern/kern_clock.c22
-rw-r--r--sys/kern/kern_exec.c4
-rw-r--r--sys/kern/kern_exit.c6
-rw-r--r--sys/kern/kern_fork.c12
-rw-r--r--sys/kern/subr_prof.c22
-rw-r--r--sys/sys/proc.h6
-rw-r--r--sys/sys/systm.h7
8 files changed, 47 insertions, 38 deletions
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1
index 7356f797864..432df90e1f9 100644
--- a/bin/ps/ps.1
+++ b/bin/ps/ps.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ps.1,v 1.82 2012/04/12 06:07:33 guenther Exp $
+.\" $OpenBSD: ps.1,v 1.83 2012/08/02 03:18:48 guenther Exp $
.\" $NetBSD: ps.1,v 1.16 1996/03/21 01:36:28 jtc Exp $
.\"
.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
@@ -30,7 +30,7 @@
.\"
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
.\"
-.Dd $Mdocdate: April 12 2012 $
+.Dd $Mdocdate: August 2 2012 $
.Dt PS 1
.Os
.Sh NAME
@@ -226,7 +226,7 @@ PS_CONTROLT 0x2 process has a controlling terminal
P_SIGSUSPEND 0x8 need to restore before-suspend mask
PS_PPWAIT 0x10 parent is waiting for child to
exec/exit
-P_PROFIL 0x20 process has started profiling
+PS_PROFIL 0x20 process has started profiling
P_SELECT 0x40 selecting; wakeup/waiting danger
P_SINTR 0x80 sleep is interruptible
PS_SUGID 0x100 process had set ID privileges since
diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c
index c35ff9e95a0..843965b74c4 100644
--- a/sys/kern/kern_clock.c
+++ b/sys/kern/kern_clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_clock.c,v 1.74 2012/05/24 07:17:42 guenther Exp $ */
+/* $OpenBSD: kern_clock.c,v 1.75 2012/08/02 03:18:48 guenther Exp $ */
/* $NetBSD: kern_clock.c,v 1.34 1996/06/09 04:51:03 briggs Exp $ */
/*-
@@ -410,12 +410,12 @@ tvtohz(const struct timeval *tv)
* keeps the profile clock running constantly.
*/
void
-startprofclock(struct proc *p)
+startprofclock(struct process *pr)
{
int s;
- if ((p->p_flag & P_PROFIL) == 0) {
- atomic_setbits_int(&p->p_flag, P_PROFIL);
+ if ((pr->ps_flags & PS_PROFIL) == 0) {
+ atomic_setbits_int(&pr->ps_flags, PS_PROFIL);
if (++profprocs == 1 && stathz != 0) {
s = splstatclock();
psdiv = pscnt = psratio;
@@ -429,12 +429,12 @@ startprofclock(struct proc *p)
* Stop profiling on a process.
*/
void
-stopprofclock(struct proc *p)
+stopprofclock(struct process *pr)
{
int s;
- if (p->p_flag & P_PROFIL) {
- atomic_clearbits_int(&p->p_flag, P_PROFIL);
+ if (pr->ps_flags & PS_PROFIL) {
+ atomic_clearbits_int(&pr->ps_flags, PS_PROFIL);
if (--profprocs == 0 && stathz != 0) {
s = splstatclock();
psdiv = pscnt = 1;
@@ -458,6 +458,7 @@ statclock(struct clockframe *frame)
struct cpu_info *ci = curcpu();
struct schedstate_percpu *spc = &ci->ci_schedstate;
struct proc *p = curproc;
+ struct process *pr;
/*
* Notice changes in divisor frequency, and adjust clock
@@ -474,7 +475,8 @@ statclock(struct clockframe *frame)
}
if (CLKF_USERMODE(frame)) {
- if (p->p_flag & P_PROFIL)
+ pr = p->p_p;
+ if (pr->ps_flags & PS_PROFIL)
addupc_intr(p, CLKF_PC(frame));
if (--spc->spc_pscnt > 0)
return;
@@ -483,7 +485,7 @@ statclock(struct clockframe *frame)
* If this process is being profiled record the tick.
*/
p->p_uticks++;
- if (p->p_p->ps_nice > NZERO)
+ if (pr->ps_nice > NZERO)
spc->spc_cp_time[CP_NICE]++;
else
spc->spc_cp_time[CP_USER]++;
@@ -502,7 +504,7 @@ statclock(struct clockframe *frame)
}
#endif
#if defined(PROC_PC)
- if (p != NULL && p->p_flag & P_PROFIL)
+ if (p != NULL && p->p_p->ps_flags & PS_PROFIL)
addupc_intr(p, PROC_PC(p));
#endif
if (--spc->spc_pscnt > 0)
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index e7a2b3a53f7..4ea7a68c5cc 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exec.c,v 1.131 2012/05/01 03:21:50 guenther Exp $ */
+/* $OpenBSD: kern_exec.c,v 1.132 2012/08/02 03:18:48 guenther Exp $ */
/* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */
/*-
@@ -466,7 +466,7 @@ sys_execve(struct proc *p, void *v, register_t *retval)
if (copyout(&arginfo, (char *)PS_STRINGS, sizeof(arginfo)))
goto exec_abort;
- stopprofclock(p); /* stop profiling */
+ stopprofclock(pr); /* stop profiling */
fdcloseexec(p); /* handle close on exec */
execsigs(p); /* reset caught signals */
TCB_SET(p, NULL); /* reset the TCB address */
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index bced9841c5b..f5f1ad1debc 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exit.c,v 1.117 2012/07/11 08:45:21 guenther Exp $ */
+/* $OpenBSD: kern_exit.c,v 1.118 2012/08/02 03:18:48 guenther Exp $ */
/* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */
/*
@@ -164,11 +164,11 @@ exit1(struct proc *p, int rv, int flags)
/* main thread gotta wait because it has the pid, et al */
while (! TAILQ_EMPTY(&pr->ps_threads))
tsleep(&pr->ps_threads, PUSER, "thrdeath", 0);
+ if (pr->ps_flags & PS_PROFIL)
+ stopprofclock(pr);
} else if (TAILQ_EMPTY(&pr->ps_threads))
wakeup(&pr->ps_threads);
- if (p->p_flag & P_PROFIL)
- stopprofclock(p);
rup = pr->ps_ru;
if (rup == NULL) {
rup = pool_get(&rusage_pool, PR_WAITOK | PR_ZERO);
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 7546a5f682d..498b52605cf 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.141 2012/06/21 00:56:59 guenther Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.142 2012/08/02 03:18:48 guenther Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -349,10 +349,12 @@ fork1(struct proc *curp, int exitsig, int flags, void *stack, pid_t *tidptr,
* Duplicate sub-structures as needed.
* Increase reference counts on shared objects.
*/
- if (curp->p_flag & P_PROFIL)
- startprofclock(p);
- if (flags & FORK_PTRACE)
- atomic_setbits_int(&pr->ps_flags, curpr->ps_flags & PS_TRACED);
+ if ((flags & FORK_THREAD) == 0) {
+ if (curpr->ps_flags & PS_PROFIL)
+ startprofclock(pr);
+ if ((flags & FORK_PTRACE) && (curpr->ps_flags & PS_TRACED))
+ atomic_setbits_int(&pr->ps_flags, PS_TRACED);
+ }
/* bump references to the text vnode (for procfs) */
p->p_textvp = curp->p_textvp;
diff --git a/sys/kern/subr_prof.c b/sys/kern/subr_prof.c
index 070c632bc1a..04e5003b1f6 100644
--- a/sys/kern/subr_prof.c
+++ b/sys/kern/subr_prof.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_prof.c,v 1.20 2012/03/23 15:51:26 guenther Exp $ */
+/* $OpenBSD: subr_prof.c,v 1.21 2012/08/02 03:18:48 guenther Exp $ */
/* $NetBSD: subr_prof.c,v 1.12 1996/04/22 01:38:50 christos Exp $ */
/*-
@@ -114,9 +114,9 @@ sysctl_doprof(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
if (error)
return (error);
if (gp->state == GMON_PROF_OFF)
- stopprofclock(&proc0);
+ stopprofclock(&process0);
else
- startprofclock(&proc0);
+ startprofclock(&process0);
return (0);
case GPROF_COUNT:
return (sysctl_struct(oldp, oldlenp, newp, newlen,
@@ -152,16 +152,17 @@ sys_profil(struct proc *p, void *v, register_t *retval)
syscallarg(u_long) offset;
syscallarg(u_int) scale;
} */ *uap = v;
+ struct process *pr = p->p_p;
struct uprof *upp;
int s;
if (SCARG(uap, scale) > (1 << 16))
return (EINVAL);
if (SCARG(uap, scale) == 0) {
- stopprofclock(p);
+ stopprofclock(pr);
return (0);
}
- upp = &p->p_p->ps_prof;
+ upp = &pr->ps_prof;
/* Block profile interrupts while changing state. */
s = splstatclock();
@@ -169,7 +170,7 @@ sys_profil(struct proc *p, void *v, register_t *retval)
upp->pr_scale = SCARG(uap, scale);
upp->pr_base = (caddr_t)SCARG(uap, samples);
upp->pr_size = SCARG(uap, size);
- startprofclock(p);
+ startprofclock(pr);
splx(s);
return (0);
@@ -214,16 +215,17 @@ addupc_intr(struct proc *p, u_long pc)
void
addupc_task(struct proc *p, u_long pc, u_int nticks)
{
+ struct process *pr = p->p_p;
struct uprof *prof;
caddr_t addr;
u_int i;
u_short v;
- /* Testing P_PROFIL may be unnecessary, but is certainly safe. */
- if ((p->p_flag & P_PROFIL) == 0 || nticks == 0)
+ /* Testing PS_PROFIL may be unnecessary, but is certainly safe. */
+ if ((pr->ps_flags & PS_PROFIL) == 0 || nticks == 0)
return;
- prof = &p->p_p->ps_prof;
+ prof = &pr->ps_prof;
if (pc < prof->pr_off ||
(i = PC_TO_INDEX(pc, prof)) >= prof->pr_size)
return;
@@ -234,5 +236,5 @@ addupc_task(struct proc *p, u_long pc, u_int nticks)
if (copyout((caddr_t)&v, addr, sizeof(v)) == 0)
return;
}
- stopprofclock(p);
+ stopprofclock(pr);
}
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index b4f24dec40e..e0d8c60938d 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.h,v 1.161 2012/07/17 21:59:56 guenther Exp $ */
+/* $OpenBSD: proc.h,v 1.162 2012/08/02 03:18:48 guenther Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
@@ -368,7 +368,7 @@ struct proc {
#define P_INMEM 0x000004 /* Loaded into memory. UNUSED */
#define P_SIGSUSPEND 0x000008 /* Need to restore before-suspend mask*/
#define _P_PPWAIT 0x000010 /* Parent waits for exec/exit. */
-#define P_PROFIL 0x000020 /* Has started profiling. */
+#define _P_PROFIL 0x000020 /* Has started profiling. */
#define P_SELECT 0x000040 /* Selecting; wakeup/waiting danger. */
#define P_SINTR 0x000080 /* Sleep is interruptible. */
#define _P_SUGID 0x000100 /* Had set id privs since last exec. */
@@ -404,6 +404,7 @@ struct proc {
#ifndef _KERNEL
#define P_CONTROLT _P_CONTROLT
#define P_PPWAIT _P_PPWAIT
+#define P_PROFIL _P_PROFIL
#define P_SUGID _P_SUGID
#define P_TRACED _P_TRACED
#define P_EXEC _P_EXEC
@@ -493,6 +494,7 @@ extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
extern u_long pgrphash;
extern struct proc proc0; /* Process slot for swapper. */
+extern struct process process0; /* Process slot for kernel threads. */
extern int nprocesses, maxprocess; /* Cur and max number of processes. */
extern int nthreads, maxthread; /* Cur and max number of threads. */
extern int randompid; /* fork() should create random pid's */
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index 2c414615cd7..5dd1bfd8766 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: systm.h,v 1.90 2012/01/13 12:55:52 jsing Exp $ */
+/* $OpenBSD: systm.h,v 1.91 2012/08/02 03:18:48 guenther Exp $ */
/* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */
/*-
@@ -107,6 +107,7 @@ extern dev_t swapdev; /* swapping device */
extern struct vnode *swapdev_vp;/* vnode equivalent to above */
struct proc;
+struct process;
#define curproc curcpu()->ci_curproc
extern int rthreads_enabled;
@@ -233,8 +234,8 @@ void inittodr(time_t);
void resettodr(void);
void cpu_initclocks(void);
-void startprofclock(struct proc *);
-void stopprofclock(struct proc *);
+void startprofclock(struct process *);
+void stopprofclock(struct process *);
void setstatclockrate(int);
struct sleep_state;