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 (!alloc_cpumask_var(&prof_cpu_mask, GFP_KERNEL))
  104. return -ENOMEM;
  105. cpumask_copy(prof_cpu_mask, cpu_possible_mask);
  106. prof_buffer = kzalloc(buffer_bytes, GFP_KERNEL|__GFP_NOWARN);
  107. if (prof_buffer)
  108. return 0;
  109. prof_buffer = alloc_pages_exact(buffer_bytes,
  110. GFP_KERNEL|__GFP_ZERO|__GFP_NOWARN);
  111. if (prof_buffer)
  112. return 0;
  113. prof_buffer = vmalloc(buffer_bytes);
  114. if (prof_buffer) {
  115. memset(prof_buffer, 0, buffer_bytes);
  116. return 0;
  117. }
  118. free_cpumask_var(prof_cpu_mask);
  119. return -ENOMEM;
  120. }
  121. /* Profile event notifications */
  122. static BLOCKING_NOTIFIER_HEAD(task_exit_notifier);
  123. static ATOMIC_NOTIFIER_HEAD(task_free_notifier);
  124. static BLOCKING_NOTIFIER_HEAD(munmap_notifier);
  125. void profile_task_exit(struct task_struct *task)
  126. {
  127. blocking_notifier_call_chain(&task_exit_notifier, 0, task);
  128. }
  129. int profile_handoff_task(struct task_struct *task)
  130. {
  131. int ret;
  132. ret = atomic_notifier_call_chain(&task_free_notifier, 0, task);
  133. return (ret == NOTIFY_OK) ? 1 : 0;
  134. }
  135. void profile_munmap(unsigned long addr)
  136. {
  137. blocking_notifier_call_chain(&munmap_notifier, 0, (void *)addr);
  138. }
  139. int task_handoff_register(struct notifier_block *n)
  140. {
  141. return atomic_notifier_chain_register(&task_free_notifier, n);
  142. }
  143. EXPORT_SYMBOL_GPL(task_handoff_register);
  144. int task_handoff_unregister(struct notifier_block *n)
  145. {
  146. return atomic_notifier_chain_unregister(&task_free_notifier, n);
  147. }
  148. EXPORT_SYMBOL_GPL(task_handoff_unregister);
  149. int profile_event_register(enum profile_type type, struct notifier_block *n)
  150. {
  151. int err = -EINVAL;
  152. switch (type) {
  153. case PROFILE_TASK_EXIT:
  154. err = blocking_notifier_chain_register(
  155. &task_exit_notifier, n);
  156. break;
  157. case PROFILE_MUNMAP:
  158. err = blocking_notifier_chain_register(
  159. &munmap_notifier, n);
  160. break;
  161. }
  162. return err;
  163. }
  164. EXPORT_SYMBOL_GPL(profile_event_register);
  165. int profile_event_unregister(enum profile_type type, struct notifier_block *n)
  166. {
  167. int err = -EINVAL;
  168. switch (type) {
  169. case PROFILE_TASK_EXIT:
  170. err = blocking_notifier_chain_unregister(
  171. &task_exit_notifier, n);
  172. break;
  173. case PROFILE_MUNMAP:
  174. err = blocking_notifier_chain_unregister(
  175. &munmap_notifier, n);
  176. break;
  177. }
  178. return err;
  179. }
  180. EXPORT_SYMBOL_GPL(profile_event_unregister);
  181. int register_timer_hook(int (*hook)(struct pt_regs *))
  182. {
  183. if (timer_hook)
  184. return -EBUSY;
  185. timer_hook = hook;
  186. return 0;
  187. }
  188. EXPORT_SYMBOL_GPL(register_timer_hook);
  189. void unregister_timer_hook(int (*hook)(struct pt_regs *))
  190. {
  191. WARN_ON(hook != timer_hook);
  192. timer_hook = NULL;
  193. /* make sure all CPUs see the NULL hook */
  194. synchronize_sched(); /* Allow ongoing interrupts to complete. */
  195. }
  196. EXPORT_SYMBOL_GPL(unregister_timer_hook);
  197. #ifdef CONFIG_SMP
  198. /*
  199. * Each cpu has a pair of open-addressed hashtables for pending
  200. * profile hits. read_profile() IPI's all cpus to request them
  201. * to flip buffers and flushes their contents to prof_buffer itself.
  202. * Flip requests are serialized by the profile_flip_mutex. The sole
  203. * use of having a second hashtable is for avoiding cacheline
  204. * contention that would otherwise happen during flushes of pending
  205. * profile hits required for the accuracy of reported profile hits
  206. * and so resurrect the interrupt livelock issue.
  207. *
  208. * The open-addressed hashtables are indexed by profile buffer slot
  209. * and hold the number of pending hits to that profile buffer slot on
  210. * a cpu in an entry. When the hashtable overflows, all pending hits
  211. * are accounted to their corresponding profile buffer slots with
  212. * atomic_add() and the hashtable emptied. As numerous pending hits
  213. * may be accounted to a profile buffer slot in a hashtable entry,
  214. * this amortizes a number of atomic profile buffer increments likely
  215. * to be far larger than the number of entries in the hashtable,
  216. * particularly given that the number of distinct profile buffer
  217. * positions to which hits are accounted during short intervals (e.g.
  218. * several seconds) is usually very small. Exclusion from buffer
  219. * flipping is provided by interrupt disablement (note that for
  220. * SCHED_PROFILING or SLEEP_PROFILING profile_hit() may be called from
  221. * process context).
  222. * The hash function is meant to be lightweight as opposed to strong,
  223. * and was vaguely inspired by ppc64 firmware-supported inverted
  224. * pagetable hash functions, but uses a full hashtable full of finite
  225. * collision chains, not just pairs of them.
  226. *
  227. * -- wli
  228. */
  229. static void __profile_flip_buffers(void *unused)
  230. {
  231. int cpu = smp_processor_id();
  232. per_cpu(cpu_profile_flip, cpu) = !per_cpu(cpu_profile_flip, cpu);
  233. }
  234. static void profile_flip_buffers(void)
  235. {
  236. int i, j, cpu;
  237. mutex_lock(&profile_flip_mutex);
  238. j = per_cpu(cpu_profile_flip, get_cpu());
  239. put_cpu();
  240. on_each_cpu(__profile_flip_buffers, NULL, 1);
  241. for_each_online_cpu(cpu) {
  242. struct profile_hit *hits = per_cpu(cpu_profile_hits, cpu)[j];
  243. for (i = 0; i < NR_PROFILE_HIT; ++i) {
  244. if (!hits[i].hits) {
  245. if (hits[i].pc)
  246. hits[i].pc = 0;
  247. continue;
  248. }
  249. atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
  250. hits[i].hits = hits[i].pc = 0;
  251. }
  252. }
  253. mutex_unlock(&profile_flip_mutex);
  254. }
  255. static void profile_discard_flip_buffers(void)
  256. {
  257. int i, cpu;
  258. mutex_lock(&profile_flip_mutex);
  259. i = per_cpu(cpu_profile_flip, get_cpu());
  260. put_cpu();
  261. on_each_cpu(__profile_flip_buffers, NULL, 1);
  262. for_each_online_cpu(cpu) {
  263. struct profile_hit *hits = per_cpu(cpu_profile_hits, cpu)[i];
  264. memset(hits, 0, NR_PROFILE_HIT*sizeof(struct profile_hit));
  265. }
  266. mutex_unlock(&profile_flip_mutex);
  267. }
  268. void profile_hits(int type, void *__pc, unsigned int nr_hits)
  269. {
  270. unsigned long primary, secondary, flags, pc = (unsigned long)__pc;
  271. int i, j, cpu;
  272. struct profile_hit *hits;
  273. if (prof_on != type || !prof_buffer)
  274. return;
  275. pc = min((pc - (unsigned long)_stext) >> prof_shift, prof_len - 1);
  276. i = primary = (pc & (NR_PROFILE_GRP - 1)) << PROFILE_GRPSHIFT;
  277. secondary = (~(pc << 1) & (NR_PROFILE_GRP - 1)) << PROFILE_GRPSHIFT;
  278. cpu = get_cpu();
  279. hits = per_cpu(cpu_profile_hits, cpu)[per_cpu(cpu_profile_flip, cpu)];
  280. if (!hits) {
  281. put_cpu();
  282. return;
  283. }
  284. /*
  285. * We buffer the global profiler buffer into a per-CPU
  286. * queue and thus reduce the number of global (and possibly
  287. * NUMA-alien) accesses. The write-queue is self-coalescing:
  288. */
  289. local_irq_save(flags);
  290. do {
  291. for (j = 0; j < PROFILE_GRPSZ; ++j) {
  292. if (hits[i + j].pc == pc) {
  293. hits[i + j].hits += nr_hits;
  294. goto out;
  295. } else if (!hits[i + j].hits) {
  296. hits[i + j].pc = pc;
  297. hits[i + j].hits = nr_hits;
  298. goto out;
  299. }
  300. }
  301. i = (i + secondary) & (NR_PROFILE_HIT - 1);
  302. } while (i != primary);
  303. /*
  304. * Add the current hit(s) and flush the write-queue out
  305. * to the global buffer:
  306. */
  307. atomic_add(nr_hits, &prof_buffer[pc]);
  308. for (i = 0; i < NR_PROFILE_HIT; ++i) {
  309. atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
  310. hits[i].pc = hits[i].hits = 0;
  311. }
  312. out:
  313. local_irq_restore(flags);
  314. put_cpu();
  315. }
  316. static int __cpuinit profile_cpu_callback(struct notifier_block *info,
  317. unsigned long action, void *__cpu)
  318. {
  319. int node, cpu = (unsigned long)__cpu;
  320. struct page *page;
  321. switch (action) {
  322. case CPU_UP_PREPARE:
  323. case CPU_UP_PREPARE_FROZEN:
  324. node = cpu_to_mem(cpu);
  325. per_cpu(cpu_profile_flip, cpu) = 0;
  326. if (!per_cpu(cpu_profile_hits, cpu)[1]) {
  327. page = alloc_pages_exact_node(node,
  328. GFP_KERNEL | __GFP_ZERO,
  329. 0);
  330. if (!page)
  331. return notifier_from_errno(-ENOMEM);
  332. per_cpu(cpu_profile_hits, cpu)[1] = page_address(page);
  333. }
  334. if (!per_cpu(cpu_profile_hits, cpu)[0]) {
  335. page = alloc_pages_exact_node(node,
  336. GFP_KERNEL | __GFP_ZERO,
  337. 0);
  338. if (!page)
  339. goto out_free;
  340. per_cpu(cpu_profile_hits, cpu)[0] = page_address(page);
  341. }
  342. break;
  343. out_free:
  344. page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[1]);
  345. per_cpu(cpu_profile_hits, cpu)[1] = NULL;
  346. __free_page(page);
  347. return notifier_from_errno(-ENOMEM);
  348. case CPU_ONLINE:
  349. case CPU_ONLINE_FROZEN:
  350. if (prof_cpu_mask != NULL)
  351. cpumask_set_cpu(cpu, prof_cpu_mask);
  352. break;
  353. case CPU_UP_CANCELED:
  354. case CPU_UP_CANCELED_FROZEN:
  355. case CPU_DEAD:
  356. case CPU_DEAD_FROZEN:
  357. if (prof_cpu_mask != NULL)
  358. cpumask_clear_cpu(cpu, prof_cpu_mask);
  359. if (per_cpu(cpu_profile_hits, cpu)[0]) {
  360. page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[0]);
  361. per_cpu(cpu_profile_hits, cpu)[0] = NULL;
  362. __free_page(page);
  363. }
  364. if (per_cpu(cpu_profile_hits, cpu)[1]) {
  365. page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[1]);
  366. per_cpu(cpu_profile_hits, cpu)[1] = NULL;
  367. __free_page(page);
  368. }
  369. break;
  370. }
  371. return NOTIFY_OK;
  372. }
  373. #else /* !CONFIG_SMP */
  374. #define profile_flip_buffers() do { } while (0)
  375. #define profile_discard_flip_buffers() do { } while (0)
  376. #define profile_cpu_callback NULL
  377. void profile_hits(int type, void *__pc, unsigned int nr_hits)
  378. {
  379. unsigned long pc;
  380. if (prof_on != type || !prof_buffer)
  381. return;
  382. pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
  383. atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
  384. }
  385. #endif /* !CONFIG_SMP */
  386. EXPORT_SYMBOL_GPL(profile_hits);
  387. void profile_tick(int type)
  388. {
  389. struct pt_regs *regs = get_irq_regs();
  390. if (type == CPU_PROFILING && timer_hook)
  391. timer_hook(regs);
  392. if (!user_mode(regs) && prof_cpu_mask != NULL &&
  393. cpumask_test_cpu(smp_processor_id(), prof_cpu_mask))
  394. profile_hit(type, (void *)profile_pc(regs));
  395. }
  396. #ifdef CONFIG_PROC_FS
  397. #include <linux/proc_fs.h>
  398. #include <linux/seq_file.h>
  399. #include <asm/uaccess.h>
  400. static int prof_cpu_mask_proc_show(struct seq_file *m, void *v)
  401. {
  402. seq_cpumask(m, prof_cpu_mask);
  403. seq_putc(m, '\n');
  404. return 0;
  405. }
  406. static int prof_cpu_mask_proc_open(struct inode *inode, struct file *file)
  407. {
  408. return single_open(file, prof_cpu_mask_proc_show, NULL);
  409. }
  410. static ssize_t prof_cpu_mask_proc_write(struct file *file,
  411. const char __user *buffer, size_t count, loff_t *pos)
  412. {
  413. cpumask_var_t new_value;
  414. int err;
  415. if (!alloc_cpumask_var(&new_value, GFP_KERNEL))
  416. return -ENOMEM;
  417. err = cpumask_parse_user(buffer, count, new_value);
  418. if (!err) {
  419. cpumask_copy(prof_cpu_mask, new_value);
  420. err = count;
  421. }
  422. free_cpumask_var(new_value);
  423. return err;
  424. }
  425. static const struct file_operations prof_cpu_mask_proc_fops = {
  426. .open = prof_cpu_mask_proc_open,
  427. .read = seq_read,
  428. .llseek = seq_lseek,
  429. .release = single_release,
  430. .write = prof_cpu_mask_proc_write,
  431. };
  432. void create_prof_cpu_mask(struct proc_dir_entry *root_irq_dir)
  433. {
  434. /* create /proc/irq/prof_cpu_mask */
  435. proc_create("prof_cpu_mask", 0600, root_irq_dir, &prof_cpu_mask_proc_fops);
  436. }
  437. /*
  438. * This function accesses profiling information. The returned data is
  439. * binary: the sampling step and the actual contents of the profile
  440. * buffer. Use of the program readprofile is recommended in order to
  441. * get meaningful info out of these data.
  442. */
  443. static ssize_t
  444. read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
  445. {
  446. unsigned long p = *ppos;
  447. ssize_t read;
  448. char *pnt;
  449. unsigned int sample_step = 1 << prof_shift;
  450. profile_flip_buffers();
  451. if (p >= (prof_len+1)*sizeof(unsigned int))
  452. return 0;
  453. if (count > (prof_len+1)*sizeof(unsigned int) - p)
  454. count = (prof_len+1)*sizeof(unsigned int) - p;
  455. read = 0;
  456. while (p < sizeof(unsigned int) && count > 0) {
  457. if (put_user(*((char *)(&sample_step)+p), buf))
  458. return -EFAULT;
  459. buf++; p++; count--; read++;
  460. }
  461. pnt = (char *)prof_buffer + p - sizeof(atomic_t);
  462. if (copy_to_user(buf, (void *)pnt, count))
  463. return -EFAULT;
  464. read += count;
  465. *ppos += read;
  466. return read;
  467. }
  468. /*
  469. * Writing to /proc/profile resets the counters
  470. *
  471. * Writing a 'profiling multiplier' value into it also re-sets the profiling
  472. * interrupt frequency, on architectures that support this.
  473. */
  474. static ssize_t write_profile(struct file *file, const char __user *buf,
  475. size_t count, loff_t *ppos)
  476. {
  477. #ifdef CONFIG_SMP
  478. extern int setup_profiling_timer(unsigned int multiplier);
  479. if (count == sizeof(int)) {
  480. unsigned int multiplier;
  481. if (copy_from_user(&multiplier, buf, sizeof(int)))
  482. return -EFAULT;
  483. if (setup_profiling_timer(multiplier))
  484. return -EINVAL;
  485. }
  486. #endif
  487. profile_discard_flip_buffers();
  488. memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
  489. return count;
  490. }
  491. static const struct file_operations proc_profile_operations = {
  492. .read = read_profile,
  493. .write = write_profile,
  494. };
  495. #ifdef CONFIG_SMP
  496. static void profile_nop(void *unused)
  497. {
  498. }
  499. static int create_hash_tables(void)
  500. {
  501. int cpu;
  502. for_each_online_cpu(cpu) {
  503. int node = cpu_to_mem(cpu);
  504. struct page *page;
  505. page = alloc_pages_exact_node(node,
  506. GFP_KERNEL | __GFP_ZERO | GFP_THISNODE,
  507. 0);
  508. if (!page)
  509. goto out_cleanup;
  510. per_cpu(cpu_profile_hits, cpu)[1]
  511. = (struct profile_hit *)page_address(page);
  512. page = alloc_pages_exact_node(node,
  513. GFP_KERNEL | __GFP_ZERO | GFP_THISNODE,
  514. 0);
  515. if (!page)
  516. goto out_cleanup;
  517. per_cpu(cpu_profile_hits, cpu)[0]
  518. = (struct profile_hit *)page_address(page);
  519. }
  520. return 0;
  521. out_cleanup:
  522. prof_on = 0;
  523. smp_mb();
  524. on_each_cpu(profile_nop, NULL, 1);
  525. for_each_online_cpu(cpu) {
  526. struct page *page;
  527. if (per_cpu(cpu_profile_hits, cpu)[0]) {
  528. page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[0]);
  529. per_cpu(cpu_profile_hits, cpu)[0] = NULL;
  530. __free_page(page);
  531. }
  532. if (per_cpu(cpu_profile_hits, cpu)[1]) {
  533. page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[1]);
  534. per_cpu(cpu_profile_hits, cpu)[1] = NULL;
  535. __free_page(page);
  536. }
  537. }
  538. return -1;
  539. }
  540. #else
  541. #define create_hash_tables() ({ 0; })
  542. #endif
  543. int __ref create_proc_profile(void) /* false positive from hotcpu_notifier */
  544. {
  545. struct proc_dir_entry *entry;
  546. if (!prof_on)
  547. return 0;
  548. if (create_hash_tables())
  549. return -ENOMEM;
  550. entry = proc_create("profile", S_IWUSR | S_IRUGO,
  551. NULL, &proc_profile_operations);
  552. if (!entry)
  553. return 0;
  554. entry->size = (1+prof_len) * sizeof(atomic_t);
  555. hotcpu_notifier(profile_cpu_callback, 0);
  556. return 0;
  557. }
  558. module_init(create_proc_profile);
  559. #endif /* CONFIG_PROC_FS */