appldata_os.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * arch/s390/appldata/appldata_os.c
  3. *
  4. * Data gathering module for Linux-VM Monitor Stream, Stage 1.
  5. * Collects misc. OS related data (CPU utilization, running processes).
  6. *
  7. * Copyright (C) 2003,2006 IBM Corporation, IBM Deutschland Entwicklung GmbH.
  8. *
  9. * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/slab.h>
  14. #include <linux/errno.h>
  15. #include <linux/kernel_stat.h>
  16. #include <linux/netdevice.h>
  17. #include <linux/sched.h>
  18. #include <asm/appldata.h>
  19. #include <asm/smp.h>
  20. #include "appldata.h"
  21. #define MY_PRINT_NAME "appldata_os" /* for debug messages, etc. */
  22. #define LOAD_INT(x) ((x) >> FSHIFT)
  23. #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
  24. /*
  25. * OS data
  26. *
  27. * This is accessed as binary data by z/VM. If changes to it can't be avoided,
  28. * the structure version (product ID, see appldata_base.c) needs to be changed
  29. * as well and all documentation and z/VM applications using it must be
  30. * updated.
  31. *
  32. * The record layout is documented in the Linux for zSeries Device Drivers
  33. * book:
  34. * http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml
  35. */
  36. struct appldata_os_per_cpu {
  37. u32 per_cpu_user; /* timer ticks spent in user mode */
  38. u32 per_cpu_nice; /* ... spent with modified priority */
  39. u32 per_cpu_system; /* ... spent in kernel mode */
  40. u32 per_cpu_idle; /* ... spent in idle mode */
  41. /* New in 2.6 */
  42. u32 per_cpu_irq; /* ... spent in interrupts */
  43. u32 per_cpu_softirq; /* ... spent in softirqs */
  44. u32 per_cpu_iowait; /* ... spent while waiting for I/O */
  45. /* New in modification level 01 */
  46. u32 per_cpu_steal; /* ... stolen by hypervisor */
  47. u32 cpu_id; /* number of this CPU */
  48. } __attribute__((packed));
  49. struct appldata_os_data {
  50. u64 timestamp;
  51. u32 sync_count_1; /* after VM collected the record data, */
  52. u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the
  53. same. If not, the record has been updated on
  54. the Linux side while VM was collecting the
  55. (possibly corrupt) data */
  56. u32 nr_cpus; /* number of (virtual) CPUs */
  57. u32 per_cpu_size; /* size of the per-cpu data struct */
  58. u32 cpu_offset; /* offset of the first per-cpu data struct */
  59. u32 nr_running; /* number of runnable threads */
  60. u32 nr_threads; /* number of threads */
  61. u32 avenrun[3]; /* average nr. of running processes during */
  62. /* the last 1, 5 and 15 minutes */
  63. /* New in 2.6 */
  64. u32 nr_iowait; /* number of blocked threads
  65. (waiting for I/O) */
  66. /* per cpu data */
  67. struct appldata_os_per_cpu os_cpu[0];
  68. } __attribute__((packed));
  69. static struct appldata_os_data *appldata_os_data;
  70. static struct appldata_ops ops = {
  71. .name = "os",
  72. .record_nr = APPLDATA_RECORD_OS_ID,
  73. .owner = THIS_MODULE,
  74. .mod_lvl = {0xF0, 0xF1}, /* EBCDIC "01" */
  75. };
  76. /*
  77. * appldata_get_os_data()
  78. *
  79. * gather OS data
  80. */
  81. static void appldata_get_os_data(void *data)
  82. {
  83. int i, j, rc;
  84. struct appldata_os_data *os_data;
  85. unsigned int new_size;
  86. os_data = data;
  87. os_data->sync_count_1++;
  88. os_data->nr_threads = nr_threads;
  89. os_data->nr_running = nr_running();
  90. os_data->nr_iowait = nr_iowait();
  91. os_data->avenrun[0] = avenrun[0] + (FIXED_1/200);
  92. os_data->avenrun[1] = avenrun[1] + (FIXED_1/200);
  93. os_data->avenrun[2] = avenrun[2] + (FIXED_1/200);
  94. j = 0;
  95. for_each_online_cpu(i) {
  96. os_data->os_cpu[j].per_cpu_user =
  97. cputime_to_jiffies(kstat_cpu(i).cpustat.user);
  98. os_data->os_cpu[j].per_cpu_nice =
  99. cputime_to_jiffies(kstat_cpu(i).cpustat.nice);
  100. os_data->os_cpu[j].per_cpu_system =
  101. cputime_to_jiffies(kstat_cpu(i).cpustat.system);
  102. os_data->os_cpu[j].per_cpu_idle =
  103. cputime_to_jiffies(kstat_cpu(i).cpustat.idle);
  104. os_data->os_cpu[j].per_cpu_irq =
  105. cputime_to_jiffies(kstat_cpu(i).cpustat.irq);
  106. os_data->os_cpu[j].per_cpu_softirq =
  107. cputime_to_jiffies(kstat_cpu(i).cpustat.softirq);
  108. os_data->os_cpu[j].per_cpu_iowait =
  109. cputime_to_jiffies(kstat_cpu(i).cpustat.iowait);
  110. os_data->os_cpu[j].per_cpu_steal =
  111. cputime_to_jiffies(kstat_cpu(i).cpustat.steal);
  112. os_data->os_cpu[j].cpu_id = i;
  113. j++;
  114. }
  115. os_data->nr_cpus = j;
  116. new_size = sizeof(struct appldata_os_data) +
  117. (os_data->nr_cpus * sizeof(struct appldata_os_per_cpu));
  118. if (ops.size != new_size) {
  119. if (ops.active) {
  120. rc = appldata_diag(APPLDATA_RECORD_OS_ID,
  121. APPLDATA_START_INTERVAL_REC,
  122. (unsigned long) ops.data, new_size,
  123. ops.mod_lvl);
  124. if (rc != 0)
  125. P_ERROR("os: START NEW DIAG 0xDC failed, "
  126. "return code: %d, new size = %i\n", rc,
  127. new_size);
  128. rc = appldata_diag(APPLDATA_RECORD_OS_ID,
  129. APPLDATA_STOP_REC,
  130. (unsigned long) ops.data, ops.size,
  131. ops.mod_lvl);
  132. if (rc != 0)
  133. P_ERROR("os: STOP OLD DIAG 0xDC failed, "
  134. "return code: %d, old size = %i\n", rc,
  135. ops.size);
  136. else
  137. P_INFO("os: old record size = %i stopped\n",
  138. ops.size);
  139. }
  140. ops.size = new_size;
  141. }
  142. os_data->timestamp = get_clock();
  143. os_data->sync_count_2++;
  144. }
  145. /*
  146. * appldata_os_init()
  147. *
  148. * init data, register ops
  149. */
  150. static int __init appldata_os_init(void)
  151. {
  152. int rc, max_size;
  153. max_size = sizeof(struct appldata_os_data) +
  154. (NR_CPUS * sizeof(struct appldata_os_per_cpu));
  155. if (max_size > APPLDATA_MAX_REC_SIZE) {
  156. P_ERROR("Max. size of OS record = %i, bigger than maximum "
  157. "record size (%i)\n", max_size, APPLDATA_MAX_REC_SIZE);
  158. rc = -ENOMEM;
  159. goto out;
  160. }
  161. appldata_os_data = kzalloc(max_size, GFP_DMA);
  162. if (appldata_os_data == NULL) {
  163. rc = -ENOMEM;
  164. goto out;
  165. }
  166. appldata_os_data->per_cpu_size = sizeof(struct appldata_os_per_cpu);
  167. appldata_os_data->cpu_offset = offsetof(struct appldata_os_data,
  168. os_cpu);
  169. ops.data = appldata_os_data;
  170. ops.callback = &appldata_get_os_data;
  171. rc = appldata_register_ops(&ops);
  172. if (rc != 0)
  173. kfree(appldata_os_data);
  174. out:
  175. return rc;
  176. }
  177. /*
  178. * appldata_os_exit()
  179. *
  180. * unregister ops
  181. */
  182. static void __exit appldata_os_exit(void)
  183. {
  184. appldata_unregister_ops(&ops);
  185. kfree(appldata_os_data);
  186. }
  187. module_init(appldata_os_init);
  188. module_exit(appldata_os_exit);
  189. MODULE_LICENSE("GPL");
  190. MODULE_AUTHOR("Gerald Schaefer");
  191. MODULE_DESCRIPTION("Linux-VM Monitor Stream, OS statistics");