Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4195224pxb; Mon, 8 Feb 2021 10:06:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcYvu+7TRN/a8q3fGlQ1CeJvIVWO+NSVvFuS7Ery8Do5q+T13JyQ9AnLkBuLUzSLgecFQS X-Received: by 2002:a17:906:3649:: with SMTP id r9mr17698002ejb.202.1612807598365; Mon, 08 Feb 2021 10:06:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612807598; cv=none; d=google.com; s=arc-20160816; b=bpV/yI28cKeOvGaCFbEwgnpIVE3aG+USqba8ROHKauDADS8phXZX7wAbtLob21dMmo 5WquCp909PCKglWJY1C6rnBj9YO3yE3ZXN5AZOE8B5EqOJcSyhaxrQNhDDZUMAqe6M23 MEddo3iJqGbYyiHrtfrC02cJS/YoqKfh67asoQY/ef/sVhiVehaiHBRKlA0ddt4gPS2X l8ZKmjcydJwhgs597J+osBxyQHYQATBy2j64uz+ihQIs7VFhXLAuORChpkRh06w2SULj GrtOS30+7cuKhF/OkUHtPHgxJpHp+/KEpZeWgyoxN4v78AfQLolJ9flXPITPRHd98wm0 Iapw== 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=+4YkrRVh0f/tBGFrmkGMxHlGOArdHzGaaUN+Hd0XH00=; b=xMVQfM+Xhbs2kYiGjUlDYJ92/iO6MwkqHerO/k3uzFGE6Fmkq8bAoZBhkLudpMLVSA zr1IlqQw0eP60wFaxM55Kyn14P8GnWPhcolCYNJFN+c+xjiey0Q+vCdfXvOm4mpKLOdK 0QwQPn12gpK4V2jDdT5rsaH8/QFErmfQllEJdkCeTxqTiovxB4BfpCW/2o066NikGRqX 3FefKTPEyT/BPStvCOzXi3lal/om12S9OoobHdB2uT5UDGrEJCaxATV59vugZvjmprjm ar8N2aDJNhQIxWIPNErUqFv/vtUhUaKZSrD2E0QqKzci/1qZ2Fmzp9iCfxa4PoW2uJnm 7Uew== 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 k4si12479440edq.62.2021.02.08.10.06.14; Mon, 08 Feb 2021 10:06:38 -0800 (PST) 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 S235211AbhBHSEj (ORCPT + 99 others); Mon, 8 Feb 2021 13:04:39 -0500 Received: from mga14.intel.com ([192.55.52.115]:62778 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234085AbhBHPiN (ORCPT ); Mon, 8 Feb 2021 10:38:13 -0500 IronPort-SDR: MNYHPsKRM9xa8DItWsXlDBzwrcvRbn3LLhzpn5vybASIuG4K4KhIm88nTgBIpacBQ/FK6eEz5Z 7b8Aei+etERw== X-IronPort-AV: E=McAfee;i="6000,8403,9889"; a="180951926" X-IronPort-AV: E=Sophos;i="5.81,162,1610438400"; d="scan'208";a="180951926" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2021 07:30:08 -0800 IronPort-SDR: l0kZcHKY3wsI6RukQtC5DpVSbvxpEfPDl6hzvordlvgYusEn7D0BmSYuUkUYg/v9EGHU+2/d4y LDxeaYxmfPIg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,162,1610438400"; d="scan'208";a="358820608" Received: from otc-lr-04.jf.intel.com ([10.54.39.41]) by orsmga003.jf.intel.com with ESMTP; 08 Feb 2021 07:30:08 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, acme@kernel.org, mingo@kernel.org, linux-kernel@vger.kernel.org Cc: 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, Kan Liang Subject: [PATCH 10/49] perf/x86/intel: Factor out intel_pmu_check_num_counters Date: Mon, 8 Feb 2021 07:25:07 -0800 Message-Id: <1612797946-18784-11-git-send-email-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612797946-18784-1-git-send-email-kan.liang@linux.intel.com> References: <1612797946-18784-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 its own number of counters and mask fixed counters before registration. The intel_pmu_check_num_counters will be reused later when registering a dedicated hybrid PMU. Reviewed-by: Andi Kleen Signed-off-by: Kan Liang --- arch/x86/events/intel/core.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 582d191..2c02e1e 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -4219,6 +4219,26 @@ static void flip_smm_bit(void *data) } } +static void intel_pmu_check_num_counters(int *num_counters, + int *num_counters_fixed, + u64 *intel_ctrl, u64 fixed_mask) +{ + if (*num_counters > INTEL_PMC_MAX_GENERIC) { + WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!", + *num_counters, INTEL_PMC_MAX_GENERIC); + *num_counters = INTEL_PMC_MAX_GENERIC; + } + *intel_ctrl = (1ULL << *num_counters) - 1; + + if (*num_counters_fixed > INTEL_PMC_MAX_FIXED) { + WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!", + *num_counters_fixed, INTEL_PMC_MAX_FIXED); + *num_counters_fixed = INTEL_PMC_MAX_FIXED; + } + + *intel_ctrl |= fixed_mask << INTEL_PMC_IDX_FIXED; +} + static void intel_pmu_cpu_starting(int cpu) { struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu); @@ -5707,20 +5727,10 @@ __init int intel_pmu_init(void) x86_pmu.attr_update = attr_update; - if (x86_pmu.num_counters > INTEL_PMC_MAX_GENERIC) { - WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!", - x86_pmu.num_counters, INTEL_PMC_MAX_GENERIC); - x86_pmu.num_counters = INTEL_PMC_MAX_GENERIC; - } - x86_pmu.intel_ctrl = (1ULL << x86_pmu.num_counters) - 1; - - if (x86_pmu.num_counters_fixed > INTEL_PMC_MAX_FIXED) { - WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!", - x86_pmu.num_counters_fixed, INTEL_PMC_MAX_FIXED); - x86_pmu.num_counters_fixed = INTEL_PMC_MAX_FIXED; - } - - x86_pmu.intel_ctrl |= (u64)fixed_mask << INTEL_PMC_IDX_FIXED; + intel_pmu_check_num_counters(&x86_pmu.num_counters, + &x86_pmu.num_counters_fixed, + &x86_pmu.intel_ctrl, + (u64)fixed_mask); /* AnyThread may be deprecated on arch perfmon v5 or later */ if (x86_pmu.intel_cap.anythread_deprecated) -- 2.7.4