linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Andi Kleen <ak@linux.intel.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	Thomas Richter <tmricht@linux.ibm.com>,
	James Clark <james.clark@arm.com>,
	Miaoqian Lin <linmq006@gmail.com>,
	John Garry <john.garry@huawei.com>,
	Zhengjun Xing <zhengjun.xing@linux.intel.com>,
	Florian Fischer <florian.fischer@muhq.space>,
	linux-perf-users <linux-perf-users@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	perry.taylor@intel.com, caleb.biggers@intel.com,
	kshipra.bopardikar@intel.com, ahmad.yasin@intel.com,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH v2 4/7] perf topology: Add core_wide
Date: Thu, 1 Sep 2022 23:29:22 -0700	[thread overview]
Message-ID: <CAM9d7cgRb6_jFXCfoZZ+=K5WSH42hj4U2ZH-i-4oZTMKw+LAiA@mail.gmail.com> (raw)
In-Reply-To: <20220831174926.579643-5-irogers@google.com>

Hi Ian,

On Wed, Aug 31, 2022 at 10:50 AM Ian Rogers <irogers@google.com> wrote:
>
> It is possible to optimize metrics when all SMT threads (CPUs) on a
> core are measuring events in system wide mode. For example, TMA
> metrics defines CORE_CLKS for Sandybrdige as:
>
> if SMT is disabled:
>   CPU_CLK_UNHALTED.THREAD
> if SMT is enabled and recording on all SMT threads:
>   CPU_CLK_UNHALTED.THREAD_ANY / 2
> if SMT is enabled and not recording on all SMT threads:
>   (CPU_CLK_UNHALTED.THREAD/2)*
>   (1+CPU_CLK_UNHALTED.ONE_THREAD_ACTIVE/CPU_CLK_UNHALTED.REF_XCLK )
>
> That is two more events are necessary when not gathering counts on all
> SMT threads. To distinguish all SMT threads on a core vs system wide
> (all CPUs) call the new property core wide.  Add a core wide test that
> determines the property from user requested CPUs, the topology and
> system wide. System wide is required as other processes running on a
> SMT thread will change the counts.
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
[SNIP]
> diff --git a/tools/perf/util/smt.c b/tools/perf/util/smt.c
> index ce90c4ee4138..994e9e418227 100644
> --- a/tools/perf/util/smt.c
> +++ b/tools/perf/util/smt.c
> @@ -21,3 +21,17 @@ bool smt_on(const struct cpu_topology *topology)
>         cached = true;
>         return cached_result;
>  }
> +
> +bool core_wide(bool system_wide, const char *user_requested_cpu_list,
> +              const struct cpu_topology *topology)
> +{
> +       /* If not everything running on a core is being recorded then we can't use core_wide. */
> +       if (!system_wide)
> +               return false;

I'm not sure if it's correct.  Wouldn't it be ok if it runs on all
threads in a core
even if system wide is off?  I thought that's what the below code checks.

In fact I thought the opposite logic like

    if (system_wide)
        return true;

But it seems the code allows to have cpu_list in the system wide mode.
Then it also needs to check the user requested cpus being NULL.
(IMHO system_wide should be cleared when it has a cpu list...)

    if (system_wide && !user_requested_cpu_list)
        return true;

And if we have a target pointer, we could add this too.

    if (!target__has_cpu(target))
        return false;

Thanks,
Namhyung


> +
> +       /* Cheap case that SMT is disabled and therefore we're inherently core_wide. */
> +       if (!smt_on(topology))
> +               return true;
> +
> +       return cpu_topology__core_wide(topology, user_requested_cpu_list);
> +}
> diff --git a/tools/perf/util/smt.h b/tools/perf/util/smt.h
> index e26999c6b8d4..ae9095f2c38c 100644
> --- a/tools/perf/util/smt.h
> +++ b/tools/perf/util/smt.h
> @@ -7,4 +7,11 @@ struct cpu_topology;
>  /* Returns true if SMT (aka hyperthreading) is enabled. */
>  bool smt_on(const struct cpu_topology *topology);
>
> +/*
> + * Returns true when system wide and all SMT threads for a core are in the
> + * user_requested_cpus map.
> + */
> +bool core_wide(bool system_wide, const char *user_requested_cpu_list,
> +              const struct cpu_topology *topology);
> +
>  #endif /* __SMT_H */
> --
> 2.37.2.672.g94769d06f0-goog
>

  reply	other threads:[~2022-09-02  6:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31 17:49 [PATCH v2 0/7] Add core wide metric literal Ian Rogers
2022-08-31 17:49 ` [PATCH v2 1/7] perf metric: Return early if no CPU PMU table exists Ian Rogers
2022-08-31 17:49 ` [PATCH v2 2/7] perf expr: Move the scanner_ctx into the parse_ctx Ian Rogers
2022-08-31 17:49 ` [PATCH v2 3/7] perf smt: Compute SMT from topology Ian Rogers
2022-08-31 17:49 ` [PATCH v2 4/7] perf topology: Add core_wide Ian Rogers
2022-09-02  6:29   ` Namhyung Kim [this message]
2022-09-06 18:56     ` Ian Rogers
2022-09-09 18:29       ` Namhyung Kim
2022-08-31 17:49 ` [PATCH v2 5/7] perf stat: Delay metric parsing Ian Rogers
2022-08-31 17:49 ` [PATCH v2 6/7] perf metrics: Wire up core_wide Ian Rogers
2022-08-31 17:49 ` [PATCH v2 7/7] perf test: Add basic core_wide expression test Ian Rogers

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='CAM9d7cgRb6_jFXCfoZZ+=K5WSH42hj4U2ZH-i-4oZTMKw+LAiA@mail.gmail.com' \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=ahmad.yasin@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=caleb.biggers@intel.com \
    --cc=eranian@google.com \
    --cc=florian.fischer@muhq.space \
    --cc=irogers@google.com \
    --cc=james.clark@arm.com \
    --cc=john.garry@huawei.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=kshipra.bopardikar@intel.com \
    --cc=linmq006@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=perry.taylor@intel.com \
    --cc=peterz@infradead.org \
    --cc=tmricht@linux.ibm.com \
    --cc=zhengjun.xing@linux.intel.com \
    /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).