~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/s390/appldata/appldata_net_sum.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  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 IBM Corp. 2003, 2006
  8  *
  9  * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
 10  */
 11 
 12 #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>
 18 
 19 #include "appldata.h"
 20 
 21 
 22 /*
 23  * Network data
 24  *
 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 changed
 27  * as well and all documentation and z/VM applications using it must be updated.
 28  */
 29 struct appldata_net_sum_data {
 30         u64 timestamp;
 31         u32 sync_count_1;       /* after VM collected the record data, */
 32         u32 sync_count_2;       /* sync_count_1 and sync_count_2 should be the
 33                                    same. If not, the record has been updated on
 34                                    the Linux side while VM was collecting the
 35                                    (possibly corrupt) data */
 36 
 37         u32 nr_interfaces;      /* nr. of network interfaces being monitored */
 38 
 39         u32 padding;            /* next value is 64-bit aligned, so these */
 40                                 /* 4 byte would be padded out by compiler */
 41 
 42         u64 rx_packets;         /* total packets received        */
 43         u64 tx_packets;         /* total packets transmitted     */
 44         u64 rx_bytes;           /* total bytes received          */
 45         u64 tx_bytes;           /* total bytes transmitted       */
 46         u64 rx_errors;          /* bad packets received          */
 47         u64 tx_errors;          /* packet transmit problems      */
 48         u64 rx_dropped;         /* no space in linux buffers     */
 49         u64 tx_dropped;         /* no space available in linux   */
 50         u64 collisions;         /* collisions while transmitting */
 51 } __packed;
 52 
 53 
 54 /*
 55  * appldata_get_net_sum_data()
 56  *
 57  * gather accumulated network statistics
 58  */
 59 static void appldata_get_net_sum_data(void *data)
 60 {
 61         int i;
 62         struct appldata_net_sum_data *net_data;
 63         struct net_device *dev;
 64         unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors,
 65                         tx_errors, rx_dropped, tx_dropped, collisions;
 66 
 67         net_data = data;
 68         net_data->sync_count_1++;
 69 
 70         i = 0;
 71         rx_packets = 0;
 72         tx_packets = 0;
 73         rx_bytes   = 0;
 74         tx_bytes   = 0;
 75         rx_errors  = 0;
 76         tx_errors  = 0;
 77         rx_dropped = 0;
 78         tx_dropped = 0;
 79         collisions = 0;
 80 
 81         rcu_read_lock();
 82         for_each_netdev_rcu(&init_net, dev) {
 83                 const struct rtnl_link_stats64 *stats;
 84                 struct rtnl_link_stats64 temp;
 85 
 86                 stats = dev_get_stats(dev, &temp);
 87                 rx_packets += stats->rx_packets;
 88                 tx_packets += stats->tx_packets;
 89                 rx_bytes   += stats->rx_bytes;
 90                 tx_bytes   += stats->tx_bytes;
 91                 rx_errors  += stats->rx_errors;
 92                 tx_errors  += stats->tx_errors;
 93                 rx_dropped += stats->rx_dropped;
 94                 tx_dropped += stats->tx_dropped;
 95                 collisions += stats->collisions;
 96                 i++;
 97         }
 98         rcu_read_unlock();
 99 
100         net_data->nr_interfaces = i;
101         net_data->rx_packets = rx_packets;
102         net_data->tx_packets = tx_packets;
103         net_data->rx_bytes   = rx_bytes;
104         net_data->tx_bytes   = tx_bytes;
105         net_data->rx_errors  = rx_errors;
106         net_data->tx_errors  = tx_errors;
107         net_data->rx_dropped = rx_dropped;
108         net_data->tx_dropped = tx_dropped;
109         net_data->collisions = collisions;
110 
111         net_data->timestamp = get_tod_clock();
112         net_data->sync_count_2++;
113 }
114 
115 
116 static struct appldata_ops ops = {
117         .name      = "net_sum",
118         .record_nr = APPLDATA_RECORD_NET_SUM_ID,
119         .size      = sizeof(struct appldata_net_sum_data),
120         .callback  = &appldata_get_net_sum_data,
121         .owner     = THIS_MODULE,
122         .mod_lvl   = {0xF0, 0xF0},              /* EBCDIC "00" */
123 };
124 
125 
126 /*
127  * appldata_net_init()
128  *
129  * init data, register ops
130  */
131 static int __init appldata_net_init(void)
132 {
133         int ret;
134 
135         ops.data = kzalloc(sizeof(struct appldata_net_sum_data), GFP_KERNEL);
136         if (!ops.data)
137                 return -ENOMEM;
138 
139         ret = appldata_register_ops(&ops);
140         if (ret)
141                 kfree(ops.data);
142 
143         return ret;
144 }
145 
146 /*
147  * appldata_net_exit()
148  *
149  * unregister ops
150  */
151 static void __exit appldata_net_exit(void)
152 {
153         appldata_unregister_ops(&ops);
154         kfree(ops.data);
155 }
156 
157 
158 module_init(appldata_net_init);
159 module_exit(appldata_net_exit);
160 
161 MODULE_LICENSE("GPL");
162 MODULE_AUTHOR("Gerald Schaefer");
163 MODULE_DESCRIPTION("Linux-VM Monitor Stream, accumulated network statistics");
164 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php