profile.c 17 KB

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