diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/s390/appldata |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/s390/appldata')
-rw-r--r-- | arch/s390/appldata/Makefile | 8 | ||||
-rw-r--r-- | arch/s390/appldata/appldata.h | 59 | ||||
-rw-r--r-- | arch/s390/appldata/appldata_base.c | 770 | ||||
-rw-r--r-- | arch/s390/appldata/appldata_mem.c | 195 | ||||
-rw-r--r-- | arch/s390/appldata/appldata_net_sum.c | 195 | ||||
-rw-r--r-- | arch/s390/appldata/appldata_os.c | 241 |
6 files changed, 1468 insertions, 0 deletions
diff --git a/arch/s390/appldata/Makefile b/arch/s390/appldata/Makefile new file mode 100644 index 000000000000..99f1cf071304 --- /dev/null +++ b/arch/s390/appldata/Makefile | |||
@@ -0,0 +1,8 @@ | |||
1 | # | ||
2 | # Makefile for the Linux - z/VM Monitor Stream. | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_APPLDATA_BASE) += appldata_base.o | ||
6 | obj-$(CONFIG_APPLDATA_MEM) += appldata_mem.o | ||
7 | obj-$(CONFIG_APPLDATA_OS) += appldata_os.o | ||
8 | obj-$(CONFIG_APPLDATA_NET_SUM) += appldata_net_sum.o | ||
diff --git a/arch/s390/appldata/appldata.h b/arch/s390/appldata/appldata.h new file mode 100644 index 000000000000..e806a8922bbb --- /dev/null +++ b/arch/s390/appldata/appldata.h | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | * arch/s390/appldata/appldata.h | ||
3 | * | ||
4 | * Definitions and interface for Linux - z/VM Monitor Stream. | ||
5 | * | ||
6 | * Copyright (C) 2003 IBM Corporation, IBM Deutschland Entwicklung GmbH. | ||
7 | * | ||
8 | * Author: Gerald Schaefer <geraldsc@de.ibm.com> | ||
9 | */ | ||
10 | |||
11 | //#define APPLDATA_DEBUG /* Debug messages on/off */ | ||
12 | |||
13 | #define APPLDATA_MAX_REC_SIZE 4024 /* Maximum size of the */ | ||
14 | /* data buffer */ | ||
15 | #define APPLDATA_MAX_PROCS 100 | ||
16 | |||
17 | #define APPLDATA_PROC_NAME_LENGTH 16 /* Max. length of /proc name */ | ||
18 | |||
19 | #define APPLDATA_RECORD_MEM_ID 0x01 /* IDs to identify the */ | ||
20 | #define APPLDATA_RECORD_OS_ID 0x02 /* individual records, */ | ||
21 | #define APPLDATA_RECORD_NET_SUM_ID 0x03 /* must be < 256 ! */ | ||
22 | #define APPLDATA_RECORD_PROC_ID 0x04 | ||
23 | |||
24 | #define CTL_APPLDATA 2120 /* sysctl IDs, must be unique */ | ||
25 | #define CTL_APPLDATA_TIMER 2121 | ||
26 | #define CTL_APPLDATA_INTERVAL 2122 | ||
27 | #define CTL_APPLDATA_MEM 2123 | ||
28 | #define CTL_APPLDATA_OS 2124 | ||
29 | #define CTL_APPLDATA_NET_SUM 2125 | ||
30 | #define CTL_APPLDATA_PROC 2126 | ||
31 | |||
32 | #define P_INFO(x...) printk(KERN_INFO MY_PRINT_NAME " info: " x) | ||
33 | #define P_ERROR(x...) printk(KERN_ERR MY_PRINT_NAME " error: " x) | ||
34 | #define P_WARNING(x...) printk(KERN_WARNING MY_PRINT_NAME " status: " x) | ||
35 | |||
36 | #ifdef APPLDATA_DEBUG | ||
37 | #define P_DEBUG(x...) printk(KERN_DEBUG MY_PRINT_NAME " debug: " x) | ||
38 | #else | ||
39 | #define P_DEBUG(x...) do {} while (0) | ||
40 | #endif | ||
41 | |||
42 | struct appldata_ops { | ||
43 | struct list_head list; | ||
44 | struct ctl_table_header *sysctl_header; | ||
45 | struct ctl_table *ctl_table; | ||
46 | int active; /* monitoring status */ | ||
47 | |||
48 | /* fill in from here */ | ||
49 | unsigned int ctl_nr; /* sysctl ID */ | ||
50 | char name[APPLDATA_PROC_NAME_LENGTH]; /* name of /proc fs node */ | ||
51 | unsigned char record_nr; /* Record Nr. for Product ID */ | ||
52 | void (*callback)(void *data); /* callback function */ | ||
53 | void *data; /* record data */ | ||
54 | unsigned int size; /* size of record */ | ||
55 | struct module *owner; /* THIS_MODULE */ | ||
56 | }; | ||
57 | |||
58 | extern int appldata_register_ops(struct appldata_ops *ops); | ||
59 | extern void appldata_unregister_ops(struct appldata_ops *ops); | ||
diff --git a/arch/s390/appldata/appldata_base.c b/arch/s390/appldata/appldata_base.c new file mode 100644 index 000000000000..01ae1964c938 --- /dev/null +++ b/arch/s390/appldata/appldata_base.c | |||
@@ -0,0 +1,770 @@ | |||
1 | /* | ||
2 | * arch/s390/appldata/appldata_base.c | ||
3 | * | ||
4 | * Base infrastructure for Linux-z/VM Monitor Stream, Stage 1. | ||
5 | * Exports appldata_register_ops() and appldata_unregister_ops() for the | ||
6 | * data gathering modules. | ||
7 | * | ||
8 | * Copyright (C) 2003 IBM Corporation, IBM Deutschland Entwicklung GmbH. | ||
9 | * | ||
10 | * Author: Gerald Schaefer <geraldsc@de.ibm.com> | ||
11 | */ | ||
12 | |||
13 | #include <linux/config.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/errno.h> | ||
18 | #include <asm/uaccess.h> | ||
19 | #include <asm/io.h> | ||
20 | #include <asm/smp.h> | ||
21 | #include <linux/interrupt.h> | ||
22 | #include <linux/proc_fs.h> | ||
23 | #include <linux/page-flags.h> | ||
24 | #include <linux/swap.h> | ||
25 | #include <linux/pagemap.h> | ||
26 | #include <linux/sysctl.h> | ||
27 | #include <asm/timer.h> | ||
28 | //#include <linux/kernel_stat.h> | ||
29 | #include <linux/notifier.h> | ||
30 | #include <linux/cpu.h> | ||
31 | |||
32 | #include "appldata.h" | ||
33 | |||
34 | |||
35 | #define MY_PRINT_NAME "appldata" /* for debug messages, etc. */ | ||
36 | #define APPLDATA_CPU_INTERVAL 10000 /* default (CPU) time for | ||
37 | sampling interval in | ||
38 | milliseconds */ | ||
39 | |||
40 | #define TOD_MICRO 0x01000 /* nr. of TOD clock units | ||
41 | for 1 microsecond */ | ||
42 | #ifndef CONFIG_ARCH_S390X | ||
43 | |||
44 | #define APPLDATA_START_INTERVAL_REC 0x00 /* Function codes for */ | ||
45 | #define APPLDATA_STOP_REC 0x01 /* DIAG 0xDC */ | ||
46 | #define APPLDATA_GEN_EVENT_RECORD 0x02 | ||
47 | #define APPLDATA_START_CONFIG_REC 0x03 | ||
48 | |||
49 | #else | ||
50 | |||
51 | #define APPLDATA_START_INTERVAL_REC 0x80 | ||
52 | #define APPLDATA_STOP_REC 0x81 | ||
53 | #define APPLDATA_GEN_EVENT_RECORD 0x82 | ||
54 | #define APPLDATA_START_CONFIG_REC 0x83 | ||
55 | |||
56 | #endif /* CONFIG_ARCH_S390X */ | ||
57 | |||
58 | |||
59 | /* | ||
60 | * Parameter list for DIAGNOSE X'DC' | ||
61 | */ | ||
62 | #ifndef CONFIG_ARCH_S390X | ||
63 | struct appldata_parameter_list { | ||
64 | u16 diag; /* The DIAGNOSE code X'00DC' */ | ||
65 | u8 function; /* The function code for the DIAGNOSE */ | ||
66 | u8 parlist_length; /* Length of the parameter list */ | ||
67 | u32 product_id_addr; /* Address of the 16-byte product ID */ | ||
68 | u16 reserved; | ||
69 | u16 buffer_length; /* Length of the application data buffer */ | ||
70 | u32 buffer_addr; /* Address of the application data buffer */ | ||
71 | }; | ||
72 | #else | ||
73 | struct appldata_parameter_list { | ||
74 | u16 diag; | ||
75 | u8 function; | ||
76 | u8 parlist_length; | ||
77 | u32 unused01; | ||
78 | u16 reserved; | ||
79 | u16 buffer_length; | ||
80 | u32 unused02; | ||
81 | u64 product_id_addr; | ||
82 | u64 buffer_addr; | ||
83 | }; | ||
84 | #endif /* CONFIG_ARCH_S390X */ | ||
85 | |||
86 | /* | ||
87 | * /proc entries (sysctl) | ||
88 | */ | ||
89 | static const char appldata_proc_name[APPLDATA_PROC_NAME_LENGTH] = "appldata"; | ||
90 | static int appldata_timer_handler(ctl_table *ctl, int write, struct file *filp, | ||
91 | void __user *buffer, size_t *lenp, loff_t *ppos); | ||
92 | static int appldata_interval_handler(ctl_table *ctl, int write, | ||
93 | struct file *filp, | ||
94 | void __user *buffer, | ||
95 | size_t *lenp, loff_t *ppos); | ||
96 | |||
97 | static struct ctl_table_header *appldata_sysctl_header; | ||
98 | static struct ctl_table appldata_table[] = { | ||
99 | { | ||
100 | .ctl_name = CTL_APPLDATA_TIMER, | ||
101 | .procname = "timer", | ||
102 | .mode = S_IRUGO | S_IWUSR, | ||
103 | .proc_handler = &appldata_timer_handler, | ||
104 | }, | ||
105 | { | ||
106 | .ctl_name = CTL_APPLDATA_INTERVAL, | ||
107 | .procname = "interval", | ||
108 | .mode = S_IRUGO | S_IWUSR, | ||
109 | .proc_handler = &appldata_interval_handler, | ||
110 | }, | ||
111 | { .ctl_name = 0 } | ||
112 | }; | ||
113 | |||
114 | static struct ctl_table appldata_dir_table[] = { | ||
115 | { | ||
116 | .ctl_name = CTL_APPLDATA, | ||
117 | .procname = appldata_proc_name, | ||
118 | .maxlen = 0, | ||
119 | .mode = S_IRUGO | S_IXUGO, | ||
120 | .child = appldata_table, | ||
121 | }, | ||
122 | { .ctl_name = 0 } | ||
123 | }; | ||
124 | |||
125 | /* | ||
126 | * Timer | ||
127 | */ | ||
128 | DEFINE_PER_CPU(struct vtimer_list, appldata_timer); | ||
129 | static atomic_t appldata_expire_count = ATOMIC_INIT(0); | ||
130 | |||
131 | static DEFINE_SPINLOCK(appldata_timer_lock); | ||
132 | static int appldata_interval = APPLDATA_CPU_INTERVAL; | ||
133 | static int appldata_timer_active; | ||
134 | |||
135 | /* | ||
136 | * Tasklet | ||
137 | */ | ||
138 | static struct tasklet_struct appldata_tasklet_struct; | ||
139 | |||
140 | /* | ||
141 | * Ops list | ||
142 | */ | ||
143 | static DEFINE_SPINLOCK(appldata_ops_lock); | ||
144 | static LIST_HEAD(appldata_ops_list); | ||
145 | |||
146 | |||
147 | /************************* timer, tasklet, DIAG ******************************/ | ||
148 | /* | ||
149 | * appldata_timer_function() | ||
150 | * | ||
151 | * schedule tasklet and reschedule timer | ||
152 | */ | ||
153 | static void appldata_timer_function(unsigned long data, struct pt_regs *regs) | ||
154 | { | ||
155 | P_DEBUG(" -= Timer =-\n"); | ||
156 | P_DEBUG("CPU: %i, expire_count: %i\n", smp_processor_id(), | ||
157 | atomic_read(&appldata_expire_count)); | ||
158 | if (atomic_dec_and_test(&appldata_expire_count)) { | ||
159 | atomic_set(&appldata_expire_count, num_online_cpus()); | ||
160 | tasklet_schedule((struct tasklet_struct *) data); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | /* | ||
165 | * appldata_tasklet_function() | ||
166 | * | ||
167 | * call data gathering function for each (active) module | ||
168 | */ | ||
169 | static void appldata_tasklet_function(unsigned long data) | ||
170 | { | ||
171 | struct list_head *lh; | ||
172 | struct appldata_ops *ops; | ||
173 | int i; | ||
174 | |||
175 | P_DEBUG(" -= Tasklet =-\n"); | ||
176 | i = 0; | ||
177 | spin_lock(&appldata_ops_lock); | ||
178 | list_for_each(lh, &appldata_ops_list) { | ||
179 | ops = list_entry(lh, struct appldata_ops, list); | ||
180 | P_DEBUG("list_for_each loop: %i) active = %u, name = %s\n", | ||
181 | ++i, ops->active, ops->name); | ||
182 | if (ops->active == 1) { | ||
183 | ops->callback(ops->data); | ||
184 | } | ||
185 | } | ||
186 | spin_unlock(&appldata_ops_lock); | ||
187 | } | ||
188 | |||
189 | /* | ||
190 | * appldata_diag() | ||
191 | * | ||
192 | * prepare parameter list, issue DIAG 0xDC | ||
193 | */ | ||
194 | static int appldata_diag(char record_nr, u16 function, unsigned long buffer, | ||
195 | u16 length) | ||
196 | { | ||
197 | unsigned long ry; | ||
198 | struct appldata_product_id { | ||
199 | char prod_nr[7]; /* product nr. */ | ||
200 | char prod_fn[2]; /* product function */ | ||
201 | char record_nr; /* record nr. */ | ||
202 | char version_nr[2]; /* version */ | ||
203 | char release_nr[2]; /* release */ | ||
204 | char mod_lvl[2]; /* modification lvl. */ | ||
205 | } appldata_product_id = { | ||
206 | /* all strings are EBCDIC, record_nr is byte */ | ||
207 | .prod_nr = {0xD3, 0xC9, 0xD5, 0xE4, | ||
208 | 0xE7, 0xD2, 0xD9}, /* "LINUXKR" */ | ||
209 | .prod_fn = {0xD5, 0xD3}, /* "NL" */ | ||
210 | .record_nr = record_nr, | ||
211 | .version_nr = {0xF2, 0xF6}, /* "26" */ | ||
212 | .release_nr = {0xF0, 0xF1}, /* "01" */ | ||
213 | .mod_lvl = {0xF0, 0xF0}, /* "00" */ | ||
214 | }; | ||
215 | struct appldata_parameter_list appldata_parameter_list = { | ||
216 | .diag = 0xDC, | ||
217 | .function = function, | ||
218 | .parlist_length = | ||
219 | sizeof(appldata_parameter_list), | ||
220 | .buffer_length = length, | ||
221 | .product_id_addr = | ||
222 | (unsigned long) &appldata_product_id, | ||
223 | .buffer_addr = virt_to_phys((void *) buffer) | ||
224 | }; | ||
225 | |||
226 | if (!MACHINE_IS_VM) | ||
227 | return -ENOSYS; | ||
228 | ry = -1; | ||
229 | asm volatile( | ||
230 | "diag %1,%0,0xDC\n\t" | ||
231 | : "=d" (ry) : "d" (&(appldata_parameter_list)) : "cc"); | ||
232 | return (int) ry; | ||
233 | } | ||
234 | /********************** timer, tasklet, DIAG <END> ***************************/ | ||
235 | |||
236 | |||
237 | /****************************** /proc stuff **********************************/ | ||
238 | |||
239 | /* | ||
240 | * appldata_mod_vtimer_wrap() | ||
241 | * | ||
242 | * wrapper function for mod_virt_timer(), because smp_call_function_on() | ||
243 | * accepts only one parameter. | ||
244 | */ | ||
245 | static void __appldata_mod_vtimer_wrap(void *p) { | ||
246 | struct { | ||
247 | struct vtimer_list *timer; | ||
248 | u64 expires; | ||
249 | } *args = p; | ||
250 | mod_virt_timer(args->timer, args->expires); | ||
251 | } | ||
252 | |||
253 | #define APPLDATA_ADD_TIMER 0 | ||
254 | #define APPLDATA_DEL_TIMER 1 | ||
255 | #define APPLDATA_MOD_TIMER 2 | ||
256 | |||
257 | /* | ||
258 | * __appldata_vtimer_setup() | ||
259 | * | ||
260 | * Add, delete or modify virtual timers on all online cpus. | ||
261 | * The caller needs to get the appldata_timer_lock spinlock. | ||
262 | */ | ||
263 | static void | ||
264 | __appldata_vtimer_setup(int cmd) | ||
265 | { | ||
266 | u64 per_cpu_interval; | ||
267 | int i; | ||
268 | |||
269 | switch (cmd) { | ||
270 | case APPLDATA_ADD_TIMER: | ||
271 | if (appldata_timer_active) | ||
272 | break; | ||
273 | per_cpu_interval = (u64) (appldata_interval*1000 / | ||
274 | num_online_cpus()) * TOD_MICRO; | ||
275 | for_each_online_cpu(i) { | ||
276 | per_cpu(appldata_timer, i).expires = per_cpu_interval; | ||
277 | smp_call_function_on(add_virt_timer_periodic, | ||
278 | &per_cpu(appldata_timer, i), | ||
279 | 0, 1, i); | ||
280 | } | ||
281 | appldata_timer_active = 1; | ||
282 | P_INFO("Monitoring timer started.\n"); | ||
283 | break; | ||
284 | case APPLDATA_DEL_TIMER: | ||
285 | for_each_online_cpu(i) | ||
286 | del_virt_timer(&per_cpu(appldata_timer, i)); | ||
287 | if (!appldata_timer_active) | ||
288 | break; | ||
289 | appldata_timer_active = 0; | ||
290 | atomic_set(&appldata_expire_count, num_online_cpus()); | ||
291 | P_INFO("Monitoring timer stopped.\n"); | ||
292 | break; | ||
293 | case APPLDATA_MOD_TIMER: | ||
294 | per_cpu_interval = (u64) (appldata_interval*1000 / | ||
295 | num_online_cpus()) * TOD_MICRO; | ||
296 | if (!appldata_timer_active) | ||
297 | break; | ||
298 | for_each_online_cpu(i) { | ||
299 | struct { | ||
300 | struct vtimer_list *timer; | ||
301 | u64 expires; | ||
302 | } args; | ||
303 | args.timer = &per_cpu(appldata_timer, i); | ||
304 | args.expires = per_cpu_interval; | ||
305 | smp_call_function_on(__appldata_mod_vtimer_wrap, | ||
306 | &args, 0, 1, i); | ||
307 | } | ||
308 | } | ||
309 | } | ||
310 | |||
311 | /* | ||
312 | * appldata_timer_handler() | ||
313 | * | ||
314 | * Start/Stop timer, show status of timer (0 = not active, 1 = active) | ||
315 | */ | ||
316 | static int | ||
317 | appldata_timer_handler(ctl_table *ctl, int write, struct file *filp, | ||
318 | void __user *buffer, size_t *lenp, loff_t *ppos) | ||
319 | { | ||
320 | int len; | ||
321 | char buf[2]; | ||
322 | |||
323 | if (!*lenp || *ppos) { | ||
324 | *lenp = 0; | ||
325 | return 0; | ||
326 | } | ||
327 | if (!write) { | ||
328 | len = sprintf(buf, appldata_timer_active ? "1\n" : "0\n"); | ||
329 | if (len > *lenp) | ||
330 | len = *lenp; | ||
331 | if (copy_to_user(buffer, buf, len)) | ||
332 | return -EFAULT; | ||
333 | goto out; | ||
334 | } | ||
335 | len = *lenp; | ||
336 | if (copy_from_user(buf, buffer, len > sizeof(buf) ? sizeof(buf) : len)) | ||
337 | return -EFAULT; | ||
338 | spin_lock(&appldata_timer_lock); | ||
339 | if (buf[0] == '1') | ||
340 | __appldata_vtimer_setup(APPLDATA_ADD_TIMER); | ||
341 | else if (buf[0] == '0') | ||
342 | __appldata_vtimer_setup(APPLDATA_DEL_TIMER); | ||
343 | spin_unlock(&appldata_timer_lock); | ||
344 | out: | ||
345 | *lenp = len; | ||
346 | *ppos += len; | ||
347 | return 0; | ||
348 | } | ||
349 | |||
350 | /* | ||
351 | * appldata_interval_handler() | ||
352 | * | ||
353 | * Set (CPU) timer interval for collection of data (in milliseconds), show | ||
354 | * current timer interval. | ||
355 | */ | ||
356 | static int | ||
357 | appldata_interval_handler(ctl_table *ctl, int write, struct file *filp, | ||
358 | void __user *buffer, size_t *lenp, loff_t *ppos) | ||
359 | { | ||
360 | int len, interval; | ||
361 | char buf[16]; | ||
362 | |||
363 | if (!*lenp || *ppos) { | ||
364 | *lenp = 0; | ||
365 | return 0; | ||
366 | } | ||
367 | if (!write) { | ||
368 | len = sprintf(buf, "%i\n", appldata_interval); | ||
369 | if (len > *lenp) | ||
370 | len = *lenp; | ||
371 | if (copy_to_user(buffer, buf, len)) | ||
372 | return -EFAULT; | ||
373 | goto out; | ||
374 | } | ||
375 | len = *lenp; | ||
376 | if (copy_from_user(buf, buffer, len > sizeof(buf) ? sizeof(buf) : len)) { | ||
377 | return -EFAULT; | ||
378 | } | ||
379 | sscanf(buf, "%i", &interval); | ||
380 | if (interval <= 0) { | ||
381 | P_ERROR("Timer CPU interval has to be > 0!\n"); | ||
382 | return -EINVAL; | ||
383 | } | ||
384 | |||
385 | spin_lock(&appldata_timer_lock); | ||
386 | appldata_interval = interval; | ||
387 | __appldata_vtimer_setup(APPLDATA_MOD_TIMER); | ||
388 | spin_unlock(&appldata_timer_lock); | ||
389 | |||
390 | P_INFO("Monitoring CPU interval set to %u milliseconds.\n", | ||
391 | interval); | ||
392 | out: | ||
393 | *lenp = len; | ||
394 | *ppos += len; | ||
395 | return 0; | ||
396 | } | ||
397 | |||
398 | /* | ||
399 | * appldata_generic_handler() | ||
400 | * | ||
401 | * Generic start/stop monitoring and DIAG, show status of | ||
402 | * monitoring (0 = not in process, 1 = in process) | ||
403 | */ | ||
404 | static int | ||
405 | appldata_generic_handler(ctl_table *ctl, int write, struct file *filp, | ||
406 | void __user *buffer, size_t *lenp, loff_t *ppos) | ||
407 | { | ||
408 | struct appldata_ops *ops = NULL, *tmp_ops; | ||
409 | int rc, len, found; | ||
410 | char buf[2]; | ||
411 | struct list_head *lh; | ||
412 | |||
413 | found = 0; | ||
414 | spin_lock_bh(&appldata_ops_lock); | ||
415 | list_for_each(lh, &appldata_ops_list) { | ||
416 | tmp_ops = list_entry(lh, struct appldata_ops, list); | ||
417 | if (&tmp_ops->ctl_table[2] == ctl) { | ||
418 | found = 1; | ||
419 | } | ||
420 | } | ||
421 | if (!found) { | ||
422 | spin_unlock_bh(&appldata_ops_lock); | ||
423 | return -ENODEV; | ||
424 | } | ||
425 | ops = ctl->data; | ||
426 | if (!try_module_get(ops->owner)) { // protect this function | ||
427 | spin_unlock_bh(&appldata_ops_lock); | ||
428 | return -ENODEV; | ||
429 | } | ||
430 | spin_unlock_bh(&appldata_ops_lock); | ||
431 | |||
432 | if (!*lenp || *ppos) { | ||
433 | *lenp = 0; | ||
434 | module_put(ops->owner); | ||
435 | return 0; | ||
436 | } | ||
437 | if (!write) { | ||
438 | len = sprintf(buf, ops->active ? "1\n" : "0\n"); | ||
439 | if (len > *lenp) | ||
440 | len = *lenp; | ||
441 | if (copy_to_user(buffer, buf, len)) { | ||
442 | module_put(ops->owner); | ||
443 | return -EFAULT; | ||
444 | } | ||
445 | goto out; | ||
446 | } | ||
447 | len = *lenp; | ||
448 | if (copy_from_user(buf, buffer, | ||
449 | len > sizeof(buf) ? sizeof(buf) : len)) { | ||
450 | module_put(ops->owner); | ||
451 | return -EFAULT; | ||
452 | } | ||
453 | |||
454 | spin_lock_bh(&appldata_ops_lock); | ||
455 | if ((buf[0] == '1') && (ops->active == 0)) { | ||
456 | if (!try_module_get(ops->owner)) { // protect tasklet | ||
457 | spin_unlock_bh(&appldata_ops_lock); | ||
458 | module_put(ops->owner); | ||
459 | return -ENODEV; | ||
460 | } | ||
461 | ops->active = 1; | ||
462 | ops->callback(ops->data); // init record | ||
463 | rc = appldata_diag(ops->record_nr, | ||
464 | APPLDATA_START_INTERVAL_REC, | ||
465 | (unsigned long) ops->data, ops->size); | ||
466 | if (rc != 0) { | ||
467 | P_ERROR("START DIAG 0xDC for %s failed, " | ||
468 | "return code: %d\n", ops->name, rc); | ||
469 | module_put(ops->owner); | ||
470 | ops->active = 0; | ||
471 | } else { | ||
472 | P_INFO("Monitoring %s data enabled, " | ||
473 | "DIAG 0xDC started.\n", ops->name); | ||
474 | } | ||
475 | } else if ((buf[0] == '0') && (ops->active == 1)) { | ||
476 | ops->active = 0; | ||
477 | rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC, | ||
478 | (unsigned long) ops->data, ops->size); | ||
479 | if (rc != 0) { | ||
480 | P_ERROR("STOP DIAG 0xDC for %s failed, " | ||
481 | "return code: %d\n", ops->name, rc); | ||
482 | } else { | ||
483 | P_INFO("Monitoring %s data disabled, " | ||
484 | "DIAG 0xDC stopped.\n", ops->name); | ||
485 | } | ||
486 | module_put(ops->owner); | ||
487 | } | ||
488 | spin_unlock_bh(&appldata_ops_lock); | ||
489 | out: | ||
490 | *lenp = len; | ||
491 | *ppos += len; | ||
492 | module_put(ops->owner); | ||
493 | return 0; | ||
494 | } | ||
495 | |||
496 | /*************************** /proc stuff <END> *******************************/ | ||
497 | |||
498 | |||
499 | /************************* module-ops management *****************************/ | ||
500 | /* | ||
501 | * appldata_register_ops() | ||
502 | * | ||
503 | * update ops list, register /proc/sys entries | ||
504 | */ | ||
505 | int appldata_register_ops(struct appldata_ops *ops) | ||
506 | { | ||
507 | struct list_head *lh; | ||
508 | struct appldata_ops *tmp_ops; | ||
509 | int i; | ||
510 | |||
511 | i = 0; | ||
512 | |||
513 | if ((ops->size > APPLDATA_MAX_REC_SIZE) || | ||
514 | (ops->size < 0)){ | ||
515 | P_ERROR("Invalid size of %s record = %i, maximum = %i!\n", | ||
516 | ops->name, ops->size, APPLDATA_MAX_REC_SIZE); | ||
517 | return -ENOMEM; | ||
518 | } | ||
519 | if ((ops->ctl_nr == CTL_APPLDATA) || | ||
520 | (ops->ctl_nr == CTL_APPLDATA_TIMER) || | ||
521 | (ops->ctl_nr == CTL_APPLDATA_INTERVAL)) { | ||
522 | P_ERROR("ctl_nr %i already in use!\n", ops->ctl_nr); | ||
523 | return -EBUSY; | ||
524 | } | ||
525 | ops->ctl_table = kmalloc(4*sizeof(struct ctl_table), GFP_KERNEL); | ||
526 | if (ops->ctl_table == NULL) { | ||
527 | P_ERROR("Not enough memory for %s ctl_table!\n", ops->name); | ||
528 | return -ENOMEM; | ||
529 | } | ||
530 | memset(ops->ctl_table, 0, 4*sizeof(struct ctl_table)); | ||
531 | |||
532 | spin_lock_bh(&appldata_ops_lock); | ||
533 | list_for_each(lh, &appldata_ops_list) { | ||
534 | tmp_ops = list_entry(lh, struct appldata_ops, list); | ||
535 | P_DEBUG("register_ops loop: %i) name = %s, ctl = %i\n", | ||
536 | ++i, tmp_ops->name, tmp_ops->ctl_nr); | ||
537 | P_DEBUG("Comparing %s (ctl %i) with %s (ctl %i)\n", | ||
538 | tmp_ops->name, tmp_ops->ctl_nr, ops->name, | ||
539 | ops->ctl_nr); | ||
540 | if (strncmp(tmp_ops->name, ops->name, | ||
541 | APPLDATA_PROC_NAME_LENGTH) == 0) { | ||
542 | P_ERROR("Name \"%s\" already registered!\n", ops->name); | ||
543 | kfree(ops->ctl_table); | ||
544 | spin_unlock_bh(&appldata_ops_lock); | ||
545 | return -EBUSY; | ||
546 | } | ||
547 | if (tmp_ops->ctl_nr == ops->ctl_nr) { | ||
548 | P_ERROR("ctl_nr %i already registered!\n", ops->ctl_nr); | ||
549 | kfree(ops->ctl_table); | ||
550 | spin_unlock_bh(&appldata_ops_lock); | ||
551 | return -EBUSY; | ||
552 | } | ||
553 | } | ||
554 | list_add(&ops->list, &appldata_ops_list); | ||
555 | spin_unlock_bh(&appldata_ops_lock); | ||
556 | |||
557 | ops->ctl_table[0].ctl_name = CTL_APPLDATA; | ||
558 | ops->ctl_table[0].procname = appldata_proc_name; | ||
559 | ops->ctl_table[0].maxlen = 0; | ||
560 | ops->ctl_table[0].mode = S_IRUGO | S_IXUGO; | ||
561 | ops->ctl_table[0].child = &ops->ctl_table[2]; | ||
562 | |||
563 | ops->ctl_table[1].ctl_name = 0; | ||
564 | |||
565 | ops->ctl_table[2].ctl_name = ops->ctl_nr; | ||
566 | ops->ctl_table[2].procname = ops->name; | ||
567 | ops->ctl_table[2].mode = S_IRUGO | S_IWUSR; | ||
568 | ops->ctl_table[2].proc_handler = appldata_generic_handler; | ||
569 | ops->ctl_table[2].data = ops; | ||
570 | |||
571 | ops->ctl_table[3].ctl_name = 0; | ||
572 | |||
573 | ops->sysctl_header = register_sysctl_table(ops->ctl_table,1); | ||
574 | |||
575 | P_INFO("%s-ops registered!\n", ops->name); | ||
576 | return 0; | ||
577 | } | ||
578 | |||
579 | /* | ||
580 | * appldata_unregister_ops() | ||
581 | * | ||
582 | * update ops list, unregister /proc entries, stop DIAG if necessary | ||
583 | */ | ||
584 | void appldata_unregister_ops(struct appldata_ops *ops) | ||
585 | { | ||
586 | spin_lock_bh(&appldata_ops_lock); | ||
587 | unregister_sysctl_table(ops->sysctl_header); | ||
588 | list_del(&ops->list); | ||
589 | kfree(ops->ctl_table); | ||
590 | ops->ctl_table = NULL; | ||
591 | spin_unlock_bh(&appldata_ops_lock); | ||
592 | P_INFO("%s-ops unregistered!\n", ops->name); | ||
593 | } | ||
594 | /********************** module-ops management <END> **************************/ | ||
595 | |||
596 | |||
597 | /******************************* init / exit *********************************/ | ||
598 | |||
599 | static void | ||
600 | appldata_online_cpu(int cpu) | ||
601 | { | ||
602 | init_virt_timer(&per_cpu(appldata_timer, cpu)); | ||
603 | per_cpu(appldata_timer, cpu).function = appldata_timer_function; | ||
604 | per_cpu(appldata_timer, cpu).data = (unsigned long) | ||
605 | &appldata_tasklet_struct; | ||
606 | atomic_inc(&appldata_expire_count); | ||
607 | spin_lock(&appldata_timer_lock); | ||
608 | __appldata_vtimer_setup(APPLDATA_MOD_TIMER); | ||
609 | spin_unlock(&appldata_timer_lock); | ||
610 | } | ||
611 | |||
612 | static void | ||
613 | appldata_offline_cpu(int cpu) | ||
614 | { | ||
615 | del_virt_timer(&per_cpu(appldata_timer, cpu)); | ||
616 | if (atomic_dec_and_test(&appldata_expire_count)) { | ||
617 | atomic_set(&appldata_expire_count, num_online_cpus()); | ||
618 | tasklet_schedule(&appldata_tasklet_struct); | ||
619 | } | ||
620 | spin_lock(&appldata_timer_lock); | ||
621 | __appldata_vtimer_setup(APPLDATA_MOD_TIMER); | ||
622 | spin_unlock(&appldata_timer_lock); | ||
623 | } | ||
624 | |||
625 | static int | ||
626 | appldata_cpu_notify(struct notifier_block *self, | ||
627 | unsigned long action, void *hcpu) | ||
628 | { | ||
629 | switch (action) { | ||
630 | case CPU_ONLINE: | ||
631 | appldata_online_cpu((long) hcpu); | ||
632 | break; | ||
633 | #ifdef CONFIG_HOTPLUG_CPU | ||
634 | case CPU_DEAD: | ||
635 | appldata_offline_cpu((long) hcpu); | ||
636 | break; | ||
637 | #endif | ||
638 | default: | ||
639 | break; | ||
640 | } | ||
641 | return NOTIFY_OK; | ||
642 | } | ||
643 | |||
644 | static struct notifier_block __devinitdata appldata_nb = { | ||
645 | .notifier_call = appldata_cpu_notify, | ||
646 | }; | ||
647 | |||
648 | /* | ||
649 | * appldata_init() | ||
650 | * | ||
651 | * init timer and tasklet, register /proc entries | ||
652 | */ | ||
653 | static int __init appldata_init(void) | ||
654 | { | ||
655 | int i; | ||
656 | |||
657 | P_DEBUG("sizeof(parameter_list) = %lu\n", | ||
658 | sizeof(struct appldata_parameter_list)); | ||
659 | |||
660 | for_each_online_cpu(i) | ||
661 | appldata_online_cpu(i); | ||
662 | |||
663 | /* Register cpu hotplug notifier */ | ||
664 | register_cpu_notifier(&appldata_nb); | ||
665 | |||
666 | appldata_sysctl_header = register_sysctl_table(appldata_dir_table, 1); | ||
667 | #ifdef MODULE | ||
668 | appldata_dir_table[0].de->owner = THIS_MODULE; | ||
669 | appldata_table[0].de->owner = THIS_MODULE; | ||
670 | appldata_table[1].de->owner = THIS_MODULE; | ||
671 | #endif | ||
672 | |||
673 | tasklet_init(&appldata_tasklet_struct, appldata_tasklet_function, 0); | ||
674 | P_DEBUG("Base interface initialized.\n"); | ||
675 | return 0; | ||
676 | } | ||
677 | |||
678 | /* | ||
679 | * appldata_exit() | ||
680 | * | ||
681 | * stop timer and tasklet, unregister /proc entries | ||
682 | */ | ||
683 | static void __exit appldata_exit(void) | ||
684 | { | ||
685 | struct list_head *lh; | ||
686 | struct appldata_ops *ops; | ||
687 | int rc, i; | ||
688 | |||
689 | P_DEBUG("Unloading module ...\n"); | ||
690 | /* | ||
691 | * ops list should be empty, but just in case something went wrong... | ||
692 | */ | ||
693 | spin_lock_bh(&appldata_ops_lock); | ||
694 | list_for_each(lh, &appldata_ops_list) { | ||
695 | ops = list_entry(lh, struct appldata_ops, list); | ||
696 | rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC, | ||
697 | (unsigned long) ops->data, ops->size); | ||
698 | if (rc != 0) { | ||
699 | P_ERROR("STOP DIAG 0xDC for %s failed, " | ||
700 | "return code: %d\n", ops->name, rc); | ||
701 | } | ||
702 | } | ||
703 | spin_unlock_bh(&appldata_ops_lock); | ||
704 | |||
705 | for_each_online_cpu(i) | ||
706 | appldata_offline_cpu(i); | ||
707 | |||
708 | appldata_timer_active = 0; | ||
709 | |||
710 | unregister_sysctl_table(appldata_sysctl_header); | ||
711 | |||
712 | tasklet_kill(&appldata_tasklet_struct); | ||
713 | P_DEBUG("... module unloaded!\n"); | ||
714 | } | ||
715 | /**************************** init / exit <END> ******************************/ | ||
716 | |||
717 | |||
718 | module_init(appldata_init); | ||
719 | module_exit(appldata_exit); | ||
720 | MODULE_LICENSE("GPL"); | ||
721 | MODULE_AUTHOR("Gerald Schaefer"); | ||
722 | MODULE_DESCRIPTION("Linux-VM Monitor Stream, base infrastructure"); | ||
723 | |||
724 | EXPORT_SYMBOL_GPL(appldata_register_ops); | ||
725 | EXPORT_SYMBOL_GPL(appldata_unregister_ops); | ||
726 | |||
727 | #ifdef MODULE | ||
728 | /* | ||
729 | * Kernel symbols needed by appldata_mem and appldata_os modules. | ||
730 | * However, if this file is compiled as a module (for testing only), these | ||
731 | * symbols are not exported. In this case, we define them locally and export | ||
732 | * those. | ||
733 | */ | ||
734 | void si_swapinfo(struct sysinfo *val) | ||
735 | { | ||
736 | val->freeswap = -1ul; | ||
737 | val->totalswap = -1ul; | ||
738 | } | ||
739 | |||
740 | unsigned long avenrun[3] = {-1 - FIXED_1/200, -1 - FIXED_1/200, | ||
741 | -1 - FIXED_1/200}; | ||
742 | int nr_threads = -1; | ||
743 | |||
744 | void get_full_page_state(struct page_state *ps) | ||
745 | { | ||
746 | memset(ps, -1, sizeof(struct page_state)); | ||
747 | } | ||
748 | |||
749 | unsigned long nr_running(void) | ||
750 | { | ||
751 | return -1; | ||
752 | } | ||
753 | |||
754 | unsigned long nr_iowait(void) | ||
755 | { | ||
756 | return -1; | ||
757 | } | ||
758 | |||
759 | /*unsigned long nr_context_switches(void) | ||
760 | { | ||
761 | return -1; | ||
762 | }*/ | ||
763 | #endif /* MODULE */ | ||
764 | EXPORT_SYMBOL_GPL(si_swapinfo); | ||
765 | EXPORT_SYMBOL_GPL(nr_threads); | ||
766 | EXPORT_SYMBOL_GPL(avenrun); | ||
767 | EXPORT_SYMBOL_GPL(get_full_page_state); | ||
768 | EXPORT_SYMBOL_GPL(nr_running); | ||
769 | EXPORT_SYMBOL_GPL(nr_iowait); | ||
770 | //EXPORT_SYMBOL_GPL(nr_context_switches); | ||
diff --git a/arch/s390/appldata/appldata_mem.c b/arch/s390/appldata/appldata_mem.c new file mode 100644 index 000000000000..462ee9a84e76 --- /dev/null +++ b/arch/s390/appldata/appldata_mem.c | |||
@@ -0,0 +1,195 @@ | |||
1 | /* | ||
2 | * arch/s390/appldata/appldata_mem.c | ||
3 | * | ||
4 | * Data gathering module for Linux-VM Monitor Stream, Stage 1. | ||
5 | * Collects data related to memory management. | ||
6 | * | ||
7 | * Copyright (C) 2003 IBM Corporation, IBM Deutschland Entwicklung GmbH. | ||
8 | * | ||
9 | * Author: Gerald Schaefer <geraldsc@de.ibm.com> | ||
10 | */ | ||
11 | |||
12 | #include <linux/config.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/errno.h> | ||
17 | #include <linux/kernel_stat.h> | ||
18 | #include <asm/io.h> | ||
19 | #include <linux/pagemap.h> | ||
20 | #include <linux/swap.h> | ||
21 | |||
22 | #include "appldata.h" | ||
23 | |||
24 | |||
25 | #define MY_PRINT_NAME "appldata_mem" /* for debug messages, etc. */ | ||
26 | #define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ | ||
27 | |||
28 | /* | ||
29 | * Memory data | ||
30 | * | ||
31 | * This is accessed as binary data by z/VM. If changes to it can't be avoided, | ||
32 | * the structure version (product ID, see appldata_base.c) needs to be changed | ||
33 | * as well and all documentation and z/VM applications using it must be | ||
34 | * updated. | ||
35 | * | ||
36 | * The record layout is documented in the Linux for zSeries Device Drivers | ||
37 | * book: | ||
38 | * http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml | ||
39 | */ | ||
40 | struct appldata_mem_data { | ||
41 | u64 timestamp; | ||
42 | u32 sync_count_1; /* after VM collected the record data, */ | ||
43 | u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the | ||
44 | same. If not, the record has been updated on | ||
45 | the Linux side while VM was collecting the | ||
46 | (possibly corrupt) data */ | ||
47 | |||
48 | u64 pgpgin; /* data read from disk */ | ||
49 | u64 pgpgout; /* data written to disk */ | ||
50 | u64 pswpin; /* pages swapped in */ | ||
51 | u64 pswpout; /* pages swapped out */ | ||
52 | |||
53 | u64 sharedram; /* sharedram is currently set to 0 */ | ||
54 | |||
55 | u64 totalram; /* total main memory size */ | ||
56 | u64 freeram; /* free main memory size */ | ||
57 | u64 totalhigh; /* total high memory size */ | ||
58 | u64 freehigh; /* free high memory size */ | ||
59 | |||
60 | u64 bufferram; /* memory reserved for buffers, free cache */ | ||
61 | u64 cached; /* size of (used) cache, w/o buffers */ | ||
62 | u64 totalswap; /* total swap space size */ | ||
63 | u64 freeswap; /* free swap space */ | ||
64 | |||
65 | // New in 2.6 --> | ||
66 | u64 pgalloc; /* page allocations */ | ||
67 | u64 pgfault; /* page faults (major+minor) */ | ||
68 | u64 pgmajfault; /* page faults (major only) */ | ||
69 | // <-- New in 2.6 | ||
70 | |||
71 | } appldata_mem_data; | ||
72 | |||
73 | |||
74 | static inline void appldata_debug_print(struct appldata_mem_data *mem_data) | ||
75 | { | ||
76 | P_DEBUG("--- MEM - RECORD ---\n"); | ||
77 | P_DEBUG("pgpgin = %8lu KB\n", mem_data->pgpgin); | ||
78 | P_DEBUG("pgpgout = %8lu KB\n", mem_data->pgpgout); | ||
79 | P_DEBUG("pswpin = %8lu Pages\n", mem_data->pswpin); | ||
80 | P_DEBUG("pswpout = %8lu Pages\n", mem_data->pswpout); | ||
81 | P_DEBUG("pgalloc = %8lu \n", mem_data->pgalloc); | ||
82 | P_DEBUG("pgfault = %8lu \n", mem_data->pgfault); | ||
83 | P_DEBUG("pgmajfault = %8lu \n", mem_data->pgmajfault); | ||
84 | P_DEBUG("sharedram = %8lu KB\n", mem_data->sharedram); | ||
85 | P_DEBUG("totalram = %8lu KB\n", mem_data->totalram); | ||
86 | P_DEBUG("freeram = %8lu KB\n", mem_data->freeram); | ||
87 | P_DEBUG("totalhigh = %8lu KB\n", mem_data->totalhigh); | ||
88 | P_DEBUG("freehigh = %8lu KB\n", mem_data->freehigh); | ||
89 | P_DEBUG("bufferram = %8lu KB\n", mem_data->bufferram); | ||
90 | P_DEBUG("cached = %8lu KB\n", mem_data->cached); | ||
91 | P_DEBUG("totalswap = %8lu KB\n", mem_data->totalswap); | ||
92 | P_DEBUG("freeswap = %8lu KB\n", mem_data->freeswap); | ||
93 | P_DEBUG("sync_count_1 = %u\n", mem_data->sync_count_1); | ||
94 | P_DEBUG("sync_count_2 = %u\n", mem_data->sync_count_2); | ||
95 | P_DEBUG("timestamp = %lX\n", mem_data->timestamp); | ||
96 | } | ||
97 | |||
98 | /* | ||
99 | * appldata_get_mem_data() | ||
100 | * | ||
101 | * gather memory data | ||
102 | */ | ||
103 | static void appldata_get_mem_data(void *data) | ||
104 | { | ||
105 | /* | ||
106 | * don't put large structures on the stack, we are | ||
107 | * serialized through the appldata_ops_lock and can use static | ||
108 | */ | ||
109 | static struct sysinfo val; | ||
110 | static struct page_state ps; | ||
111 | struct appldata_mem_data *mem_data; | ||
112 | |||
113 | mem_data = data; | ||
114 | mem_data->sync_count_1++; | ||
115 | |||
116 | get_full_page_state(&ps); | ||
117 | mem_data->pgpgin = ps.pgpgin >> 1; | ||
118 | mem_data->pgpgout = ps.pgpgout >> 1; | ||
119 | mem_data->pswpin = ps.pswpin; | ||
120 | mem_data->pswpout = ps.pswpout; | ||
121 | mem_data->pgalloc = ps.pgalloc_high + ps.pgalloc_normal + | ||
122 | ps.pgalloc_dma; | ||
123 | mem_data->pgfault = ps.pgfault; | ||
124 | mem_data->pgmajfault = ps.pgmajfault; | ||
125 | |||
126 | si_meminfo(&val); | ||
127 | mem_data->sharedram = val.sharedram; | ||
128 | mem_data->totalram = P2K(val.totalram); | ||
129 | mem_data->freeram = P2K(val.freeram); | ||
130 | mem_data->totalhigh = P2K(val.totalhigh); | ||
131 | mem_data->freehigh = P2K(val.freehigh); | ||
132 | mem_data->bufferram = P2K(val.bufferram); | ||
133 | mem_data->cached = P2K(atomic_read(&nr_pagecache) - val.bufferram); | ||
134 | |||
135 | si_swapinfo(&val); | ||
136 | mem_data->totalswap = P2K(val.totalswap); | ||
137 | mem_data->freeswap = P2K(val.freeswap); | ||
138 | |||
139 | mem_data->timestamp = get_clock(); | ||
140 | mem_data->sync_count_2++; | ||
141 | #ifdef APPLDATA_DEBUG | ||
142 | appldata_debug_print(mem_data); | ||
143 | #endif | ||
144 | } | ||
145 | |||
146 | |||
147 | static struct appldata_ops ops = { | ||
148 | .ctl_nr = CTL_APPLDATA_MEM, | ||
149 | .name = "mem", | ||
150 | .record_nr = APPLDATA_RECORD_MEM_ID, | ||
151 | .size = sizeof(struct appldata_mem_data), | ||
152 | .callback = &appldata_get_mem_data, | ||
153 | .data = &appldata_mem_data, | ||
154 | .owner = THIS_MODULE, | ||
155 | }; | ||
156 | |||
157 | |||
158 | /* | ||
159 | * appldata_mem_init() | ||
160 | * | ||
161 | * init_data, register ops | ||
162 | */ | ||
163 | static int __init appldata_mem_init(void) | ||
164 | { | ||
165 | int rc; | ||
166 | |||
167 | P_DEBUG("sizeof(mem) = %lu\n", sizeof(struct appldata_mem_data)); | ||
168 | |||
169 | rc = appldata_register_ops(&ops); | ||
170 | if (rc != 0) { | ||
171 | P_ERROR("Error registering ops, rc = %i\n", rc); | ||
172 | } else { | ||
173 | P_DEBUG("%s-ops registered!\n", ops.name); | ||
174 | } | ||
175 | return rc; | ||
176 | } | ||
177 | |||
178 | /* | ||
179 | * appldata_mem_exit() | ||
180 | * | ||
181 | * unregister ops | ||
182 | */ | ||
183 | static void __exit appldata_mem_exit(void) | ||
184 | { | ||
185 | appldata_unregister_ops(&ops); | ||
186 | P_DEBUG("%s-ops unregistered!\n", ops.name); | ||
187 | } | ||
188 | |||
189 | |||
190 | module_init(appldata_mem_init); | ||
191 | module_exit(appldata_mem_exit); | ||
192 | |||
193 | MODULE_LICENSE("GPL"); | ||
194 | MODULE_AUTHOR("Gerald Schaefer"); | ||
195 | MODULE_DESCRIPTION("Linux-VM Monitor Stream, MEMORY statistics"); | ||
diff --git a/arch/s390/appldata/appldata_net_sum.c b/arch/s390/appldata/appldata_net_sum.c new file mode 100644 index 000000000000..dd61638d3027 --- /dev/null +++ b/arch/s390/appldata/appldata_net_sum.c | |||
@@ -0,0 +1,195 @@ | |||
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 IBM Corporation, IBM Deutschland Entwicklung GmbH. | ||
9 | * | ||
10 | * Author: Gerald Schaefer <geraldsc@de.ibm.com> | ||
11 | */ | ||
12 | |||
13 | #include <linux/config.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/errno.h> | ||
18 | #include <linux/kernel_stat.h> | ||
19 | #include <linux/netdevice.h> | ||
20 | |||
21 | #include "appldata.h" | ||
22 | |||
23 | |||
24 | #define MY_PRINT_NAME "appldata_net_sum" /* for debug messages, etc. */ | ||
25 | |||
26 | |||
27 | /* | ||
28 | * Network data | ||
29 | * | ||
30 | * This is accessed as binary data by z/VM. If changes to it can't be avoided, | ||
31 | * the structure version (product ID, see appldata_base.c) needs to be changed | ||
32 | * as well and all documentation and z/VM applications using it must be updated. | ||
33 | * | ||
34 | * The record layout is documented in the Linux for zSeries Device Drivers | ||
35 | * book: | ||
36 | * http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml | ||
37 | */ | ||
38 | struct appldata_net_sum_data { | ||
39 | u64 timestamp; | ||
40 | u32 sync_count_1; /* after VM collected the record data, */ | ||
41 | u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the | ||
42 | same. If not, the record has been updated on | ||
43 | the Linux side while VM was collecting the | ||
44 | (possibly corrupt) data */ | ||
45 | |||
46 | u32 nr_interfaces; /* nr. of network interfaces being monitored */ | ||
47 | |||
48 | u32 padding; /* next value is 64-bit aligned, so these */ | ||
49 | /* 4 byte would be padded out by compiler */ | ||
50 | |||
51 | u64 rx_packets; /* total packets received */ | ||
52 | u64 tx_packets; /* total packets transmitted */ | ||
53 | u64 rx_bytes; /* total bytes received */ | ||
54 | u64 tx_bytes; /* total bytes transmitted */ | ||
55 | u64 rx_errors; /* bad packets received */ | ||
56 | u64 tx_errors; /* packet transmit problems */ | ||
57 | u64 rx_dropped; /* no space in linux buffers */ | ||
58 | u64 tx_dropped; /* no space available in linux */ | ||
59 | u64 collisions; /* collisions while transmitting */ | ||
60 | } appldata_net_sum_data; | ||
61 | |||
62 | |||
63 | static inline void appldata_print_debug(struct appldata_net_sum_data *net_data) | ||
64 | { | ||
65 | P_DEBUG("--- NET - RECORD ---\n"); | ||
66 | |||
67 | P_DEBUG("nr_interfaces = %u\n", net_data->nr_interfaces); | ||
68 | P_DEBUG("rx_packets = %8lu\n", net_data->rx_packets); | ||
69 | P_DEBUG("tx_packets = %8lu\n", net_data->tx_packets); | ||
70 | P_DEBUG("rx_bytes = %8lu\n", net_data->rx_bytes); | ||
71 | P_DEBUG("tx_bytes = %8lu\n", net_data->tx_bytes); | ||
72 | P_DEBUG("rx_errors = %8lu\n", net_data->rx_errors); | ||
73 | P_DEBUG("tx_errors = %8lu\n", net_data->tx_errors); | ||
74 | P_DEBUG("rx_dropped = %8lu\n", net_data->rx_dropped); | ||
75 | P_DEBUG("tx_dropped = %8lu\n", net_data->tx_dropped); | ||
76 | P_DEBUG("collisions = %8lu\n", net_data->collisions); | ||
77 | |||
78 | P_DEBUG("sync_count_1 = %u\n", net_data->sync_count_1); | ||
79 | P_DEBUG("sync_count_2 = %u\n", net_data->sync_count_2); | ||
80 | P_DEBUG("timestamp = %lX\n", net_data->timestamp); | ||
81 | } | ||
82 | |||
83 | /* | ||
84 | * appldata_get_net_sum_data() | ||
85 | * | ||
86 | * gather accumulated network statistics | ||
87 | */ | ||
88 | static void appldata_get_net_sum_data(void *data) | ||
89 | { | ||
90 | int i; | ||
91 | struct appldata_net_sum_data *net_data; | ||
92 | struct net_device *dev; | ||
93 | struct net_device_stats *stats; | ||
94 | unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors, | ||
95 | tx_errors, rx_dropped, tx_dropped, collisions; | ||
96 | |||
97 | net_data = data; | ||
98 | net_data->sync_count_1++; | ||
99 | |||
100 | i = 0; | ||
101 | rx_packets = 0; | ||
102 | tx_packets = 0; | ||
103 | rx_bytes = 0; | ||
104 | tx_bytes = 0; | ||
105 | rx_errors = 0; | ||
106 | tx_errors = 0; | ||
107 | rx_dropped = 0; | ||
108 | tx_dropped = 0; | ||
109 | collisions = 0; | ||
110 | read_lock(&dev_base_lock); | ||
111 | for (dev = dev_base; dev != NULL; dev = dev->next) { | ||
112 | if (dev->get_stats == NULL) { | ||
113 | continue; | ||
114 | } | ||
115 | stats = dev->get_stats(dev); | ||
116 | rx_packets += stats->rx_packets; | ||
117 | tx_packets += stats->tx_packets; | ||
118 | rx_bytes += stats->rx_bytes; | ||
119 | tx_bytes += stats->tx_bytes; | ||
120 | rx_errors += stats->rx_errors; | ||
121 | tx_errors += stats->tx_errors; | ||
122 | rx_dropped += stats->rx_dropped; | ||
123 | tx_dropped += stats->tx_dropped; | ||
124 | collisions += stats->collisions; | ||
125 | i++; | ||
126 | } | ||
127 | read_unlock(&dev_base_lock); | ||
128 | net_data->nr_interfaces = i; | ||
129 | net_data->rx_packets = rx_packets; | ||
130 | net_data->tx_packets = tx_packets; | ||
131 | net_data->rx_bytes = rx_bytes; | ||
132 | net_data->tx_bytes = tx_bytes; | ||
133 | net_data->rx_errors = rx_errors; | ||
134 | net_data->tx_errors = tx_errors; | ||
135 | net_data->rx_dropped = rx_dropped; | ||
136 | net_data->tx_dropped = tx_dropped; | ||
137 | net_data->collisions = collisions; | ||
138 | |||
139 | net_data->timestamp = get_clock(); | ||
140 | net_data->sync_count_2++; | ||
141 | #ifdef APPLDATA_DEBUG | ||
142 | appldata_print_debug(net_data); | ||
143 | #endif | ||
144 | } | ||
145 | |||
146 | |||
147 | static struct appldata_ops ops = { | ||
148 | .ctl_nr = CTL_APPLDATA_NET_SUM, | ||
149 | .name = "net_sum", | ||
150 | .record_nr = APPLDATA_RECORD_NET_SUM_ID, | ||
151 | .size = sizeof(struct appldata_net_sum_data), | ||
152 | .callback = &appldata_get_net_sum_data, | ||
153 | .data = &appldata_net_sum_data, | ||
154 | .owner = THIS_MODULE, | ||
155 | }; | ||
156 | |||
157 | |||
158 | /* | ||
159 | * appldata_net_init() | ||
160 | * | ||
161 | * init data, register ops | ||
162 | */ | ||
163 | static int __init appldata_net_init(void) | ||
164 | { | ||
165 | int rc; | ||
166 | |||
167 | P_DEBUG("sizeof(net) = %lu\n", sizeof(struct appldata_net_sum_data)); | ||
168 | |||
169 | rc = appldata_register_ops(&ops); | ||
170 | if (rc != 0) { | ||
171 | P_ERROR("Error registering ops, rc = %i\n", rc); | ||
172 | } else { | ||
173 | P_DEBUG("%s-ops registered!\n", ops.name); | ||
174 | } | ||
175 | return rc; | ||
176 | } | ||
177 | |||
178 | /* | ||
179 | * appldata_net_exit() | ||
180 | * | ||
181 | * unregister ops | ||
182 | */ | ||
183 | static void __exit appldata_net_exit(void) | ||
184 | { | ||
185 | appldata_unregister_ops(&ops); | ||
186 | P_DEBUG("%s-ops unregistered!\n", ops.name); | ||
187 | } | ||
188 | |||
189 | |||
190 | module_init(appldata_net_init); | ||
191 | module_exit(appldata_net_exit); | ||
192 | |||
193 | MODULE_LICENSE("GPL"); | ||
194 | MODULE_AUTHOR("Gerald Schaefer"); | ||
195 | MODULE_DESCRIPTION("Linux-VM Monitor Stream, accumulated network statistics"); | ||
diff --git a/arch/s390/appldata/appldata_os.c b/arch/s390/appldata/appldata_os.c new file mode 100644 index 000000000000..b83f07484551 --- /dev/null +++ b/arch/s390/appldata/appldata_os.c | |||
@@ -0,0 +1,241 @@ | |||
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 IBM Corporation, IBM Deutschland Entwicklung GmbH. | ||
8 | * | ||
9 | * Author: Gerald Schaefer <geraldsc@de.ibm.com> | ||
10 | */ | ||
11 | |||
12 | #include <linux/config.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/errno.h> | ||
17 | #include <linux/kernel_stat.h> | ||
18 | #include <linux/netdevice.h> | ||
19 | #include <linux/sched.h> | ||
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 | |||
47 | // New in 2.6 --> | ||
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 */ | ||
51 | // <-- New in 2.6 | ||
52 | }; | ||
53 | |||
54 | struct appldata_os_data { | ||
55 | u64 timestamp; | ||
56 | u32 sync_count_1; /* after VM collected the record data, */ | ||
57 | u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the | ||
58 | same. If not, the record has been updated on | ||
59 | the Linux side while VM was collecting the | ||
60 | (possibly corrupt) data */ | ||
61 | |||
62 | u32 nr_cpus; /* number of (virtual) CPUs */ | ||
63 | u32 per_cpu_size; /* size of the per-cpu data struct */ | ||
64 | u32 cpu_offset; /* offset of the first per-cpu data struct */ | ||
65 | |||
66 | u32 nr_running; /* number of runnable threads */ | ||
67 | u32 nr_threads; /* number of threads */ | ||
68 | u32 avenrun[3]; /* average nr. of running processes during */ | ||
69 | /* the last 1, 5 and 15 minutes */ | ||
70 | |||
71 | // New in 2.6 --> | ||
72 | u32 nr_iowait; /* number of blocked threads | ||
73 | (waiting for I/O) */ | ||
74 | // <-- New in 2.6 | ||
75 | |||
76 | /* per cpu data */ | ||
77 | struct appldata_os_per_cpu os_cpu[0]; | ||
78 | }; | ||
79 | |||
80 | static struct appldata_os_data *appldata_os_data; | ||
81 | |||
82 | |||
83 | static inline void appldata_print_debug(struct appldata_os_data *os_data) | ||
84 | { | ||
85 | int a0, a1, a2, i; | ||
86 | |||
87 | P_DEBUG("--- OS - RECORD ---\n"); | ||
88 | P_DEBUG("nr_threads = %u\n", os_data->nr_threads); | ||
89 | P_DEBUG("nr_running = %u\n", os_data->nr_running); | ||
90 | P_DEBUG("nr_iowait = %u\n", os_data->nr_iowait); | ||
91 | P_DEBUG("avenrun(int) = %8x / %8x / %8x\n", os_data->avenrun[0], | ||
92 | os_data->avenrun[1], os_data->avenrun[2]); | ||
93 | a0 = os_data->avenrun[0]; | ||
94 | a1 = os_data->avenrun[1]; | ||
95 | a2 = os_data->avenrun[2]; | ||
96 | P_DEBUG("avenrun(float) = %d.%02d / %d.%02d / %d.%02d\n", | ||
97 | LOAD_INT(a0), LOAD_FRAC(a0), LOAD_INT(a1), LOAD_FRAC(a1), | ||
98 | LOAD_INT(a2), LOAD_FRAC(a2)); | ||
99 | |||
100 | P_DEBUG("nr_cpus = %u\n", os_data->nr_cpus); | ||
101 | for (i = 0; i < os_data->nr_cpus; i++) { | ||
102 | P_DEBUG("cpu%u : user = %u, nice = %u, system = %u, " | ||
103 | "idle = %u, irq = %u, softirq = %u, iowait = %u\n", | ||
104 | i, | ||
105 | os_data->os_cpu[i].per_cpu_user, | ||
106 | os_data->os_cpu[i].per_cpu_nice, | ||
107 | os_data->os_cpu[i].per_cpu_system, | ||
108 | os_data->os_cpu[i].per_cpu_idle, | ||
109 | os_data->os_cpu[i].per_cpu_irq, | ||
110 | os_data->os_cpu[i].per_cpu_softirq, | ||
111 | os_data->os_cpu[i].per_cpu_iowait); | ||
112 | } | ||
113 | |||
114 | P_DEBUG("sync_count_1 = %u\n", os_data->sync_count_1); | ||
115 | P_DEBUG("sync_count_2 = %u\n", os_data->sync_count_2); | ||
116 | P_DEBUG("timestamp = %lX\n", os_data->timestamp); | ||
117 | } | ||
118 | |||
119 | /* | ||
120 | * appldata_get_os_data() | ||
121 | * | ||
122 | * gather OS data | ||
123 | */ | ||
124 | static void appldata_get_os_data(void *data) | ||
125 | { | ||
126 | int i, j; | ||
127 | struct appldata_os_data *os_data; | ||
128 | |||
129 | os_data = data; | ||
130 | os_data->sync_count_1++; | ||
131 | |||
132 | os_data->nr_cpus = num_online_cpus(); | ||
133 | |||
134 | os_data->nr_threads = nr_threads; | ||
135 | os_data->nr_running = nr_running(); | ||
136 | os_data->nr_iowait = nr_iowait(); | ||
137 | os_data->avenrun[0] = avenrun[0] + (FIXED_1/200); | ||
138 | os_data->avenrun[1] = avenrun[1] + (FIXED_1/200); | ||
139 | os_data->avenrun[2] = avenrun[2] + (FIXED_1/200); | ||
140 | |||
141 | j = 0; | ||
142 | for_each_online_cpu(i) { | ||
143 | os_data->os_cpu[j].per_cpu_user = | ||
144 | kstat_cpu(i).cpustat.user; | ||
145 | os_data->os_cpu[j].per_cpu_nice = | ||
146 | kstat_cpu(i).cpustat.nice; | ||
147 | os_data->os_cpu[j].per_cpu_system = | ||
148 | kstat_cpu(i).cpustat.system; | ||
149 | os_data->os_cpu[j].per_cpu_idle = | ||
150 | kstat_cpu(i).cpustat.idle; | ||
151 | os_data->os_cpu[j].per_cpu_irq = | ||
152 | kstat_cpu(i).cpustat.irq; | ||
153 | os_data->os_cpu[j].per_cpu_softirq = | ||
154 | kstat_cpu(i).cpustat.softirq; | ||
155 | os_data->os_cpu[j].per_cpu_iowait = | ||
156 | kstat_cpu(i).cpustat.iowait; | ||
157 | j++; | ||
158 | } | ||
159 | |||
160 | os_data->timestamp = get_clock(); | ||
161 | os_data->sync_count_2++; | ||
162 | #ifdef APPLDATA_DEBUG | ||
163 | appldata_print_debug(os_data); | ||
164 | #endif | ||
165 | } | ||
166 | |||
167 | |||
168 | static struct appldata_ops ops = { | ||
169 | .ctl_nr = CTL_APPLDATA_OS, | ||
170 | .name = "os", | ||
171 | .record_nr = APPLDATA_RECORD_OS_ID, | ||
172 | .callback = &appldata_get_os_data, | ||
173 | .owner = THIS_MODULE, | ||
174 | }; | ||
175 | |||
176 | |||
177 | /* | ||
178 | * appldata_os_init() | ||
179 | * | ||
180 | * init data, register ops | ||
181 | */ | ||
182 | static int __init appldata_os_init(void) | ||
183 | { | ||
184 | int rc, size; | ||
185 | |||
186 | size = sizeof(struct appldata_os_data) + | ||
187 | (NR_CPUS * sizeof(struct appldata_os_per_cpu)); | ||
188 | if (size > APPLDATA_MAX_REC_SIZE) { | ||
189 | P_ERROR("Size of record = %i, bigger than maximum (%i)!\n", | ||
190 | size, APPLDATA_MAX_REC_SIZE); | ||
191 | rc = -ENOMEM; | ||
192 | goto out; | ||
193 | } | ||
194 | P_DEBUG("sizeof(os) = %i, sizeof(os_cpu) = %lu\n", size, | ||
195 | sizeof(struct appldata_os_per_cpu)); | ||
196 | |||
197 | appldata_os_data = kmalloc(size, GFP_DMA); | ||
198 | if (appldata_os_data == NULL) { | ||
199 | P_ERROR("No memory for %s!\n", ops.name); | ||
200 | rc = -ENOMEM; | ||
201 | goto out; | ||
202 | } | ||
203 | memset(appldata_os_data, 0, size); | ||
204 | |||
205 | appldata_os_data->per_cpu_size = sizeof(struct appldata_os_per_cpu); | ||
206 | appldata_os_data->cpu_offset = offsetof(struct appldata_os_data, | ||
207 | os_cpu); | ||
208 | P_DEBUG("cpu offset = %u\n", appldata_os_data->cpu_offset); | ||
209 | |||
210 | ops.data = appldata_os_data; | ||
211 | ops.size = size; | ||
212 | rc = appldata_register_ops(&ops); | ||
213 | if (rc != 0) { | ||
214 | P_ERROR("Error registering ops, rc = %i\n", rc); | ||
215 | kfree(appldata_os_data); | ||
216 | } else { | ||
217 | P_DEBUG("%s-ops registered!\n", ops.name); | ||
218 | } | ||
219 | out: | ||
220 | return rc; | ||
221 | } | ||
222 | |||
223 | /* | ||
224 | * appldata_os_exit() | ||
225 | * | ||
226 | * unregister ops | ||
227 | */ | ||
228 | static void __exit appldata_os_exit(void) | ||
229 | { | ||
230 | appldata_unregister_ops(&ops); | ||
231 | kfree(appldata_os_data); | ||
232 | P_DEBUG("%s-ops unregistered!\n", ops.name); | ||
233 | } | ||
234 | |||
235 | |||
236 | module_init(appldata_os_init); | ||
237 | module_exit(appldata_os_exit); | ||
238 | |||
239 | MODULE_LICENSE("GPL"); | ||
240 | MODULE_AUTHOR("Gerald Schaefer"); | ||
241 | MODULE_DESCRIPTION("Linux-VM Monitor Stream, OS statistics"); | ||