$NetBSD: patch-ab,v 1.7 2007/11/05 19:06:03 drochner Exp $ --- sysdeps/bsd/proctime.c.orig 2007-04-27 00:27:34.000000000 +0200 +++ sysdeps/bsd/proctime.c @@ -40,11 +40,25 @@ static const unsigned long _glibtop_sysd #define tv2sec(tv) (((guint64) tv.tv_sec * 1000000) + (guint64) tv.tv_usec) +#if defined(__NetBSD__) +static unsigned int clockrate; +static const int mib [] = { CTL_KERN, KERN_CLOCKRATE }; +#endif + /* Init function. */ void _glibtop_init_proc_time_p (glibtop *server) { +#if defined(__NetBSD__) + struct clockinfo ci; + size_t length; + length = sizeof (ci); + if (sysctl (mib, 2, &ci, &length, NULL, 0) == 0) + clockrate = ci.hz; + if (!clockrate) + clockrate = 1; /* XXX avoid div by 0 later */ +#endif server->sysdeps.proc_time = _glibtop_sysdeps_proc_time | _glibtop_sysdeps_proc_time_user; } @@ -56,7 +70,7 @@ _glibtop_init_proc_time_p (glibtop *serv * system, and interrupt time usage. */ -#if !(defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) +#if !(defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)) static void calcru(p, up, sp, ip) @@ -114,13 +128,17 @@ void glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf, pid_t pid) { +#if defined (__NetBSD__) + struct kinfo_proc2 *pinfo; +#else struct kinfo_proc *pinfo; -#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || (defined(OpenBSD) && (OpenBSD >= 199912)) +#if (defined(OpenBSD) && (OpenBSD >= 199912)) register struct rusage *rup; #else struct user *u_addr = (struct user *)USRSTACK; #endif struct pstats pstats; +#endif /* NetBSD */ int count; glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_TIME), 0); @@ -136,7 +154,12 @@ glibtop_get_proc_time_p (glibtop *server #endif /* Get the process information */ +#if defined (__NetBSD__) + pinfo = kvm_getproc2 (server->machine.kd, KERN_PROC_PID, pid, + sizeof (*pinfo), &count); +#else pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count); +#endif if ((pinfo == NULL) || (count != 1)) { glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid); return; @@ -146,14 +169,31 @@ glibtop_get_proc_time_p (glibtop *server buf->rtime = pinfo [0].ki_runtime; #elif (defined __FreeBSD__) && (__FreeBSD_version <= 500013) buf->rtime = pinfo [0].kp_proc.p_runtime; +#elif defined (__NetBSD__) + buf->rtime = pinfo[0].p_rtime_sec * clockrate + + pinfo[0].p_rtime_usec * clockrate / 1000000; + buf->frequency = clockrate; #else buf->rtime = tv2sec (pinfo [0].kp_proc.p_rtime); + buf->frequency = 1000000; #endif - buf->frequency = 1000000; buf->flags = _glibtop_sysdeps_proc_time; -#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || (defined(OpenBSD) && (OpenBSD >= 199912)) +#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) + + buf->utime = pinfo[0].p_uutime_sec * 1000000 + + pinfo[0].p_uutime_usec; + buf->stime = pinfo[0].p_ustime_sec * 1000000 + + pinfo[0].p_ustime_usec; + buf->cutime = pinfo[0].p_uctime_sec * 1000000 + + pinfo[0].p_uctime_usec; /* XXX is u+s */ + buf->cstime = 0; /* XXX */ + buf->start_time = pinfo[0].p_ustart_sec; + + buf->flags |= _glibtop_sysdeps_proc_time_user; + +#elif (defined(OpenBSD) && (OpenBSD >= 199912)) glibtop_suid_enter (server); if (kvm_read (server->machine.kd,