Re: [PATCH v2 2/4] perf util: Add host_is_bigendian to util.h

From: Arnaldo Carvalho de Melo
Date: Mon Dec 05 2022 - 08:17:11 EST


Em Wed, Nov 30, 2022 at 10:52:35AM -0800, Namhyung Kim escreveu:
> On Tue, Nov 29, 2022 at 10:30 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
> >
> > Avoid libtraceevent dependency for tep_is_bigendian or trace-event.h
> > dependency for bigendian. Add a new host_is_bigendian to util.h, using
> > the compiler defined __BYTE_ORDER__ when available.
> >
> > Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
>
> Acked-by: Namhyung Kim <namhyung@xxxxxxxxxx>
>
> A nit below...
>
> > ---
> [SNIP]
> > diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
> > index 63cdab0e5314..87d418cb6792 100644
> > --- a/tools/perf/util/util.h
> > +++ b/tools/perf/util/util.h
> > @@ -94,4 +94,23 @@ int do_realloc_array_as_needed(void **arr, size_t *arr_sz, size_t x,
> > 0; \
> > })
> >
> > +static inline bool host_is_bigendian(void)
> > +{
> > +#ifdef __BYTE_ORDER__
> > +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> > + return false;
> > +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> > + return true;
> > +#else
> > +#error "Unrecognized __BYTE_ORDER__"
> > +#endif
> > +#else
>
> It'd be nice if we could have a comment at least there's a nested
> ifdef condition. Like below?
>
> #else /* !__BYTE_ORDER__ */

Reasonable, added it and applied the first two patches in this series,
with your Acked-by, thanks.

- Arnaldo


diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 87d418cb67929576..a06c54ab85ee4506 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -104,7 +104,7 @@ static inline bool host_is_bigendian(void)
#else
#error "Unrecognized __BYTE_ORDER__"
#endif
-#else
+#else /* !__BYTE_ORDER__ */
unsigned char str[] = { 0x1, 0x2, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0};
unsigned int *ptr;