Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3234487pxb; Tue, 20 Apr 2021 03:51:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJNV+X15/8OsbgkK3ShdcCaRN5n2cA8iKntrGG3782zw68RjcfGkG6uY/Q+ivoZiW4+dWu X-Received: by 2002:a05:6402:10c6:: with SMTP id p6mr31554386edu.241.1618915892755; Tue, 20 Apr 2021 03:51:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618915892; cv=none; d=google.com; s=arc-20160816; b=vWUvzxqHuu4QM7XrcHrbIFxKLlABcv/MljOSV+EdyldMORPJ/faTR19JZ3pT7Wyjuu le6FQs0SPdwAa3Zcud61c/wc8HgntJIGMpD2Muv6GOc6rM/HC0z+phBcAUuphI4vHDSP 846i9XXF331SHw0Z9BXOlmxsCJ5soqqpdQ7+4x0ojCZR48+ViNHy00AaZi26/suyz6Bz SD5Uf6dwIXM99tDWzMC3Ywc0nuS7rjawLX06fYtH0tGgDTeUFE9AJm7La+TVy7/AQWZK f6KPcrAPLUHVIefGQJ0qz1g2EslG34b4N6skTAqUikJypNj1/+mNldC7x7QfeVPCVuEd bJEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=7oCBInMN1U2Z+0UqKq+DjT86NbNKVxJz1s8+neUJqFA=; b=u/S8I6M18E6rGxC7YdFQjyvnTuk3MIOuDk9LydR0qoW/+ku/NYztzQIQjIiujFnfCn OK3SnhYe/XNLoPjEgpJ2nyqKprw7zS3fLnomYPtxdefXUvkjSVVbvY6GkJTS+KewZOUH Unwe7Zf2acWZMPSSPKI1gwg62L7Q/haB/bU4XQz5DzgMGqCO9q4Bj9fxoHKEnrISiqM7 VR1sF6wEC90VriHdsRmyiFAwGoMX2CLunfY5dwtj4GSKbkPzp0YpQRzMqIcYMTbDzI/e AabpmA+pOCOVw1pBXXykJFhoR6hmqvaBNHWEFNkDYi8qrUgyGDPtssN8jDYq7BFkQ7Uk 4e+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qqfKmzTy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=o1+Vx18d; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d9si14562244edv.176.2021.04.20.03.51.08; Tue, 20 Apr 2021 03:51:32 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qqfKmzTy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=o1+Vx18d; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231863AbhDTKsM (ORCPT + 99 others); Tue, 20 Apr 2021 06:48:12 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:51726 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231720AbhDTKrS (ORCPT ); Tue, 20 Apr 2021 06:47:18 -0400 Date: Tue, 20 Apr 2021 10:46:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1618915606; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7oCBInMN1U2Z+0UqKq+DjT86NbNKVxJz1s8+neUJqFA=; b=qqfKmzTy3n6xZW0JBpy5IEou7LcwUvzm9Jb+p1VLcU+tpdAhEb5FqEX81BCoQ7ZvRT+6AB OMBOZUstB/LYQLwGQIH4cvZWgZmRmnD+zxjvJwVL93FW4VLyjVTCoIfTNvQccdpMFzQSfs V/mpj1V7lTKXALuKdxXAjjUGucB825pF81ZvIiq+nvID0pw6ieFUjOd2qzywmZ0xWNWT1U bjkdaTy4IrZRhGzpHMqn1QRDctRkLVbN3nL0sThzKdioivKCCamBUjkfvK9BSlH3OTlO88 nhsFVDR123pW+zqWPnihnu7S6nMj3RJfUmlNVnjwHyNR5jCtw+tDvQRWgpXAdQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1618915606; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7oCBInMN1U2Z+0UqKq+DjT86NbNKVxJz1s8+neUJqFA=; b=o1+Vx18ddMBaYBy2lOlhUR/fLI3BCBO4cYK1RDLQOg7LXv271BwQz95u/dzLtARAIcmsCO we+KqAhXlAJTMGBA== From: "tip-bot2 for Kan Liang" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/x86/intel: Factor out intel_pmu_check_num_counters Cc: Kan Liang , "Peter Zijlstra (Intel)" , Andi Kleen , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <1618237865-33448-12-git-send-email-kan.liang@linux.intel.com> References: <1618237865-33448-12-git-send-email-kan.liang@linux.intel.com> MIME-Version: 1.0 Message-ID: <161891560610.29796.15047527697144952551.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/core branch of tip: Commit-ID: b8c4d1a87610ba20da1abddb7aacbde0b2817c1a Gitweb: https://git.kernel.org/tip/b8c4d1a87610ba20da1abddb7aacbde0b2817c1a Author: Kan Liang AuthorDate: Mon, 12 Apr 2021 07:30:51 -07:00 Committer: Peter Zijlstra CommitterDate: Mon, 19 Apr 2021 20:03:26 +02:00 perf/x86/intel: Factor out intel_pmu_check_num_counters 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 to check the number of the counters for each hybrid PMU. Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Andi Kleen Link: https://lkml.kernel.org/r/1618237865-33448-12-git-send-email-kan.liang@linux.intel.com --- 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 f727aa5..d7e2021 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -5064,6 +5064,26 @@ static const struct attribute_group *attr_update[] = { static struct attribute *empty_attrs; +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; +} + __init int intel_pmu_init(void) { struct attribute **extra_skl_attr = &empty_attrs; @@ -5703,20 +5723,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)