Re: [PATCH v2] perf tool: fix endianness handling of u32 data in samples

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


Em Fri, Sep 02, 2011 at 01:12:30PM -0600, David Ahern escreveu:
> On 09/02/2011 12:18 PM, Arnaldo Carvalho de Melo wrote:
> > Em Fri, Sep 02, 2011 at 10:03:46AM -0600, David Ahern escreveu:
> >>  	if (type & PERF_SAMPLE_RAW) {
> >> -		u32 *p = (u32 *)array;
> >> +		u.val64 = *array;
> >> +		if (swapped) {
> >> +			static bool show_warn = true;
> >> +
> >> +			/* undo swap of u64, then swap on individual u32s */
> >> +			u.val64 = bswap_64(u.val64);
> >> +			u.val32[0] = bswap_32(u.val32[0]);
> >> +			u.val32[1] = bswap_32(u.val32[1]);
> >> +
> >> +			if (show_warn) {
> >> +				pr_warning("Endianness of raw data not corrected!\n");
> >> +				show_warn = false;
> >> +			}
> >> +		}
> > 
> > Can you use WARN_ONCE? Would become:
> > 	
> > 		if (WARN_ONCE(swapped, "Endianness of raw data not corrected!\n")) {
> > 			/* undo swap of u64, then swap on individual u32s */
> > 			u.val64 = bswap_64(u.val64);
> > 			u.val32[0] = bswap_32(u.val32[0]);
> > 			u.val32[1] = bswap_32(u.val32[1]);
> > 		}
> 
> That's not quite what we need. The bswap's happen all the time; the warn
> once is to tell the user one time that samples in the file contain raw
> data and those cannot be programmatically adjusted for endianness.
> 
> ie., more like:
>     WARN_ONCE(swapped, "Endianness of raw data not corrected!\n");
> and no action taken (the 'if (WARN_ONCE())'part).

Look again:

#define WARN_ONCE(condition, format...) ({                      \
        static bool __warned;                                   \
        int __ret_warn_once = !!(condition);                    \
                                                                \
        if (unlikely(__ret_warn_once))                          \
                if (WARN(!__warned, format))                    \
                        __warned = true;                        \
        unlikely(__ret_warn_once);                              \
}) 


See that ({ }) construct? It evaluates to what is in its last statement,
which is...

	unlikely(__ret_warn_once);

Forget about the unlikely, __ret_warn_once is:

	!!condition

I.e. it always evaluates to what is passed as condition, so in fact it
could be seen as:

             if (swapped) {
                     /* undo swap of u64, then swap on individual
                     u32s */
                     u.val64 = bswap_64(u.val64);
                     u.val32[0] = bswap_32(u.val32[0]);
                     u.val32[1] = bswap_32(u.val32[1]);
             }

The rest is the boilerplate needed to warn the user the first time
condition is true.

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Free Online Dating]     [Linux Kernel]     [Linux SCSI]     [XFree86]

Add to Google Powered by Linux