Received: by 10.192.165.148 with SMTP id m20csp1888448imm; Thu, 26 Apr 2018 03:49:24 -0700 (PDT) X-Google-Smtp-Source: AIpwx48xVG5BnLKExgKsu8h+MnGC4+TyRA1N1yll7GAz6J33CKFvkU0615UYjFe/7W22AJhSWfpZ X-Received: by 10.98.118.130 with SMTP id r124mr31689413pfc.80.1524739764288; Thu, 26 Apr 2018 03:49:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524739764; cv=none; d=google.com; s=arc-20160816; b=CfQkeieY7aQdftexn+MOxmcNZZxs39DrwEc6XqG8mO6YXMJmHpSQBNHB72Qc4BRdIn yYXDlzd5/ll6Jgs/P/tQQCoHGRyVcWk6h6/TkMoALrUXPf8rPdud/tdrRSEIYAvOnzHN mm+1dPmzkQYZtb7GTPbjVPDHPecg6xMaBDKR3m1sPzBXwEca1TZMQu+adETU3J9GUT9j pUCmBuqLDhXEcCxXUIr34YbXEeFx5evjWr89MZK/SjscJBFLcfg90BcmouG07BFcKlF7 TecW6UJZ1L/uDGPMY3/4/aP9JpvgXisQ1ATT1rVtcYl+FcPqfp75mYxV2i1UKSGpaRTC +ziA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=3wA/lSlupvgTpYom109prSUkanAkjG9YdBpCfj1gGyQ=; b=BTTFzDNhnByL17wGvI/la+aO5wXACkj4EF+rbZCuUg+KV1Cz4l/ZNwbYTlX/0dO0BI 9C2AOFn/ZM3O4JmcXZtlgGNblyclMr2f6puOBo/0kTo2DredVmz4+PdwoeI77jq/e4K3 Le7rI/fIVFt7fZ7C5uDyjH1iWqTIx3t/tOexbXurXSiAstyanZvSDTe3oKeBLppC3AaQ MYQDPONswvzafZmgNgAg334ID8MIVdgPE66M+nMocUzU/71W+q7mXiTqahXEdmenF28L U0W9tzCw8b5bZMcRRHGUJMUu+H++udcfqsRF9na3/h9VtvjxVPxoSLT+hnPetmGGBV9H u4qw== 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 l85si18091872pfb.231.2018.04.26.03.49.09; Thu, 26 Apr 2018 03:49:24 -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 S1755388AbeDZKrf (ORCPT + 99 others); Thu, 26 Apr 2018 06:47:35 -0400 Received: from ZXSHCAS1.zhaoxin.com ([203.148.12.81]:16479 "EHLO ZXSHCAS1.zhaoxin.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1754891AbeDZKre (ORCPT ); Thu, 26 Apr 2018 06:47:34 -0400 Received: from zxbjmbx3.zhaoxin.com (10.29.252.165) by ZXSHCAS1.zhaoxin.com (10.28.252.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1261.35; Thu, 26 Apr 2018 18:47:31 +0800 Received: from timguo-System-Product-Name.zhaoxin.com (10.29.8.54) by zxbjmbx3.zhaoxin.com (10.29.252.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1261.35; Thu, 26 Apr 2018 18:47:30 +0800 From: David Wang To: , , , , , CC: , , , , , , David Wang Subject: [PATCH v3] report correct CPU/cache topology Date: Thu, 26 Apr 2018 18:47:27 +0800 Message-ID: <1524739647-30980-1-git-send-email-davidwang@zhaoxin.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.29.8.54] X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To zxbjmbx3.zhaoxin.com (10.29.252.165) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Centaur CPUs enumerate the cache topology in the same way as Intel CPUs, but the function is unused so far. The Centaur init code also misses to initialize x86_info::max_cores, so the CPU topology can't be described correctly. Initialize x86_info::max_cores and invoke init_intel_cachinfo() to make CPU and cache topology information avaliable and correct Signed-off-by: David Wang Changes from v2 to v3: *1 define new detect_num_cpu_cores() in common.c to replace the original intel_num_cpu_cores; *2 move cpu_detect_cache_sizes inside init_intel_cacheinfo. Changes from v1 to v2: *1 replace centaur_num_cpu_cores with early_init_centaur_mc according to suggestions from tglx; *2 call cpu_detect_cache_sizes when init_intel_cacheinfo returns 0. For some very old Centaur CPUs can't support the mechanisms defined in init_ intel_cacheinfo. --- arch/x86/include/asm/processor.h | 1 + arch/x86/kernel/cpu/centaur.c | 5 +++++ arch/x86/kernel/cpu/common.c | 14 ++++++++++++++ arch/x86/kernel/cpu/intel.c | 28 ++-------------------------- arch/x86/kernel/cpu/intel_cacheinfo.c | 6 ++++++ 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 21a1149..96e9070 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -192,6 +192,7 @@ extern u32 get_scattered_cpuid_leaf(unsigned int level, enum cpuid_regs_idx reg); extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c); extern void init_amd_cacheinfo(struct cpuinfo_x86 *c); +extern int detect_num_cpu_cores(struct cpuinfo_x86 *c); extern void detect_extended_topology(struct cpuinfo_x86 *c); extern void detect_ht(struct cpuinfo_x86 *c); diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c index 80d5110..c265494 100644 --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -160,6 +160,11 @@ static void init_centaur(struct cpuinfo_x86 *c) clear_cpu_cap(c, 0*32+31); #endif early_init_centaur(c); + init_intel_cacheinfo(c); + c->x86_max_cores = detect_num_cpu_cores(c); +#ifdef CONFIG_X86_32 + detect_ht(c); +#endif if (c->cpuid_level > 9) { unsigned int eax = cpuid_eax(10); diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 8a5b185..0c80d50 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -577,6 +577,20 @@ static void get_model_name(struct cpuinfo_x86 *c) *(s + 1) = '\0'; } +int detect_num_cpu_cores(struct cpuinfo_x86 *c) +{ + unsigned int eax, ebx, ecx, edx; + + if (!IS_ENABLED(CONFIG_SMP) || c->cpuid_level < 4) + return 1; + + cpuid_count(4, 0, &eax, &ebx, &ecx, &edx); + if (eax & 0x1f) + return (eax >> 26) + 1; + else + return 1; +} + void cpu_detect_cache_sizes(struct cpuinfo_x86 *c) { unsigned int n, dummy, ebx, ecx, edx, l2size; diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index b9693b8..e1138da 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -453,24 +453,6 @@ static void srat_detect_node(struct cpuinfo_x86 *c) #endif } -/* - * find out the number of processor cores on the die - */ -static int intel_num_cpu_cores(struct cpuinfo_x86 *c) -{ - unsigned int eax, ebx, ecx, edx; - - if (!IS_ENABLED(CONFIG_SMP) || c->cpuid_level < 4) - return 1; - - /* Intel has a non-standard dependency on %ecx for this CPUID level. */ - cpuid_count(4, 0, &eax, &ebx, &ecx, &edx); - if (eax & 0x1f) - return (eax >> 26) + 1; - else - return 1; -} - static void detect_vmx_virtcap(struct cpuinfo_x86 *c) { /* Intel VMX MSR indicated features */ @@ -671,19 +653,13 @@ static void init_intel(struct cpuinfo_x86 *c) * let's use the legacy cpuid vector 0x1 and 0x4 for topology * detection. */ - c->x86_max_cores = intel_num_cpu_cores(c); + c->x86_max_cores = detect_num_cpu_cores(c); #ifdef CONFIG_X86_32 detect_ht(c); #endif } - l2 = init_intel_cacheinfo(c); - - /* Detect legacy cache sizes if init_intel_cacheinfo did not */ - if (l2 == 0) { - cpu_detect_cache_sizes(c); - l2 = c->x86_cache_size; - } + init_intel_cacheinfo(c); if (c->cpuid_level > 9) { unsigned eax = cpuid_eax(10); diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c index 54d04d5..2a0597c 100644 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c @@ -20,6 +20,8 @@ #include #include +#include "cpu.h" + #define LVL_1_INST 1 #define LVL_1_DATA 2 #define LVL_2 3 @@ -802,6 +804,10 @@ unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c) c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d)); + if (!l2) { + cpu_detect_cache_sizes(c); + l2 = c->x86_cache_size; + } return l2; } -- 1.9.1