Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1179234ybi; Fri, 2 Aug 2019 10:37:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqylX7KgdL/imO/ey05wP6jheAvkdvhowQnNacuNRyyRWiR+1YbggxERsZvqm/j+54/U2PjM X-Received: by 2002:a17:90a:fa18:: with SMTP id cm24mr5271512pjb.120.1564767431860; Fri, 02 Aug 2019 10:37:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564767431; cv=none; d=google.com; s=arc-20160816; b=tp7SQyDMT33GyrkgtZCyUFZzC4+rjYEOQQas8IB6tsYZDvysG6s+LOTKqwDczJk08y VuSPDTvzOLW+0VuwvW7RCkZC6WqQA49rfmJvh7VAvGIVAWby9i/tq6bv+jvVF5c+DuRN /Z8YdyTh6FcfNtJ/aRvze3uxit36v5QxvUaNEoQxw30x8mRnVH0Al2gT61p1FHORIIJ4 5fuWxgDDSWyzbuqz1cebZgAoBe2WcY61DTkiVDJ8/L8vjVjIMi/GqjHAWHS8V1vvEZj1 xeU5egvxnDfLRvdLuLK8EJNZwKWmnSYznV20TdPcsDn7lD8KJyF2NlFgWRFt9koKVwp3 DY3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=W3Va3Zb+9rOvd4j2zCM+wTSgsw7qemklTQZamCFIEsM=; b=0q1Oh7EAwqtePJEYh+R9r+XHDri/8pjtHQ5qkJFCDmFBmy8u5CSQz5ty6FljqXCJsI xwM4TK7tkiW1v0VZyOTtwR0KFTUrI12KaYAweBme4qpT2Yy1UULLHeVnoeszU3grlmAA RslOYUJNu7/T8r3JeMnQZHp9RcabobydxDlBpvMJ/IZtY2H+WEuxqmFkFxQSfL7vLQR+ NvJUZtpVkZkCxjC7xaDMngLAzxkud4/HOpu8A0Shtd3v2WJAYbdg0KVa2M6lSG61Eywq Vl7ruuQBgCgeC4N6Nhqp+Zfaz+QEgKy5l5wTv+LCZPbeGpw4PTQ1DCD03zVvpYInhxgu CGHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T8ga7047; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v1si33518002plb.381.2019.08.02.10.36.56; Fri, 02 Aug 2019 10:37:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T8ga7047; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405723AbfHBJrq (ORCPT + 99 others); Fri, 2 Aug 2019 05:47:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:52678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405716AbfHBJro (ORCPT ); Fri, 2 Aug 2019 05:47:44 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B618820880; Fri, 2 Aug 2019 09:47:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564739264; bh=+WUMdsBTBGurwTRfQbddsebWWDW3fHpFQ8g9jEtC8wY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T8ga7047pUwMMcWgVaSsqZayHAhlbqkijzFw0gdU+lkOT5izywcpch4hCWBrRafmJ /vG/RemtVhapwHt95KOyRHskEJx1x9tcN/eSCEp97IkjIh70ZlKg1gYqLE43MtpJe9 fRJQMMF4ZChcoAB0SxWzr+/y7VmvU12Kt+7eIhgM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Janakarajan Natarajan , "Peter Zijlstra (Intel)" , Borislav Petkov , Alexander Shishkin , Arnaldo Carvalho de Melo , Linus Torvalds , Suravee Suthikulpanit , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.9 152/223] perf/x86/amd/uncore: Get correct number of cores sharing last level cache Date: Fri, 2 Aug 2019 11:36:17 +0200 Message-Id: <20190802092248.283719085@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802092238.692035242@linuxfoundation.org> References: <20190802092238.692035242@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In Family 17h, the number of cores sharing a cache level is obtained from the Cache Properties CPUID leaf (0x8000001d) by passing in the cache level in ECX. In prior families, a cache level of 2 was used to determine this information. To get the right information, irrespective of Family, iterate over the cache levels using CPUID 0x8000001d. The last level cache is the last value to return a non-zero value in EAX. Signed-off-by: Janakarajan Natarajan Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Borislav Petkov Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Suravee Suthikulpanit Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/5ab569025b39cdfaeca55b571d78c0fc800bdb69.1497452002.git.Janakarajan.Natarajan@amd.com Signed-off-by: Ingo Molnar --- arch/x86/events/amd/uncore.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index 094973313037..10f023799f11 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -378,11 +378,24 @@ static int amd_uncore_cpu_starting(unsigned int cpu) if (amd_uncore_llc) { unsigned int apicid = cpu_data(cpu).apicid; - unsigned int nshared; + unsigned int nshared, subleaf, prev_eax = 0; uncore = *per_cpu_ptr(amd_uncore_llc, cpu); - cpuid_count(0x8000001d, 2, &eax, &ebx, &ecx, &edx); - nshared = ((eax >> 14) & 0xfff) + 1; + /* + * Iterate over Cache Topology Definition leaves until no + * more cache descriptions are available. + */ + for (subleaf = 0; subleaf < 5; subleaf++) { + cpuid_count(0x8000001d, subleaf, &eax, &ebx, &ecx, &edx); + + /* EAX[0:4] gives type of cache */ + if (!(eax & 0x1f)) + break; + + prev_eax = eax; + } + nshared = ((prev_eax >> 14) & 0xfff) + 1; + uncore->id = apicid - (apicid % nshared); uncore = amd_uncore_find_online_sibling(uncore, amd_uncore_llc); -- 2.20.1