Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1543578

Re: Allow tracepoints to use direct indexing for number->string translation

Path csiph.com!news.redatomik.org!aioe.org!bofh.it!news.nic.it!robomod
From Steven Rostedt <rostedt@goodmis.org>
Newsgroups linux.kernel
Subject Re: Allow tracepoints to use direct indexing for number->string translation
Date Fri, 16 Dec 2016 17:40:01 +0100
Message-ID <sP3I5-65D-7@gated-at.bofh.it> (permalink)
References <sP2sG-5nI-19@gated-at.bofh.it> <sOIaC-cX-35@gated-at.bofh.it> <sLFLX-65b-1@gated-at.bofh.it> <sOZl7-36c-13@gated-at.bofh.it> <sP3yq-61M-13@gated-at.bofh.it>
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
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 robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 148
Organization linux.* mail to news gateway
X-Original-Cc Christian König <deathsimple@vodafone.de>, LKML <linux-kernel@vger.kernel.org>, Alex Deucher <alexander.deucher@amd.com>
X-Original-Date Fri, 16 Dec 2016 11:37:39 -0500
X-Original-Message-ID <20161216113739.5b5a4a5e@gandalf.local.home>
X-Original-References <20161216100241.160a81b2@gandalf.local.home> <23920.1481823475@warthog.procyon.org.uk> <ad6fb376-4fa8-3001-8cc9-7e0a41393616@vodafone.de> <25916.1481889335@warthog.procyon.org.uk> <31530.1481905345@warthog.procyon.org.uk>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1543578

Show key headers only | View raw


On Fri, 16 Dec 2016 16:22:25 +0000
David Howells <dhowells@redhat.com> wrote:

> Steven Rostedt <rostedt@goodmis.org> 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;

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Enabling trace points during module load/init David Howells <dhowells@redhat.com> - 2016-12-15 18:40 +0100
  Allow tracepoints to use direct indexing for number->string translation David Howells <dhowells@redhat.com> - 2016-12-16 13:00 +0100
    Re: Allow tracepoints to use direct indexing for number->string  translation Steven Rostedt <rostedt@goodmis.org> - 2016-12-16 16:20 +0100
      Re: Allow tracepoints to use direct indexing for number->string translation David Howells <dhowells@redhat.com> - 2016-12-16 17:30 +0100
        Re: Allow tracepoints to use direct indexing for number->string  translation Steven Rostedt <rostedt@goodmis.org> - 2016-12-16 17:40 +0100
          Re: Allow tracepoints to use direct indexing for number->string translation David Howells <dhowells@redhat.com> - 2016-12-16 18:00 +0100

csiph-web