Skip to content

Commit d6a735e

Browse files
namhyungacmel
authored andcommitted
perf bpf_counter: Move common functions to bpf_counter.h
Some helper functions will be used for cgroup counting too. Move them to a header file for sharing. Committer notes: Fix the build on older systems with: - struct bpf_map_info map_info = {0}; + struct bpf_map_info map_info = { .id = 0, }; This wasn't breaking the build in such systems as bpf_counter.c isn't built due to: tools/perf/util/Build: perf-$(CONFIG_PERF_BPF_SKEL) += bpf_counter.o The bpf_counter.h file on the other hand is included from places that are built everywhere. Signed-off-by: Namhyung Kim <[email protected]> Acked-by: Song Liu <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 21bcc72 commit d6a735e

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

tools/perf/util/bpf_counter.c

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77
#include <unistd.h>
88
#include <sys/file.h>
99
#include <sys/time.h>
10-
#include <sys/resource.h>
1110
#include <linux/err.h>
1211
#include <linux/zalloc.h>
13-
#include <bpf/bpf.h>
14-
#include <bpf/btf.h>
15-
#include <bpf/libbpf.h>
1612
#include <api/fs/fs.h>
1713
#include <perf/bpf_perf.h>
1814

@@ -37,13 +33,6 @@ static inline void *u64_to_ptr(__u64 ptr)
3733
return (void *)(unsigned long)ptr;
3834
}
3935

40-
static void set_max_rlimit(void)
41-
{
42-
struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY };
43-
44-
setrlimit(RLIMIT_MEMLOCK, &rinf);
45-
}
46-
4736
static struct bpf_counter *bpf_counter_alloc(void)
4837
{
4938
struct bpf_counter *counter;
@@ -297,33 +286,6 @@ struct bpf_counter_ops bpf_program_profiler_ops = {
297286
.install_pe = bpf_program_profiler__install_pe,
298287
};
299288

300-
static __u32 bpf_link_get_id(int fd)
301-
{
302-
struct bpf_link_info link_info = {0};
303-
__u32 link_info_len = sizeof(link_info);
304-
305-
bpf_obj_get_info_by_fd(fd, &link_info, &link_info_len);
306-
return link_info.id;
307-
}
308-
309-
static __u32 bpf_link_get_prog_id(int fd)
310-
{
311-
struct bpf_link_info link_info = {0};
312-
__u32 link_info_len = sizeof(link_info);
313-
314-
bpf_obj_get_info_by_fd(fd, &link_info, &link_info_len);
315-
return link_info.prog_id;
316-
}
317-
318-
static __u32 bpf_map_get_id(int fd)
319-
{
320-
struct bpf_map_info map_info = {0};
321-
__u32 map_info_len = sizeof(map_info);
322-
323-
bpf_obj_get_info_by_fd(fd, &map_info, &map_info_len);
324-
return map_info.id;
325-
}
326-
327289
static bool bperf_attr_map_compatible(int attr_map_fd)
328290
{
329291
struct bpf_map_info map_info = {0};
@@ -385,20 +347,6 @@ static int bperf_lock_attr_map(struct target *target)
385347
return map_fd;
386348
}
387349

388-
/* trigger the leader program on a cpu */
389-
static int bperf_trigger_reading(int prog_fd, int cpu)
390-
{
391-
DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts,
392-
.ctx_in = NULL,
393-
.ctx_size_in = 0,
394-
.flags = BPF_F_TEST_RUN_ON_CPU,
395-
.cpu = cpu,
396-
.retval = 0,
397-
);
398-
399-
return bpf_prog_test_run_opts(prog_fd, &opts);
400-
}
401-
402350
static int bperf_check_target(struct evsel *evsel,
403351
struct target *target,
404352
enum bperf_filter_type *filter_type,

tools/perf/util/bpf_counter.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#define __PERF_BPF_COUNTER_H 1
44

55
#include <linux/list.h>
6+
#include <sys/resource.h>
7+
#include <bpf/bpf.h>
8+
#include <bpf/btf.h>
9+
#include <bpf/libbpf.h>
610

711
struct evsel;
812
struct target;
@@ -76,4 +80,52 @@ static inline int bpf_counter__install_pe(struct evsel *evsel __maybe_unused,
7680

7781
#endif /* HAVE_BPF_SKEL */
7882

83+
static inline void set_max_rlimit(void)
84+
{
85+
struct rlimit rinf = { RLIM_INFINITY, RLIM_INFINITY };
86+
87+
setrlimit(RLIMIT_MEMLOCK, &rinf);
88+
}
89+
90+
static inline __u32 bpf_link_get_id(int fd)
91+
{
92+
struct bpf_link_info link_info = { .id = 0, };
93+
__u32 link_info_len = sizeof(link_info);
94+
95+
bpf_obj_get_info_by_fd(fd, &link_info, &link_info_len);
96+
return link_info.id;
97+
}
98+
99+
static inline __u32 bpf_link_get_prog_id(int fd)
100+
{
101+
struct bpf_link_info link_info = { .id = 0, };
102+
__u32 link_info_len = sizeof(link_info);
103+
104+
bpf_obj_get_info_by_fd(fd, &link_info, &link_info_len);
105+
return link_info.prog_id;
106+
}
107+
108+
static inline __u32 bpf_map_get_id(int fd)
109+
{
110+
struct bpf_map_info map_info = { .id = 0, };
111+
__u32 map_info_len = sizeof(map_info);
112+
113+
bpf_obj_get_info_by_fd(fd, &map_info, &map_info_len);
114+
return map_info.id;
115+
}
116+
117+
/* trigger the leader program on a cpu */
118+
static inline int bperf_trigger_reading(int prog_fd, int cpu)
119+
{
120+
DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts,
121+
.ctx_in = NULL,
122+
.ctx_size_in = 0,
123+
.flags = BPF_F_TEST_RUN_ON_CPU,
124+
.cpu = cpu,
125+
.retval = 0,
126+
);
127+
128+
return bpf_prog_test_run_opts(prog_fd, &opts);
129+
}
130+
79131
#endif /* __PERF_BPF_COUNTER_H */

0 commit comments

Comments
 (0)