Module Name: src Committed By: rmind Date: Mon May 31 03:18:33 UTC 2010
Modified Files: src/bin/ps: extern.h print.c ps.c src/external/bsd/top/dist/machine: m_netbsd.c Log Message: Fix ps(1) and top(1) to show reasonable CPU numbers i.e. cpu_index() provided by the kernel, instead of CPU order number, which is generally random. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/bin/ps/extern.h cvs rdiff -u -r1.112 -r1.113 src/bin/ps/print.c cvs rdiff -u -r1.74 -r1.75 src/bin/ps/ps.c cvs rdiff -u -r1.12 -r1.13 src/external/bsd/top/dist/machine/m_netbsd.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/ps/extern.h diff -u src/bin/ps/extern.h:1.32 src/bin/ps/extern.h:1.33 --- src/bin/ps/extern.h:1.32 Sun Feb 10 17:47:59 2008 +++ src/bin/ps/extern.h Mon May 31 03:18:33 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.32 2008/02/10 17:47:59 christos Exp $ */ +/* $NetBSD: extern.h,v 1.33 2010/05/31 03:18:33 rmind Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -83,7 +83,6 @@ void rgname(void *, VARENT *, int); void rssize(void *, VARENT *, int); void runame(void *, VARENT *, int); -void setncpu(void); void showkey(void); void started(void *, VARENT *, int); void state(void *, VARENT *, int); Index: src/bin/ps/print.c diff -u src/bin/ps/print.c:1.112 src/bin/ps/print.c:1.113 --- src/bin/ps/print.c:1.112 Wed Oct 21 21:11:57 2009 +++ src/bin/ps/print.c Mon May 31 03:18:33 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: print.c,v 1.112 2009/10/21 21:11:57 rmind Exp $ */ +/* $NetBSD: print.c,v 1.113 2010/05/31 03:18:33 rmind Exp $ */ /* * Copyright (c) 2000, 2007 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ #if 0 static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94"; #else -__RCSID("$NetBSD: print.c,v 1.112 2009/10/21 21:11:57 rmind Exp $"); +__RCSID("$NetBSD: print.c,v 1.113 2010/05/31 03:18:33 rmind Exp $"); #endif #endif /* not lint */ @@ -101,8 +101,6 @@ static void strprintorsetwidth(VAR *, const char *, int); static time_t now; -static int ncpu; -static u_int64_t *cp_id; #define min(a,b) ((a) <= (b) ? (a) : (b)) @@ -999,39 +997,6 @@ } void -setncpu(void) -{ - int mib[2]; - size_t size; - - mib[0] = CTL_HW; - mib[1] = HW_NCPU; - size = sizeof(ncpu); - if (sysctl(mib, 2, &ncpu, &size, NULL, 0) == -1) { - ncpu = 0; - return; - } - cp_id = malloc(sizeof(cp_id[0]) * ncpu); - if (cp_id == NULL) - err(1, NULL); - mib[0] = CTL_KERN; - mib[1] = KERN_CP_ID; - size = sizeof(cp_id[0]) * ncpu; - if (sysctl(mib, 2, cp_id, &size, NULL, 0) == -1) - ncpu = 0; -} - -static int -get_cpunum(u_int64_t id) -{ - int i = 0; - for (i = 0; i < ncpu; i++) - if (id == cp_id[i]) - return i; - return -1; -} - -void cpuid(void *arg, VARENT *ve, int mode) { struct kinfo_lwp *l; @@ -1039,7 +1004,7 @@ l = arg; v = ve->var; - intprintorsetwidth(v, get_cpunum(l->l_cpuid), mode); + intprintorsetwidth(v, l->l_cpuid, mode); } void Index: src/bin/ps/ps.c diff -u src/bin/ps/ps.c:1.74 src/bin/ps/ps.c:1.75 --- src/bin/ps/ps.c:1.74 Sun Mar 29 01:02:49 2009 +++ src/bin/ps/ps.c Mon May 31 03:18:33 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: ps.c,v 1.74 2009/03/29 01:02:49 mrg Exp $ */ +/* $NetBSD: ps.c,v 1.75 2010/05/31 03:18:33 rmind Exp $ */ /* * Copyright (c) 2000-2008 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ #if 0 static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94"; #else -__RCSID("$NetBSD: ps.c,v 1.74 2009/03/29 01:02:49 mrg Exp $"); +__RCSID("$NetBSD: ps.c,v 1.75 2010/05/31 03:18:33 rmind Exp $"); #endif #endif /* not lint */ @@ -169,8 +169,6 @@ else termwidth = ws.ws_col - 1; - setncpu(); - if (argc > 1) argv[1] = kludge_oldps_options(argv[1]); Index: src/external/bsd/top/dist/machine/m_netbsd.c diff -u src/external/bsd/top/dist/machine/m_netbsd.c:1.12 src/external/bsd/top/dist/machine/m_netbsd.c:1.13 --- src/external/bsd/top/dist/machine/m_netbsd.c:1.12 Wed May 12 22:09:36 2010 +++ src/external/bsd/top/dist/machine/m_netbsd.c Mon May 31 03:18:33 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: m_netbsd.c,v 1.12 2010/05/12 22:09:36 christos Exp $ */ +/* $NetBSD: m_netbsd.c,v 1.13 2010/05/31 03:18:33 rmind Exp $ */ /* * top - a top users display for Unix @@ -37,12 +37,12 @@ * Andrew Doran <a...@netbsd.org> * * - * $Id: m_netbsd.c,v 1.12 2010/05/12 22:09:36 christos Exp $ + * $Id: m_netbsd.c,v 1.13 2010/05/31 03:18:33 rmind Exp $ */ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: m_netbsd.c,v 1.12 2010/05/12 22:09:36 christos Exp $"); +__RCSID("$NetBSD: m_netbsd.c,v 1.13 2010/05/31 03:18:33 rmind Exp $"); #endif #include <sys/param.h> @@ -72,8 +72,6 @@ static void percentages64(int, int *, u_int64_t *, u_int64_t *, u_int64_t *); -static int get_cpunum(u_int64_t); - /* get_process_info passes back a handle. This is what it looks like: */ @@ -138,7 +136,6 @@ 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; @@ -300,17 +297,6 @@ return cmdbuf; } -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; @@ -347,15 +333,6 @@ 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); @@ -865,8 +842,8 @@ case LSRUN: case LSSLEEP: case LSIDL: - (void)snprintf(state, sizeof(state), "%.6s/%d", - statep, get_cpunum(pp->p_cpuid)); + (void)snprintf(state, sizeof(state), "%.6s/%lu", + statep, pp->p_cpuid); statep = state; break; } @@ -938,8 +915,8 @@ case LSRUN: case LSSLEEP: case LSIDL: - (void)snprintf(state, sizeof(state), "%.6s/%d", - statep, get_cpunum(pl->l_cpuid)); + (void)snprintf(state, sizeof(state), "%.6s/%lu", + statep, pl->l_cpuid); statep = state; break; }