Add a CPUID keyword; idea and some of the code from Anon Ymous
This commit is contained in:
parent
7acc9392e5
commit
da86f0e587
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: extern.h,v 1.31 2007/09/01 16:54:39 yamt Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.32 2008/02/10 17:47:59 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
|
@ -47,6 +47,7 @@ extern VARLIST displaylist;
|
|||
extern VARLIST sortlist;
|
||||
|
||||
void command(void *, VARENT *, int);
|
||||
void cpuid(void *, VARENT *, int);
|
||||
void cputime(void *, VARENT *, int);
|
||||
int donlist(void);
|
||||
int donlist_sysctl(void);
|
||||
|
@ -82,6 +83,7 @@ void pvar(void *, VARENT *, int);
|
|||
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);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: keyword.c,v 1.51 2007/09/01 16:54:39 yamt Exp $ */
|
||||
/* $NetBSD: keyword.c,v 1.52 2008/02/10 17:47:59 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993, 1994
|
||||
|
@ -34,7 +34,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)keyword.c 8.5 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: keyword.c,v 1.51 2007/09/01 16:54:39 yamt Exp $");
|
||||
__RCSID("$NetBSD: keyword.c,v 1.52 2008/02/10 17:47:59 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -118,6 +118,7 @@ VAR var[] = {
|
|||
VAR4("comm", "COMMAND", COMM|ARGV0|LJUST, command),
|
||||
VAR4("command", "COMMAND", COMM|LJUST, command),
|
||||
PVAR("cpu", "CPU", 0, p_estcpu, UINT, "u"),
|
||||
VAR4("cpuid", "CPUID", LWP, cpuid),
|
||||
VAR3("cputime", "time", ALIAS),
|
||||
VAR6("ctime", "CTIME", 0, putimeval, POFF(p_uctime_sec), TIMEVAL),
|
||||
GID("egid", "EGID", p_gid),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: print.c,v 1.103 2007/12/31 15:31:24 ad Exp $ */
|
||||
/* $NetBSD: print.c,v 1.104 2008/02/10 17:48:00 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000, 2007 The NetBSD Foundation, Inc.
|
||||
|
@ -70,7 +70,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: print.c,v 1.103 2007/12/31 15:31:24 ad Exp $");
|
||||
__RCSID("$NetBSD: print.c,v 1.104 2008/02/10 17:48:00 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -108,6 +108,8 @@ static void intprintorsetwidth(VAR *, int, int);
|
|||
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))
|
||||
|
||||
|
@ -1006,6 +1008,50 @@ p_rssize(void *arg, VARENT *ve, int mode) /* doesn't account for text */
|
|||
intprintorsetwidth(v, pgtok(k->p_vm_rssize), mode);
|
||||
}
|
||||
|
||||
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;
|
||||
VAR *v;
|
||||
|
||||
l = arg;
|
||||
v = ve->var;
|
||||
intprintorsetwidth(v, get_cpunum(l->l_cpuid), mode);
|
||||
}
|
||||
|
||||
void
|
||||
cputime(void *arg, VARENT *ve, int mode)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: ps.1,v 1.81 2007/12/31 15:31:24 ad Exp $
|
||||
.\" $NetBSD: ps.1,v 1.82 2008/02/10 17:48:00 christos Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
|
@ -29,7 +29,7 @@
|
|||
.\"
|
||||
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
|
||||
.\"
|
||||
.Dd September 9, 2007
|
||||
.Dd Februrary 10, 2008
|
||||
.Dt PS 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -502,6 +502,8 @@ command and arguments (alias
|
|||
.Ar args )
|
||||
.It Ar cpu
|
||||
short-term CPU usage factor (for scheduling)
|
||||
.It Ar cpuid
|
||||
CPU number the current process or lwp is running on.
|
||||
.It Ar ctime
|
||||
accumulated CPU time of all children that have exited
|
||||
.It Ar egid
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ps.c,v 1.64 2007/10/24 12:10:11 yamt Exp $ */
|
||||
/* $NetBSD: ps.c,v 1.65 2008/02/10 17:48:00 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
|
@ -75,7 +75,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\n\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: ps.c,v 1.64 2007/10/24 12:10:11 yamt Exp $");
|
||||
__RCSID("$NetBSD: ps.c,v 1.65 2008/02/10 17:48:00 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
|
@ -171,6 +171,8 @@ main(int argc, char *argv[])
|
|||
else
|
||||
termwidth = ws.ws_col - 1;
|
||||
|
||||
setncpu();
|
||||
|
||||
if (argc > 1)
|
||||
argv[1] = kludge_oldps_options(argv[1]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue