From patchwork Mon Aug 14 08:54: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: 135269 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp2626242vqi; Mon, 14 Aug 2023 02:37:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFA/s9jF5g3I7WUmw8dyI6TyMD3Vtfuy1dltR4V2JSbxvAakttcIRPsK90yHr3QutGTTsMu X-Received: by 2002:a05:6a20:938c:b0:13a:6bca:7a84 with SMTP id x12-20020a056a20938c00b0013a6bca7a84mr14298420pzh.44.1692005841303; Mon, 14 Aug 2023 02:37:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692005841; cv=none; d=google.com; s=arc-20160816; b=ounWh+3H7AwC5L9CdMtEcemHIkfjvfgKbhbO3+kApg5FQVDgx59uHYTemT4nd9GiUZ SNuWeeYRIs28WhAuS4LIld//xbauW9YVDVS2E5cHjvzpDYhuLQRQ+LyDdWDmrdq4sXZM cKuuWyWjdzmSz7lI69FVLWEX8IkchFWQGJTZSfiyStsJY20b0tw8ZySJCOf3V2O5DYu3 vYIQle08FIgBm2uIvCQYPHotXQyA4L4JbNxSnk6yFXJO3o1U23x33rVQzomJ/AksdIss H5W1ulz7UWBTUTCb/gMmRBYVJC4CWL4Bn7AIfVo356dTMCInx6c11VAFZFySqmUdDIQz cMIQ== 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=gfUTIPblkGwpIS64sQCM323mDciLTw/qUO5rOF9RNNw=; fh=vmKIJtcbtoHWhyuxI4oEq8r1SWZ2V9Rrbp1Orw2DxqA=; b=ClmwQtnR0C4BS2BkMhDOKTEJvx2MsXFpbq+4/M4q5YAdyY8OTOlAa2pH3K+vQnRjQi oH/whd6S9C4Ydo41pxPQ/v8mtfIBX5xNM2JBfjROFJ+Hes8plZn4AJEyN0V9sEuvFYqm ml8O58fTb5beKTMtTGQqW/3320bjD1iMOlc1u1qCv+68vBsNx/p3iOvewHwzA0IDTMLI lN3h0bQ9Ry2z4p1tnkHFahBAlFGp8/Is++8zsKkEyZCeJjAWnt7MROilxne/YRtbaaJk qyOXw9kDgzejX5yp9VGb+pIRF6atIjkwbW4zMuCz0lMuh+qmx5bwvoYmlI9nfR1vtFLY TD6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fUo3gc3b; dkim=neutral (no key) header.i=@linutronix.de header.b=w5vLvANh; 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 c4-20020a6566c4000000b0055c7da0216dsi7976414pgw.635.2023.08.14.02.37.07; Mon, 14 Aug 2023 02:37:21 -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=fUo3gc3b; dkim=neutral (no key) header.i=@linutronix.de header.b=w5vLvANh; 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 S235143AbjHNIzi (ORCPT + 99 others); Mon, 14 Aug 2023 04:55:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234982AbjHNIyL (ORCPT ); Mon, 14 Aug 2023 04:54:11 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C8B010B for ; Mon, 14 Aug 2023 01:54:10 -0700 (PDT) Message-ID: <20230814085113.353191313@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1692003249; 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=gfUTIPblkGwpIS64sQCM323mDciLTw/qUO5rOF9RNNw=; b=fUo3gc3bicjahjrwsHlIeBYy5N7A+pacJrkOICkby8OeIU/00KC0wqCG+b3NaB/C2Vr6oW W27eUPqWJ5JcZOKDNP0s8DWHmWraDRt5HAJp2jwc+UIKUondGTexegwib/vbprGbcrf1dJ tVwIajA8fZjR6kyBPctdOeweY4ty5eP+ZF1wPQWdroxkVrmGXJmOCjqaMJZ+TL2moMbdzd ggI2MpmjvLiliEDpx+ek0Eddv5jF/S4YIcp/6upI/+/jgBCWTkYx92dyuCcBJm9ev5Iyzx bTszXIr60AH/sn9gMLSqLMrVuoO1sIxTro7FV+aA22U261dZlVCm8CzO2PoMFg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1692003249; 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=gfUTIPblkGwpIS64sQCM323mDciLTw/qUO5rOF9RNNw=; b=w5vLvANhXTr2/wnHK5MAoq3iMaabpBZwNoUvYH530HZzoZMaLZRBXsSPXFnxzmXTF3ZjEq mhZJn6J/Wk5g26Dw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Huang Rui , Juergen Gross , Dimitri Sivanich , Michael Kelley , Wei Liu , Pu Wen , Qiuxu Zhuo , Sohil Mehta Subject: [patch V4 22/41] x86/cpu: Provide debug interface References: <20230814085006.593997112@linutronix.de> MIME-Version: 1.0 Date: Mon, 14 Aug 2023 10:54:08 +0200 (CEST) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS 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: 1774196716821512723 X-GMAIL-MSGID: 1774196716821512723 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 Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- V2: Don't return ENODEV when offline and make online a field. --- arch/x86/kernel/cpu/Makefile | 2 + arch/x86/kernel/cpu/debugfs.c | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 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,58 @@ +// 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 = per_cpu_ptr(&cpu_info, cpu); + + seq_printf(m, "online: %d\n", cpu_online(cpu)); + if (!c->initialized) + return 0; + + 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);