From patchwork Thu Sep 21 08:51:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 142827 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5052907vqi; Thu, 21 Sep 2023 11:27:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDl5psC30ORX9F6CAFwGt/WSvDu2M1cOwxHW2qVKLwClZnZvKvhEAQIKBBZO11+fx+7+3t X-Received: by 2002:a05:6a00:23d3:b0:68a:5773:6319 with SMTP id g19-20020a056a0023d300b0068a57736319mr7055436pfc.11.1695320846130; Thu, 21 Sep 2023 11:27:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695320846; cv=none; d=google.com; s=arc-20160816; b=HdB0tC+Oebr0xSnZ8aKhzHwcoV+BLI9SazmAQrCKN+LdHNpoDUvCxNPWbOfHdlqqM2 hkM0sPO/Pc2bNSDif6Rg8raeenMqinM10tgXewWDtM/DeJ/QeG1pY48R99qGKXOGr2Lv 19ZtiRpK4jb8lNKajfsLV0hyh52R7A+INftK0TCsYsULPXZb41zMlWZyR8p7djtQwkWS bXxzNqIxRAmLsj72+WCMW0r5bKa5lTx/LNFy9BaUsCfavhpwU1gFAtPd5gQ1yqyYI+7h mhPSNSjD7oeYXqQBMGa9T88ynVfI2kFfHqSUriuIru6njwdzgZaHE9k8MniJhYuqo79X IWwg== 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=3zuye6cuN/UXKpEDGt76GmiwBqKZcclp/r7kmn7YPt8=; fh=JN7tMyF6zC6ERZ5PXsr4V7IKiYp4vRUwR5tQFwkRxbI=; b=ihv4GcgFUSDpWjxD1q1wTOfn5ACMFXW1L3NDw2VgKXLNQKuVCYXTCjOY3EkFcHVrsj wHctbfgoaLETScofZuWLlfN97yyzG+W8nDloocUhcNAUNesTGDnJ5yTbzdqizrM+Nnux zPhHTRMM29Cb5i0aprwLt6GZSnL4J3tXjEyyiJIssSDUbhsafYhFUituiFpuFDWve+XQ dAR5YLt+AT65LC3BVKk+m7DjsTKQCl+NhRbT+Nu+idXfLFQFUy7oYmye0nWwyQp3npCK XCYLa8yKKhe0zxwju5fIB7x3AAZZOZDul1R2pNk+evfyocS1kTs5cFeBhUVag8qeEKnc 9ReA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=YLEJXpBm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id u190-20020a6385c7000000b00565e5651c6dsi1814967pgd.766.2023.09.21.11.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 11:27:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=YLEJXpBm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 70434832A01D; Thu, 21 Sep 2023 10:26:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229595AbjIUR0H (ORCPT + 29 others); Thu, 21 Sep 2023 13:26:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbjIURZf (ORCPT ); Thu, 21 Sep 2023 13:25:35 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:242:246e::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2024559E1; Thu, 21 Sep 2023 10:09:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=3zuye6cuN/UXKpEDGt76GmiwBqKZcclp/r7kmn7YPt8=; t=1695316191; x=1696525791; b=YLEJXpBmqRgzWnGLLIg3lfq3TZDW0FXsGGDdlYK2wl0F4Kw qOgd83ieNnwUKZ2GELAfvipv7AwWkkgGvce8wwrb6/BAl9M961J0cyccxYCVzJ7V0ggCcnzZYnAV7 EqAIwponONEfRnvMStrGKLvYEIXwzlpKKJ2OQILkeOtryJ4rHLmRpmAsk1NCSSrvQRJCsNamhy0fV ek5oTp0D+z0CeXDIaxLOjKuL+yqc9oVoFUSjg9xOlH2N1gqGdzQUuh9A68w1qa3FP2bAU7J3zRjUN 0ccg3gbT1pPu6ocy6vQ6hye9HFTTj7kRUA76UxIrXX7BlxaOAfBqIwPr30Ziwc8w==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1qjFPl-00D3lb-18; Thu, 21 Sep 2023 10:52:01 +0200 From: Johannes Berg To: linux-kernel@vger.kernel.org Cc: linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, Johannes Berg Subject: [RFC PATCH 1/4] tracing: add __print_sym() to replace __print_symbolic() Date: Thu, 21 Sep 2023 10:51:31 +0200 Message-ID: <20230921105129.cd040deee13e.I9bd2617499f0d170df58471bc51379742190f92d@changeid> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921085129.261556-5-johannes@sipsolutions.net> References: <20230921085129.261556-5-johannes@sipsolutions.net> MIME-Version: 1.0 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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 10:26:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777672751234562849 X-GMAIL-MSGID: 1777672751234562849 From: Johannes Berg The way __print_symbolic() works is limited and inefficient in multiple ways: - you can only use it with a static list of symbols, but e.g. the SKB dropreasons are now a dynamic list - it builds the list in memory _three_ times, so it takes a lot of memory: - The print_fmt contains the list (since it's passed to the macro there). This actually contains the names _twice_, which is fixed up at runtime. - TRACE_DEFINE_ENUM() puts a 24-byte struct trace_eval_map for every entry, plus the string pointed to by it, which cannot be deduplicated with the strings in the print_fmt - The in-kernel symbolic printing creates yet another list of struct trace_print_flags for trace_print_symbols_seq() - it also requires runtime fixup during init, which is a lot of string parsing due to the print_fmt fixup Introduce __print_sym() to - over time - replace the old one. We can easily extend this also to __print_flags later, but I cared more about the SKB dropreasons for now. This new __print_sym() requires only a single list of items, created by TRACE_DEFINE_SYM_LIST(), for can even use another already existing list by using TRACE_DEFINE_SYM_FNS() with lookup and show methods. Then, instead of doing an init-time fixup, just do this at the time when userspace reads the print_fmt. This way, dynamically updated lists are possible. For userspace, nothing actually changes, because the print_fmt is shown exactly the same way the old __print_symbolic() was. This adds about 4k .text in my test builds, but that'll be more than paid for by the actual conversions. OPEN QUESTIONS: - do we need TRACE_EVENT_FL_DYNPRINT or should we just always go through show_print_fmt()? If we do, we can get rid of set_event_dynprint() which is also a stupid function, and somewhat inefficient. - Is the WARN_ON() in show_print_fmt() correct? Can we have a dynamic event using this infrastructure? I don't know about dynamic events enough. - Is the double-slash (//) thing a good approach? I was looking for something that couldn't happen in C, and that's a comment so it shouldn't be possible ... It's only internal though so we could always change it. Parsing to the next , means we'd have to parse a LOT of C, so that's out of the question. - Is it correct that we can assume RCU critical section when in the lookup function? The SKB code currently does, but I may not ever have actually run this code yet. - Where should all the functions be implemented :-) Signed-off-by: Johannes Berg --- include/asm-generic/vmlinux.lds.h | 3 +- include/linux/module.h | 2 + include/linux/trace_events.h | 10 ++ include/linux/tracepoint.h | 20 ++++ include/trace/stages/init.h | 54 +++++++++ include/trace/stages/stage2_data_offsets.h | 6 + include/trace/stages/stage3_trace_output.h | 9 ++ include/trace/stages/stage7_class_define.h | 4 + kernel/module/main.c | 3 + kernel/trace/trace_events.c | 131 ++++++++++++++++++++- kernel/trace/trace_output.c | 43 +++++++ 11 files changed, 282 insertions(+), 3 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 9c59409104f6..b2b45ff0a701 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -263,7 +263,8 @@ #define FTRACE_EVENTS() \ . = ALIGN(8); \ BOUNDED_SECTION(_ftrace_events) \ - BOUNDED_SECTION_BY(_ftrace_eval_map, _ftrace_eval_maps) + BOUNDED_SECTION_BY(_ftrace_eval_map, _ftrace_eval_maps) \ + BOUNDED_SECTION(_ftrace_sym_defs) #else #define FTRACE_EVENTS() #endif diff --git a/include/linux/module.h b/include/linux/module.h index a98e188cf37b..bf14b74a872c 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -524,6 +524,8 @@ struct module { unsigned int num_trace_events; struct trace_eval_map **trace_evals; unsigned int num_trace_evals; + struct trace_sym_def **trace_sym_defs; + unsigned int num_trace_sym_defs; #endif #ifdef CONFIG_FTRACE_MCOUNT_RECORD unsigned int num_ftrace_callsites; diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index eb5c3add939b..9ab651a8fa0b 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -24,6 +24,13 @@ const char *trace_print_flags_seq(struct trace_seq *p, const char *delim, const char *trace_print_symbols_seq(struct trace_seq *p, unsigned long val, const struct trace_print_flags *symbol_array); +const char *trace_print_sym_seq(struct trace_seq *p, unsigned long long val, + const char *(*lookup)(unsigned long long val)); +const char *trace_sym_lookup(const struct trace_sym_entry *list, + size_t len, unsigned long long value); +void trace_sym_show(struct seq_file *m, + const struct trace_sym_entry *list, size_t len); + #if BITS_PER_LONG == 32 const char *trace_print_flags_seq_u64(struct trace_seq *p, const char *delim, unsigned long long flags, @@ -331,6 +338,7 @@ enum { TRACE_EVENT_FL_EPROBE_BIT, TRACE_EVENT_FL_FPROBE_BIT, TRACE_EVENT_FL_CUSTOM_BIT, + TRACE_EVENT_FL_DYNPRINT_BIT, }; /* @@ -348,6 +356,7 @@ enum { * CUSTOM - Event is a custom event (to be attached to an exsiting tracepoint) * This is set when the custom event has not been attached * to a tracepoint yet, then it is cleared when it is. + * DYNPRINT - Event has dynamic symbol prints */ enum { TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT), @@ -361,6 +370,7 @@ enum { TRACE_EVENT_FL_EPROBE = (1 << TRACE_EVENT_FL_EPROBE_BIT), TRACE_EVENT_FL_FPROBE = (1 << TRACE_EVENT_FL_FPROBE_BIT), TRACE_EVENT_FL_CUSTOM = (1 << TRACE_EVENT_FL_CUSTOM_BIT), + TRACE_EVENT_FL_DYNPRINT = (1 << TRACE_EVENT_FL_DYNPRINT_BIT), }; #define TRACE_EVENT_FL_UKPROBE (TRACE_EVENT_FL_KPROBE | TRACE_EVENT_FL_UPROBE) diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 88c0ba623ee6..7650019f4347 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -31,6 +31,24 @@ struct trace_eval_map { unsigned long eval_value; }; +struct trace_sym_def { + const char *system; + const char *symbol_id; + /* may return NULL */ + const char * (*lookup)(unsigned long long); + /* + * Must print the list: ', { val, "name"}, ...' + * with no trailing comma, but with the leading ', ' + * to simplify things: + */ + void (*show)(struct seq_file *); +}; + +struct trace_sym_entry { + unsigned long long value; + const char *name; +}; + #define TRACEPOINT_DEFAULT_PRIO 10 extern struct srcu_struct tracepoint_srcu; @@ -109,6 +127,8 @@ extern void syscall_unregfunc(void); #define TRACE_DEFINE_ENUM(x) #define TRACE_DEFINE_SIZEOF(x) +#define TRACE_DEFINE_SYM_FNS(...) +#define TRACE_DEFINE_SYM_LIST(...) #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p) diff --git a/include/trace/stages/init.h b/include/trace/stages/init.h index 000bcfc8dd2e..251ab22485d1 100644 --- a/include/trace/stages/init.h +++ b/include/trace/stages/init.h @@ -23,6 +23,60 @@ TRACE_MAKE_SYSTEM_STR(); __section("_ftrace_eval_map") \ *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a +/* + * Define a symbol for __print_sym by giving lookup and + * show functions. See &struct trace_sym_def. + */ +#define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show) \ + _TRACE_DEFINE_SYM_FNS(TRACE_SYSTEM, _symbol_id, _lookup, _show) +#define _TRACE_DEFINE_SYM_FNS(_system, _symbol_id, _lookup, _show) \ + __TRACE_DEFINE_SYM_FNS(_system, _symbol_id, _lookup, _show) +#define __TRACE_DEFINE_SYM_FNS(_system, _symbol_id, _lookup, _show) \ + ___TRACE_DEFINE_SYM_FNS(_system ## _ ## _symbol_id, _symbol_id, \ + _lookup, _show) +#define ___TRACE_DEFINE_SYM_FNS(_name, _symbol_id, _lookup, _show) \ + static struct trace_sym_def \ + __trace_sym_def_ ## _name = { \ + .system = TRACE_SYSTEM_STRING, \ + /* need the ) for later strcmp */ \ + .symbol_id = #_symbol_id ")", \ + .lookup = _lookup, \ + .show = _show, \ + }; \ + static struct trace_sym_def \ + __section("_ftrace_sym_defs") \ + *__trace_sym_def_p_ ## _name = &__trace_sym_def_ ## _name + +/* + * Define a symbol for __print_sym by giving lookup and + * show functions. See &struct trace_sym_def. + */ +#define TRACE_DEFINE_SYM_LIST(_symbol_id, ...) \ + _TRACE_DEFINE_SYM_LIST(TRACE_SYSTEM, _symbol_id, __VA_ARGS__) +#define _TRACE_DEFINE_SYM_LIST(_system, _symbol_id, ...) \ + __TRACE_DEFINE_SYM_LIST(_system, _symbol_id, __VA_ARGS__) +#define __TRACE_DEFINE_SYM_LIST(_system, _symbol_id, ...) \ + ___TRACE_DEFINE_SYM_LIST(_system ## _ ## _symbol_id, _symbol_id,\ + __VA_ARGS__) +#define ___TRACE_DEFINE_SYM_LIST(_name, _symbol_id, ...) \ + static struct trace_sym_entry \ + __trace_sym_list_ ## _name[] = { __VA_ARGS__ }; \ + static const char * \ + __trace_sym_lookup_ ## _name(unsigned long long value) \ + { \ + return trace_sym_lookup(__trace_sym_list_ ## _name, \ + ARRAY_SIZE(__trace_sym_list_ ## _name), value); \ + } \ + static void \ + __trace_sym_show_ ## _name(struct seq_file *m) \ + { \ + trace_sym_show(m, __trace_sym_list_ ## _name, \ + ARRAY_SIZE(__trace_sym_list_ ## _name)); \ + } \ + ___TRACE_DEFINE_SYM_FNS(_name, _symbol_id, \ + __trace_sym_lookup_ ## _name, \ + __trace_sym_show_ ## _name) + #undef TRACE_DEFINE_SIZEOF #define TRACE_DEFINE_SIZEOF(a) \ static struct trace_eval_map __used __initdata \ diff --git a/include/trace/stages/stage2_data_offsets.h b/include/trace/stages/stage2_data_offsets.h index 469b6a64293d..83a287f78501 100644 --- a/include/trace/stages/stage2_data_offsets.h +++ b/include/trace/stages/stage2_data_offsets.h @@ -5,6 +5,12 @@ #undef TRACE_DEFINE_ENUM #define TRACE_DEFINE_ENUM(a) +#undef TRACE_DEFINE_SYM_FNS +#define TRACE_DEFINE_SYM_FNS(_symbol_id, _lookup, _show) + +#undef TRACE_DEFINE_SYM_LIST +#define TRACE_DEFINE_SYM_LIST(_symbol_id, ...) + #undef TRACE_DEFINE_SIZEOF #define TRACE_DEFINE_SIZEOF(a) diff --git a/include/trace/stages/stage3_trace_output.h b/include/trace/stages/stage3_trace_output.h index c1fb1355d309..d2c6458b62dc 100644 --- a/include/trace/stages/stage3_trace_output.h +++ b/include/trace/stages/stage3_trace_output.h @@ -79,6 +79,15 @@ trace_print_symbols_seq(p, value, symbols); \ }) +#undef __print_sym +#define __print_sym(value, symbol_id) \ + ___print_sym(TRACE_SYSTEM, value, symbol_id) +#define ___print_sym(sys, value, symbol_id) \ + ____print_sym(sys, value, symbol_id) +#define ____print_sym(sys, value, symbol_id) \ + trace_print_sym_seq(p, value, \ + __trace_sym_def_p_ ## sys ## _ ## symbol_id->lookup) + #undef __print_flags_u64 #undef __print_symbolic_u64 #if BITS_PER_LONG == 32 diff --git a/include/trace/stages/stage7_class_define.h b/include/trace/stages/stage7_class_define.h index bcb960d16fc0..ce802172b5d7 100644 --- a/include/trace/stages/stage7_class_define.h +++ b/include/trace/stages/stage7_class_define.h @@ -25,6 +25,10 @@ #undef __print_hex_dump #undef __get_buf +#undef __print_sym +/* use // as the separator since it'd be a comment in C */ +#define __print_sym(value, symbol_id) __print_sym(value\/\/symbol_id) + /* * The below is not executed in the kernel. It is only what is * displayed in the print format for userspace to parse. diff --git a/kernel/module/main.c b/kernel/module/main.c index 98fedfdb8db5..7752c3883cd2 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2161,6 +2161,9 @@ static int find_module_sections(struct module *mod, struct load_info *info) mod->trace_evals = section_objs(info, "_ftrace_eval_map", sizeof(*mod->trace_evals), &mod->num_trace_evals); + mod->trace_sym_defs = section_objs(info, "_ftrace_sym_defs", + sizeof(*mod->trace_sym_defs), + &mod->num_trace_sym_defs); #endif #ifdef CONFIG_TRACING mod->trace_bprintk_fmt_start = section_objs(info, "__trace_printk_fmt", diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index ed367d713be0..38eaa7dce078 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -1559,6 +1559,104 @@ static void *f_next(struct seq_file *m, void *v, loff_t *pos) return node; } +extern struct trace_sym_def *__start_ftrace_sym_defs[]; +extern struct trace_sym_def *__stop_ftrace_sym_defs[]; + +static void show_sym_list(struct seq_file *m, struct trace_event_call *call, + const char *name) +{ + struct trace_sym_def **sym_defs; + unsigned int n_sym_defs, i; + + if (call->module) { + struct module *mod = call->module; + + sym_defs = mod->trace_sym_defs; + n_sym_defs = mod->num_trace_sym_defs; + } else { + sym_defs = __start_ftrace_sym_defs; + n_sym_defs = __stop_ftrace_sym_defs - __start_ftrace_sym_defs; + } + + for (i = 0; i < n_sym_defs; i++) { + if (!sym_defs[i]) + continue; + if (sym_defs[i]->system != call->class->system) + continue; + if (strncmp(name, sym_defs[i]->symbol_id, + strlen(sym_defs[i]->symbol_id))) + continue; + if (sym_defs[i]->show) + sym_defs[i]->show(m); + break; + } +} + +static void show_print_fmt(struct seq_file *m, struct trace_event_call *call) +{ + char *ptr = call->print_fmt; + int quote = 0; + int wait_for_doubleslash = 0; + + if (!(call->flags & TRACE_EVENT_FL_DYNPRINT) || + /* WARN because dynamic events have no module */ + WARN_ON_ONCE(call->flags & TRACE_EVENT_FL_DYNAMIC)) { + seq_printf(m, "\nprint fmt: %s\n", call->print_fmt); + return; + } + + seq_puts(m, "\nprint fmt: "); + while (*ptr) { + if (*ptr == '\\') { + seq_putc(m, *ptr); + ptr++; + /* paranoid */ + if (!*ptr) + break; + goto next; + } + if (*ptr == '"') { + quote ^= 1; + goto next; + } + if (quote) + goto next; + + if (wait_for_doubleslash == 1 && *ptr == '/') { + wait_for_doubleslash = 2; + ptr++; + continue; + } else if (wait_for_doubleslash == 2 && *ptr != '/') { + seq_putc(m, '/'); + wait_for_doubleslash = 1; + goto next; + } else if (wait_for_doubleslash == 2 && *ptr == '/') { + const char *name; + + ptr++; + name = ptr; + /* skip the name */ + while (*ptr && *ptr != ')') + ptr++; + wait_for_doubleslash = 0; + show_sym_list(m, call, name); + continue; + } + + if (strncmp(ptr, "__print_sym(", 12) == 0) { + ptr += 12; + seq_puts(m, "__print_symbolic("); + wait_for_doubleslash = 1; + continue; + } +next: + seq_putc(m, *ptr); + ptr++; + } + + seq_putc(m, '\n'); +} + static int f_show(struct seq_file *m, void *v) { struct trace_event_call *call = event_file_data(m->private); @@ -1577,8 +1675,7 @@ static int f_show(struct seq_file *m, void *v) return 0; case FORMAT_PRINTFMT: - seq_printf(m, "\nprint fmt: %s\n", - call->print_fmt); + show_print_fmt(m, call); return 0; } @@ -2552,6 +2649,32 @@ static int event_init(struct trace_event_call *call) return ret; } +static void set_event_dynprint(struct trace_event_call *call) +{ + char *ptr; + int quote = 0; + + for (ptr = call->print_fmt; *ptr; ptr++) { + if (*ptr == '\\') { + ptr++; + /* paranoid */ + if (!*ptr) + break; + continue; + } + if (*ptr == '"') { + quote ^= 1; + continue; + } + if (quote) + continue; + if (strncmp(ptr, "__print_sym(", 12) == 0) { + call->flags |= TRACE_EVENT_FL_DYNPRINT; + break; + } + } +} + static int __register_event(struct trace_event_call *call, struct module *mod) { @@ -2567,6 +2690,8 @@ __register_event(struct trace_event_call *call, struct module *mod) else call->module = mod; + set_event_dynprint(call); + return 0; } @@ -3810,6 +3935,8 @@ static __init int event_trace_enable(void) ret = event_init(call); if (!ret) list_add(&call->list, &ftrace_events); + + set_event_dynprint(call); } register_trigger_cmds(); diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index db575094c498..9196f408a1d2 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -124,6 +124,49 @@ trace_print_symbols_seq(struct trace_seq *p, unsigned long val, } EXPORT_SYMBOL(trace_print_symbols_seq); +const char *trace_sym_lookup(const struct trace_sym_entry *list, + size_t len, unsigned long long value) +{ + size_t i; + + for (i = 0; i < len; i++) { + if (list[i].value == value) + return list[i].name; + } + return NULL; +} +EXPORT_SYMBOL(trace_sym_lookup); + +void trace_sym_show(struct seq_file *m, + const struct trace_sym_entry *list, size_t len) +{ + size_t i; + + for (i = 0; i < len; i++) + seq_printf(m, ", { %lld, \"%s\" }", + list[i].value, list[i].name); +} +EXPORT_SYMBOL(trace_sym_show); + +const char * +trace_print_sym_seq(struct trace_seq *p, unsigned long long val, + const char *(*lookup)(unsigned long long val)) +{ + const char *ret = trace_seq_buffer_ptr(p); + const char *name; + + name = lookup(val); + if (name) + trace_seq_puts(p, name); + else + trace_seq_printf(p, "0x%llx", val); + + trace_seq_putc(p, 0); + + return ret; +} +EXPORT_SYMBOL(trace_print_sym_seq); + #if BITS_PER_LONG == 32 const char * trace_print_flags_seq_u64(struct trace_seq *p, const char *delim, From patchwork Thu Sep 21 08:51:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 143488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5639134vqi; Fri, 22 Sep 2023 07:53:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjLfYXKEI4VW5RGIihp7BoP6anMDpijXtpA6Juu0TMAtK9xDtylXsFyfTrM90JA7HEADmV X-Received: by 2002:a05:6358:7e14:b0:143:383e:5b22 with SMTP id o20-20020a0563587e1400b00143383e5b22mr10486231rwm.28.1695394431342; Fri, 22 Sep 2023 07:53:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695394431; cv=none; d=google.com; s=arc-20160816; b=EpIY29jDzZp7nlgB69TTGk8+F3nhlyWFEAzvRTpYGFGiE7ItowabwMDDwKQEbCyVU/ V+h5bYAVEIikNZGxJTxACQx+6Xc/xDPTrFvtnGOzq3eYlB+gdov7iCntEopMgsFQqiBr MySB37uoKEppYafju1eT/D77s8cCBZ3WlgclkTfgjL1N0/UESfxmsla/FS489/XRzTzs ozpArvs3tmzCqAsk1uB2XqWWHIr9uuhsM9FqOcfSgkUaH1rpCVaLWi5D3H6Gx899z2Gl b2dJHVgOdbwWW6hahVMftR2UZXgukzYwkDb1Fwrbdv6agSX7AKCcqiFXp/A7g5qykrJg NN+A== 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=KcbEGqZWRjDRIS84NcPwJ70wJrRePDMy7FnnB2l/XTc=; fh=JN7tMyF6zC6ERZ5PXsr4V7IKiYp4vRUwR5tQFwkRxbI=; b=WRVBefeXAnaCLOq1ynJN9GakQV1lN3USjMlGpT6hZ5r2xSQWLEU5gCPctjpk21JDfV xSXgLUcxXCj8a9eFe7PtR+yOutQPtvHAZbYQ3G8uZfCUgiw1FjZqvbLyzFyEDwJ6kinC WiyvZtI+wzcwLjlnrvGlTK7HhOa1+wtvPhNiCHhMIn0w2ADVd+TUSl9Zo7tq2raV8htg 5+KE4aAFygdxVHD2ygtNFtnWXc44jp8jKTY2ev8a/Fm6ZR2/EP1CI0R/jG7aYFsvKcYg XbG1AIgTcKMEQOjR50fFtPUXNnJiJVnlJmlzfoM1yJk0vWpVOllQe/BT7+LXusfZ1nsv WktQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=IQW96roG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id w71-20020a63824a000000b00573fd75b486si4051701pgd.658.2023.09.22.07.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 07:53:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=IQW96roG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 53F148363C47; Thu, 21 Sep 2023 14:16:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232713AbjIUVQm (ORCPT + 29 others); Thu, 21 Sep 2023 17:16:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233238AbjIUVP3 (ORCPT ); Thu, 21 Sep 2023 17:15:29 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:242:246e::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D76DAE3A4; Thu, 21 Sep 2023 10:08:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=KcbEGqZWRjDRIS84NcPwJ70wJrRePDMy7FnnB2l/XTc=; t=1695316084; x=1696525684; b=IQW96roGNxzONuN9PjcFsaqTedRIWrD2bO14nXq8M2es3l8 bnZzAgnlNO6iaNG8dZUfCxVtzGQIk7LmP08aymBYLKrVBRpBMA070wDeZbXvgFBJtc1e8tMHt8hE+ HKYHvfTAa1XJVyjEPdBJT4NVHQBbX1kiKr8XZxsNK7qVjLpfa5rJn2wsMYeuoqj24HR603rRzp0vx WeVqVWhCvy2IAjHVj0dFk4AEnkppQMzs3yUq0/1LQMyGb16wbeJ7NDcibUv1pgYG0IUANitDQPVCU kgDCgNuXOBRi7p5RKLqVnYBNBe/V6nNAB9yQWy0R4gQT+O6ZIiv44a76jalixKbA==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1qjFPm-00D3lb-0E; Thu, 21 Sep 2023 10:52:02 +0200 From: Johannes Berg To: linux-kernel@vger.kernel.org Cc: linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, Johannes Berg Subject: [RFC PATCH 2/4] net: dropreason: use new __print_sym() in tracing Date: Thu, 21 Sep 2023 10:51:32 +0200 Message-ID: <20230921105129.2f2774a87760.I075de1ac698b47710b94c631afdfb328f07be961@changeid> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921085129.261556-5-johannes@sipsolutions.net> References: <20230921085129.261556-5-johannes@sipsolutions.net> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:16:46 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777749911290218921 X-GMAIL-MSGID: 1777749911290218921 From: Johannes Berg The __print_symbolic() could only ever print the core drop reasons, since that's the way the infrastructure works. Now that we have __print_sym() with all the advantages mentioned in that commit, convert to that and get all the drop reasons from all subsystems. As we already have a list of them, that's really easy. This is a little bit of .text (~100 bytes in my build) and saves a lot of .data (~17k). Signed-off-by: Johannes Berg --- include/net/dropreason.h | 5 +++++ include/trace/events/skb.h | 16 +++----------- net/core/skbuff.c | 43 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/include/net/dropreason.h b/include/net/dropreason.h index 56cb7be92244..c157070b5303 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -42,6 +42,11 @@ struct drop_reason_list { extern const struct drop_reason_list __rcu * drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_NUM]; +#ifdef CONFIG_TRACEPOINTS +const char *drop_reason_lookup(unsigned long long value); +void drop_reason_show(struct seq_file *m); +#endif + void drop_reasons_register_subsys(enum skb_drop_reason_subsys subsys, const struct drop_reason_list *list); void drop_reasons_unregister_subsys(enum skb_drop_reason_subsys subsys); diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 07e0715628ec..8a1a63f9e796 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -8,15 +8,9 @@ #include #include #include +#include -#undef FN -#define FN(reason) TRACE_DEFINE_ENUM(SKB_DROP_REASON_##reason); -DEFINE_DROP_REASON(FN, FN) - -#undef FN -#undef FNe -#define FN(reason) { SKB_DROP_REASON_##reason, #reason }, -#define FNe(reason) { SKB_DROP_REASON_##reason, #reason } +TRACE_DEFINE_SYM_FNS(drop_reason, drop_reason_lookup, drop_reason_show); /* * Tracepoint for free an sk_buff: @@ -44,13 +38,9 @@ TRACE_EVENT(kfree_skb, TP_printk("skbaddr=%p protocol=%u location=%pS reason: %s", __entry->skbaddr, __entry->protocol, __entry->location, - __print_symbolic(__entry->reason, - DEFINE_DROP_REASON(FN, FNe))) + __print_sym(__entry->reason, drop_reason )) ); -#undef FN -#undef FNe - TRACE_EVENT(consume_skb, TP_PROTO(struct sk_buff *skb, void *location), diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 4eaf7ed0d1f4..415329b76921 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -132,6 +132,49 @@ drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_NUM] = { }; EXPORT_SYMBOL(drop_reasons_by_subsys); +#ifdef CONFIG_TRACEPOINTS +const char *drop_reason_lookup(unsigned long long value) +{ + unsigned long long subsys_id = value >> SKB_DROP_REASON_SUBSYS_SHIFT; + u32 reason = value & ~SKB_DROP_REASON_SUBSYS_MASK; + const struct drop_reason_list *subsys; + + if (subsys_id >= SKB_DROP_REASON_SUBSYS_NUM) + return NULL; + + subsys = rcu_dereference(drop_reasons_by_subsys[subsys_id]); + if (!subsys) + return NULL; + if (reason >= subsys->n_reasons) + return NULL; + return subsys->reasons[reason]; +} + +void drop_reason_show(struct seq_file *m) +{ + u32 subsys_id; + + rcu_read_lock(); + for (subsys_id = 0; subsys_id < SKB_DROP_REASON_SUBSYS_NUM; subsys_id++) { + const struct drop_reason_list *subsys; + u32 i; + + subsys = rcu_dereference(drop_reasons_by_subsys[subsys_id]); + if (!subsys) + continue; + + for (i = 0; i < subsys->n_reasons; i++) { + if (!subsys->reasons[i]) + continue; + seq_printf(m, ", { %u, \"%s\" }", + (subsys_id << SKB_DROP_REASON_SUBSYS_SHIFT) | i, + subsys->reasons[i]); + } + } + rcu_read_unlock(); +} +#endif + /** * drop_reasons_register_subsys - register another drop reason subsystem * @subsys: the subsystem to register, must not be the core From patchwork Thu Sep 21 08:51:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 142908 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5136569vqi; Thu, 21 Sep 2023 14:03:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdQpXzUv94EGrvvOKblKD+rzLqa4O1i/E5iWQdB+eA56GgVGgoe5/GLvdt3a1DfTUSkbOf X-Received: by 2002:a05:6a20:ce87:b0:135:8a04:9045 with SMTP id if7-20020a056a20ce8700b001358a049045mr5349187pzb.1.1695330182922; Thu, 21 Sep 2023 14:03:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695330182; cv=none; d=google.com; s=arc-20160816; b=TaHQFloiZfpILOKR1utfvmIc2C6EqywmU7IXIezOCuOpGA+xBgWsb6dgwoh8xYuizJ SsJaztgTLZCOn6eH/JH+SdULLI/NPjrN0AHHpIU5Uyat66kyfZ3dsYkogW9thZ00P9pm IglNInUskUxd85B/pu1zvt+yqalRIhQsbmizy4BkPqDIrxeEXocnoZelAEBm4hEMv8gg E/VfuLsIXfnIc/eJXMn7zuPCaSrLZIYHysb+SrpGUH3Oiekr4fT3qjOLR5wGUNeKg14p FVU8Z1m5XYZdKIFoOH/H0g/SHYatC9nnHW2vuHNRXiy5Pajd3x3o6qdg2tcmprSi6XLQ M+Pw== 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=+GqK9nIH4JMvkwqjWovkNfDPm8gLz4+0kcQHvxgQK7c=; fh=JN7tMyF6zC6ERZ5PXsr4V7IKiYp4vRUwR5tQFwkRxbI=; b=ySg+HQePcV41WQ/wPEfcjByyFCQfOUiQvWyG4ADivLNOvD1VGdbUIAx8Fp0ZfbWntT nWPx1YnpFq3ooKVwzRGv7z7o9OuC39R9L06Gt2xV1yui6EwG3KX7gHbsxW8AvS3d3vxC pqp6TC29LsEWFMWlV/MMuOraq3khEPuKLtKe+tn8u9ortN+NVSyGrzO6WYHQm/CIdzkk NDVqJKxIeoiaAfMIN8f6Z+W45xD9IZXBXpUfGrsyQe3FbZ08J8RhBFO5cs2XR2S6+Ptb Nd2gmJ4ciCDUeJ7isCNcwQlkJQ3i5ItlPtKgvmAjSywhGPHzGvstpn+6IA7zG1l571rG mDMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=hfLzyQE+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id u5-20020a656705000000b005680cb68678si2101586pgf.446.2023.09.21.14.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 14:03:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=hfLzyQE+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 98588829FDE3; Thu, 21 Sep 2023 10:52:05 -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 S230163AbjIURvy (ORCPT + 29 others); Thu, 21 Sep 2023 13:51:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229936AbjIURv1 (ORCPT ); Thu, 21 Sep 2023 13:51:27 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:242:246e::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64E3E6A4F; Thu, 21 Sep 2023 10:09:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=+GqK9nIH4JMvkwqjWovkNfDPm8gLz4+0kcQHvxgQK7c=; t=1695316173; x=1696525773; b=hfLzyQE+WLIlacNFWoSUHIDtrcbN7yLr/2lefzwXQS+b9/D vT6FHChv0AaYBFMryeKkr49rZFPJcG1O0qGyCql0ue/gMeJj0PJH+sM4s4PRQPDqeTUoqh1UasO6g EmhU3IgX/YfTrg6tJGPOlPS99UxOV9BQXi7/CUlEa/LRg5/laO6IwWfC/pdu4hLz6kFfhkaMJBdAN 2CDzoRlC3Z1ttsPOXOa0POfXIw12k1CNdOwMgRyPK30ju06siYlpLujGc4lOy3BwYbt+ihuUHWdV0 PoBY84MOxD+5bzRmJa5P6lRUzScr2hSAnOHsPcpfrSARAc0FGwbp1ggC52V1lmdg==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1qjFPn-00D3lb-1V; Thu, 21 Sep 2023 10:52:03 +0200 From: Johannes Berg To: linux-kernel@vger.kernel.org Cc: linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, Johannes Berg Subject: [RFC PATCH 3/4] net: drop_monitor: use drop_reason_lookup() Date: Thu, 21 Sep 2023 10:51:33 +0200 Message-ID: <20230921105129.c6e7e803398d.Idc122c3395bea9652f34ccaa678e918bfd4fae75@changeid> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921085129.261556-5-johannes@sipsolutions.net> References: <20230921085129.261556-5-johannes@sipsolutions.net> MIME-Version: 1.0 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]); Thu, 21 Sep 2023 10:52:05 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777682541947224336 X-GMAIL-MSGID: 1777682541947224336 From: Johannes Berg Now that we have drop_reason_lookup(), we can just use it for drop_monitor as well, rather than exporting the list itself. Signed-off-by: Johannes Berg --- include/net/dropreason.h | 4 ---- net/core/drop_monitor.c | 18 +++--------------- net/core/skbuff.c | 6 +++--- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/include/net/dropreason.h b/include/net/dropreason.h index c157070b5303..0e2195ccf2cd 100644 --- a/include/net/dropreason.h +++ b/include/net/dropreason.h @@ -38,10 +38,6 @@ struct drop_reason_list { size_t n_reasons; }; -/* Note: due to dynamic registrations, access must be under RCU */ -extern const struct drop_reason_list __rcu * -drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_NUM]; - #ifdef CONFIG_TRACEPOINTS const char *drop_reason_lookup(unsigned long long value); void drop_reason_show(struct seq_file *m); diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c index aff31cd944c2..d110a16cde46 100644 --- a/net/core/drop_monitor.c +++ b/net/core/drop_monitor.c @@ -610,9 +610,8 @@ static int net_dm_packet_report_fill(struct sk_buff *msg, struct sk_buff *skb, size_t payload_len) { struct net_dm_skb_cb *cb = NET_DM_SKB_CB(skb); - const struct drop_reason_list *list = NULL; - unsigned int subsys, subsys_reason; char buf[NET_DM_MAX_SYMBOL_LEN]; + const char *reason_str; struct nlattr *attr; void *hdr; int rc; @@ -630,19 +629,8 @@ static int net_dm_packet_report_fill(struct sk_buff *msg, struct sk_buff *skb, goto nla_put_failure; rcu_read_lock(); - subsys = u32_get_bits(cb->reason, SKB_DROP_REASON_SUBSYS_MASK); - if (subsys < SKB_DROP_REASON_SUBSYS_NUM) - list = rcu_dereference(drop_reasons_by_subsys[subsys]); - subsys_reason = cb->reason & ~SKB_DROP_REASON_SUBSYS_MASK; - if (!list || - subsys_reason >= list->n_reasons || - !list->reasons[subsys_reason] || - strlen(list->reasons[subsys_reason]) > NET_DM_MAX_REASON_LEN) { - list = rcu_dereference(drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_CORE]); - subsys_reason = SKB_DROP_REASON_NOT_SPECIFIED; - } - if (nla_put_string(msg, NET_DM_ATTR_REASON, - list->reasons[subsys_reason])) { + reason_str = drop_reason_lookup(cb->reason); + if (nla_put_string(msg, NET_DM_ATTR_REASON, reason_str)) { rcu_read_unlock(); goto nla_put_failure; } diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 415329b76921..9efde769949d 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -126,13 +126,11 @@ static const struct drop_reason_list drop_reasons_core = { .n_reasons = ARRAY_SIZE(drop_reasons), }; -const struct drop_reason_list __rcu * +static const struct drop_reason_list __rcu * drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_NUM] = { [SKB_DROP_REASON_SUBSYS_CORE] = RCU_INITIALIZER(&drop_reasons_core), }; -EXPORT_SYMBOL(drop_reasons_by_subsys); -#ifdef CONFIG_TRACEPOINTS const char *drop_reason_lookup(unsigned long long value) { unsigned long long subsys_id = value >> SKB_DROP_REASON_SUBSYS_SHIFT; @@ -149,7 +147,9 @@ const char *drop_reason_lookup(unsigned long long value) return NULL; return subsys->reasons[reason]; } +EXPORT_SYMBOL(drop_reason_lookup); +#ifdef CONFIG_TRACEPOINTS void drop_reason_show(struct seq_file *m) { u32 subsys_id; From patchwork Thu Sep 21 08:51:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 143041 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5237799vqi; Thu, 21 Sep 2023 17:46:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMfv5tp/pzMEigqRJICfjx5Fn/RI1z7BstOPNeZzNMsOx4oAH9r7Adliio+877QsOjKEmh X-Received: by 2002:a17:90a:e512:b0:26b:56fa:87d3 with SMTP id t18-20020a17090ae51200b0026b56fa87d3mr6745376pjy.31.1695343617135; Thu, 21 Sep 2023 17:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695343617; cv=none; d=google.com; s=arc-20160816; b=tue/IetuFHkZ9epub3YLuu7qcIH+hTiODtKfoQlIgrPea3qk/J93SODStgAmH7sPNA gqShPN/WqS/e4u7dbFY9V6R01UgP7lw/BI5PFB8d/1PQoHMbdsL9Lzd/i5ciDlwItF32 RHe2C+Mydp09oHixMX+BklhkmWSU717AiTHpjI30cDQWHkySsLGlwVD8r1WIDiHHxJmD 1Cb1E2Zizs8gj5F5vQYOnM4BWw3Gt3fEG7vDdziIlHoCqSZvqXbiVrvnsoABXLyFjQ33 k9XPu4Atga7JCjwMGRbl2nthWV+n/wl/q1TDaHpqvwyYcJWien2Fa6QArhCESN+uMXOE Bzlg== 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=nqDTsSYtIrtsgJfRZxQSmVfUy4UI0fM8vU1yAMBIetU=; fh=JN7tMyF6zC6ERZ5PXsr4V7IKiYp4vRUwR5tQFwkRxbI=; b=P7t+57kK5fwnpo2QlFB8HmSXln7Ajauih4cQutGXMJEHu0xQ/HHnKzEk2h3CCGMlQC fwMlOTvO+Q2tvjQbcZA5XDX1tz9LWrJMYE4ZzBMNI+p7LPskFVP4rnw48fSMw+iKWjRj qmcM/Va25aFHhbPPxi+Keu5SJSFuspUz1X5JIRrdAUq430mANW4EK/15MvC/53f2y6dX ot7rF6OtujEXYsXc6x0wNKSy9zL6qNjbjsbLIftYksEg8L1/vmK+EfOYR+F1sAzUfoXg abDHFM0ux9DuOz9ewwR43822Dx5kODZ+1j4KEPJgQqMMLQFQsCdr9J47FKBP3wh7fkmt OpCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=EXKAgTuP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id h13-20020a17090acf0d00b00263fa42fdcbsi4983893pju.107.2023.09.21.17.46.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 17:46:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=EXKAgTuP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 5E3F080A7CF0; Thu, 21 Sep 2023 15:30:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231752AbjIUWab (ORCPT + 29 others); Thu, 21 Sep 2023 18:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232329AbjIUWaY (ORCPT ); Thu, 21 Sep 2023 18:30:24 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:242:246e::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3F4465A5; Thu, 21 Sep 2023 10:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=nqDTsSYtIrtsgJfRZxQSmVfUy4UI0fM8vU1yAMBIetU=; t=1695316163; x=1696525763; b=EXKAgTuPVVfy8ylWiMVnePM2S25FQbqLGHAhT1vpoj7XbtN noPgP9Jg0aEsCyUWzDGafbS9LhYXtZGmWlZIHEcZ5/9Hl2KjA4Jez+eevbJN0LyTUwZyaJ2h/dFv5 nUADlD6Z2jmONDwwQ8LGjyibG8/cSVRhcY925jJ0P8uCjkIcSt7GeuD/wen370bqujHA+uGuKFFkj lmki8Q/Vl8R7xDOJxOwFmgGXlbDxpvhyFLAJauCE6D1i/0sf9THBR/UJz4b/qdU1ZHYh6F6Czc2gE OmP0MD0ktlF4pyiL4bhjTWW8EiPtkJVX4+5BsSpAvxGYWkvxkjH0637rQA7vGoxg==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1qjFPo-00D3lb-0V; Thu, 21 Sep 2023 10:52:04 +0200 From: Johannes Berg To: linux-kernel@vger.kernel.org Cc: linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, Johannes Berg Subject: [RFC PATCH 4/4] tracing/timer: use __print_sym() Date: Thu, 21 Sep 2023 10:51:34 +0200 Message-ID: <20230921105129.e76b17c18447.I5e112e423a69704fa05db74a05a6ebaad45d4f6e@changeid> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230921085129.261556-5-johannes@sipsolutions.net> References: <20230921085129.261556-5-johannes@sipsolutions.net> MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 21 Sep 2023 15:30:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777696628610595045 X-GMAIL-MSGID: 1777696628610595045 From: Johannes Berg Use the new __print_sym() in the timer tracing, just to show how to convert something. This adds ~80 bytes of .text for a saving of ~1.5K of data in my builds. Note the format changes from print fmt: "success=%d dependency=%s", REC->success, __print_symbolic(REC->dependency, { 0, "NONE" }, { (1 << 0), "POSIX_TIMER" }, { (1 << 1), "PERF_EVENTS" }, { (1 << 2), "SCHED" }, { (1 << 3), "CLOCK_UNSTABLE" }, { (1 << 4), "RCU" }, { (1 << 5), "RCU_EXP" }) to print fmt: "success=%d dependency=%s", REC->success, __print_symbolic(REC->dependency, { 0, "NONE" }, { 1, "POSIX_TIMER" }, { 2, "PERF_EVENTS" }, { 4, "SCHED" }, { 8, "CLOCK_UNSTABLE" }, { 16, "RCU" }, { 32, "RCU_EXP" }) Since the values are now just printed in the show function as pure decimal values. Signed-off-by: Johannes Berg --- include/trace/events/timer.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/include/trace/events/timer.h b/include/trace/events/timer.h index b4bc2828fa09..cb8294da29d0 100644 --- a/include/trace/events/timer.h +++ b/include/trace/events/timer.h @@ -382,26 +382,18 @@ TRACE_EVENT(itimer_expire, #undef tick_dep_mask_name #undef tick_dep_name_end -/* The MASK will convert to their bits and they need to be processed too */ -#define tick_dep_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \ - TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep); -#define tick_dep_name_end(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \ - TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep); -/* NONE only has a mask defined for it */ -#define tick_dep_mask_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep); - -TICK_DEP_NAMES - -#undef tick_dep_name -#undef tick_dep_mask_name -#undef tick_dep_name_end - #define tick_dep_name(sdep) { TICK_DEP_MASK_##sdep, #sdep }, #define tick_dep_mask_name(sdep) { TICK_DEP_MASK_##sdep, #sdep }, #define tick_dep_name_end(sdep) { TICK_DEP_MASK_##sdep, #sdep } +TRACE_DEFINE_SYM_LIST(tick_dep_names, TICK_DEP_NAMES); + +#undef tick_dep_name +#undef tick_dep_mask_name +#undef tick_dep_name_end + #define show_tick_dep_name(val) \ - __print_symbolic(val, TICK_DEP_NAMES) + __print_sym(val, tick_dep_names) TRACE_EVENT(tick_stop,