linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
To: kan.liang@linux.intel.com, peterz@infradead.org,
	mingo@redhat.com, namhyung@kernel.org, irogers@google.com,
	mark.rutland@arm.com, linux-kernel@vger.kernel.org,
	linux-perf-users@vger.kernel.org,
	Athira Rajeev <atrajeev@linux.ibm.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: eranian@google.com, ctshao@google.com, tmricht@linux.ibm.com,
	leo.yan@arm.com, Aishwarya TCV <aishwarya.tcv@arm.com>
Subject: Re: [PATCH V2] perf: Fix the throttle error of some clock events
Date: Tue, 3 Jun 2025 18:15:16 +0530	[thread overview]
Message-ID: <8e8f51d8-af64-4d9e-934b-c0ee9f131293@linux.ibm.com> (raw)
In-Reply-To: <20250528175832.2999139-1-kan.liang@linux.intel.com>


On 28/05/25 11:28 pm, kan.liang@linux.intel.com wrote:
> From: Kan Liang <kan.liang@linux.intel.com>
>
> The Arm CI reports RCU stall, which can be reproduced by the below perf
> command.
>    perf record -a -e cpu-clock -- sleep 2


This issue is reported on IBM CI as well. But the issue is hit, while 
running perf test (specifically while running  76: perf list tests)

>
> The cpu-clock and task_clock are two special SW events, which rely on
> the hrtimer. Instead of invoking the stop(), the HRTIMER_NORESTART is
> returned to stop the timer. Because the hrtimer interrupt handler cannot
> cancel itself, which causes infinite loop.
>
> There may be two ways to fix it.
> - Add a check of MAX_INTERRUPTS in the event_stop. Return immediately if
> the stop is invoked by the throttle.
> - Introduce a PMU flag to track the case. Avoid the event_stop in
> perf_event_throttle() if the flag is detected.
>
> The latter looks more generic. It may be used if there are more other
> cases that want to avoid the stop later. The latter is implemented.


Tested this patch by applying on the linux-mainline kernel on IBM Power9 
system, and it fixes the issue. Hence,


Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>



Regards,

Venkat.

>
> Reported-by: Leo Yan <leo.yan@arm.com>
> Reported-by: Aishwarya TCV <aishwarya.tcv@arm.com>
> Closes: https://lore.kernel.org/lkml/20250527161656.GJ2566836@e132581.arm.com/
> Tested-by: Leo Yan <leo.yan@arm.com>
> Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
> ---
>
> Changes since V1:
> - Rebase on top of the latest tip.git
> - Add Tested-by from Leo
>
>   include/linux/perf_event.h |  1 +
>   kernel/events/core.c       | 23 ++++++++++++++++++++---
>   2 files changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> index 52dc7cfab0e0..97a747a97a50 100644
> --- a/include/linux/perf_event.h
> +++ b/include/linux/perf_event.h
> @@ -305,6 +305,7 @@ struct perf_event_pmu_context;
>   #define PERF_PMU_CAP_EXTENDED_HW_TYPE	0x0100
>   #define PERF_PMU_CAP_AUX_PAUSE		0x0200
>   #define PERF_PMU_CAP_AUX_PREFER_LARGE	0x0400
> +#define PERF_PMU_CAP_NO_THROTTLE_STOP	0x0800
>   
>   /**
>    * pmu::scope
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index f34c99f8ce8f..abd19bb571e3 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -2656,7 +2656,22 @@ static void perf_event_unthrottle(struct perf_event *event, bool start)
>   
>   static void perf_event_throttle(struct perf_event *event)
>   {
> -	event->pmu->stop(event, 0);
> +	/*
> +	 * Some PMUs, e.g., cpu-clock and task_clock, may rely on
> +	 * a special mechanism (hrtimer) to manipulate counters.
> +	 * The regular stop doesn't work, since the hrtimer interrupt
> +	 * handler cannot cancel itself.
> +	 *
> +	 * The stop should be avoided for such cases. Let the
> +	 * driver-specific code handle it.
> +	 *
> +	 * The counters will eventually be disabled in the driver-specific
> +	 * code. In unthrottle, they still need to be re-enabled.
> +	 * There is no handling for PERF_PMU_CAP_NO_THROTTLE_STOP in
> +	 * the perf_event_unthrottle().
> +	 */
> +	if (!(event->pmu->capabilities & PERF_PMU_CAP_NO_THROTTLE_STOP))
> +		event->pmu->stop(event, 0);
>   	event->hw.interrupts = MAX_INTERRUPTS;
>   	if (event == event->group_leader)
>   		perf_log_throttle(event, 0);
> @@ -11848,7 +11863,8 @@ static int cpu_clock_event_init(struct perf_event *event)
>   static struct pmu perf_cpu_clock = {
>   	.task_ctx_nr	= perf_sw_context,
>   
> -	.capabilities	= PERF_PMU_CAP_NO_NMI,
> +	.capabilities	= PERF_PMU_CAP_NO_NMI |
> +			  PERF_PMU_CAP_NO_THROTTLE_STOP,
>   	.dev		= PMU_NULL_DEV,
>   
>   	.event_init	= cpu_clock_event_init,
> @@ -11930,7 +11946,8 @@ static int task_clock_event_init(struct perf_event *event)
>   static struct pmu perf_task_clock = {
>   	.task_ctx_nr	= perf_sw_context,
>   
> -	.capabilities	= PERF_PMU_CAP_NO_NMI,
> +	.capabilities	= PERF_PMU_CAP_NO_NMI |
> +			  PERF_PMU_CAP_NO_THROTTLE_STOP,
>   	.dev		= PMU_NULL_DEV,
>   
>   	.event_init	= task_clock_event_init,

  reply	other threads:[~2025-06-03 12:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-28 17:58 [PATCH V2] perf: Fix the throttle error of some clock events kan.liang
2025-06-03 12:45 ` Venkat Rao Bagalkote [this message]
2025-06-03 16:35 ` Ian Rogers
2025-06-03 20:22   ` Liang, Kan

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=8e8f51d8-af64-4d9e-934b-c0ee9f131293@linux.ibm.com \
    --to=venkat88@linux.ibm.com \
    --cc=aishwarya.tcv@arm.com \
    --cc=atrajeev@linux.ibm.com \
    --cc=ctshao@google.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=kan.liang@linux.intel.com \
    --cc=leo.yan@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=maddy@linux.ibm.com \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tmricht@linux.ibm.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).