hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/tools/perf/util/evsel.c
....@@ -1,10 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
34 *
45 * Parts came from builtin-{top,stat,record}.c, see those files for further
56 * copyright notes.
6
- *
7
- * Released under the GPL v2. (and only v2, not any later version)
87 */
98
109 #include <byteswap.h>
....@@ -18,57 +17,68 @@
1817 #include <linux/perf_event.h>
1918 #include <linux/compiler.h>
2019 #include <linux/err.h>
20
+#include <linux/zalloc.h>
2121 #include <sys/ioctl.h>
2222 #include <sys/resource.h>
2323 #include <sys/types.h>
2424 #include <dirent.h>
25
+#include <stdlib.h>
26
+#include <perf/evsel.h>
2527 #include "asm/bug.h"
2628 #include "callchain.h"
2729 #include "cgroup.h"
30
+#include "counts.h"
2831 #include "event.h"
2932 #include "evsel.h"
33
+#include "util/env.h"
34
+#include "util/evsel_config.h"
35
+#include "util/evsel_fprintf.h"
3036 #include "evlist.h"
31
-#include "util.h"
32
-#include "cpumap.h"
37
+#include <perf/cpumap.h>
3338 #include "thread_map.h"
3439 #include "target.h"
3540 #include "perf_regs.h"
41
+#include "record.h"
3642 #include "debug.h"
3743 #include "trace-event.h"
3844 #include "stat.h"
45
+#include "string2.h"
3946 #include "memswap.h"
47
+#include "util.h"
48
+#include "../perf-sys.h"
4049 #include "util/parse-branch-options.h"
50
+#include <internal/xyarray.h>
51
+#include <internal/lib.h>
4152
42
-#include "sane_ctype.h"
53
+#include <linux/ctype.h>
4354
4455 struct perf_missing_features perf_missing_features;
4556
4657 static clockid_t clockid;
4758
48
-static int perf_evsel__no_extra_init(struct perf_evsel *evsel __maybe_unused)
59
+static int evsel__no_extra_init(struct evsel *evsel __maybe_unused)
4960 {
5061 return 0;
5162 }
5263
5364 void __weak test_attr__ready(void) { }
5465
55
-static void perf_evsel__no_extra_fini(struct perf_evsel *evsel __maybe_unused)
66
+static void evsel__no_extra_fini(struct evsel *evsel __maybe_unused)
5667 {
5768 }
5869
5970 static struct {
6071 size_t size;
61
- int (*init)(struct perf_evsel *evsel);
62
- void (*fini)(struct perf_evsel *evsel);
72
+ int (*init)(struct evsel *evsel);
73
+ void (*fini)(struct evsel *evsel);
6374 } perf_evsel__object = {
64
- .size = sizeof(struct perf_evsel),
65
- .init = perf_evsel__no_extra_init,
66
- .fini = perf_evsel__no_extra_fini,
75
+ .size = sizeof(struct evsel),
76
+ .init = evsel__no_extra_init,
77
+ .fini = evsel__no_extra_fini,
6778 };
6879
69
-int perf_evsel__object_config(size_t object_size,
70
- int (*init)(struct perf_evsel *evsel),
71
- void (*fini)(struct perf_evsel *evsel))
80
+int evsel__object_config(size_t object_size, int (*init)(struct evsel *evsel),
81
+ void (*fini)(struct evsel *evsel))
7282 {
7383
7484 if (object_size == 0)
....@@ -89,9 +99,9 @@
8999 return 0;
90100 }
91101
92
-#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
102
+#define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))
93103
94
-int __perf_evsel__sample_size(u64 sample_type)
104
+int __evsel__sample_size(u64 sample_type)
95105 {
96106 u64 mask = sample_type & PERF_SAMPLE_MASK;
97107 int size = 0;
....@@ -113,7 +123,7 @@
113123 *
114124 * This function returns the position of the event id (PERF_SAMPLE_ID or
115125 * PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of struct
116
- * sample_event.
126
+ * perf_record_sample.
117127 */
118128 static int __perf_evsel__calc_id_pos(u64 sample_type)
119129 {
....@@ -167,53 +177,53 @@
167177 return idx;
168178 }
169179
170
-void perf_evsel__calc_id_pos(struct perf_evsel *evsel)
180
+void evsel__calc_id_pos(struct evsel *evsel)
171181 {
172
- evsel->id_pos = __perf_evsel__calc_id_pos(evsel->attr.sample_type);
173
- evsel->is_pos = __perf_evsel__calc_is_pos(evsel->attr.sample_type);
182
+ evsel->id_pos = __perf_evsel__calc_id_pos(evsel->core.attr.sample_type);
183
+ evsel->is_pos = __perf_evsel__calc_is_pos(evsel->core.attr.sample_type);
174184 }
175185
176
-void __perf_evsel__set_sample_bit(struct perf_evsel *evsel,
186
+void __evsel__set_sample_bit(struct evsel *evsel,
177187 enum perf_event_sample_format bit)
178188 {
179
- if (!(evsel->attr.sample_type & bit)) {
180
- evsel->attr.sample_type |= bit;
189
+ if (!(evsel->core.attr.sample_type & bit)) {
190
+ evsel->core.attr.sample_type |= bit;
181191 evsel->sample_size += sizeof(u64);
182
- perf_evsel__calc_id_pos(evsel);
192
+ evsel__calc_id_pos(evsel);
183193 }
184194 }
185195
186
-void __perf_evsel__reset_sample_bit(struct perf_evsel *evsel,
196
+void __evsel__reset_sample_bit(struct evsel *evsel,
187197 enum perf_event_sample_format bit)
188198 {
189
- if (evsel->attr.sample_type & bit) {
190
- evsel->attr.sample_type &= ~bit;
199
+ if (evsel->core.attr.sample_type & bit) {
200
+ evsel->core.attr.sample_type &= ~bit;
191201 evsel->sample_size -= sizeof(u64);
192
- perf_evsel__calc_id_pos(evsel);
202
+ evsel__calc_id_pos(evsel);
193203 }
194204 }
195205
196
-void perf_evsel__set_sample_id(struct perf_evsel *evsel,
206
+void evsel__set_sample_id(struct evsel *evsel,
197207 bool can_sample_identifier)
198208 {
199209 if (can_sample_identifier) {
200
- perf_evsel__reset_sample_bit(evsel, ID);
201
- perf_evsel__set_sample_bit(evsel, IDENTIFIER);
210
+ evsel__reset_sample_bit(evsel, ID);
211
+ evsel__set_sample_bit(evsel, IDENTIFIER);
202212 } else {
203
- perf_evsel__set_sample_bit(evsel, ID);
213
+ evsel__set_sample_bit(evsel, ID);
204214 }
205
- evsel->attr.read_format |= PERF_FORMAT_ID;
215
+ evsel->core.attr.read_format |= PERF_FORMAT_ID;
206216 }
207217
208218 /**
209
- * perf_evsel__is_function_event - Return whether given evsel is a function
219
+ * evsel__is_function_event - Return whether given evsel is a function
210220 * trace event
211221 *
212222 * @evsel - evsel selector to be tested
213223 *
214224 * Return %true if event is function trace event
215225 */
216
-bool perf_evsel__is_function_event(struct perf_evsel *evsel)
226
+bool evsel__is_function_event(struct evsel *evsel)
217227 {
218228 #define FUNCTION_EVENT "ftrace:function"
219229
....@@ -223,45 +233,47 @@
223233 #undef FUNCTION_EVENT
224234 }
225235
226
-void perf_evsel__init(struct perf_evsel *evsel,
227
- struct perf_event_attr *attr, int idx)
236
+void evsel__init(struct evsel *evsel,
237
+ struct perf_event_attr *attr, int idx)
228238 {
239
+ perf_evsel__init(&evsel->core, attr);
229240 evsel->idx = idx;
230241 evsel->tracking = !idx;
231
- evsel->attr = *attr;
232242 evsel->leader = evsel;
233243 evsel->unit = "";
234244 evsel->scale = 1.0;
245
+ evsel->max_events = ULONG_MAX;
235246 evsel->evlist = NULL;
247
+ evsel->bpf_obj = NULL;
236248 evsel->bpf_fd = -1;
237
- INIT_LIST_HEAD(&evsel->node);
238249 INIT_LIST_HEAD(&evsel->config_terms);
239250 perf_evsel__object.init(evsel);
240
- evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
241
- perf_evsel__calc_id_pos(evsel);
251
+ evsel->sample_size = __evsel__sample_size(attr->sample_type);
252
+ evsel__calc_id_pos(evsel);
242253 evsel->cmdline_group_boundary = false;
243254 evsel->metric_expr = NULL;
244255 evsel->metric_name = NULL;
245256 evsel->metric_events = NULL;
257
+ evsel->per_pkg_mask = NULL;
246258 evsel->collect_stat = false;
247259 evsel->pmu_name = NULL;
248260 }
249261
250
-struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
262
+struct evsel *evsel__new_idx(struct perf_event_attr *attr, int idx)
251263 {
252
- struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
264
+ struct evsel *evsel = zalloc(perf_evsel__object.size);
253265
254266 if (!evsel)
255267 return NULL;
256
- perf_evsel__init(evsel, attr, idx);
268
+ evsel__init(evsel, attr, idx);
257269
258
- if (perf_evsel__is_bpf_output(evsel)) {
259
- evsel->attr.sample_type |= (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
270
+ if (evsel__is_bpf_output(evsel)) {
271
+ evsel->core.attr.sample_type |= (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
260272 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD),
261
- evsel->attr.sample_period = 1;
273
+ evsel->core.attr.sample_period = 1;
262274 }
263275
264
- if (perf_evsel__is_clock(evsel)) {
276
+ if (evsel__is_clock(evsel)) {
265277 /*
266278 * The evsel->unit points to static alias->unit
267279 * so it's ok to use static string in here.
....@@ -277,40 +289,33 @@
277289
278290 static bool perf_event_can_profile_kernel(void)
279291 {
280
- return geteuid() == 0 || perf_event_paranoid() == -1;
292
+ return perf_event_paranoid_check(1);
281293 }
282294
283
-struct perf_evsel *perf_evsel__new_cycles(bool precise)
295
+struct evsel *evsel__new_cycles(bool precise)
284296 {
285297 struct perf_event_attr attr = {
286298 .type = PERF_TYPE_HARDWARE,
287299 .config = PERF_COUNT_HW_CPU_CYCLES,
288300 .exclude_kernel = !perf_event_can_profile_kernel(),
289301 };
290
- struct perf_evsel *evsel;
302
+ struct evsel *evsel;
291303
292304 event_attr_init(&attr);
293305
294306 if (!precise)
295307 goto new_event;
296
- /*
297
- * Unnamed union member, not supported as struct member named
298
- * initializer in older compilers such as gcc 4.4.7
299
- *
300
- * Just for probing the precise_ip:
301
- */
302
- attr.sample_period = 1;
303308
304
- perf_event_attr__set_max_precise_ip(&attr);
305309 /*
306310 * Now let the usual logic to set up the perf_event_attr defaults
307311 * to kick in when we return and before perf_evsel__open() is called.
308312 */
309
- attr.sample_period = 0;
310313 new_event:
311
- evsel = perf_evsel__new(&attr);
314
+ evsel = evsel__new(&attr);
312315 if (evsel == NULL)
313316 goto out;
317
+
318
+ evsel->precise_max = true;
314319
315320 /* use asprintf() because free(evsel) assumes name is allocated */
316321 if (asprintf(&evsel->name, "cycles%s%s%.*s",
....@@ -321,17 +326,121 @@
321326 out:
322327 return evsel;
323328 error_free:
324
- perf_evsel__delete(evsel);
329
+ evsel__delete(evsel);
325330 evsel = NULL;
326331 goto out;
332
+}
333
+
334
+static int evsel__copy_config_terms(struct evsel *dst, struct evsel *src)
335
+{
336
+ struct evsel_config_term *pos, *tmp;
337
+
338
+ list_for_each_entry(pos, &src->config_terms, list) {
339
+ tmp = malloc(sizeof(*tmp));
340
+ if (tmp == NULL)
341
+ return -ENOMEM;
342
+
343
+ *tmp = *pos;
344
+ if (tmp->free_str) {
345
+ tmp->val.str = strdup(pos->val.str);
346
+ if (tmp->val.str == NULL) {
347
+ free(tmp);
348
+ return -ENOMEM;
349
+ }
350
+ }
351
+ list_add_tail(&tmp->list, &dst->config_terms);
352
+ }
353
+ return 0;
354
+}
355
+
356
+/**
357
+ * evsel__clone - create a new evsel copied from @orig
358
+ * @orig: original evsel
359
+ *
360
+ * The assumption is that @orig is not configured nor opened yet.
361
+ * So we only care about the attributes that can be set while it's parsed.
362
+ */
363
+struct evsel *evsel__clone(struct evsel *orig)
364
+{
365
+ struct evsel *evsel;
366
+
367
+ BUG_ON(orig->core.fd);
368
+ BUG_ON(orig->counts);
369
+ BUG_ON(orig->priv);
370
+ BUG_ON(orig->per_pkg_mask);
371
+
372
+ /* cannot handle BPF objects for now */
373
+ if (orig->bpf_obj)
374
+ return NULL;
375
+
376
+ evsel = evsel__new(&orig->core.attr);
377
+ if (evsel == NULL)
378
+ return NULL;
379
+
380
+ evsel->core.cpus = perf_cpu_map__get(orig->core.cpus);
381
+ evsel->core.own_cpus = perf_cpu_map__get(orig->core.own_cpus);
382
+ evsel->core.threads = perf_thread_map__get(orig->core.threads);
383
+ evsel->core.nr_members = orig->core.nr_members;
384
+ evsel->core.system_wide = orig->core.system_wide;
385
+
386
+ if (orig->name) {
387
+ evsel->name = strdup(orig->name);
388
+ if (evsel->name == NULL)
389
+ goto out_err;
390
+ }
391
+ if (orig->group_name) {
392
+ evsel->group_name = strdup(orig->group_name);
393
+ if (evsel->group_name == NULL)
394
+ goto out_err;
395
+ }
396
+ if (orig->pmu_name) {
397
+ evsel->pmu_name = strdup(orig->pmu_name);
398
+ if (evsel->pmu_name == NULL)
399
+ goto out_err;
400
+ }
401
+ if (orig->filter) {
402
+ evsel->filter = strdup(orig->filter);
403
+ if (evsel->filter == NULL)
404
+ goto out_err;
405
+ }
406
+ evsel->cgrp = cgroup__get(orig->cgrp);
407
+ evsel->tp_format = orig->tp_format;
408
+ evsel->handler = orig->handler;
409
+ evsel->leader = orig->leader;
410
+
411
+ evsel->max_events = orig->max_events;
412
+ evsel->tool_event = orig->tool_event;
413
+ evsel->unit = orig->unit;
414
+ evsel->scale = orig->scale;
415
+ evsel->snapshot = orig->snapshot;
416
+ evsel->per_pkg = orig->per_pkg;
417
+ evsel->percore = orig->percore;
418
+ evsel->precise_max = orig->precise_max;
419
+ evsel->use_uncore_alias = orig->use_uncore_alias;
420
+ evsel->is_libpfm_event = orig->is_libpfm_event;
421
+
422
+ evsel->exclude_GH = orig->exclude_GH;
423
+ evsel->sample_read = orig->sample_read;
424
+ evsel->auto_merge_stats = orig->auto_merge_stats;
425
+ evsel->collect_stat = orig->collect_stat;
426
+ evsel->weak_group = orig->weak_group;
427
+
428
+ if (evsel__copy_config_terms(evsel, orig) < 0)
429
+ goto out_err;
430
+
431
+ return evsel;
432
+
433
+out_err:
434
+ evsel__delete(evsel);
435
+ return NULL;
327436 }
328437
329438 /*
330439 * Returns pointer with encoded error via <linux/err.h> interface.
331440 */
332
-struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx)
441
+struct evsel *evsel__newtp_idx(const char *sys, const char *name, int idx)
333442 {
334
- struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
443
+ struct evsel *evsel = zalloc(perf_evsel__object.size);
335444 int err = -ENOMEM;
336445
337446 if (evsel == NULL) {
....@@ -355,7 +464,7 @@
355464 event_attr_init(&attr);
356465 attr.config = evsel->tp_format->id;
357466 attr.sample_period = 1;
358
- perf_evsel__init(evsel, &attr, idx);
467
+ evsel__init(evsel, &attr, idx);
359468 }
360469
361470 return evsel;
....@@ -367,7 +476,7 @@
367476 return ERR_PTR(err);
368477 }
369478
370
-const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = {
479
+const char *evsel__hw_names[PERF_COUNT_HW_MAX] = {
371480 "cycles",
372481 "instructions",
373482 "cache-references",
....@@ -380,18 +489,18 @@
380489 "ref-cycles",
381490 };
382491
383
-static const char *__perf_evsel__hw_name(u64 config)
492
+static const char *__evsel__hw_name(u64 config)
384493 {
385
- if (config < PERF_COUNT_HW_MAX && perf_evsel__hw_names[config])
386
- return perf_evsel__hw_names[config];
494
+ if (config < PERF_COUNT_HW_MAX && evsel__hw_names[config])
495
+ return evsel__hw_names[config];
387496
388497 return "unknown-hardware";
389498 }
390499
391
-static int perf_evsel__add_modifiers(struct perf_evsel *evsel, char *bf, size_t size)
500
+static int perf_evsel__add_modifiers(struct evsel *evsel, char *bf, size_t size)
392501 {
393502 int colon = 0, r = 0;
394
- struct perf_event_attr *attr = &evsel->attr;
503
+ struct perf_event_attr *attr = &evsel->core.attr;
395504 bool exclude_guest_default = false;
396505
397506 #define MOD_PRINT(context, mod) do { \
....@@ -424,13 +533,13 @@
424533 return r;
425534 }
426535
427
-static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size)
536
+static int evsel__hw_name(struct evsel *evsel, char *bf, size_t size)
428537 {
429
- int r = scnprintf(bf, size, "%s", __perf_evsel__hw_name(evsel->attr.config));
538
+ int r = scnprintf(bf, size, "%s", __evsel__hw_name(evsel->core.attr.config));
430539 return r + perf_evsel__add_modifiers(evsel, bf + r, size - r);
431540 }
432541
433
-const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX] = {
542
+const char *evsel__sw_names[PERF_COUNT_SW_MAX] = {
434543 "cpu-clock",
435544 "task-clock",
436545 "page-faults",
....@@ -443,20 +552,20 @@
443552 "dummy",
444553 };
445554
446
-static const char *__perf_evsel__sw_name(u64 config)
555
+static const char *__evsel__sw_name(u64 config)
447556 {
448
- if (config < PERF_COUNT_SW_MAX && perf_evsel__sw_names[config])
449
- return perf_evsel__sw_names[config];
557
+ if (config < PERF_COUNT_SW_MAX && evsel__sw_names[config])
558
+ return evsel__sw_names[config];
450559 return "unknown-software";
451560 }
452561
453
-static int perf_evsel__sw_name(struct perf_evsel *evsel, char *bf, size_t size)
562
+static int evsel__sw_name(struct evsel *evsel, char *bf, size_t size)
454563 {
455
- int r = scnprintf(bf, size, "%s", __perf_evsel__sw_name(evsel->attr.config));
564
+ int r = scnprintf(bf, size, "%s", __evsel__sw_name(evsel->core.attr.config));
456565 return r + perf_evsel__add_modifiers(evsel, bf + r, size - r);
457566 }
458567
459
-static int __perf_evsel__bp_name(char *bf, size_t size, u64 addr, u64 type)
568
+static int __evsel__bp_name(char *bf, size_t size, u64 addr, u64 type)
460569 {
461570 int r;
462571
....@@ -474,15 +583,14 @@
474583 return r;
475584 }
476585
477
-static int perf_evsel__bp_name(struct perf_evsel *evsel, char *bf, size_t size)
586
+static int evsel__bp_name(struct evsel *evsel, char *bf, size_t size)
478587 {
479
- struct perf_event_attr *attr = &evsel->attr;
480
- int r = __perf_evsel__bp_name(bf, size, attr->bp_addr, attr->bp_type);
588
+ struct perf_event_attr *attr = &evsel->core.attr;
589
+ int r = __evsel__bp_name(bf, size, attr->bp_addr, attr->bp_type);
481590 return r + perf_evsel__add_modifiers(evsel, bf + r, size - r);
482591 }
483592
484
-const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX]
485
- [PERF_EVSEL__MAX_ALIASES] = {
593
+const char *evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX][EVSEL__MAX_ALIASES] = {
486594 { "L1-dcache", "l1-d", "l1d", "L1-data", },
487595 { "L1-icache", "l1-i", "l1i", "L1-instruction", },
488596 { "LLC", "L2", },
....@@ -492,15 +600,13 @@
492600 { "node", },
493601 };
494602
495
-const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX]
496
- [PERF_EVSEL__MAX_ALIASES] = {
603
+const char *evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX][EVSEL__MAX_ALIASES] = {
497604 { "load", "loads", "read", },
498605 { "store", "stores", "write", },
499606 { "prefetch", "prefetches", "speculative-read", "speculative-load", },
500607 };
501608
502
-const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX]
503
- [PERF_EVSEL__MAX_ALIASES] = {
609
+const char *evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX][EVSEL__MAX_ALIASES] = {
504610 { "refs", "Reference", "ops", "access", },
505611 { "misses", "miss", },
506612 };
....@@ -516,7 +622,7 @@
516622 * L1I : Read and prefetch only
517623 * ITLB and BPU : Read-only
518624 */
519
-static unsigned long perf_evsel__hw_cache_stat[C(MAX)] = {
625
+static unsigned long evsel__hw_cache_stat[C(MAX)] = {
520626 [C(L1D)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
521627 [C(L1I)] = (CACHE_READ | CACHE_PREFETCH),
522628 [C(LL)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
....@@ -526,28 +632,27 @@
526632 [C(NODE)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
527633 };
528634
529
-bool perf_evsel__is_cache_op_valid(u8 type, u8 op)
635
+bool evsel__is_cache_op_valid(u8 type, u8 op)
530636 {
531
- if (perf_evsel__hw_cache_stat[type] & COP(op))
637
+ if (evsel__hw_cache_stat[type] & COP(op))
532638 return true; /* valid */
533639 else
534640 return false; /* invalid */
535641 }
536642
537
-int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
538
- char *bf, size_t size)
643
+int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size_t size)
539644 {
540645 if (result) {
541
- return scnprintf(bf, size, "%s-%s-%s", perf_evsel__hw_cache[type][0],
542
- perf_evsel__hw_cache_op[op][0],
543
- perf_evsel__hw_cache_result[result][0]);
646
+ return scnprintf(bf, size, "%s-%s-%s", evsel__hw_cache[type][0],
647
+ evsel__hw_cache_op[op][0],
648
+ evsel__hw_cache_result[result][0]);
544649 }
545650
546
- return scnprintf(bf, size, "%s-%s", perf_evsel__hw_cache[type][0],
547
- perf_evsel__hw_cache_op[op][1]);
651
+ return scnprintf(bf, size, "%s-%s", evsel__hw_cache[type][0],
652
+ evsel__hw_cache_op[op][1]);
548653 }
549654
550
-static int __perf_evsel__hw_cache_name(u64 config, char *bf, size_t size)
655
+static int __evsel__hw_cache_name(u64 config, char *bf, size_t size)
551656 {
552657 u8 op, result, type = (config >> 0) & 0xff;
553658 const char *err = "unknown-ext-hardware-cache-type";
....@@ -566,27 +671,33 @@
566671 goto out_err;
567672
568673 err = "invalid-cache";
569
- if (!perf_evsel__is_cache_op_valid(type, op))
674
+ if (!evsel__is_cache_op_valid(type, op))
570675 goto out_err;
571676
572
- return __perf_evsel__hw_cache_type_op_res_name(type, op, result, bf, size);
677
+ return __evsel__hw_cache_type_op_res_name(type, op, result, bf, size);
573678 out_err:
574679 return scnprintf(bf, size, "%s", err);
575680 }
576681
577
-static int perf_evsel__hw_cache_name(struct perf_evsel *evsel, char *bf, size_t size)
682
+static int evsel__hw_cache_name(struct evsel *evsel, char *bf, size_t size)
578683 {
579
- int ret = __perf_evsel__hw_cache_name(evsel->attr.config, bf, size);
684
+ int ret = __evsel__hw_cache_name(evsel->core.attr.config, bf, size);
580685 return ret + perf_evsel__add_modifiers(evsel, bf + ret, size - ret);
581686 }
582687
583
-static int perf_evsel__raw_name(struct perf_evsel *evsel, char *bf, size_t size)
688
+static int evsel__raw_name(struct evsel *evsel, char *bf, size_t size)
584689 {
585
- int ret = scnprintf(bf, size, "raw 0x%" PRIx64, evsel->attr.config);
690
+ int ret = scnprintf(bf, size, "raw 0x%" PRIx64, evsel->core.attr.config);
586691 return ret + perf_evsel__add_modifiers(evsel, bf + ret, size - ret);
587692 }
588693
589
-const char *perf_evsel__name(struct perf_evsel *evsel)
694
+static int evsel__tool_name(char *bf, size_t size)
695
+{
696
+ int ret = scnprintf(bf, size, "duration_time");
697
+ return ret;
698
+}
699
+
700
+const char *evsel__name(struct evsel *evsel)
590701 {
591702 char bf[128];
592703
....@@ -596,21 +707,24 @@
596707 if (evsel->name)
597708 return evsel->name;
598709
599
- switch (evsel->attr.type) {
710
+ switch (evsel->core.attr.type) {
600711 case PERF_TYPE_RAW:
601
- perf_evsel__raw_name(evsel, bf, sizeof(bf));
712
+ evsel__raw_name(evsel, bf, sizeof(bf));
602713 break;
603714
604715 case PERF_TYPE_HARDWARE:
605
- perf_evsel__hw_name(evsel, bf, sizeof(bf));
716
+ evsel__hw_name(evsel, bf, sizeof(bf));
606717 break;
607718
608719 case PERF_TYPE_HW_CACHE:
609
- perf_evsel__hw_cache_name(evsel, bf, sizeof(bf));
720
+ evsel__hw_cache_name(evsel, bf, sizeof(bf));
610721 break;
611722
612723 case PERF_TYPE_SOFTWARE:
613
- perf_evsel__sw_name(evsel, bf, sizeof(bf));
724
+ if (evsel->tool_event)
725
+ evsel__tool_name(bf, sizeof(bf));
726
+ else
727
+ evsel__sw_name(evsel, bf, sizeof(bf));
614728 break;
615729
616730 case PERF_TYPE_TRACEPOINT:
....@@ -618,12 +732,12 @@
618732 break;
619733
620734 case PERF_TYPE_BREAKPOINT:
621
- perf_evsel__bp_name(evsel, bf, sizeof(bf));
735
+ evsel__bp_name(evsel, bf, sizeof(bf));
622736 break;
623737
624738 default:
625739 scnprintf(bf, sizeof(bf), "unknown attr type: %d",
626
- evsel->attr.type);
740
+ evsel->core.attr.type);
627741 break;
628742 }
629743
....@@ -635,7 +749,7 @@
635749 return "unknown";
636750 }
637751
638
-const char *perf_evsel__group_name(struct perf_evsel *evsel)
752
+const char *evsel__group_name(struct evsel *evsel)
639753 {
640754 return evsel->group_name ?: "anon group";
641755 }
....@@ -650,21 +764,19 @@
650764 * For record -e 'cycles,instructions' and report --group
651765 * 'cycles:u, instructions:u'
652766 */
653
-int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size)
767
+int evsel__group_desc(struct evsel *evsel, char *buf, size_t size)
654768 {
655769 int ret = 0;
656
- struct perf_evsel *pos;
657
- const char *group_name = perf_evsel__group_name(evsel);
770
+ struct evsel *pos;
771
+ const char *group_name = evsel__group_name(evsel);
658772
659773 if (!evsel->forced_leader)
660774 ret = scnprintf(buf, size, "%s { ", group_name);
661775
662
- ret += scnprintf(buf + ret, size - ret, "%s",
663
- perf_evsel__name(evsel));
776
+ ret += scnprintf(buf + ret, size - ret, "%s", evsel__name(evsel));
664777
665778 for_each_group_member(pos, evsel)
666
- ret += scnprintf(buf + ret, size - ret, ", %s",
667
- perf_evsel__name(pos));
779
+ ret += scnprintf(buf + ret, size - ret, ", %s", evsel__name(pos));
668780
669781 if (!evsel->forced_leader)
670782 ret += scnprintf(buf + ret, size - ret, " }");
....@@ -672,17 +784,20 @@
672784 return ret;
673785 }
674786
675
-static void __perf_evsel__config_callchain(struct perf_evsel *evsel,
676
- struct record_opts *opts,
677
- struct callchain_param *param)
787
+static void __evsel__config_callchain(struct evsel *evsel, struct record_opts *opts,
788
+ struct callchain_param *param)
678789 {
679
- bool function = perf_evsel__is_function_event(evsel);
680
- struct perf_event_attr *attr = &evsel->attr;
790
+ bool function = evsel__is_function_event(evsel);
791
+ struct perf_event_attr *attr = &evsel->core.attr;
681792
682
- perf_evsel__set_sample_bit(evsel, CALLCHAIN);
793
+ evsel__set_sample_bit(evsel, CALLCHAIN);
683794
684795 attr->sample_max_stack = param->max_stack;
685796
797
+ if (opts->kernel_callchains)
798
+ attr->exclude_callchain_user = 1;
799
+ if (opts->user_callchains)
800
+ attr->exclude_callchain_kernel = 1;
686801 if (param->record_mode == CALLCHAIN_LBR) {
687802 if (!opts->branch_stack) {
688803 if (attr->exclude_user) {
....@@ -690,11 +805,12 @@
690805 "to get user callchain information. "
691806 "Falling back to framepointers.\n");
692807 } else {
693
- perf_evsel__set_sample_bit(evsel, BRANCH_STACK);
808
+ evsel__set_sample_bit(evsel, BRANCH_STACK);
694809 attr->branch_sample_type = PERF_SAMPLE_BRANCH_USER |
695810 PERF_SAMPLE_BRANCH_CALL_STACK |
696811 PERF_SAMPLE_BRANCH_NO_CYCLES |
697
- PERF_SAMPLE_BRANCH_NO_FLAGS;
812
+ PERF_SAMPLE_BRANCH_NO_FLAGS |
813
+ PERF_SAMPLE_BRANCH_HW_INDEX;
698814 }
699815 } else
700816 pr_warning("Cannot use LBR callstack with branch stack. "
....@@ -703,9 +819,16 @@
703819
704820 if (param->record_mode == CALLCHAIN_DWARF) {
705821 if (!function) {
706
- perf_evsel__set_sample_bit(evsel, REGS_USER);
707
- perf_evsel__set_sample_bit(evsel, STACK_USER);
708
- attr->sample_regs_user |= PERF_REGS_MASK;
822
+ evsel__set_sample_bit(evsel, REGS_USER);
823
+ evsel__set_sample_bit(evsel, STACK_USER);
824
+ if (opts->sample_user_regs && DWARF_MINIMAL_REGS != PERF_REGS_MASK) {
825
+ attr->sample_regs_user |= DWARF_MINIMAL_REGS;
826
+ pr_warning("WARNING: The use of --call-graph=dwarf may require all the user registers, "
827
+ "specifying a subset with --user-regs may render DWARF unwinding unreliable, "
828
+ "so the minimal registers set (IP, SP) is explicitly forced.\n");
829
+ } else {
830
+ attr->sample_regs_user |= PERF_REGS_MASK;
831
+ }
709832 attr->sample_stack_user = param->dump_size;
710833 attr->exclude_callchain_user = 1;
711834 } else {
....@@ -720,38 +843,38 @@
720843 }
721844 }
722845
723
-void perf_evsel__config_callchain(struct perf_evsel *evsel,
724
- struct record_opts *opts,
725
- struct callchain_param *param)
846
+void evsel__config_callchain(struct evsel *evsel, struct record_opts *opts,
847
+ struct callchain_param *param)
726848 {
727849 if (param->enabled)
728
- return __perf_evsel__config_callchain(evsel, opts, param);
850
+ return __evsel__config_callchain(evsel, opts, param);
729851 }
730852
731853 static void
732
-perf_evsel__reset_callgraph(struct perf_evsel *evsel,
854
+perf_evsel__reset_callgraph(struct evsel *evsel,
733855 struct callchain_param *param)
734856 {
735
- struct perf_event_attr *attr = &evsel->attr;
857
+ struct perf_event_attr *attr = &evsel->core.attr;
736858
737
- perf_evsel__reset_sample_bit(evsel, CALLCHAIN);
859
+ evsel__reset_sample_bit(evsel, CALLCHAIN);
738860 if (param->record_mode == CALLCHAIN_LBR) {
739
- perf_evsel__reset_sample_bit(evsel, BRANCH_STACK);
861
+ evsel__reset_sample_bit(evsel, BRANCH_STACK);
740862 attr->branch_sample_type &= ~(PERF_SAMPLE_BRANCH_USER |
741
- PERF_SAMPLE_BRANCH_CALL_STACK);
863
+ PERF_SAMPLE_BRANCH_CALL_STACK |
864
+ PERF_SAMPLE_BRANCH_HW_INDEX);
742865 }
743866 if (param->record_mode == CALLCHAIN_DWARF) {
744
- perf_evsel__reset_sample_bit(evsel, REGS_USER);
745
- perf_evsel__reset_sample_bit(evsel, STACK_USER);
867
+ evsel__reset_sample_bit(evsel, REGS_USER);
868
+ evsel__reset_sample_bit(evsel, STACK_USER);
746869 }
747870 }
748871
749
-static void apply_config_terms(struct perf_evsel *evsel,
750
- struct record_opts *opts, bool track)
872
+static void evsel__apply_config_terms(struct evsel *evsel,
873
+ struct record_opts *opts, bool track)
751874 {
752
- struct perf_evsel_config_term *term;
875
+ struct evsel_config_term *term;
753876 struct list_head *config_terms = &evsel->config_terms;
754
- struct perf_event_attr *attr = &evsel->attr;
877
+ struct perf_event_attr *attr = &evsel->core.attr;
755878 /* callgraph default */
756879 struct callchain_param param = {
757880 .record_mode = callchain_param.record_mode,
....@@ -762,56 +885,69 @@
762885
763886 list_for_each_entry(term, config_terms, list) {
764887 switch (term->type) {
765
- case PERF_EVSEL__CONFIG_TERM_PERIOD:
888
+ case EVSEL__CONFIG_TERM_PERIOD:
766889 if (!(term->weak && opts->user_interval != ULLONG_MAX)) {
767890 attr->sample_period = term->val.period;
768891 attr->freq = 0;
769
- perf_evsel__reset_sample_bit(evsel, PERIOD);
892
+ evsel__reset_sample_bit(evsel, PERIOD);
770893 }
771894 break;
772
- case PERF_EVSEL__CONFIG_TERM_FREQ:
895
+ case EVSEL__CONFIG_TERM_FREQ:
773896 if (!(term->weak && opts->user_freq != UINT_MAX)) {
774897 attr->sample_freq = term->val.freq;
775898 attr->freq = 1;
776
- perf_evsel__set_sample_bit(evsel, PERIOD);
899
+ evsel__set_sample_bit(evsel, PERIOD);
777900 }
778901 break;
779
- case PERF_EVSEL__CONFIG_TERM_TIME:
902
+ case EVSEL__CONFIG_TERM_TIME:
780903 if (term->val.time)
781
- perf_evsel__set_sample_bit(evsel, TIME);
904
+ evsel__set_sample_bit(evsel, TIME);
782905 else
783
- perf_evsel__reset_sample_bit(evsel, TIME);
906
+ evsel__reset_sample_bit(evsel, TIME);
784907 break;
785
- case PERF_EVSEL__CONFIG_TERM_CALLGRAPH:
786
- callgraph_buf = term->val.callgraph;
908
+ case EVSEL__CONFIG_TERM_CALLGRAPH:
909
+ callgraph_buf = term->val.str;
787910 break;
788
- case PERF_EVSEL__CONFIG_TERM_BRANCH:
789
- if (term->val.branch && strcmp(term->val.branch, "no")) {
790
- perf_evsel__set_sample_bit(evsel, BRANCH_STACK);
791
- parse_branch_str(term->val.branch,
911
+ case EVSEL__CONFIG_TERM_BRANCH:
912
+ if (term->val.str && strcmp(term->val.str, "no")) {
913
+ evsel__set_sample_bit(evsel, BRANCH_STACK);
914
+ parse_branch_str(term->val.str,
792915 &attr->branch_sample_type);
793916 } else
794
- perf_evsel__reset_sample_bit(evsel, BRANCH_STACK);
917
+ evsel__reset_sample_bit(evsel, BRANCH_STACK);
795918 break;
796
- case PERF_EVSEL__CONFIG_TERM_STACK_USER:
919
+ case EVSEL__CONFIG_TERM_STACK_USER:
797920 dump_size = term->val.stack_user;
798921 break;
799
- case PERF_EVSEL__CONFIG_TERM_MAX_STACK:
922
+ case EVSEL__CONFIG_TERM_MAX_STACK:
800923 max_stack = term->val.max_stack;
801924 break;
802
- case PERF_EVSEL__CONFIG_TERM_INHERIT:
925
+ case EVSEL__CONFIG_TERM_MAX_EVENTS:
926
+ evsel->max_events = term->val.max_events;
927
+ break;
928
+ case EVSEL__CONFIG_TERM_INHERIT:
803929 /*
804930 * attr->inherit should has already been set by
805
- * perf_evsel__config. If user explicitly set
931
+ * evsel__config. If user explicitly set
806932 * inherit using config terms, override global
807933 * opt->no_inherit setting.
808934 */
809935 attr->inherit = term->val.inherit ? 1 : 0;
810936 break;
811
- case PERF_EVSEL__CONFIG_TERM_OVERWRITE:
937
+ case EVSEL__CONFIG_TERM_OVERWRITE:
812938 attr->write_backward = term->val.overwrite ? 1 : 0;
813939 break;
814
- case PERF_EVSEL__CONFIG_TERM_DRV_CFG:
940
+ case EVSEL__CONFIG_TERM_DRV_CFG:
941
+ break;
942
+ case EVSEL__CONFIG_TERM_PERCORE:
943
+ break;
944
+ case EVSEL__CONFIG_TERM_AUX_OUTPUT:
945
+ attr->aux_output = term->val.aux_output ? 1 : 0;
946
+ break;
947
+ case EVSEL__CONFIG_TERM_AUX_SAMPLE_SIZE:
948
+ /* Already applied by auxtrace */
949
+ break;
950
+ case EVSEL__CONFIG_TERM_CFG_CHG:
815951 break;
816952 default:
817953 break;
....@@ -857,19 +993,36 @@
857993 /* set perf-event callgraph */
858994 if (param.enabled) {
859995 if (sample_address) {
860
- perf_evsel__set_sample_bit(evsel, ADDR);
861
- perf_evsel__set_sample_bit(evsel, DATA_SRC);
862
- evsel->attr.mmap_data = track;
996
+ evsel__set_sample_bit(evsel, ADDR);
997
+ evsel__set_sample_bit(evsel, DATA_SRC);
998
+ evsel->core.attr.mmap_data = track;
863999 }
864
- perf_evsel__config_callchain(evsel, opts, &param);
1000
+ evsel__config_callchain(evsel, opts, &param);
8651001 }
8661002 }
8671003 }
8681004
869
-static bool is_dummy_event(struct perf_evsel *evsel)
1005
+struct evsel_config_term *__evsel__get_config_term(struct evsel *evsel, enum evsel_term_type type)
8701006 {
871
- return (evsel->attr.type == PERF_TYPE_SOFTWARE) &&
872
- (evsel->attr.config == PERF_COUNT_SW_DUMMY);
1007
+ struct evsel_config_term *term, *found_term = NULL;
1008
+
1009
+ list_for_each_entry(term, &evsel->config_terms, list) {
1010
+ if (term->type == type)
1011
+ found_term = term;
1012
+ }
1013
+
1014
+ return found_term;
1015
+}
1016
+
1017
+static void evsel__set_default_freq_period(struct record_opts *opts,
1018
+ struct perf_event_attr *attr)
1019
+{
1020
+ if (opts->freq) {
1021
+ attr->freq = 1;
1022
+ attr->sample_freq = opts->freq;
1023
+ } else {
1024
+ attr->sample_period = opts->default_interval;
1025
+ }
8731026 }
8741027
8751028 /*
....@@ -900,11 +1053,11 @@
9001053 * enable/disable events specifically, as there's no
9011054 * initial traced exec call.
9021055 */
903
-void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
904
- struct callchain_param *callchain)
1056
+void evsel__config(struct evsel *evsel, struct record_opts *opts,
1057
+ struct callchain_param *callchain)
9051058 {
906
- struct perf_evsel *leader = evsel->leader;
907
- struct perf_event_attr *attr = &evsel->attr;
1059
+ struct evsel *leader = evsel->leader;
1060
+ struct perf_event_attr *attr = &evsel->core.attr;
9081061 int track = evsel->tracking;
9091062 bool per_cpu = opts->target.default_per_cpu && !opts->target.per_thread;
9101063
....@@ -912,23 +1065,23 @@
9121065 attr->inherit = !opts->no_inherit;
9131066 attr->write_backward = opts->overwrite ? 1 : 0;
9141067
915
- perf_evsel__set_sample_bit(evsel, IP);
916
- perf_evsel__set_sample_bit(evsel, TID);
1068
+ evsel__set_sample_bit(evsel, IP);
1069
+ evsel__set_sample_bit(evsel, TID);
9171070
9181071 if (evsel->sample_read) {
919
- perf_evsel__set_sample_bit(evsel, READ);
1072
+ evsel__set_sample_bit(evsel, READ);
9201073
9211074 /*
9221075 * We need ID even in case of single event, because
9231076 * PERF_SAMPLE_READ process ID specific data.
9241077 */
925
- perf_evsel__set_sample_id(evsel, false);
1078
+ evsel__set_sample_id(evsel, false);
9261079
9271080 /*
9281081 * Apply group format only if we belong to group
9291082 * with more than one members.
9301083 */
931
- if (leader->nr_members > 1) {
1084
+ if (leader->core.nr_members > 1) {
9321085 attr->read_format |= PERF_FORMAT_GROUP;
9331086 attr->inherit = 0;
9341087 }
....@@ -938,33 +1091,24 @@
9381091 * We default some events to have a default interval. But keep
9391092 * it a weak assumption overridable by the user.
9401093 */
941
- if (!attr->sample_period || (opts->user_freq != UINT_MAX ||
942
- opts->user_interval != ULLONG_MAX)) {
943
- if (opts->freq) {
944
- perf_evsel__set_sample_bit(evsel, PERIOD);
945
- attr->freq = 1;
946
- attr->sample_freq = opts->freq;
947
- } else {
948
- attr->sample_period = opts->default_interval;
949
- }
950
- }
1094
+ if ((evsel->is_libpfm_event && !attr->sample_period) ||
1095
+ (!evsel->is_libpfm_event && (!attr->sample_period ||
1096
+ opts->user_freq != UINT_MAX ||
1097
+ opts->user_interval != ULLONG_MAX)))
1098
+ evsel__set_default_freq_period(opts, attr);
9511099
9521100 /*
953
- * Disable sampling for all group members other
954
- * than leader in case leader 'leads' the sampling.
1101
+ * If attr->freq was set (here or earlier), ask for period
1102
+ * to be sampled.
9551103 */
956
- if ((leader != evsel) && leader->sample_read) {
957
- attr->freq = 0;
958
- attr->sample_freq = 0;
959
- attr->sample_period = 0;
960
- attr->write_backward = 0;
961
- }
1104
+ if (attr->freq)
1105
+ evsel__set_sample_bit(evsel, PERIOD);
9621106
9631107 if (opts->no_samples)
9641108 attr->sample_freq = 0;
9651109
9661110 if (opts->inherit_stat) {
967
- evsel->attr.read_format |=
1111
+ evsel->core.attr.read_format |=
9681112 PERF_FORMAT_TOTAL_TIME_ENABLED |
9691113 PERF_FORMAT_TOTAL_TIME_RUNNING |
9701114 PERF_FORMAT_ID;
....@@ -972,7 +1116,7 @@
9721116 }
9731117
9741118 if (opts->sample_address) {
975
- perf_evsel__set_sample_bit(evsel, ADDR);
1119
+ evsel__set_sample_bit(evsel, ADDR);
9761120 attr->mmap_data = track;
9771121 }
9781122
....@@ -981,24 +1125,26 @@
9811125 * event, due to issues with page faults while tracing page
9821126 * fault handler and its overall trickiness nature.
9831127 */
984
- if (perf_evsel__is_function_event(evsel))
985
- evsel->attr.exclude_callchain_user = 1;
1128
+ if (evsel__is_function_event(evsel))
1129
+ evsel->core.attr.exclude_callchain_user = 1;
9861130
9871131 if (callchain && callchain->enabled && !evsel->no_aux_samples)
988
- perf_evsel__config_callchain(evsel, opts, callchain);
1132
+ evsel__config_callchain(evsel, opts, callchain);
9891133
990
- if (opts->sample_intr_regs) {
1134
+ if (opts->sample_intr_regs && !evsel->no_aux_samples &&
1135
+ !evsel__is_dummy_event(evsel)) {
9911136 attr->sample_regs_intr = opts->sample_intr_regs;
992
- perf_evsel__set_sample_bit(evsel, REGS_INTR);
1137
+ evsel__set_sample_bit(evsel, REGS_INTR);
9931138 }
9941139
995
- if (opts->sample_user_regs) {
1140
+ if (opts->sample_user_regs && !evsel->no_aux_samples &&
1141
+ !evsel__is_dummy_event(evsel)) {
9961142 attr->sample_regs_user |= opts->sample_user_regs;
997
- perf_evsel__set_sample_bit(evsel, REGS_USER);
1143
+ evsel__set_sample_bit(evsel, REGS_USER);
9981144 }
9991145
10001146 if (target__has_cpu(&opts->target) || opts->sample_cpu)
1001
- perf_evsel__set_sample_bit(evsel, CPU);
1147
+ evsel__set_sample_bit(evsel, CPU);
10021148
10031149 /*
10041150 * When the user explicitly disabled time don't force it here.
....@@ -1007,48 +1153,60 @@
10071153 (!perf_missing_features.sample_id_all &&
10081154 (!opts->no_inherit || target__has_cpu(&opts->target) || per_cpu ||
10091155 opts->sample_time_set)))
1010
- perf_evsel__set_sample_bit(evsel, TIME);
1156
+ evsel__set_sample_bit(evsel, TIME);
10111157
10121158 if (opts->raw_samples && !evsel->no_aux_samples) {
1013
- perf_evsel__set_sample_bit(evsel, TIME);
1014
- perf_evsel__set_sample_bit(evsel, RAW);
1015
- perf_evsel__set_sample_bit(evsel, CPU);
1159
+ evsel__set_sample_bit(evsel, TIME);
1160
+ evsel__set_sample_bit(evsel, RAW);
1161
+ evsel__set_sample_bit(evsel, CPU);
10161162 }
10171163
10181164 if (opts->sample_address)
1019
- perf_evsel__set_sample_bit(evsel, DATA_SRC);
1165
+ evsel__set_sample_bit(evsel, DATA_SRC);
10201166
10211167 if (opts->sample_phys_addr)
1022
- perf_evsel__set_sample_bit(evsel, PHYS_ADDR);
1168
+ evsel__set_sample_bit(evsel, PHYS_ADDR);
10231169
10241170 if (opts->no_buffering) {
10251171 attr->watermark = 0;
10261172 attr->wakeup_events = 1;
10271173 }
10281174 if (opts->branch_stack && !evsel->no_aux_samples) {
1029
- perf_evsel__set_sample_bit(evsel, BRANCH_STACK);
1175
+ evsel__set_sample_bit(evsel, BRANCH_STACK);
10301176 attr->branch_sample_type = opts->branch_stack;
10311177 }
10321178
10331179 if (opts->sample_weight)
1034
- perf_evsel__set_sample_bit(evsel, WEIGHT);
1180
+ evsel__set_sample_bit(evsel, WEIGHT);
10351181
10361182 attr->task = track;
10371183 attr->mmap = track;
10381184 attr->mmap2 = track && !perf_missing_features.mmap2;
10391185 attr->comm = track;
1186
+ /*
1187
+ * ksymbol is tracked separately with text poke because it needs to be
1188
+ * system wide and enabled immediately.
1189
+ */
1190
+ if (!opts->text_poke)
1191
+ attr->ksymbol = track && !perf_missing_features.ksymbol;
1192
+ attr->bpf_event = track && !opts->no_bpf_event && !perf_missing_features.bpf;
10401193
10411194 if (opts->record_namespaces)
10421195 attr->namespaces = track;
1196
+
1197
+ if (opts->record_cgroup) {
1198
+ attr->cgroup = track && !perf_missing_features.cgroup;
1199
+ evsel__set_sample_bit(evsel, CGROUP);
1200
+ }
10431201
10441202 if (opts->record_switch_events)
10451203 attr->context_switch = track;
10461204
10471205 if (opts->sample_transaction)
1048
- perf_evsel__set_sample_bit(evsel, TRANSACTION);
1206
+ evsel__set_sample_bit(evsel, TRANSACTION);
10491207
10501208 if (opts->running_time) {
1051
- evsel->attr.read_format |=
1209
+ evsel->core.attr.read_format |=
10521210 PERF_FORMAT_TOTAL_TIME_ENABLED |
10531211 PERF_FORMAT_TOTAL_TIME_RUNNING;
10541212 }
....@@ -1059,15 +1217,15 @@
10591217 * Disabling only independent events or group leaders,
10601218 * keeping group members enabled.
10611219 */
1062
- if (perf_evsel__is_group_leader(evsel))
1220
+ if (evsel__is_group_leader(evsel))
10631221 attr->disabled = 1;
10641222
10651223 /*
10661224 * Setting enable_on_exec for independent events and
10671225 * group leaders for traced executed by perf.
10681226 */
1069
- if (target__none(&opts->target) && perf_evsel__is_group_leader(evsel) &&
1070
- !opts->initial_delay)
1227
+ if (target__none(&opts->target) && evsel__is_group_leader(evsel) &&
1228
+ !opts->initial_delay)
10711229 attr->enable_on_exec = 1;
10721230
10731231 if (evsel->immediate) {
....@@ -1082,7 +1240,7 @@
10821240 }
10831241
10841242 if (evsel->precise_max)
1085
- perf_event_attr__set_max_precise_ip(attr);
1243
+ attr->precise_ip = 3;
10861244
10871245 if (opts->all_user) {
10881246 attr->exclude_kernel = 1;
....@@ -1094,79 +1252,38 @@
10941252 attr->exclude_user = 1;
10951253 }
10961254
1097
- if (evsel->own_cpus || evsel->unit)
1098
- evsel->attr.read_format |= PERF_FORMAT_ID;
1255
+ if (evsel->core.own_cpus || evsel->unit)
1256
+ evsel->core.attr.read_format |= PERF_FORMAT_ID;
10991257
11001258 /*
11011259 * Apply event specific term settings,
11021260 * it overloads any global configuration.
11031261 */
1104
- apply_config_terms(evsel, opts, track);
1262
+ evsel__apply_config_terms(evsel, opts, track);
11051263
11061264 evsel->ignore_missing_thread = opts->ignore_missing_thread;
11071265
11081266 /* The --period option takes the precedence. */
11091267 if (opts->period_set) {
11101268 if (opts->period)
1111
- perf_evsel__set_sample_bit(evsel, PERIOD);
1269
+ evsel__set_sample_bit(evsel, PERIOD);
11121270 else
1113
- perf_evsel__reset_sample_bit(evsel, PERIOD);
1271
+ evsel__reset_sample_bit(evsel, PERIOD);
11141272 }
11151273
11161274 /*
1275
+ * A dummy event never triggers any actual counter and therefore
1276
+ * cannot be used with branch_stack.
1277
+ *
11171278 * For initial_delay, a dummy event is added implicitly.
11181279 * The software event will trigger -EOPNOTSUPP error out,
11191280 * if BRANCH_STACK bit is set.
11201281 */
1121
- if (opts->initial_delay && is_dummy_event(evsel))
1122
- perf_evsel__reset_sample_bit(evsel, BRANCH_STACK);
1282
+ if (evsel__is_dummy_event(evsel))
1283
+ evsel__reset_sample_bit(evsel, BRANCH_STACK);
11231284 }
11241285
1125
-static int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
1126
-{
1127
- if (evsel->system_wide)
1128
- nthreads = 1;
1129
-
1130
- evsel->fd = xyarray__new(ncpus, nthreads, sizeof(int));
1131
-
1132
- if (evsel->fd) {
1133
- int cpu, thread;
1134
- for (cpu = 0; cpu < ncpus; cpu++) {
1135
- for (thread = 0; thread < nthreads; thread++) {
1136
- FD(evsel, cpu, thread) = -1;
1137
- }
1138
- }
1139
- }
1140
-
1141
- return evsel->fd != NULL ? 0 : -ENOMEM;
1142
-}
1143
-
1144
-static int perf_evsel__run_ioctl(struct perf_evsel *evsel,
1145
- int ioc, void *arg)
1146
-{
1147
- int cpu, thread;
1148
-
1149
- for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) {
1150
- for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) {
1151
- int fd = FD(evsel, cpu, thread),
1152
- err = ioctl(fd, ioc, arg);
1153
-
1154
- if (err)
1155
- return err;
1156
- }
1157
- }
1158
-
1159
- return 0;
1160
-}
1161
-
1162
-int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter)
1163
-{
1164
- return perf_evsel__run_ioctl(evsel,
1165
- PERF_EVENT_IOC_SET_FILTER,
1166
- (void *)filter);
1167
-}
1168
-
1169
-int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter)
1286
+int evsel__set_filter(struct evsel *evsel, const char *filter)
11701287 {
11711288 char *new_filter = strdup(filter);
11721289
....@@ -1179,13 +1296,12 @@
11791296 return -1;
11801297 }
11811298
1182
-static int perf_evsel__append_filter(struct perf_evsel *evsel,
1183
- const char *fmt, const char *filter)
1299
+static int evsel__append_filter(struct evsel *evsel, const char *fmt, const char *filter)
11841300 {
11851301 char *new_filter;
11861302
11871303 if (evsel->filter == NULL)
1188
- return perf_evsel__set_filter(evsel, filter);
1304
+ return evsel__set_filter(evsel, filter);
11891305
11901306 if (asprintf(&new_filter, fmt, evsel->filter, filter) > 0) {
11911307 free(evsel->filter);
....@@ -1196,98 +1312,76 @@
11961312 return -1;
11971313 }
11981314
1199
-int perf_evsel__append_tp_filter(struct perf_evsel *evsel, const char *filter)
1315
+int evsel__append_tp_filter(struct evsel *evsel, const char *filter)
12001316 {
1201
- return perf_evsel__append_filter(evsel, "(%s) && (%s)", filter);
1317
+ return evsel__append_filter(evsel, "(%s) && (%s)", filter);
12021318 }
12031319
1204
-int perf_evsel__append_addr_filter(struct perf_evsel *evsel, const char *filter)
1320
+int evsel__append_addr_filter(struct evsel *evsel, const char *filter)
12051321 {
1206
- return perf_evsel__append_filter(evsel, "%s,%s", filter);
1322
+ return evsel__append_filter(evsel, "%s,%s", filter);
12071323 }
12081324
1209
-int perf_evsel__enable(struct perf_evsel *evsel)
1325
+/* Caller has to clear disabled after going through all CPUs. */
1326
+int evsel__enable_cpu(struct evsel *evsel, int cpu)
12101327 {
1211
- return perf_evsel__run_ioctl(evsel,
1212
- PERF_EVENT_IOC_ENABLE,
1213
- 0);
1328
+ return perf_evsel__enable_cpu(&evsel->core, cpu);
12141329 }
12151330
1216
-int perf_evsel__disable(struct perf_evsel *evsel)
1331
+int evsel__enable(struct evsel *evsel)
12171332 {
1218
- return perf_evsel__run_ioctl(evsel,
1219
- PERF_EVENT_IOC_DISABLE,
1220
- 0);
1333
+ int err = perf_evsel__enable(&evsel->core);
1334
+
1335
+ if (!err)
1336
+ evsel->disabled = false;
1337
+ return err;
12211338 }
12221339
1223
-int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads)
1340
+/* Caller has to set disabled after going through all CPUs. */
1341
+int evsel__disable_cpu(struct evsel *evsel, int cpu)
12241342 {
1225
- if (ncpus == 0 || nthreads == 0)
1226
- return 0;
1227
-
1228
- if (evsel->system_wide)
1229
- nthreads = 1;
1230
-
1231
- evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id));
1232
- if (evsel->sample_id == NULL)
1233
- return -ENOMEM;
1234
-
1235
- evsel->id = zalloc(ncpus * nthreads * sizeof(u64));
1236
- if (evsel->id == NULL) {
1237
- xyarray__delete(evsel->sample_id);
1238
- evsel->sample_id = NULL;
1239
- return -ENOMEM;
1240
- }
1241
-
1242
- return 0;
1343
+ return perf_evsel__disable_cpu(&evsel->core, cpu);
12431344 }
12441345
1245
-static void perf_evsel__free_fd(struct perf_evsel *evsel)
1346
+int evsel__disable(struct evsel *evsel)
12461347 {
1247
- xyarray__delete(evsel->fd);
1248
- evsel->fd = NULL;
1348
+ int err = perf_evsel__disable(&evsel->core);
1349
+ /*
1350
+ * We mark it disabled here so that tools that disable a event can
1351
+ * ignore events after they disable it. I.e. the ring buffer may have
1352
+ * already a few more events queued up before the kernel got the stop
1353
+ * request.
1354
+ */
1355
+ if (!err)
1356
+ evsel->disabled = true;
1357
+
1358
+ return err;
12491359 }
12501360
1251
-static void perf_evsel__free_id(struct perf_evsel *evsel)
1361
+static void evsel__free_config_terms(struct evsel *evsel)
12521362 {
1253
- xyarray__delete(evsel->sample_id);
1254
- evsel->sample_id = NULL;
1255
- zfree(&evsel->id);
1256
-}
1257
-
1258
-static void perf_evsel__free_config_terms(struct perf_evsel *evsel)
1259
-{
1260
- struct perf_evsel_config_term *term, *h;
1363
+ struct evsel_config_term *term, *h;
12611364
12621365 list_for_each_entry_safe(term, h, &evsel->config_terms, list) {
1263
- list_del(&term->list);
1366
+ list_del_init(&term->list);
1367
+ if (term->free_str)
1368
+ zfree(&term->val.str);
12641369 free(term);
12651370 }
12661371 }
12671372
1268
-void perf_evsel__close_fd(struct perf_evsel *evsel)
1373
+void evsel__exit(struct evsel *evsel)
12691374 {
1270
- int cpu, thread;
1271
-
1272
- for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++)
1273
- for (thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) {
1274
- close(FD(evsel, cpu, thread));
1275
- FD(evsel, cpu, thread) = -1;
1276
- }
1277
-}
1278
-
1279
-void perf_evsel__exit(struct perf_evsel *evsel)
1280
-{
1281
- assert(list_empty(&evsel->node));
1375
+ assert(list_empty(&evsel->core.node));
12821376 assert(evsel->evlist == NULL);
1283
- perf_evsel__free_counts(evsel);
1284
- perf_evsel__free_fd(evsel);
1285
- perf_evsel__free_id(evsel);
1286
- perf_evsel__free_config_terms(evsel);
1377
+ evsel__free_counts(evsel);
1378
+ perf_evsel__free_fd(&evsel->core);
1379
+ perf_evsel__free_id(&evsel->core);
1380
+ evsel__free_config_terms(evsel);
12871381 cgroup__put(evsel->cgrp);
1288
- cpu_map__put(evsel->cpus);
1289
- cpu_map__put(evsel->own_cpus);
1290
- thread_map__put(evsel->threads);
1382
+ perf_cpu_map__put(evsel->core.cpus);
1383
+ perf_cpu_map__put(evsel->core.own_cpus);
1384
+ perf_thread_map__put(evsel->core.threads);
12911385 zfree(&evsel->group_name);
12921386 zfree(&evsel->name);
12931387 zfree(&evsel->pmu_name);
....@@ -1296,14 +1390,14 @@
12961390 perf_evsel__object.fini(evsel);
12971391 }
12981392
1299
-void perf_evsel__delete(struct perf_evsel *evsel)
1393
+void evsel__delete(struct evsel *evsel)
13001394 {
1301
- perf_evsel__exit(evsel);
1395
+ evsel__exit(evsel);
13021396 free(evsel);
13031397 }
13041398
1305
-void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu, int thread,
1306
- struct perf_counts_values *count)
1399
+void evsel__compute_deltas(struct evsel *evsel, int cpu, int thread,
1400
+ struct perf_counts_values *count)
13071401 {
13081402 struct perf_counts_values tmp;
13091403
....@@ -1334,66 +1428,23 @@
13341428 count->val = 0;
13351429 } else if (count->run < count->ena) {
13361430 scaled = 1;
1337
- count->val = (u64)((double) count->val * count->ena / count->run + 0.5);
1431
+ count->val = (u64)((double) count->val * count->ena / count->run);
13381432 }
1339
- } else
1340
- count->ena = count->run = 0;
1433
+ }
13411434
13421435 if (pscaled)
13431436 *pscaled = scaled;
13441437 }
13451438
1346
-static int perf_evsel__read_size(struct perf_evsel *evsel)
1347
-{
1348
- u64 read_format = evsel->attr.read_format;
1349
- int entry = sizeof(u64); /* value */
1350
- int size = 0;
1351
- int nr = 1;
1352
-
1353
- if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
1354
- size += sizeof(u64);
1355
-
1356
- if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
1357
- size += sizeof(u64);
1358
-
1359
- if (read_format & PERF_FORMAT_ID)
1360
- entry += sizeof(u64);
1361
-
1362
- if (read_format & PERF_FORMAT_GROUP) {
1363
- nr = evsel->nr_members;
1364
- size += sizeof(u64);
1365
- }
1366
-
1367
- size += entry * nr;
1368
- return size;
1369
-}
1370
-
1371
-int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
1372
- struct perf_counts_values *count)
1373
-{
1374
- size_t size = perf_evsel__read_size(evsel);
1375
-
1376
- memset(count, 0, sizeof(*count));
1377
-
1378
- if (FD(evsel, cpu, thread) < 0)
1379
- return -EINVAL;
1380
-
1381
- if (readn(FD(evsel, cpu, thread), count->values, size) <= 0)
1382
- return -errno;
1383
-
1384
- return 0;
1385
-}
1386
-
1387
-static int
1388
-perf_evsel__read_one(struct perf_evsel *evsel, int cpu, int thread)
1439
+static int evsel__read_one(struct evsel *evsel, int cpu, int thread)
13891440 {
13901441 struct perf_counts_values *count = perf_counts(evsel->counts, cpu, thread);
13911442
1392
- return perf_evsel__read(evsel, cpu, thread, count);
1443
+ return perf_evsel__read(&evsel->core, cpu, thread, count);
13931444 }
13941445
13951446 static void
1396
-perf_evsel__set_count(struct perf_evsel *counter, int cpu, int thread,
1447
+perf_evsel__set_count(struct evsel *counter, int cpu, int thread,
13971448 u64 val, u64 ena, u64 run)
13981449 {
13991450 struct perf_counts_values *count;
....@@ -1403,20 +1454,21 @@
14031454 count->val = val;
14041455 count->ena = ena;
14051456 count->run = run;
1406
- count->loaded = true;
1457
+
1458
+ perf_counts__set_loaded(counter->counts, cpu, thread, true);
14071459 }
14081460
14091461 static int
1410
-perf_evsel__process_group_data(struct perf_evsel *leader,
1462
+perf_evsel__process_group_data(struct evsel *leader,
14111463 int cpu, int thread, u64 *data)
14121464 {
1413
- u64 read_format = leader->attr.read_format;
1465
+ u64 read_format = leader->core.attr.read_format;
14141466 struct sample_read_value *v;
14151467 u64 nr, ena = 0, run = 0, i;
14161468
14171469 nr = *data++;
14181470
1419
- if (nr != (u64) leader->nr_members)
1471
+ if (nr != (u64) leader->core.nr_members)
14201472 return -EINVAL;
14211473
14221474 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
....@@ -1431,7 +1483,7 @@
14311483 v[0].value, ena, run);
14321484
14331485 for (i = 1; i < nr; i++) {
1434
- struct perf_evsel *counter;
1486
+ struct evsel *counter;
14351487
14361488 counter = perf_evlist__id2evsel(leader->evlist, v[i].id);
14371489 if (!counter)
....@@ -1444,18 +1496,17 @@
14441496 return 0;
14451497 }
14461498
1447
-static int
1448
-perf_evsel__read_group(struct perf_evsel *leader, int cpu, int thread)
1499
+static int evsel__read_group(struct evsel *leader, int cpu, int thread)
14491500 {
14501501 struct perf_stat_evsel *ps = leader->stats;
1451
- u64 read_format = leader->attr.read_format;
1452
- int size = perf_evsel__read_size(leader);
1502
+ u64 read_format = leader->core.attr.read_format;
1503
+ int size = perf_evsel__read_size(&leader->core);
14531504 u64 *data = ps->group_data;
14541505
14551506 if (!(read_format & PERF_FORMAT_ID))
14561507 return -EINVAL;
14571508
1458
- if (!perf_evsel__is_group_leader(leader))
1509
+ if (!evsel__is_group_leader(leader))
14591510 return -EINVAL;
14601511
14611512 if (!data) {
....@@ -1475,18 +1526,17 @@
14751526 return perf_evsel__process_group_data(leader, cpu, thread, data);
14761527 }
14771528
1478
-int perf_evsel__read_counter(struct perf_evsel *evsel, int cpu, int thread)
1529
+int evsel__read_counter(struct evsel *evsel, int cpu, int thread)
14791530 {
1480
- u64 read_format = evsel->attr.read_format;
1531
+ u64 read_format = evsel->core.attr.read_format;
14811532
14821533 if (read_format & PERF_FORMAT_GROUP)
1483
- return perf_evsel__read_group(evsel, cpu, thread);
1484
- else
1485
- return perf_evsel__read_one(evsel, cpu, thread);
1534
+ return evsel__read_group(evsel, cpu, thread);
1535
+
1536
+ return evsel__read_one(evsel, cpu, thread);
14861537 }
14871538
1488
-int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
1489
- int cpu, int thread, bool scale)
1539
+int __evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread, bool scale)
14901540 {
14911541 struct perf_counts_values count;
14921542 size_t nv = scale ? 3 : 1;
....@@ -1494,31 +1544,31 @@
14941544 if (FD(evsel, cpu, thread) < 0)
14951545 return -EINVAL;
14961546
1497
- if (evsel->counts == NULL && perf_evsel__alloc_counts(evsel, cpu + 1, thread + 1) < 0)
1547
+ if (evsel->counts == NULL && evsel__alloc_counts(evsel, cpu + 1, thread + 1) < 0)
14981548 return -ENOMEM;
14991549
15001550 if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) <= 0)
15011551 return -errno;
15021552
1503
- perf_evsel__compute_deltas(evsel, cpu, thread, &count);
1553
+ evsel__compute_deltas(evsel, cpu, thread, &count);
15041554 perf_counts_values__scale(&count, scale, NULL);
15051555 *perf_counts(evsel->counts, cpu, thread) = count;
15061556 return 0;
15071557 }
15081558
1509
-static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread)
1559
+static int get_group_fd(struct evsel *evsel, int cpu, int thread)
15101560 {
1511
- struct perf_evsel *leader = evsel->leader;
1561
+ struct evsel *leader = evsel->leader;
15121562 int fd;
15131563
1514
- if (perf_evsel__is_group_leader(evsel))
1564
+ if (evsel__is_group_leader(evsel))
15151565 return -1;
15161566
15171567 /*
15181568 * Leader must be already processed/open,
15191569 * if not it's a bug.
15201570 */
1521
- BUG_ON(!leader->fd);
1571
+ BUG_ON(!leader->core.fd);
15221572
15231573 fd = FD(leader, cpu, thread);
15241574 BUG_ON(fd == -1);
....@@ -1526,150 +1576,7 @@
15261576 return fd;
15271577 }
15281578
1529
-struct bit_names {
1530
- int bit;
1531
- const char *name;
1532
-};
1533
-
1534
-static void __p_bits(char *buf, size_t size, u64 value, struct bit_names *bits)
1535
-{
1536
- bool first_bit = true;
1537
- int i = 0;
1538
-
1539
- do {
1540
- if (value & bits[i].bit) {
1541
- buf += scnprintf(buf, size, "%s%s", first_bit ? "" : "|", bits[i].name);
1542
- first_bit = false;
1543
- }
1544
- } while (bits[++i].name != NULL);
1545
-}
1546
-
1547
-static void __p_sample_type(char *buf, size_t size, u64 value)
1548
-{
1549
-#define bit_name(n) { PERF_SAMPLE_##n, #n }
1550
- struct bit_names bits[] = {
1551
- bit_name(IP), bit_name(TID), bit_name(TIME), bit_name(ADDR),
1552
- bit_name(READ), bit_name(CALLCHAIN), bit_name(ID), bit_name(CPU),
1553
- bit_name(PERIOD), bit_name(STREAM_ID), bit_name(RAW),
1554
- bit_name(BRANCH_STACK), bit_name(REGS_USER), bit_name(STACK_USER),
1555
- bit_name(IDENTIFIER), bit_name(REGS_INTR), bit_name(DATA_SRC),
1556
- bit_name(WEIGHT), bit_name(PHYS_ADDR),
1557
- { .name = NULL, }
1558
- };
1559
-#undef bit_name
1560
- __p_bits(buf, size, value, bits);
1561
-}
1562
-
1563
-static void __p_branch_sample_type(char *buf, size_t size, u64 value)
1564
-{
1565
-#define bit_name(n) { PERF_SAMPLE_BRANCH_##n, #n }
1566
- struct bit_names bits[] = {
1567
- bit_name(USER), bit_name(KERNEL), bit_name(HV), bit_name(ANY),
1568
- bit_name(ANY_CALL), bit_name(ANY_RETURN), bit_name(IND_CALL),
1569
- bit_name(ABORT_TX), bit_name(IN_TX), bit_name(NO_TX),
1570
- bit_name(COND), bit_name(CALL_STACK), bit_name(IND_JUMP),
1571
- bit_name(CALL), bit_name(NO_FLAGS), bit_name(NO_CYCLES),
1572
- { .name = NULL, }
1573
- };
1574
-#undef bit_name
1575
- __p_bits(buf, size, value, bits);
1576
-}
1577
-
1578
-static void __p_read_format(char *buf, size_t size, u64 value)
1579
-{
1580
-#define bit_name(n) { PERF_FORMAT_##n, #n }
1581
- struct bit_names bits[] = {
1582
- bit_name(TOTAL_TIME_ENABLED), bit_name(TOTAL_TIME_RUNNING),
1583
- bit_name(ID), bit_name(GROUP),
1584
- { .name = NULL, }
1585
- };
1586
-#undef bit_name
1587
- __p_bits(buf, size, value, bits);
1588
-}
1589
-
1590
-#define BUF_SIZE 1024
1591
-
1592
-#define p_hex(val) snprintf(buf, BUF_SIZE, "%#"PRIx64, (uint64_t)(val))
1593
-#define p_unsigned(val) snprintf(buf, BUF_SIZE, "%"PRIu64, (uint64_t)(val))
1594
-#define p_signed(val) snprintf(buf, BUF_SIZE, "%"PRId64, (int64_t)(val))
1595
-#define p_sample_type(val) __p_sample_type(buf, BUF_SIZE, val)
1596
-#define p_branch_sample_type(val) __p_branch_sample_type(buf, BUF_SIZE, val)
1597
-#define p_read_format(val) __p_read_format(buf, BUF_SIZE, val)
1598
-
1599
-#define PRINT_ATTRn(_n, _f, _p) \
1600
-do { \
1601
- if (attr->_f) { \
1602
- _p(attr->_f); \
1603
- ret += attr__fprintf(fp, _n, buf, priv);\
1604
- } \
1605
-} while (0)
1606
-
1607
-#define PRINT_ATTRf(_f, _p) PRINT_ATTRn(#_f, _f, _p)
1608
-
1609
-int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
1610
- attr__fprintf_f attr__fprintf, void *priv)
1611
-{
1612
- char buf[BUF_SIZE];
1613
- int ret = 0;
1614
-
1615
- PRINT_ATTRf(type, p_unsigned);
1616
- PRINT_ATTRf(size, p_unsigned);
1617
- PRINT_ATTRf(config, p_hex);
1618
- PRINT_ATTRn("{ sample_period, sample_freq }", sample_period, p_unsigned);
1619
- PRINT_ATTRf(sample_type, p_sample_type);
1620
- PRINT_ATTRf(read_format, p_read_format);
1621
-
1622
- PRINT_ATTRf(disabled, p_unsigned);
1623
- PRINT_ATTRf(inherit, p_unsigned);
1624
- PRINT_ATTRf(pinned, p_unsigned);
1625
- PRINT_ATTRf(exclusive, p_unsigned);
1626
- PRINT_ATTRf(exclude_user, p_unsigned);
1627
- PRINT_ATTRf(exclude_kernel, p_unsigned);
1628
- PRINT_ATTRf(exclude_hv, p_unsigned);
1629
- PRINT_ATTRf(exclude_idle, p_unsigned);
1630
- PRINT_ATTRf(mmap, p_unsigned);
1631
- PRINT_ATTRf(comm, p_unsigned);
1632
- PRINT_ATTRf(freq, p_unsigned);
1633
- PRINT_ATTRf(inherit_stat, p_unsigned);
1634
- PRINT_ATTRf(enable_on_exec, p_unsigned);
1635
- PRINT_ATTRf(task, p_unsigned);
1636
- PRINT_ATTRf(watermark, p_unsigned);
1637
- PRINT_ATTRf(precise_ip, p_unsigned);
1638
- PRINT_ATTRf(mmap_data, p_unsigned);
1639
- PRINT_ATTRf(sample_id_all, p_unsigned);
1640
- PRINT_ATTRf(exclude_host, p_unsigned);
1641
- PRINT_ATTRf(exclude_guest, p_unsigned);
1642
- PRINT_ATTRf(exclude_callchain_kernel, p_unsigned);
1643
- PRINT_ATTRf(exclude_callchain_user, p_unsigned);
1644
- PRINT_ATTRf(mmap2, p_unsigned);
1645
- PRINT_ATTRf(comm_exec, p_unsigned);
1646
- PRINT_ATTRf(use_clockid, p_unsigned);
1647
- PRINT_ATTRf(context_switch, p_unsigned);
1648
- PRINT_ATTRf(write_backward, p_unsigned);
1649
- PRINT_ATTRf(namespaces, p_unsigned);
1650
-
1651
- PRINT_ATTRn("{ wakeup_events, wakeup_watermark }", wakeup_events, p_unsigned);
1652
- PRINT_ATTRf(bp_type, p_unsigned);
1653
- PRINT_ATTRn("{ bp_addr, config1 }", bp_addr, p_hex);
1654
- PRINT_ATTRn("{ bp_len, config2 }", bp_len, p_hex);
1655
- PRINT_ATTRf(branch_sample_type, p_branch_sample_type);
1656
- PRINT_ATTRf(sample_regs_user, p_hex);
1657
- PRINT_ATTRf(sample_stack_user, p_unsigned);
1658
- PRINT_ATTRf(clockid, p_signed);
1659
- PRINT_ATTRf(sample_regs_intr, p_hex);
1660
- PRINT_ATTRf(aux_watermark, p_unsigned);
1661
- PRINT_ATTRf(sample_max_stack, p_unsigned);
1662
-
1663
- return ret;
1664
-}
1665
-
1666
-static int __open_attr__fprintf(FILE *fp, const char *name, const char *val,
1667
- void *priv __maybe_unused)
1668
-{
1669
- return fprintf(fp, " %-32s %s\n", name, val);
1670
-}
1671
-
1672
-static void perf_evsel__remove_fd(struct perf_evsel *pos,
1579
+static void perf_evsel__remove_fd(struct evsel *pos,
16731580 int nr_cpus, int nr_threads,
16741581 int thread_idx)
16751582 {
....@@ -1678,11 +1585,11 @@
16781585 FD(pos, cpu, thread) = FD(pos, cpu, thread + 1);
16791586 }
16801587
1681
-static int update_fds(struct perf_evsel *evsel,
1588
+static int update_fds(struct evsel *evsel,
16821589 int nr_cpus, int cpu_idx,
16831590 int nr_threads, int thread_idx)
16841591 {
1685
- struct perf_evsel *pos;
1592
+ struct evsel *pos;
16861593
16871594 if (cpu_idx >= nr_cpus || thread_idx >= nr_threads)
16881595 return -EINVAL;
....@@ -1702,18 +1609,18 @@
17021609 return 0;
17031610 }
17041611
1705
-static bool ignore_missing_thread(struct perf_evsel *evsel,
1612
+static bool ignore_missing_thread(struct evsel *evsel,
17061613 int nr_cpus, int cpu,
1707
- struct thread_map *threads,
1614
+ struct perf_thread_map *threads,
17081615 int thread, int err)
17091616 {
1710
- pid_t ignore_pid = thread_map__pid(threads, thread);
1617
+ pid_t ignore_pid = perf_thread_map__pid(threads, thread);
17111618
17121619 if (!evsel->ignore_missing_thread)
17131620 return false;
17141621
17151622 /* The system wide setup does not work with threads. */
1716
- if (evsel->system_wide)
1623
+ if (evsel->core.system_wide)
17171624 return false;
17181625
17191626 /* The -ESRCH is perf event syscall errno for pid's not found. */
....@@ -1739,22 +1646,77 @@
17391646 return true;
17401647 }
17411648
1742
-int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
1743
- struct thread_map *threads)
1649
+static int __open_attr__fprintf(FILE *fp, const char *name, const char *val,
1650
+ void *priv __maybe_unused)
1651
+{
1652
+ return fprintf(fp, " %-32s %s\n", name, val);
1653
+}
1654
+
1655
+static void display_attr(struct perf_event_attr *attr)
1656
+{
1657
+ if (verbose >= 2 || debug_peo_args) {
1658
+ fprintf(stderr, "%.60s\n", graph_dotted_line);
1659
+ fprintf(stderr, "perf_event_attr:\n");
1660
+ perf_event_attr__fprintf(stderr, attr, __open_attr__fprintf, NULL);
1661
+ fprintf(stderr, "%.60s\n", graph_dotted_line);
1662
+ }
1663
+}
1664
+
1665
+static int perf_event_open(struct evsel *evsel,
1666
+ pid_t pid, int cpu, int group_fd,
1667
+ unsigned long flags)
1668
+{
1669
+ int precise_ip = evsel->core.attr.precise_ip;
1670
+ int fd;
1671
+
1672
+ while (1) {
1673
+ pr_debug2_peo("sys_perf_event_open: pid %d cpu %d group_fd %d flags %#lx",
1674
+ pid, cpu, group_fd, flags);
1675
+
1676
+ fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, group_fd, flags);
1677
+ if (fd >= 0)
1678
+ break;
1679
+
1680
+ /* Do not try less precise if not requested. */
1681
+ if (!evsel->precise_max)
1682
+ break;
1683
+
1684
+ /*
1685
+ * We tried all the precise_ip values, and it's
1686
+ * still failing, so leave it to standard fallback.
1687
+ */
1688
+ if (!evsel->core.attr.precise_ip) {
1689
+ evsel->core.attr.precise_ip = precise_ip;
1690
+ break;
1691
+ }
1692
+
1693
+ pr_debug2_peo("\nsys_perf_event_open failed, error %d\n", -ENOTSUP);
1694
+ evsel->core.attr.precise_ip--;
1695
+ pr_debug2_peo("decreasing precise_ip by one (%d)\n", evsel->core.attr.precise_ip);
1696
+ display_attr(&evsel->core.attr);
1697
+ }
1698
+
1699
+ return fd;
1700
+}
1701
+
1702
+static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
1703
+ struct perf_thread_map *threads,
1704
+ int start_cpu, int end_cpu)
17441705 {
17451706 int cpu, thread, nthreads;
17461707 unsigned long flags = PERF_FLAG_FD_CLOEXEC;
1747
- int pid = -1, err;
1708
+ int pid = -1, err, old_errno;
17481709 enum { NO_CHANGE, SET_TO_MAX, INCREASED_MAX } set_rlimit = NO_CHANGE;
17491710
1750
- if (perf_missing_features.write_backward && evsel->attr.write_backward)
1711
+ if ((perf_missing_features.write_backward && evsel->core.attr.write_backward) ||
1712
+ (perf_missing_features.aux_output && evsel->core.attr.aux_output))
17511713 return -EINVAL;
17521714
17531715 if (cpus == NULL) {
1754
- static struct cpu_map *empty_cpu_map;
1716
+ static struct perf_cpu_map *empty_cpu_map;
17551717
17561718 if (empty_cpu_map == NULL) {
1757
- empty_cpu_map = cpu_map__dummy_new();
1719
+ empty_cpu_map = perf_cpu_map__dummy_new();
17581720 if (empty_cpu_map == NULL)
17591721 return -ENOMEM;
17601722 }
....@@ -1763,7 +1725,7 @@
17631725 }
17641726
17651727 if (threads == NULL) {
1766
- static struct thread_map *empty_thread_map;
1728
+ static struct perf_thread_map *empty_thread_map;
17671729
17681730 if (empty_thread_map == NULL) {
17691731 empty_thread_map = thread_map__new_by_tid(-1);
....@@ -1774,13 +1736,13 @@
17741736 threads = empty_thread_map;
17751737 }
17761738
1777
- if (evsel->system_wide)
1739
+ if (evsel->core.system_wide)
17781740 nthreads = 1;
17791741 else
17801742 nthreads = threads->nr;
17811743
1782
- if (evsel->fd == NULL &&
1783
- perf_evsel__alloc_fd(evsel, cpus->nr, nthreads) < 0)
1744
+ if (evsel->core.fd == NULL &&
1745
+ perf_evsel__alloc_fd(&evsel->core, cpus->nr, nthreads) < 0)
17841746 return -ENOMEM;
17851747
17861748 if (evsel->cgrp) {
....@@ -1790,52 +1752,55 @@
17901752
17911753 fallback_missing_features:
17921754 if (perf_missing_features.clockid_wrong)
1793
- evsel->attr.clockid = CLOCK_MONOTONIC; /* should always work */
1755
+ evsel->core.attr.clockid = CLOCK_MONOTONIC; /* should always work */
17941756 if (perf_missing_features.clockid) {
1795
- evsel->attr.use_clockid = 0;
1796
- evsel->attr.clockid = 0;
1757
+ evsel->core.attr.use_clockid = 0;
1758
+ evsel->core.attr.clockid = 0;
17971759 }
17981760 if (perf_missing_features.cloexec)
17991761 flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC;
18001762 if (perf_missing_features.mmap2)
1801
- evsel->attr.mmap2 = 0;
1763
+ evsel->core.attr.mmap2 = 0;
18021764 if (perf_missing_features.exclude_guest)
1803
- evsel->attr.exclude_guest = evsel->attr.exclude_host = 0;
1765
+ evsel->core.attr.exclude_guest = evsel->core.attr.exclude_host = 0;
18041766 if (perf_missing_features.lbr_flags)
1805
- evsel->attr.branch_sample_type &= ~(PERF_SAMPLE_BRANCH_NO_FLAGS |
1767
+ evsel->core.attr.branch_sample_type &= ~(PERF_SAMPLE_BRANCH_NO_FLAGS |
18061768 PERF_SAMPLE_BRANCH_NO_CYCLES);
1807
- if (perf_missing_features.group_read && evsel->attr.inherit)
1808
- evsel->attr.read_format &= ~(PERF_FORMAT_GROUP|PERF_FORMAT_ID);
1769
+ if (perf_missing_features.group_read && evsel->core.attr.inherit)
1770
+ evsel->core.attr.read_format &= ~(PERF_FORMAT_GROUP|PERF_FORMAT_ID);
1771
+ if (perf_missing_features.ksymbol)
1772
+ evsel->core.attr.ksymbol = 0;
1773
+ if (perf_missing_features.bpf)
1774
+ evsel->core.attr.bpf_event = 0;
1775
+ if (perf_missing_features.branch_hw_idx)
1776
+ evsel->core.attr.branch_sample_type &= ~PERF_SAMPLE_BRANCH_HW_INDEX;
18091777 retry_sample_id:
18101778 if (perf_missing_features.sample_id_all)
1811
- evsel->attr.sample_id_all = 0;
1779
+ evsel->core.attr.sample_id_all = 0;
18121780
1813
- if (verbose >= 2) {
1814
- fprintf(stderr, "%.60s\n", graph_dotted_line);
1815
- fprintf(stderr, "perf_event_attr:\n");
1816
- perf_event_attr__fprintf(stderr, &evsel->attr, __open_attr__fprintf, NULL);
1817
- fprintf(stderr, "%.60s\n", graph_dotted_line);
1818
- }
1781
+ display_attr(&evsel->core.attr);
18191782
1820
- for (cpu = 0; cpu < cpus->nr; cpu++) {
1783
+ for (cpu = start_cpu; cpu < end_cpu; cpu++) {
18211784
18221785 for (thread = 0; thread < nthreads; thread++) {
18231786 int fd, group_fd;
18241787
1825
- if (!evsel->cgrp && !evsel->system_wide)
1826
- pid = thread_map__pid(threads, thread);
1788
+ if (!evsel->cgrp && !evsel->core.system_wide)
1789
+ pid = perf_thread_map__pid(threads, thread);
18271790
18281791 group_fd = get_group_fd(evsel, cpu, thread);
18291792 retry_open:
1830
- pr_debug2("sys_perf_event_open: pid %d cpu %d group_fd %d flags %#lx",
1831
- pid, cpus->map[cpu], group_fd, flags);
1832
-
18331793 test_attr__ready();
18341794
1835
- fd = sys_perf_event_open(&evsel->attr, pid, cpus->map[cpu],
1836
- group_fd, flags);
1795
+ fd = perf_event_open(evsel, pid, cpus->map[cpu],
1796
+ group_fd, flags);
18371797
18381798 FD(evsel, cpu, thread) = fd;
1799
+
1800
+ if (unlikely(test_attr__enabled)) {
1801
+ test_attr__open(&evsel->core.attr, pid, cpus->map[cpu],
1802
+ fd, group_fd, flags);
1803
+ }
18391804
18401805 if (fd < 0) {
18411806 err = -errno;
....@@ -1854,12 +1819,12 @@
18541819 continue;
18551820 }
18561821
1857
- pr_debug2("\nsys_perf_event_open failed, error %d\n",
1822
+ pr_debug2_peo("\nsys_perf_event_open failed, error %d\n",
18581823 err);
18591824 goto try_fallback;
18601825 }
18611826
1862
- pr_debug2(" = %d\n", fd);
1827
+ pr_debug2_peo(" = %d\n", fd);
18631828
18641829 if (evsel->bpf_fd >= 0) {
18651830 int evt_fd = fd;
....@@ -1880,8 +1845,7 @@
18801845
18811846 /*
18821847 * If we succeeded but had to kill clockid, fail and
1883
- * have perf_evsel__open_strerror() print us a nice
1884
- * error.
1848
+ * have evsel__open_strerror() print us a nice error.
18851849 */
18861850 if (perf_missing_features.clockid ||
18871851 perf_missing_features.clockid_wrong) {
....@@ -1900,8 +1864,8 @@
19001864 */
19011865 if (err == -EMFILE && set_rlimit < INCREASED_MAX) {
19021866 struct rlimit l;
1903
- int old_errno = errno;
19041867
1868
+ old_errno = errno;
19051869 if (getrlimit(RLIMIT_NOFILE, &l) == 0) {
19061870 if (set_rlimit == NO_CHANGE)
19071871 l.rlim_cur = l.rlim_max;
....@@ -1925,91 +1889,120 @@
19251889 * Must probe features in the order they were added to the
19261890 * perf_event_attr interface.
19271891 */
1928
- if (!perf_missing_features.write_backward && evsel->attr.write_backward) {
1929
- perf_missing_features.write_backward = true;
1930
- pr_debug2("switching off write_backward\n");
1892
+ if (!perf_missing_features.cgroup && evsel->core.attr.cgroup) {
1893
+ perf_missing_features.cgroup = true;
1894
+ pr_debug2_peo("Kernel has no cgroup sampling support, bailing out\n");
19311895 goto out_close;
1932
- } else if (!perf_missing_features.clockid_wrong && evsel->attr.use_clockid) {
1933
- perf_missing_features.clockid_wrong = true;
1934
- pr_debug2("switching off clockid\n");
1896
+ } else if (!perf_missing_features.branch_hw_idx &&
1897
+ (evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_HW_INDEX)) {
1898
+ perf_missing_features.branch_hw_idx = true;
1899
+ pr_debug2("switching off branch HW index support\n");
19351900 goto fallback_missing_features;
1936
- } else if (!perf_missing_features.clockid && evsel->attr.use_clockid) {
1901
+ } else if (!perf_missing_features.aux_output && evsel->core.attr.aux_output) {
1902
+ perf_missing_features.aux_output = true;
1903
+ pr_debug2_peo("Kernel has no attr.aux_output support, bailing out\n");
1904
+ goto out_close;
1905
+ } else if (!perf_missing_features.bpf && evsel->core.attr.bpf_event) {
1906
+ perf_missing_features.bpf = true;
1907
+ pr_debug2_peo("switching off bpf_event\n");
1908
+ goto fallback_missing_features;
1909
+ } else if (!perf_missing_features.ksymbol && evsel->core.attr.ksymbol) {
1910
+ perf_missing_features.ksymbol = true;
1911
+ pr_debug2_peo("switching off ksymbol\n");
1912
+ goto fallback_missing_features;
1913
+ } else if (!perf_missing_features.write_backward && evsel->core.attr.write_backward) {
1914
+ perf_missing_features.write_backward = true;
1915
+ pr_debug2_peo("switching off write_backward\n");
1916
+ goto out_close;
1917
+ } else if (!perf_missing_features.clockid_wrong && evsel->core.attr.use_clockid) {
1918
+ perf_missing_features.clockid_wrong = true;
1919
+ pr_debug2_peo("switching off clockid\n");
1920
+ goto fallback_missing_features;
1921
+ } else if (!perf_missing_features.clockid && evsel->core.attr.use_clockid) {
19371922 perf_missing_features.clockid = true;
1938
- pr_debug2("switching off use_clockid\n");
1923
+ pr_debug2_peo("switching off use_clockid\n");
19391924 goto fallback_missing_features;
19401925 } else if (!perf_missing_features.cloexec && (flags & PERF_FLAG_FD_CLOEXEC)) {
19411926 perf_missing_features.cloexec = true;
1942
- pr_debug2("switching off cloexec flag\n");
1927
+ pr_debug2_peo("switching off cloexec flag\n");
19431928 goto fallback_missing_features;
1944
- } else if (!perf_missing_features.mmap2 && evsel->attr.mmap2) {
1929
+ } else if (!perf_missing_features.mmap2 && evsel->core.attr.mmap2) {
19451930 perf_missing_features.mmap2 = true;
1946
- pr_debug2("switching off mmap2\n");
1931
+ pr_debug2_peo("switching off mmap2\n");
19471932 goto fallback_missing_features;
19481933 } else if (!perf_missing_features.exclude_guest &&
1949
- (evsel->attr.exclude_guest || evsel->attr.exclude_host)) {
1934
+ (evsel->core.attr.exclude_guest || evsel->core.attr.exclude_host)) {
19501935 perf_missing_features.exclude_guest = true;
1951
- pr_debug2("switching off exclude_guest, exclude_host\n");
1936
+ pr_debug2_peo("switching off exclude_guest, exclude_host\n");
19521937 goto fallback_missing_features;
19531938 } else if (!perf_missing_features.sample_id_all) {
19541939 perf_missing_features.sample_id_all = true;
1955
- pr_debug2("switching off sample_id_all\n");
1940
+ pr_debug2_peo("switching off sample_id_all\n");
19561941 goto retry_sample_id;
19571942 } else if (!perf_missing_features.lbr_flags &&
1958
- (evsel->attr.branch_sample_type &
1943
+ (evsel->core.attr.branch_sample_type &
19591944 (PERF_SAMPLE_BRANCH_NO_CYCLES |
19601945 PERF_SAMPLE_BRANCH_NO_FLAGS))) {
19611946 perf_missing_features.lbr_flags = true;
1962
- pr_debug2("switching off branch sample type no (cycles/flags)\n");
1947
+ pr_debug2_peo("switching off branch sample type no (cycles/flags)\n");
19631948 goto fallback_missing_features;
19641949 } else if (!perf_missing_features.group_read &&
1965
- evsel->attr.inherit &&
1966
- (evsel->attr.read_format & PERF_FORMAT_GROUP) &&
1967
- perf_evsel__is_group_leader(evsel)) {
1950
+ evsel->core.attr.inherit &&
1951
+ (evsel->core.attr.read_format & PERF_FORMAT_GROUP) &&
1952
+ evsel__is_group_leader(evsel)) {
19681953 perf_missing_features.group_read = true;
1969
- pr_debug2("switching off group read\n");
1954
+ pr_debug2_peo("switching off group read\n");
19701955 goto fallback_missing_features;
19711956 }
19721957 out_close:
19731958 if (err)
19741959 threads->err_thread = thread;
19751960
1961
+ old_errno = errno;
19761962 do {
19771963 while (--thread >= 0) {
1978
- close(FD(evsel, cpu, thread));
1964
+ if (FD(evsel, cpu, thread) >= 0)
1965
+ close(FD(evsel, cpu, thread));
19791966 FD(evsel, cpu, thread) = -1;
19801967 }
19811968 thread = nthreads;
19821969 } while (--cpu >= 0);
1970
+ errno = old_errno;
19831971 return err;
19841972 }
19851973
1986
-void perf_evsel__close(struct perf_evsel *evsel)
1974
+int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
1975
+ struct perf_thread_map *threads)
19871976 {
1988
- if (evsel->fd == NULL)
1989
- return;
1990
-
1991
- perf_evsel__close_fd(evsel);
1992
- perf_evsel__free_fd(evsel);
1977
+ return evsel__open_cpu(evsel, cpus, threads, 0, cpus ? cpus->nr : 1);
19931978 }
19941979
1995
-int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
1996
- struct cpu_map *cpus)
1980
+void evsel__close(struct evsel *evsel)
19971981 {
1998
- return perf_evsel__open(evsel, cpus, NULL);
1982
+ perf_evsel__close(&evsel->core);
1983
+ perf_evsel__free_id(&evsel->core);
19991984 }
20001985
2001
-int perf_evsel__open_per_thread(struct perf_evsel *evsel,
2002
- struct thread_map *threads)
1986
+int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu)
20031987 {
2004
- return perf_evsel__open(evsel, NULL, threads);
1988
+ if (cpu == -1)
1989
+ return evsel__open_cpu(evsel, cpus, NULL, 0,
1990
+ cpus ? cpus->nr : 1);
1991
+
1992
+ return evsel__open_cpu(evsel, cpus, NULL, cpu, cpu + 1);
20051993 }
20061994
2007
-static int perf_evsel__parse_id_sample(const struct perf_evsel *evsel,
1995
+int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads)
1996
+{
1997
+ return evsel__open(evsel, NULL, threads);
1998
+}
1999
+
2000
+static int perf_evsel__parse_id_sample(const struct evsel *evsel,
20082001 const union perf_event *event,
20092002 struct perf_sample *sample)
20102003 {
2011
- u64 type = evsel->attr.sample_type;
2012
- const u64 *array = event->sample.array;
2004
+ u64 type = evsel->core.attr.sample_type;
2005
+ const __u64 *array = event->sample.array;
20132006 bool swapped = evsel->needs_swap;
20142007 union u64_swap u;
20152008
....@@ -2094,12 +2087,12 @@
20942087 return 0;
20952088 }
20962089
2097
-int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
2098
- struct perf_sample *data)
2090
+int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
2091
+ struct perf_sample *data)
20992092 {
2100
- u64 type = evsel->attr.sample_type;
2093
+ u64 type = evsel->core.attr.sample_type;
21012094 bool swapped = evsel->needs_swap;
2102
- const u64 *array;
2095
+ const __u64 *array;
21032096 u16 max_size = event->header.size;
21042097 const void *endp = (void *)event + max_size;
21052098 u64 sz;
....@@ -2113,14 +2106,14 @@
21132106 memset(data, 0, sizeof(*data));
21142107 data->cpu = data->pid = data->tid = -1;
21152108 data->stream_id = data->id = data->time = -1ULL;
2116
- data->period = evsel->attr.sample_period;
2109
+ data->period = evsel->core.attr.sample_period;
21172110 data->cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
21182111 data->misc = event->header.misc;
21192112 data->id = -1ULL;
21202113 data->data_src = PERF_MEM_DATA_SRC_NONE;
21212114
21222115 if (event->header.type != PERF_RECORD_SAMPLE) {
2123
- if (!evsel->attr.sample_id_all)
2116
+ if (!evsel->core.attr.sample_id_all)
21242117 return 0;
21252118 return perf_evsel__parse_id_sample(evsel, event, data);
21262119 }
....@@ -2193,7 +2186,7 @@
21932186 }
21942187
21952188 if (type & PERF_SAMPLE_READ) {
2196
- u64 read_format = evsel->attr.read_format;
2189
+ u64 read_format = evsel->core.attr.read_format;
21972190
21982191 OVERFLOW_CHECK_u64(array);
21992192 if (read_format & PERF_FORMAT_GROUP)
....@@ -2235,7 +2228,7 @@
22352228 }
22362229 }
22372230
2238
- if (evsel__has_callchain(evsel)) {
2231
+ if (type & PERF_SAMPLE_CALLCHAIN) {
22392232 const u64 max_callchain_nr = UINT64_MAX / sizeof(u64);
22402233
22412234 OVERFLOW_CHECK_u64(array);
....@@ -2287,7 +2280,12 @@
22872280
22882281 if (data->branch_stack->nr > max_branch_nr)
22892282 return -EFAULT;
2283
+
22902284 sz = data->branch_stack->nr * sizeof(struct branch_entry);
2285
+ if (evsel__has_branch_hw_idx(evsel))
2286
+ sz += sizeof(u64);
2287
+ else
2288
+ data->no_hw_idx = true;
22912289 OVERFLOW_CHECK(array, sz, max_size);
22922290 array = (void *)array + sz;
22932291 }
....@@ -2298,9 +2296,9 @@
22982296 array++;
22992297
23002298 if (data->user_regs.abi) {
2301
- u64 mask = evsel->attr.sample_regs_user;
2299
+ u64 mask = evsel->core.attr.sample_regs_user;
23022300
2303
- sz = hweight_long(mask) * sizeof(u64);
2301
+ sz = hweight64(mask) * sizeof(u64);
23042302 OVERFLOW_CHECK(array, sz, max_size);
23052303 data->user_regs.mask = mask;
23062304 data->user_regs.regs = (u64 *)array;
....@@ -2354,9 +2352,9 @@
23542352 array++;
23552353
23562354 if (data->intr_regs.abi != PERF_SAMPLE_REGS_ABI_NONE) {
2357
- u64 mask = evsel->attr.sample_regs_intr;
2355
+ u64 mask = evsel->core.attr.sample_regs_intr;
23582356
2359
- sz = hweight_long(mask) * sizeof(u64);
2357
+ sz = hweight64(mask) * sizeof(u64);
23602358 OVERFLOW_CHECK(array, sz, max_size);
23612359 data->intr_regs.mask = mask;
23622360 data->intr_regs.regs = (u64 *)array;
....@@ -2370,15 +2368,33 @@
23702368 array++;
23712369 }
23722370
2371
+ data->cgroup = 0;
2372
+ if (type & PERF_SAMPLE_CGROUP) {
2373
+ data->cgroup = *array;
2374
+ array++;
2375
+ }
2376
+
2377
+ if (type & PERF_SAMPLE_AUX) {
2378
+ OVERFLOW_CHECK_u64(array);
2379
+ sz = *array++;
2380
+
2381
+ OVERFLOW_CHECK(array, sz, max_size);
2382
+ /* Undo swap of data */
2383
+ if (swapped)
2384
+ mem_bswap_64((char *)array, sz);
2385
+ data->aux_sample.size = sz;
2386
+ data->aux_sample.data = (char *)array;
2387
+ array = (void *)array + sz;
2388
+ }
2389
+
23732390 return 0;
23742391 }
23752392
2376
-int perf_evsel__parse_sample_timestamp(struct perf_evsel *evsel,
2377
- union perf_event *event,
2378
- u64 *timestamp)
2393
+int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event,
2394
+ u64 *timestamp)
23792395 {
2380
- u64 type = evsel->attr.sample_type;
2381
- const u64 *array;
2396
+ u64 type = evsel->core.attr.sample_type;
2397
+ const __u64 *array;
23822398
23832399 if (!(type & PERF_SAMPLE_TIME))
23842400 return -1;
....@@ -2388,7 +2404,7 @@
23882404 .time = -1ULL,
23892405 };
23902406
2391
- if (!evsel->attr.sample_id_all)
2407
+ if (!evsel->core.attr.sample_id_all)
23922408 return -1;
23932409 if (perf_evsel__parse_id_sample(evsel, event, &data))
23942410 return -1;
....@@ -2417,292 +2433,14 @@
24172433 return 0;
24182434 }
24192435
2420
-size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
2421
- u64 read_format)
2422
-{
2423
- size_t sz, result = sizeof(struct sample_event);
2424
-
2425
- if (type & PERF_SAMPLE_IDENTIFIER)
2426
- result += sizeof(u64);
2427
-
2428
- if (type & PERF_SAMPLE_IP)
2429
- result += sizeof(u64);
2430
-
2431
- if (type & PERF_SAMPLE_TID)
2432
- result += sizeof(u64);
2433
-
2434
- if (type & PERF_SAMPLE_TIME)
2435
- result += sizeof(u64);
2436
-
2437
- if (type & PERF_SAMPLE_ADDR)
2438
- result += sizeof(u64);
2439
-
2440
- if (type & PERF_SAMPLE_ID)
2441
- result += sizeof(u64);
2442
-
2443
- if (type & PERF_SAMPLE_STREAM_ID)
2444
- result += sizeof(u64);
2445
-
2446
- if (type & PERF_SAMPLE_CPU)
2447
- result += sizeof(u64);
2448
-
2449
- if (type & PERF_SAMPLE_PERIOD)
2450
- result += sizeof(u64);
2451
-
2452
- if (type & PERF_SAMPLE_READ) {
2453
- result += sizeof(u64);
2454
- if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
2455
- result += sizeof(u64);
2456
- if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
2457
- result += sizeof(u64);
2458
- /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */
2459
- if (read_format & PERF_FORMAT_GROUP) {
2460
- sz = sample->read.group.nr *
2461
- sizeof(struct sample_read_value);
2462
- result += sz;
2463
- } else {
2464
- result += sizeof(u64);
2465
- }
2466
- }
2467
-
2468
- if (type & PERF_SAMPLE_CALLCHAIN) {
2469
- sz = (sample->callchain->nr + 1) * sizeof(u64);
2470
- result += sz;
2471
- }
2472
-
2473
- if (type & PERF_SAMPLE_RAW) {
2474
- result += sizeof(u32);
2475
- result += sample->raw_size;
2476
- }
2477
-
2478
- if (type & PERF_SAMPLE_BRANCH_STACK) {
2479
- sz = sample->branch_stack->nr * sizeof(struct branch_entry);
2480
- sz += sizeof(u64);
2481
- result += sz;
2482
- }
2483
-
2484
- if (type & PERF_SAMPLE_REGS_USER) {
2485
- if (sample->user_regs.abi) {
2486
- result += sizeof(u64);
2487
- sz = hweight_long(sample->user_regs.mask) * sizeof(u64);
2488
- result += sz;
2489
- } else {
2490
- result += sizeof(u64);
2491
- }
2492
- }
2493
-
2494
- if (type & PERF_SAMPLE_STACK_USER) {
2495
- sz = sample->user_stack.size;
2496
- result += sizeof(u64);
2497
- if (sz) {
2498
- result += sz;
2499
- result += sizeof(u64);
2500
- }
2501
- }
2502
-
2503
- if (type & PERF_SAMPLE_WEIGHT)
2504
- result += sizeof(u64);
2505
-
2506
- if (type & PERF_SAMPLE_DATA_SRC)
2507
- result += sizeof(u64);
2508
-
2509
- if (type & PERF_SAMPLE_TRANSACTION)
2510
- result += sizeof(u64);
2511
-
2512
- if (type & PERF_SAMPLE_REGS_INTR) {
2513
- if (sample->intr_regs.abi) {
2514
- result += sizeof(u64);
2515
- sz = hweight_long(sample->intr_regs.mask) * sizeof(u64);
2516
- result += sz;
2517
- } else {
2518
- result += sizeof(u64);
2519
- }
2520
- }
2521
-
2522
- if (type & PERF_SAMPLE_PHYS_ADDR)
2523
- result += sizeof(u64);
2524
-
2525
- return result;
2526
-}
2527
-
2528
-int perf_event__synthesize_sample(union perf_event *event, u64 type,
2529
- u64 read_format,
2530
- const struct perf_sample *sample)
2531
-{
2532
- u64 *array;
2533
- size_t sz;
2534
- /*
2535
- * used for cross-endian analysis. See git commit 65014ab3
2536
- * for why this goofiness is needed.
2537
- */
2538
- union u64_swap u;
2539
-
2540
- array = event->sample.array;
2541
-
2542
- if (type & PERF_SAMPLE_IDENTIFIER) {
2543
- *array = sample->id;
2544
- array++;
2545
- }
2546
-
2547
- if (type & PERF_SAMPLE_IP) {
2548
- *array = sample->ip;
2549
- array++;
2550
- }
2551
-
2552
- if (type & PERF_SAMPLE_TID) {
2553
- u.val32[0] = sample->pid;
2554
- u.val32[1] = sample->tid;
2555
- *array = u.val64;
2556
- array++;
2557
- }
2558
-
2559
- if (type & PERF_SAMPLE_TIME) {
2560
- *array = sample->time;
2561
- array++;
2562
- }
2563
-
2564
- if (type & PERF_SAMPLE_ADDR) {
2565
- *array = sample->addr;
2566
- array++;
2567
- }
2568
-
2569
- if (type & PERF_SAMPLE_ID) {
2570
- *array = sample->id;
2571
- array++;
2572
- }
2573
-
2574
- if (type & PERF_SAMPLE_STREAM_ID) {
2575
- *array = sample->stream_id;
2576
- array++;
2577
- }
2578
-
2579
- if (type & PERF_SAMPLE_CPU) {
2580
- u.val32[0] = sample->cpu;
2581
- u.val32[1] = 0;
2582
- *array = u.val64;
2583
- array++;
2584
- }
2585
-
2586
- if (type & PERF_SAMPLE_PERIOD) {
2587
- *array = sample->period;
2588
- array++;
2589
- }
2590
-
2591
- if (type & PERF_SAMPLE_READ) {
2592
- if (read_format & PERF_FORMAT_GROUP)
2593
- *array = sample->read.group.nr;
2594
- else
2595
- *array = sample->read.one.value;
2596
- array++;
2597
-
2598
- if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
2599
- *array = sample->read.time_enabled;
2600
- array++;
2601
- }
2602
-
2603
- if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
2604
- *array = sample->read.time_running;
2605
- array++;
2606
- }
2607
-
2608
- /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */
2609
- if (read_format & PERF_FORMAT_GROUP) {
2610
- sz = sample->read.group.nr *
2611
- sizeof(struct sample_read_value);
2612
- memcpy(array, sample->read.group.values, sz);
2613
- array = (void *)array + sz;
2614
- } else {
2615
- *array = sample->read.one.id;
2616
- array++;
2617
- }
2618
- }
2619
-
2620
- if (type & PERF_SAMPLE_CALLCHAIN) {
2621
- sz = (sample->callchain->nr + 1) * sizeof(u64);
2622
- memcpy(array, sample->callchain, sz);
2623
- array = (void *)array + sz;
2624
- }
2625
-
2626
- if (type & PERF_SAMPLE_RAW) {
2627
- u.val32[0] = sample->raw_size;
2628
- *array = u.val64;
2629
- array = (void *)array + sizeof(u32);
2630
-
2631
- memcpy(array, sample->raw_data, sample->raw_size);
2632
- array = (void *)array + sample->raw_size;
2633
- }
2634
-
2635
- if (type & PERF_SAMPLE_BRANCH_STACK) {
2636
- sz = sample->branch_stack->nr * sizeof(struct branch_entry);
2637
- sz += sizeof(u64);
2638
- memcpy(array, sample->branch_stack, sz);
2639
- array = (void *)array + sz;
2640
- }
2641
-
2642
- if (type & PERF_SAMPLE_REGS_USER) {
2643
- if (sample->user_regs.abi) {
2644
- *array++ = sample->user_regs.abi;
2645
- sz = hweight_long(sample->user_regs.mask) * sizeof(u64);
2646
- memcpy(array, sample->user_regs.regs, sz);
2647
- array = (void *)array + sz;
2648
- } else {
2649
- *array++ = 0;
2650
- }
2651
- }
2652
-
2653
- if (type & PERF_SAMPLE_STACK_USER) {
2654
- sz = sample->user_stack.size;
2655
- *array++ = sz;
2656
- if (sz) {
2657
- memcpy(array, sample->user_stack.data, sz);
2658
- array = (void *)array + sz;
2659
- *array++ = sz;
2660
- }
2661
- }
2662
-
2663
- if (type & PERF_SAMPLE_WEIGHT) {
2664
- *array = sample->weight;
2665
- array++;
2666
- }
2667
-
2668
- if (type & PERF_SAMPLE_DATA_SRC) {
2669
- *array = sample->data_src;
2670
- array++;
2671
- }
2672
-
2673
- if (type & PERF_SAMPLE_TRANSACTION) {
2674
- *array = sample->transaction;
2675
- array++;
2676
- }
2677
-
2678
- if (type & PERF_SAMPLE_REGS_INTR) {
2679
- if (sample->intr_regs.abi) {
2680
- *array++ = sample->intr_regs.abi;
2681
- sz = hweight_long(sample->intr_regs.mask) * sizeof(u64);
2682
- memcpy(array, sample->intr_regs.regs, sz);
2683
- array = (void *)array + sz;
2684
- } else {
2685
- *array++ = 0;
2686
- }
2687
- }
2688
-
2689
- if (type & PERF_SAMPLE_PHYS_ADDR) {
2690
- *array = sample->phys_addr;
2691
- array++;
2692
- }
2693
-
2694
- return 0;
2695
-}
2696
-
2697
-struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name)
2436
+struct tep_format_field *evsel__field(struct evsel *evsel, const char *name)
26982437 {
26992438 return tep_find_field(evsel->tp_format, name);
27002439 }
27012440
2702
-void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
2703
- const char *name)
2441
+void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name)
27042442 {
2705
- struct format_field *field = perf_evsel__field(evsel, name);
2443
+ struct tep_format_field *field = evsel__field(evsel, name);
27062444 int offset;
27072445
27082446 if (!field)
....@@ -2710,7 +2448,7 @@
27102448
27112449 offset = field->offset;
27122450
2713
- if (field->flags & FIELD_IS_DYNAMIC) {
2451
+ if (field->flags & TEP_FIELD_IS_DYNAMIC) {
27142452 offset = *(int *)(sample->raw_data + field->offset);
27152453 offset &= 0xffff;
27162454 }
....@@ -2718,7 +2456,7 @@
27182456 return sample->raw_data + offset;
27192457 }
27202458
2721
-u64 format_field__intval(struct format_field *field, struct perf_sample *sample,
2459
+u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sample,
27222460 bool needs_swap)
27232461 {
27242462 u64 value;
....@@ -2757,10 +2495,9 @@
27572495 return 0;
27582496 }
27592497
2760
-u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
2761
- const char *name)
2498
+u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name)
27622499 {
2763
- struct format_field *field = perf_evsel__field(evsel, name);
2500
+ struct tep_format_field *field = evsel__field(evsel, name);
27642501
27652502 if (!field)
27662503 return 0;
....@@ -2768,14 +2505,13 @@
27682505 return field ? format_field__intval(field, sample, evsel->needs_swap) : 0;
27692506 }
27702507
2771
-bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
2772
- char *msg, size_t msgsize)
2508
+bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize)
27732509 {
27742510 int paranoid;
27752511
27762512 if ((err == ENOENT || err == ENXIO || err == ENODEV) &&
2777
- evsel->attr.type == PERF_TYPE_HARDWARE &&
2778
- evsel->attr.config == PERF_COUNT_HW_CPU_CYCLES) {
2513
+ evsel->core.attr.type == PERF_TYPE_HARDWARE &&
2514
+ evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES) {
27792515 /*
27802516 * If it's cycles then fall back to hrtimer based
27812517 * cpu-clock-tick sw counter, which is always available even if
....@@ -2787,20 +2523,24 @@
27872523 scnprintf(msg, msgsize, "%s",
27882524 "The cycles event is not supported, trying to fall back to cpu-clock-ticks");
27892525
2790
- evsel->attr.type = PERF_TYPE_SOFTWARE;
2791
- evsel->attr.config = PERF_COUNT_SW_CPU_CLOCK;
2526
+ evsel->core.attr.type = PERF_TYPE_SOFTWARE;
2527
+ evsel->core.attr.config = PERF_COUNT_SW_CPU_CLOCK;
27922528
27932529 zfree(&evsel->name);
27942530 return true;
2795
- } else if (err == EACCES && !evsel->attr.exclude_kernel &&
2531
+ } else if (err == EACCES && !evsel->core.attr.exclude_kernel &&
27962532 (paranoid = perf_event_paranoid()) > 1) {
2797
- const char *name = perf_evsel__name(evsel);
2533
+ const char *name = evsel__name(evsel);
27982534 char *new_name;
27992535 const char *sep = ":";
28002536
2537
+ /* If event has exclude user then don't exclude kernel. */
2538
+ if (evsel->core.attr.exclude_user)
2539
+ return false;
2540
+
28012541 /* Is there already the separator in the name. */
28022542 if (strchr(name, '/') ||
2803
- strchr(name, ':'))
2543
+ (strchr(name, ':') && !evsel->is_libpfm_event))
28042544 sep = "";
28052545
28062546 if (asprintf(&new_name, "%s%su", name, sep) < 0)
....@@ -2809,9 +2549,11 @@
28092549 if (evsel->name)
28102550 free(evsel->name);
28112551 evsel->name = new_name;
2812
- scnprintf(msg, msgsize,
2813
-"kernel.perf_event_paranoid=%d, trying to fall back to excluding kernel samples", paranoid);
2814
- evsel->attr.exclude_kernel = 1;
2552
+ scnprintf(msg, msgsize, "kernel.perf_event_paranoid=%d, trying "
2553
+ "to fall back to excluding kernel and hypervisor "
2554
+ " samples", paranoid);
2555
+ evsel->core.attr.exclude_kernel = 1;
2556
+ evsel->core.attr.exclude_hv = 1;
28152557
28162558 return true;
28172559 }
....@@ -2855,39 +2597,48 @@
28552597 return ret ? false : true;
28562598 }
28572599
2858
-int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
2859
- int err, char *msg, size_t size)
2600
+int evsel__open_strerror(struct evsel *evsel, struct target *target,
2601
+ int err, char *msg, size_t size)
28602602 {
28612603 char sbuf[STRERR_BUFSIZE];
2862
- int printed = 0;
2604
+ int printed = 0, enforced = 0;
28632605
28642606 switch (err) {
28652607 case EPERM:
28662608 case EACCES:
2609
+ printed += scnprintf(msg + printed, size - printed,
2610
+ "Access to performance monitoring and observability operations is limited.\n");
2611
+
2612
+ if (!sysfs__read_int("fs/selinux/enforce", &enforced)) {
2613
+ if (enforced) {
2614
+ printed += scnprintf(msg + printed, size - printed,
2615
+ "Enforced MAC policy settings (SELinux) can limit access to performance\n"
2616
+ "monitoring and observability operations. Inspect system audit records for\n"
2617
+ "more perf_event access control information and adjusting the policy.\n");
2618
+ }
2619
+ }
2620
+
28672621 if (err == EPERM)
2868
- printed = scnprintf(msg, size,
2869
- "No permission to enable %s event.\n\n",
2870
- perf_evsel__name(evsel));
2622
+ printed += scnprintf(msg, size,
2623
+ "No permission to enable %s event.\n\n", evsel__name(evsel));
28712624
28722625 return scnprintf(msg + printed, size - printed,
2873
- "You may not have permission to collect %sstats.\n\n"
2874
- "Consider tweaking /proc/sys/kernel/perf_event_paranoid,\n"
2875
- "which controls use of the performance events system by\n"
2876
- "unprivileged users (without CAP_SYS_ADMIN).\n\n"
2877
- "The current value is %d:\n\n"
2626
+ "Consider adjusting /proc/sys/kernel/perf_event_paranoid setting to open\n"
2627
+ "access to performance monitoring and observability operations for processes\n"
2628
+ "without CAP_PERFMON, CAP_SYS_PTRACE or CAP_SYS_ADMIN Linux capability.\n"
2629
+ "More information can be found at 'Perf events and tool security' document:\n"
2630
+ "https://www.kernel.org/doc/html/latest/admin-guide/perf-security.html\n"
2631
+ "perf_event_paranoid setting is %d:\n"
28782632 " -1: Allow use of (almost) all events by all users\n"
28792633 " Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK\n"
2880
- ">= 0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN\n"
2881
- " Disallow raw tracepoint access by users without CAP_SYS_ADMIN\n"
2882
- ">= 1: Disallow CPU event access by users without CAP_SYS_ADMIN\n"
2883
- ">= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN\n\n"
2884
- "To make this setting permanent, edit /etc/sysctl.conf too, e.g.:\n\n"
2885
- " kernel.perf_event_paranoid = -1\n" ,
2886
- target->system_wide ? "system-wide " : "",
2887
- perf_event_paranoid());
2634
+ ">= 0: Disallow raw and ftrace function tracepoint access\n"
2635
+ ">= 1: Disallow CPU event access\n"
2636
+ ">= 2: Disallow kernel profiling\n"
2637
+ "To make the adjusted perf_event_paranoid setting permanent preserve it\n"
2638
+ "in /etc/sysctl.conf (e.g. kernel.perf_event_paranoid = <setting>)",
2639
+ perf_event_paranoid());
28882640 case ENOENT:
2889
- return scnprintf(msg, size, "The %s event is not supported.",
2890
- perf_evsel__name(evsel));
2641
+ return scnprintf(msg, size, "The %s event is not supported.", evsel__name(evsel));
28912642 case EMFILE:
28922643 return scnprintf(msg, size, "%s",
28932644 "Too many events are opened.\n"
....@@ -2908,15 +2659,19 @@
29082659 "No such device - did you specify an out-of-range profile CPU?");
29092660 break;
29102661 case EOPNOTSUPP:
2911
- if (evsel->attr.sample_period != 0)
2662
+ if (evsel->core.attr.aux_output)
2663
+ return scnprintf(msg, size,
2664
+ "%s: PMU Hardware doesn't support 'aux_output' feature",
2665
+ evsel__name(evsel));
2666
+ if (evsel->core.attr.sample_period != 0)
29122667 return scnprintf(msg, size,
29132668 "%s: PMU Hardware doesn't support sampling/overflow-interrupts. Try 'perf stat'",
2914
- perf_evsel__name(evsel));
2915
- if (evsel->attr.precise_ip)
2669
+ evsel__name(evsel));
2670
+ if (evsel->core.attr.precise_ip)
29162671 return scnprintf(msg, size, "%s",
29172672 "\'precise\' request may not be supported. Try removing 'p' modifier.");
29182673 #if defined(__i386__) || defined(__x86_64__)
2919
- if (evsel->attr.type == PERF_TYPE_HARDWARE)
2674
+ if (evsel->core.attr.type == PERF_TYPE_HARDWARE)
29202675 return scnprintf(msg, size, "%s",
29212676 "No hardware sampling interrupt available.\n");
29222677 #endif
....@@ -2928,12 +2683,14 @@
29282683 "We found oprofile daemon running, please stop it and try again.");
29292684 break;
29302685 case EINVAL:
2931
- if (evsel->attr.write_backward && perf_missing_features.write_backward)
2686
+ if (evsel->core.attr.write_backward && perf_missing_features.write_backward)
29322687 return scnprintf(msg, size, "Reading from overwrite event is not supported by this kernel.");
29332688 if (perf_missing_features.clockid)
29342689 return scnprintf(msg, size, "clockid feature not supported.");
29352690 if (perf_missing_features.clockid_wrong)
29362691 return scnprintf(msg, size, "wrong clockid (%d).", clockid);
2692
+ if (perf_missing_features.aux_output)
2693
+ return scnprintf(msg, size, "The 'aux_output' feature is not supported, update the kernel.");
29372694 break;
29382695 default:
29392696 break;
....@@ -2942,13 +2699,41 @@
29422699 return scnprintf(msg, size,
29432700 "The sys_perf_event_open() syscall returned with %d (%s) for event (%s).\n"
29442701 "/bin/dmesg | grep -i perf may provide additional information.\n",
2945
- err, str_error_r(err, sbuf, sizeof(sbuf)),
2946
- perf_evsel__name(evsel));
2702
+ err, str_error_r(err, sbuf, sizeof(sbuf)), evsel__name(evsel));
29472703 }
29482704
2949
-struct perf_env *perf_evsel__env(struct perf_evsel *evsel)
2705
+struct perf_env *evsel__env(struct evsel *evsel)
29502706 {
29512707 if (evsel && evsel->evlist)
29522708 return evsel->evlist->env;
2953
- return NULL;
2709
+ return &perf_env;
2710
+}
2711
+
2712
+static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist)
2713
+{
2714
+ int cpu, thread;
2715
+
2716
+ for (cpu = 0; cpu < xyarray__max_x(evsel->core.fd); cpu++) {
2717
+ for (thread = 0; thread < xyarray__max_y(evsel->core.fd);
2718
+ thread++) {
2719
+ int fd = FD(evsel, cpu, thread);
2720
+
2721
+ if (perf_evlist__id_add_fd(&evlist->core, &evsel->core,
2722
+ cpu, thread, fd) < 0)
2723
+ return -1;
2724
+ }
2725
+ }
2726
+
2727
+ return 0;
2728
+}
2729
+
2730
+int evsel__store_ids(struct evsel *evsel, struct evlist *evlist)
2731
+{
2732
+ struct perf_cpu_map *cpus = evsel->core.cpus;
2733
+ struct perf_thread_map *threads = evsel->core.threads;
2734
+
2735
+ if (perf_evsel__alloc_id(&evsel->core, cpus->nr, threads->nr))
2736
+ return -ENOMEM;
2737
+
2738
+ return store_evsel_ids(evsel, evlist);
29542739 }