bpftool: introduce prog profile
Subsystems (4)
v4 cover bpftool: introduce prog profile
This set introduces bpftool prog profile command, which uses hardware counters to profile BPF programs.
This command attaches fentry/fexit programs to a target program. These two programs read hardware counters before and after the target program and calculate the difference.
Changes v3 => v4:
1. Simplify err handling in profile_open_perf_events() (Quentin);
2. Remove redundant p_err() (Quentin);
3. Replace tab with space in bash-completion; (Quentin);
4. Fix typo _bpftool_get_map_names => _bpftool_get_prog_names (Quentin).
Changes v2 => v3:
1. Change order of arguments (Quentin), as:
bpftool prog profile PROG [duration DURATION] METRICs
2. Add bash-completion for bpftool prog profile (Quentin);
3. Fix build of selftests (Yonghong);
4. Better handling of bpf_map_lookup_elem() returns (Yonghong);
5. Improve clean up logic of do_profile() (Yonghong);
6. Other smaller fixes/cleanups.
Changes RFC => v2:
1. Use new bpf_program__set_attach_target() API;
2. Update output format to be perf-stat like (Alexei);
3. Incorporate skeleton generation into Makefile;
4. Make DURATION optional and Allow Ctrl-C (Alexei);
5. Add calcated values "insn per cycle" and "LLC misses per million isns".
Song Liu (4):
bpftool: introduce "prog profile" command
bpftool: Documentation for bpftool prog profile
bpftool: bash completion for "bpftool prog profile"
bpftool: fix typo in bash-completion
.../bpftool/Documentation/bpftool-prog.rst | 19 + tools/bpf/bpftool/Makefile | 18 + tools/bpf/bpftool/bash-completion/bpftool | 47 +- tools/bpf/bpftool/prog.c | 425 +++++++++++++++++- tools/bpf/bpftool/skeleton/profiler.bpf.c | 171 +++++++ tools/bpf/bpftool/skeleton/profiler.h | 47 ++ tools/scripts/Makefile.include | 1 + 7 files changed, 725 insertions(+), 3 deletions(-) create mode 100644 tools/bpf/bpftool/skeleton/profiler.bpf.c create mode 100644 tools/bpf/bpftool/skeleton/profiler.h
--
2.17.1
PATCH v4 1/4 bpftool: introduce "prog profile" command
With fentry/fexit programs, it is possible to profile BPF program with hardware counters. Introduce bpftool "prog profile", which measures key metrics of a BPF program.
bpftool prog profile command creates per-cpu perf events. Then it attaches fentry/fexit programs to the target BPF program. The fentry program saves perf event value to a map. The fexit program reads the perf event again, and calculates the difference, which is the instructions/cycles used by the target program.
Example input and output:
./bpftool prog profile id 337 duration 3 cycles instructions llc_misses
4228 run_cnt
3403698 cycles (84.08%)
3525294 instructions # 1.04 insn per cycle (84.05%)
13 llc_misses # 3.69 LLC misses per million isns (83.50%)This command measures cycles and instructions for BPF program with id 337 for 3 seconds. The program has triggered 4228 times. The rest of the output is similar to perf-stat. In this example, the counters were only counting ~84% of the time because of time multiplexing of perf counters.
Note that, this approach measures cycles and instructions in very small increments. So the fentry/fexit programs introduce noticeable errors to the measurement results.
The fentry/fexit programs are generated with BPF skeletons. Therefore, we build bpftool twice. The first time _bpftool is built without skeletons. Then, _bpftool is used to generate the skeletons. The second time, bpftool is built with skeletons.
--- tools/bpf/bpftool/Makefile | 18 + tools/bpf/bpftool/prog.c | 425 +++++++++++++++++++++- tools/bpf/bpftool/skeleton/profiler.bpf.c | 171 +++++++++ tools/bpf/bpftool/skeleton/profiler.h | 47 +++ tools/scripts/Makefile.include | 1 + 5 files changed, 661 insertions(+), 1 deletion(-) create mode 100644 tools/bpf/bpftool/skeleton/profiler.bpf.c create mode 100644 tools/bpf/bpftool/skeleton/profiler.h
tools/bpf/bpftool/Makefile +18 -0
@@ -59,6 +59,7 @@ LIBS = $(LIBBPF) -lelf -lz INSTALL ?= install RM ?= rm -f +CLANG ?= clang FEATURE_USER = .bpftool FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib
@@ -110,6 +111,22 @@ SRCS += $(BFD_SRCS) endif OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o +_OBJS = $(filter-out $(OUTPUT)prog.o,$(OBJS)) $(OUTPUT)_prog.o + +$(OUTPUT)_prog.o: prog.c + $(QUIET_CC)$(COMPILE.c) -MMD -DBPFTOOL_WITHOUT_SKELETONS -o $@ $< + +$(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF) + $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(_OBJS) $(LIBS) + +skeleton/profiler.bpf.o: skeleton/profiler.bpf.c + $(QUIET_CLANG)$(CLANG) -I$(srctree)/tools/lib -g -O2 -target bpf -c $< -o $@ + +profiler.skel.h: $(OUTPUT)_bpftool skeleton/profiler.bpf.o + $(QUIET_GEN)$(OUTPUT)./_bpftool gen skeleton skeleton/profiler.bpf.o > $@ + +$(OUTPUT)prog.o: prog.c profiler.skel.h + $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $< $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
@@ -125,6 +142,7 @@ $(OUTPUT)%.o: %.c clean: $(LIBBPF)-clean $(call QUIET_CLEAN, bpftool) $(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d + $(Q)$(RM) -- $(OUTPUT)_bpftool profiler.skel.h skeleton/profiler.bpf.o $(Q)$(RM) -r -- $(OUTPUT)libbpf/ $(call QUIET_CLEAN, core-gen) $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpftool
tools/bpf/bpftool/prog.c +424 -1
470 lines not on this page · raw message
tools/bpf/bpftool/skeleton/profiler.bpf.c new file +171 -0
171 lines not on this page · raw message
tools/bpf/bpftool/skeleton/profiler.h new file +47 -0
47 lines not on this page · raw message
tools/scripts/Makefile.include +1 -0
@@ -106,6 +106,7 @@ ifneq ($(silent),1) ifneq ($(V),1) QUIET_CC = @echo ' CC '$@; QUIET_CC_FPIC = @echo ' CC FPIC '$@; + QUIET_CLANG = @echo ' CLANG '$@; QUIET_AR = @echo ' AR '$@; QUIET_LINK = @echo ' LINK '$@; QUIET_MKDIR = @echo ' MKDIR '$@;
Signature · 1 line
2.17.1
Re: [PATCH v4 bpf-next 1/4] bpftool: introduce "prog profile" command
Quoted 10 lines · Song Liu
With fentry/fexit programs, it is possible to profile BPF program with hardware counters. Introduce bpftool "prog profile", which measures key metrics of a BPF program.
bpftool prog profile command creates per-cpu perf events. Then it attaches fentry/fexit programs to the target BPF program. The fentry program saves perf event value to a map. The fexit program reads the perf event again, and calculates the difference, which is the instructions/cycles used by the target program.
Quoted 8 lines
Example input and output:
./bpftool prog profile id 337 duration 3 cycles instructions
llc_misses4228 run_cnt 3403698 cycles (84.08%) 3525294 instructions # 1.04 insn per cycle (84.05%) 13 llc_misses # 3.69 LLC misses per million isns (83.50%)
FYI I'm in the middle of moving perf's 'events parsing' interface to libperf, which takes event name/s on input and returns list of perf_event_attr objects
parse_events("cycles") -> ready to use 'struct perf_event_attr'
You can use any event that's listed in 'perf list' command, which includes also all vendor (Intel/Arm/ppc..) events. It might be useful extension for this command.
jirka
Re: [PATCH v4 bpf-next 1/4] bpftool: introduce "prog profile" command
Quoted 24 lines · Jiri Olsa
Quoted 10 lines · Song Liu
With fentry/fexit programs, it is possible to profile BPF program with hardware counters. Introduce bpftool "prog profile", which measures key metrics of a BPF program.
bpftool prog profile command creates per-cpu perf events. Then it attaches fentry/fexit programs to the target BPF program. The fentry program saves perf event value to a map. The fexit program reads the perf event again, and calculates the difference, which is the instructions/cycles used by the target program.
Quoted 8 lines
Example input and output:
./bpftool prog profile id 337 duration 3 cycles instructions
llc_misses4228 run_cnt 3403698 cycles (84.08%) 3525294 instructions # 1.04 insn per cycle (84.05%) 13 llc_misses # 3.69 LLC misses per million isns (83.50%)
Quoted 8 lines
FYI I'm in the middle of moving perf's 'events parsing' interface to libperf, which takes event name/s on input and returns list of
perf_event_attrobjects
parse_events("cycles")-> ready to use 'structperf_event_attr'You can use any event that's listed in 'perf list' command, which includes also all vendor (Intel/Arm/ppc..) events. It might be useful extension for this command.
That's great news! Thanks for the information!
Song
Re: [PATCH v4 bpf-next 1/4] bpftool: introduce "prog profile" command
In reply to Song LiuOn Wed, Mar 04, 2020 at 10:07:07AM -0800, Song Liu wrote:
SNIP
Quoted 9 lines
tools/bpf/bpftool/prog.c +9
-0+ +#include "profiler.skel.h" + +#define SAMPLE_PERIOD 0x7fffffffffffffffULL +struct profile_metric { +const char *name; +struct bpf_perf_event_value val; +struct perf_event_attr attr; +bool selected;
tools/bpf/bpftool/prog.c static int do_loadall(int argc, char **argv) · line 1570
Quoted 10 lines
tools/bpf/bpftool/prog.c +10
-0+ +/* calculate ratios like instructions per cycle */ +const int ratio_metric;/* 0 for N/A, 1 for index 0 (cycles) */ +const char *ratio_desc; +const float ratio_mul; +} metrics[] = { + { + .name = "cycles", + .attr = { + .sample_period = SAMPLE_PERIOD,
I don't think you need to set sample_period for counting.. why?
tools/bpf/bpftool/prog.c static int do_loadall(int argc, char **argv) · line 1572
Quoted 2 lines
tools/bpf/bpftool/prog.c +2
-0+ .type = PERF_TYPE_HARDWARE, + .config = PERF_COUNT_HW_CPU_CYCLES,
you could also add .exclude_user = 1
jirka
Re: [PATCH v4 bpf-next 1/4] bpftool: introduce "prog profile" command
Quoted 30 lines · Jiri Olsa
On Wed, Mar 04, 2020 at 10:07:07AM -0800, Song Liu wrote:
SNIP
Quoted 9 lines
tools/bpf/bpftool/prog.c +9
-0+ +#include "profiler.skel.h" + +#define SAMPLE_PERIOD 0x7fffffffffffffffULL +struct profile_metric { +const char *name; +struct bpf_perf_event_value val; +struct perf_event_attr attr; +bool selected;tools/bpf/bpftool/prog.c static int do_loadall(int argc, char **argv) · line 1570
Quoted 10 lines
tools/bpf/bpftool/prog.c +10
-0+ +/* calculate ratios like instructions per cycle */ +const int ratio_metric;/* 0 for N/A, 1 for index 0 (cycles) */ +const char *ratio_desc; +const float ratio_mul; +} metrics[] = { + { + .name = "cycles", + .attr = { + .sample_period = SAMPLE_PERIOD,I don't think you need to set
sample_periodfor counting.. why?
Quoted 4 lines
tools/bpf/bpftool/prog.c static int do_loadall(int argc, char **argv) · line 1572
Quoted 2 lines
tools/bpf/bpftool/prog.c +2
-0+ .type = PERF_TYPE_HARDWARE, + .config = PERF_COUNT_HW_CPU_CYCLES,you could also add .exclude_user = 1
Fixed this in v5. Thanks!
Song
PATCH v4 2/4 bpftool: Documentation for bpftool prog profile
In reply to Song LiuAdd documentation for the new bpftool prog profile command.
--- .../bpftool/Documentation/bpftool-prog.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
tools/bpf/bpftool/Documentation/bpftool-prog.rst +19 -0
@@ -30,6 +30,7 @@ PROG COMMANDS | **bpftool** **prog detach** *PROG* *ATTACH_TYPE* [*MAP*] | **bpftool** **prog tracelog** | **bpftool** **prog run** *PROG* **data_in** *FILE* [**data_out** *FILE* [**data_size_out** *L*]] [**ctx_in** *FILE* [**ctx_out** *FILE* [**ctx_size_out** *M*]]] [**repeat** *N*] +| **bpftool** **prog profile** *PROG* [**duration** *DURATION*] *METRICs* | **bpftool** **prog help** | | *MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
@@ -48,6 +49,9 @@ PROG COMMANDS | *ATTACH_TYPE* := { | **msg_verdict** | **stream_verdict** | **stream_parser** | **flow_dissector** | } +| *METRIC* := { +| **cycles** | **instructions** | **l1d_loads** | **llc_misses** +| } DESCRIPTION
@@ -189,6 +193,12 @@ DESCRIPTION not all of them can take the **ctx_in**/**ctx_out** arguments. bpftool does not perform checks on program types. + **bpftool prog profile** *PROG* [**duration** *DURATION*] *METRICs* + Profile *METRICs* for bpf program *PROG* for *DURATION* + seconds or until user hits Ctrl-C. *DURATION* is optional. + If *DURATION* is not specified, the profiling will run up to + UINT_MAX seconds. + **bpftool prog help** Print short help message.
@@ -311,6 +321,15 @@ EXAMPLES **# rm /sys/fs/bpf/xdp1** +| +| **# bpftool prog profile id 337 duration 10 cycles instructions llc_misses** + +:: + 51397 run_cnt + 40176203 cycles (83.05%) + 42518139 instructions # 1.06 insns per cycle (83.39%) + 123 llc_misses # 2.89 LLC misses per million insns (83.15%) + SEE ALSO ======== **bpf**\ (2),
Signature · 1 line
2.17.1
PATCH v4 3/4 bpftool: bash completion for "bpftool prog profile"
In reply to Song LiuAdd bash completion for "bpftool prog profile" command.
--- tools/bpf/bpftool/bash-completion/bpftool | 45 ++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
tools/bpf/bpftool/bash-completion/bpftool +44 -1
@@ -337,6 +337,7 @@ _bpftool() local PROG_TYPE='id pinned tag name' local MAP_TYPE='id pinned name' + local METRIC_TYPE='cycles instructions l1d_loads llc_misses' case $command in show|list) [[ $prev != "$command" ]] && return 0
@@ -498,6 +499,48 @@ _bpftool() tracelog) return 0 ;; + profile) + case $cword in + 3) + COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) ) + return 0 + ;; + 4) + case $prev in + id) + _bpftool_get_prog_ids + ;; + name) + _bpftool_get_prog_names + ;; + pinned) + _filedir + ;; + esac + return 0 + ;; + 5) + COMPREPLY=( $( compgen -W "$METRIC_TYPE duration" -- "$cur" ) ) + return 0 + ;; + 6) + case $prev in + duration) + return 0 + ;; + *) + COMPREPLY=( $( compgen -W "$METRIC_TYPE" -- "$cur" ) ) + return 0 + ;; + esac + return 0 + ;; + *) + COMPREPLY=( $( compgen -W "$METRIC_TYPE" -- "$cur" ) ) + return 0 + ;; + esac + ;; run) if [[ ${#words[@]} -lt 5 ]]; then _filedir
@@ -525,7 +568,7 @@ _bpftool() *) [[ $prev == $object ]] && \ COMPREPLY=( $( compgen -W 'dump help pin attach detach \ - load loadall show list tracelog run' -- "$cur" ) ) + load loadall show list tracelog run profile' -- "$cur" ) ) ;; esac ;;
Signature · 1 line
2.17.1
PATCH v4 4/4 bpftool: fix typo in bash-completion
In reply to Song Liu_bpftool_get_map_names => _bpftool_get_prog_names for prog-attach|detach.
--- tools/bpf/bpftool/bash-completion/bpftool | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/bash-completion/bpftool +1 -1
@@ -389,7 +389,7 @@ _bpftool() _bpftool_get_prog_ids ;; name) - _bpftool_get_map_names + _bpftool_get_prog_names ;; pinned) _filedir
Signature · 1 line
2.17.1
Quoted 7 lines · Song Liu
This set introduces bpftool prog profile command, which uses hardware counters to profile BPF programs.
This command attaches fentry/fexit programs to a target program. These two programs read hardware counters before and after the target program and calculate the difference.
Quoted 5 lines
Changes v3 => v4:
1. Simplify err handling inprofile_open_perf_events()(Quentin);
2. Remove redundantp_err()(Quentin);
3. Replace tab with space in bash-completion; (Quentin);
4. Fix typo_bpftool_get_map_names=>_bpftool_get_prog_names(Quentin).
hum, I'm getting:
[jolsa@dell-r440-01 bpftool]$ pwd /home/jolsa/linux-perf/tools/bpf/bpftool [jolsa@dell-r440-01 bpftool]$ make ... make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf' LINK _bpftool make: *** No rule to make target 'skeleton/profiler.bpf.c', needed by 'skeleton/profiler.bpf.o'. Stop.
jirka
Quoted 37 lines
Changes v2 => v3:
1. Change order of arguments (Quentin), as:
bpftool prog profile PROG [duration DURATION] METRICs
2. Add bash-completion for bpftool prog profile (Quentin);
3. Fix build of selftests (Yonghong);
4. Better handling ofbpf_map_lookup_elem()returns (Yonghong);
5. Improve clean up logic ofdo_profile()(Yonghong);
6. Other smaller fixes/cleanups.Changes RFC => v2:
1. Use newbpf_program__set_attach_target()API;
2. Update output format to be perf-stat like (Alexei);
3. Incorporate skeleton generation intoMakefile;
4. Make DURATION optional and Allow Ctrl-C (Alexei);
5. Add calcated values "insn per cycle" and "LLC misses per million isns".Song Liu (4):
bpftool: introduce "prog profile" command
bpftool: Documentation for bpftool prog profile
bpftool: bash completion for "bpftool prog profile"
bpftool: fix typo in bash-completion.../bpftool/Documentation/bpftool-prog.rst | 19 + tools/bpf/bpftool/Makefile | 18 + tools/bpf/bpftool/bash-completion/bpftool | 47 +- tools/bpf/bpftool/prog.c | 425 +++++++++++++++++- tools/bpf/bpftool/skeleton/profiler.bpf.c | 171 +++++++ tools/bpf/bpftool/skeleton/profiler.h | 47 ++ tools/scripts/Makefile.include | 1 + 7 files changed, 725 insertions(+), 3 deletions(-) create mode 100644 tools/bpf/bpftool/skeleton/profiler.bpf.c create mode 100644 tools/bpf/bpftool/skeleton/profiler.h--
2.17.1
Quoted 16 lines · Jiri Olsa
Quoted 7 lines · Song Liu
This set introduces bpftool prog profile command, which uses hardware counters to profile BPF programs.
This command attaches fentry/fexit programs to a target program. These two programs read hardware counters before and after the target program and calculate the difference.
Quoted 5 lines
Changes v3 => v4:
1. Simplify err handling inprofile_open_perf_events()(Quentin);
2. Remove redundantp_err()(Quentin);
3. Replace tab with space in bash-completion; (Quentin);
4. Fix typo_bpftool_get_map_names=>_bpftool_get_prog_names(Quentin).hum, I'm getting:
Quoted 7 lines
[jolsa@dell-r440-01 bpftool]$ pwd /home/jolsa/linux-perf/tools/bpf/bpftool [jolsa@dell-r440-01 bpftool]$ make ... make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf' LINK _bpftool make: *** No rule to make target 'skeleton/profiler.bpf.c', needed by 'skeleton/profiler.bpf.o'. Stop.
ok, I had to apply your patches by hand, because 'git am' refused to due to fuzz.. so some of you new files did not make it to my tree ;-)
anyway I hit another error now:
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 | __u32 m, cpu, num_cpu = obj->rodata->num_cpu;
I'll try to figure it out.. might be error on my end
do you have git repo with these changes?
thanks,
jirka
Quoted 44 lines · Jiri Olsa
Quoted 16 lines · Jiri Olsa
Quoted 7 lines · Song Liu
This set introduces bpftool prog profile command, which uses hardware counters to profile BPF programs.
This command attaches fentry/fexit programs to a target program. These two programs read hardware counters before and after the target program and calculate the difference.
Quoted 5 lines
Changes v3 => v4:
1. Simplify err handling inprofile_open_perf_events()(Quentin);
2. Remove redundantp_err()(Quentin);
3. Replace tab with space in bash-completion; (Quentin);
4. Fix typo_bpftool_get_map_names=>_bpftool_get_prog_names(Quentin).hum, I'm getting:
Quoted 7 lines
[jolsa@dell-r440-01 bpftool]$ pwd /home/jolsa/linux-perf/tools/bpf/bpftool [jolsa@dell-r440-01 bpftool]$ make ... make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf' LINK _bpftool make: *** No rule to make target 'skeleton/profiler.bpf.c', needed by 'skeleton/profiler.bpf.o'. Stop.ok, I had to apply your patches by hand, because 'git am' refused to due to fuzz.. so some of you new files did not make it to my tree ;-)
anyway I hit another error now:
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;
Quoted 3 lines
I'll try to figure it out.. might be error on my end
do you have git repo with these changes?
I pushed it to
https://git.kernel.org/pub/scm/linux/kernel/git/song/linux.git/tree/?h=bpf-per-prog-stats
Thanks,
Song
Quoted 44 lines · Song Liu
Quoted 44 lines · Jiri Olsa
Quoted 16 lines · Jiri Olsa
Quoted 7 lines · Song Liu
This set introduces bpftool prog profile command, which uses hardware counters to profile BPF programs.
This command attaches fentry/fexit programs to a target program. These two programs read hardware counters before and after the target program and calculate the difference.
Quoted 5 lines
Changes v3 => v4:
1. Simplify err handling inprofile_open_perf_events()(Quentin);
2. Remove redundantp_err()(Quentin);
3. Replace tab with space in bash-completion; (Quentin);
4. Fix typo_bpftool_get_map_names=>_bpftool_get_prog_names(Quentin).hum, I'm getting:
Quoted 7 lines
[jolsa@dell-r440-01 bpftool]$ pwd /home/jolsa/linux-perf/tools/bpf/bpftool [jolsa@dell-r440-01 bpftool]$ make ... make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf' LINK _bpftool make: *** No rule to make target 'skeleton/profiler.bpf.c', needed by 'skeleton/profiler.bpf.o'. Stop.ok, I had to apply your patches by hand, because 'git am' refused to due to fuzz.. so some of you new files did not make it to my tree ;-)
anyway I hit another error now:
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;
Quoted 7 lines
Quoted 3 lines
I'll try to figure it out.. might be error on my end
do you have git repo with these changes?
I pushed it to
https://git.kernel.org/pub/scm/linux/kernel/git/song/linux.git/tree/?h=bpf-per-prog-stats
still the same:
[jolsa@dell-r440-01 bpftool]$ git show --oneline HEAD | head -1 7bbda5cca00a bpftool: fix typo in bash-completion [jolsa@dell-r440-01 bpftool]$ make
make[1]: Entering directory '/home/jolsa/linux-perf/tools/lib/bpf' make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf'
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 | __u32 m, cpu, num_cpu = obj->rodata->num_cpu;
| ^~
prog.c: In function ‘profile_open_perf_events’:
prog.c:1810:19: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int), obj->rodata->num_cpu * obj->rodata->num_metric);
| ^~
prog.c:1810:42: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int), obj->rodata->num_cpu * obj->rodata->num_metric);
| ^~
prog.c:1825:26: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1825 | for (cpu = 0; cpu < obj->rodata->num_cpu; cpu++) {
| ^~
prog.c: In function ‘do_profile’:
prog.c:1904:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1904 | profile_obj->rodata->num_cpu = num_cpu;
| ^~
prog.c:1905:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1905 | profile_obj->rodata->num_metric = num_metric;
| ^~
make: *** [Makefile:129: prog.o] Error 1
jirka
Quoted 84 lines · Jiri Olsa
Quoted 44 lines · Song Liu
Quoted 44 lines · Jiri Olsa
Quoted 16 lines · Jiri Olsa
Quoted 7 lines · Song Liu
This set introduces bpftool prog profile command, which uses hardware counters to profile BPF programs.
This command attaches fentry/fexit programs to a target program. These two programs read hardware counters before and after the target program and calculate the difference.
Quoted 5 lines
Changes v3 => v4:
1. Simplify err handling inprofile_open_perf_events()(Quentin);
2. Remove redundantp_err()(Quentin);
3. Replace tab with space in bash-completion; (Quentin);
4. Fix typo_bpftool_get_map_names=>_bpftool_get_prog_names(Quentin).hum, I'm getting:
Quoted 7 lines
[jolsa@dell-r440-01 bpftool]$ pwd /home/jolsa/linux-perf/tools/bpf/bpftool [jolsa@dell-r440-01 bpftool]$ make ... make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf' LINK _bpftool make: *** No rule to make target 'skeleton/profiler.bpf.c', needed by 'skeleton/profiler.bpf.o'. Stop.ok, I had to apply your patches by hand, because 'git am' refused to due to fuzz.. so some of you new files did not make it to my tree ;-)
anyway I hit another error now:
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;Quoted 7 lines
Quoted 3 lines
I'll try to figure it out.. might be error on my end
do you have git repo with these changes?
I pushed it to
https://git.kernel.org/pub/scm/linux/kernel/git/song/linux.git/tree/?h=bpf-per-prog-stats
still the same:
[jolsa@dell-r440-01 bpftool]$ git show --oneline HEAD | head -1
7bbda5cca00abpftool: fix typo in bash-completion [jolsa@dell-r440-01 bpftool]$ make
make[1]: Entering directory '/home/jolsa/linux-perf/tools/lib/bpf' make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf'
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;
| ^~
prog.c: In function ‘profile_open_perf_events’:
prog.c:1810:19: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int),obj->rodata->num_cpu*obj->rodata->num_metric);
| ^~
prog.c:1810:42: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int),obj->rodata->num_cpu*obj->rodata->num_metric);
| ^~
prog.c:1825:26: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1825 | for (cpu = 0; cpu <obj->rodata->num_cpu; cpu++) {
| ^~
Quoted 8 lines
prog.c: In function ‘do_profile’:
prog.c:1904:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1904 |profile_obj->rodata->num_cpu=num_cpu;
| ^~
prog.c:1905:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1905 |profile_obj->rodata->num_metric=num_metric;
| ^~
make: *** [Makefile:129: prog.o] Error 1
I guess you need a newer version of clang that supports global data in BPF programs.
Thanks,
Song
Quoted 97 lines · Song Liu
Quoted 85 lines · Jiri Olsa
Quoted 44 lines · Song Liu
Quoted 44 lines · Jiri Olsa
Quoted 16 lines · Jiri Olsa
Quoted 7 lines · Song Liu
This set introduces bpftool prog profile command, which uses hardware counters to profile BPF programs.
This command attaches fentry/fexit programs to a target program. These two programs read hardware counters before and after the target program and calculate the difference.
Quoted 5 lines
Changes v3 => v4:
1. Simplify err handling inprofile_open_perf_events()(Quentin);
2. Remove redundantp_err()(Quentin);
3. Replace tab with space in bash-completion; (Quentin);
4. Fix typo_bpftool_get_map_names=>_bpftool_get_prog_names(Quentin).hum, I'm getting:
Quoted 7 lines
[jolsa@dell-r440-01 bpftool]$ pwd /home/jolsa/linux-perf/tools/bpf/bpftool [jolsa@dell-r440-01 bpftool]$ make ... make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf' LINK _bpftool make: *** No rule to make target 'skeleton/profiler.bpf.c', needed by 'skeleton/profiler.bpf.o'. Stop.ok, I had to apply your patches by hand, because 'git am' refused to due to fuzz.. so some of you new files did not make it to my tree ;-)
anyway I hit another error now:
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;Quoted 7 lines
Quoted 3 lines
I'll try to figure it out.. might be error on my end
do you have git repo with these changes?
I pushed it to
https://git.kernel.org/pub/scm/linux/kernel/git/song/linux.git/tree/?h=bpf-per-prog-stats
still the same:
[jolsa@dell-r440-01 bpftool]$ git show --oneline HEAD | head -1
7bbda5cca00abpftool: fix typo in bash-completion [jolsa@dell-r440-01 bpftool]$ make
make[1]: Entering directory '/home/jolsa/linux-perf/tools/lib/bpf' make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf'
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;
| ^~
prog.c: In function ‘profile_open_perf_events’:
prog.c:1810:19: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int),obj->rodata->num_cpu*obj->rodata->num_metric);
| ^~
prog.c:1810:42: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int),obj->rodata->num_cpu*obj->rodata->num_metric);
| ^~
prog.c:1825:26: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1825 | for (cpu = 0; cpu <obj->rodata->num_cpu; cpu++) {
| ^~Quoted 8 lines
prog.c: In function ‘do_profile’:
prog.c:1904:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1904 |profile_obj->rodata->num_cpu=num_cpu;
| ^~
prog.c:1905:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1905 |profile_obj->rodata->num_metric=num_metric;
| ^~
make: *** [Makefile:129: prog.o] Error 1
Quoted 1 line
I guess you need a newer version of clang that supports global data in BPF programs.
Hi Jiri,
Have you got chance to test this with latest clang?
Thanks,
Song
On Thu, Mar 05, 2020 at 08:03:53PM +0000, Song Liu wrote:
SNIP
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;
| ^~
prog.c: In function ‘profile_open_perf_events’:
prog.c:1810:19: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int),obj->rodata->num_cpu*obj->rodata->num_metric);
| ^~
prog.c:1810:42: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int),obj->rodata->num_cpu*obj->rodata->num_metric);
| ^~
prog.c:1825:26: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1825 | for (cpu = 0; cpu <obj->rodata->num_cpu; cpu++) {
| ^~
prog.c: In function ‘do_profile’:
prog.c:1904:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1904 |profile_obj->rodata->num_cpu=num_cpu;
| ^~
prog.c:1905:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1905 |profile_obj->rodata->num_metric=num_metric;
| ^~
make: *** [Makefile:129: prog.o] Error 1
Quoted 5 lines
Quoted 1 line
I guess you need a newer version of clang that supports global data in BPF programs.
Hi Jiri,
Have you got chance to test this with latest clang?
yep, got it compiled with new clang
I was testing in on bpftrace programs and couldn't made it work, because it relies on BTF info.. so I got stuck ;-)
# bpftool prog profile id 241 duration 3 cycles instructions llc_misses Error: prog FD 3 doesn't have valid btf
nit.. ^^^ you could display ID instead of FD in here
I need to check if we can provide BTF info for bpftrace programs
jirka
2020-03-04 21:39 UTC+0000 ~ Song Liu <[email protected]>
Quoted 93 lines
Quoted 84 lines · Jiri Olsa
Quoted 44 lines · Song Liu
Quoted 44 lines · Jiri Olsa
Quoted 16 lines · Jiri Olsa
Quoted 7 lines · Song Liu
This set introduces bpftool prog profile command, which uses hardware counters to profile BPF programs.
This command attaches fentry/fexit programs to a target program. These two programs read hardware counters before and after the target program and calculate the difference.
Quoted 5 lines
Changes v3 => v4:
1. Simplify err handling inprofile_open_perf_events()(Quentin);
2. Remove redundantp_err()(Quentin);
3. Replace tab with space in bash-completion; (Quentin);
4. Fix typo_bpftool_get_map_names=>_bpftool_get_prog_names(Quentin).hum, I'm getting:
Quoted 7 lines
[jolsa@dell-r440-01 bpftool]$ pwd /home/jolsa/linux-perf/tools/bpf/bpftool [jolsa@dell-r440-01 bpftool]$ make ... make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf' LINK _bpftool make: *** No rule to make target 'skeleton/profiler.bpf.c', needed by 'skeleton/profiler.bpf.o'. Stop.ok, I had to apply your patches by hand, because 'git am' refused to due to fuzz.. so some of you new files did not make it to my tree ;-)
anyway I hit another error now:
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;Quoted 7 lines
Quoted 3 lines
I'll try to figure it out.. might be error on my end
do you have git repo with these changes?
I pushed it to
https://git.kernel.org/pub/scm/linux/kernel/git/song/linux.git/tree/?h=bpf-per-prog-stats
still the same:
[jolsa@dell-r440-01 bpftool]$ git show --oneline HEAD | head -1
7bbda5cca00abpftool: fix typo in bash-completion [jolsa@dell-r440-01 bpftool]$ make
make[1]: Entering directory '/home/jolsa/linux-perf/tools/lib/bpf' make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf'
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;
| ^~
prog.c: In function ‘profile_open_perf_events’:
prog.c:1810:19: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int),obj->rodata->num_cpu*obj->rodata->num_metric);
| ^~
prog.c:1810:42: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int),obj->rodata->num_cpu*obj->rodata->num_metric);
| ^~
prog.c:1825:26: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1825 | for (cpu = 0; cpu <obj->rodata->num_cpu; cpu++) {
| ^~Quoted 8 lines
prog.c: In function ‘do_profile’:
prog.c:1904:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1904 |profile_obj->rodata->num_cpu=num_cpu;
| ^~
prog.c:1905:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1905 |profile_obj->rodata->num_metric=num_metric;
| ^~
make: *** [Makefile:129: prog.o] Error 1
Quoted 5 lines
I guess you need a newer version of clang that supports global data in BPF programs.
Thanks,
Song
Thinking about this requirement again... Do you think it would be worth adding (as a follow-up) a feature check on the availability of clang with global data support to bpftool's Makefile? So that we could compile out program profiling if clang is not present or does not support it. Just like libbfd support is optional already.
I'm asking mostly because a number of distributions now package bpftool, and e.g. Ubuntu builds it from kernel source when creating its linux-images and linux-tools-* packages. And I am pretty sure the build environment does not have latest clang/LLVM, but it would be great to remain able to build bpftool.
Best regards,
Quentin
Quoted 110 lines · Quentin Monnet
2020-03-04 21:39 UTC+0000 ~ Song Liu <[email protected]>
Quoted 93 lines
Quoted 84 lines · Jiri Olsa
Quoted 44 lines · Song Liu
Quoted 44 lines · Jiri Olsa
Quoted 16 lines · Jiri Olsa
Quoted 7 lines · Song Liu
This set introduces bpftool prog profile command, which uses hardware counters to profile BPF programs.
This command attaches fentry/fexit programs to a target program. These two programs read hardware counters before and after the target program and calculate the difference.
Quoted 5 lines
Changes v3 => v4:
1. Simplify err handling inprofile_open_perf_events()(Quentin);
2. Remove redundantp_err()(Quentin);
3. Replace tab with space in bash-completion; (Quentin);
4. Fix typo_bpftool_get_map_names=>_bpftool_get_prog_names(Quentin).hum, I'm getting:
Quoted 7 lines
[jolsa@dell-r440-01 bpftool]$ pwd /home/jolsa/linux-perf/tools/bpf/bpftool [jolsa@dell-r440-01 bpftool]$ make ... make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf' LINK _bpftool make: *** No rule to make target 'skeleton/profiler.bpf.c', needed by 'skeleton/profiler.bpf.o'. Stop.ok, I had to apply your patches by hand, because 'git am' refused to due to fuzz.. so some of you new files did not make it to my tree ;-)
anyway I hit another error now:
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;Quoted 7 lines
Quoted 3 lines
I'll try to figure it out.. might be error on my end
do you have git repo with these changes?
I pushed it to
https://git.kernel.org/pub/scm/linux/kernel/git/song/linux.git/tree/?h=bpf-per-prog-stats
still the same:
[jolsa@dell-r440-01 bpftool]$ git show --oneline HEAD | head -1
7bbda5cca00abpftool: fix typo in bash-completion [jolsa@dell-r440-01 bpftool]$ make
make[1]: Entering directory '/home/jolsa/linux-perf/tools/lib/bpf' make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf'
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;
| ^~
prog.c: In function ‘profile_open_perf_events’:
prog.c:1810:19: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int),obj->rodata->num_cpu*obj->rodata->num_metric);
| ^~
prog.c:1810:42: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int),obj->rodata->num_cpu*obj->rodata->num_metric);
| ^~
prog.c:1825:26: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1825 | for (cpu = 0; cpu <obj->rodata->num_cpu; cpu++) {
| ^~Quoted 8 lines
prog.c: In function ‘do_profile’:
prog.c:1904:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1904 |profile_obj->rodata->num_cpu=num_cpu;
| ^~
prog.c:1905:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1905 |profile_obj->rodata->num_metric=num_metric;
| ^~
make: *** [Makefile:129: prog.o] Error 1Quoted 5 lines
I guess you need a newer version of clang that supports global data in BPF programs.
Thanks,
SongThinking about this requirement again... Do you think it would be worth adding (as a follow-up) a feature check on the availability of clang with global data support to bpftool's
Makefile? So that we could compile out program profiling if clang is not present or does not support it. Just like libbfd support is optional already.
Quoted 5 lines
I'm asking mostly because a number of distributions now package bpftool, and e.g. Ubuntu builds it from kernel source when creating its linux-images and linux-tools-* packages. And I am pretty sure the build environment does not have latest clang/LLVM, but it would be great to remain able to build bpftool.
Yeah, I think it is a good idea. Some more Makefile fun. ;)
Thanks,
Song
Quoted 110 lines · Song Liu
Quoted 110 lines · Quentin Monnet
2020-03-04 21:39 UTC+0000 ~ Song Liu <[email protected]>
Quoted 93 lines
Quoted 84 lines · Jiri Olsa
Quoted 44 lines · Song Liu
Quoted 44 lines · Jiri Olsa
Quoted 16 lines · Jiri Olsa
Quoted 7 lines · Song Liu
This set introduces bpftool prog profile command, which uses hardware counters to profile BPF programs.
This command attaches fentry/fexit programs to a target program. These two programs read hardware counters before and after the target program and calculate the difference.
Quoted 5 lines
Changes v3 => v4:
1. Simplify err handling inprofile_open_perf_events()(Quentin);
2. Remove redundantp_err()(Quentin);
3. Replace tab with space in bash-completion; (Quentin);
4. Fix typo_bpftool_get_map_names=>_bpftool_get_prog_names(Quentin).hum, I'm getting:
Quoted 7 lines
[jolsa@dell-r440-01 bpftool]$ pwd /home/jolsa/linux-perf/tools/bpf/bpftool [jolsa@dell-r440-01 bpftool]$ make ... make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf' LINK _bpftool make: *** No rule to make target 'skeleton/profiler.bpf.c', needed by 'skeleton/profiler.bpf.o'. Stop.ok, I had to apply your patches by hand, because 'git am' refused to due to fuzz.. so some of you new files did not make it to my tree ;-)
anyway I hit another error now:
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;Quoted 7 lines
Quoted 3 lines
I'll try to figure it out.. might be error on my end
do you have git repo with these changes?
I pushed it to
https://git.kernel.org/pub/scm/linux/kernel/git/song/linux.git/tree/?h=bpf-per-prog-stats
still the same:
[jolsa@dell-r440-01 bpftool]$ git show --oneline HEAD | head -1
7bbda5cca00abpftool: fix typo in bash-completion [jolsa@dell-r440-01 bpftool]$ make
make[1]: Entering directory '/home/jolsa/linux-perf/tools/lib/bpf' make[1]: Leaving directory '/home/jolsa/linux-perf/tools/lib/bpf'
CC prog.o
In file included from prog.c:1553:
profiler.skel.h: In function ‘profiler_bpf__create_skeleton’:
profiler.skel.h:136:35: error: ‘struct profiler_bpf’ has no member named ‘rodata’
136 | s->maps[4].mmaped = (void **)&obj->rodata;
| ^~
prog.c: In function ‘profile_read_values’:
prog.c:1650:29: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1650 |__u32m, cpu,num_cpu=obj->rodata->num_cpu;
| ^~
prog.c: In function ‘profile_open_perf_events’:
prog.c:1810:19: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int),obj->rodata->num_cpu*obj->rodata->num_metric);
| ^~
prog.c:1810:42: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1810 | sizeof(int),obj->rodata->num_cpu*obj->rodata->num_metric);
| ^~
prog.c:1825:26: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1825 | for (cpu = 0; cpu <obj->rodata->num_cpu; cpu++) {
| ^~Quoted 8 lines
prog.c: In function ‘do_profile’:
prog.c:1904:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1904 |profile_obj->rodata->num_cpu=num_cpu;
| ^~
prog.c:1905:13: error: ‘struct profiler_bpf’ has no member named ‘rodata’
1905 |profile_obj->rodata->num_metric=num_metric;
| ^~
make: *** [Makefile:129: prog.o] Error 1Quoted 5 lines
I guess you need a newer version of clang that supports global data in BPF programs.
Thanks,
SongThinking about this requirement again... Do you think it would be worth adding (as a follow-up) a feature check on the availability of clang with global data support to bpftool's
Makefile? So that we could compile out program profiling if clang is not present or does not support it. Just like libbfd support is optional already.
Quoted 7 lines
Quoted 5 lines
I'm asking mostly because a number of distributions now package bpftool, and e.g. Ubuntu builds it from kernel source when creating its linux-images and linux-tools-* packages. And I am pretty sure the build environment does not have latest clang/LLVM, but it would be great to remain able to build bpftool.
Yeah, I think it is a good idea. Some more
Makefilefun. ;)
I think it's good idea, also bpftool is already using feature detection from tools/build/features.. you can check commits like:
fb982666e380 tools/bpftool: fix bpftool build with bintutils >= 2.9
for adding new feature detection
jirka
2020-03-04 10:07 UTC-0800 ~ Song Liu <[email protected]>
Quoted 46 lines
This set introduces bpftool prog profile command, which uses hardware counters to profile BPF programs.
This command attaches fentry/fexit programs to a target program. These two programs read hardware counters before and after the target program and calculate the difference.
Changes v3 => v4:
1. Simplify err handling inprofile_open_perf_events()(Quentin);
2. Remove redundantp_err()(Quentin);
3. Replace tab with space in bash-completion; (Quentin);
4. Fix typo_bpftool_get_map_names=>_bpftool_get_prog_names(Quentin).Changes v2 => v3:
1. Change order of arguments (Quentin), as:
bpftool prog profile PROG [duration DURATION] METRICs
2. Add bash-completion for bpftool prog profile (Quentin);
3. Fix build of selftests (Yonghong);
4. Better handling ofbpf_map_lookup_elem()returns (Yonghong);
5. Improve clean up logic ofdo_profile()(Yonghong);
6. Other smaller fixes/cleanups.Changes RFC => v2:
1. Use newbpf_program__set_attach_target()API;
2. Update output format to be perf-stat like (Alexei);
3. Incorporate skeleton generation intoMakefile;
4. Make DURATION optional and Allow Ctrl-C (Alexei);
5. Add calcated values "insn per cycle" and "LLC misses per million isns".Song Liu (4):
bpftool: introduce "prog profile" command
bpftool: Documentation for bpftool prog profile
bpftool: bash completion for "bpftool prog profile"
bpftool: fix typo in bash-completion.../bpftool/Documentation/bpftool-prog.rst | 19 + tools/bpf/bpftool/Makefile | 18 + tools/bpf/bpftool/bash-completion/bpftool | 47 +- tools/bpf/bpftool/prog.c | 425 +++++++++++++++++- tools/bpf/bpftool/skeleton/profiler.bpf.c | 171 +++++++ tools/bpf/bpftool/skeleton/profiler.h | 47 ++ tools/scripts/Makefile.include | 1 + 7 files changed, 725 insertions(+), 3 deletions(-) create mode 100644 tools/bpf/bpftool/skeleton/profiler.bpf.c create mode 100644 tools/bpf/bpftool/skeleton/profiler.h
Quoted 1 line
--
Thanks again! This version looks good to me, although I've not tested the patchset, so there's still the error met by Jiri to figure out. For the rest of the series: