Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5069285pxj; Wed, 26 May 2021 01:58:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGeA/MeiqbLuEFZhN1KbegiOGIPFR0yRk0ry3bu4f7YbMw0aSDRLCaYHn8OJVZF5lS3IBj X-Received: by 2002:a05:6602:2f0f:: with SMTP id q15mr25588419iow.75.1622019538508; Wed, 26 May 2021 01:58:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622019538; cv=none; d=google.com; s=arc-20160816; b=b2kF3AsNeOExn4Skl4ZXoz9yx/sexzD5FWnKmzK3XHONjv+1CcQ6hI3azlDYV5t83S 2dOdpWIGz6od5XmyW1K7hcTQVKRQvKGv905Bc5kBec3Usg2OAlgujALjJmRTxTS8fcYC sFesr/B21bPid4sKODiobgsly0WegeYDD6uhFOQzxzp9EK5dEm4wopv8X0t6VhK+xdsO xy1/QJeq5PRz1paTqATJraFyooxA6U01vIa0p4YktbwPJiV8E8WxJ2oPs7aLe258NePv 5TSjNsAmNS0TfExn3ccN6Ri7e8kcOqyS8RnCDa1vw8R7ZhaMy4eG9CyKK7WQoVm7gykR UQvg== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=YhkPVaZKIm9DZQqqxgLb/Cl0n6VLgqEfhyr5+MGRQiM=; b=IBCi+fBXKpymYDEWoMGum3X51zn1XkP+SRPsPaoXwM0xmtCUc0A62ZajFZyLk+ugbN s9FCAv8wkkVEt/XSAL5cgN8IOcnIT/TjCzybygXOM3zYdimYKMF2+KYWaRKYFALN3Jct 7Q/B8UbT5vfFKJgU9zPcCWZ0rP8R51KPjFoEmTGwBMnts7RyAD7SgbvZRs0LkPyFsGpK Jg7BgvIWUMSPQ48kfU4WTWCzLjNWQelXVQh2AbbeKJrjDJly4DRxJJXo78sc/AkDpe6Z 4eS1J9ej3qswUHIXMXMViDoHGuPP1VsRwEndsHpVNgbyEBjLdjWuyAn5QtxWzC5ioYHn yidw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=CzKC88p6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k14si1472223ili.35.2021.05.26.01.58.42; Wed, 26 May 2021 01:58:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=CzKC88p6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233509AbhEZI6l (ORCPT + 99 others); Wed, 26 May 2021 04:58:41 -0400 Received: from mx2.suse.de ([195.135.220.15]:49944 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233463AbhEZI6d (ORCPT ); Wed, 26 May 2021 04:58:33 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1622019421; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YhkPVaZKIm9DZQqqxgLb/Cl0n6VLgqEfhyr5+MGRQiM=; b=CzKC88p6vMROOwspfcEw1cL6s53X7tKkK9jA7OVrL3WCYzjh3f6p2myiTIRJcyRBmlLOWq /UsF7tQvL7bE6w/r7UCJ1pIULq3n+YEkTdPKBT2TjPzrPpUph+bFmj4vPwQlA/1OwRIhdc kANy4gO5wC3efYXIs48L0l7s0w9BNIE= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C6B82B01E; Wed, 26 May 2021 08:57:01 +0000 (UTC) Date: Wed, 26 May 2021 10:57:00 +0200 From: Petr Mladek To: Chris Down Cc: linux-kernel@vger.kernel.org, Jessica Yu , Sergey Senozhatsky , John Ogness , Steven Rostedt , Greg Kroah-Hartman , Johannes Weiner , Kees Cook , Andy Shevchenko , Rasmus Villemoes , kernel-team@fb.com Subject: Re: [PATCH v6 4/4] printk: index: Add indexing support to dev_printk Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 2021-05-18 13:00:48, Chris Down wrote: > While for most kinds of issues we have counters, tracepoints, or metrics > with a stable interface which can reliably be used to indicate issues, > in order to react to production issues quickly we sometimes need to work > with the interface which most kernel developers naturally use when > developing: printk, and printk-esques like dev_printk. > > dev_printk is by far the most likely custom subsystem printk to benefit > from the printk indexing infrastructure, since niche device issues > brought about by production changes, firmware upgrades, and the like are > one of the most common things that we need printk infrastructure's > assistance to monitor. > > Often these errors were never expected to practically manifest in > reality, and exhibit in code without extensive (or any) metrics present. > As such, there are typically very few options for issue detection > available to those with large fleets at the time the incident happens, > and we thus benefit strongly from monitoring netconsole in these > instances. > > As such, add the infrastructure for dev_printk to be indexed in the > printk index. Even on a minimal kernel config, the coverage of the base > kernel's printk index is significantly improved: > > Before: > > [root@ktst ~]# wc -l /sys/kernel/debug/printk/index/vmlinux > 4497 /sys/kernel/debug/printk/index/vmlinux > > After: > > [root@ktst ~]# wc -l /sys/kernel/debug/printk/index/vmlinux > 5573 /sys/kernel/debug/printk/index/vmlinux Cool. > In terms of implementation, in order to trivially disambiguate them, > dev_printk is now a macro which wraps _dev_printk. If preferred, it's > also possible to have the macro and function have the same name. I prefer to use _dev_printk to disambiguate the macro and function names. By other words, I prefer the approach used in this patch. Please, remove the "If preferred..." sentence in the next version. > diff --git a/include/linux/dev_printk.h b/include/linux/dev_printk.h > index 6f009559ee54..202c6a9ea7eb 100644 > --- a/include/linux/dev_printk.h > +++ b/include/linux/dev_printk.h > @@ -97,25 +97,54 @@ void _dev_info(const struct device *dev, const char *fmt, ...) > > #endif > > +/* > + * Some callsites directly call dev_printk rather than going through the > + * dev_ infrastructure, so we need to emit here as well as inside those > + * level-specific macros. Only one index entry will be produced, either way, > + * since dev_printk's `fmt` isn't known at compile time if going through the > + * dev_ macros. > + */ > +#define dev_printk(level, dev, fmt, ...) ({ \ > + dev_printk_index_emit(level, fmt); \ Please, define dev_printk_index_emit() macro before it is used for the first time. > + _dev_printk(level, dev, fmt, ##__VA_ARGS__); \ > +}) > + > /* > * #defines for all the dev_ macros to prefix with whatever > * possible use of #define dev_fmt(fmt) ... > */ > > -#define dev_emerg(dev, fmt, ...) \ > - _dev_emerg(dev, dev_fmt(fmt), ##__VA_ARGS__) > -#define dev_crit(dev, fmt, ...) \ > - _dev_crit(dev, dev_fmt(fmt), ##__VA_ARGS__) > -#define dev_alert(dev, fmt, ...) \ > - _dev_alert(dev, dev_fmt(fmt), ##__VA_ARGS__) > -#define dev_err(dev, fmt, ...) \ > - _dev_err(dev, dev_fmt(fmt), ##__VA_ARGS__) > -#define dev_warn(dev, fmt, ...) \ > - _dev_warn(dev, dev_fmt(fmt), ##__VA_ARGS__) > -#define dev_notice(dev, fmt, ...) \ > - _dev_notice(dev, dev_fmt(fmt), ##__VA_ARGS__) > -#define dev_info(dev, fmt, ...) \ > - _dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__) > +#define dev_printk_index_emit(level, fmt) \ > + printk_index_subsys_emit("%s %s: ", "", level, fmt) > + > +#define dev_emerg(dev, fmt, ...) ({ \ > + dev_printk_index_emit(KERN_EMERG, dev_fmt(fmt)); \ > + _dev_emerg(dev, dev_fmt(fmt), ##__VA_ARGS__); \ > +}) > +#define dev_crit(dev, fmt, ...) ({ \ > + dev_printk_index_emit(KERN_CRIT, dev_fmt(fmt)); \ > + _dev_crit(dev, dev_fmt(fmt), ##__VA_ARGS__); \ > +}) > +#define dev_alert(dev, fmt, ...) ({ \ > + dev_printk_index_emit(KERN_ALERT, dev_fmt(fmt)); \ > + _dev_alert(dev, dev_fmt(fmt), ##__VA_ARGS__); \ > +}) I would slightly reduce the duplcation the follwing way: #define dev_printk_index_wrap(_p_func, level, dev, fmt, ...) \ ({ \ printk_index_subsys_emit("%s %s: ", "", level, dev_fmt(fmt)); \ _p_func(dev, dev_fmt(fmt), ##__VA_ARGS__); \ }) #define dev_printk(level, dev, fmt, ...) \ dev_printk_index_wrap(_dev_printk, level, dev, ##__VA_ARGS__) #define dev_crit(dev, fmt, ...) \ dev_printk_index_wrap(_dev_crit, KERN_CRIT, dev, ##__VA_ARGS__) #define dev_alert(dev, fmt, ...) \ dev_printk_index_wrap(_dev_alert, KERN_ALERT, dev, ##__VA_ARGS__) Note that I did not try to complile it, so there might be a mistake. BTW: I was curious why we actually need _dev_crit() defined as a function. But it seems to reduce size of the kernel binaries, see the commit 38a1ec40efa196efbac0253 ("device.h drivers/base/core.c Convert dev_ logging macros to functions"). Sigh. Best Regards, Petr