All of lore.kernel.org
 help / color / mirror / Atom feed
From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] arm64: perf: Count EL2 events if either of kernel and hyp are not excluded
Date: Tue, 4 Apr 2017 12:18:26 +0100	[thread overview]
Message-ID: <20170404111826.GD14898@arm.com> (raw)
In-Reply-To: <1491302455-5939-1-git-send-email-ganapatrao.kulkarni@cavium.com>

On Tue, Apr 04, 2017 at 04:10:55PM +0530, Ganapatrao Kulkarni wrote:
> commit d98ecda (arm64: perf: Count EL2 events if the kernel is running in HYP)
> is returning error for perf syscall with mixed attribute set for exclude_kernel
> and exlude_hv.
> 
> This change is breaking some applications (observed with hhvm) when
> ran with VHE enabled. Adding change to enable EL2 event counting,
> if either of or both of exclude_kernel and exlude_hv are not set.
> 
> Signed-off-by: Ganapatrao Kulkarni <ganapatrao.kulkarni@cavium.com>
> ---
>  arch/arm64/kernel/perf_event.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)

Hmm. When we have VHE, we can't distinguish between hypervisor and kernel,
so this patch doesn't seem right to me. The code currently requires
both exclude_kernel and exclude_hv to be clear before we enable profiling
EL2, otherwise we're failing to exclude samples that were asked to be
excluded.

Will

> diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
> index daf95919..ea5848a 100644
> --- a/arch/arm64/kernel/perf_event.c
> +++ b/arch/arm64/kernel/perf_event.c
> @@ -871,15 +871,20 @@ static int armv8pmu_set_event_filter(struct hw_perf_event *event,
>  
>  	if (attr->exclude_idle)
>  		return -EPERM;
> -	if (is_kernel_in_hyp_mode() &&
> -	    attr->exclude_kernel != attr->exclude_hv)
> -		return -EINVAL;
> +	if (is_kernel_in_hyp_mode()) {
> +		/* include EL2 events, if either of not excluded */
> +		if ((attr->exclude_kernel != attr->exclude_hv) ||
> +				!attr->exclude_kernel ||
> +				!attr->exclude_hv)
> +			config_base |= ARMV8_PMU_INCLUDE_EL2;
> +	} else {
> +		if (attr->exclude_kernel)
> +			config_base |= ARMV8_PMU_EXCLUDE_EL1;
> +		if (!attr->exclude_hv)
> +			config_base |= ARMV8_PMU_INCLUDE_EL2;
> +	}
>  	if (attr->exclude_user)
>  		config_base |= ARMV8_PMU_EXCLUDE_EL0;
> -	if (!is_kernel_in_hyp_mode() && attr->exclude_kernel)
> -		config_base |= ARMV8_PMU_EXCLUDE_EL1;
> -	if (!attr->exclude_hv)
> -		config_base |= ARMV8_PMU_INCLUDE_EL2;
>  
>  	/*
>  	 * Install the filter into config_base as this is used to
> -- 
> 1.8.1.4
> 

WARNING: multiple messages have this Message-ID (diff)
From: Will Deacon <will.deacon@arm.com>
To: Ganapatrao Kulkarni <ganapatrao.kulkarni@cavium.com>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com,
	mark.rutland@arm.com, marc.zyngier@arm.com,
	jnair@caviumnetworks.com, gpkulkarni@gmail.com
Subject: Re: [PATCH] arm64: perf: Count EL2 events if either of kernel and hyp are not excluded
Date: Tue, 4 Apr 2017 12:18:26 +0100	[thread overview]
Message-ID: <20170404111826.GD14898@arm.com> (raw)
In-Reply-To: <1491302455-5939-1-git-send-email-ganapatrao.kulkarni@cavium.com>

On Tue, Apr 04, 2017 at 04:10:55PM +0530, Ganapatrao Kulkarni wrote:
> commit d98ecda (arm64: perf: Count EL2 events if the kernel is running in HYP)
> is returning error for perf syscall with mixed attribute set for exclude_kernel
> and exlude_hv.
> 
> This change is breaking some applications (observed with hhvm) when
> ran with VHE enabled. Adding change to enable EL2 event counting,
> if either of or both of exclude_kernel and exlude_hv are not set.
> 
> Signed-off-by: Ganapatrao Kulkarni <ganapatrao.kulkarni@cavium.com>
> ---
>  arch/arm64/kernel/perf_event.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)

Hmm. When we have VHE, we can't distinguish between hypervisor and kernel,
so this patch doesn't seem right to me. The code currently requires
both exclude_kernel and exclude_hv to be clear before we enable profiling
EL2, otherwise we're failing to exclude samples that were asked to be
excluded.

Will

> diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
> index daf95919..ea5848a 100644
> --- a/arch/arm64/kernel/perf_event.c
> +++ b/arch/arm64/kernel/perf_event.c
> @@ -871,15 +871,20 @@ static int armv8pmu_set_event_filter(struct hw_perf_event *event,
>  
>  	if (attr->exclude_idle)
>  		return -EPERM;
> -	if (is_kernel_in_hyp_mode() &&
> -	    attr->exclude_kernel != attr->exclude_hv)
> -		return -EINVAL;
> +	if (is_kernel_in_hyp_mode()) {
> +		/* include EL2 events, if either of not excluded */
> +		if ((attr->exclude_kernel != attr->exclude_hv) ||
> +				!attr->exclude_kernel ||
> +				!attr->exclude_hv)
> +			config_base |= ARMV8_PMU_INCLUDE_EL2;
> +	} else {
> +		if (attr->exclude_kernel)
> +			config_base |= ARMV8_PMU_EXCLUDE_EL1;
> +		if (!attr->exclude_hv)
> +			config_base |= ARMV8_PMU_INCLUDE_EL2;
> +	}
>  	if (attr->exclude_user)
>  		config_base |= ARMV8_PMU_EXCLUDE_EL0;
> -	if (!is_kernel_in_hyp_mode() && attr->exclude_kernel)
> -		config_base |= ARMV8_PMU_EXCLUDE_EL1;
> -	if (!attr->exclude_hv)
> -		config_base |= ARMV8_PMU_INCLUDE_EL2;
>  
>  	/*
>  	 * Install the filter into config_base as this is used to
> -- 
> 1.8.1.4
> 

  reply	other threads:[~2017-04-04 11:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-04 10:40 [PATCH] arm64: perf: Count EL2 events if either of kernel and hyp are not excluded Ganapatrao Kulkarni
2017-04-04 10:40 ` Ganapatrao Kulkarni
2017-04-04 11:18 ` Will Deacon [this message]
2017-04-04 11:18   ` Will Deacon
2017-04-04 12:07   ` Ganapatrao Kulkarni
2017-04-04 12:07     ` Ganapatrao Kulkarni
2017-04-04 12:26     ` Will Deacon
2017-04-04 12:26       ` Will Deacon
2017-04-05  3:59       ` Ganapatrao Kulkarni
2017-04-05  3:59         ` Ganapatrao Kulkarni
2017-04-05  8:31         ` Will Deacon
2017-04-05  8:31           ` Will Deacon
2017-04-05  9:46           ` Ganapatrao Kulkarni
2017-04-05  9:46             ` Ganapatrao Kulkarni
2017-04-05  9:48           ` Ganapatrao Kulkarni
2017-04-05  9:48             ` Ganapatrao Kulkarni

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=20170404111826.GD14898@arm.com \
    --to=will.deacon@arm.com \
    --cc=linux-arm-kernel@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.