Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Data gathering module for Linux-VM Monitor Stream, Stage 1. |
| 3 | * Collects accumulated network statistics (Packets received/transmitted, |
| 4 | * dropped, errors, ...). |
| 5 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 6 | * Copyright IBM Corp. 2003, 2006 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 8 | * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/errno.h> |
| 14 | #include <linux/kernel_stat.h> |
| 15 | #include <linux/netdevice.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 16 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #include "appldata.h" |
| 19 | |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | /* |
| 22 | * Network data |
| 23 | * |
| 24 | * This is accessed as binary data by z/VM. If changes to it can't be avoided, |
| 25 | * the structure version (product ID, see appldata_base.c) needs to be changed |
| 26 | * as well and all documentation and z/VM applications using it must be updated. |
| 27 | * |
| 28 | * The record layout is documented in the Linux for zSeries Device Drivers |
| 29 | * book: |
| 30 | * http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml |
| 31 | */ |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 32 | static struct appldata_net_sum_data { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | u64 timestamp; |
| 34 | u32 sync_count_1; /* after VM collected the record data, */ |
| 35 | u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the |
| 36 | same. If not, the record has been updated on |
| 37 | the Linux side while VM was collecting the |
| 38 | (possibly corrupt) data */ |
| 39 | |
| 40 | u32 nr_interfaces; /* nr. of network interfaces being monitored */ |
| 41 | |
| 42 | u32 padding; /* next value is 64-bit aligned, so these */ |
| 43 | /* 4 byte would be padded out by compiler */ |
| 44 | |
| 45 | u64 rx_packets; /* total packets received */ |
| 46 | u64 tx_packets; /* total packets transmitted */ |
| 47 | u64 rx_bytes; /* total bytes received */ |
| 48 | u64 tx_bytes; /* total bytes transmitted */ |
| 49 | u64 rx_errors; /* bad packets received */ |
| 50 | u64 tx_errors; /* packet transmit problems */ |
| 51 | u64 rx_dropped; /* no space in linux buffers */ |
| 52 | u64 tx_dropped; /* no space available in linux */ |
| 53 | u64 collisions; /* collisions while transmitting */ |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 54 | } __attribute__((packed)) appldata_net_sum_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /* |
| 58 | * appldata_get_net_sum_data() |
| 59 | * |
| 60 | * gather accumulated network statistics |
| 61 | */ |
| 62 | static void appldata_get_net_sum_data(void *data) |
| 63 | { |
| 64 | int i; |
| 65 | struct appldata_net_sum_data *net_data; |
| 66 | struct net_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors, |
| 68 | tx_errors, rx_dropped, tx_dropped, collisions; |
| 69 | |
| 70 | net_data = data; |
| 71 | net_data->sync_count_1++; |
| 72 | |
| 73 | i = 0; |
| 74 | rx_packets = 0; |
| 75 | tx_packets = 0; |
| 76 | rx_bytes = 0; |
| 77 | tx_bytes = 0; |
| 78 | rx_errors = 0; |
| 79 | tx_errors = 0; |
| 80 | rx_dropped = 0; |
| 81 | tx_dropped = 0; |
| 82 | collisions = 0; |
stephen hemminger | e576b9e | 2009-11-10 07:54:52 +0000 | [diff] [blame] | 83 | |
| 84 | rcu_read_lock(); |
| 85 | for_each_netdev_rcu(&init_net, dev) { |
Heiko Carstens | e402e38 | 2010-08-13 10:06:42 +0200 | [diff] [blame] | 86 | const struct rtnl_link_stats64 *stats; |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 87 | struct rtnl_link_stats64 temp; |
Stephen Hemminger | eeda3fd | 2008-11-19 21:40:23 -0800 | [diff] [blame] | 88 | |
Heiko Carstens | e402e38 | 2010-08-13 10:06:42 +0200 | [diff] [blame] | 89 | stats = dev_get_stats(dev, &temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | rx_packets += stats->rx_packets; |
| 91 | tx_packets += stats->tx_packets; |
| 92 | rx_bytes += stats->rx_bytes; |
| 93 | tx_bytes += stats->tx_bytes; |
| 94 | rx_errors += stats->rx_errors; |
| 95 | tx_errors += stats->tx_errors; |
| 96 | rx_dropped += stats->rx_dropped; |
| 97 | tx_dropped += stats->tx_dropped; |
| 98 | collisions += stats->collisions; |
| 99 | i++; |
| 100 | } |
stephen hemminger | e576b9e | 2009-11-10 07:54:52 +0000 | [diff] [blame] | 101 | rcu_read_unlock(); |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | net_data->nr_interfaces = i; |
| 104 | net_data->rx_packets = rx_packets; |
| 105 | net_data->tx_packets = tx_packets; |
| 106 | net_data->rx_bytes = rx_bytes; |
| 107 | net_data->tx_bytes = tx_bytes; |
| 108 | net_data->rx_errors = rx_errors; |
| 109 | net_data->tx_errors = tx_errors; |
| 110 | net_data->rx_dropped = rx_dropped; |
| 111 | net_data->tx_dropped = tx_dropped; |
| 112 | net_data->collisions = collisions; |
| 113 | |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 114 | net_data->timestamp = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | net_data->sync_count_2++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | |
| 119 | static struct appldata_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | .name = "net_sum", |
| 121 | .record_nr = APPLDATA_RECORD_NET_SUM_ID, |
| 122 | .size = sizeof(struct appldata_net_sum_data), |
| 123 | .callback = &appldata_get_net_sum_data, |
| 124 | .data = &appldata_net_sum_data, |
| 125 | .owner = THIS_MODULE, |
Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 126 | .mod_lvl = {0xF0, 0xF0}, /* EBCDIC "00" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | |
| 130 | /* |
| 131 | * appldata_net_init() |
| 132 | * |
| 133 | * init data, register ops |
| 134 | */ |
| 135 | static int __init appldata_net_init(void) |
| 136 | { |
Gerald Schaefer | d3ae942 | 2008-07-14 09:59:34 +0200 | [diff] [blame] | 137 | return appldata_register_ops(&ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /* |
| 141 | * appldata_net_exit() |
| 142 | * |
| 143 | * unregister ops |
| 144 | */ |
| 145 | static void __exit appldata_net_exit(void) |
| 146 | { |
| 147 | appldata_unregister_ops(&ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | |
| 151 | module_init(appldata_net_init); |
| 152 | module_exit(appldata_net_exit); |
| 153 | |
| 154 | MODULE_LICENSE("GPL"); |
| 155 | MODULE_AUTHOR("Gerald Schaefer"); |
| 156 | MODULE_DESCRIPTION("Linux-VM Monitor Stream, accumulated network statistics"); |