mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Liang Yan <lyan@digitalocean.com>, Ravi Bangoria <ravi.bangoria@amd.com>
Cc: 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>, Namhyung Kim <namhyung@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] arch/x86/events/amd/core.c: Return -ENODEV when CPU does not have PERFCTL_CORE bit
Date: Mon, 31 Oct 2022 13:59:42 +0100	[thread overview]
Message-ID: <Y1/Gvs0xkk/W0Nro@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20221027133511.161922-1-lyan@digtalocean.com>

On Thu, Oct 27, 2022 at 09:35:11AM -0400, Liang Yan wrote:
> After disabling cpu.perfctr_core in qemu, I noticed that the guest kernel
> still loads the pmu driver while the cpuid does not have perfctl_core.
> 
> The test is running on an EPYC Rome machine.
> root@ubuntu-s-4vcpu-8gb-amd-nyc1-01:~# lscpu | grep perfctl
> root@ubuntu-s-4vcpu-8gb-amd-nyc1-01:~#
> root@ubuntu-s-4vcpu-8gb-amd-nyc1-01:~# dmesg | grep PMU
> [    0.732097] Performance Events: AMD PMU driver.
> 
> By further looking,
> 
> ==> init_hw_perf_events
>     ==> amd_pmu_init
>         ==> amd_core_pmu_init
>             ==>
>                 if (!boot_cpu_has(X86_FEATURE_PERFCTR_CORE))
> 			return 0;
> 
> With returning 0, it will bypass amd_pmu_init and return 0 to
> init_hw_perf_events, and continue the initialization.
> 
> I am not a perf expert and not sure if it is expected for AMD PMU,
> otherwise, it would be nice to return -ENODEV instead.
> 
> New output after the change:
> root@ubuntu-s-4vcpu-8gb-amd-nyc1-01:~# dmesg | grep PMU
> [    0.531609] Performance Events: no PMU driver, software events only.
> 
> Signed-off-by: Liang Yan <lyan@digtalocean.com>

Looks about right, Ravi?

> ---
>  arch/x86/events/amd/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
> index 8b70237c33f7..34d3d2944020 100644
> --- a/arch/x86/events/amd/core.c
> +++ b/arch/x86/events/amd/core.c
> @@ -1335,7 +1335,7 @@ static int __init amd_core_pmu_init(void)
>  	int i;
>  
>  	if (!boot_cpu_has(X86_FEATURE_PERFCTR_CORE))
> -		return 0;
> +		return -ENODEV;
>  
>  	/* Avoid calculating the value each time in the NMI handler */
>  	perf_nmi_window = msecs_to_jiffies(100);
> -- 
> 2.34.1
> 

  reply	other threads:[~2022-10-31 12:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-27 13:35 Liang Yan
2022-10-31 12:59 ` Peter Zijlstra [this message]
2022-10-31 14:28   ` Sandipan Das
2022-11-12 22:33     ` Liang Yan
2022-11-14 10:52       ` Sandipan Das
2022-11-23  5:41         ` Sandipan Das

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=Y1/Gvs0xkk/W0Nro@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=lyan@digitalocean.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=ravi.bangoria@amd.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

all inboxes | Powered by JetHome®