Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/systat PR/53906: Paul Ripke: systat(1) vmstat & sysc...



details:   https://anonhg.NetBSD.org/src/rev/1411f275cd85
branches:  trunk
changeset: 448191:1411f275cd85
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jan 25 15:31:11 2019 +0000

description:
PR/53906: Paul Ripke: systat(1) vmstat & syscall get
"alternate system clock has died" on terminal resize (SIGWINCH)

diffstat:

 usr.bin/systat/extern.h  |   7 ++++++-
 usr.bin/systat/iostat.c  |   5 ++---
 usr.bin/systat/main.c    |  35 ++++++++++++++++++++++++++++++++---
 usr.bin/systat/syscall.c |  23 +++--------------------
 usr.bin/systat/vmstat.c  |  24 ++++--------------------
 5 files changed, 47 insertions(+), 47 deletions(-)

diffs (279 lines):

diff -r dd8bd4de5007 -r 1411f275cd85 usr.bin/systat/extern.h
--- a/usr.bin/systat/extern.h   Fri Jan 25 14:29:05 2019 +0000
+++ b/usr.bin/systat/extern.h   Fri Jan 25 15:31:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.46 2016/10/22 22:02:55 christos Exp $     */
+/*     $NetBSD: extern.h,v 1.47 2019/01/25 15:31:11 christos Exp $     */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -33,10 +33,12 @@
 
 #include <sys/cdefs.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <kvm.h>
 
 #define ADJINETCTR(c, o, n, e) (c.e = n.e - o.e)
 #define xADJINETCTR(c, o, n, e)        (c[e] = n[e] - o[e])
+#define MAXFAIL        5
 
 extern struct  command global_commands[];
 extern struct  mode *curmode;
@@ -60,6 +62,8 @@
 extern int     allflag;
 extern int     turns;
 extern gid_t   egid;
+extern float   hertz;
+extern double  etime;
 
 struct inpcb;
 #ifdef INET6
@@ -210,6 +214,7 @@
 void    tcp_run(char *);
 void    tcp_time(char *);
 void    tcp_zero(char *);
+bool    toofast(int *);
 void    vmstat_boot(char *);
 void    vmstat_run(char *);
 void    vmstat_time(char *);
diff -r dd8bd4de5007 -r 1411f275cd85 usr.bin/systat/iostat.c
--- a/usr.bin/systat/iostat.c   Fri Jan 25 14:29:05 2019 +0000
+++ b/usr.bin/systat/iostat.c   Fri Jan 25 15:31:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iostat.c,v 1.38 2017/07/15 08:22:23 mlelstv Exp $      */
+/*     $NetBSD: iostat.c,v 1.39 2019/01/25 15:31:11 christos Exp $     */
 
 /*
  * Copyright (c) 1980, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)iostat.c   8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: iostat.c,v 1.38 2017/07/15 08:22:23 mlelstv Exp $");
+__RCSID("$NetBSD: iostat.c,v 1.39 2019/01/25 15:31:11 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -46,7 +46,6 @@
 #include "drvstats.h"
 
 static  int linesperregion;
-static double etime;
 static  int numbers = 0;               /* default display bar graphs */
 static  int secs = 0;                  /* default seconds shown */
 static  int read_write = 0;            /* default read/write shown */
diff -r dd8bd4de5007 -r 1411f275cd85 usr.bin/systat/main.c
--- a/usr.bin/systat/main.c     Fri Jan 25 14:29:05 2019 +0000
+++ b/usr.bin/systat/main.c     Fri Jan 25 15:31:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.54 2018/12/26 01:47:37 sevan Exp $  */
+/*     $NetBSD: main.c,v 1.55 2019/01/25 15:31:11 christos Exp $       */
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -36,7 +36,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: main.c,v 1.54 2018/12/26 01:47:37 sevan Exp $");
+__RCSID("$NetBSD: main.c,v 1.55 2019/01/25 15:31:11 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -57,6 +57,7 @@
 
 #include "systat.h"
 #include "extern.h"
+#include "drvstats.h"
 
 static int     dellave;
 
@@ -78,6 +79,8 @@
 int     allflag;
 int     allcounter;
 sig_atomic_t needsredraw = 0;
+float  hertz;
+double etime;
 
 static WINDOW *wload;                  /* one line window for load average */
 
@@ -332,7 +335,6 @@
 void
 redraw(void)
 {
-       resizeterm(LINES, COLS);
        CMDLINE = LINES - 1;
        labels();
 
@@ -417,3 +419,30 @@
        endwin();
        exit(1);
 }
+
+bool
+toofast(int *failcnt)
+{
+       static char pigs[] = "pigs";
+       etime = cur.cp_etime;
+       /* < 1 ticks - sleep for a tick */
+       /* this is often triggered by repeated SIGWINCH */
+       if ((etime * hertz) >= 1.0)
+               return false;
+
+       if ((*failcnt)++ <= MAXFAIL) {
+               struct timespec interval = { 0, 1000000000L / hertz };
+               while (nanosleep(&interval, &interval) == -1)
+                       continue;
+               return true;
+       }
+       clear();
+       mvprintw(2, 10, "The alternate system clock has died!");
+       mvprintw(3, 10, "Reverting to ``pigs'' display.");
+       move(CMDLINE, 0);
+       refresh();
+       failcnt = 0;
+       sleep(5);
+       command(pigs);
+       return true;
+}
diff -r dd8bd4de5007 -r 1411f275cd85 usr.bin/systat/syscall.c
--- a/usr.bin/systat/syscall.c  Fri Jan 25 14:29:05 2019 +0000
+++ b/usr.bin/systat/syscall.c  Fri Jan 25 15:31:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: syscall.c,v 1.9 2014/02/19 20:42:14 dsl Exp $  */
+/*     $NetBSD: syscall.c,v 1.10 2019/01/25 15:31:11 christos Exp $    */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: syscall.c,v 1.9 2014/02/19 20:42:14 dsl Exp $");
+__RCSID("$NetBSD: syscall.c,v 1.10 2019/01/25 15:31:11 christos Exp $");
 
 /* System call stats */
 
@@ -75,7 +75,6 @@
 static void getinfo(struct Info *, int);
 
 static char buf[32];
-static float hertz;
 
 static size_t counts_mib_len, times_mib_len;
 static int counts_mib[4], times_mib[4];
@@ -146,8 +145,6 @@
        labelvmstat_top();
 }
 
-#define MAXFAIL 5
-
 static void
 putuint64(uint64_t v, int row, int col, int width)
 {
@@ -186,7 +183,6 @@
        uint64_t v;
        static int failcnt = 0;
        static int relabel = 0;
-       static char pigs[] = "pigs";
        uint64_t itime;
 
        if (relabel) {
@@ -196,21 +192,8 @@
 
        cpuswap();
        if (display_mode == TIME) {
-               etime = cur.cp_etime;
-               /* < 5 ticks - ignore this trash */
-               if ((etime * hertz) < 1.0) {
-                       if (failcnt++ <= MAXFAIL)
-                               return;
-                       clear();
-                       mvprintw(2, 10, "The alternate system clock has died!");
-                       mvprintw(3, 10, "Reverting to ``pigs'' display.");
-                       move(CMDLINE, 0);
-                       refresh();
-                       failcnt = 0;
-                       sleep(5);
-                       command(pigs);
+               if (toofast(&failcnt))
                        return;
-               }
        } else
                etime = 1.0;
        itime = etime * 100;
diff -r dd8bd4de5007 -r 1411f275cd85 usr.bin/systat/vmstat.c
--- a/usr.bin/systat/vmstat.c   Fri Jan 25 14:29:05 2019 +0000
+++ b/usr.bin/systat/vmstat.c   Fri Jan 25 15:31:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmstat.c,v 1.84 2019/01/08 08:22:20 tih Exp $  */
+/*     $NetBSD: vmstat.c,v 1.85 2019/01/25 15:31:11 christos Exp $     */
 
 /*-
  * Copyright (c) 1983, 1989, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)vmstat.c   8.2 (Berkeley) 1/12/94";
 #endif
-__RCSID("$NetBSD: vmstat.c,v 1.84 2019/01/08 08:22:20 tih Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.85 2019/01/25 15:31:11 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -53,6 +53,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <util.h>
+#include <curses.h>
 
 #include "systat.h"
 #include "extern.h"
@@ -80,8 +81,6 @@
 
 static char buf[26];
 static u_int64_t temp;
-double etime;
-static float hertz;
 static int nintr;
 static long *intrloc;
 static char **intrname;
@@ -415,7 +414,6 @@
                        {temp = (s).fld; (s).fld -= (s1).fld; \
                        if (display_mode == TIME) (s1).fld = temp; \
                        putint((int)((float)(s).fld/etime + 0.5), l, c, w);}
-#define MAXFAIL 5
 
 static char cpuchar[CPUSTATES] = { '=' , '>', '-', '%', ' ' };
 static char cpuorder[CPUSTATES] = { CP_SYS, CP_USER, CP_NICE, CP_INTR, CP_IDLE };
@@ -483,7 +481,6 @@
        static int failcnt = 0;
        static int relabel = 0;
        static int last_disks = 0;
-       static char pigs[] = "pigs";
        static u_long bufmem;
        struct buf_sysctl *buffers;
        int mib[6];
@@ -498,21 +495,8 @@
        cpuswap();
        if (display_mode == TIME) {
                drvswap();
-               etime = cur.cp_etime;
-               /* < 5 ticks - ignore this trash */
-               if ((etime * hertz) < 1.0) {
-                       if (failcnt++ <= MAXFAIL)
-                               return;
-                       clear();
-                       mvprintw(2, 10, "The alternate system clock has died!");
-                       mvprintw(3, 10, "Reverting to ``pigs'' display.");
-                       move(CMDLINE, 0);
-                       refresh();
-                       failcnt = 0;
-                       sleep(5);
-                       command(pigs);
+               if (toofast(&failcnt))
                        return;
-               }
        } else
                etime = 1.0;
 



Home | Main Index | Thread Index | Old Index