appldata_base.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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_64BIT
  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_64BIT */
  49. /*
  50. * Parameter list for DIAGNOSE X'DC'
  51. */
  52. #ifndef CONFIG_64BIT
  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_64BIT */
  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)
  211. : "d" (&appldata_parameter_list),
  212. "m" (appldata_parameter_list),
  213. "m" (appldata_product_id)
  214. : "cc");
  215. return (int) ry;
  216. }
  217. /************************ timer, work, DIAG <END> ****************************/
  218. /****************************** /proc stuff **********************************/
  219. /*
  220. * appldata_mod_vtimer_wrap()
  221. *
  222. * wrapper function for mod_virt_timer(), because smp_call_function_on()
  223. * accepts only one parameter.
  224. */
  225. static void __appldata_mod_vtimer_wrap(void *p) {
  226. struct {
  227. struct vtimer_list *timer;
  228. u64 expires;
  229. } *args = p;
  230. mod_virt_timer(args->timer, args->expires);
  231. }
  232. #define APPLDATA_ADD_TIMER 0
  233. #define APPLDATA_DEL_TIMER 1
  234. #define APPLDATA_MOD_TIMER 2
  235. /*
  236. * __appldata_vtimer_setup()
  237. *
  238. * Add, delete or modify virtual timers on all online cpus.
  239. * The caller needs to get the appldata_timer_lock spinlock.
  240. */
  241. static void
  242. __appldata_vtimer_setup(int cmd)
  243. {
  244. u64 per_cpu_interval;
  245. int i;
  246. switch (cmd) {
  247. case APPLDATA_ADD_TIMER:
  248. if (appldata_timer_active)
  249. break;
  250. per_cpu_interval = (u64) (appldata_interval*1000 /
  251. num_online_cpus()) * TOD_MICRO;
  252. for_each_online_cpu(i) {
  253. per_cpu(appldata_timer, i).expires = per_cpu_interval;
  254. smp_call_function_on(add_virt_timer_periodic,
  255. &per_cpu(appldata_timer, i),
  256. 0, 1, i);
  257. }
  258. appldata_timer_active = 1;
  259. P_INFO("Monitoring timer started.\n");
  260. break;
  261. case APPLDATA_DEL_TIMER:
  262. for_each_online_cpu(i)
  263. del_virt_timer(&per_cpu(appldata_timer, i));
  264. if (!appldata_timer_active)
  265. break;
  266. appldata_timer_active = 0;
  267. atomic_set(&appldata_expire_count, num_online_cpus());
  268. P_INFO("Monitoring timer stopped.\n");
  269. break;
  270. case APPLDATA_MOD_TIMER:
  271. per_cpu_interval = (u64) (appldata_interval*1000 /
  272. num_online_cpus()) * TOD_MICRO;
  273. if (!appldata_timer_active)
  274. break;
  275. for_each_online_cpu(i) {
  276. struct {
  277. struct vtimer_list *timer;
  278. u64 expires;
  279. } args;
  280. args.timer = &per_cpu(appldata_timer, i);
  281. args.expires = per_cpu_interval;
  282. smp_call_function_on(__appldata_mod_vtimer_wrap,
  283. &args, 0, 1, i);
  284. }
  285. }
  286. }
  287. /*
  288. * appldata_timer_handler()
  289. *
  290. * Start/Stop timer, show status of timer (0 = not active, 1 = active)
  291. */
  292. static int
  293. appldata_timer_handler(ctl_table *ctl, int write, struct file *filp,
  294. void __user *buffer, size_t *lenp, loff_t *ppos)
  295. {
  296. int len;
  297. char buf[2];
  298. if (!*lenp || *ppos) {
  299. *lenp = 0;
  300. return 0;
  301. }
  302. if (!write) {
  303. len = sprintf(buf, appldata_timer_active ? "1\n" : "0\n");
  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. spin_lock(&appldata_timer_lock);
  314. if (buf[0] == '1')
  315. __appldata_vtimer_setup(APPLDATA_ADD_TIMER);
  316. else if (buf[0] == '0')
  317. __appldata_vtimer_setup(APPLDATA_DEL_TIMER);
  318. spin_unlock(&appldata_timer_lock);
  319. out:
  320. *lenp = len;
  321. *ppos += len;
  322. return 0;
  323. }
  324. /*
  325. * appldata_interval_handler()
  326. *
  327. * Set (CPU) timer interval for collection of data (in milliseconds), show
  328. * current timer interval.
  329. */
  330. static int
  331. appldata_interval_handler(ctl_table *ctl, int write, struct file *filp,
  332. void __user *buffer, size_t *lenp, loff_t *ppos)
  333. {
  334. int len, interval;
  335. char buf[16];
  336. if (!*lenp || *ppos) {
  337. *lenp = 0;
  338. return 0;
  339. }
  340. if (!write) {
  341. len = sprintf(buf, "%i\n", appldata_interval);
  342. if (len > *lenp)
  343. len = *lenp;
  344. if (copy_to_user(buffer, buf, len))
  345. return -EFAULT;
  346. goto out;
  347. }
  348. len = *lenp;
  349. if (copy_from_user(buf, buffer, len > sizeof(buf) ? sizeof(buf) : len)) {
  350. return -EFAULT;
  351. }
  352. sscanf(buf, "%i", &interval);
  353. if (interval <= 0) {
  354. P_ERROR("Timer CPU interval has to be > 0!\n");
  355. return -EINVAL;
  356. }
  357. spin_lock(&appldata_timer_lock);
  358. appldata_interval = interval;
  359. __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
  360. spin_unlock(&appldata_timer_lock);
  361. P_INFO("Monitoring CPU interval set to %u milliseconds.\n",
  362. interval);
  363. out:
  364. *lenp = len;
  365. *ppos += len;
  366. return 0;
  367. }
  368. /*
  369. * appldata_generic_handler()
  370. *
  371. * Generic start/stop monitoring and DIAG, show status of
  372. * monitoring (0 = not in process, 1 = in process)
  373. */
  374. static int
  375. appldata_generic_handler(ctl_table *ctl, int write, struct file *filp,
  376. void __user *buffer, size_t *lenp, loff_t *ppos)
  377. {
  378. struct appldata_ops *ops = NULL, *tmp_ops;
  379. int rc, len, found;
  380. char buf[2];
  381. struct list_head *lh;
  382. found = 0;
  383. spin_lock(&appldata_ops_lock);
  384. list_for_each(lh, &appldata_ops_list) {
  385. tmp_ops = list_entry(lh, struct appldata_ops, list);
  386. if (&tmp_ops->ctl_table[2] == ctl) {
  387. found = 1;
  388. }
  389. }
  390. if (!found) {
  391. spin_unlock(&appldata_ops_lock);
  392. return -ENODEV;
  393. }
  394. ops = ctl->data;
  395. if (!try_module_get(ops->owner)) { // protect this function
  396. spin_unlock(&appldata_ops_lock);
  397. return -ENODEV;
  398. }
  399. spin_unlock(&appldata_ops_lock);
  400. if (!*lenp || *ppos) {
  401. *lenp = 0;
  402. module_put(ops->owner);
  403. return 0;
  404. }
  405. if (!write) {
  406. len = sprintf(buf, ops->active ? "1\n" : "0\n");
  407. if (len > *lenp)
  408. len = *lenp;
  409. if (copy_to_user(buffer, buf, len)) {
  410. module_put(ops->owner);
  411. return -EFAULT;
  412. }
  413. goto out;
  414. }
  415. len = *lenp;
  416. if (copy_from_user(buf, buffer,
  417. len > sizeof(buf) ? sizeof(buf) : len)) {
  418. module_put(ops->owner);
  419. return -EFAULT;
  420. }
  421. spin_lock(&appldata_ops_lock);
  422. if ((buf[0] == '1') && (ops->active == 0)) {
  423. // protect work queue callback
  424. if (!try_module_get(ops->owner)) {
  425. spin_unlock(&appldata_ops_lock);
  426. module_put(ops->owner);
  427. return -ENODEV;
  428. }
  429. ops->active = 1;
  430. ops->callback(ops->data); // init record
  431. rc = appldata_diag(ops->record_nr,
  432. APPLDATA_START_INTERVAL_REC,
  433. (unsigned long) ops->data, ops->size);
  434. if (rc != 0) {
  435. P_ERROR("START DIAG 0xDC for %s failed, "
  436. "return code: %d\n", ops->name, rc);
  437. module_put(ops->owner);
  438. ops->active = 0;
  439. } else {
  440. P_INFO("Monitoring %s data enabled, "
  441. "DIAG 0xDC started.\n", ops->name);
  442. }
  443. } else if ((buf[0] == '0') && (ops->active == 1)) {
  444. ops->active = 0;
  445. rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
  446. (unsigned long) ops->data, ops->size);
  447. if (rc != 0) {
  448. P_ERROR("STOP DIAG 0xDC for %s failed, "
  449. "return code: %d\n", ops->name, rc);
  450. } else {
  451. P_INFO("Monitoring %s data disabled, "
  452. "DIAG 0xDC stopped.\n", ops->name);
  453. }
  454. module_put(ops->owner);
  455. }
  456. spin_unlock(&appldata_ops_lock);
  457. out:
  458. *lenp = len;
  459. *ppos += len;
  460. module_put(ops->owner);
  461. return 0;
  462. }
  463. /*************************** /proc stuff <END> *******************************/
  464. /************************* module-ops management *****************************/
  465. /*
  466. * appldata_register_ops()
  467. *
  468. * update ops list, register /proc/sys entries
  469. */
  470. int appldata_register_ops(struct appldata_ops *ops)
  471. {
  472. struct list_head *lh;
  473. struct appldata_ops *tmp_ops;
  474. int i;
  475. i = 0;
  476. if ((ops->size > APPLDATA_MAX_REC_SIZE) ||
  477. (ops->size < 0)){
  478. P_ERROR("Invalid size of %s record = %i, maximum = %i!\n",
  479. ops->name, ops->size, APPLDATA_MAX_REC_SIZE);
  480. return -ENOMEM;
  481. }
  482. if ((ops->ctl_nr == CTL_APPLDATA) ||
  483. (ops->ctl_nr == CTL_APPLDATA_TIMER) ||
  484. (ops->ctl_nr == CTL_APPLDATA_INTERVAL)) {
  485. P_ERROR("ctl_nr %i already in use!\n", ops->ctl_nr);
  486. return -EBUSY;
  487. }
  488. ops->ctl_table = kmalloc(4*sizeof(struct ctl_table), GFP_KERNEL);
  489. if (ops->ctl_table == NULL) {
  490. P_ERROR("Not enough memory for %s ctl_table!\n", ops->name);
  491. return -ENOMEM;
  492. }
  493. memset(ops->ctl_table, 0, 4*sizeof(struct ctl_table));
  494. spin_lock(&appldata_ops_lock);
  495. list_for_each(lh, &appldata_ops_list) {
  496. tmp_ops = list_entry(lh, struct appldata_ops, list);
  497. P_DEBUG("register_ops loop: %i) name = %s, ctl = %i\n",
  498. ++i, tmp_ops->name, tmp_ops->ctl_nr);
  499. P_DEBUG("Comparing %s (ctl %i) with %s (ctl %i)\n",
  500. tmp_ops->name, tmp_ops->ctl_nr, ops->name,
  501. ops->ctl_nr);
  502. if (strncmp(tmp_ops->name, ops->name,
  503. APPLDATA_PROC_NAME_LENGTH) == 0) {
  504. P_ERROR("Name \"%s\" already registered!\n", ops->name);
  505. kfree(ops->ctl_table);
  506. spin_unlock(&appldata_ops_lock);
  507. return -EBUSY;
  508. }
  509. if (tmp_ops->ctl_nr == ops->ctl_nr) {
  510. P_ERROR("ctl_nr %i already registered!\n", ops->ctl_nr);
  511. kfree(ops->ctl_table);
  512. spin_unlock(&appldata_ops_lock);
  513. return -EBUSY;
  514. }
  515. }
  516. list_add(&ops->list, &appldata_ops_list);
  517. spin_unlock(&appldata_ops_lock);
  518. ops->ctl_table[0].ctl_name = CTL_APPLDATA;
  519. ops->ctl_table[0].procname = appldata_proc_name;
  520. ops->ctl_table[0].maxlen = 0;
  521. ops->ctl_table[0].mode = S_IRUGO | S_IXUGO;
  522. ops->ctl_table[0].child = &ops->ctl_table[2];
  523. ops->ctl_table[1].ctl_name = 0;
  524. ops->ctl_table[2].ctl_name = ops->ctl_nr;
  525. ops->ctl_table[2].procname = ops->name;
  526. ops->ctl_table[2].mode = S_IRUGO | S_IWUSR;
  527. ops->ctl_table[2].proc_handler = appldata_generic_handler;
  528. ops->ctl_table[2].data = ops;
  529. ops->ctl_table[3].ctl_name = 0;
  530. ops->sysctl_header = register_sysctl_table(ops->ctl_table,1);
  531. P_INFO("%s-ops registered!\n", ops->name);
  532. return 0;
  533. }
  534. /*
  535. * appldata_unregister_ops()
  536. *
  537. * update ops list, unregister /proc entries, stop DIAG if necessary
  538. */
  539. void appldata_unregister_ops(struct appldata_ops *ops)
  540. {
  541. void *table;
  542. spin_lock(&appldata_ops_lock);
  543. list_del(&ops->list);
  544. /* at that point any incoming access will fail */
  545. table = ops->ctl_table;
  546. ops->ctl_table = NULL;
  547. spin_unlock(&appldata_ops_lock);
  548. unregister_sysctl_table(ops->sysctl_header);
  549. kfree(table);
  550. P_INFO("%s-ops unregistered!\n", ops->name);
  551. }
  552. /********************** module-ops management <END> **************************/
  553. /******************************* init / exit *********************************/
  554. static void
  555. appldata_online_cpu(int cpu)
  556. {
  557. init_virt_timer(&per_cpu(appldata_timer, cpu));
  558. per_cpu(appldata_timer, cpu).function = appldata_timer_function;
  559. per_cpu(appldata_timer, cpu).data = (unsigned long)
  560. &appldata_work;
  561. atomic_inc(&appldata_expire_count);
  562. spin_lock(&appldata_timer_lock);
  563. __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
  564. spin_unlock(&appldata_timer_lock);
  565. }
  566. static void
  567. appldata_offline_cpu(int cpu)
  568. {
  569. del_virt_timer(&per_cpu(appldata_timer, cpu));
  570. if (atomic_dec_and_test(&appldata_expire_count)) {
  571. atomic_set(&appldata_expire_count, num_online_cpus());
  572. queue_work(appldata_wq, &appldata_work);
  573. }
  574. spin_lock(&appldata_timer_lock);
  575. __appldata_vtimer_setup(APPLDATA_MOD_TIMER);
  576. spin_unlock(&appldata_timer_lock);
  577. }
  578. static int
  579. appldata_cpu_notify(struct notifier_block *self,
  580. unsigned long action, void *hcpu)
  581. {
  582. switch (action) {
  583. case CPU_ONLINE:
  584. appldata_online_cpu((long) hcpu);
  585. break;
  586. #ifdef CONFIG_HOTPLUG_CPU
  587. case CPU_DEAD:
  588. appldata_offline_cpu((long) hcpu);
  589. break;
  590. #endif
  591. default:
  592. break;
  593. }
  594. return NOTIFY_OK;
  595. }
  596. static struct notifier_block __devinitdata appldata_nb = {
  597. .notifier_call = appldata_cpu_notify,
  598. };
  599. /*
  600. * appldata_init()
  601. *
  602. * init timer, register /proc entries
  603. */
  604. static int __init appldata_init(void)
  605. {
  606. int i;
  607. P_DEBUG("sizeof(parameter_list) = %lu\n",
  608. sizeof(struct appldata_parameter_list));
  609. appldata_wq = create_singlethread_workqueue("appldata");
  610. if (!appldata_wq) {
  611. P_ERROR("Could not create work queue\n");
  612. return -ENOMEM;
  613. }
  614. for_each_online_cpu(i)
  615. appldata_online_cpu(i);
  616. /* Register cpu hotplug notifier */
  617. register_cpu_notifier(&appldata_nb);
  618. appldata_sysctl_header = register_sysctl_table(appldata_dir_table, 1);
  619. #ifdef MODULE
  620. appldata_dir_table[0].de->owner = THIS_MODULE;
  621. appldata_table[0].de->owner = THIS_MODULE;
  622. appldata_table[1].de->owner = THIS_MODULE;
  623. #endif
  624. P_DEBUG("Base interface initialized.\n");
  625. return 0;
  626. }
  627. /*
  628. * appldata_exit()
  629. *
  630. * stop timer, unregister /proc entries
  631. */
  632. static void __exit appldata_exit(void)
  633. {
  634. struct list_head *lh;
  635. struct appldata_ops *ops;
  636. int rc, i;
  637. P_DEBUG("Unloading module ...\n");
  638. /*
  639. * ops list should be empty, but just in case something went wrong...
  640. */
  641. spin_lock(&appldata_ops_lock);
  642. list_for_each(lh, &appldata_ops_list) {
  643. ops = list_entry(lh, struct appldata_ops, list);
  644. rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
  645. (unsigned long) ops->data, ops->size);
  646. if (rc != 0) {
  647. P_ERROR("STOP DIAG 0xDC for %s failed, "
  648. "return code: %d\n", ops->name, rc);
  649. }
  650. }
  651. spin_unlock(&appldata_ops_lock);
  652. for_each_online_cpu(i)
  653. appldata_offline_cpu(i);
  654. appldata_timer_active = 0;
  655. unregister_sysctl_table(appldata_sysctl_header);
  656. destroy_workqueue(appldata_wq);
  657. P_DEBUG("... module unloaded!\n");
  658. }
  659. /**************************** init / exit <END> ******************************/
  660. module_init(appldata_init);
  661. module_exit(appldata_exit);
  662. MODULE_LICENSE("GPL");
  663. MODULE_AUTHOR("Gerald Schaefer");
  664. MODULE_DESCRIPTION("Linux-VM Monitor Stream, base infrastructure");
  665. EXPORT_SYMBOL_GPL(appldata_register_ops);
  666. EXPORT_SYMBOL_GPL(appldata_unregister_ops);
  667. #ifdef MODULE
  668. /*
  669. * Kernel symbols needed by appldata_mem and appldata_os modules.
  670. * However, if this file is compiled as a module (for testing only), these
  671. * symbols are not exported. In this case, we define them locally and export
  672. * those.
  673. */
  674. void si_swapinfo(struct sysinfo *val)
  675. {
  676. val->freeswap = -1ul;
  677. val->totalswap = -1ul;
  678. }
  679. unsigned long avenrun[3] = {-1 - FIXED_1/200, -1 - FIXED_1/200,
  680. -1 - FIXED_1/200};
  681. int nr_threads = -1;
  682. void get_full_page_state(struct page_state *ps)
  683. {
  684. memset(ps, -1, sizeof(struct page_state));
  685. }
  686. unsigned long nr_running(void)
  687. {
  688. return -1;
  689. }
  690. unsigned long nr_iowait(void)
  691. {
  692. return -1;
  693. }
  694. /*unsigned long nr_context_switches(void)
  695. {
  696. return -1;
  697. }*/
  698. #endif /* MODULE */
  699. EXPORT_SYMBOL_GPL(si_swapinfo);
  700. EXPORT_SYMBOL_GPL(nr_threads);
  701. EXPORT_SYMBOL_GPL(avenrun);
  702. EXPORT_SYMBOL_GPL(get_full_page_state);
  703. EXPORT_SYMBOL_GPL(nr_running);
  704. EXPORT_SYMBOL_GPL(nr_iowait);
  705. //EXPORT_SYMBOL_GPL(nr_context_switches);