linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Namhyung Kim <namhyung@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Jiri Olsa <jolsa@kernel.org>
Cc: Ian Rogers <irogers@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-perf-users@vger.kernel.org,
	Kan Liang <kan.liang@linux.intel.com>,
	Leo Yan <leo.yan@linaro.org>
Subject: Re: [PATCH 9/9] perf intel-pt: Use perf_pmu__scan_file_at() if possible
Date: Mon, 3 Apr 2023 07:51:01 +0300	[thread overview]
Message-ID: <eb1c058c-f84f-ae94-ced6-92f22b6d9b69@intel.com> (raw)
In-Reply-To: <20230331202949.810326-10-namhyung@kernel.org>

On 31/03/23 23:29, Namhyung Kim wrote:
> 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: Namhyung Kim <namhyung@kernel.org>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  tools/perf/arch/x86/util/intel-pt.c | 52 ++++++++++++++++++-----------
>  1 file changed, 32 insertions(+), 20 deletions(-)
> 
> diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
> index 1e39a034cee9..2cff11de9d8a 100644
> --- a/tools/perf/arch/x86/util/intel-pt.c
> +++ b/tools/perf/arch/x86/util/intel-pt.c
> @@ -194,16 +194,19 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu)
>  	int pos = 0;
>  	u64 config;
>  	char c;
> +	int dirfd;
> +
> +	dirfd = perf_pmu__event_source_devices_fd();
>  
>  	pos += scnprintf(buf + pos, sizeof(buf) - pos, "tsc");
>  
> -	if (perf_pmu__scan_file(intel_pt_pmu, "caps/mtc", "%d",
> -				&mtc) != 1)
> +	if (perf_pmu__scan_file_at(intel_pt_pmu, dirfd, "caps/mtc", "%d",
> +				   &mtc) != 1)
>  		mtc = 1;
>  
>  	if (mtc) {
> -		if (perf_pmu__scan_file(intel_pt_pmu, "caps/mtc_periods", "%x",
> -					&mtc_periods) != 1)
> +		if (perf_pmu__scan_file_at(intel_pt_pmu, dirfd, "caps/mtc_periods", "%x",
> +					   &mtc_periods) != 1)
>  			mtc_periods = 0;
>  		if (mtc_periods) {
>  			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)
>  		}
>  	}
>  
> -	if (perf_pmu__scan_file(intel_pt_pmu, "caps/psb_cyc", "%d",
> -				&psb_cyc) != 1)
> +	if (perf_pmu__scan_file_at(intel_pt_pmu, dirfd, "caps/psb_cyc", "%d",
> +				   &psb_cyc) != 1)
>  		psb_cyc = 1;
>  
>  	if (psb_cyc && mtc_periods) {
> -		if (perf_pmu__scan_file(intel_pt_pmu, "caps/psb_periods", "%x",
> -					&psb_periods) != 1)
> +		if (perf_pmu__scan_file_at(intel_pt_pmu, dirfd, "caps/psb_periods", "%x",
> +					   &psb_periods) != 1)
>  			psb_periods = 0;
>  		if (psb_periods) {
>  			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)
>  		}
>  	}
>  
> -	if (perf_pmu__scan_file(intel_pt_pmu, "format/pt", "%c", &c) == 1 &&
> -	    perf_pmu__scan_file(intel_pt_pmu, "format/branch", "%c", &c) == 1)
> +	if (perf_pmu__scan_file_at(intel_pt_pmu, dirfd, "format/pt", "%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");
>  
>  	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)
>  	intel_pt_parse_terms(intel_pt_pmu->name, &intel_pt_pmu->format, buf,
>  			     &config);
>  
> +	close(dirfd);
>  	return config;
>  }
>  
> @@ -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 *supported, u64 config)
>  {
> @@ -498,11 +502,11 @@ static int intel_pt_val_config_term(struct perf_pmu *intel_pt_pmu,
>  	u64 bits;
>  	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;
>  
>  	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 |= 1;
> @@ -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,
>  				    struct evsel *evsel)
>  {
> -	int err;
> +	int err, dirfd;
>  	char c;
>  
>  	if (!evsel)
>  		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
>  	 * 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)) {
>  		pr_warning("pt=0 doesn't make sense, forcing pt=1\n");
>  		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",
>  				       evsel->core.attr.config);
>  	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",
>  				       evsel->core.attr.config);
>  	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",
>  					evsel->core.attr.config);
> +
> +out:
> +	close(dirfd);
> +	return err;
>  }
>  
>  static void intel_pt_config_sample_mode(struct perf_pmu *intel_pt_pmu,


  reply	other threads:[~2023-04-03  4:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-31 20:29 [PATCHSET 0/9] perf tools: Update pmu scan using openat() (v1) Namhyung Kim
2023-03-31 20:29 ` [PATCH 1/9] perf list: Use relative path for tracepoint scan Namhyung Kim
2023-04-03 21:59   ` Arnaldo Carvalho de Melo
2023-04-03 22:00     ` Arnaldo Carvalho de Melo
2023-04-04 14:10     ` Arnaldo Carvalho de Melo
2023-04-04 22:08       ` Namhyung Kim
2023-04-04 22:19         ` Arnaldo Carvalho de Melo
2023-03-31 20:29 ` [PATCH 2/9] perf tools: Fix a asan issue in parse_events_multi_pmu_add() Namhyung Kim
2023-03-31 20:29 ` [PATCH 3/9] perf pmu: Add perf_pmu__destroy() function Namhyung Kim
2023-03-31 20:29 ` [PATCH 4/9] perf bench: Add pmu-scan benchmark Namhyung Kim
2023-03-31 20:29 ` [PATCH 5/9] perf pmu: Use relative path for sysfs scan Namhyung Kim
2023-04-03 17:23   ` Ian Rogers
2023-03-31 20:29 ` [PATCH 6/9] perf pmu: Use relative path in perf_pmu__caps_parse() Namhyung Kim
2023-03-31 20:29 ` [PATCH 7/9] perf pmu: Use relative path in setup_pmu_alias_list() Namhyung Kim
2023-03-31 20:29 ` [PATCH 8/9] perf pmu: Add perf_pmu__{open,scan}_file_at() Namhyung Kim
2023-03-31 20:29 ` [PATCH 9/9] perf intel-pt: Use perf_pmu__scan_file_at() if possible Namhyung Kim
2023-04-03  4:51   ` Adrian Hunter [this message]
2023-04-03 17:28 ` [PATCHSET 0/9] perf tools: Update pmu scan using openat() (v1) Ian Rogers
2023-04-03 20:25   ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb1c058c-f84f-ae94-ced6-92f22b6d9b69@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).