perf jevents: Enable build warnings
cover perf jevents: Enable build warnings
Currently jevents builds without any complier warning flags enabled. So use newly-defined HOSTCFLAGS, which comes from EXTRA_WARNINGS. I am not 100% confident that this is the best way, but sending out for review.
Baseline is be8ecc57f180 (HEAD, acme/perf/core) perf srcline: Use long-running addr2line per DSO
Thanks!
John Garry (2):
perf jevents: Fix some would-be warnings perf jevents: Enable warnings through HOSTCFLAGS
tools/perf/Makefile.config | 1 + tools/perf/Makefile.perf | 2 +- tools/perf/pmu-events/Build | 2 +- tools/perf/pmu-events/jevents.c | 10 ++++------ 4 files changed, 7 insertions(+), 8 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/2 perf jevents: Fix some would-be warnings
Before enabling warnings through HOSTCFLAGS, fix the would-be warnings:
HOSTCC pmu-events/jevents.opmu-events/jevents.c:74:22: warning: no previous prototype for ‘convert’ [-Wmissing-prototypes]
74 | enum aggr_mode_class convert(const char *aggr_mode)
| ^~~~~~~
pmu-events/jevents.c: In function ‘print_events_table_entry’:
pmu-events/jevents.c:373:8: warning: declaration of ‘topic’ shadows a global declaration [-Wshadow]
373 | char *topic = pd->topic;
| ^~~~~
pmu-events/jevents.c:316:14: note: shadowed declaration is here
316 | static char *topic;
| ^~~~~
pmu-events/jevents.c: In function ‘json_events’:
pmu-events/jevents.c:554:9: warning: declaration of ‘func’ shadows a global declaration [-Wshadow]
554 | int (*func)(void *data, struct json_event *je),
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~pmu-events/jevents.c:85:15: note: shadowed declaration is here
85 | typedef int (*func)(void *data, struct json_event *je);
| ^~~~pmu-events/jevents.c: In function ‘main’:pmu-events/jevents.c:1211:25: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
1211 | char *err_string_ext = "";
| ^~pmu-events/jevents.c:1304:17: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
1304 | err_string_ext = " for std arch event";
| ^
--- tools/perf/pmu-events/jevents.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
tools/perf/pmu-events/jevents.c +4 -6
@@ -71,7 +71,7 @@ struct json_event {char *metric_constraint; }; -enum aggr_mode_class convert (const char *aggr_mode) +static enum aggr_mode_class convert (const char *aggr_mode) {if (!strcmp (aggr_mode,"PerCore" ))return PerCore;
@@ -82,8 +82,6 @@ enum aggr_mode_class convert(const char *aggr_mode)return -1 ; } -typedef int (*func )(void *data,struct json_event *je); -static LIST_HEAD (sys_event_tables);struct sys_event_table {
@@ -370,7 +368,7 @@ static int print_events_table_entry(void *data, struct json_event *je) {struct perf_entry_data *pd = data;FILE *outfp = pd->outfp; -char *topic = pd->topic; +char *topic_local = pd->topic;/* * TODO: Remove formatting chars after debugging to reduce
@@ -385,7 +383,7 @@ static int print_events_table_entry(void *data, struct json_event *je)fprintf (outfp,"\t.desc = \"%s\",\n" , je->desc);if (je->compat)fprintf (outfp,"\t.compat = \"%s\",\n" , je->compat); -fprintf (outfp,"\t.topic = \"%s\",\n" , topic); +fprintf (outfp,"\t.topic = \"%s\",\n" , topic_local);if (je->long_desc && je->long_desc[0 ])fprintf (outfp,"\t.long_desc = \"%s\",\n" , je->long_desc);if (je->pmu)
@@ -1208,7 +1206,7 @@ int main(int argc, char *argv[])const char *arch;const char *output_file;const char *start_dirname; -char *err_string_ext ="" ; +const char *err_string_ext ="" ;struct stat stbuf; prog =basename (argv[0 ]);
Signature · 1 line
2.26.2
PATCH 2/2 perf jevents: Enable warnings through HOSTCFLAGS
In reply to John GarryCurrently no compiler warnings at all are enabled for building jevents, so help catch bugs at compile time by enabling through HOSTCFLAGS.
--- tools/perf/Makefile.config | 1 + tools/perf/Makefile.perf | 2 +- tools/perf/pmu-events/Build | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-)
tools/perf/Makefile.config +1 -0
@@ -17,6 +17,7 @@ detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected) detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected) CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) +HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) include $(srctree)/tools/scripts/Makefile.arch
tools/perf/Makefile.perf +1 -1
@@ -226,7 +226,7 @@ else endif export srctree OUTPUT RM CC CXX LD AR CFLAGS CXXFLAGS V BISON FLEX AWK -export HOSTCC HOSTLD HOSTAR +export HOSTCC HOSTLD HOSTAR HOSTCFLAGS include $(srctree)/tools/build/Makefile.include
tools/perf/pmu-events/Build +1 -1
@@ -1,7 +1,7 @@ hostprogs := jevents jevents-y += json.o jsmn.o jevents.o -HOSTCFLAGS_jevents.o = -I$(srctree)/tools/include +HOSTCFLAGS_jevents.o = -I$(srctree)/tools/include $(HOSTCFLAGS) pmu-events-y += pmu-events.o JDIR = pmu-events/arch/$(SRCARCH) JSON = $(shell [ -d $(JDIR) ] && \
Signature · 1 line
2.26.2
Re: [PATCH 2/2] perf jevents: Enable warnings through HOSTCFLAGS
Quoted 2 lines · John Garry
Currently no compiler warnings at all are enabled for building jevents, so help catch bugs at compile time by enabling through HOSTCFLAGS.
Is there any reason to not enable -Wall and -Werror so that it builds like the main project? Or if HOSTCFLAGS ends up being the same as CORE_CFLAGS then why not use CORE_CFLAGS instead?
I added them like this and only one unused function needs to be removed to make it build successfully:
tools/perf/Makefile.config +3 -0
@@ -18,6 +18,8 @@ detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected) CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) +HOSTCFLAGS += -Wall +HOSTCFLAGS += -Wextra include $(srctree)/tools/scripts/Makefile.arch
@@ -212,6 +214,7 @@ endif ifneq ($(WERROR),0) CORE_CFLAGS += -Werror CXXFLAGS += -Werror + HOSTCFLAGS += -Werror endif ifndef DEBUG
Quoted 47 lines
Signed-off-by John Garry <[email protected]>--- tools/perf/Makefile.config | 1 + tools/perf/Makefile.perf | 2 +- tools/perf/pmu-events/Build | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-)tools/perf/Makefile.config +1
-0@@ -17,6 +17,7 @@ detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected) detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected) CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) +HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) include $(srctree)/tools/scripts/Makefile.archtools/perf/Makefile.perf +1
-1@@ -226,7 +226,7 @@ else endif export srctree OUTPUT RM CC CXX LD AR CFLAGS CXXFLAGS V BISON FLEX AWK -export HOSTCC HOSTLD HOSTAR +export HOSTCC HOSTLD HOSTAR HOSTCFLAGS include $(srctree)/tools/build/Makefile.includetools/perf/pmu-events/Build +1
-1@@ -1,7 +1,7 @@ hostprogs := jevents jevents-y += json.o jsmn.o jevents.o -HOSTCFLAGS_jevents.o = -I$(srctree)/tools/include +HOSTCFLAGS_jevents.o = -I$(srctree)/tools/include $(HOSTCFLAGS) pmu-events-y += pmu-events.o JDIR = pmu-events/arch/$(SRCARCH) JSON = $(shell [ -d $(JDIR) ] && \
Re: [PATCH 2/2] perf jevents: Enable warnings through HOSTCFLAGS
Quoted 6 lines · James Clark
Quoted 2 lines · John Garry
Currently no compiler warnings at all are enabled for building jevents, so help catch bugs at compile time by enabling through HOSTCFLAGS.
Hi James,
Quoted 3 lines
Is there any reason to not enable -Wall and -Werror so that it builds like the main project? Or if HOSTCFLAGS ends up being the same as
CORE_CFLAGSthen why not useCORE_CFLAGSinstead?
I am not sure that we really want that, as CORE_CFLAGS brings with it things like _LARGEFILE64_SOURCE, which I doubt we want.
Quoted 19 lines
I added them like this and only one unused function needs to be removed to make it build successfully:
tools/perf/Makefile.config +2
-0@@ -18,6 +18,8 @@ detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected) CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) +HOSTCFLAGS += -Wall +HOSTCFLAGS += -Wextra include $(srctree)/tools/scripts/Makefile.arch
tools/perf/Makefile.config endif · line 217
Quoted 4 lines
tools/perf/Makefile.config +1
-0@@ -212,6 +214,7 @@ endif ifneq ($(WERROR),0) CORE_CFLAGS += -Werror CXXFLAGS += -Werror + HOSTCFLAGS += -Werror
These seem fine to add. Actually what I have in HOSTCFLAGS doesn't seem to detect unused functions, with one example fixed in b94729919db2.
Thanks,
John
Em Sat, Oct 16, 2021 at 12:48:25AM +0800, John Garry escreveu:
Quoted 6 lines
Currently jevents builds without any complier warning flags enabled. So use newly-defined HOSTCFLAGS, which comes from
EXTRA_WARNINGS. I am not 100% confident that this is the best way, but sending out for review.Baseline is
be8ecc57f180(HEAD, acme/perf/core) perf srcline: Use long-running addr2line per DSO
Thanks, applied.
- Arnaldo
Quoted 10 lines · Arnaldo Carvalho de Melo
Em Sat, Oct 16, 2021 at 12:48:25AM +0800, John Garry escreveu:
Quoted 6 lines
Currently jevents builds without any complier warning flags enabled. So use newly-defined HOSTCFLAGS, which comes from
EXTRA_WARNINGS. I am not 100% confident that this is the best way, but sending out for review.Baseline is
be8ecc57f180(HEAD, acme/perf/core) perf srcline: Use long-running addr2line per DSOThanks, applied.
Hi Arnaldo,
I was going to send a v2, with changes according to James Clark's review
- that was to add -Wall & -Werror, but they caused a problem on your
perf/core branch as they triggered the warn fixed in commit b94729919db2.
I suppose the best thing now is to send a patch on top once perf/core contains that commit. Let me know otherwise.
Thanks
Quoted 12 lines · John Garry
Quoted 10 lines · Arnaldo Carvalho de Melo
Em Sat, Oct 16, 2021 at 12:48:25AM +0800, John Garry escreveu:
Quoted 6 lines
Currently jevents builds without any complier warning flags enabled. So use newly-defined HOSTCFLAGS, which comes from
EXTRA_WARNINGS. I am not 100% confident that this is the best way, but sending out for review.Baseline is
be8ecc57f180(HEAD, acme/perf/core) perf srcline: Use long-running addr2line per DSOThanks, applied.
Quoted 8 lines
Hi Arnaldo,
I was going to send a v2, with changes according to James Clark's review
- that was to add -Wall & -Werror, but they caused a problem on your
perf/core branch as they triggered the warn fixed in commitb94729919db2.I suppose the best thing now is to send a patch on top once perf/core contains that commit. Let me know otherwise.
Tests are running, if something fails, then I'll have to fix it and will not make my perf/core public, so I can replace what I have with a v2, otherwise you please send a patch on top after l make it public.
- Arnaldo
Quoted 2 lines
Thanks
Em Wed, Oct 20, 2021 at 03:41:01PM +0100, John Garry escreveu:
Quoted 9 lines · Arnaldo Carvalho de Melo
Quoted 8 lines
Em Sat, Oct 16, 2021 at 12:48:25AM +0800, John Garry escreveu:
Quoted 6 lines
Currently jevents builds without any complier warning flags enabled. So use newly-defined HOSTCFLAGS, which comes from
EXTRA_WARNINGS. I am not 100% confident that this is the best way, but sending out for review.Baseline is
be8ecc57f180(HEAD, acme/perf/core) perf srcline: Use long-running addr2line per DSO
Quoted 8 lines
Quoted 1 line
Thanks, applied.
I was going to send a v2, with changes according to James Clark's review - that was to add -Wall & -Werror, but they caused a problem on your perf/core branch as they triggered the warn fixed in commit
b94729919db2.I suppose the best thing now is to send a patch on top once perf/core contains that commit. Let me know otherwise.
You can send a v2, as:
29 8.60 debian:experimental-x-mipsel : FAIL gcc version 11.2.0 (Debian 11.2.0-9)
util/intel-pt.c: In function 'intel_pt_synth_pebs_sample':
util/intel-pt.c:2146:33: error: passing argument 1 of 'find_first_bit' from incompatible pointer type [-Werror=incompatible-pointer-types]
2146 | for_each_set_bit(hw_id, &items->applicable_counters, INTEL_PT_MAX_PEBS) {
/git/perf-5.15.0-rc4/tools/include/linux/bitops.h:37:38: note: in definition of macro 'for_each_set_bit'
37 | for ((bit) = find_first_bit((addr), (size)); \
| ^~~~
In file included from /git/perf-5.15.0-rc4/tools/include/asm-generic/bitops.h:21,
from /git/perf-5.15.0-rc4/tools/include/linux/bitops.h:34,
from /git/perf-5.15.0-rc4/tools/include/linux/bitmap.h:6,
from util/header.h:10,
from util/session.h:7,
from util/intel-pt.c:16:
/git/perf-5.15.0-rc4/tools/include/asm-generic/bitops/find.h:109:51: note: expected 'const long unsigned int *' but argument is of type 'const uint64_t *' {aka 'const long long unsigned int *'}Adrian, this is on:
commit 803a3c9233990e1adac8ea2421e3759c2d380cf8
Author: Adrian Hunter <[email protected]> Date: Tue Sep 7 19:39:03 2021 +0300
perf intel-pt: Add support for PERF_RECORD_AUX_OUTPUT_HW_ID
Originally, software only supported redirecting at most one PEBS event to Intel PT (PEBS-via-PT) because it was not able to differentiate one event from another. To overcome that, add support for the PERF_RECORD_AUX_OUTPUT_HW_ID side-band event.
That is still just on tmp.perf/core, so we can fix it, probably its just making that uint64_t into a unsigned long, will check later if you don't beat me to it.
- Arnaldo
Arnaldo Carvalho de Melo
maintainer[RFC] Support Intel-PT code build in 32-bit arches
Em Wed, Oct 20, 2021 at 02:25:43PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 34 lines
Em Wed, Oct 20, 2021 at 03:41:01PM +0100, John Garry escreveu:
Quoted 2 lines
I suppose the best thing now is to send a patch on top once perf/core contains that commit. Let me know otherwise.
You can send a v2, as:
29 8.60 debian:experimental-x-mipsel : FAIL gcc version 11.2.0 (Debian 11.2.0-9)
util/intel-pt.c: In function 'intel_pt_synth_pebs_sample': util/intel-pt.c:2146:33: error: passing argument 1 of 'find_first_bit' from incompatible pointer type [-Werror=incompatible-pointer-types] 2146 | for_each_set_bit(hw_id, &items->applicable_counters, INTEL_PT_MAX_PEBS) { /git/perf-5.15.0-rc4/tools/include/linux/bitops.h:37:38: note: in definition of macro 'for_each_set_bit' 37 | for ((bit) = find_first_bit((addr), (size)); \ | ^~~~ In file included from /git/perf-5.15.0-rc4/tools/include/asm-generic/bitops.h:21, from /git/perf-5.15.0-rc4/tools/include/linux/bitops.h:34, from /git/perf-5.15.0-rc4/tools/include/linux/bitmap.h:6, from util/header.h:10, from util/session.h:7, from util/intel-pt.c:16: /git/perf-5.15.0-rc4/tools/include/asm-generic/bitops/find.h:109:51: note: expected 'const long unsigned int *' but argument is of type 'const uint64_t *' {aka 'const long long unsigned int *'}Adrian, this is on:
commit
803a3c9233990e1adac8ea2421e3759c2d380cf8Author: Adrian Hunter <[email protected]> Date: Tue Sep 7 19:39:03 2021 +0300perf intel-pt: Add support for
PERF_RECORD_AUX_OUTPUT_HW_IDOriginally, software only supported redirecting at most one PEBS event to Intel PT (PEBS-via-PT) because it was not able to differentiate one event from another. To overcome that, add support for the
PERF_RECORD_AUX_OUTPUT_HW_IDside-band event.
Quoted 7 lines
Reviewed-by Alexander Shishkin <[email protected]>Reviewed-by Andi Kleen <[email protected]>That is still just on tmp.perf/core, so we can fix it, probably its just making that
uint64_tinto a unsigned long, will check later if you don't beat me to it.
Adrian,
Probably we should just disable Intel PT support from being
built on 32-bit arches, right? I don't know if anybody is interested on that, my tests just try to figure out if it continues to build, and if fixing any problem isn't costly, which in this case is more than my threshold, wdyt?
- Arnaldo
Adrian Hunter
reviewerRe: [RFC] Support Intel-PT code build in 32-bit arches
Quoted 43 lines · Arnaldo Carvalho de Melo
Em Wed, Oct 20, 2021 at 02:25:43PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 34 lines
Em Wed, Oct 20, 2021 at 03:41:01PM +0100, John Garry escreveu:
Quoted 2 lines
I suppose the best thing now is to send a patch on top once perf/core contains that commit. Let me know otherwise.
You can send a v2, as:
29 8.60 debian:experimental-x-mipsel : FAIL gcc version 11.2.0 (Debian 11.2.0-9)
util/intel-pt.c: In function 'intel_pt_synth_pebs_sample': util/intel-pt.c:2146:33: error: passing argument 1 of 'find_first_bit' from incompatible pointer type [-Werror=incompatible-pointer-types] 2146 | for_each_set_bit(hw_id, &items->applicable_counters, INTEL_PT_MAX_PEBS) { /git/perf-5.15.0-rc4/tools/include/linux/bitops.h:37:38: note: in definition of macro 'for_each_set_bit' 37 | for ((bit) = find_first_bit((addr), (size)); \ | ^~~~ In file included from /git/perf-5.15.0-rc4/tools/include/asm-generic/bitops.h:21, from /git/perf-5.15.0-rc4/tools/include/linux/bitops.h:34, from /git/perf-5.15.0-rc4/tools/include/linux/bitmap.h:6, from util/header.h:10, from util/session.h:7, from util/intel-pt.c:16: /git/perf-5.15.0-rc4/tools/include/asm-generic/bitops/find.h:109:51: note: expected 'const long unsigned int *' but argument is of type 'const uint64_t *' {aka 'const long long unsigned int *'}Adrian, this is on:
commit
803a3c9233990e1adac8ea2421e3759c2d380cf8Author: Adrian Hunter <[email protected]> Date: Tue Sep 7 19:39:03 2021 +0300perf intel-pt: Add support for
PERF_RECORD_AUX_OUTPUT_HW_IDOriginally, software only supported redirecting at most one PEBS event to Intel PT (PEBS-via-PT) because it was not able to differentiate one event from another. To overcome that, add support for the
PERF_RECORD_AUX_OUTPUT_HW_IDside-band event.Quoted 7 lines
Reviewed-by Alexander Shishkin <[email protected]>Reviewed-by Andi Kleen <[email protected]>That is still just on tmp.perf/core, so we can fix it, probably its just making that
uint64_tinto a unsigned long, will check later if you don't beat me to it.
Quoted 7 lines
Adrian,
Probably we should just disable Intel PT support from being
built on 32-bit arches, right? I don't know if anybody is interested on that, my tests just try to figure out if it continues to build, and if fixing any problem isn't costly, which in this case is more than my threshold, wdyt?
It feels like bad form not to compile on 32-bit.
In this case we could just cast it, and I see that has been done in other places for for_each_set_bit(), but (and maybe I've got it wrong) that wouldn't work for a 32-bit big endian system?
The following might cover all cases, do you think?
tools/perf/util/intel-pt.c +9 -1
@@ -2129,9 +2129,17 @@ static int intel_pt_synth_single_pebs_sample(struct intel_pt_queue *ptq)return intel_pt_do_synth_pebs_sample (ptq, evsel, id); } +/* For 32-bit big endian, put the longs from u64 in correct order */ +#define U64_BITS (var, val) \ + unsigned long var[] = { \ + [0] = (val), \ + [1] = (val) >> 32, \ + } +static int intel_pt_synth_pebs_sample (struct intel_pt_queue *ptq) {const struct intel_pt_blk_items *items = &ptq->state->items; +U64_BITS (ac_bits, items->applicable_counters);struct intel_pt_pebs_event *pe;struct intel_pt *pt = ptq->pt;int err = -EINVAL ;
@@ -2143,7 +2151,7 @@ static int intel_pt_synth_pebs_sample(struct intel_pt_queue *ptq)return intel_pt_synth_single_pebs_sample (ptq); } -for_each_set_bit (hw_id, &items->applicable_counters,INTEL_PT_MAX_PEBS ) { +for_each_set_bit (hw_id, ac_bits,INTEL_PT_MAX_PEBS ) { pe = &ptq->pebs[hw_id];if (!pe->evsel) {if (!pt->single_pebs)