init.c 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/**
 * @file init.c
 *
 * @remark Copyright 2002 OProfile authors
 * @remark Read the file COPYING
 *
 * @author John Levon <levon@movementarian.org>
 */

#include <linux/kernel.h>
#include <linux/oprofile.h>
#include <linux/errno.h>
#include <linux/init.h>
 
15
#ifdef CONFIG_SPARC64
16 17 18 19
#include <linux/notifier.h>
#include <linux/rcupdate.h>
#include <linux/kdebug.h>
#include <asm/nmi.h>
20

21 22
static int profile_timer_exceptions_notify(struct notifier_block *self,
					   unsigned long val, void *data)
23
{
24
	struct die_args *args = data;
25
	int ret = NOTIFY_DONE;
26

27 28 29 30 31 32 33
	switch (val) {
	case DIE_NMI:
		oprofile_add_sample(args->regs, 0);
		ret = NOTIFY_STOP;
		break;
	default:
		break;
34
	}
35
	return ret;
36 37
}

38 39 40
static struct notifier_block profile_timer_exceptions_nb = {
	.notifier_call	= profile_timer_exceptions_notify,
};
41

42
static int timer_start(void)
43
{
44 45 46 47
	if (register_die_notifier(&profile_timer_exceptions_nb))
		return 1;
	nmi_adjust_hz(HZ);
	return 0;
48 49 50
}


51
static void timer_stop(void)
52
{
53 54 55
	nmi_adjust_hz(1);
	unregister_die_notifier(&profile_timer_exceptions_nb);
	synchronize_sched();  /* Allow already-started NMIs to complete. */
56 57
}

58
static int op_nmi_timer_init(struct oprofile_operations *ops)
59
{
60
	if (atomic_read(&nmi_active) <= 0)
61 62
		return -ENODEV;

63 64
	ops->start = timer_start;
	ops->stop = timer_stop;
65
	ops->cpu_type = "timer";
66
	printk(KERN_INFO "oprofile: Using perfctr NMI timer interrupt.\n");
67 68 69 70
	return 0;
}
#endif

R
Robert Richter 已提交
71
int __init oprofile_arch_init(struct oprofile_operations *ops)
72
{
73 74 75
	int ret = -ENODEV;

#ifdef CONFIG_SPARC64
76
	ret = op_nmi_timer_init(ops);
77 78 79 80 81
	if (!ret)
		return ret;
#endif

	return ret;
82 83 84 85 86
}

void oprofile_arch_exit(void)
{
}