]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf auxtrace: Remove dummy tools
authorIan Rogers <irogers@google.com>
Mon, 12 Aug 2024 20:46:53 +0000 (13:46 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 12 Aug 2024 21:04:36 +0000 (18:04 -0300)
Add perf_session__deliver_synth_attr_event that synthesizes a
perf_record_header_attr event with one id. Remove use of
perf_event__synthesize_attr that necessitates the use of the dummy
tool in order to pass the session.

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Adrian Hunter <adrian.hunter@intel.com>
Tested-by: Leo Yan <leo.yan@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ilkka Koskinen <ilkka@os.amperecomputing.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Jonathan Cameron <jonathan.cameron@huawei.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Nick Terrell <terrelln@fb.com>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <song@kernel.org>
Cc: Sun Haiyong <sunhaiyong@loongson.cn>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yanteng Si <siyanteng@loongson.cn>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20240812204720.631678-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/arm-spe.c
tools/perf/util/cs-etm.c
tools/perf/util/intel-bts.c
tools/perf/util/intel-pt.c
tools/perf/util/session.c
tools/perf/util/session.h

index afbd5869f6bff2a1f582fb088412d82adf2dc81c..fa40f3cb6266d7bc51d494e667bb53f0ba423b90 100644 (file)
@@ -1073,35 +1073,6 @@ static void arm_spe_print_info(__u64 *arr)
        fprintf(stdout, arm_spe_info_fmts[ARM_SPE_PMU_TYPE], arr[ARM_SPE_PMU_TYPE]);
 }
 
-struct arm_spe_synth {
-       struct perf_tool dummy_tool;
-       struct perf_session *session;
-};
-
-static int arm_spe_event_synth(struct perf_tool *tool,
-                              union perf_event *event,
-                              struct perf_sample *sample __maybe_unused,
-                              struct machine *machine __maybe_unused)
-{
-       struct arm_spe_synth *arm_spe_synth =
-                     container_of(tool, struct arm_spe_synth, dummy_tool);
-
-       return perf_session__deliver_synth_event(arm_spe_synth->session,
-                                                event, NULL);
-}
-
-static int arm_spe_synth_event(struct perf_session *session,
-                              struct perf_event_attr *attr, u64 id)
-{
-       struct arm_spe_synth arm_spe_synth;
-
-       memset(&arm_spe_synth, 0, sizeof(struct arm_spe_synth));
-       arm_spe_synth.session = session;
-
-       return perf_event__synthesize_attr(&arm_spe_synth.dummy_tool, attr, 1,
-                                          &id, arm_spe_event_synth);
-}
-
 static void arm_spe_set_event_name(struct evlist *evlist, u64 id,
                                    const char *name)
 {
@@ -1172,7 +1143,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
                spe->sample_flc = true;
 
                /* Level 1 data cache miss */
-               err = arm_spe_synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err)
                        return err;
                spe->l1d_miss_id = id;
@@ -1180,7 +1151,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
                id += 1;
 
                /* Level 1 data cache access */
-               err = arm_spe_synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err)
                        return err;
                spe->l1d_access_id = id;
@@ -1192,7 +1163,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
                spe->sample_llc = true;
 
                /* Last level cache miss */
-               err = arm_spe_synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err)
                        return err;
                spe->llc_miss_id = id;
@@ -1200,7 +1171,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
                id += 1;
 
                /* Last level cache access */
-               err = arm_spe_synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err)
                        return err;
                spe->llc_access_id = id;
@@ -1212,7 +1183,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
                spe->sample_tlb = true;
 
                /* TLB miss */
-               err = arm_spe_synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err)
                        return err;
                spe->tlb_miss_id = id;
@@ -1220,7 +1191,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
                id += 1;
 
                /* TLB access */
-               err = arm_spe_synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err)
                        return err;
                spe->tlb_access_id = id;
@@ -1232,7 +1203,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
                spe->sample_branch = true;
 
                /* Branch miss */
-               err = arm_spe_synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err)
                        return err;
                spe->branch_miss_id = id;
@@ -1244,7 +1215,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
                spe->sample_remote_access = true;
 
                /* Remote access */
-               err = arm_spe_synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err)
                        return err;
                spe->remote_access_id = id;
@@ -1255,7 +1226,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
        if (spe->synth_opts.mem) {
                spe->sample_memory = true;
 
-               err = arm_spe_synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err)
                        return err;
                spe->memory_id = id;
@@ -1276,7 +1247,7 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
                attr.config = PERF_COUNT_HW_INSTRUCTIONS;
                attr.sample_period = spe->synth_opts.period;
                spe->instructions_sample_period = attr.sample_period;
-               err = arm_spe_synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err)
                        return err;
                spe->instructions_id = id;
index d3e9c64d17d4354452b8f47393de7a70f87b4ec8..566498ebc6947a58c422192ffb6746886bcf5075 100644 (file)
@@ -1599,35 +1599,6 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq,
        return ret;
 }
 
-struct cs_etm_synth {
-       struct perf_tool dummy_tool;
-       struct perf_session *session;
-};
-
-static int cs_etm__event_synth(struct perf_tool *tool,
-                              union perf_event *event,
-                              struct perf_sample *sample __maybe_unused,
-                              struct machine *machine __maybe_unused)
-{
-       struct cs_etm_synth *cs_etm_synth =
-                     container_of(tool, struct cs_etm_synth, dummy_tool);
-
-       return perf_session__deliver_synth_event(cs_etm_synth->session,
-                                                event, NULL);
-}
-
-static int cs_etm__synth_event(struct perf_session *session,
-                              struct perf_event_attr *attr, u64 id)
-{
-       struct cs_etm_synth cs_etm_synth;
-
-       memset(&cs_etm_synth, 0, sizeof(struct cs_etm_synth));
-       cs_etm_synth.session = session;
-
-       return perf_event__synthesize_attr(&cs_etm_synth.dummy_tool, attr, 1,
-                                          &id, cs_etm__event_synth);
-}
-
 static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
                                struct perf_session *session)
 {
@@ -1679,7 +1650,7 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
                attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
                attr.sample_period = 1;
                attr.sample_type |= PERF_SAMPLE_ADDR;
-               err = cs_etm__synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err)
                        return err;
                etm->branches_sample_type = attr.sample_type;
@@ -1702,7 +1673,7 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
                attr.config = PERF_COUNT_HW_INSTRUCTIONS;
                attr.sample_period = etm->synth_opts.period;
                etm->instructions_sample_period = attr.sample_period;
-               err = cs_etm__synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err)
                        return err;
                etm->instructions_sample_type = attr.sample_type;
index ec1b3bd9f53093463e1f6c7b14ba69e41a55dea4..160d346cb450f68320e340ea801c98caf6a4ac32 100644 (file)
@@ -737,35 +737,6 @@ static bool intel_bts_evsel_is_auxtrace(struct perf_session *session,
        return evsel->core.attr.type == bts->pmu_type;
 }
 
-struct intel_bts_synth {
-       struct perf_tool dummy_tool;
-       struct perf_session *session;
-};
-
-static int intel_bts_event_synth(struct perf_tool *tool,
-                                union perf_event *event,
-                                struct perf_sample *sample __maybe_unused,
-                                struct machine *machine __maybe_unused)
-{
-       struct intel_bts_synth *intel_bts_synth =
-                       container_of(tool, struct intel_bts_synth, dummy_tool);
-
-       return perf_session__deliver_synth_event(intel_bts_synth->session,
-                                                event, NULL);
-}
-
-static int intel_bts_synth_event(struct perf_session *session,
-                                struct perf_event_attr *attr, u64 id)
-{
-       struct intel_bts_synth intel_bts_synth;
-
-       memset(&intel_bts_synth, 0, sizeof(struct intel_bts_synth));
-       intel_bts_synth.session = session;
-
-       return perf_event__synthesize_attr(&intel_bts_synth.dummy_tool, attr, 1,
-                                          &id, intel_bts_event_synth);
-}
-
 static int intel_bts_synth_events(struct intel_bts *bts,
                                  struct perf_session *session)
 {
@@ -814,7 +785,7 @@ static int intel_bts_synth_events(struct intel_bts *bts,
                attr.sample_type |= PERF_SAMPLE_ADDR;
                pr_debug("Synthesizing 'branches' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
                         id, (u64)attr.sample_type);
-               err = intel_bts_synth_event(session, &attr, id);
+               err = perf_session__deliver_synth_attr_event(session, &attr, id);
                if (err) {
                        pr_err("%s: failed to synthesize 'branches' event type\n",
                               __func__);
index d6d7b75125051d67fa8620e0b9ca4004393f93d3..1fc03bfd14c397bd555f986d40dd5f1820c812c6 100644 (file)
@@ -3659,37 +3659,15 @@ static int intel_pt_queue_data(struct perf_session *session,
                                           data_offset, timestamp);
 }
 
-struct intel_pt_synth {
-       struct perf_tool dummy_tool;
-       struct perf_session *session;
-};
-
-static int intel_pt_event_synth(struct perf_tool *tool,
-                               union perf_event *event,
-                               struct perf_sample *sample __maybe_unused,
-                               struct machine *machine __maybe_unused)
-{
-       struct intel_pt_synth *intel_pt_synth =
-                       container_of(tool, struct intel_pt_synth, dummy_tool);
-
-       return perf_session__deliver_synth_event(intel_pt_synth->session, event,
-                                                NULL);
-}
-
 static int intel_pt_synth_event(struct perf_session *session, const char *name,
                                struct perf_event_attr *attr, u64 id)
 {
-       struct intel_pt_synth intel_pt_synth;
        int err;
 
        pr_debug("Synthesizing '%s' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
                 name, id, (u64)attr->sample_type);
 
-       memset(&intel_pt_synth, 0, sizeof(struct intel_pt_synth));
-       intel_pt_synth.session = session;
-
-       err = perf_event__synthesize_attr(&intel_pt_synth.dummy_tool, attr, 1,
-                                         &id, intel_pt_event_synth);
+       err = perf_session__deliver_synth_attr_event(session, attr, id);
        if (err)
                pr_err("%s: failed to synthesize '%s' event type\n",
                       __func__, name);
index 453ca0297c8035bbd69835a7a85e043a8d6c0612..aa02c1d7b1f9d22c1b40c8c62703f8b3d9646248 100644 (file)
@@ -1769,6 +1769,30 @@ int perf_session__deliver_synth_event(struct perf_session *session,
        return machines__deliver_event(&session->machines, evlist, event, sample, tool, 0, NULL);
 }
 
+int perf_session__deliver_synth_attr_event(struct perf_session *session,
+                                          const struct perf_event_attr *attr,
+                                          u64 id)
+{
+       union {
+               struct {
+                       struct perf_record_header_attr attr;
+                       u64 ids[1];
+               } attr_id;
+               union perf_event ev;
+       } ev = {
+               .attr_id.attr.header.type = PERF_RECORD_HEADER_ATTR,
+               .attr_id.attr.header.size = sizeof(ev.attr_id),
+               .attr_id.ids[0] = id,
+       };
+
+       if (attr->size != sizeof(ev.attr_id.attr.attr)) {
+               pr_debug("Unexpected perf_event_attr size\n");
+               return -EINVAL;
+       }
+       ev.attr_id.attr.attr = *attr;
+       return perf_session__deliver_synth_event(session, &ev.ev, NULL);
+}
+
 static void event_swap(union perf_event *event, bool sample_id_all)
 {
        perf_event__swap_op swap;
index 4c29dc86956f21eb9c752731cb5ce11ac5d5c84e..cc28976bb00e341430a06f7b1dc8f418adb3aa36 100644 (file)
@@ -154,6 +154,9 @@ extern volatile int session_done;
 int perf_session__deliver_synth_event(struct perf_session *session,
                                      union perf_event *event,
                                      struct perf_sample *sample);
+int perf_session__deliver_synth_attr_event(struct perf_session *session,
+                                          const struct perf_event_attr *attr,
+                                          u64 id);
 
 int perf_session__dsos_hit_all(struct perf_session *session);