ia64/linux-2.6.18-xen.hg

diff kernel/profile.c @ 0:831230e53067

Import 2.6.18 from kernel.org tarball.
author Ian Campbell <ian.campbell@xensource.com>
date Wed Apr 11 14:15:44 2007 +0100 (2007-04-11)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/kernel/profile.c	Wed Apr 11 14:15:44 2007 +0100
     1.3 @@ -0,0 +1,546 @@
     1.4 +/*
     1.5 + *  linux/kernel/profile.c
     1.6 + *  Simple profiling. Manages a direct-mapped profile hit count buffer,
     1.7 + *  with configurable resolution, support for restricting the cpus on
     1.8 + *  which profiling is done, and switching between cpu time and
     1.9 + *  schedule() calls via kernel command line parameters passed at boot.
    1.10 + *
    1.11 + *  Scheduler profiling support, Arjan van de Ven and Ingo Molnar,
    1.12 + *	Red Hat, July 2004
    1.13 + *  Consolidation of architecture support code for profiling,
    1.14 + *	William Irwin, Oracle, July 2004
    1.15 + *  Amortized hit count accounting via per-cpu open-addressed hashtables
    1.16 + *	to resolve timer interrupt livelocks, William Irwin, Oracle, 2004
    1.17 + */
    1.18 +
    1.19 +#include <linux/module.h>
    1.20 +#include <linux/profile.h>
    1.21 +#include <linux/bootmem.h>
    1.22 +#include <linux/notifier.h>
    1.23 +#include <linux/mm.h>
    1.24 +#include <linux/cpumask.h>
    1.25 +#include <linux/cpu.h>
    1.26 +#include <linux/profile.h>
    1.27 +#include <linux/highmem.h>
    1.28 +#include <linux/mutex.h>
    1.29 +#include <asm/sections.h>
    1.30 +#include <asm/semaphore.h>
    1.31 +
    1.32 +struct profile_hit {
    1.33 +	u32 pc, hits;
    1.34 +};
    1.35 +#define PROFILE_GRPSHIFT	3
    1.36 +#define PROFILE_GRPSZ		(1 << PROFILE_GRPSHIFT)
    1.37 +#define NR_PROFILE_HIT		(PAGE_SIZE/sizeof(struct profile_hit))
    1.38 +#define NR_PROFILE_GRP		(NR_PROFILE_HIT/PROFILE_GRPSZ)
    1.39 +
    1.40 +/* Oprofile timer tick hook */
    1.41 +int (*timer_hook)(struct pt_regs *) __read_mostly;
    1.42 +
    1.43 +static atomic_t *prof_buffer;
    1.44 +static unsigned long prof_len, prof_shift;
    1.45 +static int prof_on __read_mostly;
    1.46 +static cpumask_t prof_cpu_mask = CPU_MASK_ALL;
    1.47 +#ifdef CONFIG_SMP
    1.48 +static DEFINE_PER_CPU(struct profile_hit *[2], cpu_profile_hits);
    1.49 +static DEFINE_PER_CPU(int, cpu_profile_flip);
    1.50 +static DEFINE_MUTEX(profile_flip_mutex);
    1.51 +#endif /* CONFIG_SMP */
    1.52 +
    1.53 +static int __init profile_setup(char * str)
    1.54 +{
    1.55 +	static char __initdata schedstr[] = "schedule";
    1.56 +	int par;
    1.57 +
    1.58 +	if (!strncmp(str, schedstr, strlen(schedstr))) {
    1.59 +		prof_on = SCHED_PROFILING;
    1.60 +		if (str[strlen(schedstr)] == ',')
    1.61 +			str += strlen(schedstr) + 1;
    1.62 +		if (get_option(&str, &par))
    1.63 +			prof_shift = par;
    1.64 +		printk(KERN_INFO
    1.65 +			"kernel schedule profiling enabled (shift: %ld)\n",
    1.66 +			prof_shift);
    1.67 +	} else if (get_option(&str, &par)) {
    1.68 +		prof_shift = par;
    1.69 +		prof_on = CPU_PROFILING;
    1.70 +		printk(KERN_INFO "kernel profiling enabled (shift: %ld)\n",
    1.71 +			prof_shift);
    1.72 +	}
    1.73 +	return 1;
    1.74 +}
    1.75 +__setup("profile=", profile_setup);
    1.76 +
    1.77 +
    1.78 +void __init profile_init(void)
    1.79 +{
    1.80 +	if (!prof_on) 
    1.81 +		return;
    1.82 + 
    1.83 +	/* only text is profiled */
    1.84 +	prof_len = (_etext - _stext) >> prof_shift;
    1.85 +	prof_buffer = alloc_bootmem(prof_len*sizeof(atomic_t));
    1.86 +}
    1.87 +
    1.88 +/* Profile event notifications */
    1.89 + 
    1.90 +#ifdef CONFIG_PROFILING
    1.91 + 
    1.92 +static BLOCKING_NOTIFIER_HEAD(task_exit_notifier);
    1.93 +static ATOMIC_NOTIFIER_HEAD(task_free_notifier);
    1.94 +static BLOCKING_NOTIFIER_HEAD(munmap_notifier);
    1.95 + 
    1.96 +void profile_task_exit(struct task_struct * task)
    1.97 +{
    1.98 +	blocking_notifier_call_chain(&task_exit_notifier, 0, task);
    1.99 +}
   1.100 + 
   1.101 +int profile_handoff_task(struct task_struct * task)
   1.102 +{
   1.103 +	int ret;
   1.104 +	ret = atomic_notifier_call_chain(&task_free_notifier, 0, task);
   1.105 +	return (ret == NOTIFY_OK) ? 1 : 0;
   1.106 +}
   1.107 +
   1.108 +void profile_munmap(unsigned long addr)
   1.109 +{
   1.110 +	blocking_notifier_call_chain(&munmap_notifier, 0, (void *)addr);
   1.111 +}
   1.112 +
   1.113 +int task_handoff_register(struct notifier_block * n)
   1.114 +{
   1.115 +	return atomic_notifier_chain_register(&task_free_notifier, n);
   1.116 +}
   1.117 +
   1.118 +int task_handoff_unregister(struct notifier_block * n)
   1.119 +{
   1.120 +	return atomic_notifier_chain_unregister(&task_free_notifier, n);
   1.121 +}
   1.122 +
   1.123 +int profile_event_register(enum profile_type type, struct notifier_block * n)
   1.124 +{
   1.125 +	int err = -EINVAL;
   1.126 + 
   1.127 +	switch (type) {
   1.128 +		case PROFILE_TASK_EXIT:
   1.129 +			err = blocking_notifier_chain_register(
   1.130 +					&task_exit_notifier, n);
   1.131 +			break;
   1.132 +		case PROFILE_MUNMAP:
   1.133 +			err = blocking_notifier_chain_register(
   1.134 +					&munmap_notifier, n);
   1.135 +			break;
   1.136 +	}
   1.137 + 
   1.138 +	return err;
   1.139 +}
   1.140 +
   1.141 + 
   1.142 +int profile_event_unregister(enum profile_type type, struct notifier_block * n)
   1.143 +{
   1.144 +	int err = -EINVAL;
   1.145 + 
   1.146 +	switch (type) {
   1.147 +		case PROFILE_TASK_EXIT:
   1.148 +			err = blocking_notifier_chain_unregister(
   1.149 +					&task_exit_notifier, n);
   1.150 +			break;
   1.151 +		case PROFILE_MUNMAP:
   1.152 +			err = blocking_notifier_chain_unregister(
   1.153 +					&munmap_notifier, n);
   1.154 +			break;
   1.155 +	}
   1.156 +
   1.157 +	return err;
   1.158 +}
   1.159 +
   1.160 +int register_timer_hook(int (*hook)(struct pt_regs *))
   1.161 +{
   1.162 +	if (timer_hook)
   1.163 +		return -EBUSY;
   1.164 +	timer_hook = hook;
   1.165 +	return 0;
   1.166 +}
   1.167 +
   1.168 +void unregister_timer_hook(int (*hook)(struct pt_regs *))
   1.169 +{
   1.170 +	WARN_ON(hook != timer_hook);
   1.171 +	timer_hook = NULL;
   1.172 +	/* make sure all CPUs see the NULL hook */
   1.173 +	synchronize_sched();  /* Allow ongoing interrupts to complete. */
   1.174 +}
   1.175 +
   1.176 +EXPORT_SYMBOL_GPL(register_timer_hook);
   1.177 +EXPORT_SYMBOL_GPL(unregister_timer_hook);
   1.178 +EXPORT_SYMBOL_GPL(task_handoff_register);
   1.179 +EXPORT_SYMBOL_GPL(task_handoff_unregister);
   1.180 +
   1.181 +#endif /* CONFIG_PROFILING */
   1.182 +
   1.183 +EXPORT_SYMBOL_GPL(profile_event_register);
   1.184 +EXPORT_SYMBOL_GPL(profile_event_unregister);
   1.185 +
   1.186 +#ifdef CONFIG_SMP
   1.187 +/*
   1.188 + * Each cpu has a pair of open-addressed hashtables for pending
   1.189 + * profile hits. read_profile() IPI's all cpus to request them
   1.190 + * to flip buffers and flushes their contents to prof_buffer itself.
   1.191 + * Flip requests are serialized by the profile_flip_mutex. The sole
   1.192 + * use of having a second hashtable is for avoiding cacheline
   1.193 + * contention that would otherwise happen during flushes of pending
   1.194 + * profile hits required for the accuracy of reported profile hits
   1.195 + * and so resurrect the interrupt livelock issue.
   1.196 + *
   1.197 + * The open-addressed hashtables are indexed by profile buffer slot
   1.198 + * and hold the number of pending hits to that profile buffer slot on
   1.199 + * a cpu in an entry. When the hashtable overflows, all pending hits
   1.200 + * are accounted to their corresponding profile buffer slots with
   1.201 + * atomic_add() and the hashtable emptied. As numerous pending hits
   1.202 + * may be accounted to a profile buffer slot in a hashtable entry,
   1.203 + * this amortizes a number of atomic profile buffer increments likely
   1.204 + * to be far larger than the number of entries in the hashtable,
   1.205 + * particularly given that the number of distinct profile buffer
   1.206 + * positions to which hits are accounted during short intervals (e.g.
   1.207 + * several seconds) is usually very small. Exclusion from buffer
   1.208 + * flipping is provided by interrupt disablement (note that for
   1.209 + * SCHED_PROFILING profile_hit() may be called from process context).
   1.210 + * The hash function is meant to be lightweight as opposed to strong,
   1.211 + * and was vaguely inspired by ppc64 firmware-supported inverted
   1.212 + * pagetable hash functions, but uses a full hashtable full of finite
   1.213 + * collision chains, not just pairs of them.
   1.214 + *
   1.215 + * -- wli
   1.216 + */
   1.217 +static void __profile_flip_buffers(void *unused)
   1.218 +{
   1.219 +	int cpu = smp_processor_id();
   1.220 +
   1.221 +	per_cpu(cpu_profile_flip, cpu) = !per_cpu(cpu_profile_flip, cpu);
   1.222 +}
   1.223 +
   1.224 +static void profile_flip_buffers(void)
   1.225 +{
   1.226 +	int i, j, cpu;
   1.227 +
   1.228 +	mutex_lock(&profile_flip_mutex);
   1.229 +	j = per_cpu(cpu_profile_flip, get_cpu());
   1.230 +	put_cpu();
   1.231 +	on_each_cpu(__profile_flip_buffers, NULL, 0, 1);
   1.232 +	for_each_online_cpu(cpu) {
   1.233 +		struct profile_hit *hits = per_cpu(cpu_profile_hits, cpu)[j];
   1.234 +		for (i = 0; i < NR_PROFILE_HIT; ++i) {
   1.235 +			if (!hits[i].hits) {
   1.236 +				if (hits[i].pc)
   1.237 +					hits[i].pc = 0;
   1.238 +				continue;
   1.239 +			}
   1.240 +			atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
   1.241 +			hits[i].hits = hits[i].pc = 0;
   1.242 +		}
   1.243 +	}
   1.244 +	mutex_unlock(&profile_flip_mutex);
   1.245 +}
   1.246 +
   1.247 +static void profile_discard_flip_buffers(void)
   1.248 +{
   1.249 +	int i, cpu;
   1.250 +
   1.251 +	mutex_lock(&profile_flip_mutex);
   1.252 +	i = per_cpu(cpu_profile_flip, get_cpu());
   1.253 +	put_cpu();
   1.254 +	on_each_cpu(__profile_flip_buffers, NULL, 0, 1);
   1.255 +	for_each_online_cpu(cpu) {
   1.256 +		struct profile_hit *hits = per_cpu(cpu_profile_hits, cpu)[i];
   1.257 +		memset(hits, 0, NR_PROFILE_HIT*sizeof(struct profile_hit));
   1.258 +	}
   1.259 +	mutex_unlock(&profile_flip_mutex);
   1.260 +}
   1.261 +
   1.262 +void profile_hit(int type, void *__pc)
   1.263 +{
   1.264 +	unsigned long primary, secondary, flags, pc = (unsigned long)__pc;
   1.265 +	int i, j, cpu;
   1.266 +	struct profile_hit *hits;
   1.267 +
   1.268 +	if (prof_on != type || !prof_buffer)
   1.269 +		return;
   1.270 +	pc = min((pc - (unsigned long)_stext) >> prof_shift, prof_len - 1);
   1.271 +	i = primary = (pc & (NR_PROFILE_GRP - 1)) << PROFILE_GRPSHIFT;
   1.272 +	secondary = (~(pc << 1) & (NR_PROFILE_GRP - 1)) << PROFILE_GRPSHIFT;
   1.273 +	cpu = get_cpu();
   1.274 +	hits = per_cpu(cpu_profile_hits, cpu)[per_cpu(cpu_profile_flip, cpu)];
   1.275 +	if (!hits) {
   1.276 +		put_cpu();
   1.277 +		return;
   1.278 +	}
   1.279 +	local_irq_save(flags);
   1.280 +	do {
   1.281 +		for (j = 0; j < PROFILE_GRPSZ; ++j) {
   1.282 +			if (hits[i + j].pc == pc) {
   1.283 +				hits[i + j].hits++;
   1.284 +				goto out;
   1.285 +			} else if (!hits[i + j].hits) {
   1.286 +				hits[i + j].pc = pc;
   1.287 +				hits[i + j].hits = 1;
   1.288 +				goto out;
   1.289 +			}
   1.290 +		}
   1.291 +		i = (i + secondary) & (NR_PROFILE_HIT - 1);
   1.292 +	} while (i != primary);
   1.293 +	atomic_inc(&prof_buffer[pc]);
   1.294 +	for (i = 0; i < NR_PROFILE_HIT; ++i) {
   1.295 +		atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
   1.296 +		hits[i].pc = hits[i].hits = 0;
   1.297 +	}
   1.298 +out:
   1.299 +	local_irq_restore(flags);
   1.300 +	put_cpu();
   1.301 +}
   1.302 +
   1.303 +#ifdef CONFIG_HOTPLUG_CPU
   1.304 +static int __devinit profile_cpu_callback(struct notifier_block *info,
   1.305 +					unsigned long action, void *__cpu)
   1.306 +{
   1.307 +	int node, cpu = (unsigned long)__cpu;
   1.308 +	struct page *page;
   1.309 +
   1.310 +	switch (action) {
   1.311 +	case CPU_UP_PREPARE:
   1.312 +		node = cpu_to_node(cpu);
   1.313 +		per_cpu(cpu_profile_flip, cpu) = 0;
   1.314 +		if (!per_cpu(cpu_profile_hits, cpu)[1]) {
   1.315 +			page = alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0);
   1.316 +			if (!page)
   1.317 +				return NOTIFY_BAD;
   1.318 +			per_cpu(cpu_profile_hits, cpu)[1] = page_address(page);
   1.319 +		}
   1.320 +		if (!per_cpu(cpu_profile_hits, cpu)[0]) {
   1.321 +			page = alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0);
   1.322 +			if (!page)
   1.323 +				goto out_free;
   1.324 +			per_cpu(cpu_profile_hits, cpu)[0] = page_address(page);
   1.325 +		}
   1.326 +		break;
   1.327 +	out_free:
   1.328 +		page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[1]);
   1.329 +		per_cpu(cpu_profile_hits, cpu)[1] = NULL;
   1.330 +		__free_page(page);
   1.331 +		return NOTIFY_BAD;
   1.332 +	case CPU_ONLINE:
   1.333 +		cpu_set(cpu, prof_cpu_mask);
   1.334 +		break;
   1.335 +	case CPU_UP_CANCELED:
   1.336 +	case CPU_DEAD:
   1.337 +		cpu_clear(cpu, prof_cpu_mask);
   1.338 +		if (per_cpu(cpu_profile_hits, cpu)[0]) {
   1.339 +			page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[0]);
   1.340 +			per_cpu(cpu_profile_hits, cpu)[0] = NULL;
   1.341 +			__free_page(page);
   1.342 +		}
   1.343 +		if (per_cpu(cpu_profile_hits, cpu)[1]) {
   1.344 +			page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[1]);
   1.345 +			per_cpu(cpu_profile_hits, cpu)[1] = NULL;
   1.346 +			__free_page(page);
   1.347 +		}
   1.348 +		break;
   1.349 +	}
   1.350 +	return NOTIFY_OK;
   1.351 +}
   1.352 +#endif /* CONFIG_HOTPLUG_CPU */
   1.353 +#else /* !CONFIG_SMP */
   1.354 +#define profile_flip_buffers()		do { } while (0)
   1.355 +#define profile_discard_flip_buffers()	do { } while (0)
   1.356 +
   1.357 +void profile_hit(int type, void *__pc)
   1.358 +{
   1.359 +	unsigned long pc;
   1.360 +
   1.361 +	if (prof_on != type || !prof_buffer)
   1.362 +		return;
   1.363 +	pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
   1.364 +	atomic_inc(&prof_buffer[min(pc, prof_len - 1)]);
   1.365 +}
   1.366 +#endif /* !CONFIG_SMP */
   1.367 +
   1.368 +void profile_tick(int type, struct pt_regs *regs)
   1.369 +{
   1.370 +	if (type == CPU_PROFILING && timer_hook)
   1.371 +		timer_hook(regs);
   1.372 +	if (!user_mode(regs) && cpu_isset(smp_processor_id(), prof_cpu_mask))
   1.373 +		profile_hit(type, (void *)profile_pc(regs));
   1.374 +}
   1.375 +
   1.376 +#ifdef CONFIG_PROC_FS
   1.377 +#include <linux/proc_fs.h>
   1.378 +#include <asm/uaccess.h>
   1.379 +#include <asm/ptrace.h>
   1.380 +
   1.381 +static int prof_cpu_mask_read_proc (char *page, char **start, off_t off,
   1.382 +			int count, int *eof, void *data)
   1.383 +{
   1.384 +	int len = cpumask_scnprintf(page, count, *(cpumask_t *)data);
   1.385 +	if (count - len < 2)
   1.386 +		return -EINVAL;
   1.387 +	len += sprintf(page + len, "\n");
   1.388 +	return len;
   1.389 +}
   1.390 +
   1.391 +static int prof_cpu_mask_write_proc (struct file *file, const char __user *buffer,
   1.392 +					unsigned long count, void *data)
   1.393 +{
   1.394 +	cpumask_t *mask = (cpumask_t *)data;
   1.395 +	unsigned long full_count = count, err;
   1.396 +	cpumask_t new_value;
   1.397 +
   1.398 +	err = cpumask_parse(buffer, count, new_value);
   1.399 +	if (err)
   1.400 +		return err;
   1.401 +
   1.402 +	*mask = new_value;
   1.403 +	return full_count;
   1.404 +}
   1.405 +
   1.406 +void create_prof_cpu_mask(struct proc_dir_entry *root_irq_dir)
   1.407 +{
   1.408 +	struct proc_dir_entry *entry;
   1.409 +
   1.410 +	/* create /proc/irq/prof_cpu_mask */
   1.411 +	if (!(entry = create_proc_entry("prof_cpu_mask", 0600, root_irq_dir)))
   1.412 +		return;
   1.413 +	entry->nlink = 1;
   1.414 +	entry->data = (void *)&prof_cpu_mask;
   1.415 +	entry->read_proc = prof_cpu_mask_read_proc;
   1.416 +	entry->write_proc = prof_cpu_mask_write_proc;
   1.417 +}
   1.418 +
   1.419 +/*
   1.420 + * This function accesses profiling information. The returned data is
   1.421 + * binary: the sampling step and the actual contents of the profile
   1.422 + * buffer. Use of the program readprofile is recommended in order to
   1.423 + * get meaningful info out of these data.
   1.424 + */
   1.425 +static ssize_t
   1.426 +read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
   1.427 +{
   1.428 +	unsigned long p = *ppos;
   1.429 +	ssize_t read;
   1.430 +	char * pnt;
   1.431 +	unsigned int sample_step = 1 << prof_shift;
   1.432 +
   1.433 +	profile_flip_buffers();
   1.434 +	if (p >= (prof_len+1)*sizeof(unsigned int))
   1.435 +		return 0;
   1.436 +	if (count > (prof_len+1)*sizeof(unsigned int) - p)
   1.437 +		count = (prof_len+1)*sizeof(unsigned int) - p;
   1.438 +	read = 0;
   1.439 +
   1.440 +	while (p < sizeof(unsigned int) && count > 0) {
   1.441 +		put_user(*((char *)(&sample_step)+p),buf);
   1.442 +		buf++; p++; count--; read++;
   1.443 +	}
   1.444 +	pnt = (char *)prof_buffer + p - sizeof(atomic_t);
   1.445 +	if (copy_to_user(buf,(void *)pnt,count))
   1.446 +		return -EFAULT;
   1.447 +	read += count;
   1.448 +	*ppos += read;
   1.449 +	return read;
   1.450 +}
   1.451 +
   1.452 +/*
   1.453 + * Writing to /proc/profile resets the counters
   1.454 + *
   1.455 + * Writing a 'profiling multiplier' value into it also re-sets the profiling
   1.456 + * interrupt frequency, on architectures that support this.
   1.457 + */
   1.458 +static ssize_t write_profile(struct file *file, const char __user *buf,
   1.459 +			     size_t count, loff_t *ppos)
   1.460 +{
   1.461 +#ifdef CONFIG_SMP
   1.462 +	extern int setup_profiling_timer (unsigned int multiplier);
   1.463 +
   1.464 +	if (count == sizeof(int)) {
   1.465 +		unsigned int multiplier;
   1.466 +
   1.467 +		if (copy_from_user(&multiplier, buf, sizeof(int)))
   1.468 +			return -EFAULT;
   1.469 +
   1.470 +		if (setup_profiling_timer(multiplier))
   1.471 +			return -EINVAL;
   1.472 +	}
   1.473 +#endif
   1.474 +	profile_discard_flip_buffers();
   1.475 +	memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
   1.476 +	return count;
   1.477 +}
   1.478 +
   1.479 +static struct file_operations proc_profile_operations = {
   1.480 +	.read		= read_profile,
   1.481 +	.write		= write_profile,
   1.482 +};
   1.483 +
   1.484 +#ifdef CONFIG_SMP
   1.485 +static void __init profile_nop(void *unused)
   1.486 +{
   1.487 +}
   1.488 +
   1.489 +static int __init create_hash_tables(void)
   1.490 +{
   1.491 +	int cpu;
   1.492 +
   1.493 +	for_each_online_cpu(cpu) {
   1.494 +		int node = cpu_to_node(cpu);
   1.495 +		struct page *page;
   1.496 +
   1.497 +		page = alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0);
   1.498 +		if (!page)
   1.499 +			goto out_cleanup;
   1.500 +		per_cpu(cpu_profile_hits, cpu)[1]
   1.501 +				= (struct profile_hit *)page_address(page);
   1.502 +		page = alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0);
   1.503 +		if (!page)
   1.504 +			goto out_cleanup;
   1.505 +		per_cpu(cpu_profile_hits, cpu)[0]
   1.506 +				= (struct profile_hit *)page_address(page);
   1.507 +	}
   1.508 +	return 0;
   1.509 +out_cleanup:
   1.510 +	prof_on = 0;
   1.511 +	smp_mb();
   1.512 +	on_each_cpu(profile_nop, NULL, 0, 1);
   1.513 +	for_each_online_cpu(cpu) {
   1.514 +		struct page *page;
   1.515 +
   1.516 +		if (per_cpu(cpu_profile_hits, cpu)[0]) {
   1.517 +			page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[0]);
   1.518 +			per_cpu(cpu_profile_hits, cpu)[0] = NULL;
   1.519 +			__free_page(page);
   1.520 +		}
   1.521 +		if (per_cpu(cpu_profile_hits, cpu)[1]) {
   1.522 +			page = virt_to_page(per_cpu(cpu_profile_hits, cpu)[1]);
   1.523 +			per_cpu(cpu_profile_hits, cpu)[1] = NULL;
   1.524 +			__free_page(page);
   1.525 +		}
   1.526 +	}
   1.527 +	return -1;
   1.528 +}
   1.529 +#else
   1.530 +#define create_hash_tables()			({ 0; })
   1.531 +#endif
   1.532 +
   1.533 +static int __init create_proc_profile(void)
   1.534 +{
   1.535 +	struct proc_dir_entry *entry;
   1.536 +
   1.537 +	if (!prof_on)
   1.538 +		return 0;
   1.539 +	if (create_hash_tables())
   1.540 +		return -1;
   1.541 +	if (!(entry = create_proc_entry("profile", S_IWUSR | S_IRUGO, NULL)))
   1.542 +		return 0;
   1.543 +	entry->proc_fops = &proc_profile_operations;
   1.544 +	entry->size = (1+prof_len) * sizeof(atomic_t);
   1.545 +	hotcpu_notifier(profile_cpu_callback, 0);
   1.546 +	return 0;
   1.547 +}
   1.548 +module_init(create_proc_profile);
   1.549 +#endif /* CONFIG_PROC_FS */