hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/tools/perf/util/auxtrace.h
....@@ -1,16 +1,7 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * auxtrace.h: AUX area trace support
34 * Copyright (c) 2013-2015, Intel Corporation.
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms and conditions of the GNU General Public License,
7
- * version 2, as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope it will be useful, but WITHOUT
10
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
- * more details.
13
- *
145 */
156
167 #ifndef __PERF_AUXTRACE_H
....@@ -20,23 +11,31 @@
2011 #include <errno.h>
2112 #include <stdbool.h>
2213 #include <stddef.h>
14
+#include <stdio.h> // FILE
2315 #include <linux/list.h>
2416 #include <linux/perf_event.h>
2517 #include <linux/types.h>
26
-
27
-#include "../perf.h"
28
-#include "event.h"
29
-#include "session.h"
30
-#include "debug.h"
18
+#include <asm/bitsperlong.h>
19
+#include <asm/barrier.h>
3120
3221 union perf_event;
3322 struct perf_session;
34
-struct perf_evlist;
23
+struct evlist;
24
+struct evsel;
3525 struct perf_tool;
26
+struct mmap;
27
+struct perf_sample;
3628 struct option;
3729 struct record_opts;
38
-struct auxtrace_info_event;
30
+struct perf_record_auxtrace_error;
31
+struct perf_record_auxtrace_info;
3932 struct events_stats;
33
+struct perf_pmu;
34
+
35
+enum auxtrace_error_type {
36
+ PERF_AUXTRACE_ERROR_ITRACE = 1,
37
+ PERF_AUXTRACE_ERROR_MAX
38
+};
4039
4140 /* Auxtrace records must have the same alignment as perf event records */
4241 #define PERF_AUXTRACE_RECORD_ALIGNMENT 8
....@@ -56,53 +55,90 @@
5655 PERF_ITRACE_PERIOD_NANOSECS,
5756 };
5857
58
+#define AUXTRACE_ERR_FLG_OVERFLOW (1 << ('o' - 'a'))
59
+#define AUXTRACE_ERR_FLG_DATA_LOST (1 << ('l' - 'a'))
60
+
61
+#define AUXTRACE_LOG_FLG_ALL_PERF_EVTS (1 << ('a' - 'a'))
62
+
5963 /**
6064 * struct itrace_synth_opts - AUX area tracing synthesis options.
6165 * @set: indicates whether or not options have been set
66
+ * @default_no_sample: Default to no sampling.
6267 * @inject: indicates the event (not just the sample) must be fully synthesized
6368 * because 'perf inject' will write it out
6469 * @instructions: whether to synthesize 'instructions' events
6570 * @branches: whether to synthesize 'branches' events
71
+ * (branch misses only for Arm SPE)
6672 * @transactions: whether to synthesize events for transactions
6773 * @ptwrites: whether to synthesize events for ptwrites
6874 * @pwr_events: whether to synthesize power events
75
+ * @other_events: whether to synthesize other events recorded due to the use of
76
+ * aux_output
6977 * @errors: whether to synthesize decoder error events
7078 * @dont_decode: whether to skip decoding entirely
7179 * @log: write a decoding log
7280 * @calls: limit branch samples to calls (can be combined with @returns)
7381 * @returns: limit branch samples to returns (can be combined with @calls)
7482 * @callchain: add callchain to 'instructions' events
83
+ * @add_callchain: add callchain to existing event records
7584 * @thread_stack: feed branches to the thread_stack
7685 * @last_branch: add branch context to 'instruction' events
86
+ * @add_last_branch: add branch context to existing event records
87
+ * @flc: whether to synthesize first level cache events
88
+ * @llc: whether to synthesize last level cache events
89
+ * @tlb: whether to synthesize TLB events
90
+ * @remote_access: whether to synthesize remote access events
7791 * @callchain_sz: maximum callchain size
7892 * @last_branch_sz: branch context size
7993 * @period: 'instructions' events period
8094 * @period_type: 'instructions' events period type
8195 * @initial_skip: skip N events at the beginning.
8296 * @cpu_bitmap: CPUs for which to synthesize events, or NULL for all
97
+ * @ptime_range: time intervals to trace or NULL
98
+ * @range_num: number of time intervals to trace
99
+ * @error_plus_flags: flags to affect what errors are reported
100
+ * @error_minus_flags: flags to affect what errors are reported
101
+ * @log_plus_flags: flags to affect what is logged
102
+ * @log_minus_flags: flags to affect what is logged
103
+ * @quick: quicker (less detailed) decoding
83104 */
84105 struct itrace_synth_opts {
85106 bool set;
107
+ bool default_no_sample;
86108 bool inject;
87109 bool instructions;
88110 bool branches;
89111 bool transactions;
90112 bool ptwrites;
91113 bool pwr_events;
114
+ bool other_events;
92115 bool errors;
93116 bool dont_decode;
94117 bool log;
95118 bool calls;
96119 bool returns;
97120 bool callchain;
121
+ bool add_callchain;
98122 bool thread_stack;
99123 bool last_branch;
124
+ bool add_last_branch;
125
+ bool flc;
126
+ bool llc;
127
+ bool tlb;
128
+ bool remote_access;
100129 unsigned int callchain_sz;
101130 unsigned int last_branch_sz;
102131 unsigned long long period;
103132 enum itrace_period_type period_type;
104133 unsigned long initial_skip;
105134 unsigned long *cpu_bitmap;
135
+ struct perf_time_interval *ptime_range;
136
+ int range_num;
137
+ unsigned int error_plus_flags;
138
+ unsigned int error_minus_flags;
139
+ unsigned int log_plus_flags;
140
+ unsigned int log_minus_flags;
141
+ unsigned int quick;
106142 };
107143
108144 /**
....@@ -135,6 +171,9 @@
135171 * struct auxtrace - session callbacks to allow AUX area data decoding.
136172 * @process_event: lets the decoder see all session events
137173 * @process_auxtrace_event: process a PERF_RECORD_AUXTRACE event
174
+ * @queue_data: queue an AUX sample or PERF_RECORD_AUXTRACE event for later
175
+ * processing
176
+ * @dump_auxtrace_sample: dump AUX area sample data
138177 * @flush_events: process any remaining data
139178 * @free_events: free resources associated with event processing
140179 * @free: free resources associated with the session
....@@ -147,10 +186,17 @@
147186 int (*process_auxtrace_event)(struct perf_session *session,
148187 union perf_event *event,
149188 struct perf_tool *tool);
189
+ int (*queue_data)(struct perf_session *session,
190
+ struct perf_sample *sample, union perf_event *event,
191
+ u64 data_offset);
192
+ void (*dump_auxtrace_sample)(struct perf_session *session,
193
+ struct perf_sample *sample);
150194 int (*flush_events)(struct perf_session *session,
151195 struct perf_tool *tool);
152196 void (*free_events)(struct perf_session *session);
153197 void (*free)(struct perf_session *session);
198
+ bool (*evsel_is_auxtrace)(struct perf_session *session,
199
+ struct evsel *evsel);
154200 };
155201
156202 /**
....@@ -307,16 +353,19 @@
307353 * @reference: provide a 64-bit reference number for auxtrace_event
308354 * @read_finish: called after reading from an auxtrace mmap
309355 * @alignment: alignment (if any) for AUX area data
356
+ * @default_aux_sample_size: default sample size for --aux sample option
357
+ * @pmu: associated pmu
358
+ * @evlist: selected events list
310359 */
311360 struct auxtrace_record {
312361 int (*recording_options)(struct auxtrace_record *itr,
313
- struct perf_evlist *evlist,
362
+ struct evlist *evlist,
314363 struct record_opts *opts);
315364 size_t (*info_priv_size)(struct auxtrace_record *itr,
316
- struct perf_evlist *evlist);
365
+ struct evlist *evlist);
317366 int (*info_fill)(struct auxtrace_record *itr,
318367 struct perf_session *session,
319
- struct auxtrace_info_event *auxtrace_info,
368
+ struct perf_record_auxtrace_info *auxtrace_info,
320369 size_t priv_size);
321370 void (*free)(struct auxtrace_record *itr);
322371 int (*snapshot_start)(struct auxtrace_record *itr);
....@@ -330,6 +379,9 @@
330379 u64 (*reference)(struct auxtrace_record *itr);
331380 int (*read_finish)(struct auxtrace_record *itr, int idx);
332381 unsigned int alignment;
382
+ unsigned int default_aux_sample_size;
383
+ struct perf_pmu *pmu;
384
+ struct evlist *evlist;
333385 };
334386
335387 /**
....@@ -373,6 +425,8 @@
373425 struct list_head head;
374426 int cnt;
375427 };
428
+
429
+struct auxtrace_cache;
376430
377431 #ifdef HAVE_AUXTRACE_SUPPORT
378432
....@@ -433,17 +487,18 @@
433487 unsigned int auxtrace_pages,
434488 bool auxtrace_overwrite);
435489 void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
436
- struct perf_evlist *evlist, int idx,
490
+ struct evlist *evlist, int idx,
437491 bool per_cpu);
438492
439493 typedef int (*process_auxtrace_t)(struct perf_tool *tool,
494
+ struct mmap *map,
440495 union perf_event *event, void *data1,
441496 size_t len1, void *data2, size_t len2);
442497
443
-int auxtrace_mmap__read(struct auxtrace_mmap *mm, struct auxtrace_record *itr,
498
+int auxtrace_mmap__read(struct mmap *map, struct auxtrace_record *itr,
444499 struct perf_tool *tool, process_auxtrace_t fn);
445500
446
-int auxtrace_mmap__read_snapshot(struct auxtrace_mmap *mm,
501
+int auxtrace_mmap__read_snapshot(struct mmap *map,
447502 struct auxtrace_record *itr,
448503 struct perf_tool *tool, process_auxtrace_t fn,
449504 size_t snapshot_size);
....@@ -453,9 +508,19 @@
453508 struct perf_session *session,
454509 union perf_event *event, off_t data_offset,
455510 struct auxtrace_buffer **buffer_ptr);
511
+struct auxtrace_queue *
512
+auxtrace_queues__sample_queue(struct auxtrace_queues *queues,
513
+ struct perf_sample *sample,
514
+ struct perf_session *session);
515
+int auxtrace_queues__add_sample(struct auxtrace_queues *queues,
516
+ struct perf_session *session,
517
+ struct perf_sample *sample, u64 data_offset,
518
+ u64 reference);
456519 void auxtrace_queues__free(struct auxtrace_queues *queues);
457520 int auxtrace_queues__process_index(struct auxtrace_queues *queues,
458521 struct perf_session *session);
522
+int auxtrace_queue_data(struct perf_session *session, bool samples,
523
+ bool events);
459524 struct auxtrace_buffer *auxtrace_buffer__next(struct auxtrace_queue *queue,
460525 struct auxtrace_buffer *buffer);
461526 void *auxtrace_buffer__get_data(struct auxtrace_buffer *buffer, int fd);
....@@ -480,30 +545,35 @@
480545 void auxtrace_cache__free_entry(struct auxtrace_cache *c, void *entry);
481546 int auxtrace_cache__add(struct auxtrace_cache *c, u32 key,
482547 struct auxtrace_cache_entry *entry);
548
+void auxtrace_cache__remove(struct auxtrace_cache *c, u32 key);
483549 void *auxtrace_cache__lookup(struct auxtrace_cache *c, u32 key);
484550
485
-struct auxtrace_record *auxtrace_record__init(struct perf_evlist *evlist,
551
+struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,
486552 int *err);
487553
488554 int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
489555 struct record_opts *opts,
490556 const char *str);
557
+int auxtrace_parse_sample_options(struct auxtrace_record *itr,
558
+ struct evlist *evlist,
559
+ struct record_opts *opts, const char *str);
491560 int auxtrace_record__options(struct auxtrace_record *itr,
492
- struct perf_evlist *evlist,
561
+ struct evlist *evlist,
493562 struct record_opts *opts);
494563 size_t auxtrace_record__info_priv_size(struct auxtrace_record *itr,
495
- struct perf_evlist *evlist);
564
+ struct evlist *evlist);
496565 int auxtrace_record__info_fill(struct auxtrace_record *itr,
497566 struct perf_session *session,
498
- struct auxtrace_info_event *auxtrace_info,
567
+ struct perf_record_auxtrace_info *auxtrace_info,
499568 size_t priv_size);
500569 void auxtrace_record__free(struct auxtrace_record *itr);
501570 int auxtrace_record__snapshot_start(struct auxtrace_record *itr);
502
-int auxtrace_record__snapshot_finish(struct auxtrace_record *itr);
571
+int auxtrace_record__snapshot_finish(struct auxtrace_record *itr, bool on_exit);
503572 int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx,
504573 struct auxtrace_mmap *mm,
505574 unsigned char *data, u64 *head, u64 *old);
506575 u64 auxtrace_record__reference(struct auxtrace_record *itr);
576
+int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx);
507577
508578 int auxtrace_index__auxtrace_event(struct list_head *head, union perf_event *event,
509579 off_t file_offset);
....@@ -512,26 +582,20 @@
512582 bool needs_swap);
513583 void auxtrace_index__free(struct list_head *head);
514584
515
-void auxtrace_synth_error(struct auxtrace_error_event *auxtrace_error, int type,
585
+void auxtrace_synth_error(struct perf_record_auxtrace_error *auxtrace_error, int type,
516586 int code, int cpu, pid_t pid, pid_t tid, u64 ip,
517
- const char *msg);
587
+ const char *msg, u64 timestamp);
518588
519
-int perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr,
520
- struct perf_tool *tool,
521
- struct perf_session *session,
522
- perf_event__handler_t process);
523
-int perf_event__process_auxtrace_info(struct perf_tool *tool,
524
- union perf_event *event,
525
- struct perf_session *session);
526
-s64 perf_event__process_auxtrace(struct perf_tool *tool,
527
- union perf_event *event,
528
- struct perf_session *session);
529
-int perf_event__process_auxtrace_error(struct perf_tool *tool,
530
- union perf_event *event,
531
- struct perf_session *session);
589
+int perf_event__process_auxtrace_info(struct perf_session *session,
590
+ union perf_event *event);
591
+s64 perf_event__process_auxtrace(struct perf_session *session,
592
+ union perf_event *event);
593
+int perf_event__process_auxtrace_error(struct perf_session *session,
594
+ union perf_event *event);
532595 int itrace_parse_synth_opts(const struct option *opt, const char *str,
533596 int unset);
534
-void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts);
597
+void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts,
598
+ bool no_sample);
535599
536600 size_t perf_event__fprintf_auxtrace_error(union perf_event *event, FILE *fp);
537601 void perf_session__auxtrace_error_inc(struct perf_session *session,
....@@ -542,48 +606,69 @@
542606 void addr_filters__exit(struct addr_filters *filts);
543607 int addr_filters__parse_bare_filter(struct addr_filters *filts,
544608 const char *filter);
545
-int auxtrace_parse_filters(struct perf_evlist *evlist);
609
+int auxtrace_parse_filters(struct evlist *evlist);
546610
547
-static inline int auxtrace__process_event(struct perf_session *session,
548
- union perf_event *event,
549
- struct perf_sample *sample,
550
- struct perf_tool *tool)
611
+int auxtrace__process_event(struct perf_session *session, union perf_event *event,
612
+ struct perf_sample *sample, struct perf_tool *tool);
613
+void auxtrace__dump_auxtrace_sample(struct perf_session *session,
614
+ struct perf_sample *sample);
615
+int auxtrace__flush_events(struct perf_session *session, struct perf_tool *tool);
616
+void auxtrace__free_events(struct perf_session *session);
617
+void auxtrace__free(struct perf_session *session);
618
+bool auxtrace__evsel_is_auxtrace(struct perf_session *session,
619
+ struct evsel *evsel);
620
+
621
+#define ITRACE_HELP \
622
+" i[period]: synthesize instructions events\n" \
623
+" b: synthesize branches events (branch misses for Arm SPE)\n" \
624
+" c: synthesize branches events (calls only)\n" \
625
+" r: synthesize branches events (returns only)\n" \
626
+" x: synthesize transactions events\n" \
627
+" w: synthesize ptwrite events\n" \
628
+" p: synthesize power events\n" \
629
+" o: synthesize other events recorded due to the use\n" \
630
+" of aux-output (refer to perf record)\n" \
631
+" e[flags]: synthesize error events\n" \
632
+" each flag must be preceded by + or -\n" \
633
+" error flags are: o (overflow)\n" \
634
+" l (data lost)\n" \
635
+" d[flags]: create a debug log\n" \
636
+" each flag must be preceded by + or -\n" \
637
+" log flags are: a (all perf events)\n" \
638
+" f: synthesize first level cache events\n" \
639
+" m: synthesize last level cache events\n" \
640
+" t: synthesize TLB events\n" \
641
+" a: synthesize remote access events\n" \
642
+" g[len]: synthesize a call chain (use with i or x)\n" \
643
+" G[len]: synthesize a call chain on existing event records\n" \
644
+" l[len]: synthesize last branch entries (use with i or x)\n" \
645
+" L[len]: synthesize last branch entries on existing event records\n" \
646
+" sNUMBER: skip initial number of events\n" \
647
+" q: quicker (less detailed) decoding\n" \
648
+" PERIOD[ns|us|ms|i|t]: specify period to sample stream\n" \
649
+" concatenate multiple options. Default is ibxwpe or cewp\n"
650
+
651
+static inline
652
+void itrace_synth_opts__set_time_range(struct itrace_synth_opts *opts,
653
+ struct perf_time_interval *ptime_range,
654
+ int range_num)
551655 {
552
- if (!session->auxtrace)
553
- return 0;
554
-
555
- return session->auxtrace->process_event(session, event, sample, tool);
656
+ opts->ptime_range = ptime_range;
657
+ opts->range_num = range_num;
556658 }
557659
558
-static inline int auxtrace__flush_events(struct perf_session *session,
559
- struct perf_tool *tool)
660
+static inline
661
+void itrace_synth_opts__clear_time_range(struct itrace_synth_opts *opts)
560662 {
561
- if (!session->auxtrace)
562
- return 0;
563
-
564
- return session->auxtrace->flush_events(session, tool);
565
-}
566
-
567
-static inline void auxtrace__free_events(struct perf_session *session)
568
-{
569
- if (!session->auxtrace)
570
- return;
571
-
572
- return session->auxtrace->free_events(session);
573
-}
574
-
575
-static inline void auxtrace__free(struct perf_session *session)
576
-{
577
- if (!session->auxtrace)
578
- return;
579
-
580
- return session->auxtrace->free(session);
663
+ opts->ptime_range = NULL;
664
+ opts->range_num = 0;
581665 }
582666
583667 #else
668
+#include "debug.h"
584669
585670 static inline struct auxtrace_record *
586
-auxtrace_record__init(struct perf_evlist *evlist __maybe_unused,
671
+auxtrace_record__init(struct evlist *evlist __maybe_unused,
587672 int *err)
588673 {
589674 *err = 0;
....@@ -595,18 +680,9 @@
595680 {
596681 }
597682
598
-static inline int
599
-perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr __maybe_unused,
600
- struct perf_tool *tool __maybe_unused,
601
- struct perf_session *session __maybe_unused,
602
- perf_event__handler_t process __maybe_unused)
603
-{
604
- return -EINVAL;
605
-}
606
-
607683 static inline
608684 int auxtrace_record__options(struct auxtrace_record *itr __maybe_unused,
609
- struct perf_evlist *evlist __maybe_unused,
685
+ struct evlist *evlist __maybe_unused,
610686 struct record_opts *opts __maybe_unused)
611687 {
612688 return 0;
....@@ -651,12 +727,30 @@
651727 }
652728
653729 static inline
730
+int auxtrace_parse_sample_options(struct auxtrace_record *itr __maybe_unused,
731
+ struct evlist *evlist __maybe_unused,
732
+ struct record_opts *opts __maybe_unused,
733
+ const char *str)
734
+{
735
+ if (!str)
736
+ return 0;
737
+ pr_err("AUX area tracing not supported\n");
738
+ return -EINVAL;
739
+}
740
+
741
+static inline
654742 int auxtrace__process_event(struct perf_session *session __maybe_unused,
655743 union perf_event *event __maybe_unused,
656744 struct perf_sample *sample __maybe_unused,
657745 struct perf_tool *tool __maybe_unused)
658746 {
659747 return 0;
748
+}
749
+
750
+static inline
751
+void auxtrace__dump_auxtrace_sample(struct perf_session *session __maybe_unused,
752
+ struct perf_sample *sample __maybe_unused)
753
+{
660754 }
661755
662756 static inline
....@@ -703,7 +797,14 @@
703797 }
704798
705799 static inline
706
-int auxtrace_parse_filters(struct perf_evlist *evlist __maybe_unused)
800
+bool auxtrace__evsel_is_auxtrace(struct perf_session *session __maybe_unused,
801
+ struct evsel *evsel __maybe_unused)
802
+{
803
+ return false;
804
+}
805
+
806
+static inline
807
+int auxtrace_parse_filters(struct evlist *evlist __maybe_unused)
707808 {
708809 return 0;
709810 }
....@@ -717,9 +818,26 @@
717818 unsigned int auxtrace_pages,
718819 bool auxtrace_overwrite);
719820 void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
720
- struct perf_evlist *evlist, int idx,
821
+ struct evlist *evlist, int idx,
721822 bool per_cpu);
722823
824
+#define ITRACE_HELP ""
825
+
826
+static inline
827
+void itrace_synth_opts__set_time_range(struct itrace_synth_opts *opts
828
+ __maybe_unused,
829
+ struct perf_time_interval *ptime_range
830
+ __maybe_unused,
831
+ int range_num __maybe_unused)
832
+{
833
+}
834
+
835
+static inline
836
+void itrace_synth_opts__clear_time_range(struct itrace_synth_opts *opts
837
+ __maybe_unused)
838
+{
839
+}
840
+
723841 #endif
724842
725843 #endif