linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Luo Gengkun <luogengkun@huaweicloud.com>, peterz@infradead.org
Cc: acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, jolsa@kernel.org,
	irogers@google.com, adrian.hunter@intel.com, tglx@linutronix.de,
	bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
	hpa@zytor.com, linux-perf-users@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf/x86/intel: Fix lbr event can placed into non lbr group
Date: Mon, 14 Apr 2025 10:29:47 -0400	[thread overview]
Message-ID: <342ad7ad-417b-446d-8269-521a1ce9a6c6@linux.intel.com> (raw)
In-Reply-To: <20250412091423.1839809-1-luogengkun@huaweicloud.com>



On 2025-04-12 5:14 a.m., Luo Gengkun wrote:
> The following perf command can trigger a warning on
> intel_pmu_lbr_counters_reorder.
> 
>  # perf record -e "{cpu-clock,cycles/call-graph="lbr"/}" -- sleep 1
> 
> The reason is that a lbr event are placed in non lbr group. And the
> previous implememtation cannot force the leader to be a lbr event in this
> case. 

Perf should only force the LBR leader for the branch counters case, so
perf only needs to reset the LBRs for the leader.
I don't think the leader restriction should be applied to other cases.

> And is_branch_counters_group will check if the group_leader supports
> BRANCH_COUNTERS.
> So if a software event becomes a group_leader, which
> hw.flags is -1, this check will alway pass.

I think the default flags for all events is 0. Can you point me to where
it is changed to -1?

Thanks,
Kan>
> To fix this problem, using has_branch_stack to judge if leader is lbr
> event.
> 
> Fixes: 33744916196b ("perf/x86/intel: Support branch counters logging")
> Signed-off-by: Luo Gengkun <luogengkun@huaweicloud.com>
> ---
>  arch/x86/events/intel/core.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> index 09d2d66c9f21..c6b394019e54 100644
> --- a/arch/x86/events/intel/core.c
> +++ b/arch/x86/events/intel/core.c
> @@ -4114,6 +4114,13 @@ static int intel_pmu_hw_config(struct perf_event *event)
>  			event->hw.flags |= PERF_X86_EVENT_NEEDS_BRANCH_STACK;
>  	}
>  
> +	/*
> +	 * Force the leader to be a LBR event. So LBRs can be reset
> +	 * with the leader event. See intel_pmu_lbr_del() for details.
> +	 */
> +	if (has_branch_stack(event) && !has_branch_stack(event->group_leader))
> +		return -EINVAL;
> +
>  	if (branch_sample_counters(event)) {
>  		struct perf_event *leader, *sibling;
>  		int num = 0;
> @@ -4157,13 +4164,6 @@ static int intel_pmu_hw_config(struct perf_event *event)
>  			  ~(PERF_SAMPLE_BRANCH_PLM_ALL |
>  			    PERF_SAMPLE_BRANCH_COUNTERS)))
>  			event->hw.flags  &= ~PERF_X86_EVENT_NEEDS_BRANCH_STACK;
> -
> -		/*
> -		 * Force the leader to be a LBR event. So LBRs can be reset
> -		 * with the leader event. See intel_pmu_lbr_del() for details.
> -		 */
> -		if (!intel_pmu_needs_branch_stack(leader))
> -			return -EINVAL;
>  	}
>  
>  	if (intel_pmu_needs_branch_stack(event)) {


  reply	other threads:[~2025-04-14 14:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-12  9:14 [PATCH] perf/x86/intel: Fix lbr event can placed into non lbr group Luo Gengkun
2025-04-14 14:29 ` Liang, Kan [this message]
2025-04-19  2:25   ` Luo Gengkun
2025-04-19  4:50     ` Luo Gengkun
2025-04-21 14:56       ` Liang, Kan
2025-04-23 22:11         ` Liang, Kan
2025-04-25  3:44           ` Luo Gengkun

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=342ad7ad-417b-446d-8269-521a1ce9a6c6@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bp@alien8.de \
    --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=luogengkun@huaweicloud.com \
    --cc=mark.rutland@arm.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --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;
as well as URLs for NNTP newsgroup(s).