Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 8 | * Copyright (C) 2003,2006 IBM Corporation, IBM Deutschland Entwicklung GmbH. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 10 | * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/proc_fs.h> |
Heiko Carstens | 2dcea57 | 2006-09-29 01:58:41 -0700 | [diff] [blame] | 19 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/swap.h> |
| 21 | #include <linux/pagemap.h> |
| 22 | #include <linux/sysctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/notifier.h> |
| 24 | #include <linux/cpu.h> |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 25 | #include <linux/workqueue.h> |
Gerald Schaefer | 1f38d61 | 2006-09-20 15:59:26 +0200 | [diff] [blame] | 26 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | /* |
| 43 | * /proc entries (sysctl) |
| 44 | */ |
| 45 | static const char appldata_proc_name[APPLDATA_PROC_NAME_LENGTH] = "appldata"; |
| 46 | static int appldata_timer_handler(ctl_table *ctl, int write, struct file *filp, |
| 47 | void __user *buffer, size_t *lenp, loff_t *ppos); |
| 48 | static 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 | |
| 53 | static struct ctl_table_header *appldata_sysctl_header; |
| 54 | static struct ctl_table appldata_table[] = { |
| 55 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | .procname = "timer", |
| 57 | .mode = S_IRUGO | S_IWUSR, |
| 58 | .proc_handler = &appldata_timer_handler, |
| 59 | }, |
| 60 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | .procname = "interval", |
| 62 | .mode = S_IRUGO | S_IWUSR, |
| 63 | .proc_handler = &appldata_interval_handler, |
| 64 | }, |
Heiko Carstens | 37e3a6a | 2007-11-20 11:13:34 +0100 | [diff] [blame] | 65 | { }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | static struct ctl_table appldata_dir_table[] = { |
| 69 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | .procname = appldata_proc_name, |
| 71 | .maxlen = 0, |
| 72 | .mode = S_IRUGO | S_IXUGO, |
| 73 | .child = appldata_table, |
| 74 | }, |
Heiko Carstens | 37e3a6a | 2007-11-20 11:13:34 +0100 | [diff] [blame] | 75 | { }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | /* |
| 79 | * Timer |
| 80 | */ |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 81 | static DEFINE_PER_CPU(struct vtimer_list, appldata_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | static atomic_t appldata_expire_count = ATOMIC_INIT(0); |
| 83 | |
| 84 | static DEFINE_SPINLOCK(appldata_timer_lock); |
| 85 | static int appldata_interval = APPLDATA_CPU_INTERVAL; |
| 86 | static int appldata_timer_active; |
| 87 | |
| 88 | /* |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 89 | * Work queue |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | */ |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 91 | static struct workqueue_struct *appldata_wq; |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 92 | static void appldata_work_fn(struct work_struct *work); |
| 93 | static DECLARE_WORK(appldata_work, appldata_work_fn); |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * Ops list |
| 98 | */ |
| 99 | static DEFINE_SPINLOCK(appldata_ops_lock); |
| 100 | static LIST_HEAD(appldata_ops_list); |
| 101 | |
| 102 | |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 103 | /*************************** timer, work, DIAG *******************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /* |
| 105 | * appldata_timer_function() |
| 106 | * |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 107 | * schedule work and reschedule timer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | */ |
Heiko Carstens | 9d0a57c | 2006-10-11 15:31:26 +0200 | [diff] [blame] | 109 | static void appldata_timer_function(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
| 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 Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 116 | queue_work(appldata_wq, (struct work_struct *) data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | /* |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 121 | * appldata_work_fn() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | * |
| 123 | * call data gathering function for each (active) module |
| 124 | */ |
David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 125 | static void appldata_work_fn(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
| 127 | struct list_head *lh; |
| 128 | struct appldata_ops *ops; |
| 129 | int i; |
| 130 | |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 131 | P_DEBUG(" -= Work Queue =-\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | i = 0; |
Gerald Schaefer | 1760537 | 2008-05-30 10:03:28 +0200 | [diff] [blame] | 133 | get_online_cpus(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | 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 Schaefer | 1760537 | 2008-05-30 10:03:28 +0200 | [diff] [blame] | 144 | put_online_cpus(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* |
| 148 | * appldata_diag() |
| 149 | * |
| 150 | * prepare parameter list, issue DIAG 0xDC |
| 151 | */ |
Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 152 | int appldata_diag(char record_nr, u16 function, unsigned long buffer, |
| 153 | u16 length, char *mod_lvl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Gerald Schaefer | 1f38d61 | 2006-09-20 15:59:26 +0200 | [diff] [blame] | 155 | struct appldata_product_id id = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | .prod_nr = {0xD3, 0xC9, 0xD5, 0xE4, |
Gerald Schaefer | 1f38d61 | 2006-09-20 15:59:26 +0200 | [diff] [blame] | 157 | 0xE7, 0xD2, 0xD9}, /* "LINUXKR" */ |
| 158 | .prod_fn = 0xD5D3, /* "NL" */ |
Gerald Schaefer | 1f38d61 | 2006-09-20 15:59:26 +0200 | [diff] [blame] | 159 | .version_nr = 0xF2F6, /* "26" */ |
| 160 | .release_nr = 0xF0F1, /* "01" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
Gerald Schaefer | 925afbd | 2006-09-28 16:55:23 +0200 | [diff] [blame] | 163 | id.record_nr = record_nr; |
| 164 | id.mod_lvl = (mod_lvl[0]) << 8 | mod_lvl[1]; |
Gerald Schaefer | 1f38d61 | 2006-09-20 15:59:26 +0200 | [diff] [blame] | 165 | return appldata_asm(&id, function, (void *) buffer, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 167 | /************************ timer, work, DIAG <END> ****************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | |
| 170 | /****************************** /proc stuff **********************************/ |
| 171 | |
| 172 | /* |
| 173 | * appldata_mod_vtimer_wrap() |
| 174 | * |
Heiko Carstens | 3bb447f | 2007-07-27 12:29:08 +0200 | [diff] [blame] | 175 | * wrapper function for mod_virt_timer(), because smp_call_function_single() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | * accepts only one parameter. |
| 177 | */ |
| 178 | static 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 | */ |
| 196 | static 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 Carstens | 3bb447f | 2007-07-27 12:29:08 +0200 | [diff] [blame] | 210 | smp_call_function_single(i, add_virt_timer_periodic, |
| 211 | &per_cpu(appldata_timer, i), |
| 212 | 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 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 Carstens | 3bb447f | 2007-07-27 12:29:08 +0200 | [diff] [blame] | 238 | smp_call_function_single(i, __appldata_mod_vtimer_wrap, |
| 239 | &args, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | * appldata_timer_handler() |
| 246 | * |
| 247 | * Start/Stop timer, show status of timer (0 = not active, 1 = active) |
| 248 | */ |
| 249 | static int |
| 250 | appldata_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 Schaefer | 1760537 | 2008-05-30 10:03:28 +0200 | [diff] [blame] | 271 | get_online_cpus(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | 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 Schaefer | 1760537 | 2008-05-30 10:03:28 +0200 | [diff] [blame] | 278 | put_online_cpus(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | out: |
| 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 | */ |
| 291 | static int |
| 292 | appldata_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 Schaefer | 95425f1 | 2006-10-27 12:39:13 +0200 | [diff] [blame] | 314 | interval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | 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 Schaefer | 1760537 | 2008-05-30 10:03:28 +0200 | [diff] [blame] | 321 | get_online_cpus(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | spin_lock(&appldata_timer_lock); |
| 323 | appldata_interval = interval; |
| 324 | __appldata_vtimer_setup(APPLDATA_MOD_TIMER); |
| 325 | spin_unlock(&appldata_timer_lock); |
Gerald Schaefer | 1760537 | 2008-05-30 10:03:28 +0200 | [diff] [blame] | 326 | put_online_cpus(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
| 328 | P_INFO("Monitoring CPU interval set to %u milliseconds.\n", |
| 329 | interval); |
| 330 | out: |
| 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 | */ |
| 342 | static int |
| 343 | appldata_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 Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 352 | spin_lock(&appldata_ops_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | 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 Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 360 | spin_unlock(&appldata_ops_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | return -ENODEV; |
| 362 | } |
| 363 | ops = ctl->data; |
| 364 | if (!try_module_get(ops->owner)) { // protect this function |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 365 | spin_unlock(&appldata_ops_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | return -ENODEV; |
| 367 | } |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 368 | spin_unlock(&appldata_ops_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 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 Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 392 | spin_lock(&appldata_ops_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | if ((buf[0] == '1') && (ops->active == 0)) { |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 394 | // protect work queue callback |
| 395 | if (!try_module_get(ops->owner)) { |
| 396 | spin_unlock(&appldata_ops_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | module_put(ops->owner); |
| 398 | return -ENODEV; |
| 399 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | ops->callback(ops->data); // init record |
| 401 | rc = appldata_diag(ops->record_nr, |
| 402 | APPLDATA_START_INTERVAL_REC, |
Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 403 | (unsigned long) ops->data, ops->size, |
| 404 | ops->mod_lvl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } else { |
| 410 | P_INFO("Monitoring %s data enabled, " |
| 411 | "DIAG 0xDC started.\n", ops->name); |
Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 412 | ops->active = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
| 414 | } else if ((buf[0] == '0') && (ops->active == 1)) { |
| 415 | ops->active = 0; |
| 416 | rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC, |
Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 417 | (unsigned long) ops->data, ops->size, |
| 418 | ops->mod_lvl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | 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 Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 428 | spin_unlock(&appldata_ops_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | out: |
| 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 | */ |
| 445 | int appldata_register_ops(struct appldata_ops *ops) |
| 446 | { |
Heiko Carstens | 37e3a6a | 2007-11-20 11:13:34 +0100 | [diff] [blame] | 447 | if ((ops->size > APPLDATA_MAX_REC_SIZE) || (ops->size < 0)) |
| 448 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Heiko Carstens | 37e3a6a | 2007-11-20 11:13:34 +0100 | [diff] [blame] | 450 | ops->ctl_table = kzalloc(4 * sizeof(struct ctl_table), GFP_KERNEL); |
| 451 | if (!ops->ctl_table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 454 | spin_lock(&appldata_ops_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | list_add(&ops->list, &appldata_ops_list); |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 456 | spin_unlock(&appldata_ops_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | 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. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 468 | ops->sysctl_header = register_sysctl_table(ops->ctl_table); |
Heiko Carstens | 37e3a6a | 2007-11-20 11:13:34 +0100 | [diff] [blame] | 469 | if (!ops->sysctl_header) |
| 470 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | P_INFO("%s-ops registered!\n", ops->name); |
| 472 | return 0; |
Heiko Carstens | 37e3a6a | 2007-11-20 11:13:34 +0100 | [diff] [blame] | 473 | out: |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | /* |
| 482 | * appldata_unregister_ops() |
| 483 | * |
| 484 | * update ops list, unregister /proc entries, stop DIAG if necessary |
| 485 | */ |
| 486 | void appldata_unregister_ops(struct appldata_ops *ops) |
| 487 | { |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 488 | spin_lock(&appldata_ops_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | list_del(&ops->list); |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 490 | spin_unlock(&appldata_ops_lock); |
Al Viro | 330d57f | 2005-11-04 10:18:40 +0000 | [diff] [blame] | 491 | unregister_sysctl_table(ops->sysctl_header); |
Heiko Carstens | 37e3a6a | 2007-11-20 11:13:34 +0100 | [diff] [blame] | 492 | kfree(ops->ctl_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | P_INFO("%s-ops unregistered!\n", ops->name); |
| 494 | } |
| 495 | /********************** module-ops management <END> **************************/ |
| 496 | |
| 497 | |
| 498 | /******************************* init / exit *********************************/ |
| 499 | |
Heiko Carstens | 84b36a8 | 2007-06-19 13:10:03 +0200 | [diff] [blame] | 500 | static void __cpuinit appldata_online_cpu(int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | { |
| 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 Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 505 | &appldata_work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | 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 Sharma | 076fc80 | 2007-10-12 16:11:32 +0200 | [diff] [blame] | 512 | static void __cpuinit appldata_offline_cpu(int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
| 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 Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 517 | queue_work(appldata_wq, &appldata_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | spin_lock(&appldata_timer_lock); |
| 520 | __appldata_vtimer_setup(APPLDATA_MOD_TIMER); |
| 521 | spin_unlock(&appldata_timer_lock); |
| 522 | } |
| 523 | |
Satyam Sharma | 11b8bf0 | 2007-10-12 16:11:31 +0200 | [diff] [blame] | 524 | static int __cpuinit appldata_cpu_notify(struct notifier_block *self, |
| 525 | unsigned long action, |
| 526 | void *hcpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | { |
| 528 | switch (action) { |
| 529 | case CPU_ONLINE: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 530 | case CPU_ONLINE_FROZEN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | appldata_online_cpu((long) hcpu); |
| 532 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | case CPU_DEAD: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 534 | case CPU_DEAD_FROZEN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | appldata_offline_cpu((long) hcpu); |
| 536 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | default: |
| 538 | break; |
| 539 | } |
| 540 | return NOTIFY_OK; |
| 541 | } |
| 542 | |
Heiko Carstens | 84b36a8 | 2007-06-19 13:10:03 +0200 | [diff] [blame] | 543 | static struct notifier_block __cpuinitdata appldata_nb = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | .notifier_call = appldata_cpu_notify, |
| 545 | }; |
| 546 | |
| 547 | /* |
| 548 | * appldata_init() |
| 549 | * |
Gerald Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 550 | * init timer, register /proc entries |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | */ |
| 552 | static 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 Schaefer | f26d583 | 2005-06-04 15:43:33 -0700 | [diff] [blame] | 559 | 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 Schaefer | 1760537 | 2008-05-30 10:03:28 +0200 | [diff] [blame] | 565 | get_online_cpus(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | for_each_online_cpu(i) |
| 567 | appldata_online_cpu(i); |
Gerald Schaefer | 1760537 | 2008-05-30 10:03:28 +0200 | [diff] [blame] | 568 | put_online_cpus(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
| 570 | /* Register cpu hotplug notifier */ |
Chandra Seetharaman | be6b5a3 | 2006-07-30 03:03:37 -0700 | [diff] [blame] | 571 | register_hotcpu_notifier(&appldata_nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 573 | appldata_sysctl_header = register_sysctl_table(appldata_dir_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | P_DEBUG("Base interface initialized.\n"); |
| 576 | return 0; |
| 577 | } |
| 578 | |
Satyam Sharma | 076fc80 | 2007-10-12 16:11:32 +0200 | [diff] [blame] | 579 | __initcall(appldata_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | /**************************** init / exit <END> ******************************/ |
| 582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | EXPORT_SYMBOL_GPL(appldata_register_ops); |
| 584 | EXPORT_SYMBOL_GPL(appldata_unregister_ops); |
Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 585 | EXPORT_SYMBOL_GPL(appldata_diag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
Gerald Schaefer | 0c3252d | 2008-07-14 09:57:27 +0200 | [diff] [blame] | 587 | #ifdef CONFIG_SWAP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | EXPORT_SYMBOL_GPL(si_swapinfo); |
Gerald Schaefer | 0c3252d | 2008-07-14 09:57:27 +0200 | [diff] [blame] | 589 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | EXPORT_SYMBOL_GPL(nr_threads); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | EXPORT_SYMBOL_GPL(nr_running); |
| 592 | EXPORT_SYMBOL_GPL(nr_iowait); |