From 2eff8d176aa01780b2ae47c33df4cc78d1fc7b79 Mon Sep 17 00:00:00 2001 From: seb Date: Mon, 10 Dec 2012 21:27:46 +0100 Subject: [PATCH] Changed network counters (used by sar -n {DEV | EDEV }) to unsigned long long to keep in sync with current kernels. Keep in sync with recent kernels (3.7rc8 used here): Now use unsigned long long for network statistics. WARNING: This breaks compatibility with older sar data files format for network statistics. Mail from Matthew Hall (matthew.hall@ecsc.co.uk) 15/12/2011: I've spotted an issue with sadc when values in /proc/net/dev are greater than 4294967295, in that in rd_stats.h all values in stats_net_dev/stats_net_edev are unsigned long, but it *seems* that for a while at least (earliest reference I can see is to 2002 [1]), that values for (rx|tx)_(bytes|packets) are unsigned long long (this is the format ifconfig from net-tools uses). I've attached a sample of my /proc/net/dev (for reference) and a patch for the 9.0.6.1 version of sysstat (also applies against 10.0.2 with minor fuzz from patch) which converts lu to llu for these counters. I've not looked much further into it, since this solves my particular problem, but I expect it's not the 'correct' solution as I can see in /usr/include/linux/if_link.h that rx_bytes is a '__u32' for x86, and '__u64' for x86_64 - so it's probably not portable across different architectures. There's likely some more work to be done to have different format structs of stats_net_dev depending on arch. --- CHANGES | 6 +++++- activity.c | 4 ++-- rd_stats.c | 8 ++++---- rd_stats.h | 36 ++++++++++++++++++------------------ 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/CHANGES b/CHANGES index dedd0e5..77f9167 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,10 @@ Changes: xxxx/xx/xx: Version 10.1.3 - Sebastien Godard (sysstat orange.fr) + * Changed network counters (used by sar -n {DEV | EDEV }) to + unsigned long long to keep in sync with current kernels. + WARNING: This breaks compatibility with older sar data + files format for network statistics. * [Peter Schiffer]: Added option -y to iostat. This option prevents iostat from displaying its first report with statistics since system boot. @@ -13,7 +17,7 @@ xxxx/xx/xx: Version 10.1.3 - Sebastien Godard (sysstat orange.fr) restart, XML output file from sadf -x has no boot elements. * Remove heading spaces in softirq names displayed by mpstat for easier reading. - * Cosmetic fixes in configure script. + * Fixed wrong command execution syntax in configure script. * iostat manual page updated. 2012/10/06: Version 10.1.2 - Sebastien Godard (sysstat orange.fr) diff --git a/activity.c b/activity.c index 2cbadb6..58e258b 100644 --- a/activity.c +++ b/activity.c @@ -415,7 +415,7 @@ struct activity disk_act = { struct activity net_dev_act = { .id = A_NET_DEV, .options = AO_COLLECTED, - .magic = ACTIVITY_MAGIC_BASE, + .magic = ACTIVITY_MAGIC_BASE + 1, .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = wrap_get_iface_nr, @@ -446,7 +446,7 @@ struct activity net_dev_act = { struct activity net_edev_act = { .id = A_NET_EDEV, .options = AO_COLLECTED, - .magic = ACTIVITY_MAGIC_BASE, + .magic = ACTIVITY_MAGIC_BASE + 1, .group = G_DEFAULT, #ifdef SOURCE_SADC .f_count = wrap_get_iface_nr, diff --git a/rd_stats.c b/rd_stats.c index 721807c..3e47824 100644 --- a/rd_stats.c +++ b/rd_stats.c @@ -711,8 +711,8 @@ void read_net_dev(struct stats_net_dev *st_net_dev, int nbr) strncpy(iface, line, MINIMUM(pos, MAX_IFACE_LEN - 1)); iface[MINIMUM(pos, MAX_IFACE_LEN - 1)] = '\0'; sscanf(iface, "%s", st_net_dev_i->interface); /* Skip heading spaces */ - sscanf(line + pos + 1, "%lu %lu %*u %*u %*u %*u %lu %lu %lu %lu " - "%*u %*u %*u %*u %*u %lu", + sscanf(line + pos + 1, "%llu %llu %*u %*u %*u %*u %llu %llu %llu %llu " + "%*u %*u %*u %*u %*u %llu", &st_net_dev_i->rx_bytes, &st_net_dev_i->rx_packets, &st_net_dev_i->rx_compressed, @@ -759,8 +759,8 @@ void read_net_edev(struct stats_net_edev *st_net_edev, int nbr) strncpy(iface, line, MINIMUM(pos, MAX_IFACE_LEN - 1)); iface[MINIMUM(pos, MAX_IFACE_LEN - 1)] = '\0'; sscanf(iface, "%s", st_net_edev_i->interface); /* Skip heading spaces */ - sscanf(line + pos + 1, "%*u %*u %lu %lu %lu %lu %*u %*u %*u %*u " - "%lu %lu %lu %lu %lu", + sscanf(line + pos + 1, "%*u %*u %llu %llu %llu %llu %*u %*u %*u %*u " + "%llu %llu %llu %llu %llu", &st_net_edev_i->rx_errors, &st_net_edev_i->rx_dropped, &st_net_edev_i->rx_fifo_errors, diff --git a/rd_stats.h b/rd_stats.h index ee89b5a..57a76a5 100644 --- a/rd_stats.h +++ b/rd_stats.h @@ -220,30 +220,30 @@ struct stats_disk { /* Structure for network interfaces statistics */ struct stats_net_dev { - unsigned long rx_packets __attribute__ ((aligned (8))); - unsigned long tx_packets __attribute__ ((aligned (8))); - unsigned long rx_bytes __attribute__ ((aligned (8))); - unsigned long tx_bytes __attribute__ ((aligned (8))); - unsigned long rx_compressed __attribute__ ((aligned (8))); - unsigned long tx_compressed __attribute__ ((aligned (8))); - unsigned long multicast __attribute__ ((aligned (8))); - char interface[MAX_IFACE_LEN] __attribute__ ((aligned (8))); + unsigned long long rx_packets __attribute__ ((aligned (16))); + unsigned long long tx_packets __attribute__ ((aligned (16))); + unsigned long long rx_bytes __attribute__ ((aligned (16))); + unsigned long long tx_bytes __attribute__ ((aligned (16))); + unsigned long long rx_compressed __attribute__ ((aligned (16))); + unsigned long long tx_compressed __attribute__ ((aligned (16))); + unsigned long long multicast __attribute__ ((aligned (16))); + char interface[MAX_IFACE_LEN] __attribute__ ((aligned (16))); }; #define STATS_NET_DEV_SIZE (sizeof(struct stats_net_dev)) /* Structure for network interface errors statistics */ struct stats_net_edev { - unsigned long collisions __attribute__ ((aligned (8))); - unsigned long rx_errors __attribute__ ((aligned (8))); - unsigned long tx_errors __attribute__ ((aligned (8))); - unsigned long rx_dropped __attribute__ ((aligned (8))); - unsigned long tx_dropped __attribute__ ((aligned (8))); - unsigned long rx_fifo_errors __attribute__ ((aligned (8))); - unsigned long tx_fifo_errors __attribute__ ((aligned (8))); - unsigned long rx_frame_errors __attribute__ ((aligned (8))); - unsigned long tx_carrier_errors __attribute__ ((aligned (8))); - char interface[MAX_IFACE_LEN] __attribute__ ((aligned (8))); + unsigned long long collisions __attribute__ ((aligned (16))); + unsigned long long rx_errors __attribute__ ((aligned (16))); + unsigned long long tx_errors __attribute__ ((aligned (16))); + unsigned long long rx_dropped __attribute__ ((aligned (16))); + unsigned long long tx_dropped __attribute__ ((aligned (16))); + unsigned long long rx_fifo_errors __attribute__ ((aligned (16))); + unsigned long long tx_fifo_errors __attribute__ ((aligned (16))); + unsigned long long rx_frame_errors __attribute__ ((aligned (16))); + unsigned long long tx_carrier_errors __attribute__ ((aligned (16))); + char interface[MAX_IFACE_LEN] __attribute__ ((aligned (16))); }; #define STATS_NET_EDEV_SIZE (sizeof(struct stats_net_edev)) -- 2.49.0