Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/top/machine Instead of printing the raw cpu_id, prin...



details:   https://anonhg.NetBSD.org/src/rev/8377aa5774ee
branches:  trunk
changeset: 582095:8377aa5774ee
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jun 16 14:58:51 2005 +0000

description:
Instead of printing the raw cpu_id, print the logical cpu number. The raw
cpuid values may not be contiguous, or come in ascending order, so this
makes the cpu value of each process display match the summary display on
top.

diffstat:

 usr.bin/top/machine/m_netbsd15.c |  38 +++++++++++++++++++++++++++++++-------
 1 files changed, 31 insertions(+), 7 deletions(-)

diffs (102 lines):

diff -r 7db3cf1cdf7b -r 8377aa5774ee usr.bin/top/machine/m_netbsd15.c
--- a/usr.bin/top/machine/m_netbsd15.c  Thu Jun 16 14:56:36 2005 +0000
+++ b/usr.bin/top/machine/m_netbsd15.c  Thu Jun 16 14:58:51 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: m_netbsd15.c,v 1.22 2004/02/13 11:36:24 wiz Exp $      */
+/*     $NetBSD: m_netbsd15.c,v 1.23 2005/06/16 14:58:51 christos Exp $ */
 
 /*
  * top - a top users display for Unix
@@ -36,12 +36,12 @@
  *             Tomas Svensson <ts%unix1.net@localhost>
  *
  *
- * $Id: m_netbsd15.c,v 1.22 2004/02/13 11:36:24 wiz Exp $
+ * $Id: m_netbsd15.c,v 1.23 2005/06/16 14:58:51 christos Exp $
  */
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: m_netbsd15.c,v 1.22 2004/02/13 11:36:24 wiz Exp $");
+__RCSID("$NetBSD: m_netbsd15.c,v 1.23 2005/06/16 14:58:51 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -68,7 +68,9 @@
 #include "display.h"
 #include "loadavg.h"
 
-void percentages64 __P((int, int *, u_int64_t *, u_int64_t *, u_int64_t *));
+static void percentages64 __P((int, int *, u_int64_t *, u_int64_t *,
+    u_int64_t *));
+static int get_cpunum __P((u_int64_t));
 
 
 /* get_process_info passes back a handle.  This is what it looks like: */
@@ -120,6 +122,7 @@
 
 static int ncpu = 0;
 static u_int64_t *cp_time;
+static u_int64_t *cp_id;
 static u_int64_t *cp_old;
 static u_int64_t *cp_diff;
 
@@ -201,6 +204,17 @@
 
 #define pagetok(size) ((size) << pageshift)
 
+static int
+get_cpunum(id)
+       u_int64_t id;
+{
+       int i = 0;
+       for (i = 0; i < ncpu; i++)
+               if (id == cp_id[i])
+                       return i;
+       return -1;
+}
+
 int
 machine_init(statics)
        struct statics *statics;
@@ -230,10 +244,20 @@
                    strerror(errno));
                return(-1);
        }
+
        /* Handle old call that returned only aggregate */
        if (size == sizeof(cp_time[0]) * CPUSTATES)
                ncpu = 1;
 
+       cp_id = malloc(sizeof(cp_id[0]) * ncpu);
+       mib[0] = CTL_KERN;
+       mib[1] = KERN_CP_ID;
+       size = sizeof(cp_id[0]) * ncpu;
+       if (sysctl(mib, 2, cp_id, &size, NULL, 0) < 0) {
+               fprintf(stderr, "top: sysctl kern.cp_id failed: %s\n",
+                   strerror(errno));
+               return(-1);
+       }
        cpu_states = malloc(sizeof(cpu_states[0]) * CPUSTATES * ncpu);
        cp_old = malloc(sizeof(cp_old[0]) * CPUSTATES * ncpu);
        cp_diff = malloc(sizeof(cp_diff[0]) * CPUSTATES * ncpu);
@@ -569,8 +593,8 @@
                case LSONPROC:
                case LSRUN:
                case LSSLEEP:                   
-                       snprintf(state, sizeof(state), "%.6s/%lld", 
-                                statep, (long long)pp->p_cpuid);
+                       (void)snprintf(state, sizeof(state), "%.6s/%d", 
+                            statep, get_cpunum(pp->p_cpuid));
                        statep = state;
                        break;
                }
@@ -847,7 +871,7 @@
  *     useful on BSD mchines for calculating CPU state percentages.
  */
 
-void
+static void
 percentages64(cnt, out, new, old, diffs)
        int cnt;
        int *out;



Home | Main Index | Thread Index | Old Index