Path: blob/master/arch/s390/appldata/appldata_net_sum.c
10817 views
/*1* arch/s390/appldata/appldata_net_sum.c2*3* Data gathering module for Linux-VM Monitor Stream, Stage 1.4* Collects accumulated network statistics (Packets received/transmitted,5* dropped, errors, ...).6*7* Copyright (C) 2003,2006 IBM Corporation, IBM Deutschland Entwicklung GmbH.8*9* Author: Gerald Schaefer <[email protected]>10*/1112#include <linux/module.h>13#include <linux/init.h>14#include <linux/errno.h>15#include <linux/kernel_stat.h>16#include <linux/netdevice.h>17#include <net/net_namespace.h>1819#include "appldata.h"202122/*23* Network data24*25* This is accessed as binary data by z/VM. If changes to it can't be avoided,26* the structure version (product ID, see appldata_base.c) needs to be changed27* as well and all documentation and z/VM applications using it must be updated.28*29* The record layout is documented in the Linux for zSeries Device Drivers30* book:31* http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml32*/33static struct appldata_net_sum_data {34u64 timestamp;35u32 sync_count_1; /* after VM collected the record data, */36u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the37same. If not, the record has been updated on38the Linux side while VM was collecting the39(possibly corrupt) data */4041u32 nr_interfaces; /* nr. of network interfaces being monitored */4243u32 padding; /* next value is 64-bit aligned, so these */44/* 4 byte would be padded out by compiler */4546u64 rx_packets; /* total packets received */47u64 tx_packets; /* total packets transmitted */48u64 rx_bytes; /* total bytes received */49u64 tx_bytes; /* total bytes transmitted */50u64 rx_errors; /* bad packets received */51u64 tx_errors; /* packet transmit problems */52u64 rx_dropped; /* no space in linux buffers */53u64 tx_dropped; /* no space available in linux */54u64 collisions; /* collisions while transmitting */55} __attribute__((packed)) appldata_net_sum_data;565758/*59* appldata_get_net_sum_data()60*61* gather accumulated network statistics62*/63static void appldata_get_net_sum_data(void *data)64{65int i;66struct appldata_net_sum_data *net_data;67struct net_device *dev;68unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors,69tx_errors, rx_dropped, tx_dropped, collisions;7071net_data = data;72net_data->sync_count_1++;7374i = 0;75rx_packets = 0;76tx_packets = 0;77rx_bytes = 0;78tx_bytes = 0;79rx_errors = 0;80tx_errors = 0;81rx_dropped = 0;82tx_dropped = 0;83collisions = 0;8485rcu_read_lock();86for_each_netdev_rcu(&init_net, dev) {87const struct rtnl_link_stats64 *stats;88struct rtnl_link_stats64 temp;8990stats = dev_get_stats(dev, &temp);91rx_packets += stats->rx_packets;92tx_packets += stats->tx_packets;93rx_bytes += stats->rx_bytes;94tx_bytes += stats->tx_bytes;95rx_errors += stats->rx_errors;96tx_errors += stats->tx_errors;97rx_dropped += stats->rx_dropped;98tx_dropped += stats->tx_dropped;99collisions += stats->collisions;100i++;101}102rcu_read_unlock();103104net_data->nr_interfaces = i;105net_data->rx_packets = rx_packets;106net_data->tx_packets = tx_packets;107net_data->rx_bytes = rx_bytes;108net_data->tx_bytes = tx_bytes;109net_data->rx_errors = rx_errors;110net_data->tx_errors = tx_errors;111net_data->rx_dropped = rx_dropped;112net_data->tx_dropped = tx_dropped;113net_data->collisions = collisions;114115net_data->timestamp = get_clock();116net_data->sync_count_2++;117}118119120static struct appldata_ops ops = {121.name = "net_sum",122.record_nr = APPLDATA_RECORD_NET_SUM_ID,123.size = sizeof(struct appldata_net_sum_data),124.callback = &appldata_get_net_sum_data,125.data = &appldata_net_sum_data,126.owner = THIS_MODULE,127.mod_lvl = {0xF0, 0xF0}, /* EBCDIC "00" */128};129130131/*132* appldata_net_init()133*134* init data, register ops135*/136static int __init appldata_net_init(void)137{138return appldata_register_ops(&ops);139}140141/*142* appldata_net_exit()143*144* unregister ops145*/146static void __exit appldata_net_exit(void)147{148appldata_unregister_ops(&ops);149}150151152module_init(appldata_net_init);153module_exit(appldata_net_exit);154155MODULE_LICENSE("GPL");156MODULE_AUTHOR("Gerald Schaefer");157MODULE_DESCRIPTION("Linux-VM Monitor Stream, accumulated network statistics");158159160