On Thu 2018.10.04 at 15:42 +0100, Stuart Henderson wrote:
> On 2018/10/04 08:04, Okan Demirmen wrote:
> > I chose the minimal route; basically if one gets ENODEV back, the values
> > for the unavailable cpus will be 0.
> >
> > I don't use xstatbar, but is this an acceptable direction?
>
> The sysctl returns ENODEV before filling out the structure, so AIUI we would
> need to zero sysinfo.cpu_raw[cpu][cur] at this point because it does not
> contain
> valid data.
Oh yeah, agreed; though I'm unsure of the direction - a copyout would be
only convenient. This allows the average to drop over time, in this
case, xstatbar holds onto 45 iterations of data. In any case, the below
at least allows xstatbar to function...if this is the final landing spot
for CPTIME2.
Thanks!
Index: Makefile
===================================================================
RCS file: /home/open/cvs/ports/sysutils/xstatbar/Makefile,v
retrieving revision 1.19
diff -u -p -r1.19 Makefile
--- Makefile 1 Jun 2018 14:20:19 -0000 1.19
+++ Makefile 4 Oct 2018 11:56:06 -0000
@@ -5,7 +5,7 @@ ONLY_FOR_ARCHS= ${APM_ARCHS}
COMMENT= simple system monitor bar
DISTNAME= xstatbar-0.5
-REVISION= 9
+REVISION= 10
FIX_EXTRACT_PERMISSIONS=Yes
CATEGORIES= sysutils x11
Index: patches/patch-stats_c
===================================================================
RCS file: /home/open/cvs/ports/sysutils/xstatbar/patches/patch-stats_c,v
retrieving revision 1.9
diff -u -p -r1.9 patch-stats_c
--- patches/patch-stats_c 1 Jun 2018 14:20:19 -0000 1.9
+++ patches/patch-stats_c 5 Oct 2018 12:00:14 -0000
@@ -56,7 +56,22 @@ Index: stats.c
/* get swap status */
if ((nswaps = swapctl(SWAP_NSWAP, 0, 0)) == 0)
-@@ -509,9 +520,9 @@ int
+@@ -458,8 +469,12 @@ sysinfo_update()
+ mib_cpus[1] = KERN_CPTIME2;
+ for (cpu = 0; cpu < sysinfo.ncpu; cpu++) {
+ mib_cpus[2] = cpu;
+- if (sysctl(mib_cpus, 3, sysinfo.cpu_raw[cpu][cur], &size, NULL, 0) <
0)
+- err(1, "sysinfo update: KERN.CPTIME2.%d failed", cpu);
++ if (sysctl(mib_cpus, 3, sysinfo.cpu_raw[cpu][cur], &size, NULL, 0) <
0) {
++ if (errno != ENODEV)
++ err(1, "sysinfo update: KERN.CPTIME2.%d failed", cpu);
++ memset(sysinfo.cpu_raw[cpu][cur], 0,
++ CPUSTATES * sizeof(*sysinfo.cpu_raw[cpu][cur]));
++ }
+ }
+ } else {
+ int i;
+@@ -509,9 +524,9 @@ int
cpu_draw(int cpu, XColor color, int x, int y)
{
static char str[1000];
@@ -68,7 +83,7 @@ Index: stats.c
};
int state, startx, time, col, h, i;
-@@ -531,7 +542,7 @@ cpu_draw(int cpu, XColor color, int x, int y)
+@@ -531,7 +546,7 @@ cpu_draw(int cpu, XColor color, int x, int y)
/* user time */
h = 0;
@@ -77,7 +92,7 @@ Index: stats.c
h = h * XINFO.height / 100;
XSetForeground(XINFO.disp, XINFO.gc, COLOR_RED.pixel);
XDrawLine(XINFO.disp, XINFO.buf, XINFO.gc,
-@@ -540,7 +551,7 @@ cpu_draw(int cpu, XColor color, int x, int y)
+@@ -540,7 +555,7 @@ cpu_draw(int cpu, XColor color, int x, int y)
/* nice time */
h = 0;
@@ -86,7 +101,7 @@ Index: stats.c
h = h * XINFO.height / 100;
XSetForeground(XINFO.disp, XINFO.gc, COLOR_BLUE.pixel);
XDrawLine(XINFO.disp, XINFO.buf, XINFO.gc,
-@@ -549,15 +560,24 @@ cpu_draw(int cpu, XColor color, int x, int y)
+@@ -549,15 +564,24 @@ cpu_draw(int cpu, XColor color, int x, int y)
/* system time */
h = 0;
@@ -113,7 +128,7 @@ Index: stats.c
h = h * XINFO.height / 100;
XSetForeground(XINFO.disp, XINFO.gc, COLOR_MAGENTA.pixel);
XDrawLine(XINFO.disp, XINFO.buf, XINFO.gc,
-@@ -594,7 +614,8 @@ mem_draw(XColor color, int x, int y)
+@@ -594,7 +618,8 @@ mem_draw(XColor color, int x, int y)
/* determine total memory */
total = sysinfo.memory[cur][MEM_ACT]
+ sysinfo.memory[cur][MEM_TOT]
@@ -123,7 +138,7 @@ Index: stats.c
/* start drawing ... */
x += render_text(color, x, y, "mem:") + 1;
-@@ -610,7 +631,8 @@ mem_draw(XColor color, int x, int y)
+@@ -610,7 +635,8 @@ mem_draw(XColor color, int x, int y)
if ((sysinfo.memory[time][MEM_ACT] != 0)
|| (sysinfo.memory[time][MEM_TOT] != 0)
@@ -133,7 +148,7 @@ Index: stats.c
/* draw yellow (total) bar */
-@@ -627,6 +649,13 @@ mem_draw(XColor color, int x, int y)
+@@ -627,6 +653,13 @@ mem_draw(XColor color, int x, int y)
XDrawLine(XINFO.disp, XINFO.buf, XINFO.gc,
x + col, XINFO.height - h,
x + col, XINFO.height);
@@ -147,7 +162,7 @@ Index: stats.c
}
time = (time + 1) % sysinfo.hist_size;
-@@ -639,6 +668,8 @@ mem_draw(XColor color, int x, int y)
+@@ -639,6 +672,8 @@ mem_draw(XColor color, int x, int y)
x += render_text(COLOR_YELLOW, x, y, fmtmem(sysinfo.memory[cur][MEM_TOT]));
x += render_text(color, x, y, "/");
x += render_text(COLOR_GREEN, x, y, fmtmem(sysinfo.memory[cur][MEM_FRE]));
Index: patches/patch-stats_h
===================================================================
RCS file: /home/open/cvs/ports/sysutils/xstatbar/patches/patch-stats_h,v
retrieving revision 1.2
diff -u -p -r1.2 patch-stats_h
--- patches/patch-stats_h 8 Jul 2014 10:15:39 -0000 1.2
+++ patches/patch-stats_h 4 Oct 2018 11:55:51 -0000
@@ -1,7 +1,14 @@
$OpenBSD: patch-stats_h,v 1.2 2014/07/08 10:15:39 sthen Exp $
---- stats.h.orig Tue Aug 3 18:04:34 2010
-+++ stats.h Tue Jul 8 11:12:49 2014
-@@ -30,10 +30,12 @@
+Index: stats.h
+--- stats.h.orig
++++ stats.h
+@@ -25,15 +25,18 @@
+ #include <fcntl.h>
+ #include <math.h>
+ #include <err.h>
++#include <errno.h>
+
+ #include <machine/apmvar.h>
#include <sys/audioio.h>
#include <sys/ioctl.h>
#include <sys/param.h>
@@ -14,7 +21,7 @@ $OpenBSD: patch-stats_h,v 1.2 2014/07/08
#include "xstatbar.h"
-@@ -84,6 +86,7 @@ typedef struct {
+@@ -84,6 +87,7 @@ typedef struct {
#define MEM_ACT 0
#define MEM_TOT 1
#define MEM_FRE 2