From patchwork Mon Jul 24 17:44:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 125133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1964065vqg; Mon, 24 Jul 2023 11:03:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlFZM7Z0KJi8xKDSbfBI1DHsRX0mEnNdOihAxrROvy2OlcmSgYeK85XmE8sjQt9+nfiL6Pnn X-Received: by 2002:a05:6358:6f1d:b0:134:c37f:4b63 with SMTP id r29-20020a0563586f1d00b00134c37f4b63mr8354220rwn.2.1690221826676; Mon, 24 Jul 2023 11:03:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690221826; cv=none; d=google.com; s=arc-20160816; b=qaEuAYTzAsGoyngcGeJzOl5prr0zL4d2Y6JbnvNXR1JcLoKqePnjcJwrftM3eFw7Ha NOVQVD2nYZ/uOkMNN5kSELJEMY7+ARLsKPPp3Y17ZfcheOrXAOQiWXZTbccEmS8USJ1L W8hTqBUmKrFaw4WdE4LemwuTut2ClBrwpqjeFLAB0XA8PbB+ldi/bJ6y+HoYvrvzdTSP vtWbq3l6HRiJS+EWLBD66i5wQnJWoWOUQGd75L3/UnD2P9+LFxnXLz751VKLfbPvnuOC IpwUjCH4YuHepxwnrxejpD22zAwLk9Zaol4GtkjHg3nWvQ/IJuBunAdxp71UwlA7ch6y YXDg== 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=kFimYBoIHtAuyZ0nV8lPkTq5OiYik0emivYDmavONE8=; fh=cDlgSYzM/IiVZ/EC06yL1+GD3+pSK8bXSWGje/Xzf2k=; b=JTDsYP7iVEs8zX35gA0PRdxA/Gu1ckeSBEjOnj7D6yTRyzfigllcUIfu7orglmnCoH Hkj5rvmcVuIFfmvAkVMP/wYqL25//TUkMzyJe8dz8Rb12eWJDdbfvOl3z3CKbJKpGlnp GqDKNx56BxqxClo5iEwa9tcFiBiqdsEcHAvK9nZD3kaWspsP+Qu8kZbMZg1maLagj2W4 b3LmSfd4lvACNeh0v006Z1tJsY0QRJo2zJUHMwbpRWLv6zf6h3NPYlJB+nDSnhNsQcRd Z79Odbnqf2DFQHJDPOtHgdx+Reng0copD3jRnW2JHeNN1bxFQ5t7kDiYx8U/Ewe4fvP4 uxkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=FHSQZqpS; dkim=neutral (no key) header.i=@linutronix.de; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i65-20020a636d44000000b0054fd947f66dsi9495599pgc.210.2023.07.24.11.03.32; Mon, 24 Jul 2023 11:03:46 -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=FHSQZqpS; dkim=neutral (no key) header.i=@linutronix.de; 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 S229897AbjGXRpa (ORCPT + 99 others); Mon, 24 Jul 2023 13:45:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231796AbjGXRod (ORCPT ); Mon, 24 Jul 2023 13:44:33 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B83B1BCC; Mon, 24 Jul 2023 10:44:10 -0700 (PDT) Message-ID: <20230724172844.340632180@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690220648; 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=kFimYBoIHtAuyZ0nV8lPkTq5OiYik0emivYDmavONE8=; b=FHSQZqpS7sWP+5YUx2FGrGYljE0lKjIgQY4afB+sXzC/VZrpgh7rB9EMOg8QFvkw5580Dn dtcdgZiuJ4a1aOkepaSI9XxLQYH1wcpcI0ZSM3jRBcn0wozHYoVI9JBTi4J1roSvxDBvVV akt7sqoODAodzSJXCXQpOIoYQHq/9AxI4FXOpUMCCX+hxePsARugQQZFiIvbrGIF0GrMdt TxNmElYghrqg39J7GZ1d42CbTXP/8PahwJuIbZQGiZJtOyhzk2TI429O/h68QC9eVWa1my EiH8jZZo1q7ffXtAAHiesDTIDfmxGhFswgkYgliEZ1fKlag77pN+oZx63MkJSQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690220648; 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=kFimYBoIHtAuyZ0nV8lPkTq5OiYik0emivYDmavONE8=; b=EbATRpE/8xzED6DWIRhPSb2e/h8GCTb7+yiecMEtS1UoIKniBJoOTHjfyt/7SRdxyziWvJ J/qZc/oGcq0nFZDA== 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, linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Guenter Roeck , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch 11/29] x86/cpu: Provide debug interface References: <20230724155329.474037902@linutronix.de> MIME-Version: 1.0 Date: Mon, 24 Jul 2023 19:44:08 +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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772326042396343359 X-GMAIL-MSGID: 1772326042396343359 Provide debug files which dump the topology related information of cpuinfo_x86. This is useful to validate the upcoming conversion of the topology evaluation for correctness or bug compatibility. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/Makefile | 2 + arch/x86/kernel/cpu/debugfs.c | 59 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -54,6 +54,8 @@ obj-$(CONFIG_X86_LOCAL_APIC) += perfctr obj-$(CONFIG_HYPERVISOR_GUEST) += vmware.o hypervisor.o mshyperv.o obj-$(CONFIG_ACRN_GUEST) += acrn.o +obj-$(CONFIG_DEBUG_FS) += debugfs.o + quiet_cmd_mkcapflags = MKCAP $@ cmd_mkcapflags = $(CONFIG_SHELL) $(srctree)/$(src)/mkcapflags.sh $@ $^ --- /dev/null +++ b/arch/x86/kernel/cpu/debugfs.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +#include +#include + +static int cpu_debug_show(struct seq_file *m, void *p) +{ + unsigned long cpu = (unsigned long)m->private; + struct cpuinfo_x86 *c; + + if (!cpu_online(cpu)) + return -ENODEV; + + c = per_cpu_ptr(&cpu_info, cpu); + + seq_printf(m, "initial_apicid: %x\n", c->topo.initial_apicid); + seq_printf(m, "apicid: %x\n", c->topo.apicid); + seq_printf(m, "pkg_id: %u\n", c->topo.pkg_id); + seq_printf(m, "die_id: %u\n", c->topo.die_id); + seq_printf(m, "cu_id: %u\n", c->topo.cu_id); + seq_printf(m, "core_id: %u\n", c->topo.core_id); + seq_printf(m, "logical_pkg_id: %u\n", c->topo.logical_pkg_id); + seq_printf(m, "logical_die_id: %u\n", c->topo.logical_die_id); + seq_printf(m, "llc_id: %u\n", c->topo.llc_id); + seq_printf(m, "l2c_id: %u\n", c->topo.l2c_id); + seq_printf(m, "max_cores: %u\n", c->x86_max_cores); + seq_printf(m, "max_die_per_pkg: %u\n", __max_die_per_package); + seq_printf(m, "smp_num_siblings: %u\n", smp_num_siblings); + return 0; +} + +static int cpu_debug_open(struct inode *inode, struct file *file) +{ + return single_open(file, cpu_debug_show, inode->i_private); +} + +static const struct file_operations dfs_cpu_ops = { + .open = cpu_debug_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static __init int cpu_init_debugfs(void) +{ + struct dentry *dir, *base = debugfs_create_dir("topo", arch_debugfs_dir); + unsigned long id; + char name [10]; + + dir = debugfs_create_dir("cpus", base); + for_each_possible_cpu(id) { + sprintf(name, "%lu", id); + debugfs_create_file(name, 0444, dir, (void *)id, &dfs_cpu_ops); + } + return 0; +} +late_initcall(cpu_init_debugfs);