Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1829263pxb; Mon, 12 Apr 2021 07:40:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNj7PrV/0+rJzoWi/OEgOIEpmIWzFIduoPgjdDmgnbsy1ngis+mWvSH0CAeqW68vX5LFTV X-Received: by 2002:a17:906:3915:: with SMTP id f21mr6294928eje.256.1618238422957; Mon, 12 Apr 2021 07:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618238422; cv=none; d=google.com; s=arc-20160816; b=ZF7YowRZH9ERJmVNjV6y049d1WHuu2RJciiWRbzkfKQvowwluyhPQRXbf/uvHc/pxr pkqI1nVLNqQ5go+4Gb0IUK+UbO39ccRY3qoGwlp9Pzqr6wqUBEOb4lHiC6mObOjjIWT1 obj1bb/64qhqEhy1WJOkY9F5WTFeK+hpHipk1uwzTdmUNOtHSVCFK9ZgfYIzZKsPCKUj 4nvlIJ34Uwxv2qERFSzjZ26avGojSBj75sOqVJcc4i4sDSxqSfqN6LrG183dfIS3mv6o Fxus3al2YJ/C4UV2SuCYidw8Qskriez1+4VJbIE9oyf2GnOYOXhOAM+rJ1HWLD1px1G3 pn8Q== 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=/vBVYN15sZmA2Lp62soehx4LiJlFlqQlgJnrn5nxYh4=; b=DFKUzRgyP5eIhCg85UxlUnZczdAZX/qU+8e8xFzdqIZT+sK/+eiaLstx2lz7KTFfj1 Nv+cMBXPnLcla/Q6eThXfPqmZuzR2LaxO9ATv1XdZd3PlUOFZaYFf71YpthxNJEgKId9 LqEtIWP1Wza7IUauSQB+9BzDsYbcXTVK/87YJz2Xdbm6H4adutEE5krsmpmkd6G4AcAB siwPEYvKhYRGRkziPL2Cuam54dMdL+eP5U86fSyuHbQMpVF1BtpMozwoB+IpEiX8mJSz VdqRIKvyAz9p+ookSIulXKPzqyhLkPbNSVnz8VFEO93iQusm8K++u7ZRAcrnkzOOE+O2 FACw== 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 u13si3995417ejt.333.2021.04.12.07.39.58; Mon, 12 Apr 2021 07:40:22 -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 S242523AbhDLOjJ (ORCPT + 99 others); Mon, 12 Apr 2021 10:39:09 -0400 Received: from mga09.intel.com ([134.134.136.24]:29207 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242400AbhDLOir (ORCPT ); Mon, 12 Apr 2021 10:38:47 -0400 IronPort-SDR: zvXR1qxJ9vkJux0L5iCtFeMIsIVuEzBhxXRFNyvPQslGP+sw7D5bSpPjFDbOEAYb6aia7OKVNn nImtwgF5wHvw== X-IronPort-AV: E=McAfee;i="6200,9189,9952"; a="194317978" X-IronPort-AV: E=Sophos;i="5.82,216,1613462400"; d="scan'208";a="194317978" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2021 07:38:26 -0700 IronPort-SDR: c9HEU/UB3+aaS54n8nGHt1T7ntH7rRcNoGmA2pOHGFnwPxMyunXHeMfjGSRmzBpphxYeT4Xzh0 8q8+RdXqDKNQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,216,1613462400"; d="scan'208";a="398392806" Received: from otc-lr-04.jf.intel.com ([10.54.39.41]) by orsmga002.jf.intel.com with ESMTP; 12 Apr 2021 07:38:26 -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 V6 12/25] perf/x86/intel: Factor out intel_pmu_check_event_constraints Date: Mon, 12 Apr 2021 07:30:52 -0700 Message-Id: <1618237865-33448-13-git-send-email-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1618237865-33448-1-git-send-email-kan.liang@linux.intel.com> References: <1618237865-33448-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 d7e2021..5c5f330 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -5084,6 +5084,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; @@ -5094,7 +5137,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; @@ -5732,40 +5774,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