Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf bpf_counter: Move header declarations into C code

Reduce the API surface that is in bpf_counter.h, this helps compiler
analysis like unused static function, makes it easier to set a
breakpoint and just makes it easier to see the code is self contained.

When code is shared between BPF C code, put it inside HAVE_BPF_SKEL.
Move transitively found #includes into appropriate C files.

No functional change.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Gabriele Monaco <gmonaco@redhat.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Tengda Wu <wutengda@huaweicloud.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
8c519a82 60c38a6d

+69 -70
+60 -2
tools/perf/util/bpf_counter.c
··· 6 6 #include <limits.h> 7 7 #include <unistd.h> 8 8 #include <sys/file.h> 9 + #include <sys/resource.h> 9 10 #include <sys/time.h> 10 11 #include <linux/err.h> 12 + #include <linux/list.h> 11 13 #include <linux/zalloc.h> 12 14 #include <api/fs/fs.h> 15 + #include <bpf/bpf.h> 16 + #include <bpf/btf.h> 13 17 #include <perf/bpf_perf.h> 14 18 15 19 #include "bpf_counter.h" ··· 32 28 #include "bpf_skel/bperf_leader.skel.h" 33 29 #include "bpf_skel/bperf_follower.skel.h" 34 30 31 + struct bpf_counter { 32 + void *skel; 33 + struct list_head list; 34 + }; 35 + 35 36 #define ATTR_MAP_SIZE 16 36 37 37 - static inline void *u64_to_ptr(__u64 ptr) 38 + static void *u64_to_ptr(__u64 ptr) 38 39 { 39 40 return (void *)(unsigned long)ptr; 41 + } 42 + 43 + 44 + void set_max_rlimit(void) 45 + { 46 + struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY }; 47 + 48 + setrlimit(RLIMIT_MEMLOCK, &rinf); 49 + } 50 + 51 + static __u32 bpf_link_get_id(int fd) 52 + { 53 + struct bpf_link_info link_info = { .id = 0, }; 54 + __u32 link_info_len = sizeof(link_info); 55 + 56 + bpf_obj_get_info_by_fd(fd, &link_info, &link_info_len); 57 + return link_info.id; 58 + } 59 + 60 + static __u32 bpf_link_get_prog_id(int fd) 61 + { 62 + struct bpf_link_info link_info = { .id = 0, }; 63 + __u32 link_info_len = sizeof(link_info); 64 + 65 + bpf_obj_get_info_by_fd(fd, &link_info, &link_info_len); 66 + return link_info.prog_id; 67 + } 68 + 69 + static __u32 bpf_map_get_id(int fd) 70 + { 71 + struct bpf_map_info map_info = { .id = 0, }; 72 + __u32 map_info_len = sizeof(map_info); 73 + 74 + bpf_obj_get_info_by_fd(fd, &map_info, &map_info_len); 75 + return map_info.id; 76 + } 77 + 78 + /* trigger the leader program on a cpu */ 79 + int bperf_trigger_reading(int prog_fd, int cpu) 80 + { 81 + DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts, 82 + .ctx_in = NULL, 83 + .ctx_size_in = 0, 84 + .flags = BPF_F_TEST_RUN_ON_CPU, 85 + .cpu = cpu, 86 + .retval = 0, 87 + ); 88 + 89 + return bpf_prog_test_run_opts(prog_fd, &opts); 40 90 } 41 91 42 92 static struct bpf_counter *bpf_counter_alloc(void) ··· 843 785 844 786 extern struct bpf_counter_ops bperf_cgrp_ops; 845 787 846 - static inline bool bpf_counter_skip(struct evsel *evsel) 788 + static bool bpf_counter_skip(struct evsel *evsel) 847 789 { 848 790 return evsel->bpf_counter_ops == NULL; 849 791 }
+6 -68
tools/perf/util/bpf_counter.h
··· 2 2 #ifndef __PERF_BPF_COUNTER_H 3 3 #define __PERF_BPF_COUNTER_H 1 4 4 5 - #include <linux/list.h> 6 - #include <sys/resource.h> 7 - 8 - #ifdef HAVE_LIBBPF_SUPPORT 9 - #include <bpf/bpf.h> 10 - #include <bpf/btf.h> 11 - #include <bpf/libbpf.h> 12 - #endif 13 - 14 5 struct evsel; 15 6 struct target; 16 - struct bpf_counter; 7 + 8 + #ifdef HAVE_BPF_SKEL 17 9 18 10 typedef int (*bpf_counter_evsel_op)(struct evsel *evsel); 19 11 typedef int (*bpf_counter_evsel_target_op)(struct evsel *evsel, ··· 14 22 int cpu_map_idx, 15 23 int fd); 16 24 25 + /* Shared ops between bpf_counter, bpf_counter_cgroup, etc. */ 17 26 struct bpf_counter_ops { 18 27 bpf_counter_evsel_target_op load; 19 28 bpf_counter_evsel_op enable; ··· 24 31 bpf_counter_evsel_install_pe_op install_pe; 25 32 }; 26 33 27 - struct bpf_counter { 28 - void *skel; 29 - struct list_head list; 30 - }; 31 - 32 - #ifdef HAVE_BPF_SKEL 33 - 34 34 int bpf_counter__load(struct evsel *evsel, struct target *target); 35 35 int bpf_counter__enable(struct evsel *evsel); 36 36 int bpf_counter__disable(struct evsel *evsel); 37 37 int bpf_counter__read(struct evsel *evsel); 38 38 void bpf_counter__destroy(struct evsel *evsel); 39 39 int bpf_counter__install_pe(struct evsel *evsel, int cpu_map_idx, int fd); 40 + 41 + int bperf_trigger_reading(int prog_fd, int cpu); 42 + void set_max_rlimit(void); 40 43 41 44 #else /* HAVE_BPF_SKEL */ 42 45 ··· 70 81 return 0; 71 82 } 72 83 73 - #endif /* HAVE_BPF_SKEL */ 74 - 75 - static inline void set_max_rlimit(void) 76 - { 77 - struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY }; 78 - 79 - setrlimit(RLIMIT_MEMLOCK, &rinf); 80 - } 81 - 82 - #ifdef HAVE_BPF_SKEL 83 - 84 - static inline __u32 bpf_link_get_id(int fd) 85 - { 86 - struct bpf_link_info link_info = { .id = 0, }; 87 - __u32 link_info_len = sizeof(link_info); 88 - 89 - bpf_obj_get_info_by_fd(fd, &link_info, &link_info_len); 90 - return link_info.id; 91 - } 92 - 93 - static inline __u32 bpf_link_get_prog_id(int fd) 94 - { 95 - struct bpf_link_info link_info = { .id = 0, }; 96 - __u32 link_info_len = sizeof(link_info); 97 - 98 - bpf_obj_get_info_by_fd(fd, &link_info, &link_info_len); 99 - return link_info.prog_id; 100 - } 101 - 102 - static inline __u32 bpf_map_get_id(int fd) 103 - { 104 - struct bpf_map_info map_info = { .id = 0, }; 105 - __u32 map_info_len = sizeof(map_info); 106 - 107 - bpf_obj_get_info_by_fd(fd, &map_info, &map_info_len); 108 - return map_info.id; 109 - } 110 - 111 - /* trigger the leader program on a cpu */ 112 - static inline int bperf_trigger_reading(int prog_fd, int cpu) 113 - { 114 - DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts, 115 - .ctx_in = NULL, 116 - .ctx_size_in = 0, 117 - .flags = BPF_F_TEST_RUN_ON_CPU, 118 - .cpu = cpu, 119 - .retval = 0, 120 - ); 121 - 122 - return bpf_prog_test_run_opts(prog_fd, &opts); 123 - } 124 84 #endif /* HAVE_BPF_SKEL */ 125 85 126 86 #endif /* __PERF_BPF_COUNTER_H */
+1
tools/perf/util/bpf_counter_cgroup.c
··· 13 13 #include <linux/zalloc.h> 14 14 #include <linux/perf_event.h> 15 15 #include <api/fs/fs.h> 16 + #include <bpf/bpf.h> 16 17 #include <perf/bpf_perf.h> 17 18 18 19 #include "affinity.h"
+1
tools/perf/util/bpf_ftrace.c
··· 3 3 #include <stdint.h> 4 4 #include <stdlib.h> 5 5 6 + #include <bpf/bpf.h> 6 7 #include <linux/err.h> 7 8 8 9 #include "util/ftrace.h"
+1
tools/perf/util/bpf_off_cpu.c
··· 13 13 #include "util/cgroup.h" 14 14 #include "util/strlist.h" 15 15 #include <bpf/bpf.h> 16 + #include <bpf/btf.h> 16 17 #include <internal/xyarray.h> 17 18 #include <linux/time64.h> 18 19