appldata_base.c 19 KB

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