Merge tag 'metag-for-v4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/jhogan...
[sfrench/cifs-2.6.git] / arch / metag / oprofile / common.c
1 /*
2  * arch/metag/oprofile/common.c
3  *
4  * Copyright (C) 2013 Imagination Technologies Ltd.
5  *
6  * Based on arch/sh/oprofile/common.c:
7  *
8  * Copyright (C) 2003 - 2010  Paul Mundt
9  *
10  * Based on arch/mips/oprofile/common.c:
11  *
12  *      Copyright (C) 2004, 2005 Ralf Baechle
13  *      Copyright (C) 2005 MIPS Technologies, Inc.
14  *
15  * This file is subject to the terms and conditions of the GNU General Public
16  * License.  See the file "COPYING" in the main directory of this archive
17  * for more details.
18  */
19 #include <linux/errno.h>
20 #include <linux/init.h>
21 #include <linux/oprofile.h>
22 #include <linux/perf_event.h>
23 #include <linux/slab.h>
24
25 #include "backtrace.h"
26
27 #ifdef CONFIG_HW_PERF_EVENTS
28 /*
29  * This will need to be reworked when multiple PMUs are supported.
30  */
31 static char *metag_pmu_op_name;
32
33 char *op_name_from_perf_id(void)
34 {
35         return metag_pmu_op_name;
36 }
37
38 int __init oprofile_arch_init(struct oprofile_operations *ops)
39 {
40         ops->backtrace = metag_backtrace;
41
42         if (perf_num_counters() == 0)
43                 return -ENODEV;
44
45         metag_pmu_op_name = kasprintf(GFP_KERNEL, "metag/%s",
46                                       perf_pmu_name());
47         if (unlikely(!metag_pmu_op_name))
48                 return -ENOMEM;
49
50         return oprofile_perf_init(ops);
51 }
52
53 void oprofile_arch_exit(void)
54 {
55         oprofile_perf_exit();
56         kfree(metag_pmu_op_name);
57 }
58 #else
59 int __init oprofile_arch_init(struct oprofile_operations *ops)
60 {
61         ops->backtrace = metag_backtrace;
62         /* fall back to timer interrupt PC sampling */
63         return -ENODEV;
64 }
65 void oprofile_arch_exit(void) {}
66 #endif /* CONFIG_HW_PERF_EVENTS */