From: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
To: David Ahern <dsahern@gmail.com>
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
mingo@elte.hu, peterz@infradead.org, fweisbec@gmail.com,
paulus@samba.org, tglx@linutronix.de, anton@samba.org
Subject: Re: [PATCH v2] perf tool: fix endianness handling of u32 data in samples
Date: Fri, 2 Sep 2011 17:01:47 -0300 [thread overview]
Message-ID: <20110902200147.GF17970@ghostprotocols.net> (raw)
In-Reply-To: <4E612A9E.5000807@gmail.com>
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
next prev parent reply other threads:[~2011-09-02 20:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-02 16:03 [PATCH v2] perf tool: fix endianness handling of u32 data in samples David Ahern
2011-09-02 18:18 ` Arnaldo Carvalho de Melo
2011-09-02 19:12 ` David Ahern
2011-09-02 20:01 ` Arnaldo Carvalho de Melo [this message]
2011-09-02 20:08 ` David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110902200147.GF17970@ghostprotocols.net \
--to=acme@ghostprotocols.net \
--cc=anton@samba.org \
--cc=dsahern@gmail.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.