profile.c 17 KB

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