Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935042AbcLPQhw (ORCPT ); Fri, 16 Dec 2016 11:37:52 -0500 Received: from smtprelay0057.hostedemail.com ([216.40.44.57]:52087 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752528AbcLPQhn (ORCPT ); Fri, 16 Dec 2016 11:37:43 -0500 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::,RULES_HIT:2:41:355:379:541:560:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1593:1594:1605:1606:1730:1747:1777:1792:2194:2199:2393:2553:2559:2562:2898:3138:3139:3140:3141:3142:3622:3865:3866:3867:3871:3873:3874:4117:4321:5007:6261:7875:7903:10004:10394:10848:10967:11026:11232:11473:11658:11914:12043:12291:12296:12438:12555:12679:12683:12740:12760:12895:12986:13439:14659:21080:21324:21433:21434:21451:30029:30034:30054:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:3,LUA_SUMMARY:none X-HE-Tag: boats11_25f756d5d1d2f X-Filterd-Recvd-Size: 6440 Date: Fri, 16 Dec 2016 11:37:39 -0500 From: Steven Rostedt To: David Howells Cc: Christian =?UTF-8?B?S8O2bmln?= , LKML , Alex Deucher Subject: Re: Allow tracepoints to use direct indexing for number->string translation Message-ID: <20161216113739.5b5a4a5e@gandalf.local.home> In-Reply-To: <31530.1481905345@warthog.procyon.org.uk> References: <20161216100241.160a81b2@gandalf.local.home> <23920.1481823475@warthog.procyon.org.uk> <25916.1481889335@warthog.procyon.org.uk> <31530.1481905345@warthog.procyon.org.uk> X-Mailer: Claws Mail 3.14.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5194 Lines: 148 On Fri, 16 Dec 2016 16:22:25 +0000 David Howells wrote: > Steven Rostedt wrote: > > > > Another feature that would be very nice to have is the ability to turn a > > > number into a string by direct array index rather than by table search or > > > serial ?: ternary operators. > > > > Which function are you talking about? > > See the attached patch that converts rxrpc's tracing from using string arrays > to using TRACE_DEFINE_ENUM so that utilities like crash's trace buffer > disassembler can find the string values. > > When __print_symbolic() is used, each set of strings is rendered as an array > of trace_print_flag structs which trace_print_symbols_seq() then iterates > over to find a match. > You mean to do something like this? (untested, not even compiled) -- Steve --- include/linux/trace_events.h | 6 ++++-- include/trace/trace_events.h | 10 ++++++---- kernel/trace/trace_output.c | 28 ++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 10 deletions(-) Index: linux-trace.git/include/linux/trace_events.h =================================================================== --- linux-trace.git.orig/include/linux/trace_events.h 2016-11-15 17:27:19.397749523 -0500 +++ linux-trace.git/include/linux/trace_events.h 2016-12-16 11:34:38.783424430 -0500 @@ -20,13 +20,15 @@ const char *trace_print_flags_seq(struct const struct trace_print_flags *flag_array); const char *trace_print_symbols_seq(struct trace_seq *p, unsigned long val, - const struct trace_print_flags *symbol_array); + const struct trace_print_flags *symbol_array, + unsigned long nr); #if BITS_PER_LONG == 32 const char *trace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val, const struct trace_print_flags_u64 - *symbol_array); + *symbol_array, + unsigned long long nr); #endif const char *trace_print_bitmask_seq(struct trace_seq *p, void *bitmask_ptr, Index: linux-trace.git/include/trace/trace_events.h =================================================================== --- linux-trace.git.orig/include/trace/trace_events.h 2016-12-16 11:29:39.599950900 -0500 +++ linux-trace.git/include/trace/trace_events.h 2016-12-16 11:30:39.927844742 -0500 @@ -279,8 +279,9 @@ TRACE_MAKE_SYSTEM_STR(); #define __print_symbolic(value, symbol_array...) \ ({ \ static const struct trace_print_flags symbols[] = \ - { symbol_array, { -1, NULL }}; \ - trace_print_symbols_seq(p, value, symbols); \ + { symbol_array}}; \ + trace_print_symbols_seq(p, value, symbols, \ + ARRAY_SIZE(symbols)); \ }) #undef __print_symbolic_u64 @@ -288,8 +289,9 @@ TRACE_MAKE_SYSTEM_STR(); #define __print_symbolic_u64(value, symbol_array...) \ ({ \ static const struct trace_print_flags_u64 symbols[] = \ - { symbol_array, { -1, NULL } }; \ - trace_print_symbols_seq_u64(p, value, symbols); \ + { symbol_array }; \ + trace_print_symbols_seq_u64(p, value, symbols, \ + ARRAY_SIZE(symbols)); \ }) #else #define __print_symbolic_u64(value, symbol_array...) \ Index: linux-trace.git/kernel/trace/trace_output.c =================================================================== --- linux-trace.git.orig/kernel/trace/trace_output.c 2016-12-14 10:33:28.581929129 -0500 +++ linux-trace.git/kernel/trace/trace_output.c 2016-12-16 11:36:41.695208145 -0500 @@ -99,12 +99,21 @@ EXPORT_SYMBOL(trace_print_flags_seq); const char * trace_print_symbols_seq(struct trace_seq *p, unsigned long val, - const struct trace_print_flags *symbol_array) + const struct trace_print_flags *symbol_array, + unsigned long nr) { int i; const char *ret = trace_seq_buffer_ptr(p); - for (i = 0; symbol_array[i].name; i++) { + /* A lot of arrays are simply enums that map to the array index */ + if (val < nr) { + if (val == symbol_array[val].mask) { + trace_seq_puts(p, symbol_array[val].name); + goto out; + } + } + + for (i = 0; i < nr; i++) { if (val != symbol_array[i].mask) continue; @@ -116,6 +125,7 @@ trace_print_symbols_seq(struct trace_seq if (ret == (const char *)(trace_seq_buffer_ptr(p))) trace_seq_printf(p, "0x%lx", val); + out: trace_seq_putc(p, 0); return ret; @@ -125,12 +135,21 @@ EXPORT_SYMBOL(trace_print_symbols_seq); #if BITS_PER_LONG == 32 const char * trace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val, - const struct trace_print_flags_u64 *symbol_array) + const struct trace_print_flags_u64 *symbol_array, + unsigned long long nr) { int i; const char *ret = trace_seq_buffer_ptr(p); - for (i = 0; symbol_array[i].name; i++) { + /* A lot of arrays are simply enums that map to the array index */ + if (val < nr) { + if (val == symbol_array[val].mask) { + trace_seq_puts(p, symbol_array[val].name); + goto out; + } + } + + for (i = 0; i < nr; i++) { if (val != symbol_array[i].mask) continue; @@ -142,6 +161,7 @@ trace_print_symbols_seq_u64(struct trace if (ret == (const char *)(trace_seq_buffer_ptr(p))) trace_seq_printf(p, "0x%llx", val); + out: trace_seq_putc(p, 0); return ret;