Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1211382rwb; Fri, 28 Jul 2023 06:26:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlHSPtQL0RMmDXT7+KK3yQ4jQSPuahd2caizHzUIeHH3LkNOkcnYboL+DehQJLiWSLn11Cmv X-Received: by 2002:a05:6a21:7988:b0:125:517c:4f18 with SMTP id bh8-20020a056a21798800b00125517c4f18mr1485590pzc.8.1690550818837; Fri, 28 Jul 2023 06:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690550818; cv=none; d=google.com; s=arc-20160816; b=i8k7MlPkBj8M+ttSIpQTNEWTDMVA0EF3VqdQos5W+wqfjMt8x/GTtFjvwDSiuP/2yX wXlbiNjP821Fo/Iy/AYs4i09hMck/XNODhKfQmlOTrR2zFqCiwy4RCtiX8xQiIKm41EU E6QBg/WzHX1RfsGqUBh71zksOgN6f5Z34ppObfYXJAJrc8eDhwm8g76L2sR2i3ZrotoX OgQcCFhjKwrHZ5gksNYv82gQ8QgfeV6I/zvWqj2iFeAa1OS48tO6tVubD0BSupJk3MLl NC5kRSF+RD6kjVfOEp9DlO6u0jjtSHv6XE5KyulHvV0IagICfsvd56tsz9g966TwU/1+ o9Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=UqiiOrV6qFVmLayEKJExgkdA2s95N7jm4m59y0h1Wug=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=UIiscBMAHVrkG2CUYsjrpIolLLEWHrHNAl5jZYs9LVAWof7zCNB/4VHT9zMHCia5o3 ZZMnnBDXB5xLE4DggqOG3Bc8FTQWUd66fGISKidpYwcJx+HwuT8KXdekZs5TNv4Wkk2P vecR/p/H9Ti4NMwu7rrMjGLZqLuGPPcgkNAfeuOBVd3J9CKdwLowJKBOnVjiQm7RyeDM uC6tjSLkhQbygru8z9QvwzpFCna+a72gGvvsywxO4vVCwx+u6FXjfVKsRWJsxWv2HrU7 eBp4VnhED/o0r1J0+jDO6dMv5m8/fBRK/5Ak2Z4WeNhGxQREV+LDFKChIcxZ/zIbdklg JGSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fgQReNQd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a637211000000b00563f627f2ecsi2992838pgc.13.2023.07.28.06.26.45; Fri, 28 Jul 2023 06:26:58 -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=@linutronix.de header.s=2020 header.b=fgQReNQd; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236520AbjG1MO0 (ORCPT + 99 others); Fri, 28 Jul 2023 08:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235646AbjG1MNe (ORCPT ); Fri, 28 Jul 2023 08:13:34 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDE524219; Fri, 28 Jul 2023 05:13:11 -0700 (PDT) Message-ID: <20230728120930.895466874@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=UqiiOrV6qFVmLayEKJExgkdA2s95N7jm4m59y0h1Wug=; b=fgQReNQdRn9/yvbqP/CdlFu5LxypeGGTwddlcC0s2G4u4MHGhhmMqNYZv7BFy91KwwEA0k bSRfOJloS28zA4wkd/8zyrawfF3UwJjhX/bEVbcYRI4u+JL8urA4X2WgJAEG69/NB8AD+1 RG3xnrU98QmiXPR/m/3n8zmtF8FuOzGZZgTuUHPv5pDPovgODKVqPw+tLbarNZgkhxA/JR +9tTAIF7TKAs1nGuald5SFQdQcbI1MQCufZwoXIXudZQXh2dduR0mSnt3HgmxIE7QxqFKP hV8mZgmeqDTrdyf9VrN1C+26dFuz2qbJIbePoIoQ6/TMGacFEhs0bGVNUuPEeA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=UqiiOrV6qFVmLayEKJExgkdA2s95N7jm4m59y0h1Wug=; b=yCt1+DeZ/St5T5qYw7lNG+ybbKk1llaPu80y6NgiEy+tqc+ASby7vzN4wQVwyFcdeT4YCe CS0ai21ctKzAMbAQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 22/38] x86/cpu: Add legacy topology parser References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Fri, 28 Jul 2023 14:13:10 +0200 (CEST) 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_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 The legacy topology detection via CPUID leaf 4, which provides the number of cores in the package and CPUID leaf 1 which provides the number of logical CPUs in case that FEATURE_HT is enabled and the CMP_LEGACY feature is not set, is shared for Intel, Centaur amd Zhaoxin CPUs. Lift the code from common.c without the early detection hack and provide it as common fallback mechanism. Will be utilized in later changes. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/common.c | 3 ++ arch/x86/kernel/cpu/topology.h | 2 + arch/x86/kernel/cpu/topology_common.c | 37 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -883,6 +883,9 @@ void detect_ht(struct cpuinfo_x86 *c) #ifdef CONFIG_SMP int index_msb, core_bits; + if (topo_is_converted(c)) + return; + if (detect_ht_early(c) < 0) return; --- a/arch/x86/kernel/cpu/topology.h +++ b/arch/x86/kernel/cpu/topology.h @@ -7,6 +7,8 @@ struct topo_scan { unsigned int dom_shifts[TOPO_MAX_DOMAIN]; unsigned int dom_ncpus[TOPO_MAX_DOMAIN]; + // Legacy CPUID[1]:EBX[23:16] number of logical processors + unsigned int ebx1_nproc_shift; }; bool topo_is_converted(struct cpuinfo_x86 *c); --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -24,6 +24,41 @@ void topology_set_dom(struct topo_scan * } } +static unsigned int parse_num_cores(struct cpuinfo_x86 *c) +{ + struct { + u32 cache_type : 5, + unused : 21, + ncores : 6; + } eax; + + if (c->cpuid_level < 4) + return 1; + + cpuid_subleaf_reg(4, 0, CPUID_EAX, &eax); + if (!eax.cache_type) + return 1; + + return eax.ncores + 1; +} + +static void __maybe_unused parse_legacy(struct topo_scan *tscan) +{ + unsigned int cores, core_shift, smt_shift = 0; + struct cpuinfo_x86 *c = tscan->c; + + cores = parse_num_cores(c); + core_shift = get_count_order(cores); + + if (cpu_has(c, X86_FEATURE_HT)) { + if (!WARN_ON_ONCE(tscan->ebx1_nproc_shift < core_shift)) + smt_shift = tscan->ebx1_nproc_shift - core_shift; + } + + topology_set_dom(tscan, TOPO_SMT_DOMAIN, smt_shift, 1U << smt_shift); + topology_set_dom(tscan, TOPO_CORE_DOMAIN, core_shift, cores >> smt_shift); +} + bool topo_is_converted(struct cpuinfo_x86 *c) { /* Temporary until everything is converted over. */ @@ -88,6 +123,8 @@ static void parse_topology(struct topo_s /* The above is sufficient for UP */ if (!IS_ENABLED(CONFIG_SMP)) return; + + tscan->ebx1_nproc_shift = get_count_order(ebx.nproc); } static void topo_set_ids(struct topo_scan *tscan)