Commit 98b7ce0e authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf intel-pt: Use perf_pmu__scan_file_at() if possible

Intel-PT calls perf_pmu__scan_file() a lot, let's use relative address
when it accesses multiple files at one place.
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Acked-by: default avatarIan Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230331202949.810326-2-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 3a69672e
...@@ -194,16 +194,19 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu) ...@@ -194,16 +194,19 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu)
int pos = 0; int pos = 0;
u64 config; u64 config;
char c; char c;
int dirfd;
dirfd = perf_pmu__event_source_devices_fd();
pos += scnprintf(buf + pos, sizeof(buf) - pos, "tsc"); pos += scnprintf(buf + pos, sizeof(buf) - pos, "tsc");
if (perf_pmu__scan_file(intel_pt_pmu, "caps/mtc", "%d", if (perf_pmu__scan_file_at(intel_pt_pmu, dirfd, "caps/mtc", "%d",
&mtc) != 1) &mtc) != 1)
mtc = 1; mtc = 1;
if (mtc) { if (mtc) {
if (perf_pmu__scan_file(intel_pt_pmu, "caps/mtc_periods", "%x", if (perf_pmu__scan_file_at(intel_pt_pmu, dirfd, "caps/mtc_periods", "%x",
&mtc_periods) != 1) &mtc_periods) != 1)
mtc_periods = 0; mtc_periods = 0;
if (mtc_periods) { if (mtc_periods) {
mtc_period = intel_pt_pick_bit(mtc_periods, 3); mtc_period = intel_pt_pick_bit(mtc_periods, 3);
...@@ -212,13 +215,13 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu) ...@@ -212,13 +215,13 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu)
} }
} }
if (perf_pmu__scan_file(intel_pt_pmu, "caps/psb_cyc", "%d", if (perf_pmu__scan_file_at(intel_pt_pmu, dirfd, "caps/psb_cyc", "%d",
&psb_cyc) != 1) &psb_cyc) != 1)
psb_cyc = 1; psb_cyc = 1;
if (psb_cyc && mtc_periods) { if (psb_cyc && mtc_periods) {
if (perf_pmu__scan_file(intel_pt_pmu, "caps/psb_periods", "%x", if (perf_pmu__scan_file_at(intel_pt_pmu, dirfd, "caps/psb_periods", "%x",
&psb_periods) != 1) &psb_periods) != 1)
psb_periods = 0; psb_periods = 0;
if (psb_periods) { if (psb_periods) {
psb_period = intel_pt_pick_bit(psb_periods, 3); psb_period = intel_pt_pick_bit(psb_periods, 3);
...@@ -227,8 +230,8 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu) ...@@ -227,8 +230,8 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu)
} }
} }
if (perf_pmu__scan_file(intel_pt_pmu, "format/pt", "%c", &c) == 1 && if (perf_pmu__scan_file_at(intel_pt_pmu, dirfd, "format/pt", "%c", &c) == 1 &&
perf_pmu__scan_file(intel_pt_pmu, "format/branch", "%c", &c) == 1) perf_pmu__scan_file_at(intel_pt_pmu, dirfd, "format/branch", "%c", &c) == 1)
pos += scnprintf(buf + pos, sizeof(buf) - pos, ",pt,branch"); pos += scnprintf(buf + pos, sizeof(buf) - pos, ",pt,branch");
pr_debug2("%s default config: %s\n", intel_pt_pmu->name, buf); pr_debug2("%s default config: %s\n", intel_pt_pmu->name, buf);
...@@ -236,6 +239,7 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu) ...@@ -236,6 +239,7 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu)
intel_pt_parse_terms(intel_pt_pmu->name, &intel_pt_pmu->format, buf, intel_pt_parse_terms(intel_pt_pmu->name, &intel_pt_pmu->format, buf,
&config); &config);
close(dirfd);
return config; return config;
} }
...@@ -488,7 +492,7 @@ static void intel_pt_valid_str(char *str, size_t len, u64 valid) ...@@ -488,7 +492,7 @@ static void intel_pt_valid_str(char *str, size_t len, u64 valid)
} }
} }
static int intel_pt_val_config_term(struct perf_pmu *intel_pt_pmu, static int intel_pt_val_config_term(struct perf_pmu *intel_pt_pmu, int dirfd,
const char *caps, const char *name, const char *caps, const char *name,
const char *supported, u64 config) const char *supported, u64 config)
{ {
...@@ -498,11 +502,11 @@ static int intel_pt_val_config_term(struct perf_pmu *intel_pt_pmu, ...@@ -498,11 +502,11 @@ static int intel_pt_val_config_term(struct perf_pmu *intel_pt_pmu,
u64 bits; u64 bits;
int ok; int ok;
if (perf_pmu__scan_file(intel_pt_pmu, caps, "%llx", &valid) != 1) if (perf_pmu__scan_file_at(intel_pt_pmu, dirfd, caps, "%llx", &valid) != 1)
valid = 0; valid = 0;
if (supported && if (supported &&
perf_pmu__scan_file(intel_pt_pmu, supported, "%d", &ok) == 1 && !ok) perf_pmu__scan_file_at(intel_pt_pmu, dirfd, supported, "%d", &ok) == 1 && !ok)
valid = 0; valid = 0;
valid |= 1; valid |= 1;
...@@ -531,37 +535,45 @@ static int intel_pt_val_config_term(struct perf_pmu *intel_pt_pmu, ...@@ -531,37 +535,45 @@ static int intel_pt_val_config_term(struct perf_pmu *intel_pt_pmu,
static int intel_pt_validate_config(struct perf_pmu *intel_pt_pmu, static int intel_pt_validate_config(struct perf_pmu *intel_pt_pmu,
struct evsel *evsel) struct evsel *evsel)
{ {
int err; int err, dirfd;
char c; char c;
if (!evsel) if (!evsel)
return 0; return 0;
dirfd = perf_pmu__event_source_devices_fd();
if (dirfd < 0)
return dirfd;
/* /*
* If supported, force pass-through config term (pt=1) even if user * If supported, force pass-through config term (pt=1) even if user
* sets pt=0, which avoids senseless kernel errors. * sets pt=0, which avoids senseless kernel errors.
*/ */
if (perf_pmu__scan_file(intel_pt_pmu, "format/pt", "%c", &c) == 1 && if (perf_pmu__scan_file_at(intel_pt_pmu, dirfd, "format/pt", "%c", &c) == 1 &&
!(evsel->core.attr.config & 1)) { !(evsel->core.attr.config & 1)) {
pr_warning("pt=0 doesn't make sense, forcing pt=1\n"); pr_warning("pt=0 doesn't make sense, forcing pt=1\n");
evsel->core.attr.config |= 1; evsel->core.attr.config |= 1;
} }
err = intel_pt_val_config_term(intel_pt_pmu, "caps/cycle_thresholds", err = intel_pt_val_config_term(intel_pt_pmu, dirfd, "caps/cycle_thresholds",
"cyc_thresh", "caps/psb_cyc", "cyc_thresh", "caps/psb_cyc",
evsel->core.attr.config); evsel->core.attr.config);
if (err) if (err)
return err; goto out;
err = intel_pt_val_config_term(intel_pt_pmu, "caps/mtc_periods", err = intel_pt_val_config_term(intel_pt_pmu, dirfd, "caps/mtc_periods",
"mtc_period", "caps/mtc", "mtc_period", "caps/mtc",
evsel->core.attr.config); evsel->core.attr.config);
if (err) if (err)
return err; goto out;
return intel_pt_val_config_term(intel_pt_pmu, "caps/psb_periods", err = intel_pt_val_config_term(intel_pt_pmu, dirfd, "caps/psb_periods",
"psb_period", "caps/psb_cyc", "psb_period", "caps/psb_cyc",
evsel->core.attr.config); evsel->core.attr.config);
out:
close(dirfd);
return err;
} }
static void intel_pt_config_sample_mode(struct perf_pmu *intel_pt_pmu, static void intel_pt_config_sample_mode(struct perf_pmu *intel_pt_pmu,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment