This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / arch / s390 / appldata / appldata_base.c
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 <linux/interrupt.h>
21 #include <linux/proc_fs.h>
22 #include <linux/page-flags.h>
23 #include <linux/swap.h>
24 #include <linux/pagemap.h>
25 #include <linux/sysctl.h>
26 #include <asm/timer.h>
27 //#include <linux/kernel_stat.h>
28 #include <linux/notifier.h>
29 #include <linux/cpu.h>
30
31 #include "appldata.h"
32
33
34 #define MY_PRINT_NAME   "appldata"              /* for debug messages, etc. */
35 #define APPLDATA_CPU_INTERVAL   10000           /* default (CPU) time for
36                                                    sampling interval in
37                                                    milliseconds */
38
39 #define TOD_MICRO       0x01000                 /* nr. of TOD clock units
40                                                    for 1 microsecond */
41 #ifndef CONFIG_ARCH_S390X
42
43 #define APPLDATA_START_INTERVAL_REC 0x00        /* Function codes for */
44 #define APPLDATA_STOP_REC           0x01        /* DIAG 0xDC      */
45 #define APPLDATA_GEN_EVENT_RECORD   0x02
46 #define APPLDATA_START_CONFIG_REC   0x03
47
48 #else
49
50 #define APPLDATA_START_INTERVAL_REC 0x80
51 #define APPLDATA_STOP_REC           0x81
52 #define APPLDATA_GEN_EVENT_RECORD   0x82
53 #define APPLDATA_START_CONFIG_REC   0x83
54
55 #endif /* CONFIG_ARCH_S390X */
56
57
58 /*
59  * Parameter list for DIAGNOSE X'DC'
60  */
61 #ifndef CONFIG_ARCH_S390X
62 struct appldata_parameter_list {
63         u16 diag;               /* The DIAGNOSE code X'00DC'          */
64         u8  function;           /* The function code for the DIAGNOSE */
65         u8  parlist_length;     /* Length of the parameter list       */
66         u32 product_id_addr;    /* Address of the 16-byte product ID  */
67         u16 reserved;
68         u16 buffer_length;      /* Length of the application data buffer  */
69         u32 buffer_addr;        /* Address of the application data buffer */
70 };
71 #else
72 struct appldata_parameter_list {
73         u16 diag;
74         u8  function;
75         u8  parlist_length;
76         u32 unused01;
77         u16 reserved;
78         u16 buffer_length;
79         u32 unused02;
80         u64 product_id_addr;
81         u64 buffer_addr;
82 };
83 #endif /* CONFIG_ARCH_S390X */
84
85 /*
86  * /proc entries (sysctl)
87  */
88 static const char appldata_proc_name[APPLDATA_PROC_NAME_LENGTH] = "appldata";
89 static int appldata_timer_handler(ctl_table *ctl, int write, struct file *filp,
90                                   void __user *buffer, size_t *lenp);
91 static int appldata_interval_handler(ctl_table *ctl, int write,
92                                          struct file *filp,
93                                          void __user *buffer,
94                                          size_t *lenp);
95
96 static struct ctl_table_header *appldata_sysctl_header;
97 static struct ctl_table appldata_table[] = {
98         {
99                 .ctl_name       = CTL_APPLDATA_TIMER,
100                 .procname       = "timer",
101                 .mode           = S_IRUGO | S_IWUSR,
102                 .proc_handler   = &appldata_timer_handler,
103         },
104         {
105                 .ctl_name       = CTL_APPLDATA_INTERVAL,
106                 .procname       = "interval",
107                 .mode           = S_IRUGO | S_IWUSR,
108                 .proc_handler   = &appldata_interval_handler,
109         },
110         { .ctl_name = 0 }
111 };
112
113 static struct ctl_table appldata_dir_table[] = {
114         {
115                 .ctl_name       = CTL_APPLDATA,
116                 .procname       = appldata_proc_name,
117                 .maxlen         = 0,
118                 .mode           = S_IRUGO | S_IXUGO,
119                 .child          = appldata_table,
120         },
121         { .ctl_name = 0 }
122 };
123
124 /*
125  * Timer
126  */
127 DEFINE_PER_CPU(struct vtimer_list, appldata_timer);
128 static atomic_t appldata_expire_count = ATOMIC_INIT(0);
129
130 static spinlock_t appldata_timer_lock = SPIN_LOCK_UNLOCKED;
131 static int appldata_interval = APPLDATA_CPU_INTERVAL;
132 static int appldata_timer_active;
133
134 /*
135  * Tasklet
136  */
137 static struct tasklet_struct appldata_tasklet_struct;
138
139 /*
140  * Ops list
141  */
142 static spinlock_t appldata_ops_lock = SPIN_LOCK_UNLOCKED;
143 static LIST_HEAD(appldata_ops_list);
144
145
146 /************************* timer, tasklet, DIAG ******************************/
147 /*
148  * appldata_timer_function()
149  *
150  * schedule tasklet and reschedule timer
151  */
152 static void appldata_timer_function(unsigned long data, struct pt_regs *regs)
153 {
154         P_DEBUG("   -= Timer =-\n");
155         P_DEBUG("CPU: %i, expire_count: %i\n", smp_processor_id(),
156                 atomic_read(&appldata_expire_count));
157         if (atomic_dec_and_test(&appldata_expire_count)) {
158                 atomic_set(&appldata_expire_count, num_online_cpus());
159                 tasklet_schedule((struct tasklet_struct *) data);
160         }
161 }
162
163 /*
164  * appldata_tasklet_function()
165  *
166  * call data gathering function for each (active) module
167  */
168 static void appldata_tasklet_function(unsigned long data)
169 {
170         struct list_head *lh;
171         struct appldata_ops *ops;
172         int i;
173
174         P_DEBUG("  -= Tasklet =-\n");
175         i = 0;
176         spin_lock(&appldata_ops_lock);
177         list_for_each(lh, &appldata_ops_list) {
178                 ops = list_entry(lh, struct appldata_ops, list);
179                 P_DEBUG("list_for_each loop: %i) active = %u, name = %s\n",
180                         ++i, ops->active, ops->name);
181                 if (ops->active == 1) {
182                         ops->callback(ops->data);
183                 }
184         }
185         spin_unlock(&appldata_ops_lock);
186 }
187
188 /*
189  * appldata_diag()
190  *
191  * prepare parameter list, issue DIAG 0xDC
192  */
193 static int appldata_diag(char record_nr, u16 function, unsigned long buffer,
194                         u16 length)
195 {
196         unsigned long ry;
197         struct appldata_product_id {
198                 char prod_nr[7];                        /* product nr. */
199                 char prod_fn[2];                        /* product function */
200                 char record_nr;                         /* record nr. */
201                 char version_nr[2];                     /* version */
202                 char release_nr[2];                     /* release */
203                 char mod_lvl[2];                        /* modification lvl. */
204         } appldata_product_id = {
205         /* all strings are EBCDIC, record_nr is byte */
206                 .prod_nr    = {0xD3, 0xC9, 0xD5, 0xE4,
207                                 0xE7, 0xD2, 0xD9},      /* "LINUXKR" */
208                 .prod_fn    = {0xD5, 0xD3},             /* "NL" */
209                 .record_nr  = record_nr,
210                 .version_nr = {0xF2, 0xF6},             /* "26" */
211                 .release_nr = {0xF0, 0xF1},             /* "01" */
212                 .mod_lvl    = {0xF0, 0xF0},             /* "00" */
213         };
214         struct appldata_parameter_list appldata_parameter_list = {
215                                 .diag = 0xDC,
216                                 .function = function,
217                                 .parlist_length =
218                                         sizeof(appldata_parameter_list),
219                                 .buffer_length = length,
220                                 .product_id_addr =
221                                         (unsigned long) &appldata_product_id,
222                                 .buffer_addr = virt_to_phys((void *) buffer)
223         };
224
225         if (!MACHINE_IS_VM)
226                 return -ENOSYS;
227         ry = -1;
228         asm volatile(
229                         "diag %1,%0,0xDC\n\t"
230                         : "=d" (ry) : "d" (&(appldata_parameter_list)) : "cc");
231         return (int) ry;
232 }
233 /********************** timer, tasklet, DIAG <END> ***************************/
234
235
236 /****************************** /proc stuff **********************************/
237
238 /*
239  * appldata_mod_vtimer_wrap()
240  *
241  * wrapper function for mod_virt_timer(), because smp_call_function_on()
242  * accepts only one parameter.
243  */
244 static void __appldata_mod_vtimer_wrap(void *p) {
245         struct {
246                 struct vtimer_list *timer;
247                 u64    expires;
248         } *args = p;
249         mod_virt_timer(args->timer, args->expires);
250 }
251
252 #define APPLDATA_ADD_TIMER      0
253 #define APPLDATA_DEL_TIMER      1
254 #define APPLDATA_MOD_TIMER      2
255
256 /*
257  * __appldata_vtimer_setup()
258  *
259  * Add, delete or modify virtual timers on all online cpus.
260  * The caller needs to get the appldata_timer_lock spinlock.
261  */
262 static void
263 __appldata_vtimer_setup(int cmd)
264 {
265         u64 per_cpu_interval;
266         int i;
267
268         switch (cmd) {
269         case APPLDATA_ADD_TIMER:
270                 if (appldata_timer_active)
271                         break;
272                 per_cpu_interval = (u64) (appldata_interval*1000 /
273                                           num_online_cpus()) * TOD_MICRO;
274                 for_each_online_cpu(i) {
275                         per_cpu(appldata_timer, i).expires = per_cpu_interval;
276                         smp_call_function_on(add_virt_timer_periodic,
277                                              &per_cpu(appldata_timer, i),
278                                              0, 1, i);
279                 }
280                 appldata_timer_active = 1;
281                 P_INFO("Monitoring timer started.\n");
282                 break;
283         case APPLDATA_DEL_TIMER:
284                 for_each_online_cpu(i)
285                         del_virt_timer(&per_cpu(appldata_timer, i));
286                 if (!appldata_timer_active)
287                         break;
288                 appldata_timer_active = 0;
289                 atomic_set(&appldata_expire_count, num_online_cpus());
290                 P_INFO("Monitoring timer stopped.\n");
291                 break;
292         case APPLDATA_MOD_TIMER:
293                 per_cpu_interval = (u64) (appldata_interval*1000 /
294                                           num_online_cpus()) * TOD_MICRO;
295                 if (!appldata_timer_active)
296                         break;
297                 for_each_online_cpu(i) {
298                         struct {
299                                 struct vtimer_list *timer;
300                                 u64    expires;
301                         } args;
302                         args.timer = &per_cpu(appldata_timer, i);
303                         args.expires = per_cpu_interval;
304                         smp_call_function_on(__appldata_mod_vtimer_wrap,
305                                              &args, 0, 1, i);
306                 }
307         }
308 }
309
310 /*
311  * appldata_timer_handler()
312  *
313  * Start/Stop timer, show status of timer (0 = not active, 1 = active)
314  */
315 static int
316 appldata_timer_handler(ctl_table *ctl, int write, struct file *filp,
317                            void __user *buffer, size_t *lenp)
318 {
319         int len;
320         char buf[2];
321
322         if (!*lenp || filp->f_pos) {
323                 *lenp = 0;
324                 return 0;
325         }
326         if (!write) {
327                 len = sprintf(buf, appldata_timer_active ? "1\n" : "0\n");
328                 if (len > *lenp)
329                         len = *lenp;
330                 if (copy_to_user(buffer, buf, len))
331                         return -EFAULT;
332                 goto out;
333         }
334         len = *lenp;
335         if (copy_from_user(buf, buffer, len > sizeof(buf) ? sizeof(buf) : len))
336                 return -EFAULT;
337         spin_lock(&appldata_timer_lock);
338         if (buf[0] == '1')
339                 __appldata_vtimer_setup(APPLDATA_ADD_TIMER);
340         else if (buf[0] == '0')
341                 __appldata_vtimer_setup(APPLDATA_DEL_TIMER);
342         spin_unlock(&appldata_timer_lock);
343 out:
344         *lenp = len;
345         filp->f_pos += len;
346         return 0;
347 }
348
349 /*
350  * appldata_interval_handler()
351  *
352  * Set (CPU) timer interval for collection of data (in milliseconds), show
353  * current timer interval.
354  */
355 static int
356 appldata_interval_handler(ctl_table *ctl, int write, struct file *filp,
357                            void __user *buffer, size_t *lenp)
358 {
359         int len, interval;
360         char buf[16];
361
362         if (!*lenp || filp->f_pos) {
363                 *lenp = 0;
364                 return 0;
365         }
366         if (!write) {
367                 len = sprintf(buf, "%i\n", appldata_interval);
368                 if (len > *lenp)
369                         len = *lenp;
370                 if (copy_to_user(buffer, buf, len))
371                         return -EFAULT;
372                 goto out;
373         }
374         len = *lenp;
375         if (copy_from_user(buf, buffer, len > sizeof(buf) ? sizeof(buf) : len)) {
376                 return -EFAULT;
377         }
378         sscanf(buf, "%i", &interval);
379         if (interval <= 0) {
380                 P_ERROR("Timer CPU interval has to be > 0!\n");
381                 return -EINVAL;
382         }
383
384         spin_lock(&appldata_timer_lock);
385         appldata_interval = interval;
386         __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
387         spin_unlock(&appldata_timer_lock);
388
389         P_INFO("Monitoring CPU interval set to %u milliseconds.\n",
390                  interval);
391 out:
392         *lenp = len;
393         filp->f_pos += len;
394         return 0;
395 }
396
397 /*
398  * appldata_generic_handler()
399  *
400  * Generic start/stop monitoring and DIAG, show status of
401  * monitoring (0 = not in process, 1 = in process)
402  */
403 static int
404 appldata_generic_handler(ctl_table *ctl, int write, struct file *filp,
405                            void __user *buffer, size_t *lenp)
406 {
407         struct appldata_ops *ops = NULL, *tmp_ops;
408         int rc, len, found;
409         char buf[2];
410         struct list_head *lh;
411
412         found = 0;
413         spin_lock_bh(&appldata_ops_lock);
414         list_for_each(lh, &appldata_ops_list) {
415                 tmp_ops = list_entry(lh, struct appldata_ops, list);
416                 if (&tmp_ops->ctl_table[2] == ctl) {
417                         found = 1;
418                 }
419         }
420         if (!found) {
421                 spin_unlock_bh(&appldata_ops_lock);
422                 return -ENODEV;
423         }
424         ops = ctl->data;
425         if (!try_module_get(ops->owner)) {      // protect this function
426                 spin_unlock_bh(&appldata_ops_lock);
427                 return -ENODEV;
428         }
429         spin_unlock_bh(&appldata_ops_lock);
430
431         if (!*lenp || filp->f_pos) {
432                 *lenp = 0;
433                 module_put(ops->owner);
434                 return 0;
435         }
436         if (!write) {
437                 len = sprintf(buf, ops->active ? "1\n" : "0\n");
438                 if (len > *lenp)
439                         len = *lenp;
440                 if (copy_to_user(buffer, buf, len)) {
441                         module_put(ops->owner);
442                         return -EFAULT;
443                 }
444                 goto out;
445         }
446         len = *lenp;
447         if (copy_from_user(buf, buffer,
448                            len > sizeof(buf) ? sizeof(buf) : len)) {
449                 module_put(ops->owner);
450                 return -EFAULT;
451         }
452
453         spin_lock_bh(&appldata_ops_lock);
454         if ((buf[0] == '1') && (ops->active == 0)) {
455                 if (!try_module_get(ops->owner)) {      // protect tasklet
456                         spin_unlock_bh(&appldata_ops_lock);
457                         module_put(ops->owner);
458                         return -ENODEV;
459                 }
460                 ops->active = 1;
461                 ops->callback(ops->data);       // init record
462                 rc = appldata_diag(ops->record_nr,
463                                         APPLDATA_START_INTERVAL_REC,
464                                         (unsigned long) ops->data, ops->size);
465                 if (rc != 0) {
466                         P_ERROR("START DIAG 0xDC for %s failed, "
467                                 "return code: %d\n", ops->name, rc);
468                         module_put(ops->owner);
469                         ops->active = 0;
470                 } else {
471                         P_INFO("Monitoring %s data enabled, "
472                                 "DIAG 0xDC started.\n", ops->name);
473                 }
474         } else if ((buf[0] == '0') && (ops->active == 1)) {
475                 ops->active = 0;
476                 rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
477                                 (unsigned long) ops->data, ops->size);
478                 if (rc != 0) {
479                         P_ERROR("STOP DIAG 0xDC for %s failed, "
480                                 "return code: %d\n", ops->name, rc);
481                 } else {
482                         P_INFO("Monitoring %s data disabled, "
483                                 "DIAG 0xDC stopped.\n", ops->name);
484                 }
485                 module_put(ops->owner);
486         }
487         spin_unlock_bh(&appldata_ops_lock);
488 out:
489         *lenp = len;
490         filp->f_pos += len;
491         module_put(ops->owner);
492         return 0;
493 }
494
495 /*************************** /proc stuff <END> *******************************/
496
497
498 /************************* module-ops management *****************************/
499 /*
500  * appldata_register_ops()
501  *
502  * update ops list, register /proc/sys entries
503  */
504 int appldata_register_ops(struct appldata_ops *ops)
505 {
506         struct list_head *lh;
507         struct appldata_ops *tmp_ops;
508         int i;
509
510         i = 0;
511
512         if ((ops->size > APPLDATA_MAX_REC_SIZE) ||
513                 (ops->size < 0)){
514                 P_ERROR("Invalid size of %s record = %i, maximum = %i!\n",
515                         ops->name, ops->size, APPLDATA_MAX_REC_SIZE);
516                 return -ENOMEM;
517         }
518         if ((ops->ctl_nr == CTL_APPLDATA) ||
519             (ops->ctl_nr == CTL_APPLDATA_TIMER) ||
520             (ops->ctl_nr == CTL_APPLDATA_INTERVAL)) {
521                 P_ERROR("ctl_nr %i already in use!\n", ops->ctl_nr);
522                 return -EBUSY;
523         }
524         ops->ctl_table = kmalloc(4*sizeof(struct ctl_table), GFP_KERNEL);
525         if (ops->ctl_table == NULL) {
526                 P_ERROR("Not enough memory for %s ctl_table!\n", ops->name);
527                 return -ENOMEM;
528         }
529         memset(ops->ctl_table, 0, 4*sizeof(struct ctl_table));
530
531         spin_lock_bh(&appldata_ops_lock);
532         list_for_each(lh, &appldata_ops_list) {
533                 tmp_ops = list_entry(lh, struct appldata_ops, list);
534                 P_DEBUG("register_ops loop: %i) name = %s, ctl = %i\n",
535                         ++i, tmp_ops->name, tmp_ops->ctl_nr);
536                 P_DEBUG("Comparing %s (ctl %i) with %s (ctl %i)\n",
537                         tmp_ops->name, tmp_ops->ctl_nr, ops->name,
538                         ops->ctl_nr);
539                 if (strncmp(tmp_ops->name, ops->name,
540                                 APPLDATA_PROC_NAME_LENGTH) == 0) {
541                         P_ERROR("Name \"%s\" already registered!\n", ops->name);
542                         kfree(ops->ctl_table);
543                         spin_unlock_bh(&appldata_ops_lock);
544                         return -EBUSY;
545                 }
546                 if (tmp_ops->ctl_nr == ops->ctl_nr) {
547                         P_ERROR("ctl_nr %i already registered!\n", ops->ctl_nr);
548                         kfree(ops->ctl_table);
549                         spin_unlock_bh(&appldata_ops_lock);
550                         return -EBUSY;
551                 }
552         }
553         list_add(&ops->list, &appldata_ops_list);
554         spin_unlock_bh(&appldata_ops_lock);
555
556         ops->ctl_table[0].ctl_name = CTL_APPLDATA;
557         ops->ctl_table[0].procname = appldata_proc_name;
558         ops->ctl_table[0].maxlen   = 0;
559         ops->ctl_table[0].mode     = S_IRUGO | S_IXUGO;
560         ops->ctl_table[0].child    = &ops->ctl_table[2];
561
562         ops->ctl_table[1].ctl_name = 0;
563
564         ops->ctl_table[2].ctl_name = ops->ctl_nr;
565         ops->ctl_table[2].procname = ops->name;
566         ops->ctl_table[2].mode     = S_IRUGO | S_IWUSR;
567         ops->ctl_table[2].proc_handler = appldata_generic_handler;
568         ops->ctl_table[2].data = ops;
569
570         ops->ctl_table[3].ctl_name = 0;
571
572         ops->sysctl_header = register_sysctl_table(ops->ctl_table,1);
573
574         P_INFO("%s-ops registered!\n", ops->name);
575         return 0;
576 }
577
578 /*
579  * appldata_unregister_ops()
580  *
581  * update ops list, unregister /proc entries, stop DIAG if necessary
582  */
583 void appldata_unregister_ops(struct appldata_ops *ops)
584 {
585         spin_lock_bh(&appldata_ops_lock);
586         unregister_sysctl_table(ops->sysctl_header);
587         list_del(&ops->list);
588         kfree(ops->ctl_table);
589         ops->ctl_table = NULL;
590         spin_unlock_bh(&appldata_ops_lock);
591         P_INFO("%s-ops unregistered!\n", ops->name);
592 }
593 /********************** module-ops management <END> **************************/
594
595
596 /******************************* init / exit *********************************/
597
598 static void
599 appldata_online_cpu(int cpu)
600 {
601         init_virt_timer(&per_cpu(appldata_timer, cpu));
602         per_cpu(appldata_timer, cpu).function = appldata_timer_function;
603         per_cpu(appldata_timer, cpu).data = (unsigned long)
604                 &appldata_tasklet_struct;
605         atomic_inc(&appldata_expire_count);
606         spin_lock(&appldata_timer_lock);
607         __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
608         spin_unlock(&appldata_timer_lock);
609 }
610
611 static void
612 appldata_offline_cpu(int cpu)
613 {
614         del_virt_timer(&per_cpu(appldata_timer, cpu));
615         if (atomic_dec_and_test(&appldata_expire_count)) {
616                 atomic_set(&appldata_expire_count, num_online_cpus());
617                 tasklet_schedule(&appldata_tasklet_struct);
618         }
619         spin_lock(&appldata_timer_lock);
620         __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
621         spin_unlock(&appldata_timer_lock);
622 }
623
624 static int
625 appldata_cpu_notify(struct notifier_block *self,
626                     unsigned long action, void *hcpu)
627 {
628         switch (action) {
629         case CPU_ONLINE:
630                 appldata_online_cpu((long) hcpu);
631                 break;
632 #ifdef CONFIG_HOTPLUG_CPU
633         case CPU_DEAD:
634                 appldata_offline_cpu((long) hcpu);
635                 break;
636 #endif
637         default:
638                 break;
639         }
640         return NOTIFY_OK;
641 }
642
643 static struct notifier_block __devinitdata appldata_nb = {
644         .notifier_call = appldata_cpu_notify,
645 };
646
647 /*
648  * appldata_init()
649  *
650  * init timer and tasklet, register /proc entries
651  */
652 static int __init appldata_init(void)
653 {
654         int i;
655
656         P_DEBUG("sizeof(parameter_list) = %lu\n",
657                 sizeof(struct appldata_parameter_list));
658
659         for_each_online_cpu(i)
660                 appldata_online_cpu(i);
661
662         /* Register cpu hotplug notifier */
663         register_cpu_notifier(&appldata_nb);
664
665         appldata_sysctl_header = register_sysctl_table(appldata_dir_table, 1);
666 #ifdef MODULE
667         appldata_dir_table[0].de->owner = THIS_MODULE;
668         appldata_table[0].de->owner = THIS_MODULE;
669         appldata_table[1].de->owner = THIS_MODULE;
670 #endif
671
672         tasklet_init(&appldata_tasklet_struct, appldata_tasklet_function, 0);
673         P_DEBUG("Base interface initialized.\n");
674         return 0;
675 }
676
677 /*
678  * appldata_exit()
679  *
680  * stop timer and tasklet, unregister /proc entries
681  */
682 static void __exit appldata_exit(void)
683 {
684         struct list_head *lh;
685         struct appldata_ops *ops;
686         int rc, i;
687
688         P_DEBUG("Unloading module ...\n");
689         /*
690          * ops list should be empty, but just in case something went wrong...
691          */
692         spin_lock_bh(&appldata_ops_lock);
693         list_for_each(lh, &appldata_ops_list) {
694                 ops = list_entry(lh, struct appldata_ops, list);
695                 rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
696                                 (unsigned long) ops->data, ops->size);
697                 if (rc != 0) {
698                         P_ERROR("STOP DIAG 0xDC for %s failed, "
699                                 "return code: %d\n", ops->name, rc);
700                 }
701         }
702         spin_unlock_bh(&appldata_ops_lock);
703
704         for_each_online_cpu(i)
705                 appldata_offline_cpu(i);
706
707         appldata_timer_active = 0;
708
709         unregister_sysctl_table(appldata_sysctl_header);
710
711         tasklet_kill(&appldata_tasklet_struct);
712         P_DEBUG("... module unloaded!\n");
713 }
714 /**************************** init / exit <END> ******************************/
715
716
717 module_init(appldata_init);
718 module_exit(appldata_exit);
719 MODULE_LICENSE("GPL");
720 MODULE_AUTHOR("Gerald Schaefer");
721 MODULE_DESCRIPTION("Linux-VM Monitor Stream, base infrastructure");
722
723 EXPORT_SYMBOL_GPL(appldata_register_ops);
724 EXPORT_SYMBOL_GPL(appldata_unregister_ops);
725
726 #ifdef MODULE
727 /*
728  * Kernel symbols needed by appldata_mem and appldata_os modules.
729  * However, if this file is compiled as a module (for testing only), these
730  * symbols are not exported. In this case, we define them locally and export
731  * those.
732  */
733 void si_swapinfo(struct sysinfo *val)
734 {
735         val->freeswap = -1ul;
736         val->totalswap = -1ul;
737 }
738
739 unsigned long avenrun[3] = {-1 - FIXED_1/200, -1 - FIXED_1/200,
740                                 -1 - FIXED_1/200};
741 int nr_threads = -1;
742
743 void get_full_page_state(struct page_state *ps)
744 {
745         memset(ps, -1, sizeof(struct page_state));
746 }
747
748 unsigned long nr_running(void)
749 {
750         return -1;
751 }
752
753 unsigned long nr_iowait(void)
754 {
755         return -1;
756 }
757
758 /*unsigned long nr_context_switches(void)
759 {
760         return -1;
761 }*/
762 #endif /* MODULE */
763 EXPORT_SYMBOL_GPL(si_swapinfo);
764 EXPORT_SYMBOL_GPL(nr_threads);
765 EXPORT_SYMBOL_GPL(avenrun);
766 EXPORT_SYMBOL_GPL(get_full_page_state);
767 EXPORT_SYMBOL_GPL(nr_running);
768 EXPORT_SYMBOL_GPL(nr_iowait);
769 //EXPORT_SYMBOL_GPL(nr_context_switches);