]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
perf sample: Remove arch notion of sample parsing
authorIan Rogers <irogers@google.com>
Thu, 24 Jul 2025 16:33:00 +0000 (09:33 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 25 Jul 2025 17:37:58 +0000 (10:37 -0700)
By definition arch sample parsing and synthesis will inhibit certain
kinds of cross-platform record then analysis (report, script,
etc.). Remove arch_perf_parse_sample_weight and
arch_perf_synthesize_sample_weight replacing with a common
implementation. Combine perf_sample p_stage_cyc and retire_lat as
weight3 to capture the differing uses regardless of compiled for
architecture.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250724163302.596743-21-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
14 files changed:
tools/perf/arch/powerpc/util/event.c
tools/perf/arch/x86/tests/sample-parsing.c
tools/perf/arch/x86/util/event.c
tools/perf/builtin-script.c
tools/perf/util/dlfilter.c
tools/perf/util/event.h
tools/perf/util/evsel.c
tools/perf/util/hist.c
tools/perf/util/hist.h
tools/perf/util/intel-tpebs.c
tools/perf/util/sample.h
tools/perf/util/session.c
tools/perf/util/sort.c
tools/perf/util/synthetic-events.c

index 77d8cc2b5691f0ddfc36855efc7544d55d4c1991..024ac8b54c33bc3ecc11b79b56a2f06191fc9b69 100644 (file)
 #include "../../../util/debug.h"
 #include "../../../util/sample.h"
 
-void arch_perf_parse_sample_weight(struct perf_sample *data,
-                                  const __u64 *array, u64 type)
-{
-       union perf_sample_weight weight;
-
-       weight.full = *array;
-       if (type & PERF_SAMPLE_WEIGHT)
-               data->weight = weight.full;
-       else {
-               data->weight = weight.var1_dw;
-               data->ins_lat = weight.var2_w;
-               data->p_stage_cyc = weight.var3_w;
-       }
-}
-
-void arch_perf_synthesize_sample_weight(const struct perf_sample *data,
-                                       __u64 *array, u64 type)
-{
-       *array = data->weight;
-
-       if (type & PERF_SAMPLE_WEIGHT_STRUCT) {
-               *array &= 0xffffffff;
-               *array |= ((u64)data->ins_lat << 32);
-       }
-}
-
 const char *arch_perf_header_entry(const char *se_header)
 {
        if (!strcmp(se_header, "Local INSTR Latency"))
index a061e861926747376718443ded234dd4df46a29c..22feec23e53da13b4271bf3409a31e4993e2adf6 100644 (file)
@@ -29,7 +29,7 @@ static bool samples_same(const struct perf_sample *s1,
 {
        if (type & PERF_SAMPLE_WEIGHT_STRUCT) {
                COMP(ins_lat);
-               COMP(retire_lat);
+               COMP(weight3);
        }
 
        return true;
@@ -50,7 +50,7 @@ static int do_test(u64 sample_type)
        struct perf_sample sample = {
                .weight         = 101,
                .ins_lat        = 102,
-               .retire_lat     = 103,
+               .weight3        = 103,
        };
        struct perf_sample sample_out;
        size_t i, sz, bufsz;
index a0400707180cb82e37a643481079b67f4c2e4bc3..576c1c36046ca6a89074ada04ad64d4c358fd0c4 100644 (file)
@@ -92,33 +92,6 @@ int perf_event__synthesize_extra_kmaps(const struct perf_tool *tool,
 
 #endif
 
-void arch_perf_parse_sample_weight(struct perf_sample *data,
-                                  const __u64 *array, u64 type)
-{
-       union perf_sample_weight weight;
-
-       weight.full = *array;
-       if (type & PERF_SAMPLE_WEIGHT)
-               data->weight = weight.full;
-       else {
-               data->weight = weight.var1_dw;
-               data->ins_lat = weight.var2_w;
-               data->retire_lat = weight.var3_w;
-       }
-}
-
-void arch_perf_synthesize_sample_weight(const struct perf_sample *data,
-                                       __u64 *array, u64 type)
-{
-       *array = data->weight;
-
-       if (type & PERF_SAMPLE_WEIGHT_STRUCT) {
-               *array &= 0xffffffff;
-               *array |= ((u64)data->ins_lat << 32);
-               *array |= ((u64)data->retire_lat << 48);
-       }
-}
-
 const char *arch_perf_header_entry(const char *se_header)
 {
        if (!strcmp(se_header, "Local Pipeline Stage Cycle"))
index f2b5620165b4246b6004bffb6e2b214ff4bf3602..d9fbdcf72f252926be726b673200d62090dd90fb 100644 (file)
@@ -2252,7 +2252,7 @@ static void process_event(struct perf_script *script,
                fprintf(fp, "%16" PRIu16, sample->ins_lat);
 
        if (PRINT_FIELD(RETIRE_LAT))
-               fprintf(fp, "%16" PRIu16, sample->retire_lat);
+               fprintf(fp, "%16" PRIu16, sample->weight3);
 
        if (PRINT_FIELD(CGROUP)) {
                const char *cgrp_name;
index ddacef881af2fd7447d6ded76e21154e93d533a1..c0afcbd954f8060895f88ce9e485eba9531db8cc 100644 (file)
@@ -513,6 +513,7 @@ int dlfilter__do_filter_event(struct dlfilter *d,
        d->d_addr_al   = &d_addr_al;
 
        d_sample.size  = sizeof(d_sample);
+       d_sample.p_stage_cyc = sample->weight3;
        d_ip_al.size   = 0; /* To indicate d_ip_al is not initialized */
        d_addr_al.size = 0; /* To indicate d_addr_al is not initialized */
 
@@ -526,7 +527,6 @@ int dlfilter__do_filter_event(struct dlfilter *d,
        ASSIGN(period);
        ASSIGN(weight);
        ASSIGN(ins_lat);
-       ASSIGN(p_stage_cyc);
        ASSIGN(transaction);
        ASSIGN(insn_cnt);
        ASSIGN(cyc_cnt);
index 67ad4a2014bca09af90d83d7fd0b245431d0ed7b..b13385a6068bf399edff63203066956718692c1e 100644 (file)
@@ -391,8 +391,6 @@ extern unsigned int proc_map_timeout;
 #define PAGE_SIZE_NAME_LEN     32
 char *get_page_size_name(u64 size, char *str);
 
-void arch_perf_parse_sample_weight(struct perf_sample *data, const __u64 *array, u64 type);
-void arch_perf_synthesize_sample_weight(const struct perf_sample *data, __u64 *array, u64 type);
 const char *arch_perf_header_entry(const char *se_header);
 int arch_support_sort_key(const char *sort_key);
 
index aa6efcc4404cf210a6091b53b07b9da7c857fa91..3d27e9bdd66b89fd5ab5a480399fbeb4277d480d 100644 (file)
@@ -2880,11 +2880,18 @@ perf_event__check_size(union perf_event *event, unsigned int sample_size)
        return 0;
 }
 
-void __weak arch_perf_parse_sample_weight(struct perf_sample *data,
-                                         const __u64 *array,
-                                         u64 type __maybe_unused)
+static void perf_parse_sample_weight(struct perf_sample *data, const __u64 *array, u64 type)
 {
-       data->weight = *array;
+       union perf_sample_weight weight;
+
+       weight.full = *array;
+       if (type & PERF_SAMPLE_WEIGHT_STRUCT) {
+               data->weight = weight.var1_dw;
+               data->ins_lat = weight.var2_w;
+               data->weight3 = weight.var3_w;
+       } else {
+               data->weight = weight.full;
+       }
 }
 
 u64 evsel__bitfield_swap_branch_flags(u64 value)
@@ -3270,7 +3277,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
 
        if (type & PERF_SAMPLE_WEIGHT_TYPE) {
                OVERFLOW_CHECK_u64(array);
-               arch_perf_parse_sample_weight(data, array, type);
+               perf_parse_sample_weight(data, array, type);
                array++;
        }
 
index afc6855327ab0de66d0642854328a3929b137fb2..64ff427040c341127e8690dc438e4d0119c69aac 100644 (file)
@@ -829,7 +829,7 @@ __hists__add_entry(struct hists *hists,
                        .period = sample->period,
                        .weight1 = sample->weight,
                        .weight2 = sample->ins_lat,
-                       .weight3 = sample->p_stage_cyc,
+                       .weight3 = sample->weight3,
                        .latency = al->latency,
                },
                .parent = sym_parent,
@@ -846,7 +846,7 @@ __hists__add_entry(struct hists *hists,
                .time = hist_time(sample->time),
                .weight = sample->weight,
                .ins_lat = sample->ins_lat,
-               .p_stage_cyc = sample->p_stage_cyc,
+               .weight3 = sample->weight3,
                .simd_flags = sample->simd_flags,
        }, *he = hists__findnew_entry(hists, &entry, al, sample_self);
 
index c64254088fc77246318dc72f0858942d470a0e87..70438d03ca9c33b180948611daec1084ea1b34ac 100644 (file)
@@ -255,7 +255,8 @@ struct hist_entry {
        u64                     code_page_size;
        u64                     weight;
        u64                     ins_lat;
-       u64                     p_stage_cyc;
+       /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */
+       u64                     weight3;
        s32                     socket;
        s32                     cpu;
        int                     parallelism;
index 3b92ebf5c1121889a6a8f95e802c57c8a65f6672..8c9aee157ec48dd0292bb40e959b879e76c44965 100644 (file)
@@ -210,8 +210,8 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,
         * latency value will be used. Save the number of samples and the sum of
         * retire latency value for each event.
         */
-       t->last = sample->retire_lat;
-       update_stats(&t->stats, sample->retire_lat);
+       t->last = sample->weight3;
+       update_stats(&t->stats, sample->weight3);
        mutex_unlock(tpebs_mtx_get());
        return 0;
 }
index 0e96240052e9ec66e2652172457294daf702bfa8..fae834144ef42105d08a59704ee75cd4852bbc5a 100644 (file)
@@ -104,10 +104,8 @@ struct perf_sample {
        u8  cpumode;
        u16 misc;
        u16 ins_lat;
-       union {
-               u16 p_stage_cyc;
-               u16 retire_lat;
-       };
+       /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */
+       u16 weight3;
        bool no_hw_idx;         /* No hw_idx collected in branch_stack */
        char insn[MAX_INSN];
        void *raw_data;
index 2a79e6844f3610994585cff4bfd307ade59a2bb2..26ae078278cd67fc5894c01cbb44c4b8fa81321a 100644 (file)
@@ -1099,7 +1099,7 @@ static void dump_sample(struct evsel *evsel, union perf_event *event,
                printf("... weight: %" PRIu64 "", sample->weight);
                        if (sample_type & PERF_SAMPLE_WEIGHT_STRUCT) {
                                printf(",0x%"PRIx16"", sample->ins_lat);
-                               printf(",0x%"PRIx16"", sample->p_stage_cyc);
+                               printf(",0x%"PRIx16"", sample->weight3);
                        }
                printf("\n");
        }
index 7969d64a47bfb780c75cc5c0d1774784ceea8918..0ba2ce1b1c0707ccedf6543ad4b8177d94e3b167 100644 (file)
@@ -1884,21 +1884,20 @@ struct sort_entry sort_global_ins_lat = {
 static int64_t
 sort__p_stage_cyc_cmp(struct hist_entry *left, struct hist_entry *right)
 {
-       return left->p_stage_cyc - right->p_stage_cyc;
+       return left->weight3 - right->weight3;
 }
 
 static int hist_entry__global_p_stage_cyc_snprintf(struct hist_entry *he, char *bf,
                                        size_t size, unsigned int width)
 {
-       return repsep_snprintf(bf, size, "%-*u", width,
-                       he->p_stage_cyc * he->stat.nr_events);
+       return repsep_snprintf(bf, size, "%-*u", width, he->weight3 * he->stat.nr_events);
 }
 
 
 static int hist_entry__p_stage_cyc_snprintf(struct hist_entry *he, char *bf,
                                        size_t size, unsigned int width)
 {
-       return repsep_snprintf(bf, size, "%-*u", width, he->p_stage_cyc);
+       return repsep_snprintf(bf, size, "%-*u", width, he->weight3);
 }
 
 struct sort_entry sort_local_p_stage_cyc = {
index e7ca3f5eb4930c953ec9b4924772f81ff6ddc96b..cb2c1ace304aec7cfcb1dc88184244a65b426c0d 100644 (file)
@@ -1573,10 +1573,16 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
        return result;
 }
 
-void __weak arch_perf_synthesize_sample_weight(const struct perf_sample *data,
+static void perf_synthesize_sample_weight(const struct perf_sample *data,
                                               __u64 *array, u64 type __maybe_unused)
 {
        *array = data->weight;
+
+       if (type & PERF_SAMPLE_WEIGHT_STRUCT) {
+               *array &= 0xffffffff;
+               *array |= ((u64)data->ins_lat << 32);
+               *array |= ((u64)data->weight3 << 48);
+       }
 }
 
 static __u64 *copy_read_group_values(__u64 *array, __u64 read_format,
@@ -1736,7 +1742,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_fo
        }
 
        if (type & PERF_SAMPLE_WEIGHT_TYPE) {
-               arch_perf_synthesize_sample_weight(sample, array, type);
+               perf_synthesize_sample_weight(sample, array, type);
                array++;
        }