appldata_base.c 19 KB

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