public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Tero Kristo <tero.kristo@linux.intel.com>
Cc: x86@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com,
	tglx@linutronix.de, hpa@zytor.com, irogers@google.com,
	jolsa@kernel.org, namhyung@kernel.org, adrian.hunter@intel.com,
	acme@kernel.org, mingo@redhat.com, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org, alexander.shishkin@linux.intel.com,
	linux-perf-users@vger.kernel.org, mark.rutland@arm.com
Subject: Re: [PATCHv2 2/2] perf/core: Allow reading package events from perf_event_read_local
Date: Tue, 3 Oct 2023 13:00:18 +0200	[thread overview]
Message-ID: <20231003110018.GG27267@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20230913125956.3652667-1-tero.kristo@linux.intel.com>

On Wed, Sep 13, 2023 at 03:59:56PM +0300, Tero Kristo wrote:
> Per-package perf events are typically registered with a single CPU only,
> however they can be read across all the CPUs within the package.
> Currently perf_event_read maps the event CPU according to the topology
> information to avoid an unnecessary SMP call, however
> perf_event_read_local deals with hard values and rejects a read with a
> failure if the CPU is not the one exactly registered. Allow similar
> mapping within the perf_event_read_local if the perf event in question
> can support this.
> 
> This allows users like BPF code to read the package perf events properly
> across different CPUs within a package.
> 
> Signed-off-by: Tero Kristo <tero.kristo@linux.intel.com>
> ---
> v2:
>   * prevent illegal array access in case event->oncpu == -1
>   * split the event->cpu / event->oncpu handling to their own variables
> 
>  kernel/events/core.c | 18 +++++++++++++++---
>  1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 4c72a41f11af..6b343bac0a71 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -4425,6 +4425,9 @@ static int __perf_event_read_cpu(struct perf_event *event, int event_cpu)
>  {
>  	u16 local_pkg, event_pkg;
>  
> +	if (event_cpu < 0 || event_cpu >= nr_cpu_ids)
> +		return event_cpu;

	if ((unsigned)event_cpu >= nr_cpu_ids)
		return event_cpu;

As you could also find at the current __perf_event_read_cpu() callsite.

> +
>  	if (event->group_caps & PERF_EV_CAP_READ_ACTIVE_PKG) {
>  		int local_cpu = smp_processor_id();
>  
> @@ -4528,6 +4531,8 @@ int perf_event_read_local(struct perf_event *event, u64 *value,
>  {
>  	unsigned long flags;
>  	int ret = 0;
> +	int event_cpu;
> +	int event_oncpu;

You wrecked the x-mas tree :-)

I'll fix both up.

Thanks!

  reply	other threads:[~2023-10-03 11:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-12 12:44 [RESEND PATCH 0/2] perf/x86: Package residency counter improvements Tero Kristo
2023-09-12 12:44 ` [RESEND PATCH 1/2] perf/x86/cstate: Allow reading the package statistics from local CPU Tero Kristo
2023-09-13 12:59   ` [PATCHv2 2/2] perf/core: Allow reading package events from perf_event_read_local Tero Kristo
2023-10-03 11:00     ` Peter Zijlstra [this message]
2023-09-12 12:44 ` [RESEND PATCH " Tero Kristo
2023-09-12 14:04   ` Peter Zijlstra
2023-09-12 14:54     ` Tero Kristo

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=20231003110018.GG27267@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=bpf@vger.kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=tero.kristo@linux.intel.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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