Linux Perf
auxtrace.c
Go to the documentation of this file.
1 #include <stdbool.h>
2 #include <linux/kernel.h>
3 #include <linux/types.h>
4 #include <linux/bitops.h>
5 #include <linux/log2.h>
6 
7 #include "../../util/evlist.h"
8 #include "../../util/auxtrace.h"
9 #include "../../util/evsel.h"
10 
11 #define PERF_EVENT_CPUM_SF 0xB0000 /* Event: Basic-sampling */
12 #define PERF_EVENT_CPUM_SF_DIAG 0xBD000 /* Event: Combined-sampling */
13 #define DEFAULT_AUX_PAGES 128
14 #define DEFAULT_FREQ 4000
15 
16 static void cpumsf_free(struct auxtrace_record *itr)
17 {
18  free(itr);
19 }
20 
21 static size_t cpumsf_info_priv_size(struct auxtrace_record *itr __maybe_unused,
22  struct perf_evlist *evlist __maybe_unused)
23 {
24  return 0;
25 }
26 
27 static int
28 cpumsf_info_fill(struct auxtrace_record *itr __maybe_unused,
29  struct perf_session *session __maybe_unused,
30  struct auxtrace_info_event *auxtrace_info __maybe_unused,
31  size_t priv_size __maybe_unused)
32 {
33  return 0;
34 }
35 
36 static unsigned long
37 cpumsf_reference(struct auxtrace_record *itr __maybe_unused)
38 {
39  return 0;
40 }
41 
42 static int
43 cpumsf_recording_options(struct auxtrace_record *ar __maybe_unused,
44  struct perf_evlist *evlist __maybe_unused,
45  struct record_opts *opts)
46 {
47  unsigned int factor = 1;
48  unsigned int pages;
49 
50  opts->full_auxtrace = true;
51 
52  /*
53  * The AUX buffer size should be set properly to avoid
54  * overflow of samples if it is not set explicitly.
55  * DEFAULT_AUX_PAGES is an proper size when sampling frequency
56  * is DEFAULT_FREQ. It is expected to hold about 1/2 second
57  * of sampling data. The size used for AUX buffer will scale
58  * according to the specified frequency and DEFAULT_FREQ.
59  */
60  if (!opts->auxtrace_mmap_pages) {
61  if (opts->user_freq != UINT_MAX)
62  factor = (opts->user_freq + DEFAULT_FREQ
63  - 1) / DEFAULT_FREQ;
64  pages = DEFAULT_AUX_PAGES * factor;
65  opts->auxtrace_mmap_pages = roundup_pow_of_two(pages);
66  }
67 
68  return 0;
69 }
70 
71 static int
73  struct record_opts *opts __maybe_unused,
74  const char *str __maybe_unused)
75 {
76  return 0;
77 }
78 
79 /*
80  * auxtrace_record__init is called when perf record
81  * check if the event really need auxtrace
82  */
84  int *err)
85 {
86  struct auxtrace_record *aux;
87  struct perf_evsel *pos;
88  int diagnose = 0;
89 
90  *err = 0;
91  if (evlist->nr_entries == 0)
92  return NULL;
93 
94  evlist__for_each_entry(evlist, pos) {
95  if (pos->attr.config == PERF_EVENT_CPUM_SF_DIAG) {
96  diagnose = 1;
97  break;
98  }
99  }
100 
101  if (!diagnose)
102  return NULL;
103 
104  /* sampling in diagnose mode. alloc aux buffer */
105  aux = zalloc(sizeof(*aux));
106  if (aux == NULL) {
107  *err = -ENOMEM;
108  return NULL;
109  }
110 
115  aux->free = cpumsf_free;
117 
118  return aux;
119 }
struct auxtrace_record * auxtrace_record__init(struct perf_evlist *evlist, int *err)
Definition: auxtrace.c:52
static void cpumsf_free(struct auxtrace_record *itr)
Definition: auxtrace.c:16
static int cpumsf_info_fill(struct auxtrace_record *itr __maybe_unused, struct perf_session *session __maybe_unused, struct auxtrace_info_event *auxtrace_info __maybe_unused, size_t priv_size __maybe_unused)
Definition: auxtrace.c:28
static unsigned long cpumsf_reference(struct auxtrace_record *itr __maybe_unused)
Definition: auxtrace.c:37
bool full_auxtrace
Definition: perf.h:55
int int err
Definition: 5sec.c:44
size_t(* info_priv_size)(struct auxtrace_record *itr, struct perf_evlist *evlist)
Definition: auxtrace.h:311
int nr_entries
Definition: evlist.h:30
static int cpumsf_recording_options(struct auxtrace_record *ar __maybe_unused, struct perf_evlist *evlist __maybe_unused, struct record_opts *opts)
Definition: auxtrace.c:43
unsigned int user_freq
Definition: perf.h:69
u64(* reference)(struct auxtrace_record *itr)
Definition: auxtrace.h:326
#define DEFAULT_AUX_PAGES
Definition: auxtrace.c:13
static struct perf_session * session
Definition: builtin-lock.c:34
#define evlist__for_each_entry(evlist, evsel)
Definition: evlist.h:247
void(* free)(struct auxtrace_record *itr)
Definition: auxtrace.h:317
int(* recording_options)(struct auxtrace_record *itr, struct perf_evlist *evlist, struct record_opts *opts)
Definition: auxtrace.h:308
static int str(yyscan_t scanner, int token)
static int cpumsf_parse_snapshot_options(struct auxtrace_record *itr __maybe_unused, struct record_opts *opts __maybe_unused, const char *str __maybe_unused)
Definition: auxtrace.c:72
static size_t cpumsf_info_priv_size(struct auxtrace_record *itr __maybe_unused, struct perf_evlist *evlist __maybe_unused)
Definition: auxtrace.c:21
int(* parse_snapshot_options)(struct auxtrace_record *itr, struct record_opts *opts, const char *str)
Definition: auxtrace.h:323
#define PERF_EVENT_CPUM_SF_DIAG
Definition: auxtrace.c:12
void free(void *)
#define DEFAULT_FREQ
Definition: auxtrace.c:14
unsigned int auxtrace_mmap_pages
Definition: perf.h:68
int(* info_fill)(struct auxtrace_record *itr, struct perf_session *session, struct auxtrace_info_event *auxtrace_info, size_t priv_size)
Definition: auxtrace.h:313
struct perf_event_attr attr
Definition: evsel.h:93
void static void * zalloc(size_t size)
Definition: util.h:20