Subject: Re: recent instability
To: Chris Tribo <ctribo@dtcc.edu>
From: Bernd Ernesti <netbsd@lists.veego.de>
List: current-users
Date: 04/24/2006 23:16:32
--82I3+IH0IqGh5yIs
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Mon, Apr 24, 2006 at 04:46:22PM -0400, Chris Tribo wrote:
> I just had my system freeze. No response to pings, usb is dead, no idea 
> if I'm in db since usb keyboards don't work without disabling pckbdc 
> first. In the middle of compiling firefox, downloading an ISO, and using 
> rdesktop. I don't ues IPv6 at all or ipf.
> 
> I had xosview running, shortly before the system froze, cpu usage 
> dropped to less than 40%, and the net download stalled. Not what i'd 
> expect while compiling firefox

Hmmm, you are using the old xosview binary, with a kernel source newer then
Fri Apr 14 13:09:07 UTC 2006?
There were some sysctl changes for an interface, which xosview uses for the
disk statistics.

I fixed the compile problem for xosview to matches the interface changes,
but it contains some additional feature to only show the network statistics
for one interface (see the xosview*netIface section in the xosview manpage).
This is a patch for the latest version in pkgsrc (the netIface changes are
allready applied in the xosview cvs tree).

I'm going to fix my own xosview pr later this week, so the package would
compile again.

Bernd


--82I3+IH0IqGh5yIs
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch-aa

$NetBSD$

--- bsd/kernel.cc.orig	2006-02-18 08:36:06.000000000 +0100
+++ bsd/kernel.cc
@@ -121,2 +121,3 @@ __END_DECLS
 #include "kernel.h"		/*  To grab CVSID stuff.  */
+#include "netmeter.h"		/*  For netIface_  */
 
@@ -177,3 +178,7 @@ static struct nlist nlst[] =
 #ifndef XOSVIEW_FREEBSD	/*  NetBSD has a disklist, which FreeBSD doesn't...  */
+#if defined(XOSVIEW_NETBSD) && (__NetBSD_Version__ >= 399001800)
+{ "_iostatlist" },
+#else
 { "_disklist" },
+#endif
 #define DISKLIST_SYM_INDEX	3
@@ -442,4 +447,3 @@ BSDNetInit() {
 
-void
-BSDGetNetInOut (long long * inbytes, long long * outbytes) {
+void NetMeter::BSDGetNetInOut (long long * inbytes, long long * outbytes) {
 
@@ -468,18 +472,24 @@ BSDGetNetInOut (long long * inbytes, lon
     safe_kvm_read ((u_long) ifnetp, &ifnet, sizeof(ifnet));
-#ifdef NET_DEBUG
-    char ifname[256];
+#ifdef XOSVIEW_NETBSD
+    if (netIface_ != "False" ) {
+      char ifname[256];
 #ifdef NETBSD_OLD_IFACE
-    //  In pre-1.2A, getting the interface name was more complicated.
-    safe_kvm_read ((u_long) ifnet.if_name, ifname, 256);
-    snprintf (ifname, 256, "%s%d", ifname, ifnet.if_unit);
+      //  In pre-1.2A, getting the interface name was more complicated.
+      safe_kvm_read ((u_long) ifnet.if_name, ifname, 256);
+      snprintf (ifname, 256, "%s%d", ifname, ifnet.if_unit);
 #else
-    safe_kvm_read ((u_long) (((char*)ifnetp) + (&ifnet.if_xname[0] - (char*)&ifnet)), ifname, 256);
-    snprintf (ifname, 256, "%s", ifname);
+      safe_kvm_read ((u_long) (((char*)ifnetp) + (&ifnet.if_xname[0] - (char*)&ifnet)), ifname, 256);
+      snprintf (ifname, 256, "%s", ifname);
 #endif
-    printf ("Interface name is %s\n", ifname);
-    printf ("Ibytes: %8llu Obytes %8llu\n",
+#ifdef NET_DEBUG
+      printf ("Interface name is %s\n", ifname);
+      printf ("Ibytes: %8llu Obytes %8llu\n",
 	(unsigned long long) ifnet.if_ibytes,
 	(unsigned long long) ifnet.if_obytes);
-    printf ("Ipackets:  %8llu\n", (unsigned long long) ifnet.if_ipackets);
-#endif
+      printf ("Ipackets:  %8llu\n", (unsigned long long) ifnet.if_ipackets);
+#endif /* NET_DEBUG */
+      if (ifname != netIface_)
+	goto skipif;
+    }
+#endif /* XOSVIEW_NETBSD */
     *inbytes  += ifnet.if_ibytes;
@@ -487,2 +497,3 @@ BSDGetNetInOut (long long * inbytes, lon
 
+skipif:
     //  Linked-list step taken from if.c in netstat source, line 120.
@@ -775,2 +786,11 @@ BSDDiskInit() {
   // have been returned, and use that to figure out # drives.
+#if __NetBSD_Version__ >= 399001800
+  int mib[3] = {CTL_HW, HW_IOSTATS, sizeof(struct io_sysctl)};
+  size_t size;
+  if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) {
+    warnx("!!! The DiskMeter sysctl failed.  Disabling DiskMeter.");
+    return 0;
+  }
+  NetBSD_N_Drives = size / sizeof(struct io_sysctl);
+#else
   int mib[3] = {CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl)};
@@ -782,2 +802,3 @@ BSDDiskInit() {
   NetBSD_N_Drives = size / sizeof(struct disk_sysctl);
+#endif
   return 1;
@@ -818,2 +839,20 @@ BSDGetDiskXFerBytes (unsigned long long 
   // Use the new sysctl to do this for us.
+#if __NetBSD_Version__ >= 399001800
+  int mib[3] = {CTL_HW, HW_IOSTATS, sizeof(struct io_sysctl)};
+  size_t sysctl_sz = NetBSD_N_Drives * sizeof(struct io_sysctl);
+  struct io_sysctl io_stats[NetBSD_N_Drives];
+
+  // Do the sysctl.
+  if (sysctl(mib, 3, io_stats, &sysctl_sz, NULL, 0) < 0) {
+    err(1, "sysctl hw.iostats failed");
+  }
+
+  // Now accumulate the total, but only for disks.
+  unsigned long long xferred = 0;
+  for (unsigned int i = 0; i < NetBSD_N_Drives; i++) {
+    if (io_stats[i].type == IOSTAT_DISK)
+      xferred += io_stats[i].rbytes + io_stats[i].wbytes;
+  }
+  *bytesXferred = xferred;
+#else
   int mib[3] = {CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl)};
@@ -833,2 +872,3 @@ BSDGetDiskXFerBytes (unsigned long long 
   *bytesXferred = xferred;
+#endif
 #else

--82I3+IH0IqGh5yIs
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch-ab

$NetBSD$

--- bsd/netmeter.cc.orig	2003-10-10 06:55:37.000000000 +0200
+++ bsd/netmeter.cc
@@ -38,6 +38,7 @@ NetMeter::NetMeter( XOSView *parent, flo
     netBandwidth_ = max;
     total_ = netBandwidth_;
     _lastBytesIn = _lastBytesOut = 0;
+    netIface_ = "False";
     BSDGetNetInOut (&_lastBytesIn, &_lastBytesOut);
   }
 }
@@ -56,6 +57,7 @@ void NetMeter::checkResources( void ){
     dodecay_ = parent_->isResourceTrue("netDecay");
     useGraph_ = parent_->isResourceTrue("netGraph");
     SetUsedFormat (parent_->getResource("netUsedFormat"));
+    netIface_ = parent_->getResource( "netIface" );
   }
 }
 

--82I3+IH0IqGh5yIs
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch-ac

$NetBSD$

--- bsd/netmeter.h.orig	2003-10-09 06:23:10.000000000 +0200
+++ bsd/netmeter.h
@@ -33,8 +33,11 @@ public:
   void checkevent( void );
 
   void checkResources( void );
+
+  void BSDGetNetInOut (long long * inbytes, long long * outbytes);
 protected:
   float netBandwidth_;
+  std::string netIface_;
 
 private:
   //  NetBSD:  Use long long, so we won't run into problems after 4 GB

--82I3+IH0IqGh5yIs--