Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2434770pxy; Tue, 3 Aug 2021 06:30:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfzoCIvFOntqBi2V/k0Mk1Hss0DiXh1uM/MOLYtU4aDKrKL8AYiqHf6davFGXKm9Zxy7tU X-Received: by 2002:a17:907:2bd0:: with SMTP id gv16mr21463188ejc.49.1627997404297; Tue, 03 Aug 2021 06:30:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627997404; cv=none; d=google.com; s=arc-20160816; b=qqr1ulxpGVkgngNqZApif+xNO8WTVKjRdSGpDo96xKkgwsdaZdz047v6E8SHy7LRqj 6S/R9LKoXIUK2saBQQhUHXoeJit1Lauxo7qPlpZlZutXzMNARbte9di8LSM9RgIow7X6 yaKs6KS7l0l0uZn++HASVu94gejxRlfkc4to/TwDMQQocOageM6pAkh5YQQIoJ5OmFhj r0hXnxTj9ALO6J2wgWS05/BHqRB6yJArLT3RU4/2+3UDl32ZHUk4LHFPDIVuI8d9Mc25 dhIzjHGBV8kXJ/0en996tuyfDnQAgwmOOIx7rQzdeFjmYhw5XHK8B4oIlsEZXZRABfHD oe5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=whbTJIh/MshxfoaxRO3ykA2n0bFg3NhjJAGb3rWaS6Y=; b=xpgTL7HPyuSJZ5pjDKnt9ra6UERLS4wICWRvNpDeP1jGKc3ikU+B6NFLWyI39PM5Rk qILVppwnlVGofR850t+B2I1wnNGKQElvRYARu71kiSaP3PYOhz8aChbT0lASt9B/cYgN DoF1q+xvh0Kcrz2FMy/+nrF+Ewi95ygJqcc7oS2wNsdBcnBT2mfeNe5vXzATENsRfT4R me31Q6lk/9ZLdpoGc+xrqFeTcafNzGr4mhd5U0i1iFuZRbyXW9ZCb9xyIxUaXyJ0gSFu X9dRwJa9y+SeSnB7/cfZ3254rg2ahx+UbBMPKi6f0xLymZ7IXVhFIgpBuupl9J7BMOI2 eBvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cb18si12851457ejb.171.2021.08.03.06.29.40; Tue, 03 Aug 2021 06:30:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236372AbhHCN2D (ORCPT + 99 others); Tue, 3 Aug 2021 09:28:03 -0400 Received: from mga12.intel.com ([192.55.52.136]:37709 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236245AbhHCN2C (ORCPT ); Tue, 3 Aug 2021 09:28:02 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10064"; a="193280914" X-IronPort-AV: E=Sophos;i="5.84,291,1620716400"; d="scan'208";a="193280914" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2021 06:27:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,291,1620716400"; d="scan'208";a="502394202" Received: from otc-lr-04.jf.intel.com ([10.54.39.41]) by fmsmga004.fm.intel.com with ESMTP; 03 Aug 2021 06:27:50 -0700 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: ak@linux.intel.com, Kan Liang , stable@vger.kernel.org Subject: [PATCH V2] perf/x86/intel: Apply mid ACK for small core Date: Tue, 3 Aug 2021 06:25:28 -0700 Message-Id: <1627997128-57891-1-git-send-email-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang A warning as below may be occasionally triggered in an ADL machine when these conditions occur, - Two perf record commands run one by one. Both record a PEBS event. - Both runs on small cores. - They have different adaptive PEBS configuration (PEBS_DATA_CFG). [ 673.663291] WARNING: CPU: 4 PID: 9874 at arch/x86/events/intel/ds.c:1743 setup_pebs_adaptive_sample_data+0x55e/0x5b0 [ 673.663348] RIP: 0010:setup_pebs_adaptive_sample_data+0x55e/0x5b0 [ 673.663357] Call Trace: [ 673.663357] [ 673.663357] intel_pmu_drain_pebs_icl+0x48b/0x810 [ 673.663360] perf_event_nmi_handler+0x41/0x80 [ 673.663368] [ 673.663370] __perf_event_task_sched_in+0x2c2/0x3a0 Different from the big core, the small core requires the ACK right before re-enabling counters in the NMI handler, otherwise a stale PEBS record may be dumped into the later NMI handler, which trigger the warning. Add a new mid_ack flag to track the case. Add all PMI handler bits in the struct x86_hybrid_pmu to track the bits for different types of PMUs. Apply mid ACK for the small cores on an Alder Lake machine. The existing hybrid() macro has a compile error when taking address of a bit-field variable. Add a new macro hybrid_bit() to get the bit-field value of a given PMU. Fixes: f83d2f91d259 ("perf/x86/intel: Add Alder Lake Hybrid support") Reported-by: Ammy Yi Tested-by: Ammy Yi Reviewed-by: Andi Kleen Signed-off-by: Kan Liang Cc: stable@vger.kernel.org --- The V1 patch set can be found at https://lore.kernel.org/lkml/1625774073-153697-1-git-send-email-kan.liang@linux.intel.com/ Changes since v1: - Introduce mid ACK. The early ACK in V1 may trigger other issue based on the latest test result. - Add comments regarding early, mid and late ACK. arch/x86/events/intel/core.c | 23 +++++++++++++++-------- arch/x86/events/perf_event.h | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index d76be3b..511d1f9 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -2904,24 +2904,28 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status) */ static int intel_pmu_handle_irq(struct pt_regs *regs) { - struct cpu_hw_events *cpuc; + struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); + bool late_ack = hybrid_bit(cpuc->pmu, late_ack); + bool mid_ack = hybrid_bit(cpuc->pmu, mid_ack); int loops; u64 status; int handled; int pmu_enabled; - cpuc = this_cpu_ptr(&cpu_hw_events); - /* * Save the PMU state. * It needs to be restored when leaving the handler. */ pmu_enabled = cpuc->enabled; /* - * No known reason to not always do late ACK, - * but just in case do it opt-in. + * In general, the early ACK is only applied for old platforms. + * For the big core starts from Haswell, the late ACK should be + * applied. + * For the small core after Tremont, we have to do the ACK right + * before re-enabling counters, which is in the middle of the + * NMI handler. */ - if (!x86_pmu.late_ack) + if (!late_ack && !mid_ack) apic_write(APIC_LVTPC, APIC_DM_NMI); intel_bts_disable_local(); cpuc->enabled = 0; @@ -2958,6 +2962,8 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) goto again; done: + if (mid_ack) + apic_write(APIC_LVTPC, APIC_DM_NMI); /* Only restore PMU state when it's active. See x86_pmu_disable(). */ cpuc->enabled = pmu_enabled; if (pmu_enabled) @@ -2969,7 +2975,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) * have been reset. This avoids spurious NMIs on * Haswell CPUs. */ - if (x86_pmu.late_ack) + if (late_ack) apic_write(APIC_LVTPC, APIC_DM_NMI); return handled; } @@ -6123,7 +6129,6 @@ __init int intel_pmu_init(void) static_branch_enable(&perf_is_hybrid); x86_pmu.num_hybrid_pmus = X86_HYBRID_NUM_PMUS; - x86_pmu.late_ack = true; x86_pmu.pebs_aliases = NULL; x86_pmu.pebs_prec_dist = true; x86_pmu.pebs_block = true; @@ -6161,6 +6166,7 @@ __init int intel_pmu_init(void) pmu = &x86_pmu.hybrid_pmu[X86_HYBRID_PMU_CORE_IDX]; pmu->name = "cpu_core"; pmu->cpu_type = hybrid_big; + pmu->late_ack = true; if (cpu_feature_enabled(X86_FEATURE_HYBRID_CPU)) { pmu->num_counters = x86_pmu.num_counters + 2; pmu->num_counters_fixed = x86_pmu.num_counters_fixed + 1; @@ -6186,6 +6192,7 @@ __init int intel_pmu_init(void) pmu = &x86_pmu.hybrid_pmu[X86_HYBRID_PMU_ATOM_IDX]; pmu->name = "cpu_atom"; pmu->cpu_type = hybrid_small; + pmu->mid_ack = true; pmu->num_counters = x86_pmu.num_counters; pmu->num_counters_fixed = x86_pmu.num_counters_fixed; pmu->max_pebs_events = x86_pmu.max_pebs_events; diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index ad87cb3..eec7ce8 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -655,6 +655,10 @@ struct x86_hybrid_pmu { struct event_constraint *event_constraints; struct event_constraint *pebs_constraints; struct extra_reg *extra_regs; + + unsigned int late_ack :1, + mid_ack :1, + enabled_ack :1; }; static __always_inline struct x86_hybrid_pmu *hybrid_pmu(struct pmu *pmu) @@ -685,6 +689,16 @@ extern struct static_key_false perf_is_hybrid; __Fp; \ })) +#define hybrid_bit(_pmu, _field) \ +({ \ + bool __Fp = x86_pmu._field; \ + \ + if (is_hybrid() && (_pmu)) \ + __Fp = hybrid_pmu(_pmu)->_field; \ + \ + __Fp; \ +}) + enum hybrid_pmu_type { hybrid_big = 0x40, hybrid_small = 0x20, @@ -754,6 +768,7 @@ struct x86_pmu { /* PMI handler bits */ unsigned int late_ack :1, + mid_ack :1, enabled_ack :1; /* * sysfs attrs -- 2.7.4