blob: 65b763ad72da363f11a428080465df167dfe16b5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
2 * @file cpu_buffer.h
3 *
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
6 *
7 * @author John Levon <levon@movementarian.org>
8 */
9
10#ifndef OPROFILE_CPU_BUFFER_H
11#define OPROFILE_CPU_BUFFER_H
12
13#include <linux/types.h>
14#include <linux/spinlock.h>
15#include <linux/workqueue.h>
16#include <linux/cache.h>
Mike Travis608dfdd2008-04-28 02:14:15 -070017#include <linux/sched.h>
Robert Richter6dad8282008-12-09 01:21:32 +010018#include <linux/ring_buffer.h>
Robert Richter6a180372008-10-16 15:01:40 +020019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020struct task_struct;
Robert Richter6a180372008-10-16 15:01:40 +020021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022int alloc_cpu_buffers(void);
23void free_cpu_buffers(void);
24
25void start_cpu_work(void);
26void end_cpu_work(void);
27
28/* CPU buffer is composed of such entries (which are
29 * also used for context switch notes)
30 */
31struct op_sample {
32 unsigned long eip;
33 unsigned long event;
34};
Robert Richter6a180372008-10-16 15:01:40 +020035
Robert Richter6dad8282008-12-09 01:21:32 +010036struct op_entry {
37 struct ring_buffer_event *event;
38 struct op_sample *sample;
39 unsigned long irq_flags;
40};
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042struct oprofile_cpu_buffer {
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 unsigned long buffer_size;
Robert Richter25ad2912008-09-05 17:12:36 +020044 struct task_struct *last_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 int last_is_kernel;
46 int tracing;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 unsigned long sample_received;
48 unsigned long sample_lost_overflow;
49 unsigned long backtrace_aborted;
Philippe Eliedf9d1772007-11-14 16:58:48 -080050 unsigned long sample_invalid_eip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 int cpu;
David Howellsc4028952006-11-22 14:57:56 +000052 struct delayed_work work;
Eric Dumazet8b8b4982008-05-14 16:05:31 -070053};
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Mike Travis608dfdd2008-04-28 02:14:15 -070055DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Robert Richterfbc9bf92008-12-04 16:27:00 +010057/*
58 * Resets the cpu buffer to a sane state.
59 *
60 * reset these to invalid values; the next sample collected will
61 * populate the buffer with proper values to initialize the buffer
62 */
Robert Richter6d2c53f2008-12-24 16:53:53 +010063static inline void op_cpu_buffer_reset(int cpu)
Robert Richterfbc9bf92008-12-04 16:27:00 +010064{
65 struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu);
66
67 cpu_buf->last_is_kernel = -1;
68 cpu_buf->last_task = NULL;
69}
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Robert Richter99667182008-12-16 16:19:54 +010071int op_cpu_buffer_write_entry(struct op_entry *entry);
72int op_cpu_buffer_write_commit(struct op_entry *entry);
73struct op_sample *op_cpu_buffer_read_entry(int cpu);
74unsigned long op_cpu_buffer_entries(int cpu);
Robert Richterbf589e32008-11-27 22:33:37 +010075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076/* transient events for the CPU buffer -> event buffer */
77#define CPU_IS_KERNEL 1
78#define CPU_TRACE_BEGIN 2
Barry Kasindorf345c2572008-07-22 21:08:54 +020079#define IBS_FETCH_BEGIN 3
80#define IBS_OP_BEGIN 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82#endif /* OPROFILE_CPU_BUFFER_H */