From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: mingo@redhat.com, acme@kernel.org, linux-kernel@vger.kernel.org,
mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
jolsa@kernel.org, namhyung@kernel.org, irogers@google.com,
adrian.hunter@intel.com, ak@linux.intel.com, eranian@google.com,
alexey.v.bayduraev@linux.intel.com, tinghao.zhang@intel.com
Subject: Re: [PATCH V4 4/7] perf/x86/intel: Support LBR event logging
Date: Thu, 19 Oct 2023 09:56:02 -0400 [thread overview]
Message-ID: <86df1293-c20b-4292-abde-852861dcedf1@linux.intel.com> (raw)
In-Reply-To: <20231019092341.GE36211@noisy.programming.kicks-ass.net>
On 2023-10-19 5:23 a.m., Peter Zijlstra wrote:
> On Wed, Oct 04, 2023 at 11:40:41AM -0700, kan.liang@linux.intel.com wrote:
>
>> diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c
>> index c3b0d15a9841..1e80a551a4c2 100644
>> --- a/arch/x86/events/intel/lbr.c
>> +++ b/arch/x86/events/intel/lbr.c
>> @@ -676,6 +676,21 @@ void intel_pmu_lbr_del(struct perf_event *event)
>> WARN_ON_ONCE(cpuc->lbr_users < 0);
>> WARN_ON_ONCE(cpuc->lbr_pebs_users < 0);
>> perf_sched_cb_dec(event->pmu);
>> +
>> + /*
>> + * The logged occurrences information is only valid for the
>> + * current LBR group. If another LBR group is scheduled in
>> + * later, the information from the stale LBRs will be wrongly
>> + * interpreted. Reset the LBRs here.
>> + * For the context switch, the LBR will be unconditionally
>> + * flushed when a new task is scheduled in. If both the new task
>> + * and the old task are monitored by a LBR event group. The
>> + * reset here is redundant. But the extra reset doesn't impact
>> + * the functionality. It's hard to distinguish the above case.
>> + * Keep the unconditionally reset for a LBR event group for now.
>> + */
>
> I found this really hard to read, also should this not rely on
> !cpuc->lbr_users ?
>
It's possible that the last LBR user is not in the branch_counters
group, e.g., a branch_counters group + several normal LBR events.
For this case, the is_branch_counters_group(event) return false for the
last LBR user. The LBR will not be reset.
> As is, you'll reset the lbr for every event in the group.
>
>> + if (is_branch_counters_group(event))
>> + intel_pmu_lbr_reset();
>> }
Right, I forgot to change it after I modified flag. :(
Here I think we should only clear the LBRs once for a branch_counters
group, e.g., in the leader event.
+ if (is_branch_counters_group(event) && event == event->group_leader)+
intel_pmu_lbr_reset();
The only problem is that the leader event may not be an LBR event. But I
guess it should be OK to limit that the leader event of a
branch_counters group must be an LBR event in hw_config().
Thanks,
Kan
next prev parent reply other threads:[~2023-10-19 13:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-04 18:40 [PATCH V4 1/7] perf: Add branch stack counters kan.liang
2023-10-04 18:40 ` [PATCH V4 2/7] perf/x86: Add PERF_X86_EVENT_NEEDS_BRANCH_STACK flag kan.liang
2023-10-04 18:40 ` [PATCH V4 3/7] perf: Add branch_sample_call_stack kan.liang
2023-10-04 18:40 ` [PATCH V4 4/7] perf/x86/intel: Support LBR event logging kan.liang
2023-10-19 9:23 ` Peter Zijlstra
2023-10-19 13:56 ` Liang, Kan [this message]
2023-10-19 9:26 ` Peter Zijlstra
2023-10-19 13:58 ` Liang, Kan
2023-10-19 10:52 ` Peter Zijlstra
2023-10-19 14:26 ` Liang, Kan
2023-10-19 18:18 ` Peter Zijlstra
2023-10-19 11:00 ` Peter Zijlstra
2023-10-19 14:28 ` Liang, Kan
2023-10-19 11:09 ` Peter Zijlstra
2023-10-19 14:31 ` Liang, Kan
2023-10-19 11:12 ` Peter Zijlstra
2023-10-20 12:45 ` Liang, Kan
2023-10-04 18:40 ` [PATCH V4 5/7] tools headers UAPI: Sync include/uapi/linux/perf_event.h header with the kernel kan.liang
2023-10-04 18:40 ` [PATCH V4 6/7] perf header: Support num and width of branch counters kan.liang
2023-10-04 18:40 ` [PATCH V4 7/7] perf tools: Add branch counter knob kan.liang
2023-10-16 17:48 ` [PATCH V4 1/7] perf: Add branch stack counters 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=86df1293-c20b-4292-abde-852861dcedf1@linux.intel.com \
--to=kan.liang@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=alexey.v.bayduraev@linux.intel.com \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=tinghao.zhang@intel.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 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.