Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2418078rwb; Sun, 4 Sep 2022 15:48:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR7KiEczcsB5KNW2RT90WEeTNvz+f09xCA8E180MxlAn6uwcqJ7y5SXKk7H9Q39qdsGQqv/E X-Received: by 2002:a17:90b:4d92:b0:1fd:aec0:1c26 with SMTP id oj18-20020a17090b4d9200b001fdaec01c26mr16192901pjb.133.1662331701653; Sun, 04 Sep 2022 15:48:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662331701; cv=none; d=google.com; s=arc-20160816; b=03OqNA3whRCta2HUdIxbmX5OheylbisIZzJxLqfPCyvi1ueLTIatJZaRtuSSzMUBip 5Z0G6hXZUmWSv5QxKy6oAJUvRRR5SHvdLtXNn2BEiW+V1iuKJEmELVeF+8owMCkiqbQj LD/84vCxm1lLzj3Px6MyAD1gOGyh1DVl54yq7IU0tbfSW8mabVxX4IHQR6XpwBeGw3jD P5JIbAzI+LsK1Md0ZTc2xpDNYyy90hm3Zeu/+3ZLsdGRWLHKtU1WpwxUvoIf2D5xyF3K ++LJY+U+TUS5q066dssBgK6koZzGWH3brHYySiwbQtCt8SsKobj2eWDLjfzp7fXj9sSs i1tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Rm4xzfpSQrPPtx8VSoa62A66wbCtcyyvqJRRKDZL61w=; b=hYktZn9IZQ0lICpJXLPgwvjBoaIfrwC+KkQt7tvzzR+fZHDJMUHNQ0Lqp6oh+4hszB R9/EfFjEQsAS+M1HrgfLBMmaurrTzbaWGleD1vnFRfCJKncYk6wlWFW9UZyzSPJRvAlB gh35UboTulYbdVttGpPGfrEcM4k8F71irkbgW8KTdVQhGxnw5+hgoGvfPd3Ei03RiBDi Ol8f61HyI4Yzflk0w6XZ36+OgmUm+gmoxdiXsx9NjJ/yBKmRa8S0exHi4F7esHIgtP/t RvuAgeWXV9kP1Had2sdS/8imKFYaRajVm0UTTgs6AewAzxgNAnAvkOhWp1agx0Ndsq7u Tqig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Ztu8i1Pz; 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=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l8-20020a63ba48000000b00420bdb2f5a9si9564225pgu.263.2022.09.04.15.48.09; Sun, 04 Sep 2022 15:48: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=@gmail.com header.s=20210112 header.b=Ztu8i1Pz; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236097AbiIDVpj (ORCPT + 99 others); Sun, 4 Sep 2022 17:45:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235217AbiIDVoT (ORCPT ); Sun, 4 Sep 2022 17:44:19 -0400 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 163E5303DD for ; Sun, 4 Sep 2022 14:42:48 -0700 (PDT) Received: by mail-il1-x131.google.com with SMTP id a9so3885569ilh.1 for ; Sun, 04 Sep 2022 14:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=Rm4xzfpSQrPPtx8VSoa62A66wbCtcyyvqJRRKDZL61w=; b=Ztu8i1PzYXrrBIVkF2DTluW99gf/zMexybwuV049ePkV9na4V8i7w1QCN6zxYTzykr gWJHK2OLUi+Boeahy3lUbVhZndOD18gcDpF5to3yTILayNYKZ4bgsx/ilM5F1cusady1 0detNR1/ZaP4mXE3QDeOJN3Ua6Em4qgA+SRN1gU8L2pJeKLHb8ULMMjczUSsBwLn+TZH Fl7fIusVg1NIux1kE9DvOselusKgLkhoeoH81jzxT3c3JfNvfJFAW9TRgtjIQDm0ayCV KSsA2K0pqsDfZfpv6h3kPC2JEitI9SjrLzqxJmiXXq4ZsLTfwXk71OymdVL0+ct6JMQE 1v3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Rm4xzfpSQrPPtx8VSoa62A66wbCtcyyvqJRRKDZL61w=; b=y8XCx1na1sitUlZ1EAZU5caINnillSuJN0qLMz/gFXyz3Pi91JMPsMWzGefzfEuzaH RL7T5P8BpuLORytcY/2XRpxvkrF7osFEWjcqqmOcTYinThltpTZr8pWPpdx3AGM+CCfY ElWAwjgfJI6IuG5Yv9/uktExHN9Y4nJqAgqELE7KvzOdtBUz7TqAcQaT95qyr/xFr6AY IzXeffbaiTSJcFauRaFUXwVf/Gz/3P/rlFqeq/N26pt5ZueOR2n9IO6XhstpYZfiHDMB v5aMSFqpJY64sAk8H6BWGbAYj4jIwJr4P37W3BvLDj3ykMm7hwan9XadD443vmMHwvb4 wlLw== X-Gm-Message-State: ACgBeo2ICU2QQH2sxXggbrwa1SXW1qdAwzcFuKeQagtxQjSLhLqmUztS 9wd6Mh3G6sB+pWw96VPHqyU= X-Received: by 2002:a92:dc8c:0:b0:2e9:469f:e5a3 with SMTP id c12-20020a92dc8c000000b002e9469fe5a3mr23264515iln.251.1662327768480; Sun, 04 Sep 2022 14:42:48 -0700 (PDT) Received: from frodo.. (c-73-78-62-130.hsd1.co.comcast.net. [73.78.62.130]) by smtp.googlemail.com with ESMTPSA id e12-20020a056602044c00b006889ea7be7bsm3727688iov.29.2022.09.04.14.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Sep 2022 14:42:48 -0700 (PDT) From: Jim Cromie To: jbaron@akamai.com, gregkh@linuxfoundation.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: daniel.vetter@ffwll.ch, seanpaul@chromium.org, robdclark@gmail.com, linux@rasmusvillemoes.dk, joe@perches.com, Jim Cromie Subject: [PATCH v6 40/57] dyndbg: abstraction macros for modname,function,filename fields Date: Sun, 4 Sep 2022 15:41:17 -0600 Message-Id: <20220904214134.408619-41-jim.cromie@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220904214134.408619-1-jim.cromie@gmail.com> References: <20220904214134.408619-1-jim.cromie@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 The .data table built of struct _ddebug[]s has about 40% repetition in the "decorator" fields: modname, function, filename. The real fix is to "normalize the db", but 1st we need a layer of accessor macros, giving us just one field deref to alter later. So: define 3 field-abstraction macros: desc_{modname,function,filename}(desc). replace all raw field refs in lib/dynamic_debug.c with them. The macros protect against NULL pointer derefs, substituting "_na_" otherwise. This provides a generic guard, opening options to drop the contents of __dyndbg_sites[] opportunistically, and trim kernel/module data. DRM, which could use only .class_id to control drm.debug, could drop them. The 3 macros use a common foundation: _ddebug_map_site(), which will adapt to follow the coming table-split. Also change field names; adding '_' prefix to insure that bare field-refs are found and fixed. Most field uses get the macros, except for dynamic_debug_init(), which will need to follow the rearrangements. NOTE: macros are private, not currently for general use. trace/events/dyndbg.h was a candidate to use these macros, for which I included the header. On rethink, these macros are wrong abstraction for tracing; better to expose a dynamic_prefix_emit(1) flavor, and use it in TP_printk to "decorate" enabled trace-logs like it does for sys-logs. So this patch removes the raw field-refs rather than use the macros. I left the include to mark the intention to use privatish interfaces, see if it draws objections or compile errs. [1] fills caller provided char-buffer, perhaps not ideal for tracefs. A fixed max-size-possible per-callsite (or globally) is practical, but the struct _ddebug_site * val is probably best; it refs a prdbg's site-rec of a builtin or loadable module, which is unique over the pertinent lifetime, and has all the info. WAG,TLDR: "decorating" could be defered until `cat trace`, modulo loadable sites[] data being needed to render after module is unloaded. no functional changes. Signed-off-by: Jim Cromie TP-print-dont-use-desc-foo --- include/linux/dynamic_debug.h | 12 ++++++------ include/trace/events/dyndbg.h | 7 +++---- lib/dynamic_debug.c | 37 ++++++++++++++++++++++------------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h index 04f49df308a7..e04f5b0a31e2 100644 --- a/include/linux/dynamic_debug.h +++ b/include/linux/dynamic_debug.h @@ -18,9 +18,9 @@ struct _ddebug { * These fields are used to drive the user interface * for selecting and displaying debug callsites. */ - const char *modname; - const char *function; - const char *filename; + const char *_modname; + const char *_function; + const char *_filename; const char *format; unsigned int lineno:18; #define CLS_BITS 6 @@ -166,9 +166,9 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor, #define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \ static struct _ddebug __aligned(8) \ __section("__dyndbg") name = { \ - .modname = KBUILD_MODNAME, \ - .function = __func__, \ - .filename = __FILE__, \ + ._modname = KBUILD_MODNAME, \ + ._function = __func__, \ + ._filename = __FILE__, \ .format = (fmt), \ .lineno = __LINE__, \ .flags = _DPRINTK_FLAGS_DEFAULT, \ diff --git a/include/trace/events/dyndbg.h b/include/trace/events/dyndbg.h index e19fcb56566c..2997289c0e3f 100644 --- a/include/trace/events/dyndbg.h +++ b/include/trace/events/dyndbg.h @@ -6,6 +6,7 @@ #define _TRACE_DYNDBG_H #include +#include /* capture pr_debug() callsite descriptor and message */ TRACE_EVENT(prdbg, @@ -32,8 +33,7 @@ TRACE_EVENT(prdbg, __get_str(msg)[len] = 0; ), - TP_printk("%s.%s %s", __entry->desc->modname, - __entry->desc->function, __get_str(msg)) + TP_printk("%s", __get_str(msg)) ); /* capture dev_dbg() callsite descriptor, device, and message */ @@ -64,8 +64,7 @@ TRACE_EVENT(devdbg, __get_str(msg)[len] = 0; ), - TP_printk("%s.%s %s", __entry->desc->modname, - __entry->desc->function, __get_str(msg)) + TP_printk("%s", __get_str(msg)) ); #endif /* _TRACE_DYNDBG_H */ diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 0870e939f255..5a22708679a7 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -167,6 +167,15 @@ static struct ddebug_class_map *ddebug_find_valid_class(struct ddebug_table cons return NULL; } +static inline struct _ddebug_site * _ddebug_map_site(const struct _ddebug *desc) +{ + return desc->site; +} +#define _desc_field(desc, _fld) (desc ? (_ddebug_map_site(desc)->_fld) : "_na_") +#define desc_modname(desc) _desc_field(desc, _modname) +#define desc_function(desc) _desc_field(desc, _function) +#define desc_filename(desc) _desc_field(desc, _filename) + #define __outvar /* filled by callee */ /* * Search the tables for _ddebug's which match the given `query' and @@ -212,16 +221,16 @@ static int ddebug_change(const struct ddebug_query *query, /* match against the source filename */ if (query->filename && - !match_wildcard(query->filename, dp->filename) && + !match_wildcard(query->filename, desc_filename(dp)) && !match_wildcard(query->filename, - kbasename(dp->filename)) && + kbasename(desc_filename(dp))) && !match_wildcard(query->filename, - trim_prefix(dp->filename))) + trim_prefix(desc_filename(dp)))) continue; /* match against the function */ if (query->function && - !match_wildcard(query->function, dp->function)) + !match_wildcard(query->function, desc_function(dp))) continue; /* match against the format */ @@ -257,9 +266,9 @@ static int ddebug_change(const struct ddebug_query *query, static_branch_enable(&dp->key.dd_key_true); } #endif - v4pr_info("changed %s:%d [%s]%s %s => %s\n", - trim_prefix(dp->filename), dp->lineno, - dt->mod_name, dp->function, + v4pr_info("changed %s:%d [%s]%s %s to %s\n", + trim_prefix(desc_filename(dp)), dp->lineno, + dt->mod_name, desc_function(dp), ddebug_describe_flags(dp->flags, &fbuf), ddebug_describe_flags(newflags, &nbuf)); dp->flags = newflags; @@ -836,10 +845,10 @@ static char *__dynamic_emit_prefix(const struct _ddebug *desc, char *buf) pos_after_tid = pos; if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME) pos += snprintf(buf + pos, remaining(pos), "%s:", - desc->modname); + desc_modname(desc)); if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) pos += snprintf(buf + pos, remaining(pos), "%s:", - desc->function); + desc_function(desc)); if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO) pos += snprintf(buf + pos, remaining(pos), "%d:", desc->lineno); @@ -1241,8 +1250,8 @@ static int ddebug_proc_show(struct seq_file *m, void *p) } seq_printf(m, "%s:%u [%s]%s =%s \"", - trim_prefix(dp->filename), dp->lineno, - iter->table->mod_name, dp->function, + trim_prefix(desc_filename(dp)), dp->lineno, + iter->table->mod_name, desc_function(dp), ddebug_describe_flags(dp->flags, &flags)); seq_escape_str(m, dp->format, ESCAPE_SPACE, "\t\r\n\""); seq_puts(m, "\""); @@ -1504,12 +1513,12 @@ static int __init dynamic_debug_init(void) } iter = iter_mod_start = __start___dyndbg; - modname = iter->modname; + modname = iter->_modname; i = mod_sites = mod_ct = 0; for (; iter < __stop___dyndbg; iter++, i++, mod_sites++) { - if (strcmp(modname, iter->modname)) { + if (strcmp(modname, iter->_modname)) { mod_ct++; di.num_descs = mod_sites; di.descs = iter_mod_start; @@ -1518,7 +1527,7 @@ static int __init dynamic_debug_init(void) goto out_err; mod_sites = 0; - modname = iter->modname; + modname = iter->_modname; iter_mod_start = iter; } } -- 2.37.2