Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2560518rdb; Fri, 22 Sep 2023 02:07:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUJg1SzUO390kn1UZW4lZrDyqdlEZsOmpsqINMiN5wFr8ER+3ecN80OHy2TUcP/hDEb1uV X-Received: by 2002:a05:6359:a29:b0:143:8ea6:483 with SMTP id el41-20020a0563590a2900b001438ea60483mr2324563rwb.0.1695373625828; Fri, 22 Sep 2023 02:07:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695373625; cv=none; d=google.com; s=arc-20160816; b=UOawigOhfqGKF1NiT3xDcUNz9rGU5aBG1trVeVne6Puz1xIhONTYkHv5YFWFrq/aZN vmkCM58wHevEMtBLzUqurd9tbsrXwUu9xKtJvA73qRaTFDB9yqMo2GIVPC4OZYYt0jN7 EpX6ctjP8CYg+VcgnVvoZHu+4KNtsWoyrfdspavfzfZ0boGxtJz80exT/+dlwh5eFsQH 1r0GU7LLFLJn2jzHWHNMM1F+7ji19cL17JPd4EwcIU0wTIPnX+s3t/wKtvKioKWM3TSF Fq7fD2jjCz4yWgjKSyIDXTl3+FJbJ/O7oYcn+csVWJg16MUMxyVwDZYMDMACn3GPhgQx WkEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ZGIZ1SL3XOn4v/k/jfc0V/Kx2cFAQpv1ro3HElGvJKI=; fh=VbsyvOBQluDvXJjv3qiHjOy4YHzd3ugln7lG/NJm+W4=; b=QTgIRjrBLZIT9MgmAO9p+5Q38T7welpGSarxThmRHWwNyMz73Xrm0ZzDmZmGrDJFfi wAJv+Syz2amug81tLW5TkPdcWJI8xfja7Zt4ScVlDmEbhbDdlRl7Cb3KDvfk3s8UoNP6 ZbEUvzmkdeVufQ+B8ibsHk08b3C4oXGsWFBF1cgo2h+JsNZcW2qUjmRTpXFut+ZMbvC/ ISIVQ/v9ZNievLbwgi8q4Vs3hbK8uxoudcxckI8l+R0sBIQtlL0yWFMYLT+8NySN1zKO 6MWhZPgln90S0y/4J+weKLyehp51e+S5ZXrcf1zdjOzRK5X/FNsrTjDDbLgTF9oPT8CM +5pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=VVAadmS3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id y5-20020a056a001c8500b00665c24182bcsi3393334pfw.219.2023.09.22.02.07.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 02:07:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=VVAadmS3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 74F818293CB9; Fri, 22 Sep 2023 01:05:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232195AbjIVIFi (ORCPT + 99 others); Fri, 22 Sep 2023 04:05:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232137AbjIVIFU (ORCPT ); Fri, 22 Sep 2023 04:05:20 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB1C6CD7; Fri, 22 Sep 2023 01:03:49 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 753DE21AB9; Fri, 22 Sep 2023 08:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1695369828; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZGIZ1SL3XOn4v/k/jfc0V/Kx2cFAQpv1ro3HElGvJKI=; b=VVAadmS3V5n9yqHi52W+JiUysLV4LVQylZ3Rd+HLfeQes6xs5GDZhRvzzNSdIEyuAon763 SCGpgRLdY4W+L+srgUlGbWANiHrRpKVZNXJ/gxgDYSgrjJJ5IHLH+upiO2SLwwxkIQh8lk 1a18tDDLcqAcbIELxJHR9b3H2uXIuwg= Received: from suse.cz (pmladek.udp.ovpn2.prg.suse.de [10.100.201.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id EED312C142; Fri, 22 Sep 2023 08:03:47 +0000 (UTC) Date: Fri, 22 Sep 2023 10:03:47 +0200 From: Petr Mladek To: Enlin Mu Cc: Greg KH , John Ogness , Enlin Mu , rostedt@goodmis.org, senozhatsky@chromium.org, keescook@chromium.org, tony.luck@intel.com, gpiccoli@igalia.com, enlin.mu@unisoc.com, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] printk: add cpu id information to printk() output Message-ID: References: <8734zfx2bo.fsf@jogness.linutronix.de> <2023091547-mug-unlikable-571f@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 22 Sep 2023 01:05:52 -0700 (PDT) On Fri 2023-09-22 15:20:37, Enlin Mu wrote: > Petr Mladek 于2023年9月16日周六 00:34写道: > > > > On Fri 2023-09-15 11:53:13, Greg KH wrote: > > > On Fri, Sep 15, 2023 at 04:46:02PM +0800, Enlin Mu wrote: > > > > John Ogness 于2023年9月15日周五 16:34写道: > > > > > > > > > > On 2023-09-15, Enlin Mu wrote: > > > > > > Sometimes we want to print cpu id of printk() messages to consoles > > > > > > > > > > > > diff --git a/include/linux/threads.h b/include/linux/threads.h > > > > > > index c34173e6c5f1..6700bd9a174f 100644 > > > > > > --- a/include/linux/threads.h > > > > > > +++ b/include/linux/threads.h > > > > > > @@ -34,6 +34,9 @@ > > > > > > #define PID_MAX_LIMIT (CONFIG_BASE_SMALL ? PAGE_SIZE * 8 : \ > > > > > > (sizeof(long) > 4 ? 4 * 1024 * 1024 : PID_MAX_DEFAULT)) > > > > > > > > > > > > +#define CPU_ID_SHIFT 23 > > > > > > +#define CPU_ID_MASK 0xff800000 > > > > > > > > > > This only supports 256 CPUs. I think it doesn't make sense to try to > > > > > squish CPU and Task IDs into 32 bits. > > > > Yes, it is not good way, > > > > > > > > > > What about introducing a caller_id option to always only print the CPU > > > > > ID? Or do you really need Task _and_ CPU? > > > > Yes, I need it.Because I need to know which CPU is printing the > > > > log, so that I can identify the current system operation, such as load > > > > situation and CPU busy/idle status > > > > > > The cpu that is printing the log isn't the one that added the log > > > message, so I think you will have incorrect data here, right? > > > > We already store some metadata about the caller: > > > > * All fields are set by the printk code except for @seq, which is > > * set by the ringbuffer code. > > */ > > struct printk_info { > > u64 seq; /* sequence number */ > > u64 ts_nsec; /* timestamp in nanoseconds */ > > u16 text_len; /* length of text message */ > > u8 facility; /* syslog facility */ > > u8 flags:5; /* internal record flags */ > > u8 level:3; /* syslog level */ > > u32 caller_id; /* thread id or processor id */ > > > > struct dev_printk_info dev_info; > > }; > > > > The 32-bit caller ID is generated using: > > > > static inline u32 printk_caller_id(void) > > { > > return in_task() ? task_pid_nr(current) : > > 0x80000000 + smp_processor_id(); > > } > > > > We could add more metadata and always store the CPU ID and something > > like: > > > > [CTXT][ Tpid][ Ccpu] > > > > for example > > > > [TASK][ T234][ C4] > > [ IRQ][ T4567][ C17] > > [SIRQ][ T5][ C0] > > [ NMI][ T356][ C128] > > > Greate! > Do you have a plan to push it to linus? No. It was just a POC. It would require much more effort to make it ready for upstream, see below. > > The biggest problem is that it would change the format of the > > ringbuffer so that it would require updating external tools, > > working with crashdump, especially crash but there are also > > alternative python extensions for gdb. It would require patches for the crash tool, ./scripts/gdb/linux/dmesg.py, Documentation/admin-guide/kdump/gdbmacros.txt > > See below POC of the kernel part. It is not even compile tested. The size > > of the buffers is updated by a guess. Comments are not updated, ... And of course, make the POC working, update comments, ... I am sorry but I do not have enough time and motivation to do so. But I could answer questions, review the patches, ... when any interested person start working on it. Best Regards, Petr