Re: [PATCH V6 11/14] perf/x86/intel: Disable sample-read the slots and metrics events

From: Peter Zijlstra
Date: Tue Jul 21 2020 - 09:10:20 EST


On Fri, Jul 17, 2020 at 07:05:51AM -0700, kan.liang@xxxxxxxxxxxxxxx wrote:
> From: Kan Liang <kan.liang@xxxxxxxxxxxxxxx>
>
> Users fail to sample-read the slots and metrics events, e.g.,
> perf record -e '{slots, topdown-retiring}:S'.
>
> When reading the metrics event, the fixed counter 3 (slots) has to be
> reset, which impacts the sampling of the slots event.
>
> Add a specific validate_group() support to reject the case and error out
> for Ice Lake.
>
> An alternative fix may unconditionally disable slots sampling, but it's
> not a decent fix. Users may want to only sample the slot events
> without the topdown metrics events.
>
> Signed-off-by: Kan Liang <kan.liang@xxxxxxxxxxxxxxx>

I'm confused by this; it doesn't make sense.

Should not patch 7 have something like the below instead?

Also, I think there is a bug when we create a group like this and then
kill the leader, in that case the core code will 'promote' the sibling
metric events to their own individual events, see perf_group_detach().

We need additional code to move those events into unrecoverable ERROR
state. A new group_caps flag could indicate this promotion isn't
allowed.

--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3441,8 +3441,22 @@ static int intel_pmu_hw_config(struct pe
* A flag PERF_X86_EVENT_TOPDOWN is applied for the case.
*/
if (x86_pmu.intel_cap.perf_metrics && is_topdown_event(event)) {
- if (is_metric_event(event) && is_sampling_event(event))
- return -EINVAL;
+
+ if (is_metric_event(event)) {
+ struct perf_event *leader = event->group_leader;
+
+ if (is_sampling_event(event))
+ return -EINVAL;
+
+ if (leader == event)
+ return -EINVAL;
+
+ if (!is_slots_event(leader))
+ return -EINVAL;
+
+ if (is_sampling_event(leader))
+ return -EINVAL;
+ }

if (!is_sampling_event(event)) {
if (event->attr.config1 != 0)