Blame view

drivers/oprofile/cpu_buffer.h 2.84 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
  /**
   * @file cpu_buffer.h
   *
2cc28b9f2   Robert Richter   oprofile: add op_...
4
   * @remark Copyright 2002-2009 OProfile authors
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
7
   * @remark Read the file COPYING
   *
   * @author John Levon <levon@movementarian.org>
2cc28b9f2   Robert Richter   oprofile: add op_...
8
   * @author Robert Richter <robert.richter@amd.com>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
10
11
12
13
14
15
16
17
   */
  
  #ifndef OPROFILE_CPU_BUFFER_H
  #define OPROFILE_CPU_BUFFER_H
  
  #include <linux/types.h>
  #include <linux/spinlock.h>
  #include <linux/workqueue.h>
  #include <linux/cache.h>
608dfddd8   Mike Travis   oprofile: change ...
18
  #include <linux/sched.h>
6dad828b7   Robert Richter   oprofile: port to...
19
  #include <linux/ring_buffer.h>
6a18037d4   Robert Richter   oprofile: fixing ...
20

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  struct task_struct;
6a18037d4   Robert Richter   oprofile: fixing ...
22

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
25
26
27
  int alloc_cpu_buffers(void);
  void free_cpu_buffers(void);
  
  void start_cpu_work(void);
  void end_cpu_work(void);
3d7851b3c   Tejun Heo   oprofile: Remove ...
28
  void flush_cpu_work(void);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
32
33
34
35
  
  /* CPU buffer is composed of such entries (which are
   * also used for context switch notes)
   */
  struct op_sample {
  	unsigned long eip;
  	unsigned long event;
2cc28b9f2   Robert Richter   oprofile: add op_...
36
  	unsigned long data[0];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
  };
6a18037d4   Robert Richter   oprofile: fixing ...
38

14f0ca8ea   Robert Richter   oprofile: make ne...
39
  struct op_entry;
6dad828b7   Robert Richter   oprofile: port to...
40

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
  struct oprofile_cpu_buffer {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
  	unsigned long buffer_size;
25ad2913c   Robert Richter   oprofile: more wh...
43
  	struct task_struct *last_task;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
  	int last_is_kernel;
  	int tracing;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
  	unsigned long sample_received;
  	unsigned long sample_lost_overflow;
  	unsigned long backtrace_aborted;
df9d177aa   Philippe Elie   oProfile: oops wh...
49
  	unsigned long sample_invalid_eip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
  	int cpu;
c4028958b   David Howells   WorkStruct: make ...
51
  	struct delayed_work work;
8b8b49883   Eric Dumazet   oprofile: don't r...
52
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53

b3e9f672b   Tejun Heo   percpu: make perc...
54
  DECLARE_PER_CPU(struct oprofile_cpu_buffer, op_cpu_buffer);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55

fbc9bf9f0   Robert Richter   oprofile: moving ...
56
57
58
59
60
61
  /*
   * Resets the cpu buffer to a sane state.
   *
   * reset these to invalid values; the next sample collected will
   * populate the buffer with proper values to initialize the buffer
   */
6d2c53f3c   Robert Richter   oprofile: rename ...
62
  static inline void op_cpu_buffer_reset(int cpu)
fbc9bf9f0   Robert Richter   oprofile: moving ...
63
  {
b3e9f672b   Tejun Heo   percpu: make perc...
64
  	struct oprofile_cpu_buffer *cpu_buf = &per_cpu(op_cpu_buffer, cpu);
fbc9bf9f0   Robert Richter   oprofile: moving ...
65
66
67
68
  
  	cpu_buf->last_is_kernel = -1;
  	cpu_buf->last_task = NULL;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69

fdb6a8f4d   Robert Richter   oprofile: fix uni...
70
71
72
73
74
75
  /*
   * op_cpu_buffer_add_data() and op_cpu_buffer_write_commit() may be
   * called only if op_cpu_buffer_write_reserve() did not return NULL or
   * entry->event != NULL, otherwise entry->size or entry->event will be
   * used uninitialized.
   */
2cc28b9f2   Robert Richter   oprofile: add op_...
76
77
  struct op_sample
  *op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size);
9966718da   Robert Richter   oprofile: remove ...
78
  int op_cpu_buffer_write_commit(struct op_entry *entry);
2d87b14cf   Robert Richter   oprofile: modify ...
79
  struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu);
9966718da   Robert Richter   oprofile: remove ...
80
  unsigned long op_cpu_buffer_entries(int cpu);
bf589e329   Robert Richter   oprofile: adding ...
81

d9928c25a   Robert Richter   oprofile: add op_...
82
83
84
85
86
87
88
89
90
91
92
  /* returns the remaining free size of data in the entry */
  static inline
  int op_cpu_buffer_add_data(struct op_entry *entry, unsigned long val)
  {
  	if (!entry->size)
  		return 0;
  	*entry->data = val;
  	entry->size--;
  	entry->data++;
  	return entry->size;
  }
bd7dc46f7   Robert Richter   oprofile: add op_...
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  /* returns the size of data in the entry */
  static inline
  int op_cpu_buffer_get_size(struct op_entry *entry)
  {
  	return entry->size;
  }
  
  /* returns 0 if empty or the size of data including the current value */
  static inline
  int op_cpu_buffer_get_data(struct op_entry *entry, unsigned long *val)
  {
  	int size = entry->size;
  	if (!size)
  		return 0;
  	*val = *entry->data;
  	entry->size--;
  	entry->data++;
  	return size;
  }
ae735e996   Robert Richter   oprofile: rework ...
112
113
114
115
116
  /* extra data flags */
  #define KERNEL_CTX_SWITCH	(1UL << 0)
  #define IS_KERNEL		(1UL << 1)
  #define TRACE_BEGIN		(1UL << 2)
  #define USER_CTX_SWITCH		(1UL << 3)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
118
  
  #endif /* OPROFILE_CPU_BUFFER_H */