Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Fix ps(1) and top(1) to show reasonable CPU numbers i.e. cpu...
details: https://anonhg.NetBSD.org/src/rev/1e3784a1c2b2
branches: trunk
changeset: 755280:1e3784a1c2b2
user: rmind <rmind%NetBSD.org@localhost>
date: Mon May 31 03:18:33 2010 +0000
description:
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.
diffstat:
bin/ps/extern.h | 3 +-
bin/ps/print.c | 41 ++-----------------------------
bin/ps/ps.c | 6 +---
external/bsd/top/dist/machine/m_netbsd.c | 37 +++++-----------------------
4 files changed, 13 insertions(+), 74 deletions(-)
diffs (217 lines):
diff -r e29c6b67b149 -r 1e3784a1c2b2 bin/ps/extern.h
--- a/bin/ps/extern.h Mon May 31 03:16:47 2010 +0000
+++ b/bin/ps/extern.h Mon May 31 03:18:33 2010 +0000
@@ -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);
diff -r e29c6b67b149 -r 1e3784a1c2b2 bin/ps/print.c
--- a/bin/ps/print.c Mon May 31 03:16:47 2010 +0000
+++ b/bin/ps/print.c Mon May 31 03:18:33 2010 +0000
@@ -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
diff -r e29c6b67b149 -r 1e3784a1c2b2 bin/ps/ps.c
--- a/bin/ps/ps.c Mon May 31 03:16:47 2010 +0000
+++ b/bin/ps/ps.c Mon May 31 03:18:33 2010 +0000
@@ -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]);
diff -r e29c6b67b149 -r 1e3784a1c2b2 external/bsd/top/dist/machine/m_netbsd.c
--- a/external/bsd/top/dist/machine/m_netbsd.c Mon May 31 03:16:47 2010 +0000
+++ b/external/bsd/top/dist/machine/m_netbsd.c Mon May 31 03:18:33 2010 +0000
@@ -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 <ad%NetBSD.org@localhost>
*
*
- * $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;
}
Home |
Main Index |
Thread Index |
Old Index