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

Configure Feed

Select the types of activity you want to include in your feed.

perf tools: Add util function for overriding user set config values

There is some duplicated code to only override config values if they
haven't already been set by the user so make a util function for this.

Signed-off-by: James Clark <james.clark@arm.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Denis Nikitin <denik@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Shi <shy828301@gmail.com>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230424134748.228137-3-james.clark@arm.com
[ Moved evsel__set_config_if_unset() to util/pmu.c to avoid dragging stuff into the python binding ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

James Clark and committed by
Arnaldo Carvalho de Melo
6593f019 449067f3

+37 -44
+2 -24
tools/perf/arch/arm64/util/arm-spe.c
··· 36 36 bool *wrapped; 37 37 }; 38 38 39 - static void arm_spe_set_timestamp(struct auxtrace_record *itr, 40 - struct evsel *evsel) 41 - { 42 - struct arm_spe_recording *ptr; 43 - struct perf_pmu *arm_spe_pmu; 44 - struct evsel_config_term *term = evsel__get_config_term(evsel, CFG_CHG); 45 - u64 user_bits = 0, bit; 46 - 47 - ptr = container_of(itr, struct arm_spe_recording, itr); 48 - arm_spe_pmu = ptr->arm_spe_pmu; 49 - 50 - if (term) 51 - user_bits = term->val.cfg_chg; 52 - 53 - bit = perf_pmu__format_bits(&arm_spe_pmu->format, "ts_enable"); 54 - 55 - /* Skip if user has set it */ 56 - if (bit & user_bits) 57 - return; 58 - 59 - evsel->core.attr.config |= bit; 60 - } 61 - 62 39 static size_t 63 40 arm_spe_info_priv_size(struct auxtrace_record *itr __maybe_unused, 64 41 struct evlist *evlist __maybe_unused) ··· 215 238 */ 216 239 if (!perf_cpu_map__empty(cpus)) { 217 240 evsel__set_sample_bit(arm_spe_evsel, CPU); 218 - arm_spe_set_timestamp(itr, arm_spe_evsel); 241 + evsel__set_config_if_unset(arm_spe_pmu, arm_spe_evsel, 242 + "ts_enable", 1); 219 243 } 220 244 221 245 /*
+2 -20
tools/perf/arch/x86/util/intel-pt.c
··· 576 576 return err; 577 577 } 578 578 579 - static void intel_pt_config_sample_mode(struct perf_pmu *intel_pt_pmu, 580 - struct evsel *evsel) 581 - { 582 - u64 user_bits = 0, bits; 583 - struct evsel_config_term *term = evsel__get_config_term(evsel, CFG_CHG); 584 - 585 - if (term) 586 - user_bits = term->val.cfg_chg; 587 - 588 - bits = perf_pmu__format_bits(&intel_pt_pmu->format, "psb_period"); 589 - 590 - /* Did user change psb_period */ 591 - if (bits & user_bits) 592 - return; 593 - 594 - /* Set psb_period to 0 */ 595 - evsel->core.attr.config &= ~bits; 596 - } 597 - 598 579 static void intel_pt_min_max_sample_sz(struct evlist *evlist, 599 580 size_t *min_sz, size_t *max_sz) 600 581 { ··· 667 686 return 0; 668 687 669 688 if (opts->auxtrace_sample_mode) 670 - intel_pt_config_sample_mode(intel_pt_pmu, intel_pt_evsel); 689 + evsel__set_config_if_unset(intel_pt_pmu, intel_pt_evsel, 690 + "psb_period", 0); 671 691 672 692 err = intel_pt_validate_config(intel_pt_pmu, intel_pt_evsel); 673 693 if (err)
+3
tools/perf/util/evsel.h
··· 530 530 ((((src) >> (pos)) & ((1ull << (size)) - 1)) << (63 - ((pos) + (size) - 1))) 531 531 532 532 u64 evsel__bitfield_swap_branch_flags(u64 value); 533 + void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel, 534 + const char *config_name, u64 val); 535 + 533 536 #endif /* __PERF_EVSEL_H */
+30
tools/perf/util/pmu.c
··· 33 33 #include "strbuf.h" 34 34 #include "fncache.h" 35 35 #include "pmu-hybrid.h" 36 + #include "util/evsel_config.h" 36 37 37 38 struct perf_pmu perf_pmu__fake; 38 39 ··· 1055 1054 struct perf_pmu *pmu = evsel__find_pmu(evsel); 1056 1055 1057 1056 return pmu && pmu->auxtrace; 1057 + } 1058 + 1059 + /* 1060 + * Set @config_name to @val as long as the user hasn't already set or cleared it 1061 + * by passing a config term on the command line. 1062 + * 1063 + * @val is the value to put into the bits specified by @config_name rather than 1064 + * the bit pattern. It is shifted into position by this function, so to set 1065 + * something to true, pass 1 for val rather than a pre shifted value. 1066 + */ 1067 + #define field_prep(_mask, _val) (((_val) << (ffsll(_mask) - 1)) & (_mask)) 1068 + void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel, 1069 + const char *config_name, u64 val) 1070 + { 1071 + u64 user_bits = 0, bits; 1072 + struct evsel_config_term *term = evsel__get_config_term(evsel, CFG_CHG); 1073 + 1074 + if (term) 1075 + user_bits = term->val.cfg_chg; 1076 + 1077 + bits = perf_pmu__format_bits(&pmu->format, config_name); 1078 + 1079 + /* Do nothing if the user changed the value */ 1080 + if (bits & user_bits) 1081 + return; 1082 + 1083 + /* Otherwise replace it */ 1084 + evsel->core.attr.config &= ~bits; 1085 + evsel->core.attr.config |= field_prep(bits, val); 1058 1086 } 1059 1087 1060 1088 struct perf_pmu *perf_pmu__find(const char *name)