profile.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /*
  2. * linux/kernel/profile.c
  3. * Simple profiling. Manages a direct-mapped profile hit count buffer,
  4. * with configurable resolution, support for restricting the cpus on
  5. * which profiling is done, and switching between cpu time and
  6. * schedule() calls via kernel command line parameters passed at boot.
  7. *
  8. * Scheduler profiling support, Arjan van de Ven and Ingo Molnar,
  9. * Red Hat, July 2004
  10. * Consolidation of architecture support code for profiling,
  11. * William Irwin, Oracle, July 2004
  12. * Amortized hit count accounting via per-cpu open-addressed hashtables
  13. * to resolve timer interrupt livelocks, William Irwin, Oracle, 2004
  14. */
  15. #include <linux/module.h>
  16. #include <linux/profile.h>
  17. #include <linux/bootmem.h>
  18. #include <linux/notifier.h>
  19. #include <linux/mm.h>
  20. #include <linux/cpumask.h>
  21. #include <linux/cpu.h>
  22. #include <linux/highmem.h>
  23. #include <linux/mutex.h>
  24. #include <linux/slab.h>
  25. #include <linux/vmalloc.h>
  26. #include <asm/sections.h>
  27. #include <asm/irq_regs.h>
  28. #include <asm/ptrace.h>
  29. struct profile_hit {
  30. u32 pc, hits;
  31. };
  32. #define PROFILE_GRPSHIFT 3
  33. #define PROFILE_GRPSZ (1 << PROFILE_GRPSHIFT)
  34. #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
  35. #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
  36. /* Oprofile timer tick hook */
  37. static int (*timer_hook)(struct pt_regs *) __read_mostly;
  38. static atomic_t *prof_buffer;
  39. static unsigned long prof_len, prof_shift;
  40. int prof_on __read_mostly;
  41. EXPORT_SYMBOL_GPL(prof_on);
  42. static cpumask_var_t prof_cpu_mask;
  43. #ifdef CONFIG_SMP
  44. static DEFINE_PER_CPU(struct profile_hit *[2], cpu_profile_hits);
  45. static DEFINE_PER_CPU(int, cpu_profile_flip);
  46. static DEFINE_MUTEX(profile_flip_mutex);
  47. #endif /* CONFIG_SMP */
  48. int profile_setup(char *str)
  49. {
  50. static char schedstr[] = "schedule";
  51. static char sleepstr[] = "sleep";
  52. static char kvmstr[] = "kvm";
  53. int par;
  54. if (!strncmp(str, sleepstr, strlen(sleepstr))) {
  55. #ifdef CONFIG_SCHEDSTATS
  56. prof_on = SLEEP_PROFILING;
  57. if (str[strlen(sleepstr)] == ',')
  58. str += strlen(sleepstr) + 1;
  59. if (get_option(&str, &par))
  60. prof_shift = par;
  61. printk(KERN_INFO
  62. "kernel sleep profiling enabled (shift: %ld)\n",
  63. prof_shift);
  64. #else
  65. printk(KERN_WARNING
  66. "kernel sleep profiling requires CONFIG_SCHEDSTATS\n");
  67. #endif /* CONFIG_SCHEDSTATS */
  68. } else if (!strncmp(str, schedstr, strlen(schedstr))) {
  69. prof_on = SCHED_PROFILING;
  70. if (str[strlen(schedstr)] == ',')
  71. str += strlen(schedstr) + 1;
  72. if (get_option(&str, &par))
  73. prof_shift = par;
  74. printk(KERN_INFO
  75. "kernel schedule profiling enabled (shift: %ld)\n",
  76. prof_shift);
  77. } else if (!strncmp(str, kvmstr, strlen(kvmstr))) {
  78. prof_on = KVM_PROFILING;
  79. if (str[strlen(kvmstr)] == ',')
  80. str += strlen(kvmstr) + 1;
  81. if (get_option(&str, &par))
  82. prof_shift = par;
  83. printk(KERN_INFO
  84. "kernel KVM profiling enabled (shift: %ld)\n",
  85. prof_shift);
  86. } else if (get_option(&str, &par)) {
  87. prof_shift = par;
  88. prof_on = CPU_PROFILING;
  89. printk(KERN_INFO "kernel profiling enabled (shift: %ld)\n",
  90. prof_shift);
  91. }
  92. return 1;
  93. }
  94. __setup("profile=", profile_setup);
  95. int __ref profile_init(void)
  96. {
  97. int buffer_bytes;
  98. if (!prof_on)
  99. return 0;
  100. /* only text is profiled */
  101. prof_len = (_etext - _stext) >> prof_shift;
  102. buffer_bytes = prof_len*sizeof(atomic_t);
  103. if (!slab_is_available()) {
  104. prof_buffer = alloc_bootmem(buffer_bytes);
  105. alloc_bootmem_cpumask_var(&prof_cpu_mask);
  106. cpumask_copy(prof_cpu_mask, cpu_possible_mask);
  107. return 0;
  108. }
  109. if (!alloc_cpumask_var(&prof_cpu_mask, GFP_KERNEL))
  110. return -ENOMEM;
  111. cpumask_copy(prof_cpu_mask, cpu_possible_mask);
  112. prof_buffer = kzalloc(buffer_bytes, GFP_KERNEL);
  113. if (prof_buffer)
  114. return 0;
  115. prof_buffer = alloc_pages_exact(buffer_bytes, GFP_KERNEL|__GFP_ZERO);
  116. if (prof_buffer)
  117. return 0;
  118. prof_buffer = vmalloc(buffer_bytes);
  119. if (prof_buffer)
  120. return 0;
  121. free_cpumask_var(prof_cpu_mask);
  122. return -ENOMEM;
  123. }
  124. /* Profile event notifications */
  125. static BLOCKING_NOTIFIER_HEAD(task_exit_notifier);
  126. static ATOMIC_NOTIFIER_HEAD(task_free_notifier);
  127. static BLOCKING_NOTIFIER_HEAD(munmap_notifier);
  128. void profile_task_exit(struct task_struct *task)
  129. {
  130. blocking_notifier_call_chain(&task_exit_notifier, 0, task);
  131. }
  132. int profile_handoff_task(struct task_struct *task)
  133. {
  134. int ret;
  135. ret = atomic_notifier_call_chain(&task_free_notifier, 0, task);
  136. return (ret == NOTIFY_OK) ? 1 : 0;
  137. }
  138. void profile_munmap(unsigned long addr)
  139. {
  140. blocking_notifier_call_chain(&munmap_notifier, 0, (void *)addr);
  141. }
  142. int task_handoff_register(struct notifier_block *n)
  143. {
  144. return atomic_notifier_chain_register(&task_free_notifier, n);
  145. }
  146. EXPORT_SYMBOL_GPL(task_handoff_register);
  147. int task_handoff_unregister(struct notifier_block *n)
  148. {
  149. return atomic_notifier_chain_unregister(&task_free_notifier, n);
  150. }
  151. EXPORT_SYMBOL_GPL(task_handoff_unregister);
  152. int profile_event_register(enum profile_type type, struct notifier_block *n)
  153. {
  154. int err = -EINVAL;
  155. switch (type) {
  156. case PROFILE_TASK_EXIT:
  157. err = blocking_notifier_chain_register(
  158. &task_exit_notifier, n);
  159. break;
  160. case PROFILE_MUNMAP:
  161. err = blocking_notifier_chain_register(
  162. &munmap_notifier, n);
  163. break;
  164. }
  165. return err;
  166. }
  167. EXPORT_SYMBOL_GPL(profile_event_register);
  168. int profile_event_unregister(enum profile_type type, struct notifier_block *n)
  169. {
  170. int err = -EINVAL;
  171. switch (type) {
  172. case PROFILE_TASK_EXIT:
  173. err = blocking_notifier_chain_unregister(
  174. &task_exit_notifier, n);
  175. break;
  176. case PROFILE_MUNMAP:
  177. err = blocking_notifier_chain_unregister(
  178. &munmap_notifier, n);
  179. break;
  180. }
  181. return err;
  182. }
  183. EXPORT_SYMBOL_GPL(profile_event_unregister);
  184. int register_timer_hook(int (*hook)(struct pt_regs *))
  185. {
  186. if (timer_hook)
  187. return -EBUSY;
  188. timer_hook = hook;
  189. return 0;
  190. }
  191. EXPORT_SYMBOL_GPL(register_timer_hook);
  192. void unregister_timer_hook(int (*hook)(struct pt_regs *))
  193. {
  194. WARN_ON(hook != timer_hook);
  195. timer_hook = NULL;
  196. /* make sure all CPUs see the NULL hook */
  197. synchronize_sched(); /* Allow ongoing interrupts to complete. */
  198. }
  199. EXPORT_SYMBOL_GPL(unregister_timer_hook);
  200. #ifdef CONFIG_SMP
  201. /*
  202. * Each cpu has a pair of open-addressed hashtables for pending
  203. * profile hits. read_profile() IPI's all cpus to request them
  204. * to flip buffers and flushes their contents to prof_buffer itself.
  205. * Flip requests are serialized by the profile_flip_mutex. The sole
  206. * use of having a second hashtable is for avoiding cacheline
  207. * contention that would otherwise happen during flushes of pending
  208. * profile hits required for the accuracy of reported profile hits
  209. * and so resurrect the interrupt livelock issue.
  210. *
  211. * The open-addressed hashtables are indexed by profile buffer slot
  212. * and hold the number of pending hits to that profile buffer slot on
  213. * a cpu in an entry. When the hashtable overflows, all pending hits
  214. * are accounted to their corresponding profile buffer slots with
  215. * atomic_add() and the hashtable emptied. As numerous pending hits
  216. * may be accounted to a profile buffer slot in a hashtable entry,
  217. * this amortizes a number of atomic profile buffer increments likely
  218. * to be far larger than the number of entries in the hashtable,
  219. * particularly given that the number of distinct profile buffer
  220. * positions to which hits are accounted during short intervals (e.g.
  221. * several seconds) is usually very small. Exclusion from buffer
  222. * flipping is provided by interrupt disablement (note that for
  223. * SCHED_PROFILING or SLEEP_PROFILING profile_hit() may be called from
  224. * process context).
  225. * The hash function is meant to be lightweight as opposed to strong,
  226. * and was vaguely inspired by ppc64 firmware-supported inverted
  227. * pagetable hash functions, but uses a full hashtable full of finite
  228. * collision chains, not just pairs of them.
  229. *
  230. * -- wli
  231. */
  232. static void __profile_flip_buffers(void *unused)
  233. {
  234. int cpu = smp_processor_id();
  235. per_cpu(cpu_profile_flip, cpu) = !per_cpu(cpu_profile_flip, cpu);
  236. }
  237. static void profile_flip_buffers(void)
  238. {
  239. int i, j, cpu;
  240. mutex_lock(&profile_flip_mutex);
  241. j = per_cpu(cpu_profile_flip, get_cpu());
  242. put_cpu();
  243. on_each_cpu(__profile_flip_buffers, NULL, 1);
  244. for_each_online_cpu(cpu) {
  245. struct profile_hit *hits = per_cpu(cpu_profile_hits, cpu)[j];
  246. for (i = 0; i < NR_PROFILE_HIT; ++i) {
  247. if (!hits[i].hits) {
  248. if (hits[i].pc)
  249. hits[i].pc = 0;
  250. continue;
  251. }
  252. atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
  253. hits[i].hits = hits[i].pc = 0;
  254. }
  255. }
  256. mutex_unlock(&profile_flip_mutex);
  257. }
  258. static void profile_discard_flip_buffers(void)
  259. {
  260. int i, cpu;
  261. mutex_lock(&profile_flip_mutex);
  262. i = per_cpu(cpu_profile_flip, get_cpu());
  263. put_cpu();
  264. on_each_cpu(__profile_flip_buffers, NULL, 1);
  265. for_each_online_cpu(cpu) {
  266. struct profile_hit *hits = per_cpu(cpu_profile_hits, cpu)[i];
  267. memset(hits, 0, NR_PROFILE_HIT*sizeof(struct profile_hit));
  268. }
  269. mutex_unlock(&profile_flip_mutex);
  270. }
  271. void profile_hits(int type, void *__pc, unsigned int nr_hits)
  272. {
  273. unsigned long primary, secondary, flags, pc = (unsigned long)__pc;
  274. int i, j, cpu;
  275. struct profile_hit *hits;
  276. if (prof_on != type || !prof_buffer)
  277. return;
  278. pc = min((pc - (unsigned long)_stext) >> prof_shift, prof_len - 1);
  279. i = primary = (pc & (NR_PROFILE_GRP - 1)) << PROFILE_GRPSHIFT;
  280. secondary = (~(pc << 1) & (NR_PROFILE_GRP - 1)) << PROFILE_GRPSHIFT;
  281. cpu = get_cpu();
  282. hits = per_cpu(cpu_profile_hits, cpu)[per_cpu(cpu_profile_flip, cpu)];
  283. if (!hits) {
  284. put_cpu();
  285. return;
  286. }
  287. /*
  288. * We buffer the global profiler buffer into a per-CPU
  289. * queue and thus reduce the number of global (and possibly
  290. * NUMA-alien) accesses. The write-queue is self-coalescing:
  291. */
  292. local_irq_save(flags);
  293. do {
  294. for (j = 0; j < PROFILE_GRPSZ; ++j) {
  295. if (hits[i + j].pc == pc) {
  296. hits[i + j].hits += nr_hits;
  297. goto out;
  298. } else if (!hits[i + j].hits) {
  299. hits[i + j].pc = pc;
  300. hits[i + j].hits = nr_hits;
  301. goto out;
  302. }
  303. }
  304. i = (i + secondary) & (NR_PROFILE_HIT - 1);
  305. } while (i != primary);
  306. /*
  307. * Add the current hit(s) and flush the write-queue out
  308. * to the global buffer:
  309. */
  310. atomic_add(nr_hits, &prof_buffer[pc]);
  311. for (i = 0; i < NR_PROFILE_HIT; ++i) {
  312. atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
  313. hits[i].pc = hits[i].hits = 0;
  314. }
  315. out:
  316. local_irq_restore(flags);
  317. put_cpu();
  318. }
  319. static int __cpuinit profile_cpu_callback(struct notifier_block *info,
  320. unsigned long action, void *__cpu)
  321. {
  322. int node, cpu = (unsigned long)__cpu;
  323. struct page *page;
  324. switch (action) {
  325. case CPU_UP_PREPARE:
  326. case CPU_UP_PREPARE_FROZEN:
  327. node = cpu_to_node(cpu);
  328. per_cpu(cpu_profile_flip, cpu) = 0;
  329. if (!per_cpu(cpu_profile_hits, cpu)[1]) {
  330. page = alloc_pages_node(node,
  331. GFP_KERNEL | __GFP_ZERO,
  332. 0);
  333. if (!page)
  334. return NOTIFY_BAD;
  335. per_cpu(cpu_profile_hits, cpu)[1] = page_address(page);
  336. }
  337. if (!per_cpu(cpu_profile_hits, cpu)[0]) {
  338. page = alloc_pages_node(node,
  339. GFP_KERNEL | __GFP_ZERO,
  340. 0);
  341. if (!page)
  342. goto out_free;
  343. per_cpu(cpu_profile_hits, cpu)[0] = page_address(page);
  344. }
  345. break;
  346. out_free:
  347. page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[1]);
  348. per_cpu(cpu_profile_hits, cpu)[1] = NULL;
  349. __free_page(page);
  350. return NOTIFY_BAD;
  351. case CPU_ONLINE:
  352. case CPU_ONLINE_FROZEN:
  353. if (prof_cpu_mask != NULL)
  354. cpumask_set_cpu(cpu, prof_cpu_mask);
  355. break;
  356. case CPU_UP_CANCELED:
  357. case CPU_UP_CANCELED_FROZEN:
  358. case CPU_DEAD:
  359. case CPU_DEAD_FROZEN:
  360. if (prof_cpu_mask != NULL)
  361. cpumask_clear_cpu(cpu, prof_cpu_mask);
  362. if (per_cpu(cpu_profile_hits, cpu)[0]) {
  363. page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[0]);
  364. per_cpu(cpu_profile_hits, cpu)[0] = NULL;
  365. __free_page(page);
  366. }
  367. if (per_cpu(cpu_profile_hits, cpu)[1]) {
  368. page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[1]);
  369. per_cpu(cpu_profile_hits, cpu)[1] = NULL;
  370. __free_page(page);
  371. }
  372. break;
  373. }
  374. return NOTIFY_OK;
  375. }
  376. #else /* !CONFIG_SMP */
  377. #define profile_flip_buffers() do { } while (0)
  378. #define profile_discard_flip_buffers() do { } while (0)
  379. #define profile_cpu_callback NULL
  380. void profile_hits(int type, void *__pc, unsigned int nr_hits)
  381. {
  382. unsigned long pc;
  383. if (prof_on != type || !prof_buffer)
  384. return;
  385. pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
  386. atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
  387. }
  388. #endif /* !CONFIG_SMP */
  389. EXPORT_SYMBOL_GPL(profile_hits);
  390. void profile_tick(int type)
  391. {
  392. struct pt_regs *regs = get_irq_regs();
  393. if (type == CPU_PROFILING && timer_hook)
  394. timer_hook(regs);
  395. if (!user_mode(regs) && prof_cpu_mask != NULL &&
  396. cpumask_test_cpu(smp_processor_id(), prof_cpu_mask))
  397. profile_hit(type, (void *)profile_pc(regs));
  398. }
  399. #ifdef CONFIG_PROC_FS
  400. #include <linux/proc_fs.h>
  401. #include <asm/uaccess.h>
  402. static int prof_cpu_mask_read_proc(char *page, char **start, off_t off,
  403. int count, int *eof, void *data)
  404. {
  405. int len = cpumask_scnprintf(page, count, data);
  406. if (count - len < 2)
  407. return -EINVAL;
  408. len += sprintf(page + len, "\n");
  409. return len;
  410. }
  411. static int prof_cpu_mask_write_proc(struct file *file,
  412. const char __user *buffer, unsigned long count, void *data)
  413. {
  414. struct cpumask *mask = data;
  415. unsigned long full_count = count, err;
  416. cpumask_var_t new_value;
  417. if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
  418. return -ENOMEM;
  419. err = cpumask_parse_user(buffer, count, new_value);
  420. if (!err) {
  421. cpumask_copy(mask, new_value);
  422. err = full_count;
  423. }
  424. free_cpumask_var(new_value);
  425. return err;
  426. }
  427. void create_prof_cpu_mask(struct proc_dir_entry *root_irq_dir)
  428. {
  429. struct proc_dir_entry *entry;
  430. /* create /proc/irq/prof_cpu_mask */
  431. entry = create_proc_entry("prof_cpu_mask", 0600, root_irq_dir);
  432. if (!entry)
  433. return;
  434. entry->data = prof_cpu_mask;
  435. entry->read_proc = prof_cpu_mask_read_proc;
  436. entry->write_proc = prof_cpu_mask_write_proc;
  437. }
  438. /*
  439. * This function accesses profiling information. The returned data is
  440. * binary: the sampling step and the actual contents of the profile
  441. * buffer. Use of the program readprofile is recommended in order to
  442. * get meaningful info out of these data.
  443. */
  444. static ssize_t
  445. read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
  446. {
  447. unsigned long p = *ppos;
  448. ssize_t read;
  449. char *pnt;
  450. unsigned int sample_step = 1 << prof_shift;
  451. profile_flip_buffers();
  452. if (p >= (prof_len+1)*sizeof(unsigned int))
  453. return 0;
  454. if (count > (prof_len+1)*sizeof(unsigned int) - p)
  455. count = (prof_len+1)*sizeof(unsigned int) - p;
  456. read = 0;
  457. while (p < sizeof(unsigned int) && count > 0) {
  458. if (put_user(*((char *)(&sample_step)+p), buf))
  459. return -EFAULT;
  460. buf++; p++; count--; read++;
  461. }
  462. pnt = (char *)prof_buffer + p - sizeof(atomic_t);
  463. if (copy_to_user(buf, (void *)pnt, count))
  464. return -EFAULT;
  465. read += count;
  466. *ppos += read;
  467. return read;
  468. }
  469. /*
  470. * Writing to /proc/profile resets the counters
  471. *
  472. * Writing a 'profiling multiplier' value into it also re-sets the profiling
  473. * interrupt frequency, on architectures that support this.
  474. */
  475. static ssize_t write_profile(struct file *file, const char __user *buf,
  476. size_t count, loff_t *ppos)
  477. {
  478. #ifdef CONFIG_SMP
  479. extern int setup_profiling_timer(unsigned int multiplier);
  480. if (count == sizeof(int)) {
  481. unsigned int multiplier;
  482. if (copy_from_user(&multiplier, buf, sizeof(int)))
  483. return -EFAULT;
  484. if (setup_profiling_timer(multiplier))
  485. return -EINVAL;
  486. }
  487. #endif
  488. profile_discard_flip_buffers();
  489. memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
  490. return count;
  491. }
  492. static const struct file_operations proc_profile_operations = {
  493. .read = read_profile,
  494. .write = write_profile,
  495. };
  496. #ifdef CONFIG_SMP
  497. static void profile_nop(void *unused)
  498. {
  499. }
  500. static int create_hash_tables(void)
  501. {
  502. int cpu;
  503. for_each_online_cpu(cpu) {
  504. int node = cpu_to_node(cpu);
  505. struct page *page;
  506. page = alloc_pages_node(node,
  507. GFP_KERNEL | __GFP_ZERO | GFP_THISNODE,
  508. 0);
  509. if (!page)
  510. goto out_cleanup;
  511. per_cpu(cpu_profile_hits, cpu)[1]
  512. = (struct profile_hit *)page_address(page);
  513. page = alloc_pages_node(node,
  514. GFP_KERNEL | __GFP_ZERO | GFP_THISNODE,
  515. 0);
  516. if (!page)
  517. goto out_cleanup;
  518. per_cpu(cpu_profile_hits, cpu)[0]
  519. = (struct profile_hit *)page_address(page);
  520. }
  521. return 0;
  522. out_cleanup:
  523. prof_on = 0;
  524. smp_mb();
  525. on_each_cpu(profile_nop, NULL, 1);
  526. for_each_online_cpu(cpu) {
  527. struct page *page;
  528. if (per_cpu(cpu_profile_hits, cpu)[0]) {
  529. page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[0]);
  530. per_cpu(cpu_profile_hits, cpu)[0] = NULL;
  531. __free_page(page);
  532. }
  533. if (per_cpu(cpu_profile_hits, cpu)[1]) {
  534. page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[1]);
  535. per_cpu(cpu_profile_hits, cpu)[1] = NULL;
  536. __free_page(page);
  537. }
  538. }
  539. return -1;
  540. }
  541. #else
  542. #define create_hash_tables() ({ 0; })
  543. #endif
  544. int __ref create_proc_profile(void) /* false positive from hotcpu_notifier */
  545. {
  546. struct proc_dir_entry *entry;
  547. if (!prof_on)
  548. return 0;
  549. if (create_hash_tables())
  550. return -ENOMEM;
  551. entry = proc_create("profile", S_IWUSR | S_IRUGO,
  552. NULL, &proc_profile_operations);
  553. if (!entry)
  554. return 0;
  555. entry->size = (1+prof_len) * sizeof(atomic_t);
  556. hotcpu_notifier(profile_cpu_callback, 0);
  557. return 0;
  558. }
  559. module_init(create_proc_profile);
  560. #endif /* CONFIG_PROC_FS */