blob: 803f3645edf673d963cb901c4d49dcc965ff77f1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Gerald Schaefer5b5dd212006-06-29 15:08:35 +02008 * Copyright (C) 2003,2006 IBM Corporation, IBM Deutschland Entwicklung GmbH.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
Gerald Schaefer5b5dd212006-06-29 15:08:35 +020010 * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/slab.h>
16#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/interrupt.h>
18#include <linux/proc_fs.h>
Heiko Carstens2dcea572006-09-29 01:58:41 -070019#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/swap.h>
21#include <linux/pagemap.h>
22#include <linux/sysctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/notifier.h>
24#include <linux/cpu.h>
Gerald Schaeferf26d5832005-06-04 15:43:33 -070025#include <linux/workqueue.h>
Gerald Schaefer1f38d612006-09-20 15:59:26 +020026#include <asm/appldata.h>
27#include <asm/timer.h>
28#include <asm/uaccess.h>
29#include <asm/io.h>
30#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042/*
43 * /proc entries (sysctl)
44 */
45static const char appldata_proc_name[APPLDATA_PROC_NAME_LENGTH] = "appldata";
46static int appldata_timer_handler(ctl_table *ctl, int write, struct file *filp,
47 void __user *buffer, size_t *lenp, loff_t *ppos);
48static int appldata_interval_handler(ctl_table *ctl, int write,
49 struct file *filp,
50 void __user *buffer,
51 size_t *lenp, loff_t *ppos);
52
53static struct ctl_table_header *appldata_sysctl_header;
54static struct ctl_table appldata_table[] = {
55 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 .procname = "timer",
57 .mode = S_IRUGO | S_IWUSR,
58 .proc_handler = &appldata_timer_handler,
59 },
60 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 .procname = "interval",
62 .mode = S_IRUGO | S_IWUSR,
63 .proc_handler = &appldata_interval_handler,
64 },
Heiko Carstens37e3a6a2007-11-20 11:13:34 +010065 { },
Linus Torvalds1da177e2005-04-16 15:20:36 -070066};
67
68static struct ctl_table appldata_dir_table[] = {
69 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 .procname = appldata_proc_name,
71 .maxlen = 0,
72 .mode = S_IRUGO | S_IXUGO,
73 .child = appldata_table,
74 },
Heiko Carstens37e3a6a2007-11-20 11:13:34 +010075 { },
Linus Torvalds1da177e2005-04-16 15:20:36 -070076};
77
78/*
79 * Timer
80 */
Heiko Carstens2b67fc42007-02-05 21:16:47 +010081static DEFINE_PER_CPU(struct vtimer_list, appldata_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082static atomic_t appldata_expire_count = ATOMIC_INIT(0);
83
84static DEFINE_SPINLOCK(appldata_timer_lock);
85static int appldata_interval = APPLDATA_CPU_INTERVAL;
86static int appldata_timer_active;
87
88/*
Gerald Schaeferf26d5832005-06-04 15:43:33 -070089 * Work queue
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 */
Gerald Schaeferf26d5832005-06-04 15:43:33 -070091static struct workqueue_struct *appldata_wq;
David Howells6d5aefb2006-12-05 19:36:26 +000092static void appldata_work_fn(struct work_struct *work);
93static DECLARE_WORK(appldata_work, appldata_work_fn);
Gerald Schaeferf26d5832005-06-04 15:43:33 -070094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/*
97 * Ops list
98 */
99static DEFINE_SPINLOCK(appldata_ops_lock);
100static LIST_HEAD(appldata_ops_list);
101
102
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700103/*************************** timer, work, DIAG *******************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104/*
105 * appldata_timer_function()
106 *
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700107 * schedule work and reschedule timer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 */
Heiko Carstens9d0a57c2006-10-11 15:31:26 +0200109static void appldata_timer_function(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
111 P_DEBUG(" -= Timer =-\n");
112 P_DEBUG("CPU: %i, expire_count: %i\n", smp_processor_id(),
113 atomic_read(&appldata_expire_count));
114 if (atomic_dec_and_test(&appldata_expire_count)) {
115 atomic_set(&appldata_expire_count, num_online_cpus());
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700116 queue_work(appldata_wq, (struct work_struct *) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118}
119
120/*
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700121 * appldata_work_fn()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 *
123 * call data gathering function for each (active) module
124 */
David Howells6d5aefb2006-12-05 19:36:26 +0000125static void appldata_work_fn(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 struct list_head *lh;
128 struct appldata_ops *ops;
129 int i;
130
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700131 P_DEBUG(" -= Work Queue =-\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 i = 0;
Gerald Schaefer17605372008-05-30 10:03:28 +0200133 get_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 spin_lock(&appldata_ops_lock);
135 list_for_each(lh, &appldata_ops_list) {
136 ops = list_entry(lh, struct appldata_ops, list);
137 P_DEBUG("list_for_each loop: %i) active = %u, name = %s\n",
138 ++i, ops->active, ops->name);
139 if (ops->active == 1) {
140 ops->callback(ops->data);
141 }
142 }
143 spin_unlock(&appldata_ops_lock);
Gerald Schaefer17605372008-05-30 10:03:28 +0200144 put_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
147/*
148 * appldata_diag()
149 *
150 * prepare parameter list, issue DIAG 0xDC
151 */
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200152int appldata_diag(char record_nr, u16 function, unsigned long buffer,
153 u16 length, char *mod_lvl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Gerald Schaefer1f38d612006-09-20 15:59:26 +0200155 struct appldata_product_id id = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 .prod_nr = {0xD3, 0xC9, 0xD5, 0xE4,
Gerald Schaefer1f38d612006-09-20 15:59:26 +0200157 0xE7, 0xD2, 0xD9}, /* "LINUXKR" */
158 .prod_fn = 0xD5D3, /* "NL" */
Gerald Schaefer1f38d612006-09-20 15:59:26 +0200159 .version_nr = 0xF2F6, /* "26" */
160 .release_nr = 0xF0F1, /* "01" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 };
162
Gerald Schaefer925afbd2006-09-28 16:55:23 +0200163 id.record_nr = record_nr;
164 id.mod_lvl = (mod_lvl[0]) << 8 | mod_lvl[1];
Gerald Schaefer1f38d612006-09-20 15:59:26 +0200165 return appldata_asm(&id, function, (void *) buffer, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166}
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700167/************************ timer, work, DIAG <END> ****************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169
170/****************************** /proc stuff **********************************/
171
172/*
173 * appldata_mod_vtimer_wrap()
174 *
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200175 * wrapper function for mod_virt_timer(), because smp_call_function_single()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 * accepts only one parameter.
177 */
178static void __appldata_mod_vtimer_wrap(void *p) {
179 struct {
180 struct vtimer_list *timer;
181 u64 expires;
182 } *args = p;
183 mod_virt_timer(args->timer, args->expires);
184}
185
186#define APPLDATA_ADD_TIMER 0
187#define APPLDATA_DEL_TIMER 1
188#define APPLDATA_MOD_TIMER 2
189
190/*
191 * __appldata_vtimer_setup()
192 *
193 * Add, delete or modify virtual timers on all online cpus.
194 * The caller needs to get the appldata_timer_lock spinlock.
195 */
196static void
197__appldata_vtimer_setup(int cmd)
198{
199 u64 per_cpu_interval;
200 int i;
201
202 switch (cmd) {
203 case APPLDATA_ADD_TIMER:
204 if (appldata_timer_active)
205 break;
206 per_cpu_interval = (u64) (appldata_interval*1000 /
207 num_online_cpus()) * TOD_MICRO;
208 for_each_online_cpu(i) {
209 per_cpu(appldata_timer, i).expires = per_cpu_interval;
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200210 smp_call_function_single(i, add_virt_timer_periodic,
211 &per_cpu(appldata_timer, i),
212 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 }
214 appldata_timer_active = 1;
215 P_INFO("Monitoring timer started.\n");
216 break;
217 case APPLDATA_DEL_TIMER:
218 for_each_online_cpu(i)
219 del_virt_timer(&per_cpu(appldata_timer, i));
220 if (!appldata_timer_active)
221 break;
222 appldata_timer_active = 0;
223 atomic_set(&appldata_expire_count, num_online_cpus());
224 P_INFO("Monitoring timer stopped.\n");
225 break;
226 case APPLDATA_MOD_TIMER:
227 per_cpu_interval = (u64) (appldata_interval*1000 /
228 num_online_cpus()) * TOD_MICRO;
229 if (!appldata_timer_active)
230 break;
231 for_each_online_cpu(i) {
232 struct {
233 struct vtimer_list *timer;
234 u64 expires;
235 } args;
236 args.timer = &per_cpu(appldata_timer, i);
237 args.expires = per_cpu_interval;
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200238 smp_call_function_single(i, __appldata_mod_vtimer_wrap,
239 &args, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 }
241 }
242}
243
244/*
245 * appldata_timer_handler()
246 *
247 * Start/Stop timer, show status of timer (0 = not active, 1 = active)
248 */
249static int
250appldata_timer_handler(ctl_table *ctl, int write, struct file *filp,
251 void __user *buffer, size_t *lenp, loff_t *ppos)
252{
253 int len;
254 char buf[2];
255
256 if (!*lenp || *ppos) {
257 *lenp = 0;
258 return 0;
259 }
260 if (!write) {
261 len = sprintf(buf, appldata_timer_active ? "1\n" : "0\n");
262 if (len > *lenp)
263 len = *lenp;
264 if (copy_to_user(buffer, buf, len))
265 return -EFAULT;
266 goto out;
267 }
268 len = *lenp;
269 if (copy_from_user(buf, buffer, len > sizeof(buf) ? sizeof(buf) : len))
270 return -EFAULT;
Gerald Schaefer17605372008-05-30 10:03:28 +0200271 get_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 spin_lock(&appldata_timer_lock);
273 if (buf[0] == '1')
274 __appldata_vtimer_setup(APPLDATA_ADD_TIMER);
275 else if (buf[0] == '0')
276 __appldata_vtimer_setup(APPLDATA_DEL_TIMER);
277 spin_unlock(&appldata_timer_lock);
Gerald Schaefer17605372008-05-30 10:03:28 +0200278 put_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279out:
280 *lenp = len;
281 *ppos += len;
282 return 0;
283}
284
285/*
286 * appldata_interval_handler()
287 *
288 * Set (CPU) timer interval for collection of data (in milliseconds), show
289 * current timer interval.
290 */
291static int
292appldata_interval_handler(ctl_table *ctl, int write, struct file *filp,
293 void __user *buffer, size_t *lenp, loff_t *ppos)
294{
295 int len, interval;
296 char buf[16];
297
298 if (!*lenp || *ppos) {
299 *lenp = 0;
300 return 0;
301 }
302 if (!write) {
303 len = sprintf(buf, "%i\n", appldata_interval);
304 if (len > *lenp)
305 len = *lenp;
306 if (copy_to_user(buffer, buf, len))
307 return -EFAULT;
308 goto out;
309 }
310 len = *lenp;
311 if (copy_from_user(buf, buffer, len > sizeof(buf) ? sizeof(buf) : len)) {
312 return -EFAULT;
313 }
Gerald Schaefer95425f12006-10-27 12:39:13 +0200314 interval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 sscanf(buf, "%i", &interval);
316 if (interval <= 0) {
317 P_ERROR("Timer CPU interval has to be > 0!\n");
318 return -EINVAL;
319 }
320
Gerald Schaefer17605372008-05-30 10:03:28 +0200321 get_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 spin_lock(&appldata_timer_lock);
323 appldata_interval = interval;
324 __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
325 spin_unlock(&appldata_timer_lock);
Gerald Schaefer17605372008-05-30 10:03:28 +0200326 put_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 P_INFO("Monitoring CPU interval set to %u milliseconds.\n",
329 interval);
330out:
331 *lenp = len;
332 *ppos += len;
333 return 0;
334}
335
336/*
337 * appldata_generic_handler()
338 *
339 * Generic start/stop monitoring and DIAG, show status of
340 * monitoring (0 = not in process, 1 = in process)
341 */
342static int
343appldata_generic_handler(ctl_table *ctl, int write, struct file *filp,
344 void __user *buffer, size_t *lenp, loff_t *ppos)
345{
346 struct appldata_ops *ops = NULL, *tmp_ops;
347 int rc, len, found;
348 char buf[2];
349 struct list_head *lh;
350
351 found = 0;
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700352 spin_lock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 list_for_each(lh, &appldata_ops_list) {
354 tmp_ops = list_entry(lh, struct appldata_ops, list);
355 if (&tmp_ops->ctl_table[2] == ctl) {
356 found = 1;
357 }
358 }
359 if (!found) {
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700360 spin_unlock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 return -ENODEV;
362 }
363 ops = ctl->data;
364 if (!try_module_get(ops->owner)) { // protect this function
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700365 spin_unlock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 return -ENODEV;
367 }
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700368 spin_unlock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370 if (!*lenp || *ppos) {
371 *lenp = 0;
372 module_put(ops->owner);
373 return 0;
374 }
375 if (!write) {
376 len = sprintf(buf, ops->active ? "1\n" : "0\n");
377 if (len > *lenp)
378 len = *lenp;
379 if (copy_to_user(buffer, buf, len)) {
380 module_put(ops->owner);
381 return -EFAULT;
382 }
383 goto out;
384 }
385 len = *lenp;
386 if (copy_from_user(buf, buffer,
387 len > sizeof(buf) ? sizeof(buf) : len)) {
388 module_put(ops->owner);
389 return -EFAULT;
390 }
391
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700392 spin_lock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if ((buf[0] == '1') && (ops->active == 0)) {
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700394 // protect work queue callback
395 if (!try_module_get(ops->owner)) {
396 spin_unlock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 module_put(ops->owner);
398 return -ENODEV;
399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 ops->callback(ops->data); // init record
401 rc = appldata_diag(ops->record_nr,
402 APPLDATA_START_INTERVAL_REC,
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200403 (unsigned long) ops->data, ops->size,
404 ops->mod_lvl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 if (rc != 0) {
406 P_ERROR("START DIAG 0xDC for %s failed, "
407 "return code: %d\n", ops->name, rc);
408 module_put(ops->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 } else {
410 P_INFO("Monitoring %s data enabled, "
411 "DIAG 0xDC started.\n", ops->name);
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200412 ops->active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 }
414 } else if ((buf[0] == '0') && (ops->active == 1)) {
415 ops->active = 0;
416 rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200417 (unsigned long) ops->data, ops->size,
418 ops->mod_lvl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 if (rc != 0) {
420 P_ERROR("STOP DIAG 0xDC for %s failed, "
421 "return code: %d\n", ops->name, rc);
422 } else {
423 P_INFO("Monitoring %s data disabled, "
424 "DIAG 0xDC stopped.\n", ops->name);
425 }
426 module_put(ops->owner);
427 }
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700428 spin_unlock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429out:
430 *lenp = len;
431 *ppos += len;
432 module_put(ops->owner);
433 return 0;
434}
435
436/*************************** /proc stuff <END> *******************************/
437
438
439/************************* module-ops management *****************************/
440/*
441 * appldata_register_ops()
442 *
443 * update ops list, register /proc/sys entries
444 */
445int appldata_register_ops(struct appldata_ops *ops)
446{
Heiko Carstens37e3a6a2007-11-20 11:13:34 +0100447 if ((ops->size > APPLDATA_MAX_REC_SIZE) || (ops->size < 0))
448 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Heiko Carstens37e3a6a2007-11-20 11:13:34 +0100450 ops->ctl_table = kzalloc(4 * sizeof(struct ctl_table), GFP_KERNEL);
451 if (!ops->ctl_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700454 spin_lock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 list_add(&ops->list, &appldata_ops_list);
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700456 spin_unlock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 ops->ctl_table[0].procname = appldata_proc_name;
459 ops->ctl_table[0].maxlen = 0;
460 ops->ctl_table[0].mode = S_IRUGO | S_IXUGO;
461 ops->ctl_table[0].child = &ops->ctl_table[2];
462
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 ops->ctl_table[2].procname = ops->name;
464 ops->ctl_table[2].mode = S_IRUGO | S_IWUSR;
465 ops->ctl_table[2].proc_handler = appldata_generic_handler;
466 ops->ctl_table[2].data = ops;
467
Eric W. Biederman0b4d4142007-02-14 00:34:09 -0800468 ops->sysctl_header = register_sysctl_table(ops->ctl_table);
Heiko Carstens37e3a6a2007-11-20 11:13:34 +0100469 if (!ops->sysctl_header)
470 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 P_INFO("%s-ops registered!\n", ops->name);
472 return 0;
Heiko Carstens37e3a6a2007-11-20 11:13:34 +0100473out:
474 spin_lock(&appldata_ops_lock);
475 list_del(&ops->list);
476 spin_unlock(&appldata_ops_lock);
477 kfree(ops->ctl_table);
478 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
481/*
482 * appldata_unregister_ops()
483 *
484 * update ops list, unregister /proc entries, stop DIAG if necessary
485 */
486void appldata_unregister_ops(struct appldata_ops *ops)
487{
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700488 spin_lock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 list_del(&ops->list);
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700490 spin_unlock(&appldata_ops_lock);
Al Viro330d57f2005-11-04 10:18:40 +0000491 unregister_sysctl_table(ops->sysctl_header);
Heiko Carstens37e3a6a2007-11-20 11:13:34 +0100492 kfree(ops->ctl_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 P_INFO("%s-ops unregistered!\n", ops->name);
494}
495/********************** module-ops management <END> **************************/
496
497
498/******************************* init / exit *********************************/
499
Heiko Carstens84b36a82007-06-19 13:10:03 +0200500static void __cpuinit appldata_online_cpu(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
502 init_virt_timer(&per_cpu(appldata_timer, cpu));
503 per_cpu(appldata_timer, cpu).function = appldata_timer_function;
504 per_cpu(appldata_timer, cpu).data = (unsigned long)
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700505 &appldata_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 atomic_inc(&appldata_expire_count);
507 spin_lock(&appldata_timer_lock);
508 __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
509 spin_unlock(&appldata_timer_lock);
510}
511
Satyam Sharma076fc802007-10-12 16:11:32 +0200512static void __cpuinit appldata_offline_cpu(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513{
514 del_virt_timer(&per_cpu(appldata_timer, cpu));
515 if (atomic_dec_and_test(&appldata_expire_count)) {
516 atomic_set(&appldata_expire_count, num_online_cpus());
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700517 queue_work(appldata_wq, &appldata_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
519 spin_lock(&appldata_timer_lock);
520 __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
521 spin_unlock(&appldata_timer_lock);
522}
523
Satyam Sharma11b8bf02007-10-12 16:11:31 +0200524static int __cpuinit appldata_cpu_notify(struct notifier_block *self,
525 unsigned long action,
526 void *hcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
528 switch (action) {
529 case CPU_ONLINE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700530 case CPU_ONLINE_FROZEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 appldata_online_cpu((long) hcpu);
532 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 case CPU_DEAD:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700534 case CPU_DEAD_FROZEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 appldata_offline_cpu((long) hcpu);
536 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 default:
538 break;
539 }
540 return NOTIFY_OK;
541}
542
Heiko Carstens84b36a82007-06-19 13:10:03 +0200543static struct notifier_block __cpuinitdata appldata_nb = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .notifier_call = appldata_cpu_notify,
545};
546
547/*
548 * appldata_init()
549 *
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700550 * init timer, register /proc entries
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 */
552static int __init appldata_init(void)
553{
554 int i;
555
556 P_DEBUG("sizeof(parameter_list) = %lu\n",
557 sizeof(struct appldata_parameter_list));
558
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700559 appldata_wq = create_singlethread_workqueue("appldata");
560 if (!appldata_wq) {
561 P_ERROR("Could not create work queue\n");
562 return -ENOMEM;
563 }
564
Gerald Schaefer17605372008-05-30 10:03:28 +0200565 get_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 for_each_online_cpu(i)
567 appldata_online_cpu(i);
Gerald Schaefer17605372008-05-30 10:03:28 +0200568 put_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 /* Register cpu hotplug notifier */
Chandra Seetharamanbe6b5a32006-07-30 03:03:37 -0700571 register_hotcpu_notifier(&appldata_nb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Eric W. Biederman0b4d4142007-02-14 00:34:09 -0800573 appldata_sysctl_header = register_sysctl_table(appldata_dir_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 P_DEBUG("Base interface initialized.\n");
576 return 0;
577}
578
Satyam Sharma076fc802007-10-12 16:11:32 +0200579__initcall(appldata_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581/**************************** init / exit <END> ******************************/
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583EXPORT_SYMBOL_GPL(appldata_register_ops);
584EXPORT_SYMBOL_GPL(appldata_unregister_ops);
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200585EXPORT_SYMBOL_GPL(appldata_diag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Gerald Schaefer0c3252d2008-07-14 09:57:27 +0200587#ifdef CONFIG_SWAP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588EXPORT_SYMBOL_GPL(si_swapinfo);
Gerald Schaefer0c3252d2008-07-14 09:57:27 +0200589#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590EXPORT_SYMBOL_GPL(nr_threads);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591EXPORT_SYMBOL_GPL(nr_running);
592EXPORT_SYMBOL_GPL(nr_iowait);