From: David Laight <david.laight.linux@gmail.com>
To: Ian Rogers <irogers@google.com>
Cc: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
Namhyung Kim <namhyung@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Jiri Olsa <jolsa@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 1/1] perf tests hwmon_pmu: Use PRIu64 + (u64) cast for a __u64 field to work more widely
Date: Thu, 28 May 2026 21:40:43 +0100 [thread overview]
Message-ID: <20260528214043.58afaa56@pumpkin> (raw)
In-Reply-To: <CAP-5=fUGaDGhvBU6z9hAuqFr5hpO9S-TKcW6bhwvjoA4j+xBRg@mail.gmail.com>
On Thu, 28 May 2026 12:55:45 -0700
Ian Rogers <irogers@google.com> wrote:
> On Thu, May 28, 2026 at 12:53 PM Arnaldo Carvalho de Melo
> <arnaldo.melo@gmail.com> wrote:
> >
> > While testing perf with an updated Debian experimental cross compiler
> > (gcc version 14.2.0 (Debian 14.2.0-13)) this started failing:
> >
> > In file included from tests/hwmon_pmu.c:12:
> > tests/hwmon_pmu.c: In function 'do_test':
> > tests/hwmon_pmu.c:199:34: error: format '%lld' expects argument of type 'long long int', but argument 7 has type '__u64' {aka 'long unsigned int'} [-Werror=format=]
> > 199 | pr_debug("FAILED %s:%d Unexpected config for '%s', %lld != %ld\n",
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > /git/perf-7.1.0-rc5/tools/perf/util/debug.h:20:21: note: in definition of macro 'pr_fmt'
> > 20 | #define pr_fmt(fmt) fmt
> > | ^~~
> > tests/hwmon_pmu.c:199:25: note: in expansion of macro 'pr_debug'
> > 199 | pr_debug("FAILED %s:%d Unexpected config for '%s', %lld != %ld\n",
> > | ^~~~~~~~
> > tests/hwmon_pmu.c:199:79: note: format string is defined here
> > 199 | pr_debug("FAILED %s:%d Unexpected config for '%s', %lld != %ld\n",
> > | ~~~^
> > | |
> > | long long int
> > | %ld
> > LD /tmp/build/perf/util/intel-pt-decoder/perf-util-in.o
> >
> > The usual make that %lld a PRIu64 (since arg7 is
> > evsel->core.attr.config, which is a __u64) but then on Fedora 44 (gcc
> > version 16.1.1 20260515 (Red Hat 16.1.1-2)) it ends up with:
> >
> > In file included from tests/hwmon_pmu.c:13:
> > tests/hwmon_pmu.c: In function ‘do_test’:
> > tests/hwmon_pmu.c:200:34: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 7 has type ‘__u64’ {aka ‘long long unsigned int’} [-Werror=format=]
> > 200 | pr_debug("FAILED %s:%d Unexpected config for '%s', %" PRIu64 " != %ld\n",
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > /home/acme/git/perf-tools-next2/tools/perf/util/debug.h:20:21: note: in definition of macro ‘pr_fmt’
> > 20 | #define pr_fmt(fmt) fmt
> > | ^~~
> > tests/hwmon_pmu.c:200:25: note: in expansion of macro ‘pr_debug’
> > 200 | pr_debug("FAILED %s:%d Unexpected config for '%s', %" PRIu64 " != %ld\n",
> > | ^~~~~~~~
> > cc1: all warnings being treated as errors
> >
> > So the way to satisfy both compilers is to also add a (u64) cast to
> > arg7.
>
> As the inttypes.h definitions match stdint.h would it make more sense
> to use uint64_t for the cast?
Or use (unsigned long long) and "%lld".
Using PRIu64 and a cast is the worst of both worlds.
Where does the definition of __u64 come from?
#define __u64 @@
at the top of a file might give a clue.
I thought it was a Linux kernel type matching u64 - which is always 'unsigned long long'.
-- David
>
> Thanks,
> Ian
>
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > ---
> > tools/perf/tests/hwmon_pmu.c | 5 +++--
> > 1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/perf/tests/hwmon_pmu.c b/tools/perf/tests/hwmon_pmu.c
> > index ada6e445c4c41e1b..870d59c0f7cba2e7 100644
> > --- a/tools/perf/tests/hwmon_pmu.c
> > +++ b/tools/perf/tests/hwmon_pmu.c
> > @@ -2,6 +2,7 @@
> > #include "hwmon_pmu.h"
> >
> > #include <errno.h>
> > +#include <inttypes.h>
> >
> > #include <fcntl.h>
> > #include <linux/compiler.h>
> > @@ -196,9 +197,9 @@ static int do_test(size_t i, bool with_pmu, bool with_alias)
> > continue;
> >
> > if (evsel->core.attr.config != (u64)test_events[i].key.type_and_num) {
> > - pr_debug("FAILED %s:%d Unexpected config for '%s', %lld != %ld\n",
> > + pr_debug("FAILED %s:%d Unexpected config for '%s', %" PRIu64 " != %ld\n",
> > __FILE__, __LINE__, str,
> > - evsel->core.attr.config,
> > + (u64)evsel->core.attr.config,
> > test_events[i].key.type_and_num);
> > ret = TEST_FAIL;
> > goto out;
> > --
> > 2.54.0
> >
>
prev parent reply other threads:[~2026-05-28 20:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-28 19:52 [PATCH 1/1] perf tests hwmon_pmu: Use PRIu64 + (u64) cast for a __u64 field to work more widely Arnaldo Carvalho de Melo
2026-05-28 19:55 ` Ian Rogers
2026-05-28 20:40 ` David Laight [this message]
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=20260528214043.58afaa56@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=adrian.hunter@intel.com \
--cc=arnaldo.melo@gmail.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox