appldata_base.c 19 KB

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