Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F137030237
D25377.id73635.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D25377.id73635.diff
View Options
Index: bin/ps/extern.h
===================================================================
--- bin/ps/extern.h
+++ bin/ps/extern.h
@@ -41,13 +41,14 @@
extern int cflag, eval, fscale, nlistread, rawcpu;
extern unsigned long mempages;
extern time_t now;
-extern int showthreads, sumrusage, termwidth;
+extern int showthreads, sumrusage, termwidth, smp;
extern STAILQ_HEAD(velisthead, varent) varlist;
__BEGIN_DECLS
char *arguments(KINFO *, VARENT *);
char *command(KINFO *, VARENT *);
char *cputime(KINFO *, VARENT *);
+char *cpunum(KINFO *, VARENT *);
int donlist(void);
char *elapsed(KINFO *, VARENT *);
char *elapseds(KINFO *, VARENT *);
Index: bin/ps/keyword.c
===================================================================
--- bin/ps/keyword.c
+++ bin/ps/keyword.c
@@ -83,8 +83,7 @@
CHAR, NULL, 0},
{"cow", "COW", NULL, "copy-on-write-faults", 0, kvar, KOFF(ki_cow),
UINT, "u", 0},
- {"cpu", "CPU", NULL, "cpu-usage", 0, kvar, KOFF(ki_estcpu), UINT, "d",
- 0},
+ {"cpu", "C", NULL, "on-cpu", 0, cpunum, 0, CHAR, NULL, 0},
{"cputime", "", "time", NULL, 0, NULL, 0, CHAR, NULL, 0},
{"dsiz", "DSIZ", NULL, "data-size", 0, kvar, KOFF(ki_dsize), PGTOK,
"ld", 0},
Index: bin/ps/print.c
===================================================================
--- bin/ps/print.c
+++ bin/ps/print.c
@@ -550,6 +550,22 @@
return (printtime(k, ve, secs, psecs));
}
+char *
+cpunum(KINFO *k, VARENT *ve __unused)
+{
+ char *cpu;
+
+ if (!smp)
+ return (NULL);
+
+ if (k->ki_p->ki_stat == SRUN && k->ki_p->ki_oncpu != NOCPU) {
+ asprintf(&cpu, "%d", k->ki_p->ki_oncpu);
+ } else {
+ asprintf(&cpu, "%d", k->ki_p->ki_lastcpu);
+ }
+ return (cpu);
+}
+
char *
systime(KINFO *k, VARENT *ve)
{
Index: bin/ps/ps.1
===================================================================
--- bin/ps/ps.1
+++ bin/ps/ps.1
@@ -545,7 +545,8 @@
.It Cm cow
number of copy-on-write faults
.It Cm cpu
-short-term CPU usage factor (for scheduling)
+The processor number on which the process is executing (visible only on SMP
+systems).
.It Cm dsiz
data size (in Kbytes)
.It Cm emul
Index: bin/ps/ps.c
===================================================================
--- bin/ps/ps.c
+++ bin/ps/ps.c
@@ -105,6 +105,7 @@
int sumrusage; /* -S */
int termwidth; /* Width of the screen (0 == infinity). */
int showthreads; /* will threads be shown? */
+int smp; /* multi-processor support */
struct velisthead varlist = STAILQ_HEAD_INITIALIZER(varlist);
@@ -157,6 +158,7 @@
static void scanvars(void);
static void sizevars(void);
static void pidmax_init(void);
+static void smp_init(void);
static void usage(void);
static char dfmt[] = "pid,tt,state,time,command";
@@ -226,6 +228,7 @@
argv[1] = kludge_oldps_options(PS_ARGS, argv[1], argv[2]);
pidmax_init();
+ smp_init();
all = descendancy = _fmt = nselectors = optfatal = 0;
prtheader = showthreads = wflag = xkeep_implied = 0;
@@ -1456,6 +1459,18 @@
}
}
+static void
+smp_init(void)
+{
+ size_t size;
+
+ size = sizeof(smp);
+ if ((sysctlbyname("machdep.smp_active", &smp, &size, NULL, 0) != 0 &&
+ sysctlbyname("kern.smp.active", &smp, &size, NULL, 0) != 0) ||
+ size != sizeof(smp))
+ smp = 0;
+}
+
static void __dead2
usage(void)
{
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 22, 12:39 AM (2 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25764062
Default Alt Text
D25377.id73635.diff (3 KB)
Attached To
Mode
D25377: ps(1): reuse keyword "cpu" to show CPU number
Attached
Detach File
Event Timeline
Log In to Comment