Path: blob/master/arch/s390/appldata/appldata_net_sum.c
26426 views
// SPDX-License-Identifier: GPL-2.01/*2* Data gathering module for Linux-VM Monitor Stream, Stage 1.3* Collects accumulated network statistics (Packets received/transmitted,4* dropped, errors, ...).5*6* Copyright IBM Corp. 2003, 20067*8* Author: Gerald Schaefer <[email protected]>9*/1011#include <linux/module.h>12#include <linux/init.h>13#include <linux/errno.h>14#include <linux/kernel_stat.h>15#include <linux/netdevice.h>16#include <net/net_namespace.h>1718#include "appldata.h"192021/*22* Network data23*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 changed26* as well and all documentation and z/VM applications using it must be updated.27*/28struct appldata_net_sum_data {29u64 timestamp;30u32 sync_count_1; /* after VM collected the record data, */31u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the32same. If not, the record has been updated on33the Linux side while VM was collecting the34(possibly corrupt) data */3536u32 nr_interfaces; /* nr. of network interfaces being monitored */3738u32 padding; /* next value is 64-bit aligned, so these */39/* 4 byte would be padded out by compiler */4041u64 rx_packets; /* total packets received */42u64 tx_packets; /* total packets transmitted */43u64 rx_bytes; /* total bytes received */44u64 tx_bytes; /* total bytes transmitted */45u64 rx_errors; /* bad packets received */46u64 tx_errors; /* packet transmit problems */47u64 rx_dropped; /* no space in linux buffers */48u64 tx_dropped; /* no space available in linux */49u64 collisions; /* collisions while transmitting */50} __packed;515253/*54* appldata_get_net_sum_data()55*56* gather accumulated network statistics57*/58static void appldata_get_net_sum_data(void *data)59{60int i;61struct appldata_net_sum_data *net_data;62struct net_device *dev;63unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors,64tx_errors, rx_dropped, tx_dropped, collisions;6566net_data = data;67net_data->sync_count_1++;6869i = 0;70rx_packets = 0;71tx_packets = 0;72rx_bytes = 0;73tx_bytes = 0;74rx_errors = 0;75tx_errors = 0;76rx_dropped = 0;77tx_dropped = 0;78collisions = 0;7980rcu_read_lock();81for_each_netdev_rcu(&init_net, dev) {82const struct rtnl_link_stats64 *stats;83struct rtnl_link_stats64 temp;8485stats = dev_get_stats(dev, &temp);86rx_packets += stats->rx_packets;87tx_packets += stats->tx_packets;88rx_bytes += stats->rx_bytes;89tx_bytes += stats->tx_bytes;90rx_errors += stats->rx_errors;91tx_errors += stats->tx_errors;92rx_dropped += stats->rx_dropped;93tx_dropped += stats->tx_dropped;94collisions += stats->collisions;95i++;96}97rcu_read_unlock();9899net_data->nr_interfaces = i;100net_data->rx_packets = rx_packets;101net_data->tx_packets = tx_packets;102net_data->rx_bytes = rx_bytes;103net_data->tx_bytes = tx_bytes;104net_data->rx_errors = rx_errors;105net_data->tx_errors = tx_errors;106net_data->rx_dropped = rx_dropped;107net_data->tx_dropped = tx_dropped;108net_data->collisions = collisions;109110net_data->timestamp = get_tod_clock();111net_data->sync_count_2++;112}113114115static struct appldata_ops ops = {116.name = "net_sum",117.record_nr = APPLDATA_RECORD_NET_SUM_ID,118.size = sizeof(struct appldata_net_sum_data),119.callback = &appldata_get_net_sum_data,120.owner = THIS_MODULE,121.mod_lvl = {0xF0, 0xF0}, /* EBCDIC "00" */122};123124125/*126* appldata_net_init()127*128* init data, register ops129*/130static int __init appldata_net_init(void)131{132int ret;133134ops.data = kzalloc(sizeof(struct appldata_net_sum_data), GFP_KERNEL);135if (!ops.data)136return -ENOMEM;137138ret = appldata_register_ops(&ops);139if (ret)140kfree(ops.data);141142return ret;143}144145/*146* appldata_net_exit()147*148* unregister ops149*/150static void __exit appldata_net_exit(void)151{152appldata_unregister_ops(&ops);153kfree(ops.data);154}155156157module_init(appldata_net_init);158module_exit(appldata_net_exit);159160MODULE_LICENSE("GPL");161MODULE_AUTHOR("Gerald Schaefer");162MODULE_DESCRIPTION("Linux-VM Monitor Stream, accumulated network statistics");163164165