diff options
| author | Ingo Molnar <mingo@kernel.org> | 2017-07-30 05:15:13 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2017-07-30 05:15:13 -0400 |
| commit | f5db340f19f14a8df9dfd22d71fba1513e9f1f7e (patch) | |
| tree | 131d3345bc987aee3c922624de816492e7f323a4 /tools/lib | |
| parent | ee438ec8f33c5af0d4a4ffb935c5b9272e8c2680 (diff) | |
| parent | 38115f2f8cec8087d558c062e779c443a01f87d6 (diff) | |
Merge branch 'perf/urgent' into perf/core, to pick up latest fixes and refresh the tree
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/lib')
| -rw-r--r-- | tools/lib/bpf/bpf.c | 72 | ||||
| -rw-r--r-- | tools/lib/bpf/bpf.h | 7 |
2 files changed, 76 insertions, 3 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 6e178987af8e..412a7c82995a 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
| @@ -120,7 +120,7 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, | |||
| 120 | int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, | 120 | int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, |
| 121 | size_t insns_cnt, int strict_alignment, | 121 | size_t insns_cnt, int strict_alignment, |
| 122 | const char *license, __u32 kern_version, | 122 | const char *license, __u32 kern_version, |
| 123 | char *log_buf, size_t log_buf_sz) | 123 | char *log_buf, size_t log_buf_sz, int log_level) |
| 124 | { | 124 | { |
| 125 | union bpf_attr attr; | 125 | union bpf_attr attr; |
| 126 | 126 | ||
| @@ -131,7 +131,7 @@ int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, | |||
| 131 | attr.license = ptr_to_u64(license); | 131 | attr.license = ptr_to_u64(license); |
| 132 | attr.log_buf = ptr_to_u64(log_buf); | 132 | attr.log_buf = ptr_to_u64(log_buf); |
| 133 | attr.log_size = log_buf_sz; | 133 | attr.log_size = log_buf_sz; |
| 134 | attr.log_level = 2; | 134 | attr.log_level = log_level; |
| 135 | log_buf[0] = 0; | 135 | log_buf[0] = 0; |
| 136 | attr.kern_version = kern_version; | 136 | attr.kern_version = kern_version; |
| 137 | attr.prog_flags = strict_alignment ? BPF_F_STRICT_ALIGNMENT : 0; | 137 | attr.prog_flags = strict_alignment ? BPF_F_STRICT_ALIGNMENT : 0; |
| @@ -257,3 +257,71 @@ int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size, | |||
| 257 | *duration = attr.test.duration; | 257 | *duration = attr.test.duration; |
| 258 | return ret; | 258 | return ret; |
| 259 | } | 259 | } |
| 260 | |||
| 261 | int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id) | ||
| 262 | { | ||
| 263 | union bpf_attr attr; | ||
| 264 | int err; | ||
| 265 | |||
| 266 | bzero(&attr, sizeof(attr)); | ||
| 267 | attr.start_id = start_id; | ||
| 268 | |||
| 269 | err = sys_bpf(BPF_PROG_GET_NEXT_ID, &attr, sizeof(attr)); | ||
| 270 | if (!err) | ||
| 271 | *next_id = attr.next_id; | ||
| 272 | |||
| 273 | return err; | ||
| 274 | } | ||
| 275 | |||
| 276 | int bpf_map_get_next_id(__u32 start_id, __u32 *next_id) | ||
| 277 | { | ||
| 278 | union bpf_attr attr; | ||
| 279 | int err; | ||
| 280 | |||
| 281 | bzero(&attr, sizeof(attr)); | ||
| 282 | attr.start_id = start_id; | ||
| 283 | |||
| 284 | err = sys_bpf(BPF_MAP_GET_NEXT_ID, &attr, sizeof(attr)); | ||
| 285 | if (!err) | ||
| 286 | *next_id = attr.next_id; | ||
| 287 | |||
| 288 | return err; | ||
| 289 | } | ||
| 290 | |||
| 291 | int bpf_prog_get_fd_by_id(__u32 id) | ||
| 292 | { | ||
| 293 | union bpf_attr attr; | ||
| 294 | |||
| 295 | bzero(&attr, sizeof(attr)); | ||
| 296 | attr.prog_id = id; | ||
| 297 | |||
| 298 | return sys_bpf(BPF_PROG_GET_FD_BY_ID, &attr, sizeof(attr)); | ||
| 299 | } | ||
| 300 | |||
| 301 | int bpf_map_get_fd_by_id(__u32 id) | ||
| 302 | { | ||
| 303 | union bpf_attr attr; | ||
| 304 | |||
| 305 | bzero(&attr, sizeof(attr)); | ||
| 306 | attr.map_id = id; | ||
| 307 | |||
| 308 | return sys_bpf(BPF_MAP_GET_FD_BY_ID, &attr, sizeof(attr)); | ||
| 309 | } | ||
| 310 | |||
| 311 | int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len) | ||
| 312 | { | ||
| 313 | union bpf_attr attr; | ||
| 314 | int err; | ||
| 315 | |||
| 316 | bzero(&attr, sizeof(attr)); | ||
| 317 | bzero(info, *info_len); | ||
| 318 | attr.info.bpf_fd = prog_fd; | ||
| 319 | attr.info.info_len = *info_len; | ||
| 320 | attr.info.info = ptr_to_u64(info); | ||
| 321 | |||
| 322 | err = sys_bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr)); | ||
| 323 | if (!err) | ||
| 324 | *info_len = attr.info.info_len; | ||
| 325 | |||
| 326 | return err; | ||
| 327 | } | ||
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 972bd8333eb7..418c86e69bcb 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h | |||
| @@ -38,7 +38,7 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, | |||
| 38 | int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, | 38 | int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, |
| 39 | size_t insns_cnt, int strict_alignment, | 39 | size_t insns_cnt, int strict_alignment, |
| 40 | const char *license, __u32 kern_version, | 40 | const char *license, __u32 kern_version, |
| 41 | char *log_buf, size_t log_buf_sz); | 41 | char *log_buf, size_t log_buf_sz, int log_level); |
| 42 | 42 | ||
| 43 | int bpf_map_update_elem(int fd, const void *key, const void *value, | 43 | int bpf_map_update_elem(int fd, const void *key, const void *value, |
| 44 | __u64 flags); | 44 | __u64 flags); |
| @@ -54,5 +54,10 @@ int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type); | |||
| 54 | int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size, | 54 | int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size, |
| 55 | void *data_out, __u32 *size_out, __u32 *retval, | 55 | void *data_out, __u32 *size_out, __u32 *retval, |
| 56 | __u32 *duration); | 56 | __u32 *duration); |
| 57 | int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id); | ||
| 58 | int bpf_map_get_next_id(__u32 start_id, __u32 *next_id); | ||
| 59 | int bpf_prog_get_fd_by_id(__u32 id); | ||
| 60 | int bpf_map_get_fd_by_id(__u32 id); | ||
| 61 | int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len); | ||
| 57 | 62 | ||
| 58 | #endif | 63 | #endif |
