blob: a06a47cdd5e06e30efbde7f92b882fd2c948c610 [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 Schaeferd3ae9422008-07-14 09:59:34 +02008 * Copyright IBM Corp. 2003, 2008
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{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (atomic_dec_and_test(&appldata_expire_count)) {
112 atomic_set(&appldata_expire_count, num_online_cpus());
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700113 queue_work(appldata_wq, (struct work_struct *) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115}
116
117/*
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700118 * appldata_work_fn()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 *
120 * call data gathering function for each (active) module
121 */
David Howells6d5aefb2006-12-05 19:36:26 +0000122static void appldata_work_fn(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
124 struct list_head *lh;
125 struct appldata_ops *ops;
126 int i;
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 i = 0;
Gerald Schaefer17605372008-05-30 10:03:28 +0200129 get_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 spin_lock(&appldata_ops_lock);
131 list_for_each(lh, &appldata_ops_list) {
132 ops = list_entry(lh, struct appldata_ops, list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 if (ops->active == 1) {
134 ops->callback(ops->data);
135 }
136 }
137 spin_unlock(&appldata_ops_lock);
Gerald Schaefer17605372008-05-30 10:03:28 +0200138 put_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
141/*
142 * appldata_diag()
143 *
144 * prepare parameter list, issue DIAG 0xDC
145 */
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200146int appldata_diag(char record_nr, u16 function, unsigned long buffer,
147 u16 length, char *mod_lvl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Gerald Schaefer1f38d612006-09-20 15:59:26 +0200149 struct appldata_product_id id = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 .prod_nr = {0xD3, 0xC9, 0xD5, 0xE4,
Gerald Schaefer1f38d612006-09-20 15:59:26 +0200151 0xE7, 0xD2, 0xD9}, /* "LINUXKR" */
152 .prod_fn = 0xD5D3, /* "NL" */
Gerald Schaefer1f38d612006-09-20 15:59:26 +0200153 .version_nr = 0xF2F6, /* "26" */
154 .release_nr = 0xF0F1, /* "01" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 };
156
Gerald Schaefer925afbd2006-09-28 16:55:23 +0200157 id.record_nr = record_nr;
158 id.mod_lvl = (mod_lvl[0]) << 8 | mod_lvl[1];
Gerald Schaefer1f38d612006-09-20 15:59:26 +0200159 return appldata_asm(&id, function, (void *) buffer, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700161/************************ timer, work, DIAG <END> ****************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163
164/****************************** /proc stuff **********************************/
165
166/*
167 * appldata_mod_vtimer_wrap()
168 *
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200169 * wrapper function for mod_virt_timer(), because smp_call_function_single()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 * accepts only one parameter.
171 */
172static void __appldata_mod_vtimer_wrap(void *p) {
173 struct {
174 struct vtimer_list *timer;
175 u64 expires;
176 } *args = p;
177 mod_virt_timer(args->timer, args->expires);
178}
179
180#define APPLDATA_ADD_TIMER 0
181#define APPLDATA_DEL_TIMER 1
182#define APPLDATA_MOD_TIMER 2
183
184/*
185 * __appldata_vtimer_setup()
186 *
187 * Add, delete or modify virtual timers on all online cpus.
188 * The caller needs to get the appldata_timer_lock spinlock.
189 */
190static void
191__appldata_vtimer_setup(int cmd)
192{
193 u64 per_cpu_interval;
194 int i;
195
196 switch (cmd) {
197 case APPLDATA_ADD_TIMER:
198 if (appldata_timer_active)
199 break;
200 per_cpu_interval = (u64) (appldata_interval*1000 /
201 num_online_cpus()) * TOD_MICRO;
202 for_each_online_cpu(i) {
203 per_cpu(appldata_timer, i).expires = per_cpu_interval;
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200204 smp_call_function_single(i, add_virt_timer_periodic,
205 &per_cpu(appldata_timer, i),
Jens Axboe8691e5a2008-06-06 11:18:06 +0200206 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 }
208 appldata_timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 break;
210 case APPLDATA_DEL_TIMER:
211 for_each_online_cpu(i)
212 del_virt_timer(&per_cpu(appldata_timer, i));
213 if (!appldata_timer_active)
214 break;
215 appldata_timer_active = 0;
216 atomic_set(&appldata_expire_count, num_online_cpus());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 break;
218 case APPLDATA_MOD_TIMER:
219 per_cpu_interval = (u64) (appldata_interval*1000 /
220 num_online_cpus()) * TOD_MICRO;
221 if (!appldata_timer_active)
222 break;
223 for_each_online_cpu(i) {
224 struct {
225 struct vtimer_list *timer;
226 u64 expires;
227 } args;
228 args.timer = &per_cpu(appldata_timer, i);
229 args.expires = per_cpu_interval;
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200230 smp_call_function_single(i, __appldata_mod_vtimer_wrap,
Jens Axboe8691e5a2008-06-06 11:18:06 +0200231 &args, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
233 }
234}
235
236/*
237 * appldata_timer_handler()
238 *
239 * Start/Stop timer, show status of timer (0 = not active, 1 = active)
240 */
241static int
242appldata_timer_handler(ctl_table *ctl, int write, struct file *filp,
243 void __user *buffer, size_t *lenp, loff_t *ppos)
244{
245 int len;
246 char buf[2];
247
248 if (!*lenp || *ppos) {
249 *lenp = 0;
250 return 0;
251 }
252 if (!write) {
253 len = sprintf(buf, appldata_timer_active ? "1\n" : "0\n");
254 if (len > *lenp)
255 len = *lenp;
256 if (copy_to_user(buffer, buf, len))
257 return -EFAULT;
258 goto out;
259 }
260 len = *lenp;
261 if (copy_from_user(buf, buffer, len > sizeof(buf) ? sizeof(buf) : len))
262 return -EFAULT;
Gerald Schaefer17605372008-05-30 10:03:28 +0200263 get_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 spin_lock(&appldata_timer_lock);
265 if (buf[0] == '1')
266 __appldata_vtimer_setup(APPLDATA_ADD_TIMER);
267 else if (buf[0] == '0')
268 __appldata_vtimer_setup(APPLDATA_DEL_TIMER);
269 spin_unlock(&appldata_timer_lock);
Gerald Schaefer17605372008-05-30 10:03:28 +0200270 put_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271out:
272 *lenp = len;
273 *ppos += len;
274 return 0;
275}
276
277/*
278 * appldata_interval_handler()
279 *
280 * Set (CPU) timer interval for collection of data (in milliseconds), show
281 * current timer interval.
282 */
283static int
284appldata_interval_handler(ctl_table *ctl, int write, struct file *filp,
285 void __user *buffer, size_t *lenp, loff_t *ppos)
286{
287 int len, interval;
288 char buf[16];
289
290 if (!*lenp || *ppos) {
291 *lenp = 0;
292 return 0;
293 }
294 if (!write) {
295 len = sprintf(buf, "%i\n", appldata_interval);
296 if (len > *lenp)
297 len = *lenp;
298 if (copy_to_user(buffer, buf, len))
299 return -EFAULT;
300 goto out;
301 }
302 len = *lenp;
303 if (copy_from_user(buf, buffer, len > sizeof(buf) ? sizeof(buf) : len)) {
304 return -EFAULT;
305 }
Gerald Schaefer95425f12006-10-27 12:39:13 +0200306 interval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 sscanf(buf, "%i", &interval);
Gerald Schaeferd3ae9422008-07-14 09:59:34 +0200308 if (interval <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Gerald Schaefer17605372008-05-30 10:03:28 +0200311 get_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 spin_lock(&appldata_timer_lock);
313 appldata_interval = interval;
314 __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
315 spin_unlock(&appldata_timer_lock);
Gerald Schaefer17605372008-05-30 10:03:28 +0200316 put_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317out:
318 *lenp = len;
319 *ppos += len;
320 return 0;
321}
322
323/*
324 * appldata_generic_handler()
325 *
326 * Generic start/stop monitoring and DIAG, show status of
327 * monitoring (0 = not in process, 1 = in process)
328 */
329static int
330appldata_generic_handler(ctl_table *ctl, int write, struct file *filp,
331 void __user *buffer, size_t *lenp, loff_t *ppos)
332{
333 struct appldata_ops *ops = NULL, *tmp_ops;
334 int rc, len, found;
335 char buf[2];
336 struct list_head *lh;
337
338 found = 0;
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700339 spin_lock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 list_for_each(lh, &appldata_ops_list) {
341 tmp_ops = list_entry(lh, struct appldata_ops, list);
342 if (&tmp_ops->ctl_table[2] == ctl) {
343 found = 1;
344 }
345 }
346 if (!found) {
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700347 spin_unlock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 return -ENODEV;
349 }
350 ops = ctl->data;
351 if (!try_module_get(ops->owner)) { // protect this function
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700352 spin_unlock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return -ENODEV;
354 }
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700355 spin_unlock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 if (!*lenp || *ppos) {
358 *lenp = 0;
359 module_put(ops->owner);
360 return 0;
361 }
362 if (!write) {
363 len = sprintf(buf, ops->active ? "1\n" : "0\n");
364 if (len > *lenp)
365 len = *lenp;
366 if (copy_to_user(buffer, buf, len)) {
367 module_put(ops->owner);
368 return -EFAULT;
369 }
370 goto out;
371 }
372 len = *lenp;
373 if (copy_from_user(buf, buffer,
374 len > sizeof(buf) ? sizeof(buf) : len)) {
375 module_put(ops->owner);
376 return -EFAULT;
377 }
378
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700379 spin_lock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 if ((buf[0] == '1') && (ops->active == 0)) {
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700381 // protect work queue callback
382 if (!try_module_get(ops->owner)) {
383 spin_unlock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 module_put(ops->owner);
385 return -ENODEV;
386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 ops->callback(ops->data); // init record
388 rc = appldata_diag(ops->record_nr,
389 APPLDATA_START_INTERVAL_REC,
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200390 (unsigned long) ops->data, ops->size,
391 ops->mod_lvl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 if (rc != 0) {
393 P_ERROR("START DIAG 0xDC for %s failed, "
394 "return code: %d\n", ops->name, rc);
395 module_put(ops->owner);
Gerald Schaeferd3ae9422008-07-14 09:59:34 +0200396 } else
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200397 ops->active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 } else if ((buf[0] == '0') && (ops->active == 1)) {
399 ops->active = 0;
400 rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200401 (unsigned long) ops->data, ops->size,
402 ops->mod_lvl);
Gerald Schaeferd3ae9422008-07-14 09:59:34 +0200403 if (rc != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 P_ERROR("STOP DIAG 0xDC for %s failed, "
405 "return code: %d\n", ops->name, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 module_put(ops->owner);
407 }
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700408 spin_unlock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409out:
410 *lenp = len;
411 *ppos += len;
412 module_put(ops->owner);
413 return 0;
414}
415
416/*************************** /proc stuff <END> *******************************/
417
418
419/************************* module-ops management *****************************/
420/*
421 * appldata_register_ops()
422 *
423 * update ops list, register /proc/sys entries
424 */
425int appldata_register_ops(struct appldata_ops *ops)
426{
Roel Kluin13f8b7c2008-10-28 11:10:18 +0100427 if (ops->size > APPLDATA_MAX_REC_SIZE)
Heiko Carstens37e3a6a2007-11-20 11:13:34 +0100428 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Heiko Carstens37e3a6a2007-11-20 11:13:34 +0100430 ops->ctl_table = kzalloc(4 * sizeof(struct ctl_table), GFP_KERNEL);
431 if (!ops->ctl_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700434 spin_lock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 list_add(&ops->list, &appldata_ops_list);
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700436 spin_unlock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 ops->ctl_table[0].procname = appldata_proc_name;
439 ops->ctl_table[0].maxlen = 0;
440 ops->ctl_table[0].mode = S_IRUGO | S_IXUGO;
441 ops->ctl_table[0].child = &ops->ctl_table[2];
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 ops->ctl_table[2].procname = ops->name;
444 ops->ctl_table[2].mode = S_IRUGO | S_IWUSR;
445 ops->ctl_table[2].proc_handler = appldata_generic_handler;
446 ops->ctl_table[2].data = ops;
447
Eric W. Biederman0b4d4142007-02-14 00:34:09 -0800448 ops->sysctl_header = register_sysctl_table(ops->ctl_table);
Heiko Carstens37e3a6a2007-11-20 11:13:34 +0100449 if (!ops->sysctl_header)
450 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 return 0;
Heiko Carstens37e3a6a2007-11-20 11:13:34 +0100452out:
453 spin_lock(&appldata_ops_lock);
454 list_del(&ops->list);
455 spin_unlock(&appldata_ops_lock);
456 kfree(ops->ctl_table);
457 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458}
459
460/*
461 * appldata_unregister_ops()
462 *
463 * update ops list, unregister /proc entries, stop DIAG if necessary
464 */
465void appldata_unregister_ops(struct appldata_ops *ops)
466{
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700467 spin_lock(&appldata_ops_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 list_del(&ops->list);
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700469 spin_unlock(&appldata_ops_lock);
Al Viro330d57f2005-11-04 10:18:40 +0000470 unregister_sysctl_table(ops->sysctl_header);
Heiko Carstens37e3a6a2007-11-20 11:13:34 +0100471 kfree(ops->ctl_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472}
473/********************** module-ops management <END> **************************/
474
475
476/******************************* init / exit *********************************/
477
Heiko Carstens84b36a82007-06-19 13:10:03 +0200478static void __cpuinit appldata_online_cpu(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
480 init_virt_timer(&per_cpu(appldata_timer, cpu));
481 per_cpu(appldata_timer, cpu).function = appldata_timer_function;
482 per_cpu(appldata_timer, cpu).data = (unsigned long)
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700483 &appldata_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 atomic_inc(&appldata_expire_count);
485 spin_lock(&appldata_timer_lock);
486 __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
487 spin_unlock(&appldata_timer_lock);
488}
489
Satyam Sharma076fc802007-10-12 16:11:32 +0200490static void __cpuinit appldata_offline_cpu(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
492 del_virt_timer(&per_cpu(appldata_timer, cpu));
493 if (atomic_dec_and_test(&appldata_expire_count)) {
494 atomic_set(&appldata_expire_count, num_online_cpus());
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700495 queue_work(appldata_wq, &appldata_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497 spin_lock(&appldata_timer_lock);
498 __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
499 spin_unlock(&appldata_timer_lock);
500}
501
Satyam Sharma11b8bf02007-10-12 16:11:31 +0200502static int __cpuinit appldata_cpu_notify(struct notifier_block *self,
503 unsigned long action,
504 void *hcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
506 switch (action) {
507 case CPU_ONLINE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700508 case CPU_ONLINE_FROZEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 appldata_online_cpu((long) hcpu);
510 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 case CPU_DEAD:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700512 case CPU_DEAD_FROZEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 appldata_offline_cpu((long) hcpu);
514 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 default:
516 break;
517 }
518 return NOTIFY_OK;
519}
520
Heiko Carstens84b36a82007-06-19 13:10:03 +0200521static struct notifier_block __cpuinitdata appldata_nb = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 .notifier_call = appldata_cpu_notify,
523};
524
525/*
526 * appldata_init()
527 *
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700528 * init timer, register /proc entries
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 */
530static int __init appldata_init(void)
531{
532 int i;
533
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700534 appldata_wq = create_singlethread_workqueue("appldata");
Gerald Schaeferd3ae9422008-07-14 09:59:34 +0200535 if (!appldata_wq)
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700536 return -ENOMEM;
Gerald Schaeferf26d5832005-06-04 15:43:33 -0700537
Gerald Schaefer17605372008-05-30 10:03:28 +0200538 get_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 for_each_online_cpu(i)
540 appldata_online_cpu(i);
Gerald Schaefer17605372008-05-30 10:03:28 +0200541 put_online_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543 /* Register cpu hotplug notifier */
Chandra Seetharamanbe6b5a32006-07-30 03:03:37 -0700544 register_hotcpu_notifier(&appldata_nb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Eric W. Biederman0b4d4142007-02-14 00:34:09 -0800546 appldata_sysctl_header = register_sysctl_table(appldata_dir_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 return 0;
548}
549
Satyam Sharma076fc802007-10-12 16:11:32 +0200550__initcall(appldata_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552/**************************** init / exit <END> ******************************/
553
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554EXPORT_SYMBOL_GPL(appldata_register_ops);
555EXPORT_SYMBOL_GPL(appldata_unregister_ops);
Gerald Schaefer5b5dd212006-06-29 15:08:35 +0200556EXPORT_SYMBOL_GPL(appldata_diag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
Gerald Schaefer0c3252d2008-07-14 09:57:27 +0200558#ifdef CONFIG_SWAP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559EXPORT_SYMBOL_GPL(si_swapinfo);
Gerald Schaefer0c3252d2008-07-14 09:57:27 +0200560#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561EXPORT_SYMBOL_GPL(nr_threads);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562EXPORT_SYMBOL_GPL(nr_running);
563EXPORT_SYMBOL_GPL(nr_iowait);