blob: f148cf65267836d66e1fa666d612dca5669950c3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
2 * @file init.c
3 *
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
6 *
7 * @author John Levon <levon@movementarian.org>
8 */
9
10#include <linux/oprofile.h>
11#include <linux/init.h>
12#include <linux/errno.h>
Paolo Ciarrocchid717ca82008-02-22 23:09:50 +010013
14/*
15 * We support CPUs that have performance counters like the Pentium Pro
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * with the NMI mode driver.
17 */
Paolo Ciarrocchid717ca82008-02-22 23:09:50 +010018
19extern int op_nmi_init(struct oprofile_operations *ops);
20extern int op_nmi_timer_init(struct oprofile_operations *ops);
David Gibson96d08212005-09-06 15:17:26 -070021extern void op_nmi_exit(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022extern void x86_backtrace(struct pt_regs * const regs, unsigned int depth);
23
Robert Richter97f7f812011-10-10 16:21:10 +020024static int nmi_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Paolo Ciarrocchid717ca82008-02-22 23:09:50 +010026int __init oprofile_arch_init(struct oprofile_operations *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
28 int ret;
29
30 ret = -ENODEV;
31
32#ifdef CONFIG_X86_LOCAL_APIC
David Gibson96d08212005-09-06 15:17:26 -070033 ret = op_nmi_init(ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#endif
Robert Richter97f7f812011-10-10 16:21:10 +020035 nmi_timer = (ret != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#ifdef CONFIG_X86_IO_APIC
Robert Richter97f7f812011-10-10 16:21:10 +020037 if (nmi_timer)
David Gibson96d08212005-09-06 15:17:26 -070038 ret = op_nmi_timer_init(ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#endif
40 ops->backtrace = x86_backtrace;
41
42 return ret;
43}
44
45
46void oprofile_arch_exit(void)
47{
48#ifdef CONFIG_X86_LOCAL_APIC
Robert Richter97f7f812011-10-10 16:21:10 +020049 if (!nmi_timer)
50 op_nmi_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#endif
52}