Re: svn commit: r362705 - head/bin/ps

2020-06-27 Thread Konstantin Belousov
On Sat, Jun 27, 2020 at 09:29:32PM +0200, Piotr P. Stefaniak wrote:
> On 2020-06-27 22:21:02, Konstantin Belousov wrote:
> > On Sat, Jun 27, 2020 at 07:09:33PM +, Piotr Pawel Stefaniak wrote:
> > > Author: pstef
> 
> > > @@ -1454,6 +1457,18 @@ pidmax_init(void)
> > >   xo_warn("unable to read kern.pid_max");
> > >   pid_max = 9;
> > >   }
> > > +}
> > > +
> > > +static void
> > > +smp_init(void)
> > > +{
> > > + size_t size;
> > > +
> > > + size = sizeof(smp);
> > > + if ((sysctlbyname("machdep.smp_active", &smp, &size, NULL, 0) != 0 &&
> > There is no such sysctl machdep.smp_active, and it does not make sense to
> > call it (even if it existed in some ancient FreeBSD version, I am not sure).
> 
> top(1) does that.
For top it have some limited value, from what I see, in !smpmode top does
not add the 'C' column in CPU stat mode, which saves space.  Still,
machdep.smp_active perhaps should be dropped.

> 
> > > + sysctlbyname("kern.smp.active", &smp, &size, NULL, 0) != 0) ||
> > > + size != sizeof(smp))
> > The indent on this and previous lines is wrong.
> > 
> > > + smp = 0;
> > >  }
> > That said, I do not see why do you need to check this kind of configuration
> > at all, on UP we return CPU 0 for all threads.
> 
> I'll remove it.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r362705 - head/bin/ps

2020-06-27 Thread Piotr P. Stefaniak

On 2020-06-27 22:21:02, Konstantin Belousov wrote:

On Sat, Jun 27, 2020 at 07:09:33PM +, Piotr Pawel Stefaniak wrote:

Author: pstef



@@ -1454,6 +1457,18 @@ pidmax_init(void)
xo_warn("unable to read kern.pid_max");
pid_max = 9;
}
+}
+
+static void
+smp_init(void)
+{
+   size_t size;
+
+   size = sizeof(smp);
+   if ((sysctlbyname("machdep.smp_active", &smp, &size, NULL, 0) != 0 &&

There is no such sysctl machdep.smp_active, and it does not make sense to
call it (even if it existed in some ancient FreeBSD version, I am not sure).


top(1) does that.


+   sysctlbyname("kern.smp.active", &smp, &size, NULL, 0) != 0) ||
+   size != sizeof(smp))

The indent on this and previous lines is wrong.


+   smp = 0;
 }

That said, I do not see why do you need to check this kind of configuration
at all, on UP we return CPU 0 for all threads.


I'll remove it.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r362705 - head/bin/ps

2020-06-27 Thread Konstantin Belousov
On Sat, Jun 27, 2020 at 07:09:33PM +, Piotr Pawel Stefaniak wrote:
> Author: pstef
> Date: Sat Jun 27 19:09:33 2020
> New Revision: 362705
> URL: https://svnweb.freebsd.org/changeset/base/362705
> 
> Log:
>   ps(1): reuse keyword "cpu" to show CPU number
>   
>   This flag will now show the processor number on which a process is running.
>   
>   This change was inspired by PR129965. Initially I didn't think that the
>   patch attached to it was correct -- it sacrificed ki_estcpu use in "cpu"
>   for ki_lastcpu and I thought that the old functionality should be kept and
>   the new (cpu#) one added to it. But I've since discovered that ki_estcpu is
>   sched_4bsd-specific. What's worse, it represents the same thing as
>   ki_pctcpu, except ki_pctcpu is universal -- so "%cpu" has been using it
>   successfully. Therefore, I've decided to replace information based on
>   ki_estcpu with information based on ki_oncpu/ki_lastcpu.
>   
>   Key parts of the code and manual changes were borrowed from top(1).
>   
>   PR: 129965
>   Reported by:Nikola Knežević
>   MFC after:  1 week
>   Differential Revision:  https://reviews.freebsd.org/D25377
> 
> Modified:
>   head/bin/ps/extern.h
>   head/bin/ps/keyword.c
>   head/bin/ps/print.c
>   head/bin/ps/ps.1
>   head/bin/ps/ps.c
> 
> Modified: head/bin/ps/extern.h
> ==
> --- head/bin/ps/extern.h  Sat Jun 27 18:35:00 2020(r362704)
> +++ head/bin/ps/extern.h  Sat Jun 27 19:09:33 2020(r362705)
> @@ -41,13 +41,14 @@ extern fixpt_t ccpu;
>  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 *);
> 
> Modified: head/bin/ps/keyword.c
> ==
> --- head/bin/ps/keyword.c Sat Jun 27 18:35:00 2020(r362704)
> +++ head/bin/ps/keyword.c Sat Jun 27 19:09:33 2020(r362705)
> @@ -83,8 +83,7 @@ static VAR var[] = {
>   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},
> 
> Modified: head/bin/ps/print.c
> ==
> --- head/bin/ps/print.c   Sat Jun 27 18:35:00 2020(r362704)
> +++ head/bin/ps/print.c   Sat Jun 27 19:09:33 2020(r362705)
> @@ -551,6 +551,22 @@ cputime(KINFO *k, VARENT *ve)
>  }
>  
>  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)
>  {
>   long secs, psecs;
> 
> Modified: head/bin/ps/ps.1
> ==
> --- head/bin/ps/ps.1  Sat Jun 27 18:35:00 2020(r362704)
> +++ head/bin/ps/ps.1  Sat Jun 27 19:09:33 2020(r362705)
> @@ -29,7 +29,7 @@
>  .\" @(#)ps.1 8.3 (Berkeley) 4/18/94
>  .\" $FreeBSD$
>  .\"
> -.Dd October 31, 2018
> +.Dd June 27, 2020
>  .Dt PS 1
>  .Os
>  .Sh NAME
> @@ -545,7 +545,8 @@ command and arguments
>  .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
> 
> Modified: head/bin/ps/ps.c
> ==
> --- head/bin/ps/ps.c  Sat Jun 27 18:35:00 2020(r362704)
> +++ head/bin/ps/ps.c  Sat Jun 27 19:09:33 2020(r362705)
> @@ -105,6 +105,7 @@ intrawcpu;/* -C */
>  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 = STAIL

svn commit: r362705 - head/bin/ps

2020-06-27 Thread Piotr Pawel Stefaniak
Author: pstef
Date: Sat Jun 27 19:09:33 2020
New Revision: 362705
URL: https://svnweb.freebsd.org/changeset/base/362705

Log:
  ps(1): reuse keyword "cpu" to show CPU number
  
  This flag will now show the processor number on which a process is running.
  
  This change was inspired by PR129965. Initially I didn't think that the
  patch attached to it was correct -- it sacrificed ki_estcpu use in "cpu"
  for ki_lastcpu and I thought that the old functionality should be kept and
  the new (cpu#) one added to it. But I've since discovered that ki_estcpu is
  sched_4bsd-specific. What's worse, it represents the same thing as
  ki_pctcpu, except ki_pctcpu is universal -- so "%cpu" has been using it
  successfully. Therefore, I've decided to replace information based on
  ki_estcpu with information based on ki_oncpu/ki_lastcpu.
  
  Key parts of the code and manual changes were borrowed from top(1).
  
  PR:   129965
  Reported by:  Nikola Knežević
  MFC after:1 week
  Differential Revision:https://reviews.freebsd.org/D25377

Modified:
  head/bin/ps/extern.h
  head/bin/ps/keyword.c
  head/bin/ps/print.c
  head/bin/ps/ps.1
  head/bin/ps/ps.c

Modified: head/bin/ps/extern.h
==
--- head/bin/ps/extern.hSat Jun 27 18:35:00 2020(r362704)
+++ head/bin/ps/extern.hSat Jun 27 19:09:33 2020(r362705)
@@ -41,13 +41,14 @@ extern fixpt_t ccpu;
 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 *);

Modified: head/bin/ps/keyword.c
==
--- head/bin/ps/keyword.c   Sat Jun 27 18:35:00 2020(r362704)
+++ head/bin/ps/keyword.c   Sat Jun 27 19:09:33 2020(r362705)
@@ -83,8 +83,7 @@ static VAR var[] = {
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},

Modified: head/bin/ps/print.c
==
--- head/bin/ps/print.c Sat Jun 27 18:35:00 2020(r362704)
+++ head/bin/ps/print.c Sat Jun 27 19:09:33 2020(r362705)
@@ -551,6 +551,22 @@ cputime(KINFO *k, VARENT *ve)
 }
 
 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)
 {
long secs, psecs;

Modified: head/bin/ps/ps.1
==
--- head/bin/ps/ps.1Sat Jun 27 18:35:00 2020(r362704)
+++ head/bin/ps/ps.1Sat Jun 27 19:09:33 2020(r362705)
@@ -29,7 +29,7 @@
 .\" @(#)ps.1   8.3 (Berkeley) 4/18/94
 .\" $FreeBSD$
 .\"
-.Dd October 31, 2018
+.Dd June 27, 2020
 .Dt PS 1
 .Os
 .Sh NAME
@@ -545,7 +545,8 @@ command and arguments
 .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

Modified: head/bin/ps/ps.c
==
--- head/bin/ps/ps.cSat Jun 27 18:35:00 2020(r362704)
+++ head/bin/ps/ps.cSat Jun 27 19:09:33 2020(r362705)
@@ -105,6 +105,7 @@ int  rawcpu;/* -C */
 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  saveuser(KINFO *);
 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[] = "pi