appldata_net_sum.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * arch/s390/appldata/appldata_net_sum.c
  3. *
  4. * Data gathering module for Linux-VM Monitor Stream, Stage 1.
  5. * Collects accumulated network statistics (Packets received/transmitted,
  6. * dropped, errors, ...).
  7. *
  8. * Copyright (C) 2003,2006 IBM Corporation, IBM Deutschland Entwicklung GmbH.
  9. *
  10. * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/slab.h>
  15. #include <linux/errno.h>
  16. #include <linux/kernel_stat.h>
  17. #include <linux/netdevice.h>
  18. #include "appldata.h"
  19. #define MY_PRINT_NAME "appldata_net_sum" /* for debug messages, etc. */
  20. /*
  21. * Network data
  22. *
  23. * This is accessed as binary data by z/VM. If changes to it can't be avoided,
  24. * the structure version (product ID, see appldata_base.c) needs to be changed
  25. * as well and all documentation and z/VM applications using it must be updated.
  26. *
  27. * The record layout is documented in the Linux for zSeries Device Drivers
  28. * book:
  29. * http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml
  30. */
  31. static struct appldata_net_sum_data {
  32. u64 timestamp;
  33. u32 sync_count_1; /* after VM collected the record data, */
  34. u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the
  35. same. If not, the record has been updated on
  36. the Linux side while VM was collecting the
  37. (possibly corrupt) data */
  38. u32 nr_interfaces; /* nr. of network interfaces being monitored */
  39. u32 padding; /* next value is 64-bit aligned, so these */
  40. /* 4 byte would be padded out by compiler */
  41. u64 rx_packets; /* total packets received */
  42. u64 tx_packets; /* total packets transmitted */
  43. u64 rx_bytes; /* total bytes received */
  44. u64 tx_bytes; /* total bytes transmitted */
  45. u64 rx_errors; /* bad packets received */
  46. u64 tx_errors; /* packet transmit problems */
  47. u64 rx_dropped; /* no space in linux buffers */
  48. u64 tx_dropped; /* no space available in linux */
  49. u64 collisions; /* collisions while transmitting */
  50. } __attribute__((packed)) appldata_net_sum_data;
  51. static inline void appldata_print_debug(struct appldata_net_sum_data *net_data)
  52. {
  53. P_DEBUG("--- NET - RECORD ---\n");
  54. P_DEBUG("nr_interfaces = %u\n", net_data->nr_interfaces);
  55. P_DEBUG("rx_packets = %8lu\n", net_data->rx_packets);
  56. P_DEBUG("tx_packets = %8lu\n", net_data->tx_packets);
  57. P_DEBUG("rx_bytes = %8lu\n", net_data->rx_bytes);
  58. P_DEBUG("tx_bytes = %8lu\n", net_data->tx_bytes);
  59. P_DEBUG("rx_errors = %8lu\n", net_data->rx_errors);
  60. P_DEBUG("tx_errors = %8lu\n", net_data->tx_errors);
  61. P_DEBUG("rx_dropped = %8lu\n", net_data->rx_dropped);
  62. P_DEBUG("tx_dropped = %8lu\n", net_data->tx_dropped);
  63. P_DEBUG("collisions = %8lu\n", net_data->collisions);
  64. P_DEBUG("sync_count_1 = %u\n", net_data->sync_count_1);
  65. P_DEBUG("sync_count_2 = %u\n", net_data->sync_count_2);
  66. P_DEBUG("timestamp = %lX\n", net_data->timestamp);
  67. }
  68. /*
  69. * appldata_get_net_sum_data()
  70. *
  71. * gather accumulated network statistics
  72. */
  73. static void appldata_get_net_sum_data(void *data)
  74. {
  75. int i;
  76. struct appldata_net_sum_data *net_data;
  77. struct net_device *dev;
  78. struct net_device_stats *stats;
  79. unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors,
  80. tx_errors, rx_dropped, tx_dropped, collisions;
  81. net_data = data;
  82. net_data->sync_count_1++;
  83. i = 0;
  84. rx_packets = 0;
  85. tx_packets = 0;
  86. rx_bytes = 0;
  87. tx_bytes = 0;
  88. rx_errors = 0;
  89. tx_errors = 0;
  90. rx_dropped = 0;
  91. tx_dropped = 0;
  92. collisions = 0;
  93. read_lock(&dev_base_lock);
  94. for_each_netdev(dev) {
  95. stats = dev->get_stats(dev);
  96. rx_packets += stats->rx_packets;
  97. tx_packets += stats->tx_packets;
  98. rx_bytes += stats->rx_bytes;
  99. tx_bytes += stats->tx_bytes;
  100. rx_errors += stats->rx_errors;
  101. tx_errors += stats->tx_errors;
  102. rx_dropped += stats->rx_dropped;
  103. tx_dropped += stats->tx_dropped;
  104. collisions += stats->collisions;
  105. i++;
  106. }
  107. read_unlock(&dev_base_lock);
  108. net_data->nr_interfaces = i;
  109. net_data->rx_packets = rx_packets;
  110. net_data->tx_packets = tx_packets;
  111. net_data->rx_bytes = rx_bytes;
  112. net_data->tx_bytes = tx_bytes;
  113. net_data->rx_errors = rx_errors;
  114. net_data->tx_errors = tx_errors;
  115. net_data->rx_dropped = rx_dropped;
  116. net_data->tx_dropped = tx_dropped;
  117. net_data->collisions = collisions;
  118. net_data->timestamp = get_clock();
  119. net_data->sync_count_2++;
  120. #ifdef APPLDATA_DEBUG
  121. appldata_print_debug(net_data);
  122. #endif
  123. }
  124. static struct appldata_ops ops = {
  125. .ctl_nr = CTL_APPLDATA_NET_SUM,
  126. .name = "net_sum",
  127. .record_nr = APPLDATA_RECORD_NET_SUM_ID,
  128. .size = sizeof(struct appldata_net_sum_data),
  129. .callback = &appldata_get_net_sum_data,
  130. .data = &appldata_net_sum_data,
  131. .owner = THIS_MODULE,
  132. .mod_lvl = {0xF0, 0xF0}, /* EBCDIC "00" */
  133. };
  134. /*
  135. * appldata_net_init()
  136. *
  137. * init data, register ops
  138. */
  139. static int __init appldata_net_init(void)
  140. {
  141. int rc;
  142. P_DEBUG("sizeof(net) = %lu\n", sizeof(struct appldata_net_sum_data));
  143. rc = appldata_register_ops(&ops);
  144. if (rc != 0) {
  145. P_ERROR("Error registering ops, rc = %i\n", rc);
  146. } else {
  147. P_DEBUG("%s-ops registered!\n", ops.name);
  148. }
  149. return rc;
  150. }
  151. /*
  152. * appldata_net_exit()
  153. *
  154. * unregister ops
  155. */
  156. static void __exit appldata_net_exit(void)
  157. {
  158. appldata_unregister_ops(&ops);
  159. P_DEBUG("%s-ops unregistered!\n", ops.name);
  160. }
  161. module_init(appldata_net_init);
  162. module_exit(appldata_net_exit);
  163. MODULE_LICENSE("GPL");
  164. MODULE_AUTHOR("Gerald Schaefer");
  165. MODULE_DESCRIPTION("Linux-VM Monitor Stream, accumulated network statistics");