Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1438199pxp; Thu, 17 Mar 2022 09:14:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRYuwJx6jZvnM7YvZsZVVASxU49TZNjNVD3BN7LgFGvVU7kcTa66ZzGu93migLxMXJ2/Ex X-Received: by 2002:a05:6402:354a:b0:416:68b4:5f2 with SMTP id f10-20020a056402354a00b0041668b405f2mr5192693edd.85.1647533671337; Thu, 17 Mar 2022 09:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647533671; cv=none; d=google.com; s=arc-20160816; b=uHn1lECjHArD/ycojXxb4XZLVHTEJ0bH+AI+GQ/9Kk54M6z4WioR/+TS4FlseKG3on wf4iY4t7n3PAHqNhj/6AjKexvEnjUdK7ZKrfpvR8QvSr5xH2DKXC516HDbG2c4oPCpBQ PSldjCZsnTCFATamTeho8HW7+nwy5pUCaVz6+mX7seti3HtMWc9Gt8J+p0q9jAtWek5L AGhaFXaaq5BBi2JATM2nnc0+q+hLHbLWhivqn0r/CcLctuTZVl1ghX/MNrIdN164gFeQ 9Z930eCwsVYPns34wQhvZekf9n16n9Yme8zGcCIjR4k7uuM0UJwCI9tmLcSie+dH1Ho4 D70Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ey+fTvo2WaAXz/8S4ThmUaqCZBbCMIOrkL3sCa+NTTg=; b=DqIBIMKO2wLVN/cD4oyb+0VLzdkBJ6iEeCRlva0Eb6a7k92h7KD/pB0LUP/+HQAKHF d4DckBazKKCB8TD4CUlVxZGGkXndXYcocSfEX+qNi7MmQOFNbEU2fZtXGklcJMc1ch2a 7Yd+Y530WcGRARcAmBohpr7jBtGRAOv3ucmsx0cwEO4xM14oKk8FY3qjcnLW+1RM85E9 LoMdEyYu+Gk1EgDOYftNDA46t2KaPg9kYPgcHIg8ZGHy1HxnEj1Hod3zwVPrEPs8jFmy taderqCgJpdToxiDYHuRqtZ06Xi7JQQfas3a2ghYxD1l1mjLKZfkzp+MlF8jwp+Lgejd NCIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="DZZZ/qai"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w19-20020a50f113000000b00418c2b5be8csi1759673edl.366.2022.03.17.09.14.05; Thu, 17 Mar 2022 09:14:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="DZZZ/qai"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233042AbiCQLeH (ORCPT + 99 others); Thu, 17 Mar 2022 07:34:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230228AbiCQLeG (ORCPT ); Thu, 17 Mar 2022 07:34:06 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D94D81E3E23; Thu, 17 Mar 2022 04:32:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ey+fTvo2WaAXz/8S4ThmUaqCZBbCMIOrkL3sCa+NTTg=; b=DZZZ/qaiMvFxJJskTW+RRyyWsq TRlnPiyk/dtCK42Dv6mDxRNz4owhHryjydGyhYmrBORhvKeWfVLAuEzvIc1w3/zDq6KuPErCy7PhT idgCXcKlyPExYrnKXaNRGvazDEtawVsq/AAPsz7LmISSvuXHFrQ6buAEy4Ep/p7pmwrPQEbOh3aqV LDg7LD4oR8wbPWNsBLSFO7MwbQItFeMoON98KSSBiuM+TQXKmKVDkeq6HI/25kR88jrRngRc12d/g N0CnxxYjnJMkOVoF430KilTDGDRGpjpmQGzu0QqamoOi+pv/wf4E1d176253ikUAhexvyjmCDtfoa /rsijmBw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUoMv-006uxP-Kc; Thu, 17 Mar 2022 11:32:37 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 3967C3001EA; Thu, 17 Mar 2022 12:32:37 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1B7AD2B3B2762; Thu, 17 Mar 2022 12:32:37 +0100 (CET) Date: Thu, 17 Mar 2022 12:32:37 +0100 From: Peter Zijlstra To: Sandipan Das Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, x86@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, jolsa@kernel.org, tglx@linutronix.de, mingo@redhat.com, pbonzini@redhat.com, jmattson@google.com, like.xu.linux@gmail.com, eranian@google.com, ananth.narayan@amd.com, ravi.bangoria@amd.com, santosh.shukla@amd.com Subject: Re: [PATCH 4/7] perf/x86/amd/core: Detect available counters Message-ID: References: <7393a62ef0489c4b86034c68ff8e11bc97456385.1647498015.git.sandipan.das@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7393a62ef0489c4b86034c68ff8e11bc97456385.1647498015.git.sandipan.das@amd.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 17, 2022 at 11:58:33AM +0530, Sandipan Das wrote: > If AMD Performance Monitoring Version 2 (PerfMonV2) is > supported, use CPUID Fn80000022[EBX] to detect the number > of Core PMCs. This offers more flexibility if the counts > change across processor families. > > Signed-off-by: Sandipan Das > --- > arch/x86/events/amd/core.c | 5 +++++ > arch/x86/include/asm/perf_event.h | 8 ++++++++ > 2 files changed, 13 insertions(+) > > diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c > index a074af97faa9..05d79afe5173 100644 > --- a/arch/x86/events/amd/core.c > +++ b/arch/x86/events/amd/core.c > @@ -980,9 +980,14 @@ static int __init amd_core_pmu_init(void) > > /* Check for Performance Monitoring v2 support */ > if (boot_cpu_has(X86_FEATURE_PERFMON_V2)) { > + int ebx = cpuid_ebx(EXT_PERFMON_DEBUG_FEATURES); > + > /* Update PMU version for later usage */ > x86_pmu.version = 2; > > + /* Find the number of available Core PMCs */ > + x86_pmu.num_counters = EXT_PERFMON_DEBUG_NUM_CORE_PMC(ebx); > + > amd_pmu_global_cntr_mask = (1ULL << x86_pmu.num_counters) - 1; > } I prefer using unions like cpuid10_ebx. Such much easier to read than all this shouting.