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