Skip to content

Commit 0375691

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-core-for-mingo-20161220' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent
Pull perf/core improvements and fixes: New features: - Introduce 'perf sched timehist --idle', to analyse processes going to/from idle state (Namhyung Kim) Fixes: - Allow 'perf record -u user' to continue when facing races with threads going away after having scanned them via /proc (Jiri Olsa) - Fix 'perf mem' --all-user/--all-kernel options (Jiri Olsa) - Support jumps with multiple arguments (Ravi Bangoria) - Fix jumps to before the function where they are located (Ravi Bangoria) - Fix lock-pi help string (Davidlohr Bueso) - Fix build of 'perf trace' in odd systems such as a RHEL PPC one (Jiri Olsa) - Do not overwrite valid build id in 'perf diff' (Kan Liang) - Don't throw error for zero length symbols, allowing the use of the TUI in PowerPC, where such symbols became more common recently (Ravi Bangoria) Infrastructure changes: - Switch of samples/bpf/ to use tools/lib/bpf, removing libbpf duplication (Joe Stringer) - Move headers check into bash script (Jiri Olsa) Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2 parents 297e765 + 9899694 commit 0375691

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1075
-731
lines changed

samples/bpf/Makefile

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,43 @@ hostprogs-y += tc_l2_redirect
3535
hostprogs-y += lwt_len_hist
3636
hostprogs-y += xdp_tx_iptunnel
3737

38-
test_lru_dist-objs := test_lru_dist.o libbpf.o
39-
sock_example-objs := sock_example.o libbpf.o
40-
fds_example-objs := bpf_load.o libbpf.o fds_example.o
41-
sockex1-objs := bpf_load.o libbpf.o sockex1_user.o
42-
sockex2-objs := bpf_load.o libbpf.o sockex2_user.o
43-
sockex3-objs := bpf_load.o libbpf.o sockex3_user.o
44-
tracex1-objs := bpf_load.o libbpf.o tracex1_user.o
45-
tracex2-objs := bpf_load.o libbpf.o tracex2_user.o
46-
tracex3-objs := bpf_load.o libbpf.o tracex3_user.o
47-
tracex4-objs := bpf_load.o libbpf.o tracex4_user.o
48-
tracex5-objs := bpf_load.o libbpf.o tracex5_user.o
49-
tracex6-objs := bpf_load.o libbpf.o tracex6_user.o
50-
test_probe_write_user-objs := bpf_load.o libbpf.o test_probe_write_user_user.o
51-
trace_output-objs := bpf_load.o libbpf.o trace_output_user.o
52-
lathist-objs := bpf_load.o libbpf.o lathist_user.o
53-
offwaketime-objs := bpf_load.o libbpf.o offwaketime_user.o
54-
spintest-objs := bpf_load.o libbpf.o spintest_user.o
55-
map_perf_test-objs := bpf_load.o libbpf.o map_perf_test_user.o
56-
test_overhead-objs := bpf_load.o libbpf.o test_overhead_user.o
57-
test_cgrp2_array_pin-objs := libbpf.o test_cgrp2_array_pin.o
58-
test_cgrp2_attach-objs := libbpf.o test_cgrp2_attach.o
59-
test_cgrp2_attach2-objs := libbpf.o test_cgrp2_attach2.o cgroup_helpers.o
60-
test_cgrp2_sock-objs := libbpf.o test_cgrp2_sock.o
61-
test_cgrp2_sock2-objs := bpf_load.o libbpf.o test_cgrp2_sock2.o
62-
xdp1-objs := bpf_load.o libbpf.o xdp1_user.o
38+
# Libbpf dependencies
39+
LIBBPF := ../../tools/lib/bpf/bpf.o
40+
41+
test_lru_dist-objs := test_lru_dist.o $(LIBBPF)
42+
sock_example-objs := sock_example.o $(LIBBPF)
43+
fds_example-objs := bpf_load.o $(LIBBPF) fds_example.o
44+
sockex1-objs := bpf_load.o $(LIBBPF) sockex1_user.o
45+
sockex2-objs := bpf_load.o $(LIBBPF) sockex2_user.o
46+
sockex3-objs := bpf_load.o $(LIBBPF) sockex3_user.o
47+
tracex1-objs := bpf_load.o $(LIBBPF) tracex1_user.o
48+
tracex2-objs := bpf_load.o $(LIBBPF) tracex2_user.o
49+
tracex3-objs := bpf_load.o $(LIBBPF) tracex3_user.o
50+
tracex4-objs := bpf_load.o $(LIBBPF) tracex4_user.o
51+
tracex5-objs := bpf_load.o $(LIBBPF) tracex5_user.o
52+
tracex6-objs := bpf_load.o $(LIBBPF) tracex6_user.o
53+
test_probe_write_user-objs := bpf_load.o $(LIBBPF) test_probe_write_user_user.o
54+
trace_output-objs := bpf_load.o $(LIBBPF) trace_output_user.o
55+
lathist-objs := bpf_load.o $(LIBBPF) lathist_user.o
56+
offwaketime-objs := bpf_load.o $(LIBBPF) offwaketime_user.o
57+
spintest-objs := bpf_load.o $(LIBBPF) spintest_user.o
58+
map_perf_test-objs := bpf_load.o $(LIBBPF) map_perf_test_user.o
59+
test_overhead-objs := bpf_load.o $(LIBBPF) test_overhead_user.o
60+
test_cgrp2_array_pin-objs := $(LIBBPF) test_cgrp2_array_pin.o
61+
test_cgrp2_attach-objs := $(LIBBPF) test_cgrp2_attach.o
62+
test_cgrp2_attach2-objs := $(LIBBPF) test_cgrp2_attach2.o cgroup_helpers.o
63+
test_cgrp2_sock-objs := $(LIBBPF) test_cgrp2_sock.o
64+
test_cgrp2_sock2-objs := bpf_load.o $(LIBBPF) test_cgrp2_sock2.o
65+
xdp1-objs := bpf_load.o $(LIBBPF) xdp1_user.o
6366
# reuse xdp1 source intentionally
64-
xdp2-objs := bpf_load.o libbpf.o xdp1_user.o
65-
test_current_task_under_cgroup-objs := bpf_load.o libbpf.o cgroup_helpers.o \
67+
xdp2-objs := bpf_load.o $(LIBBPF) xdp1_user.o
68+
test_current_task_under_cgroup-objs := bpf_load.o $(LIBBPF) cgroup_helpers.o \
6669
test_current_task_under_cgroup_user.o
67-
trace_event-objs := bpf_load.o libbpf.o trace_event_user.o
68-
sampleip-objs := bpf_load.o libbpf.o sampleip_user.o
69-
tc_l2_redirect-objs := bpf_load.o libbpf.o tc_l2_redirect_user.o
70-
lwt_len_hist-objs := bpf_load.o libbpf.o lwt_len_hist_user.o
71-
xdp_tx_iptunnel-objs := bpf_load.o libbpf.o xdp_tx_iptunnel_user.o
70+
trace_event-objs := bpf_load.o $(LIBBPF) trace_event_user.o
71+
sampleip-objs := bpf_load.o $(LIBBPF) sampleip_user.o
72+
tc_l2_redirect-objs := bpf_load.o $(LIBBPF) tc_l2_redirect_user.o
73+
lwt_len_hist-objs := bpf_load.o $(LIBBPF) lwt_len_hist_user.o
74+
xdp_tx_iptunnel-objs := bpf_load.o $(LIBBPF) xdp_tx_iptunnel_user.o
7275

7376
# Tell kbuild to always build the programs
7477
always := $(hostprogs-y)
@@ -104,7 +107,10 @@ always += lwt_len_hist_kern.o
104107
always += xdp_tx_iptunnel_kern.o
105108

106109
HOSTCFLAGS += -I$(objtree)/usr/include
110+
HOSTCFLAGS += -I$(srctree)/tools/lib/
107111
HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
112+
HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
113+
HOSTCFLAGS += -I$(srctree)/tools/perf
108114

109115
HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
110116
HOSTLOADLIBES_fds_example += -lelf

samples/bpf/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
eBPF sample programs
22
====================
33

4-
This directory contains a mini eBPF library, test stubs, verifier
5-
test-suite and examples for using eBPF.
4+
This directory contains a test stubs, verifier test-suite and examples
5+
for using eBPF. The examples use libbpf from tools/lib/bpf.
66

77
Build dependencies
88
==================

samples/bpf/bpf_load.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,34 @@
2222
#include <poll.h>
2323
#include <ctype.h>
2424
#include "libbpf.h"
25-
#include "bpf_helpers.h"
2625
#include "bpf_load.h"
26+
#include "perf-sys.h"
2727

2828
#define DEBUGFS "/sys/kernel/debug/tracing/"
2929

3030
static char license[128];
3131
static int kern_version;
3232
static bool processed_sec[128];
33+
char bpf_log_buf[BPF_LOG_BUF_SIZE];
3334
int map_fd[MAX_MAPS];
3435
int prog_fd[MAX_PROGS];
3536
int event_fd[MAX_PROGS];
3637
int prog_cnt;
3738
int prog_array_fd = -1;
3839

40+
struct bpf_map_def {
41+
unsigned int type;
42+
unsigned int key_size;
43+
unsigned int value_size;
44+
unsigned int max_entries;
45+
unsigned int map_flags;
46+
};
47+
3948
static int populate_prog_array(const char *event, int prog_fd)
4049
{
4150
int ind = atoi(event), err;
4251

43-
err = bpf_update_elem(prog_array_fd, &ind, &prog_fd, BPF_ANY);
52+
err = bpf_map_update_elem(prog_array_fd, &ind, &prog_fd, BPF_ANY);
4453
if (err < 0) {
4554
printf("failed to store prog_fd in prog_array\n");
4655
return -1;
@@ -58,6 +67,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
5867
bool is_perf_event = strncmp(event, "perf_event", 10) == 0;
5968
bool is_cgroup_skb = strncmp(event, "cgroup/skb", 10) == 0;
6069
bool is_cgroup_sk = strncmp(event, "cgroup/sock", 11) == 0;
70+
size_t insns_cnt = size / sizeof(struct bpf_insn);
6171
enum bpf_prog_type prog_type;
6272
char buf[256];
6373
int fd, efd, err, id;
@@ -87,9 +97,10 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
8797
return -1;
8898
}
8999

90-
fd = bpf_prog_load(prog_type, prog, size, license, kern_version);
100+
fd = bpf_load_program(prog_type, prog, insns_cnt, license, kern_version,
101+
bpf_log_buf, BPF_LOG_BUF_SIZE);
91102
if (fd < 0) {
92-
printf("bpf_prog_load() err=%d\n%s", errno, bpf_log_buf);
103+
printf("bpf_load_program() err=%d\n%s", errno, bpf_log_buf);
93104
return -1;
94105
}
95106

@@ -169,7 +180,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
169180
id = atoi(buf);
170181
attr.config = id;
171182

172-
efd = perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0);
183+
efd = sys_perf_event_open(&attr, -1/*pid*/, 0/*cpu*/, -1/*group_fd*/, 0);
173184
if (efd < 0) {
174185
printf("event %d fd %d err %s\n", id, efd, strerror(errno));
175186
return -1;

samples/bpf/bpf_load.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#ifndef __BPF_LOAD_H
22
#define __BPF_LOAD_H
33

4+
#include "libbpf.h"
5+
46
#define MAX_MAPS 32
57
#define MAX_PROGS 32
68

79
extern int map_fd[MAX_MAPS];
810
extern int prog_fd[MAX_PROGS];
911
extern int event_fd[MAX_PROGS];
12+
extern char bpf_log_buf[BPF_LOG_BUF_SIZE];
1013
extern int prog_cnt;
1114

1215
/* parses elf file compiled by llvm .c->.o

samples/bpf/fds_example.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "bpf_load.h"
1616
#include "libbpf.h"
17+
#include "sock_example.h"
1718

1819
#define BPF_F_PIN (1 << 0)
1920
#define BPF_F_GET (1 << 1)
@@ -49,17 +50,19 @@ static int bpf_map_create(void)
4950

5051
static int bpf_prog_create(const char *object)
5152
{
52-
static const struct bpf_insn insns[] = {
53+
static struct bpf_insn insns[] = {
5354
BPF_MOV64_IMM(BPF_REG_0, 1),
5455
BPF_EXIT_INSN(),
5556
};
57+
size_t insns_cnt = sizeof(insns) / sizeof(struct bpf_insn);
5658

5759
if (object) {
5860
assert(!load_bpf_file((char *)object));
5961
return prog_fd[0];
6062
} else {
61-
return bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER,
62-
insns, sizeof(insns), "GPL", 0);
63+
return bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER,
64+
insns, insns_cnt, "GPL", 0,
65+
bpf_log_buf, BPF_LOG_BUF_SIZE);
6366
}
6467
}
6568

@@ -83,12 +86,12 @@ static int bpf_do_map(const char *file, uint32_t flags, uint32_t key,
8386
}
8487

8588
if ((flags & BPF_F_KEY_VAL) == BPF_F_KEY_VAL) {
86-
ret = bpf_update_elem(fd, &key, &value, 0);
89+
ret = bpf_map_update_elem(fd, &key, &value, 0);
8790
printf("bpf: fd:%d u->(%u:%u) ret:(%d,%s)\n", fd, key, value,
8891
ret, strerror(errno));
8992
assert(ret == 0);
9093
} else if (flags & BPF_F_KEY) {
91-
ret = bpf_lookup_elem(fd, &key, &value);
94+
ret = bpf_map_lookup_elem(fd, &key, &value);
9295
printf("bpf: fd:%d l->(%u):%u ret:(%d,%s)\n", fd, key, value,
9396
ret, strerror(errno));
9497
assert(ret == 0);

samples/bpf/lathist_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static void get_data(int fd)
7373
for (c = 0; c < MAX_CPU; c++) {
7474
for (i = 0; i < MAX_ENTRIES; i++) {
7575
key = c * MAX_ENTRIES + i;
76-
bpf_lookup_elem(fd, &key, &value);
76+
bpf_map_lookup_elem(fd, &key, &value);
7777

7878
cpu_hist[c].data[i] = value;
7979
if (value > cpu_hist[c].max)

0 commit comments

Comments
 (0)