Skip to content

Commit 6593f01

Browse files
James-A-Clarkacmel
authored andcommitted
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>
1 parent 449067f commit 6593f01

4 files changed

Lines changed: 37 additions & 44 deletions

File tree

tools/perf/arch/arm64/util/arm-spe.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,6 @@ struct arm_spe_recording {
3636
bool *wrapped;
3737
};
3838

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-
6239
static size_t
6340
arm_spe_info_priv_size(struct auxtrace_record *itr __maybe_unused,
6441
struct evlist *evlist __maybe_unused)
@@ -238,7 +215,8 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
238215
*/
239216
if (!perf_cpu_map__empty(cpus)) {
240217
evsel__set_sample_bit(arm_spe_evsel, CPU);
241-
arm_spe_set_timestamp(itr, arm_spe_evsel);
218+
evsel__set_config_if_unset(arm_spe_pmu, arm_spe_evsel,
219+
"ts_enable", 1);
242220
}
243221

244222
/*

tools/perf/arch/x86/util/intel-pt.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -576,25 +576,6 @@ static int intel_pt_validate_config(struct perf_pmu *intel_pt_pmu,
576576
return err;
577577
}
578578

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-
598579
static void intel_pt_min_max_sample_sz(struct evlist *evlist,
599580
size_t *min_sz, size_t *max_sz)
600581
{
@@ -686,7 +667,8 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
686667
return 0;
687668

688669
if (opts->auxtrace_sample_mode)
689-
intel_pt_config_sample_mode(intel_pt_pmu, intel_pt_evsel);
670+
evsel__set_config_if_unset(intel_pt_pmu, intel_pt_evsel,
671+
"psb_period", 0);
690672

691673
err = intel_pt_validate_config(intel_pt_pmu, intel_pt_evsel);
692674
if (err)

tools/perf/util/evsel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,4 +530,7 @@ bool arch_evsel__must_be_in_group(const struct evsel *evsel);
530530
((((src) >> (pos)) & ((1ull << (size)) - 1)) << (63 - ((pos) + (size) - 1)))
531531

532532
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+
533536
#endif /* __PERF_EVSEL_H */

tools/perf/util/pmu.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "strbuf.h"
3434
#include "fncache.h"
3535
#include "pmu-hybrid.h"
36+
#include "util/evsel_config.h"
3637

3738
struct perf_pmu perf_pmu__fake;
3839

@@ -1056,6 +1057,35 @@ bool evsel__is_aux_event(const struct evsel *evsel)
10561057
return pmu && pmu->auxtrace;
10571058
}
10581059

1060+
/*
1061+
* Set @config_name to @val as long as the user hasn't already set or cleared it
1062+
* by passing a config term on the command line.
1063+
*
1064+
* @val is the value to put into the bits specified by @config_name rather than
1065+
* the bit pattern. It is shifted into position by this function, so to set
1066+
* something to true, pass 1 for val rather than a pre shifted value.
1067+
*/
1068+
#define field_prep(_mask, _val) (((_val) << (ffsll(_mask) - 1)) & (_mask))
1069+
void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel,
1070+
const char *config_name, u64 val)
1071+
{
1072+
u64 user_bits = 0, bits;
1073+
struct evsel_config_term *term = evsel__get_config_term(evsel, CFG_CHG);
1074+
1075+
if (term)
1076+
user_bits = term->val.cfg_chg;
1077+
1078+
bits = perf_pmu__format_bits(&pmu->format, config_name);
1079+
1080+
/* Do nothing if the user changed the value */
1081+
if (bits & user_bits)
1082+
return;
1083+
1084+
/* Otherwise replace it */
1085+
evsel->core.attr.config &= ~bits;
1086+
evsel->core.attr.config |= field_prep(bits, val);
1087+
}
1088+
10591089
struct perf_pmu *perf_pmu__find(const char *name)
10601090
{
10611091
struct perf_pmu *pmu;

0 commit comments

Comments
 (0)