Hi,

After removing the p_swtime from the kernel, ps always prints 0.0
as %cpu time.  The simple fix is to remove the calculation in ps
that includes the process lifetime.  Just print the p_pctcpu.

This was already done when ps -C was used, now ps always behaves
this way.

ok?

bluhm

Index: bin/ps/extern.h
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/bin/ps/extern.h,v
retrieving revision 1.16
diff -u -p -r1.16 extern.h
--- bin/ps/extern.h     29 Dec 2011 17:13:55 -0000      1.16
+++ bin/ps/extern.h     11 Jun 2015 16:38:48 -0000
@@ -37,7 +37,7 @@ struct var;
 struct varent;
 
 extern fixpt_t ccpu;
-extern int eval, fscale, nlistread, rawcpu, maxslp;
+extern int eval, fscale, nlistread, maxslp;
 extern u_int mempages;
 extern int sumrusage, termwidth, totwidth, kvm_sysctl_only, needheader;
 extern VAR var[];
Index: bin/ps/print.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/bin/ps/print.c,v
retrieving revision 1.60
diff -u -p -r1.60 print.c
--- bin/ps/print.c      15 Mar 2015 00:41:27 -0000      1.60
+++ bin/ps/print.c      11 Jun 2015 16:53:54 -0000
@@ -523,28 +523,12 @@ cputime(const struct kinfo_proc *kp, VAR
 double
 getpcpu(const struct kinfo_proc *kp)
 {
-       double d;
-
        if (fscale == 0)
                return (0.0);
 
 #define        fxtofl(fixpt)   ((double)(fixpt) / fscale)
 
-       /* XXX - I don't like this */
-       if (kp->p_swtime == 0)
-               return (0.0);
-       if (rawcpu)
-               return (100.0 * fxtofl(kp->p_pctcpu));
-
-       d = kp->p_swtime * log(fxtofl(ccpu));
-       if (d < -700.0)
-               d = 0.0;                /* avoid IEEE underflow */
-       else
-               d = exp(d);
-       if (d == 1.0)
-               return (0.0);
-       return (100.0 * fxtofl(kp->p_pctcpu) /
-               (1.0 - d));
+       return (100.0 * fxtofl(kp->p_pctcpu));
 }
 
 void
Index: bin/ps/ps.1
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/bin/ps/ps.1,v
retrieving revision 1.98
diff -u -p -r1.98 ps.1
--- bin/ps/ps.1 11 Feb 2015 00:43:33 -0000      1.98
+++ bin/ps/ps.1 28 Jun 2015 10:41:42 -0000
@@ -39,7 +39,7 @@
 .Sh SYNOPSIS
 .Nm ps
 .Sm off
-.Op Fl AaCceHhjkLlmrSTuvwx
+.Op Fl AaceHhjkLlmrSTuvwx
 .Sm on
 .Op Fl M Ar core
 .Op Fl N Ar system
@@ -76,13 +76,6 @@ Display information about processes for 
 terminals.
 .It Fl a
 Display information about processes for all users with controlling terminals.
-.It Fl C
-Change the way the CPU percentage is calculated by using a
-.Dq raw
-CPU calculation that ignores
-.Dq resident
-time (this normally has
-no effect).
 .It Fl c
 Do not display full command with arguments, but only the
 executable name.
@@ -613,7 +606,7 @@ X/Open System Interfaces option of
 .St -p1003.1-2008 .
 .Pp
 The flags
-.Op Fl CcHhjkLMmNOrSTvWwx
+.Op Fl cHhjkLMmNOrSTvWwx
 are extensions to
 .St -p1003.1-2008 .
 .Pp
Index: bin/ps/ps.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/bin/ps/ps.c,v
retrieving revision 1.64
diff -u -p -r1.64 ps.c
--- bin/ps/ps.c 9 Apr 2015 19:48:25 -0000       1.64
+++ bin/ps/ps.c 11 Jun 2015 16:39:59 -0000
@@ -60,7 +60,6 @@ extern char *__progname;
 struct varent *vhead;
 
 int    eval;                   /* exit value */
-int    rawcpu;                 /* -C */
 int    sumrusage;              /* -S */
 int    termwidth;              /* width of screen (0 == infinity) */
 int    totwidth;               /* calculated width of requested variables */
@@ -135,9 +134,6 @@ main(int argc, char *argv[])
                case 'a':
                        all = 1;
                        break;
-               case 'C':
-                       rawcpu = 1;
-                       break;
                case 'c':
                        commandonly = 1;
                        break;
@@ -477,7 +473,7 @@ static void
 usage(void)
 {
        (void)fprintf(stderr,
-           "usage: %s [-AaCceHhjkLlmrSTuvwx] [-M core] [-N system] [-O fmt] 
[-o fmt] [-p pid]\n",
+           "usage: %s [-AaceHhjkLlmrSTuvwx] [-M core] [-N system] [-O fmt] [-o 
fmt] [-p pid]\n",
            __progname);        
        (void)fprintf(stderr,
            "%-*s[-t tty] [-U username] [-W swap]\n", (int)strlen(__progname) + 
8, "");

Reply via email to