aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@fb.com>2016-04-06 21:43:29 -0400
committerDavid S. Miller <davem@davemloft.net>2016-04-07 21:04:27 -0400
commitc07660409ec954403776200cec1dd04b2db851f8 (patch)
tree249cad46d3462c443e4ae9c7f8dc87f489a1ec95
parent32bbe0078afe86a8bf4c67c6b3477781b15e94dc (diff)
samples/bpf: add tracepoint support to bpf loader
Recognize "tracepoint/" section name prefix and attach the program to that tracepoint. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--samples/bpf/bpf_load.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c
index 58f86bd11b3d..022af71c2bb5 100644
--- a/samples/bpf/bpf_load.c
+++ b/samples/bpf/bpf_load.c
@@ -49,6 +49,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
49 bool is_socket = strncmp(event, "socket", 6) == 0; 49 bool is_socket = strncmp(event, "socket", 6) == 0;
50 bool is_kprobe = strncmp(event, "kprobe/", 7) == 0; 50 bool is_kprobe = strncmp(event, "kprobe/", 7) == 0;
51 bool is_kretprobe = strncmp(event, "kretprobe/", 10) == 0; 51 bool is_kretprobe = strncmp(event, "kretprobe/", 10) == 0;
52 bool is_tracepoint = strncmp(event, "tracepoint/", 11) == 0;
52 enum bpf_prog_type prog_type; 53 enum bpf_prog_type prog_type;
53 char buf[256]; 54 char buf[256];
54 int fd, efd, err, id; 55 int fd, efd, err, id;
@@ -63,6 +64,8 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
63 prog_type = BPF_PROG_TYPE_SOCKET_FILTER; 64 prog_type = BPF_PROG_TYPE_SOCKET_FILTER;
64 } else if (is_kprobe || is_kretprobe) { 65 } else if (is_kprobe || is_kretprobe) {
65 prog_type = BPF_PROG_TYPE_KPROBE; 66 prog_type = BPF_PROG_TYPE_KPROBE;
67 } else if (is_tracepoint) {
68 prog_type = BPF_PROG_TYPE_TRACEPOINT;
66 } else { 69 } else {
67 printf("Unknown event '%s'\n", event); 70 printf("Unknown event '%s'\n", event);
68 return -1; 71 return -1;
@@ -111,12 +114,23 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
111 event, strerror(errno)); 114 event, strerror(errno));
112 return -1; 115 return -1;
113 } 116 }
114 }
115 117
116 strcpy(buf, DEBUGFS); 118 strcpy(buf, DEBUGFS);
117 strcat(buf, "events/kprobes/"); 119 strcat(buf, "events/kprobes/");
118 strcat(buf, event); 120 strcat(buf, event);
119 strcat(buf, "/id"); 121 strcat(buf, "/id");
122 } else if (is_tracepoint) {
123 event += 11;
124
125 if (*event == 0) {
126 printf("event name cannot be empty\n");
127 return -1;
128 }
129 strcpy(buf, DEBUGFS);
130 strcat(buf, "events/");
131 strcat(buf, event);
132 strcat(buf, "/id");
133 }
120 134
121 efd = open(buf, O_RDONLY, 0); 135 efd = open(buf, O_RDONLY, 0);
122 if (efd < 0) { 136 if (efd < 0) {
@@ -304,6 +318,7 @@ int load_bpf_file(char *path)
304 318
305 if (memcmp(shname_prog, "kprobe/", 7) == 0 || 319 if (memcmp(shname_prog, "kprobe/", 7) == 0 ||
306 memcmp(shname_prog, "kretprobe/", 10) == 0 || 320 memcmp(shname_prog, "kretprobe/", 10) == 0 ||
321 memcmp(shname_prog, "tracepoint/", 11) == 0 ||
307 memcmp(shname_prog, "socket", 6) == 0) 322 memcmp(shname_prog, "socket", 6) == 0)
308 load_and_attach(shname_prog, insns, data_prog->d_size); 323 load_and_attach(shname_prog, insns, data_prog->d_size);
309 } 324 }
@@ -320,6 +335,7 @@ int load_bpf_file(char *path)
320 335
321 if (memcmp(shname, "kprobe/", 7) == 0 || 336 if (memcmp(shname, "kprobe/", 7) == 0 ||
322 memcmp(shname, "kretprobe/", 10) == 0 || 337 memcmp(shname, "kretprobe/", 10) == 0 ||
338 memcmp(shname, "tracepoint/", 11) == 0 ||
323 memcmp(shname, "socket", 6) == 0) 339 memcmp(shname, "socket", 6) == 0)
324 load_and_attach(shname, data->d_buf, data->d_size); 340 load_and_attach(shname, data->d_buf, data->d_size);
325 } 341 }