Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3589120pxf; Mon, 5 Apr 2021 16:44:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtRQM4GeRggjK73MPCYn7z2KmabR1c8FIVhIOVU1RUbjZYONAouzbaOhlXIDZr+PD/gO1+ X-Received: by 2002:a05:6e02:485:: with SMTP id b5mr12059489ils.266.1617666243211; Mon, 05 Apr 2021 16:44:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617666243; cv=none; d=google.com; s=arc-20160816; b=njzbbFR9cfcIgx8CSee+zc3TrC4jjsqReL8/LR56dUi1tB9KZWVWJ3edfQ6igTRiqQ R1izJu5m/iluH7OmAcbvdTj0wu5dZ1359X470FV4Rq4zPcTV3BCZh9CVKMknjZV4hKUI ZupUTpJUllwsl8c2VGAwlHurOBMVB+Nh470ETiWC5syt5rf+7A3Y7P/EbztRmUV86BEH GeNOmuTH6tFQm4N12zSXXmw1QMHueThM+9FXpMhVCnQMa3wjGygDDIN2qSMVqq7O9M6h d5WvHRgzkiYIWLqXS2kDSam0wE7XR0/33Jd6ixtGPVjKazvuMaiQwgNLzPvdXJUw6MQi ETKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=nCUFHgYRHznI23MOmX+7CYNargHqGqDM8VWOLC+On9I=; b=eMCXV+E0xjemq/Z2f8KGxpx82ruhUgBbpJ6G4tsscKw8rR7ZXaEESUWWZ/gPC8sVsC c2Sz0T2USJtNzkvtIeq9DDLrR3crx6AXGoHScCHzK0PBujw3qBUm9dMQAA1lmEppIPG8 gkce+lt/oMwmFzt2MZRnD6yknnu3oFlyqG4k3FKZF3RDX6wJHWuzv33OV1pMT3Vl7ekr BJQC+oVDaoOEgUkHSE4JVEXYYXMaYr8Srg5FFq3MSW5G99oGbzTPG4IDEK/K61XsGtQN /TrEZcOhgDdkGjEFQI/NpY1YXWN3fcM7PJri6NIX7oHC//TJmT3VibVBKLTgmQlvkxQl dWXQ== 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 p9si17541828jan.5.2021.04.05.16.43.50; Mon, 05 Apr 2021 16:44:03 -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 S241573AbhDEPSj (ORCPT + 99 others); Mon, 5 Apr 2021 11:18:39 -0400 Received: from mga18.intel.com ([134.134.136.126]:43429 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241493AbhDEPSX (ORCPT ); Mon, 5 Apr 2021 11:18:23 -0400 IronPort-SDR: ZWw/wjEchurj4NPyPehVD8sVOQL3vOW7kNY2+H2Fkklg1daXTrlJRwmcZbEAdbQ+lzxRHheyru CVwG1Wxh3gdA== X-IronPort-AV: E=McAfee;i="6000,8403,9945"; a="180402957" X-IronPort-AV: E=Sophos;i="5.81,306,1610438400"; d="scan'208";a="180402957" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2021 08:18:16 -0700 IronPort-SDR: FmIi3BADeng2JduYWSMZ0cKHt2IxtYmLyVzaTJXnjx52fhf6S2WJ6z+PRssKj6DK2q4+pbxR0J cyAEPQ8dMTxQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,306,1610438400"; d="scan'208";a="379006311" Received: from otc-lr-04.jf.intel.com ([10.54.39.41]) by orsmga003.jf.intel.com with ESMTP; 05 Apr 2021 08:18:16 -0700 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@kernel.org, linux-kernel@vger.kernel.org Cc: acme@kernel.org, tglx@linutronix.de, bp@alien8.de, namhyung@kernel.org, jolsa@redhat.com, ak@linux.intel.com, yao.jin@linux.intel.com, alexander.shishkin@linux.intel.com, adrian.hunter@intel.com, ricardo.neri-calderon@linux.intel.com, Kan Liang Subject: [PATCH V5 12/25] perf/x86/intel: Factor out intel_pmu_check_event_constraints Date: Mon, 5 Apr 2021 08:10:54 -0700 Message-Id: <1617635467-181510-13-git-send-email-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1617635467-181510-1-git-send-email-kan.liang@linux.intel.com> References: <1617635467-181510-1-git-send-email-kan.liang@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang Each Hybrid PMU has to check and update its own event constraints before registration. The intel_pmu_check_event_constraints will be reused later to check the event constraints of each hybrid PMU. Reviewed-by: Andi Kleen Signed-off-by: Kan Liang --- arch/x86/events/intel/core.c | 82 +++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 9394646..53a2e2e 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -5090,6 +5090,49 @@ static void intel_pmu_check_num_counters(int *num_counters, *intel_ctrl |= fixed_mask << INTEL_PMC_IDX_FIXED; } +static void intel_pmu_check_event_constraints(struct event_constraint *event_constraints, + int num_counters, + int num_counters_fixed, + u64 intel_ctrl) +{ + struct event_constraint *c; + + if (!event_constraints) + return; + + /* + * event on fixed counter2 (REF_CYCLES) only works on this + * counter, so do not extend mask to generic counters + */ + for_each_event_constraint(c, event_constraints) { + /* + * Don't extend the topdown slots and metrics + * events to the generic counters. + */ + if (c->idxmsk64 & INTEL_PMC_MSK_TOPDOWN) { + /* + * Disable topdown slots and metrics events, + * if slots event is not in CPUID. + */ + if (!(INTEL_PMC_MSK_FIXED_SLOTS & intel_ctrl)) + c->idxmsk64 = 0; + c->weight = hweight64(c->idxmsk64); + continue; + } + + if (c->cmask == FIXED_EVENT_FLAGS) { + /* Disabled fixed counters which are not in CPUID */ + c->idxmsk64 &= intel_ctrl; + + if (c->idxmsk64 != INTEL_PMC_MSK_FIXED_REF_CYCLES) + c->idxmsk64 |= (1ULL << num_counters) - 1; + } + c->idxmsk64 &= + ~(~0ULL << (INTEL_PMC_IDX_FIXED + num_counters_fixed)); + c->weight = hweight64(c->idxmsk64); + } +} + __init int intel_pmu_init(void) { struct attribute **extra_skl_attr = &empty_attrs; @@ -5100,7 +5143,6 @@ __init int intel_pmu_init(void) union cpuid10_edx edx; union cpuid10_eax eax; union cpuid10_ebx ebx; - struct event_constraint *c; unsigned int fixed_mask; struct extra_reg *er; bool pmem = false; @@ -5738,40 +5780,10 @@ __init int intel_pmu_init(void) if (x86_pmu.intel_cap.anythread_deprecated) x86_pmu.format_attrs = intel_arch_formats_attr; - if (x86_pmu.event_constraints) { - /* - * event on fixed counter2 (REF_CYCLES) only works on this - * counter, so do not extend mask to generic counters - */ - for_each_event_constraint(c, x86_pmu.event_constraints) { - /* - * Don't extend the topdown slots and metrics - * events to the generic counters. - */ - if (c->idxmsk64 & INTEL_PMC_MSK_TOPDOWN) { - /* - * Disable topdown slots and metrics events, - * if slots event is not in CPUID. - */ - if (!(INTEL_PMC_MSK_FIXED_SLOTS & x86_pmu.intel_ctrl)) - c->idxmsk64 = 0; - c->weight = hweight64(c->idxmsk64); - continue; - } - - if (c->cmask == FIXED_EVENT_FLAGS) { - /* Disabled fixed counters which are not in CPUID */ - c->idxmsk64 &= x86_pmu.intel_ctrl; - - if (c->idxmsk64 != INTEL_PMC_MSK_FIXED_REF_CYCLES) - c->idxmsk64 |= (1ULL << x86_pmu.num_counters) - 1; - } - c->idxmsk64 &= - ~(~0ULL << (INTEL_PMC_IDX_FIXED + x86_pmu.num_counters_fixed)); - c->weight = hweight64(c->idxmsk64); - } - } - + intel_pmu_check_event_constraints(x86_pmu.event_constraints, + x86_pmu.num_counters, + x86_pmu.num_counters_fixed, + x86_pmu.intel_ctrl); /* * Access LBR MSR may cause #GP under certain circumstances. * E.g. KVM doesn't support LBR MSR -- 2.7.4