Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2976758rwd; Fri, 2 Jun 2023 18:42:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VJf85E5ERHDJKFE2buEQU30X6Eum9DwEl9TH9us21qhPcWXvexMXgAAnsu/K+qvxfA/jt X-Received: by 2002:a17:902:e744:b0:1af:a349:3f0d with SMTP id p4-20020a170902e74400b001afa3493f0dmr2057131plf.23.1685756532441; Fri, 02 Jun 2023 18:42:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685756532; cv=none; d=google.com; s=arc-20160816; b=DKRHZc1RYnzAUQ58CoC/58eYbTbNiHhZkgVBlsUTW/4di+BNR629aELBu411QzsQDa CsE+Yt/YwLW0pka0TzmnSeA47iCVZQcilwpn5ZGNB3PFHjJEMaLbrgUHXKOOgordGlYU K09l8PRt1xziDYpdsbIxinIkkuPLBXsQnohP7qnJeY18YxV+3/gPShdyvgDvFBn1UAvh PpZstBrGSgAuYr96dqqM1CkPnFzJ41CYH801wMIGUfcufMOeRxsKhWxFEYG/GQC8rdJe NpZhvgUrGqy1JtBv4r9x5XDwWckzeKKvHzXQdc/9vWnOZF2N7UhZeQdnbPbjoj+w9KZC TTqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=8L1A67+T5PSxz1zMkFnJ4yneIMrWRpk2sulMTsaGC1Q=; b=NlfqtJ7O78fTclMjVvRyEMa2q0fS/XtlGzZ1YwdDQ2DkMQj4Ug3wf0tgihJGDRreWH pgBE/rE9yRWqXQLagtKyeacVNypUp4bECfdEA09jawA7obqsP010ImgI/TCR9WlYuAz3 f9nYmXzIT0tKwsynByK8ZzzUxk+3xSie/5mbXb5a87XYjpqgd9N8cpiKxx24X/oSj5FK Rg/PeWjG6X449wf43A61dh0iFwAoLYiu2NL4sH41GLMzP3y9+OzPWej0lvlsI8lfY/sr z0gQHrbI7TvaAJWTCGRD6/JGUdPntwhGxObYpC4IvvR7bwAJgC6ZpDhF1wAOOovOgZGV p1Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mojatatu-com.20221208.gappssmtp.com header.s=20221208 header.b=Ln56BhnK; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g16-20020a170902869000b001b1ac20dbb1si1696522plo.400.2023.06.02.18.42.00; Fri, 02 Jun 2023 18:42:12 -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=@mojatatu-com.20221208.gappssmtp.com header.s=20221208 header.b=Ln56BhnK; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237069AbjFCB3C (ORCPT + 99 others); Fri, 2 Jun 2023 21:29:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235959AbjFCB3A (ORCPT ); Fri, 2 Jun 2023 21:29:00 -0400 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 087E019B for ; Fri, 2 Jun 2023 18:28:59 -0700 (PDT) Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6af8aac7a2eso1945961a34.3 for ; Fri, 02 Jun 2023 18:28:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1685755738; x=1688347738; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=8L1A67+T5PSxz1zMkFnJ4yneIMrWRpk2sulMTsaGC1Q=; b=Ln56BhnKOK5GARtByD2d1mcCIKKWMSn16dLMcEYY8/0HGne3B2iICESfhEbcPedMui WVUFQ1S0Ai8hdqAdYfRLY+oYZtidKroaJaNkjPcrQBZbczkwxlnxfRZ9eVbSyOARfaUl cs5nxm5WafThoMT0gqTmE5xlggOUHaYwHcZ2D0GJjGeYvmnlOm6UhakTREKONPQUP8TF ml2K39UlabmuTSX3iIjOnHF6p7DftyFuOTllR5ouvK+Eq7BghjwVR4K9hi6ILj23k0Mt zG4ITJToiA9ZOojTnNV7rsj7kYPVTpW6F9/nzAYSiBmSoZurqAP/mDlYiXVz1zvGl5hi oi9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685755738; x=1688347738; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8L1A67+T5PSxz1zMkFnJ4yneIMrWRpk2sulMTsaGC1Q=; b=XoJgaR2OpspUSEJUsbpgn44j/lXz4FxLZtEAvd2zCy1Hz/tGbpRv8C5qp+JF0c1b// eHud4En9cSVWm9bv0RUjONsN3ymwir+EOhJO75pfYdTVemYVGPLo7m7gSmKIwv5WmnNW XBdeNX6KBmuDj1ZXlMGQynGi/tI2nL1WELtb4YrubeFPmJ3DObsnKx4M2ICw/qcCn++B 242X7qygeDTu+M5vV8+hEhKSk49svVvoToA8FkUcsQ91dmSU18XjsfjuaAyQMNtpFCQR I0X3bbpAhO4nENqnI/h0fMKNzxnixxCFOURH2Unz468UDHaggq+XWwQolQ9OtQlpYbWM tjEw== X-Gm-Message-State: AC+VfDy712avjO4CUxgPdQxiEocytC4sP7wUUT3BAY+uvrGyBqNVw+TS 3hIARIbVtkc4YVDC/gpvGykVyw== X-Received: by 2002:a9d:64c7:0:b0:6af:9d30:4ba8 with SMTP id n7-20020a9d64c7000000b006af9d304ba8mr2979323otl.26.1685755738131; Fri, 02 Jun 2023 18:28:58 -0700 (PDT) Received: from ?IPV6:2804:14d:5c5e:44fb:643c:5e1a:4c7c:c5cd? ([2804:14d:5c5e:44fb:643c:5e1a:4c7c:c5cd]) by smtp.gmail.com with ESMTPSA id l17-20020a9d7a91000000b006af7580c84csm1170169otn.60.2023.06.02.18.28.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 02 Jun 2023 18:28:57 -0700 (PDT) Message-ID: Date: Fri, 2 Jun 2023 22:28:53 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [RFC PATCH net-next] net/sched: introduce pretty printers for Qdiscs Content-Language: en-US To: Vladimir Oltean , netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , linux-kernel@vger.kernel.org, Peilin Ye References: <20230602162935.2380811-1-vladimir.oltean@nxp.com> From: Pedro Tammela In-Reply-To: <20230602162935.2380811-1-vladimir.oltean@nxp.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On 02/06/2023 13:29, Vladimir Oltean wrote: > Sometimes when debugging Qdiscs it may be confusing to know exactly what > you're looking at, especially since they're hierarchical. Pretty printing > the handle, parent handle and netdev is a bit cumbersome, so this patch > proposes a set of wrappers around __qdisc_printk() which are heavily > inspired from __net_printk(). Probably worth mentioning drgn (https://drgn.readthedocs.io/en/latest/user_guide.html) I've picked it up recently after Peilin mentioned it and it's quite helpful. > > It is assumed that these printers will be more useful for untalented > kernel hackers such as myself rather than to the overall quality of the > code, since Qdiscs rarely print stuff to the kernel log by design (and > where they do, maybe that should be reconsidered in the first place). > > A single demo conversion has been made, there is room for more if the > idea is appreciated. > > Signed-off-by: Vladimir Oltean > --- > include/net/sch_debug.h | 45 +++++++++++++++++++++ > net/sched/Makefile | 2 +- > net/sched/sch_api.c | 4 +- > net/sched/sch_debug.c | 86 +++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 134 insertions(+), 3 deletions(-) > create mode 100644 include/net/sch_debug.h > create mode 100644 net/sched/sch_debug.c > > diff --git a/include/net/sch_debug.h b/include/net/sch_debug.h > new file mode 100644 > index 000000000000..032de4710671 > --- /dev/null > +++ b/include/net/sch_debug.h > @@ -0,0 +1,45 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef __NET_SCHED_DEBUG_H > +#define __NET_SCHED_DEBUG_H > + > +#include > +#include > + > +struct Qdisc; > + > +__printf(3, 4) __cold > +void qdisc_printk(const char *level, const struct Qdisc *sch, > + const char *format, ...); > +__printf(2, 3) __cold > +void qdisc_emerg(const struct Qdisc *sch, const char *format, ...); > +__printf(2, 3) __cold > +void qdisc_alert(const struct Qdisc *sch, const char *format, ...); > +__printf(2, 3) __cold > +void qdisc_crit(const struct Qdisc *sch, const char *format, ...); > +__printf(2, 3) __cold > +void qdisc_err(const struct Qdisc *sch, const char *format, ...); > +__printf(2, 3) __cold > +void qdisc_warn(const struct Qdisc *sch, const char *format, ...); > +__printf(2, 3) __cold > +void qdisc_notice(const struct Qdisc *sch, const char *format, ...); > +__printf(2, 3) __cold > +void qdisc_info(const struct Qdisc *sch, const char *format, ...); > + > +#if defined(CONFIG_DYNAMIC_DEBUG) || \ > + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) > +#define qdisc_dbg(__sch, format, args...) \ > +do { \ > + dynamic_qdisc_dbg(__sch, format, ##args); \ > +} while (0) > +#elif defined(DEBUG) > +#define qdisc_dbg(__sch, format, args...) \ > + qdisc_printk(KERN_DEBUG, __sch, format, ##args) > +#else > +#define qdisc_dbg(__sch, format, args...) \ > +({ \ > + if (0) \ > + qdisc_printk(KERN_DEBUG, __sch, format, ##args); \ > +}) > +#endif > + > +#endif > diff --git a/net/sched/Makefile b/net/sched/Makefile > index b5fd49641d91..ab13bf7db283 100644 > --- a/net/sched/Makefile > +++ b/net/sched/Makefile > @@ -6,7 +6,7 @@ > obj-y := sch_generic.o sch_mq.o > > obj-$(CONFIG_INET) += sch_frag.o > -obj-$(CONFIG_NET_SCHED) += sch_api.o sch_blackhole.o > +obj-$(CONFIG_NET_SCHED) += sch_api.o sch_blackhole.o sch_debug.o > obj-$(CONFIG_NET_CLS) += cls_api.o > obj-$(CONFIG_NET_CLS_ACT) += act_api.o > obj-$(CONFIG_NET_ACT_POLICE) += act_police.o > diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c > index fdb8f429333d..a6bfe2e40f89 100644 > --- a/net/sched/sch_api.c > +++ b/net/sched/sch_api.c > @@ -31,6 +31,7 @@ > #include > #include > #include > +#include > #include > > #include > @@ -597,8 +598,7 @@ EXPORT_SYMBOL(__qdisc_calculate_pkt_len); > void qdisc_warn_nonwc(const char *txt, struct Qdisc *qdisc) > { > if (!(qdisc->flags & TCQ_F_WARN_NONWC)) { > - pr_warn("%s: %s qdisc %X: is non-work-conserving?\n", > - txt, qdisc->ops->id, qdisc->handle >> 16); > + qdisc_warn(qdisc, "%s: qdisc is non-work-conserving?\n", txt); Looks much better > qdisc->flags |= TCQ_F_WARN_NONWC; > } > } > diff --git a/net/sched/sch_debug.c b/net/sched/sch_debug.c > new file mode 100644 > index 000000000000..1f47dac88c6e > --- /dev/null > +++ b/net/sched/sch_debug.c > @@ -0,0 +1,86 @@ > +#include > +#include > +#include > + > +static void qdisc_handle_str(u32 handle, char *str) > +{ > + if (handle == TC_H_ROOT) { > + sprintf(str, "root"); > + return; > + } else if (handle == TC_H_INGRESS) { > + sprintf(str, "ingress"); > + return; > + } else { > + sprintf(str, "%x:%x", TC_H_MAJ(handle) >> 16, TC_H_MIN(handle)); > + return; > + } nit: Did you consider a switch? > +} > + > +static void __qdisc_printk(const char *level, const struct Qdisc *sch, > + struct va_format *vaf) > +{ > + struct net_device *dev = qdisc_dev(sch); > + char handle_str[10], parent_str[10]; > + > + qdisc_handle_str(sch->handle, handle_str); > + qdisc_handle_str(sch->parent, parent_str); > + > + if (dev && dev->dev.parent) { > + dev_printk_emit(level[1] - '0', > + dev->dev.parent, > + "%s %s %s%s %s %s parent %s: %pV", > + dev_driver_string(dev->dev.parent), > + dev_name(dev->dev.parent), > + netdev_name(dev), netdev_reg_state(dev), > + sch->ops->id, handle_str, parent_str, vaf); > + } else if (dev) { > + printk("%s%s%s %s %s parent %s: %pV", > + level, netdev_name(dev), netdev_reg_state(dev), > + sch->ops->id, handle_str, parent_str, vaf); > + } else { > + printk("%s(NULL net_device) %s %s parent %s: %pV", level, > + sch->ops->id, handle_str, parent_str, vaf); > + } > +} > + > +void qdisc_printk(const char *level, const struct Qdisc *sch, > + const char *format, ...) > +{ > + struct va_format vaf; > + va_list args; > + > + va_start(args, format); > + > + vaf.fmt = format; > + vaf.va = &args; > + > + __qdisc_printk(level, sch, &vaf); > + > + va_end(args); > +} > +EXPORT_SYMBOL(qdisc_printk); > + > +#define define_qdisc_printk_level(func, level) \ > +void func(const struct Qdisc *sch, const char *fmt, ...) \ > +{ \ > + struct va_format vaf; \ > + va_list args; \ > + \ > + va_start(args, fmt); \ > + \ > + vaf.fmt = fmt; \ > + vaf.va = &args; \ > + \ > + __qdisc_printk(level, sch, &vaf); \ > + \ > + va_end(args); \ > +} \ > +EXPORT_SYMBOL(func); > + > +define_qdisc_printk_level(qdisc_emerg, KERN_EMERG); > +define_qdisc_printk_level(qdisc_alert, KERN_ALERT); > +define_qdisc_printk_level(qdisc_crit, KERN_CRIT); > +define_qdisc_printk_level(qdisc_err, KERN_ERR); > +define_qdisc_printk_level(qdisc_warn, KERN_WARNING); > +define_qdisc_printk_level(qdisc_notice, KERN_NOTICE); > +define_qdisc_printk_level(qdisc_info, KERN_INFO);