RE: ftrace histogram sorting broken on BE architecures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Steven Rostedt
> Sent: 16 December 2019 16:06
> On Mon, 16 Dec 2019 15:47:12 +0000
> David Laight <David.Laight@xxxxxxxxxx> wrote:
> 
> > > From: Tom Zanussi
> > > Sent: 12 December 2019 19:17
> > > On Wed, 2019-12-11 at 11:09 -0500, Steven Rostedt wrote:
> > > > On Wed, 11 Dec 2019 10:35:57 -0500
> > > > Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> > > >
> > > > > > Any thoughts on how to fix this? I'm not sure whether i fully
> > > > > > understand the
> > > > > > ftrace maps... ;-)
> > > > >
> > > > > Your analysis makes sense. I'll take a deeper look at it.
> > > >
> > > > Sven,
> > > >
> > > > Does this patch fix it for you?
> > > >
> > > > Tom,
> > > >
> > > > Correct me if I'm wrong, from what I can tell, all sums and keys are
> > > > u64 unless they are a string. Thus, I believe this patch should not
> > > > have any issues.
> > ...
> > > > --- a/kernel/trace/tracing_map.c
> > > > +++ b/kernel/trace/tracing_map.c
> > > > @@ -148,8 +148,8 @@ static int tracing_map_cmp_atomic64(void *val_a,
> > > > void *val_b)
> > > >  #define DEFINE_TRACING_MAP_CMP_FN(type) 	\
> > > >  static int tracing_map_cmp_##type(void *val_a, void *val_b) \
> > > >  { \
> > > > -	type a = *(type *)val_a; \
> > > > -	type b = *(type *)val_b; \
> > > > +	type a = (type)(*(u64 *)val_a); 	\
> > > > +	type b = (type)(*(u64 *)val_b); 	\
> > > > \
> > > >  	return (a > b) ? 1 : ((a < b) ? -1 : 0); \
> > > >  }
> >
> > That looks so horrid/wrong it can't be right on both BE and LE.
> 
> Well, the original is obviously not right for both BE and LE, but the
> fix is:
> 
> 	type a = (type)(*(u64 *)val_a);
> 
> Which breaks down to:
> 
> 		(u64 *)val_a - make val_a a pointer to a u64 number
> 
> all values were written as u64.
> 
> 	u64 data = (u64)original_val_a
> 
> Where original_val_a could be a byte, short, int, long or long long.

I'd sort of guessed that, but then the pointer type passed to tracing_map_cmp_##type()
will always be 'u64 *' (since the field the address is taken of must be that type).
Then the (u64 *) casts are no longer needed.

Possibly you can just pass the u64 values to:
tracing_map_cmp_##type(type a, type b)
{
	return a > b ? 1 : a < b ? -1 : 0;
}

The high bit masking and sign extension is then implicit in the call.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux