diff options
author | wpaul <wpaul@FreeBSD.org> | 1999-04-01 14:45:18 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 1999-04-01 14:45:18 +0000 |
commit | 9bde04a698227594bba14e4e2128e463dd5b3d69 (patch) | |
tree | 05aca1dddd9d2eefae2113554b7f41ca604de68f /bin | |
parent | 5724f1f4047f3bc9f63ace6399920f1d6a357ee0 (diff) | |
download | FreeBSD-src-9bde04a698227594bba14e4e2128e463dd5b3d69.zip FreeBSD-src-9bde04a698227594bba14e4e2128e463dd5b3d69.tar.gz |
On FreeBSD/alpha, ps(1) does not correctly report process start times
and CPU runtime because it can't access the user area via /proc/<pid>/mem.
This is because the uarea is not mapped into the process address space
at USRSTACK on the alpha like it is on the x86.
Since I'm haven't been able to wrap my brain around the VM system enough
to be able to figure out how to achieve this mapping, and since it's
questionable that such an architectural change is correct, I implemented
a workaround to allow ps(1) to read the uarea from /dev/kmem using
kvm_read() instead of from the process address space via kvm_uread().
The kludge is hidden inside #ifdef __alpha__/#endif so as not to impact
the x86. (Note that top(1) probably uses this same gimmick since it works
on FreeBSD/alpha.)
Reviewed by: dfr
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ps/ps.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 5bcb03c..a6a7859 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -42,7 +42,7 @@ static char const copyright[] = static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94"; #endif static const char rcsid[] = - "$Id: ps.c,v 1.24 1998/05/15 06:29:17 charnier Exp $"; + "$Id: ps.c,v 1.25 1998/06/30 21:34:14 phk Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -98,6 +98,9 @@ static void scanvars __P((void)); static void dynsizevars __P((KINFO *)); static void sizevars __P((void)); static void usage __P((void)); +#ifdef __alpha__ +static int get_uarea __P((struct proc *, struct pstats *)); +#endif char dfmt[] = "pid tt state time command"; char jfmt[] = "user pid ppid pgid sess jobc state tt time command"; @@ -453,6 +456,35 @@ fmt(fn, ki, comm, maxlen) return (s); } +#ifdef __alpha__ +/* + * This is a kludge to work around the fact that on the alpha, + * the uarea is not mapped into the process address space. + */ +static int get_uarea(p, pstats) + struct proc *p; + struct pstats *pstats; +{ + size_t offset; + static struct user ubuf; + kvm_t *mkd; + int len; + + offset = (size_t)p->p_addr; + mkd = kvm_open(NULL, NULL, NULL, 0, NULL); + if (mkd == NULL) + return(0); + len = kvm_read(mkd, offset, (char *)&ubuf, sizeof(struct user)); + kvm_close(mkd); + if (len != sizeof(struct user)) + return(0); + + bcopy((char *)&ubuf.u_stats, (char *)pstats, sizeof(struct pstats)); + + return(sizeof(struct pstats)); +} +#endif + #define UREADOK(ki) (forceuread || (KI_PROC(ki)->p_flag & P_INMEM)) static void @@ -461,11 +493,18 @@ saveuser(ki) { struct pstats pstats; struct usave *usp; +#ifndef __alpha__ struct user *u_addr = (struct user *)USRSTACK; +#endif usp = &ki->ki_u; + +#ifdef __alpha__ + if (UREADOK(ki) && get_uarea(KI_PROC(ki), &pstats) == sizeof(pstats)) { +#else if (UREADOK(ki) && kvm_uread(kd, KI_PROC(ki), (unsigned long)&u_addr->u_stats, (char *)&pstats, sizeof(pstats)) == sizeof(pstats)) { +#endif /* * The u-area might be swapped out, and we can't get * at it because we have a crashdump and no swap. |