]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/oprofile.h
ARM: oprofile: Fix backtraces in timer mode
[mirror_ubuntu-bionic-kernel.git] / include / linux / oprofile.h
CommitLineData
1da177e4
LT
1/**
2 * @file oprofile.h
3 *
4 * API for machine-specific interrupts to interface
5 * to oprofile.
6 *
7 * @remark Copyright 2002 OProfile authors
8 * @remark Read the file COPYING
9 *
10 * @author John Levon <levon@movementarian.org>
11 */
12
13#ifndef OPROFILE_H
14#define OPROFILE_H
15
16#include <linux/types.h>
17#include <linux/spinlock.h>
3d90a007 18#include <linux/init.h>
d14dd7e2
AK
19#include <linux/errno.h>
20#include <linux/printk.h>
1da177e4
LT
21#include <asm/atomic.h>
22
1474855d
BN
23/* Each escaped entry is prefixed by ESCAPE_CODE
24 * then one of the following codes, then the
25 * relevant data.
26 * These #defines live in this file so that arch-specific
27 * buffer sync'ing code can access them.
28 */
29#define ESCAPE_CODE ~0UL
30#define CTX_SWITCH_CODE 1
31#define CPU_SWITCH_CODE 2
32#define COOKIE_SWITCH_CODE 3
33#define KERNEL_ENTER_SWITCH_CODE 4
34#define KERNEL_EXIT_SWITCH_CODE 5
35#define MODULE_LOADED_CODE 6
36#define CTX_TGID_CODE 7
37#define TRACE_BEGIN_CODE 8
38#define TRACE_END_CODE 9
39#define XEN_ENTER_SWITCH_CODE 10
40#define SPU_PROFILING_CODE 11
41#define SPU_CTX_SWITCH_CODE 12
ee648bc7
RR
42#define IBS_FETCH_CODE 13
43#define IBS_OP_CODE 14
1474855d 44
1da177e4
LT
45struct super_block;
46struct dentry;
47struct file_operations;
48struct pt_regs;
49
50/* Operations structure to be filled in */
51struct oprofile_operations {
52 /* create any necessary configuration files in the oprofile fs.
53 * Optional. */
54 int (*create_files)(struct super_block * sb, struct dentry * root);
55 /* Do any necessary interrupt setup. Optional. */
56 int (*setup)(void);
57 /* Do any necessary interrupt shutdown. Optional. */
58 void (*shutdown)(void);
59 /* Start delivering interrupts. */
60 int (*start)(void);
61 /* Stop delivering interrupts. */
62 void (*stop)(void);
1474855d
BN
63 /* Arch-specific buffer sync functions.
64 * Return value = 0: Success
65 * Return value = -1: Failure
66 * Return value = 1: Run generic sync function
67 */
68 int (*sync_start)(void);
69 int (*sync_stop)(void);
70
1da177e4
LT
71 /* Initiate a stack backtrace. Optional. */
72 void (*backtrace)(struct pt_regs * const regs, unsigned int depth);
4d4036e0
JY
73
74 /* Multiplex between different events. Optional. */
75 int (*switch_events)(void);
1da177e4
LT
76 /* CPU identification string. */
77 char * cpu_type;
78};
79
80/**
81 * One-time initialisation. *ops must be set to a filled-in
82 * operations structure. This is called even in timer interrupt
83 * mode so an arch can set a backtrace callback.
84 *
85 * If an error occurs, the fields should be left untouched.
86 */
87int oprofile_arch_init(struct oprofile_operations * ops);
88
89/**
90 * One-time exit/cleanup for the arch.
91 */
92void oprofile_arch_exit(void);
93
94/**
58494487 95 * Add a sample. This may be called from any context.
1da177e4
LT
96 */
97void oprofile_add_sample(struct pt_regs * const regs, unsigned long event);
98
27357716
BR
99/**
100 * Add an extended sample. Use this when the PC is not from the regs, and
101 * we cannot determine if we're in kernel mode from the regs.
102 *
103 * This function does perform a backtrace.
104 *
105 */
106void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
107 unsigned long event, int is_kernel);
108
1da177e4
LT
109/* Use this instead when the PC value is not from the regs. Doesn't
110 * backtrace. */
111void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event);
112
113/* add a backtrace entry, to be called from the ->backtrace callback */
114void oprofile_add_trace(unsigned long eip);
115
116
117/**
118 * Create a file of the given name as a child of the given root, with
119 * the specified file operations.
120 */
121int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
99ac48f5 122 char const * name, const struct file_operations * fops);
1da177e4
LT
123
124int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root,
99ac48f5 125 char const * name, const struct file_operations * fops, int perm);
1da177e4
LT
126
127/** Create a file for read/write access to an unsigned long. */
128int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
129 char const * name, ulong * val);
130
131/** Create a file for read-only access to an unsigned long. */
132int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
133 char const * name, ulong * val);
134
135/** Create a file for read-only access to an atomic_t. */
136int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
137 char const * name, atomic_t * val);
138
139/** create a directory */
140struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
141 char const * name);
142
143/**
144 * Write the given asciz string to the given user buffer @buf, updating *offset
145 * appropriately. Returns bytes written or -EFAULT.
146 */
147ssize_t oprofilefs_str_to_user(char const * str, char __user * buf, size_t count, loff_t * offset);
148
149/**
150 * Convert an unsigned long value into ASCII and copy it to the user buffer @buf,
151 * updating *offset appropriately. Returns bytes written or -EFAULT.
152 */
153ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t count, loff_t * offset);
154
155/**
156 * Read an ASCII string for a number from a userspace buffer and fill *val on success.
157 * Returns 0 on success, < 0 on error.
158 */
159int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
160
161/** lock for read/write safety */
162extern spinlock_t oprofilefs_lock;
a5598ca0
CL
163
164/**
165 * Add the contents of a circular buffer to the event buffer.
166 */
167void oprofile_put_buff(unsigned long *buf, unsigned int start,
168 unsigned int stop, unsigned int max);
169
170unsigned long oprofile_get_cpu_buffer_size(void);
171void oprofile_cpu_buffer_inc_smpl_lost(void);
1da177e4 172
14f0ca8e
RR
173/* cpu buffer functions */
174
175struct op_sample;
176
177struct op_entry {
178 struct ring_buffer_event *event;
179 struct op_sample *sample;
14f0ca8e
RR
180 unsigned long size;
181 unsigned long *data;
182};
183
184void oprofile_write_reserve(struct op_entry *entry,
185 struct pt_regs * const regs,
186 unsigned long pc, int code, int size);
187int oprofile_add_data(struct op_entry *entry, unsigned long val);
51563a0e 188int oprofile_add_data64(struct op_entry *entry, u64 val);
14f0ca8e
RR
189int oprofile_write_commit(struct op_entry *entry);
190
1ea1bdf7 191#ifdef CONFIG_HW_PERF_EVENTS
3d90a007 192int __init oprofile_perf_init(struct oprofile_operations *ops);
b3b3a9b6 193void oprofile_perf_exit(void);
56946331 194char *op_name_from_perf_id(void);
d14dd7e2
AK
195#else
196static inline int __init oprofile_perf_init(struct oprofile_operations *ops)
197{
198 pr_info("oprofile: hardware counters not available\n");
199 return -ENODEV;
200}
201static inline void oprofile_perf_exit(void) { }
1ea1bdf7 202#endif /* CONFIG_HW_PERF_EVENTS */
56946331 203
1da177e4 204#endif /* OPROFILE_H */