perf/bpf_counter: use bpf_map_create instead of bpf_create_map
Subsystems (4)
Song Liu
reviewerPATCH 1/1 perf/bpf_counter: use bpf_map_create instead of bpf_create_map
bpf_create_map is deprecated. Replace it with bpf_map_create.
--- tools/perf/util/bpf_counter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/bpf_counter.c +2 -2
@@ -320,10 +320,10 @@ static int bperf_lock_attr_map(struct target *target) }if (access (path,F_OK )) { - map_fd =bpf_create_map (BPF_MAP_TYPE_HASH , + map_fd =bpf_map_create (BPF_MAP_TYPE_HASH ,NULL ,sizeof (struct perf_event_attr ),sizeof (struct perf_event_attr_map_entry ), -ATTR_MAP_SIZE ,0 ); +ATTR_MAP_SIZE ,NULL );if (map_fd <0 )return -1 ;
Signature · 1 line
2.30.2
Quoted 4 lines · Song Liu
bpf_create_mapis deprecated. Replace it withbpf_map_create.Fixes 992c4225419a ("libbpf: Unify low-level map creation APIs w/ new bpf_map_create()")
This is not a bug fix, it's an improvement. So I don't think "Fixes: " is warranted here, tbh.
Quoted 10 lines
Signed-off-by Song Liu <[email protected]>--- tools/perf/util/bpf_counter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/util/bpf_counter.c +0
-0
tools/perf/util/bpf_counter.c static int bperf_lock_attr_map(struct target *target) · line 323
Quoted 5 lines
tools/perf/util/bpf_counter.c +1
-1@@ -320,10 +320,10 @@ static int bperf_lock_attr_map(struct target *target) }if (access (path,F_OK )) { - map_fd = bpf_create_map(BPF_MAP_TYPE_HASH, + map_fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL,
I think perf is trying to be linkable with libbpf as a shared library, so on some older versions of libbpf bpf_map_create() won't be (yet) available. So to make this work, I think you'll need to define your own weak bpf_map_create function that will use bpf_create_map().
Quoted 10 lines
tools/perf/util/bpf_counter.c +1
-2sizeof (struct perf_event_attr ),sizeof (struct perf_event_attr_map_entry ), - ATTR_MAP_SIZE, 0); + ATTR_MAP_SIZE, NULL);if (map_fd <0 )return -1 ; --2.30.2
Quoted 12 lines · Andrii Nakryiko
Quoted 4 lines · Song Liu
bpf_create_mapis deprecated. Replace it withbpf_map_create.Fixes 992c4225419a ("libbpf: Unify low-level map creation APIs w/ new bpf_map_create()")This is not a bug fix, it's an improvement. So I don't think "Fixes: " is warranted here, tbh.
I got compilation errors before this change, like
util/bpf_counter.c: In function ‘bperf_lock_attr_map’:util/bpf_counter.c:323:3: error: ‘bpf_create_map’ is deprecated: libbpf v0.7+: use bpf_map_create() instead [-Werror=deprecated-declarations]
map_fd = bpf_create_map(BPF_MAP_TYPE_HASH,
^~~~~~
In file included from util/bpf_counter.h:7,
from util/bpf_counter.c:15:
/data/users/songliubraving/kernel/linux-git/tools/lib/bpf/bpf.h:91:16: note: declared here
LIBBPF_API int bpf_create_map(enum bpf_map_type map_type, int key_size,
^~~~~~~~~~~~~~cc1: all warnings being treated as errors
make[4]: *** [/data/users/songliubraving/kernel/linux-git/tools/build/Makefile.build:96: util/bpf_counter.o] Error 1 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [/data/users/songliubraving/kernel/linux-git/tools/build/Makefile.build:139: util] Error 2 make[2]: *** [Makefile.perf:665: perf-in.o] Error 2
make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
Do we plan to remove bpf_create_map in the future? If not, we can probably just add '#pragma GCC diagnostic ignored "-Wdeprecated-declarations"' can call it done?
Quoted 13 lines
Quoted 13 lines
Signed-off-by Song Liu <[email protected]>---
tools/perf/util/bpf_counter.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/util/bpf_counter.c +0
-0@@ -320,10 +320,10 @@ static int bperf_lock_attr_map(struct target *target) }
Quoted 8 lines
tools/perf/util/bpf_counter.c static int bperf_lock_attr_map(struct target *target) · line 323
Quoted 3 lines
tools/perf/util/bpf_counter.c +1
-1if (access (path,F_OK )) { - map_fd = bpf_create_map(BPF_MAP_TYPE_HASH, + map_fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL,I think perf is trying to be linkable with libbpf as a shared library, so on some older versions of libbpf
bpf_map_create()won't be (yet) available. So to make this work, I think you'll need to define your own weakbpf_map_createfunction that will usebpf_create_map().
Hmm... I didn't know the plan to link libbpf as shared library. In this case, maybe the #pragma solution is preferred?
Thanks,
Song
Quoted 25 lines · Song Liu
Quoted 13 lines · Andrii Nakryiko
Quoted 4 lines · Song Liu
bpf_create_mapis deprecated. Replace it withbpf_map_create.Fixes 992c4225419a ("libbpf: Unify low-level map creation APIs w/ new bpf_map_create()")This is not a bug fix, it's an improvement. So I don't think "Fixes: " is warranted here, tbh.
I got compilation errors before this change, like
util/bpf_counter.c: In function ‘bperf_lock_attr_map’:util/bpf_counter.c:323:3: error: ‘bpf_create_map’ is deprecated: libbpf v0.7+: usebpf_map_create()instead [-Werror=deprecated-declarations]
map_fd= bpf_create_map(BPF_MAP_TYPE_HASH,
^~~~~~
In file included fromutil/bpf_counter.h:7,from util/bpf_counter.c:15: /data/users/songliubraving/kernel/linux-git/tools/lib/bpf/bpf.h:91:16: note: declared here LIBBPF_API int bpf_create_map(enum bpf_map_type map_type, int key_size, ^~~~~~~~~~~~~~
Quoted 8 lines
cc1: all warnings being treated as errors
make[4]: *** [/data/users/songliubraving/kernel/linux-git/tools/build/Makefile.build:96:util/bpf_counter.o] Error 1 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [/data/users/songliubraving/kernel/linux-git/tools/build/Makefile.build:139: util] Error 2 make[2]: *** [Makefile.perf:665: perf-in.o] Error 2
make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
Hmm.. is util/bpf_counter.h guarded behind some Makefile arguments? I've sent #pragma temporary workarounds just a few days ago ([0]), but this one didn't come up during the build.
[0] https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Quoted 2 lines
Do we plan to remove
bpf_create_mapin the future? If not, we can probably just add '#pragma GCC diagnostic ignored "-Wdeprecated-declarations"' can call it done?
Yes, it will be removed in a few libbpf releases when we switch to the 1.0 version. So suppressing a warning is a temporary work-around.
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
Signed-off-by Song Liu <[email protected]>---
tools/perf/util/bpf_counter.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/util/bpf_counter.c +0
-0@@ -320,10 +320,10 @@ static int bperf_lock_attr_map(struct target *target) }Quoted 8 lines
tools/perf/util/bpf_counter.c static int bperf_lock_attr_map(struct target *target) · line 323
Quoted 3 lines
tools/perf/util/bpf_counter.c +1
-1if (access (path,F_OK )) { - map_fd = bpf_create_map(BPF_MAP_TYPE_HASH, + map_fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL,I think perf is trying to be linkable with libbpf as a shared library, so on some older versions of libbpf
bpf_map_create()won't be (yet) available. So to make this work, I think you'll need to define your own weakbpf_map_createfunction that will usebpf_create_map().
Quoted 2 lines
Hmm... I didn't know the plan to link libbpf as shared library. In this case, maybe the #pragma solution is preferred?
See "perf tools: Add more weak libbpf functions" sent by Jiri not so long ago about what they did with some other used APIs that are now marked deprecated.
Quoted 4 lines
Thanks,
Song
Quoted 39 lines · Andrii Nakryiko
Quoted 25 lines · Song Liu
Quoted 13 lines · Andrii Nakryiko
Quoted 4 lines · Song Liu
bpf_create_mapis deprecated. Replace it withbpf_map_create.Fixes 992c4225419a ("libbpf: Unify low-level map creation APIs w/ new bpf_map_create()")This is not a bug fix, it's an improvement. So I don't think "Fixes: " is warranted here, tbh.
I got compilation errors before this change, like
util/bpf_counter.c: In function ‘bperf_lock_attr_map’:util/bpf_counter.c:323:3: error: ‘bpf_create_map’ is deprecated: libbpf v0.7+: usebpf_map_create()instead [-Werror=deprecated-declarations]
map_fd= bpf_create_map(BPF_MAP_TYPE_HASH,
^~~~~~
In file included fromutil/bpf_counter.h:7,from util/bpf_counter.c:15: /data/users/songliubraving/kernel/linux-git/tools/lib/bpf/bpf.h:91:16: note: declared here LIBBPF_API int bpf_create_map(enum bpf_map_type map_type, int key_size, ^~~~~~~~~~~~~~Quoted 8 lines
cc1: all warnings being treated as errors
make[4]: *** [/data/users/songliubraving/kernel/linux-git/tools/build/Makefile.build:96:util/bpf_counter.o] Error 1 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [/data/users/songliubraving/kernel/linux-git/tools/build/Makefile.build:139: util] Error 2 make[2]: *** [Makefile.perf:665: perf-in.o] Error 2
make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
Quoted 5 lines
Hmm.. is
util/bpf_counter.hguarded behind someMakefilearguments? I've sent #pragma temporary workarounds just a few days ago ([0]), but this one didn't come up during the build.[0] https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
I guess the default build test doesn't enable BUILD_BPF_SKEL?
Quoted 30 lines
Quoted 3 lines
Do we plan to remove
bpf_create_mapin the future? If not, we can probably just add '#pragma GCC diagnostic ignored "-Wdeprecated-declarations"' can call it done?Yes, it will be removed in a few libbpf releases when we switch to the 1.0 version. So suppressing a warning is a temporary work-around.
Quoted 23 lines
Quoted 22 lines
Quoted 12 lines
Signed-off-by Song Liu <[email protected]>---
tools/perf/util/bpf_counter.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/util/bpf_counter.c +0
-0tools/perf/util/bpf_counter.c static int bperf_lock_attr_map(struct target *target) · line 323
Quoted 5 lines
tools/perf/util/bpf_counter.c +1
-1@@ -320,10 +320,10 @@ static int bperf_lock_attr_map(struct target *target) }if (access (path,F_OK )) { - map_fd = bpf_create_map(BPF_MAP_TYPE_HASH, + map_fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL,I think perf is trying to be linkable with libbpf as a shared library, so on some older versions of libbpf
bpf_map_create()won't be (yet) available. So to make this work, I think you'll need to define your own weakbpf_map_createfunction that will usebpf_create_map().
Quoted 6 lines
Quoted 2 lines
Hmm... I didn't know the plan to link libbpf as shared library. In this case, maybe the #pragma solution is preferred?
See "perf tools: Add more weak libbpf functions" sent by Jiri not so long ago about what they did with some other used APIs that are now marked deprecated.
Do you mean something like this?
int __weak
bpf_map_create(enum bpf_map_type map_type,
const char *map_name __maybe_unused,
__u32 key_size,
__u32 value_size,
__u32 max_entries,
const struct bpf_map_create_opts *opts __maybe_unused)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return bpf_create_map(map_type, key_size, value_size, max_entries, 0);#pragma GCC diagnostic pop
}
I guess this won't work when bpf_create_map() is eventually removed, as __weak function are still compiled, no?
Thanks,
Song
Quoted 40 lines · Song Liu
Quoted 40 lines · Andrii Nakryiko
Quoted 33 lines · Song Liu
Quoted 13 lines · Andrii Nakryiko
Quoted 4 lines · Song Liu
bpf_create_mapis deprecated. Replace it withbpf_map_create.Fixes 992c4225419a ("libbpf: Unify low-level map creation APIs w/ new bpf_map_create()")This is not a bug fix, it's an improvement. So I don't think "Fixes: " is warranted here, tbh.
I got compilation errors before this change, like
util/bpf_counter.c: In function ‘bperf_lock_attr_map’:util/bpf_counter.c:323:3: error: ‘bpf_create_map’ is deprecated: libbpf v0.7+: usebpf_map_create()instead [-Werror=deprecated-declarations]
map_fd= bpf_create_map(BPF_MAP_TYPE_HASH,
^~~~~~
In file included fromutil/bpf_counter.h:7,from util/bpf_counter.c:15: /data/users/songliubraving/kernel/linux-git/tools/lib/bpf/bpf.h:91:16: note: declared here LIBBPF_API int bpf_create_map(enum bpf_map_type map_type, int key_size, ^~~~~~~~~~~~~~cc1: all warnings being treated as errors
make[4]: *** [/data/users/songliubraving/kernel/linux-git/tools/build/Makefile.build:96:util/bpf_counter.o] Error 1 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [/data/users/songliubraving/kernel/linux-git/tools/build/Makefile.build:139: util] Error 2 make[2]: *** [Makefile.perf:665: perf-in.o] Error 2
make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
Quoted 7 lines
Quoted 5 lines
Hmm.. is
util/bpf_counter.hguarded behind someMakefilearguments? I've sent #pragma temporary workarounds just a few days ago ([0]), but this one didn't come up during the build.[0] https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
I guess the default build test doesn't enable
BUILD_BPF_SKEL?
I see, right, I think I already asked about that before :( Is it possible to set Makefile such that it will do BUILD_BPF_SKEL=1 if Clang version is recent enough and other conditions are satisfied (unless overridden or something)?
Quoted 51 lines
Quoted 31 lines
Quoted 4 lines
Do we plan to remove
bpf_create_mapin the future? If not, we can probably just add '#pragma GCC diagnostic ignored "-Wdeprecated-declarations"' can call it done?Yes, it will be removed in a few libbpf releases when we switch to the 1.0 version. So suppressing a warning is a temporary work-around.
Quoted 23 lines
Quoted 22 lines
Quoted 12 lines
Signed-off-by Song Liu <[email protected]>---
tools/perf/util/bpf_counter.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/util/bpf_counter.c +0
-0tools/perf/util/bpf_counter.c static int bperf_lock_attr_map(struct target *target) · line 323
Quoted 5 lines
tools/perf/util/bpf_counter.c +1
-1@@ -320,10 +320,10 @@ static int bperf_lock_attr_map(struct target *target) }if (access (path,F_OK )) { - map_fd = bpf_create_map(BPF_MAP_TYPE_HASH, + map_fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL,I think perf is trying to be linkable with libbpf as a shared library, so on some older versions of libbpf
bpf_map_create()won't be (yet) available. So to make this work, I think you'll need to define your own weakbpf_map_createfunction that will usebpf_create_map().Quoted 6 lines
Quoted 2 lines
Hmm... I didn't know the plan to link libbpf as shared library. In this case, maybe the #pragma solution is preferred?
See "perf tools: Add more weak libbpf functions" sent by Jiri not so long ago about what they did with some other used APIs that are now marked deprecated.
Do you mean something like this?
int
__weak
bpf_map_create(enumbpf_map_typemap_type,const char *map_name __maybe_unused, __u32 key_size, __u32 value_size, __u32 max_entries, const struct bpf_map_create_opts *opts __maybe_unused) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" return bpf_create_map(map_type, key_size, value_size, max_entries, 0);
Quoted 5 lines
#pragma GCC diagnostic pop
}I guess this won't work when
bpf_create_map()is eventually removed, as__weakfunction are still compiled, no?
Yes and yes. I'm not sure what would be perf's plan w.r.t. libbpf 1.0, we'll need to work together to figure this out. At some point perf will need to say that the minimum version of supported libbpf is v0.6 or something and just assume all those newer APIs are there (no need to bump it all the way to libbpf 1.0, btw).
Quoted 3 lines
Thanks,
Song
Quoted 49 lines · Andrii Nakryiko
Quoted 44 lines · Song Liu
Quoted 44 lines · Andrii Nakryiko
Quoted 25 lines · Song Liu
Quoted 13 lines · Andrii Nakryiko
Quoted 4 lines · Song Liu
bpf_create_mapis deprecated. Replace it withbpf_map_create.Fixes 992c4225419a ("libbpf: Unify low-level map creation APIs w/ new bpf_map_create()")This is not a bug fix, it's an improvement. So I don't think "Fixes: " is warranted here, tbh.
I got compilation errors before this change, like
util/bpf_counter.c: In function ‘bperf_lock_attr_map’:util/bpf_counter.c:323:3: error: ‘bpf_create_map’ is deprecated: libbpf v0.7+: usebpf_map_create()instead [-Werror=deprecated-declarations]
map_fd= bpf_create_map(BPF_MAP_TYPE_HASH,
^~~~~~
In file included fromutil/bpf_counter.h:7,from util/bpf_counter.c:15: /data/users/songliubraving/kernel/linux-git/tools/lib/bpf/bpf.h:91:16: note: declared here LIBBPF_API int bpf_create_map(enum bpf_map_type map_type, int key_size, ^~~~~~~~~~~~~~Quoted 8 lines
cc1: all warnings being treated as errors
make[4]: *** [/data/users/songliubraving/kernel/linux-git/tools/build/Makefile.build:96:util/bpf_counter.o] Error 1 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [/data/users/songliubraving/kernel/linux-git/tools/build/Makefile.build:139: util] Error 2 make[2]: *** [Makefile.perf:665: perf-in.o] Error 2
make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2Hmm.. is
util/bpf_counter.hguarded behind someMakefilearguments? I've sent #pragma temporary workarounds just a few days ago ([0]), but this one didn't come up during the build.
Quoted 8 lines
Quoted 3 lines
I guess the default build test doesn't enable
BUILD_BPF_SKEL?I see, right, I think I already asked about that before :( Is it possible to set
Makefilesuch that it will do BUILD_BPF_SKEL=1 if Clang version is recent enough and other conditions are satisfied (unless overridden or something)?
Arnaldo is working on this. I guess we can flip the default soon.
Quoted 55 lines
Quoted 55 lines
Quoted 32 lines
Quoted 5 lines
Do we plan to remove
bpf_create_mapin the future? If not, we can probably just add '#pragma GCC diagnostic ignored "-Wdeprecated-declarations"' can call it done?Yes, it will be removed in a few libbpf releases when we switch to the 1.0 version. So suppressing a warning is a temporary work-around.
Quoted 23 lines
Quoted 22 lines
Quoted 12 lines
Signed-off-by Song Liu <[email protected]>---
tools/perf/util/bpf_counter.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)tools/perf/util/bpf_counter.c +0
-0tools/perf/util/bpf_counter.c static int bperf_lock_attr_map(struct target *target) · line 323
Quoted 5 lines
tools/perf/util/bpf_counter.c +1
-1@@ -320,10 +320,10 @@ static int bperf_lock_attr_map(struct target *target) }if (access (path,F_OK )) { - map_fd = bpf_create_map(BPF_MAP_TYPE_HASH, + map_fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL,I think perf is trying to be linkable with libbpf as a shared library, so on some older versions of libbpf
bpf_map_create()won't be (yet) available. So to make this work, I think you'll need to define your own weakbpf_map_createfunction that will usebpf_create_map().Quoted 6 lines
Quoted 2 lines
Hmm... I didn't know the plan to link libbpf as shared library. In this case, maybe the #pragma solution is preferred?
See "perf tools: Add more weak libbpf functions" sent by Jiri not so long ago about what they did with some other used APIs that are now marked deprecated.
Do you mean something like this?
int
__weak
bpf_map_create(enumbpf_map_typemap_type,const char *map_name __maybe_unused, __u32 key_size, __u32 value_size, __u32 max_entries, const struct bpf_map_create_opts *opts __maybe_unused) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" return bpf_create_map(map_type, key_size, value_size, max_entries, 0);#pragma GCC diagnostic pop
}
Quoted 8 lines
Quoted 2 lines
I guess this won't work when
bpf_create_map()is eventually removed, as__weakfunction are still compiled, no?Yes and yes. I'm not sure what would be perf's plan w.r.t. libbpf 1.0, we'll need to work together to figure this out. At some point perf will need to say that the minimum version of supported libbpf is v0.6 or something and just assume all those newer APIs are there (no need to bump it all the way to libbpf 1.0, btw).
OK. I will send this version. And we can decide the next step when we remove bpf_create_map().
Thanks,
Song