Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf auxtrace: Remove dummy tools

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>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
4e322c78 79bcd34e

+41 -123
+10 -39
tools/perf/util/arm-spe.c
··· 1073 1073 fprintf(stdout, arm_spe_info_fmts[ARM_SPE_PMU_TYPE], arr[ARM_SPE_PMU_TYPE]); 1074 1074 } 1075 1075 1076 - struct arm_spe_synth { 1077 - struct perf_tool dummy_tool; 1078 - struct perf_session *session; 1079 - }; 1080 - 1081 - static int arm_spe_event_synth(struct perf_tool *tool, 1082 - union perf_event *event, 1083 - struct perf_sample *sample __maybe_unused, 1084 - struct machine *machine __maybe_unused) 1085 - { 1086 - struct arm_spe_synth *arm_spe_synth = 1087 - container_of(tool, struct arm_spe_synth, dummy_tool); 1088 - 1089 - return perf_session__deliver_synth_event(arm_spe_synth->session, 1090 - event, NULL); 1091 - } 1092 - 1093 - static int arm_spe_synth_event(struct perf_session *session, 1094 - struct perf_event_attr *attr, u64 id) 1095 - { 1096 - struct arm_spe_synth arm_spe_synth; 1097 - 1098 - memset(&arm_spe_synth, 0, sizeof(struct arm_spe_synth)); 1099 - arm_spe_synth.session = session; 1100 - 1101 - return perf_event__synthesize_attr(&arm_spe_synth.dummy_tool, attr, 1, 1102 - &id, arm_spe_event_synth); 1103 - } 1104 - 1105 1076 static void arm_spe_set_event_name(struct evlist *evlist, u64 id, 1106 1077 const char *name) 1107 1078 { ··· 1143 1172 spe->sample_flc = true; 1144 1173 1145 1174 /* Level 1 data cache miss */ 1146 - err = arm_spe_synth_event(session, &attr, id); 1175 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 1147 1176 if (err) 1148 1177 return err; 1149 1178 spe->l1d_miss_id = id; ··· 1151 1180 id += 1; 1152 1181 1153 1182 /* Level 1 data cache access */ 1154 - err = arm_spe_synth_event(session, &attr, id); 1183 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 1155 1184 if (err) 1156 1185 return err; 1157 1186 spe->l1d_access_id = id; ··· 1163 1192 spe->sample_llc = true; 1164 1193 1165 1194 /* Last level cache miss */ 1166 - err = arm_spe_synth_event(session, &attr, id); 1195 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 1167 1196 if (err) 1168 1197 return err; 1169 1198 spe->llc_miss_id = id; ··· 1171 1200 id += 1; 1172 1201 1173 1202 /* Last level cache access */ 1174 - err = arm_spe_synth_event(session, &attr, id); 1203 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 1175 1204 if (err) 1176 1205 return err; 1177 1206 spe->llc_access_id = id; ··· 1183 1212 spe->sample_tlb = true; 1184 1213 1185 1214 /* TLB miss */ 1186 - err = arm_spe_synth_event(session, &attr, id); 1215 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 1187 1216 if (err) 1188 1217 return err; 1189 1218 spe->tlb_miss_id = id; ··· 1191 1220 id += 1; 1192 1221 1193 1222 /* TLB access */ 1194 - err = arm_spe_synth_event(session, &attr, id); 1223 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 1195 1224 if (err) 1196 1225 return err; 1197 1226 spe->tlb_access_id = id; ··· 1203 1232 spe->sample_branch = true; 1204 1233 1205 1234 /* Branch miss */ 1206 - err = arm_spe_synth_event(session, &attr, id); 1235 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 1207 1236 if (err) 1208 1237 return err; 1209 1238 spe->branch_miss_id = id; ··· 1215 1244 spe->sample_remote_access = true; 1216 1245 1217 1246 /* Remote access */ 1218 - err = arm_spe_synth_event(session, &attr, id); 1247 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 1219 1248 if (err) 1220 1249 return err; 1221 1250 spe->remote_access_id = id; ··· 1226 1255 if (spe->synth_opts.mem) { 1227 1256 spe->sample_memory = true; 1228 1257 1229 - err = arm_spe_synth_event(session, &attr, id); 1258 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 1230 1259 if (err) 1231 1260 return err; 1232 1261 spe->memory_id = id; ··· 1247 1276 attr.config = PERF_COUNT_HW_INSTRUCTIONS; 1248 1277 attr.sample_period = spe->synth_opts.period; 1249 1278 spe->instructions_sample_period = attr.sample_period; 1250 - err = arm_spe_synth_event(session, &attr, id); 1279 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 1251 1280 if (err) 1252 1281 return err; 1253 1282 spe->instructions_id = id;
+2 -31
tools/perf/util/cs-etm.c
··· 1599 1599 return ret; 1600 1600 } 1601 1601 1602 - struct cs_etm_synth { 1603 - struct perf_tool dummy_tool; 1604 - struct perf_session *session; 1605 - }; 1606 - 1607 - static int cs_etm__event_synth(struct perf_tool *tool, 1608 - union perf_event *event, 1609 - struct perf_sample *sample __maybe_unused, 1610 - struct machine *machine __maybe_unused) 1611 - { 1612 - struct cs_etm_synth *cs_etm_synth = 1613 - container_of(tool, struct cs_etm_synth, dummy_tool); 1614 - 1615 - return perf_session__deliver_synth_event(cs_etm_synth->session, 1616 - event, NULL); 1617 - } 1618 - 1619 - static int cs_etm__synth_event(struct perf_session *session, 1620 - struct perf_event_attr *attr, u64 id) 1621 - { 1622 - struct cs_etm_synth cs_etm_synth; 1623 - 1624 - memset(&cs_etm_synth, 0, sizeof(struct cs_etm_synth)); 1625 - cs_etm_synth.session = session; 1626 - 1627 - return perf_event__synthesize_attr(&cs_etm_synth.dummy_tool, attr, 1, 1628 - &id, cs_etm__event_synth); 1629 - } 1630 - 1631 1602 static int cs_etm__synth_events(struct cs_etm_auxtrace *etm, 1632 1603 struct perf_session *session) 1633 1604 { ··· 1650 1679 attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS; 1651 1680 attr.sample_period = 1; 1652 1681 attr.sample_type |= PERF_SAMPLE_ADDR; 1653 - err = cs_etm__synth_event(session, &attr, id); 1682 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 1654 1683 if (err) 1655 1684 return err; 1656 1685 etm->branches_sample_type = attr.sample_type; ··· 1673 1702 attr.config = PERF_COUNT_HW_INSTRUCTIONS; 1674 1703 attr.sample_period = etm->synth_opts.period; 1675 1704 etm->instructions_sample_period = attr.sample_period; 1676 - err = cs_etm__synth_event(session, &attr, id); 1705 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 1677 1706 if (err) 1678 1707 return err; 1679 1708 etm->instructions_sample_type = attr.sample_type;
+1 -30
tools/perf/util/intel-bts.c
··· 737 737 return evsel->core.attr.type == bts->pmu_type; 738 738 } 739 739 740 - struct intel_bts_synth { 741 - struct perf_tool dummy_tool; 742 - struct perf_session *session; 743 - }; 744 - 745 - static int intel_bts_event_synth(struct perf_tool *tool, 746 - union perf_event *event, 747 - struct perf_sample *sample __maybe_unused, 748 - struct machine *machine __maybe_unused) 749 - { 750 - struct intel_bts_synth *intel_bts_synth = 751 - container_of(tool, struct intel_bts_synth, dummy_tool); 752 - 753 - return perf_session__deliver_synth_event(intel_bts_synth->session, 754 - event, NULL); 755 - } 756 - 757 - static int intel_bts_synth_event(struct perf_session *session, 758 - struct perf_event_attr *attr, u64 id) 759 - { 760 - struct intel_bts_synth intel_bts_synth; 761 - 762 - memset(&intel_bts_synth, 0, sizeof(struct intel_bts_synth)); 763 - intel_bts_synth.session = session; 764 - 765 - return perf_event__synthesize_attr(&intel_bts_synth.dummy_tool, attr, 1, 766 - &id, intel_bts_event_synth); 767 - } 768 - 769 740 static int intel_bts_synth_events(struct intel_bts *bts, 770 741 struct perf_session *session) 771 742 { ··· 785 814 attr.sample_type |= PERF_SAMPLE_ADDR; 786 815 pr_debug("Synthesizing 'branches' event with id %" PRIu64 " sample type %#" PRIx64 "\n", 787 816 id, (u64)attr.sample_type); 788 - err = intel_bts_synth_event(session, &attr, id); 817 + err = perf_session__deliver_synth_attr_event(session, &attr, id); 789 818 if (err) { 790 819 pr_err("%s: failed to synthesize 'branches' event type\n", 791 820 __func__);
+1 -23
tools/perf/util/intel-pt.c
··· 3659 3659 data_offset, timestamp); 3660 3660 } 3661 3661 3662 - struct intel_pt_synth { 3663 - struct perf_tool dummy_tool; 3664 - struct perf_session *session; 3665 - }; 3666 - 3667 - static int intel_pt_event_synth(struct perf_tool *tool, 3668 - union perf_event *event, 3669 - struct perf_sample *sample __maybe_unused, 3670 - struct machine *machine __maybe_unused) 3671 - { 3672 - struct intel_pt_synth *intel_pt_synth = 3673 - container_of(tool, struct intel_pt_synth, dummy_tool); 3674 - 3675 - return perf_session__deliver_synth_event(intel_pt_synth->session, event, 3676 - NULL); 3677 - } 3678 - 3679 3662 static int intel_pt_synth_event(struct perf_session *session, const char *name, 3680 3663 struct perf_event_attr *attr, u64 id) 3681 3664 { 3682 - struct intel_pt_synth intel_pt_synth; 3683 3665 int err; 3684 3666 3685 3667 pr_debug("Synthesizing '%s' event with id %" PRIu64 " sample type %#" PRIx64 "\n", 3686 3668 name, id, (u64)attr->sample_type); 3687 3669 3688 - memset(&intel_pt_synth, 0, sizeof(struct intel_pt_synth)); 3689 - intel_pt_synth.session = session; 3690 - 3691 - err = perf_event__synthesize_attr(&intel_pt_synth.dummy_tool, attr, 1, 3692 - &id, intel_pt_event_synth); 3670 + err = perf_session__deliver_synth_attr_event(session, attr, id); 3693 3671 if (err) 3694 3672 pr_err("%s: failed to synthesize '%s' event type\n", 3695 3673 __func__, name);
+24
tools/perf/util/session.c
··· 1769 1769 return machines__deliver_event(&session->machines, evlist, event, sample, tool, 0, NULL); 1770 1770 } 1771 1771 1772 + int perf_session__deliver_synth_attr_event(struct perf_session *session, 1773 + const struct perf_event_attr *attr, 1774 + u64 id) 1775 + { 1776 + union { 1777 + struct { 1778 + struct perf_record_header_attr attr; 1779 + u64 ids[1]; 1780 + } attr_id; 1781 + union perf_event ev; 1782 + } ev = { 1783 + .attr_id.attr.header.type = PERF_RECORD_HEADER_ATTR, 1784 + .attr_id.attr.header.size = sizeof(ev.attr_id), 1785 + .attr_id.ids[0] = id, 1786 + }; 1787 + 1788 + if (attr->size != sizeof(ev.attr_id.attr.attr)) { 1789 + pr_debug("Unexpected perf_event_attr size\n"); 1790 + return -EINVAL; 1791 + } 1792 + ev.attr_id.attr.attr = *attr; 1793 + return perf_session__deliver_synth_event(session, &ev.ev, NULL); 1794 + } 1795 + 1772 1796 static void event_swap(union perf_event *event, bool sample_id_all) 1773 1797 { 1774 1798 perf_event__swap_op swap;
+3
tools/perf/util/session.h
··· 154 154 int perf_session__deliver_synth_event(struct perf_session *session, 155 155 union perf_event *event, 156 156 struct perf_sample *sample); 157 + int perf_session__deliver_synth_attr_event(struct perf_session *session, 158 + const struct perf_event_attr *attr, 159 + u64 id); 157 160 158 161 int perf_session__dsos_hit_all(struct perf_session *session); 159 162