[Sound-open-firmware] [PATCH] [RFC]rmbox: include trace class definitions from trace header

Ranjani Sridharan ranjani.sridharan at linux.intel.com
Thu May 17 19:48:19 CEST 2018


On Thu, 2018-05-17 at 15:23 +0100, Liam Girdwood wrote:
> On Mon, 2018-05-14 at 09:17 -0700, Ranjani Sridharan wrote:
> > This introduces a dependency on the sof headers being pre-installed
> > before building rmbox.
> > 
> > Signed-off-by: Ranjani Sridharan <ranjani.sridharan at linux.intel.com
> > >
> > Signed-off-by: Yan Wang <yan.wang at linux.intel.com>
> > ---
> >  rmbox/Makefile.am |  20 +++++-
> >  rmbox/rmbox.c     | 171 +++++++++++++++++++++++++++---------------
> > ----
> >  2 files changed, 121 insertions(+), 70 deletions(-)
> > 
> > diff --git a/rmbox/Makefile.am b/rmbox/Makefile.am
> > index bfeb184..9763361 100644
> > --- a/rmbox/Makefile.am
> > +++ b/rmbox/Makefile.am
> > @@ -1,4 +1,22 @@
> > +SOF_INC = $(prefix)/include/sof
> > +SOF_INC_NEW := $(subst /,_,$(SOF_INC))
> > +START_OLD =_binary_$(SOF_INC_NEW)_sof_trace_h_start
> > +END_OLD =_binary_$(SOF_INC_NEW)_sof_trace_h_end
> > +
> 
> 
> What's this for ? You can use AC_ macro in configure.ac to detect the
> presence
> of an installed header.

because the SOF headers wont be installed on the device that we run
rmbox on, I've bundled up the header in the executable. 
And the above definitions are to rename the symbols in the executable
to something like trace_start and trace_end to access the trace class
definitions from the header. 

I couldnt think of a way better way that including the trace header
object in the rmbox application.  Is this acceptable?
> 
> >  bin_PROGRAMS = rmbox
> >  
> >  rmbox_SOURCES = \
> > -	rmbox.c
> > \ No newline at end of file
> > +	rmbox.c
> > +
> > +rmbox_CFLAGS = \
> > +	-I $(SOF_INC)
> > +
> > +rmbox_LDADD = \
> > +	trace.o
> > +
> > +trace.o:
> > +	objcopy --input binary --output elf64-x86-64 \
> > +	--binary-architecture i386:x86-64 \
> > +	$(SOF_INC)/sof/trace.h trace.o
> > +	objcopy --redefine-sym $(START_OLD)=_trace_start trace.o
> > +	objcopy --redefine-sym $(END_OLD)=_trace_end trace.o
> > diff --git a/rmbox/rmbox.c b/rmbox/rmbox.c
> > index 4df2ee1..0281904 100644
> > --- a/rmbox/rmbox.c
> > +++ b/rmbox/rmbox.c
> > @@ -20,37 +20,109 @@
> >  #include <errno.h>
> >  #include <string.h>
> >  #include <ctype.h>
> > +#include <sof/trace.h>
> >  
> >  #define KNRM  "\x1B[0m"
> >  #define KRED  "\x1B[31m"
> >  
> > -// TODO: include all this stuff
> > -
> > -#define TRACE_CLASS_IRQ		(1 << 24)
> > -#define TRACE_CLASS_IPC		(2 << 24)
> > -#define TRACE_CLASS_PIPE	(3 << 24)
> > -#define TRACE_CLASS_HOST	(4 << 24)
> > -#define TRACE_CLASS_DAI		(5 << 24)
> > -#define TRACE_CLASS_DMA		(6 << 24)
> > -#define TRACE_CLASS_SSP		(7 << 24)
> > -#define TRACE_CLASS_COMP	(8 << 24)
> > -#define TRACE_CLASS_WAIT	(9 << 24)
> > -#define TRACE_CLASS_LOCK	(10 << 24)
> > -#define TRACE_CLASS_MEM		(11 << 24)
> > -#define TRACE_CLASS_MIXER	(12 << 24)
> > -#define TRACE_CLASS_BUFFER	(13 << 24)
> > -#define TRACE_CLASS_VOLUME	(14 << 24)
> > -#define TRACE_CLASS_SWITCH	(15 << 24)
> > -#define TRACE_CLASS_MUX		(16 << 24)
> > -#define TRACE_CLASS_SRC         (17 << 24)
> > -#define TRACE_CLASS_TONE        (18 << 24)
> > -#define TRACE_CLASS_EQ_FIR      (19 << 24)
> > -#define TRACE_CLASS_EQ_IIR      (20 << 24)
> > -
> > -#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
> > +#define TRACE_BLOCK_SIZE	8
> >  
> > +#define MAX_LINE_LEN	1024
> >  
> > -#define TRACE_BLOCK_SIZE	8
> > +struct trace_class_table {
> > +	int trace_class;
> > +	char *class_name;
> > +};
> > +
> > +struct trace_class_table *trace_table;
> > +int num_trace_classes;
> > +
> > +/* trace defines pointers */
> > +extern char _trace_start;
> > +extern char _trace_end;
> > +
> > +/* set up trace class identifier table based on trace.sh in sof */
> 
> trace.sh in another patch ?
> 
> Liam
> 
> > +static void setup_trace_table()
> > +{
> > +	char *token;
> > +	char line[MAX_LINE_LEN];
> > +	int ret, i = 0, j = 0;
> > +	char*  p = &_trace_start;
> > +
> > +	/* find out the number of trace class definitions from
> > trace header
> > */
> > +	while (p != &_trace_end) {
> > +		line[i++] = *p;
> > +
> > +		/* read until new line character */
> > +		if (*p == '\n') {
> > +			line[i-1] = '\0';
> > +			char identifier[MAX_LINE_LEN];
> > +			int value = 0, shift = 0;
> > +			ret = sscanf(line, "#define %s (%d <<
> > %d)",
> > identifier,
> > +				      &value, &shift);
> > +			if (ret == 3) {
> > +
> > +				/* if TRACE_CLASS definition */
> > +				if (strstr(identifier,
> > "TRACE_CLASS"))
> > +					j++;
> > +			}
> > +			i = 0;
> > +		}
> > +		p++;
> > +	}
> > +
> > +	num_trace_classes = j;
> > +
> > +	/* allocate memory for trace table */
> > +	trace_table = (struct trace_class_table
> > *)malloc(sizeof(struct
> > trace_class_table) * num_trace_classes);
> > +
> > +	i = 0;
> > +	j = 0;
> > +
> > +	/* rewind pointer */
> > +	p = &_trace_start;
> > +
> > +	/* begin reading trace header */
> > +	while (p != &_trace_end) {
> > +		line[i++] = *p;
> > +		if (*p == '\n') {
> > +			line[i-1] = '\0';
> > +			char identifier[MAX_LINE_LEN];
> > +			int value = 0, shift = 0;
> > +			ret = sscanf(line, "#define %s (%d <<
> > %d)",
> > identifier,
> > +				      &value, &shift);
> > +			if (ret == 3) {
> > +
> > +				/* if TRACE_CLASS definition */
> > +				if (strstr(identifier,
> > "TRACE_CLASS")) {
> > +					token = strtok(identifier,
> > "_");
> > +					token = strtok(NULL, "_");
> > +					token = strtok(NULL, "_");
> > +
> > +					/* add trace class entry
> > */
> > +					trace_table[j].trace_class
> > = value;
> > +					trace_table[j++].class_nam
> > e =
> > strdup(token);
> > +				}
> > +			}
> > +			i = 0;
> > +		}
> > +		p++;
> > +	}
> > +}
> > +
> > +/* look up subsystem class name from table */
> > +static char *get_trace_class(uint32_t trace_class)
> > +{
> > +	int i;
> > +
> > +	/* look up trace class table and return subsystem name */
> > +	for (i = 0; i < num_trace_classes; i++) {
> > +		if (trace_table[i].trace_class == trace_class)
> > +			return trace_table[i].class_name;
> > +	}
> > +
> > +	return "value";
> > +}
> >  
> >  static inline char get_char(uint32_t val, int idx)
> >  {
> > @@ -122,50 +194,9 @@ static void show_trace(uint64_t val, uint64_t
> > addr,
> > uint64_t *timestamp, double
> >  	}
> >  
> >  	class = val & 0xff000000;
> > -	if (class == TRACE_CLASS_IRQ)
> > -		trace = "irq";
> > -	else if (class == TRACE_CLASS_IPC)
> > -		trace = "ipc";
> > -	else if (class == TRACE_CLASS_PIPE)
> > -		trace = "pipe";
> > -	else if (class == TRACE_CLASS_HOST)
> > -		trace = "host";
> > -	else if (class == TRACE_CLASS_DAI)
> > -		trace = "dai";
> > -	else if (class == TRACE_CLASS_DMA)
> > -		trace = "dma";
> > -	else if (class == TRACE_CLASS_SSP)
> > -		trace = "ssp";
> > -	else if (class == TRACE_CLASS_COMP)
> > -		trace = "comp";
> > -	else if (class == TRACE_CLASS_WAIT)
> > -		trace = "wait";
> > -	else if (class == TRACE_CLASS_LOCK)
> > -		trace = "lock";
> > -	else if (class == TRACE_CLASS_MEM)
> > -		trace = "mem";
> > -	else if (class == TRACE_CLASS_MIXER)
> > -		trace = "mixer";
> > -	else if (class == TRACE_CLASS_BUFFER)
> > -		trace = "buffer";
> > -	else if (class == TRACE_CLASS_VOLUME)
> > -		trace = "volume";
> > -	else if (class == TRACE_CLASS_SWITCH)
> > -		trace = "switch";
> > -	else if (class == TRACE_CLASS_MUX)
> > -		trace = "mux";
> > -	else if (class == TRACE_CLASS_SRC)
> > -		trace = "src";
> > -	else if (class == TRACE_CLASS_TONE)
> > -		trace = "tone";
> > -	else if (class == TRACE_CLASS_EQ_FIR)
> > -		trace = "eq-fir";
> > -	else if (class == TRACE_CLASS_EQ_IIR)
> > -		trace = "eq-iir";
> > -	else {
> > -		printf("value 0x%8.8x\n", (uint32_t)val);
> > -		return;
> > -	}
> > +	
> > +	/* look up trace subsystem from table */
> > +	trace = strdup(get_trace_class(class >> 24));
> >  
> >  	switch ((char)(val >> 16)) {
> >  	case 'e':
> > @@ -343,6 +374,8 @@ int main(int argc, char *argv[])
> >  		}
> >  	}
> >  
> > +	setup_trace_table();
> > +
> >  	/* trace requested ? */
> >  	if (trace)
> >  		return trace_read("/sys/kernel/debug/sof/trace",


More information about the Sound-open-firmware mailing list