Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2543889imm; Sat, 12 May 2018 14:13:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZomyjdo7AiiHO8KvNBTY+UG42CPX/vdaSoknnztvKnt+27nrbXNBRqnbM+McfuuikRXipN1 X-Received: by 2002:a63:9e01:: with SMTP id s1-v6mr3725683pgd.66.1526159580344; Sat, 12 May 2018 14:13:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526159580; cv=none; d=google.com; s=arc-20160816; b=RuxNf8b9qglMxBcRs2e8xlmvUb8N8UxWMhPpKd4t9/c2Lv4ATkyiwZ6Dx/icjPcxeI M3Cm7gph1ICvY0Wn6An/Un7Kh6cdlrM4P4xfOe7i8D5jR8WAFhN3fvCSZea7pI83+Zdx 7G+uCjFLrqLI1T1j707rvhqklseAVfwupZQ5pSPpcei2bEmKV2gweMs/9SRnl3XPz44W +5OX2Ta1E4E+WDwwq8ZI12AHj7qJKeHBX7t2G2+PwNBeI636OmE2baRx1tBbM/eFH/pq IMRK8XGaN97DJH5LdXl+pHi7tqoCezVxApGwBfovqKW4rBtub1O0vxUz7qB7SUFLRkTV zV6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=4SwMemWFwMkqlVCcDlKkd5kGNR+7Og3nj19lpPMbpeg=; b=M854h2Qv6aFmsPZ+BHKACLigeJ9huFH2slz+pKrb98Fu2U+MbmFF2qqBgENnkITPie 4566LW27YHTLlZ1LCvfy3vJtU8/POsodSxdvDNNowogZbjUCxcoKDshDRaUMAZ4WsJ3h QYdhj/GafVrJkXgUtj6CRpr6Fb6sEIh0abMl/50MF20ee4X/gjB5i59o/xzog9RZgV3q PcGhtKl7aRy82mG38hk64/6ip/wcF+acrTqNv9eaXhr+6lBjKAGZsV1XsqD4JVK1upsU dkEs7zCffHsvfZEUWojZRpue/yQbl5SZSkTb5dzVd4almcjaQBsUbZOCFDqsv/QzddMr Ahzw== ARC-Authentication-Results: i=1; mx.google.com; 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 c11-v6si5625916pls.76.2018.05.12.14.12.45; Sat, 12 May 2018 14:13:00 -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; 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 S1752030AbeELVLi (ORCPT + 99 others); Sat, 12 May 2018 17:11:38 -0400 Received: from terminus.zytor.com ([198.137.202.136]:47721 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751806AbeELVLh (ORCPT ); Sat, 12 May 2018 17:11:37 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w4CLBL5O096141 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 12 May 2018 14:11:21 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w4CLBL8W096138; Sat, 12 May 2018 14:11:21 -0700 Date: Sat, 12 May 2018 14:11:21 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Suravee Suthikulpanit Message-ID: Cc: suravee.suthikulpanit@amd.com, mingo@kernel.org, bp@suse.de, hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de Reply-To: suravee.suthikulpanit@amd.com, mingo@kernel.org, linux-kernel@vger.kernel.org, bp@suse.de, hpa@zytor.com, tglx@linutronix.de In-Reply-To: <1524864877-111962-5-git-send-email-suravee.suthikulpanit@amd.com> References: <1524864877-111962-5-git-send-email-suravee.suthikulpanit@amd.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/cpu] x86/CPU/AMD: Calculate last level cache ID from number of sharing threads Git-Commit-ID: 68091ee7ac3c1a8786fe1bebbd616b14236efb99 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 68091ee7ac3c1a8786fe1bebbd616b14236efb99 Gitweb: https://git.kernel.org/tip/68091ee7ac3c1a8786fe1bebbd616b14236efb99 Author: Suravee Suthikulpanit AuthorDate: Fri, 27 Apr 2018 16:34:37 -0500 Committer: Thomas Gleixner CommitDate: Sun, 6 May 2018 12:49:15 +0200 x86/CPU/AMD: Calculate last level cache ID from number of sharing threads Last Level Cache ID can be calculated from the number of threads sharing the cache, which is available from CPUID Fn0x8000001D (Cache Properties). This is used to left-shift the APIC ID to derive LLC ID. Therefore, default to this method unless the APIC ID enumeration does not follow the scheme. Signed-off-by: Suravee Suthikulpanit Signed-off-by: Borislav Petkov Signed-off-by: Thomas Gleixner Link: http://lkml.kernel.org/r/1524864877-111962-5-git-send-email-suravee.suthikulpanit@amd.com --- arch/x86/include/asm/cacheinfo.h | 7 +++++++ arch/x86/kernel/cpu/amd.c | 19 +++---------------- arch/x86/kernel/cpu/cacheinfo.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/arch/x86/include/asm/cacheinfo.h b/arch/x86/include/asm/cacheinfo.h new file mode 100644 index 000000000000..e958e28f7ab5 --- /dev/null +++ b/arch/x86/include/asm/cacheinfo.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_CACHEINFO_H +#define _ASM_X86_CACHEINFO_H + +void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu, u8 node_id); + +#endif /* _ASM_X86_CACHEINFO_H */ diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index a37a83809665..bf27246bb7bd 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -343,22 +344,8 @@ static void amd_get_topology(struct cpuinfo_x86 *c) c->x86_max_cores /= smp_num_siblings; } - /* - * We may have multiple LLCs if L3 caches exist, so check if we - * have an L3 cache by looking at the L3 cache CPUID leaf. - */ - if (cpuid_edx(0x80000006)) { - if (c->x86 == 0x17) { - /* - * LLC is at the core complex level. - * Core complex id is ApicId[3]. - */ - per_cpu(cpu_llc_id, cpu) = c->apicid >> 3; - } else { - /* LLC is at the node level. */ - per_cpu(cpu_llc_id, cpu) = node_id; - } - } + cacheinfo_amd_init_llc_id(c, cpu, node_id); + } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { u64 value; diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c index 54d04d574148..a2e03c9401a1 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -637,6 +637,45 @@ static int find_num_cache_leaves(struct cpuinfo_x86 *c) return i; } +void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu, u8 node_id) +{ + /* + * We may have multiple LLCs if L3 caches exist, so check if we + * have an L3 cache by looking at the L3 cache CPUID leaf. + */ + if (!cpuid_edx(0x80000006)) + return; + + if (c->x86 < 0x17) { + /* LLC is at the node level. */ + per_cpu(cpu_llc_id, cpu) = node_id; + } else if (c->x86 == 0x17 && + c->x86_model >= 0 && c->x86_model <= 0x1F) { + /* + * LLC is at the core complex level. + * Core complex ID is ApicId[3] for these processors. + */ + per_cpu(cpu_llc_id, cpu) = c->apicid >> 3; + } else { + /* + * LLC ID is calculated from the number of threads sharing the + * cache. + * */ + u32 eax, ebx, ecx, edx, num_sharing_cache = 0; + u32 llc_index = find_num_cache_leaves(c) - 1; + + cpuid_count(0x8000001d, llc_index, &eax, &ebx, &ecx, &edx); + if (eax) + num_sharing_cache = ((eax >> 14) & 0xfff) + 1; + + if (num_sharing_cache) { + int bits = get_count_order(num_sharing_cache) - 1; + + per_cpu(cpu_llc_id, cpu) = c->apicid >> bits; + } + } +} + void init_amd_cacheinfo(struct cpuinfo_x86 *c) {