blob: d7c0545ef8b26e4426de9ab2970a6a978a326dd4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
2 * @file cpu_buffer.h
3 *
Robert Richter2cc28b92008-12-25 17:26:07 +01004 * @remark Copyright 2002-2009 OProfile authors
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * @remark Read the file COPYING
6 *
7 * @author John Levon <levon@movementarian.org>
Robert Richter2cc28b92008-12-25 17:26:07 +01008 * @author Robert Richter <robert.richter@amd.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
11#ifndef OPROFILE_CPU_BUFFER_H
12#define OPROFILE_CPU_BUFFER_H
13
14#include <linux/types.h>
15#include <linux/spinlock.h>
16#include <linux/workqueue.h>
17#include <linux/cache.h>
Mike Travis608dfdd2008-04-28 02:14:15 -070018#include <linux/sched.h>
Robert Richter6dad8282008-12-09 01:21:32 +010019#include <linux/ring_buffer.h>
Robert Richter6a180372008-10-16 15:01:40 +020020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021struct task_struct;
Robert Richter6a180372008-10-16 15:01:40 +020022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023int alloc_cpu_buffers(void);
24void free_cpu_buffers(void);
25
26void start_cpu_work(void);
27void end_cpu_work(void);
28
29/* CPU buffer is composed of such entries (which are
30 * also used for context switch notes)
31 */
32struct op_sample {
33 unsigned long eip;
34 unsigned long event;
Robert Richter2cc28b92008-12-25 17:26:07 +010035 unsigned long data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -070036};
Robert Richter6a180372008-10-16 15:01:40 +020037
Robert Richter6dad8282008-12-09 01:21:32 +010038struct op_entry {
39 struct ring_buffer_event *event;
40 struct op_sample *sample;
41 unsigned long irq_flags;
Robert Richter2cc28b92008-12-25 17:26:07 +010042 unsigned long size;
43 unsigned long *data;
Robert Richter6dad8282008-12-09 01:21:32 +010044};
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046struct oprofile_cpu_buffer {
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 unsigned long buffer_size;
Robert Richter25ad2912008-09-05 17:12:36 +020048 struct task_struct *last_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 int last_is_kernel;
50 int tracing;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 unsigned long sample_received;
52 unsigned long sample_lost_overflow;
53 unsigned long backtrace_aborted;
Philippe Eliedf9d1772007-11-14 16:58:48 -080054 unsigned long sample_invalid_eip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 int cpu;
David Howellsc4028952006-11-22 14:57:56 +000056 struct delayed_work work;
Eric Dumazet8b8b4982008-05-14 16:05:31 -070057};
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Mike Travis608dfdd2008-04-28 02:14:15 -070059DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Robert Richterfbc9bf92008-12-04 16:27:00 +010061/*
62 * Resets the cpu buffer to a sane state.
63 *
64 * reset these to invalid values; the next sample collected will
65 * populate the buffer with proper values to initialize the buffer
66 */
Robert Richter6d2c53f2008-12-24 16:53:53 +010067static inline void op_cpu_buffer_reset(int cpu)
Robert Richterfbc9bf92008-12-04 16:27:00 +010068{
69 struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu);
70
71 cpu_buf->last_is_kernel = -1;
72 cpu_buf->last_task = NULL;
73}
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Robert Richter2cc28b92008-12-25 17:26:07 +010075struct op_sample
76*op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size);
Robert Richter99667182008-12-16 16:19:54 +010077int op_cpu_buffer_write_commit(struct op_entry *entry);
Robert Richter2d87b142008-12-30 04:10:46 +010078struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu);
Robert Richter99667182008-12-16 16:19:54 +010079unsigned long op_cpu_buffer_entries(int cpu);
Robert Richterbf589e32008-11-27 22:33:37 +010080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081/* transient events for the CPU buffer -> event buffer */
82#define CPU_IS_KERNEL 1
83#define CPU_TRACE_BEGIN 2
Barry Kasindorf345c2572008-07-22 21:08:54 +020084#define IBS_FETCH_BEGIN 3
85#define IBS_OP_BEGIN 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87#endif /* OPROFILE_CPU_BUFFER_H */