Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/systat Use the vm.uspace sysctl instead of using the...



details:   https://anonhg.NetBSD.org/src/rev/9355b2daebcb
branches:  trunk
changeset: 975298:9355b2daebcb
user:      simonb <simonb%NetBSD.org@localhost>
date:      Wed Aug 26 10:56:01 2020 +0000

description:
Use the vm.uspace sysctl instead of using the USPACE kernel define.

diffstat:

 usr.bin/systat/ps.c |  32 ++++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 8 deletions(-)

diffs (55 lines):

diff -r 4451737eaa7a -r 9355b2daebcb usr.bin/systat/ps.c
--- a/usr.bin/systat/ps.c       Wed Aug 26 10:54:12 2020 +0000
+++ b/usr.bin/systat/ps.c       Wed Aug 26 10:56:01 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: ps.c,v 1.38 2019/02/03 10:48:47 mrg Exp $  */
+/*      $NetBSD: ps.c,v 1.39 2020/08/26 10:56:01 simonb Exp $  */
 
 /*-
  * Copyright (c) 1999
@@ -45,7 +45,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ps.c,v 1.38 2019/02/03 10:48:47 mrg Exp $");
+__RCSID("$NetBSD: ps.c,v 1.39 2020/08/26 10:56:01 simonb Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -297,14 +297,30 @@
 pmem2float(struct kinfo_proc2 *kp)
 {                             
        double fracmem;
-       int szptudot = 0;
+       static int szptudot = -1;
+
+       /*
+        * XXX want pmap ptpages, segtab, etc. (per architecture),
+        * not just the uarea.
+        */
+       if (szptudot < 0) {
+               int mib[2];
+               size_t size;
+               int uspace;
 
-#ifdef USPACE
-       /* XXX want pmap ptpages, segtab, etc. (per architecture) */
-       szptudot = USPACE/getpagesize();
-#endif
+               mib[0] = CTL_VM;
+               mib[1] = VM_USPACE;
+               size = sizeof(uspace);
+               if (sysctl(mib, 2, &uspace, &size, NULL, 0) == 0) {
+                       szptudot = uspace / getpagesize();
+               } else {
+                       /* pick a vaguely useful default */
+                       szptudot = getpagesize();
+               }
+       }
+
        /* XXX don't have info about shared */
-       fracmem = ((double)kp->p_vm_rssize + szptudot)/mempages;
+       fracmem = ((double)kp->p_vm_rssize + szptudot) / mempages;
        return (fracmem >= 0) ? 100.0 * fracmem : 0;
 }
 



Home | Main Index | Thread Index | Old Index