perf tests pmu: Initialize all fields of test_pmu variable
Arnaldo Carvalho de Melo
maintainerPATCH 1/1 perf tests pmu: Initialize all fields of test_pmu variable
Instead of explicitely initializing just the .name and .alias_name, use struct member named initialization of just the non-null -name field, the compiler will initialize all the other non-explicitely initialized fields to NULL.
This makes the code more robust, avoiding the error recently fixed when the .alias_name was used and contained a random value.
--- tools/perf/tests/pmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/tests/pmu.c +3 -3
@@ -458,10 +458,10 @@ static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __*/ static int test__pmu_match (struct test_suite *test__maybe_unused ,int subtest__maybe_unused ) { -struct perf_pmu test_pmu; - test_pmu.alias_name =NULL ; +struct perf_pmu test_pmu = { + .name ="pmuname" , + }; - test_pmu.name ="pmuname" ;TEST_ASSERT_EQUAL ("Exact match" ,perf_pmu__match (&test_pmu,"pmuname" ), true);TEST_ASSERT_EQUAL ("Longer token" ,perf_pmu__match (&test_pmu,"longertoken" ), false);TEST_ASSERT_EQUAL ("Shorter token" ,perf_pmu__match (&test_pmu,"pmu" ), false);
Signature · 1 line
2.45.2
Quoted 30 lines · Arnaldo Carvalho de Melo
Instead of explicitely initializing just the .name and .alias_name, use struct member named initialization of just the non-null -name field, the compiler will initialize all the other non-explicitely initialized fields to NULL.
This makes the code more robust, avoiding the error recently fixed when the .alias_name was used and contained a random value.
Cc Adrian Hunter <[email protected]>Cc Ian Rogers <[email protected]>Cc James Clark <[email protected]>Cc Jiri Olsa <[email protected]>Cc Kan Liang <[email protected]>Cc Michael Petlan <[email protected]>Cc Namhyung Kim <[email protected]>Cc Radostin Stoyanov <[email protected]>Cc Veronika Molnarova <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/tests/pmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)tools/perf/tests/pmu.c +0
-0@@ -458,10 +458,10 @@ static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __*/ static int test__pmu_match (struct test_suite *test__maybe_unused ,int subtest__maybe_unused ) {
tools/perf/tests/pmu.c static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __ · line 467
Quoted 10 lines
tools/perf/tests/pmu.c +3
-3-struct perf_pmu test_pmu; - test_pmu.alias_name =NULL ; +struct perf_pmu test_pmu = { + .name ="pmuname" , + }; - test_pmu.name ="pmuname" ;TEST_ASSERT_EQUAL ("Exact match" ,perf_pmu__match (&test_pmu,"pmuname" ), true);TEST_ASSERT_EQUAL ("Longer token" ,perf_pmu__match (&test_pmu,"longertoken" ), false);TEST_ASSERT_EQUAL ("Shorter token" ,perf_pmu__match (&test_pmu,"pmu" ), false);
Thanks for the rework,
Veronika
Ian Rogers
reviewerQuoted 47 lines · Veronika Molnarova
Quoted 30 lines · Arnaldo Carvalho de Melo
Instead of explicitely initializing just the .name and .alias_name, use struct member named initialization of just the non-null -name field, the compiler will initialize all the other non-explicitely initialized fields to NULL.
This makes the code more robust, avoiding the error recently fixed when the .alias_name was used and contained a random value.
Cc Adrian Hunter <[email protected]>Cc Ian Rogers <[email protected]>Cc James Clark <[email protected]>Cc Jiri Olsa <[email protected]>Cc Kan Liang <[email protected]>Cc Michael Petlan <[email protected]>Cc Namhyung Kim <[email protected]>Cc Radostin Stoyanov <[email protected]>Cc Veronika Molnarova <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/tests/pmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)tools/perf/tests/pmu.c +0
-0@@ -458,10 +458,10 @@ static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __*/ static int test__pmu_match (struct test_suite *test__maybe_unused ,int subtest__maybe_unused ) {tools/perf/tests/pmu.c static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __ · line 467
Quoted 10 lines
tools/perf/tests/pmu.c +3
-3-struct perf_pmu test_pmu; - test_pmu.alias_name =NULL ; +struct perf_pmu test_pmu = { + .name ="pmuname" , + }; - test_pmu.name ="pmuname" ;TEST_ASSERT_EQUAL ("Exact match" ,perf_pmu__match (&test_pmu,"pmuname" ), true);TEST_ASSERT_EQUAL ("Longer token" ,perf_pmu__match (&test_pmu,"longertoken" ), false);TEST_ASSERT_EQUAL ("Shorter token" ,perf_pmu__match (&test_pmu,"pmu" ), false);Reviewed-by Veronika Molnarova <[email protected]>
Quoted 2 lines
Thanks for the rework,
Veronika
This seems like a simple enough fix for a test that it could be cherry-picked into perf-tools for v6.11, I'm not seeing it currently:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools.git/log/tools/perf/tests/pmu.c?h=perf-tools
Thanks,
Ian
Arnaldo Carvalho de Melo
maintainerQuoted 20 lines · Ian Rogers
Quoted 18 lines · Veronika Molnarova
Quoted 17 lines · Arnaldo Carvalho de Melo
This makes the code more robust, avoiding the error recently fixed when the .alias_name was used and contained a random value.
+++
b/tools/perf/tests/pmu.ctools/perf/tests/pmu.c +3
-3@@ -458,10 +458,10 @@ static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __static int test__pmu_match (struct test_suite *test__maybe_unused ,int subtest__maybe_unused ) { -struct perf_pmu test_pmu; - test_pmu.alias_name =NULL ; +struct perf_pmu test_pmu = { + .name ="pmuname" , + }; - test_pmu.name ="pmuname" ;TEST_ASSERT_EQUAL ("Exact match" ,perf_pmu__match (&test_pmu,"pmuname" ), true);TEST_ASSERT_EQUAL ("Longer token" ,perf_pmu__match (&test_pmu,"longertoken" ), false);TEST_ASSERT_EQUAL ("Shorter token" ,perf_pmu__match (&test_pmu,"pmu" ), false);
Quoted 5 lines
Quoted 1 line
Reviewed-by Veronika Molnarova <[email protected]>This seems like a simple enough fix for a test that it could be cherry-picked into perf-tools for v6.11, I'm not seeing it currently:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools.git/log/tools/perf/tests/pmu.c?h=perf-tools
This is not a fix, its just to make the code more future proof by initializing all non explicitely initialized fields to zeros.
Veronika's fix, that this improves upon, is enough for the problems detected so far.
Or are you noticing some other bug that gets fixed by my patch?
Ok, now I noticed that Veronika's fix:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools.git/commit/?h=perf-tools&id=37e2a19c98bf99747ca997be876dfc13f9165e0a
is marked with:
perf test pmu: Set uninitialized PMU alias to null
Notice: this object is not reachable from any branch.
Being only in perf-tools-next:
So yeah, probably Namhyung can cherry-pick that patch (Veronika's) into perf-tools for v6.11.
There were a few more fixes that I noticed and picked for perf-tools-next that then people reported that should also be cherry-picked for v6.11, Namhyung?
- Arnaldo
Namhyung Kim
maintainerHi,
Quoted 47 lines · Arnaldo Carvalho de Melo
Quoted 20 lines · Ian Rogers
Quoted 18 lines · Veronika Molnarova
Quoted 17 lines · Arnaldo Carvalho de Melo
This makes the code more robust, avoiding the error recently fixed when the .alias_name was used and contained a random value.
+++
b/tools/perf/tests/pmu.ctools/perf/tests/pmu.c +3
-3@@ -458,10 +458,10 @@ static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __static int test__pmu_match (struct test_suite *test__maybe_unused ,int subtest__maybe_unused ) { -struct perf_pmu test_pmu; - test_pmu.alias_name =NULL ; +struct perf_pmu test_pmu = { + .name ="pmuname" , + }; - test_pmu.name ="pmuname" ;TEST_ASSERT_EQUAL ("Exact match" ,perf_pmu__match (&test_pmu,"pmuname" ), true);TEST_ASSERT_EQUAL ("Longer token" ,perf_pmu__match (&test_pmu,"longertoken" ), false);TEST_ASSERT_EQUAL ("Shorter token" ,perf_pmu__match (&test_pmu,"pmu" ), false);Quoted 5 lines
Quoted 1 line
Reviewed-by Veronika Molnarova <[email protected]>This seems like a simple enough fix for a test that it could be cherry-picked into perf-tools for v6.11, I'm not seeing it currently:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools.git/log/tools/perf/tests/pmu.c?h=perf-toolsThis is not a fix, its just to make the code more future proof by initializing all non explicitely initialized fields to zeros.
Veronika's fix, that this improves upon, is enough for the problems detected so far.
Or are you noticing some other bug that gets fixed by my patch?
Ok, now I noticed that Veronika's fix:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools.git/commit/?h=perf-tools&id=37e2a19c98bf99747ca997be876dfc13f9165e0ais marked with:
perf test pmu: Set uninitialized PMU alias to null
Notice: this object is not reachable from any branch.Being only in perf-tools-next:
Quoted 8 lines
So yeah, probably Namhyung can cherry-pick that patch (Veronika's) into perf-tools for v6.11.
There were a few more fixes that I noticed and picked for perf-tools-next that then people reported that should also be cherry-picked for v6.11, Namhyung?
Ok, I can pick this up. I think my perf lock contention fix also can go to perf-tools.
What others do you want me to pick up?
Thanks,
Namhyung
Arnaldo Carvalho de Melo
maintainerQuoted 8 lines · Namhyung Kim
Quoted 6 lines · Arnaldo Carvalho de Melo
Being only in perf-tools-next:
So yeah, probably Namhyung can cherry-pick that patch (Veronika's) into perf-tools for v6.11.
Quoted 7 lines
Quoted 3 lines
There were a few more fixes that I noticed and picked for perf-tools-next that then people reported that should also be cherry-picked for v6.11, Namhyung?
Ok, I can pick this up. I think my perf lock contention fix also can go to perf-tools.
What others do you want me to pick up?
Here Ben points to one:
https://lore.kernel.org/all/[email protected]/T/#u
Which I think its this one:
commit 2518e13275ab9ea6b2540f828cf78b0280991f85
Author: Xu Yang <[email protected]> Date: Mon Aug 19 10:34:03 2024 +0800
perf python: Fix the build on 32-bit arm by including missing "util/sample.h"
There is also this one:
commit 6236ebe07131a7746d870f1d8eb3637a8df13e70
Author: Arnaldo Carvalho de Melo <[email protected]> Date: Mon Aug 19 16:46:29 2024 -0300
perf daemon: Fix the build on more 32-bit architectures
The previous attempt fixed the build on debian:experimental-x-mipsel, but when building on a larger set of containers I noticed it broke the build on some other 32-bit architectures such as:
42 7.87 ubuntu:18.04-x-arm : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
builtin-daemon.c: In function 'cmd_session_list':
builtin-daemon.c:692:16: error: format '%llu' expects argument of type 'long long unsigned int', but argument 4 has type 'long int' [-Werror=format=]
- Arnaldo