Skip to content

Commit

Permalink
remove unnecessary prefix in some prog names (iovisor#1814)
Browse files Browse the repository at this point in the history
bcc uses some func prefixes for auto load purpose. These
func prefixes include "kprobe__", "tracepoint__" and
"raw_tracepoint__". Currently we also pass this
function name as the program name to the kernel.

The kernel can only accept 16 bytes so long program
name will be truncated. For example, with bps we will see
something like
     287- <raw_tracepoint>       0      2 Jun10/17:07  raw_tracepoint_
     290- tracepoint             0      4 Jun10/17:08  tracepoint__soc
     297- kprobe                 0      2 Jun10/17:09  kprobe__tcp_cle

Such long prefixes are unnecessarily taking the space
for the real function name. This patch removed such prefixes
before giving them to the kernel.
The result will like below:
     311- <raw_tracepoint>       0      2 Jun10/17:44  sched_switch
     321- tracepoint             0      4 Jun10/17:45  sock__inet_sock
     322- kprobe                 0      2 Jun10/17:45  tcp_cleanup_rbu

Signed-off-by: Yonghong Song <[email protected]>
  • Loading branch information
yonghong-song authored Jun 11, 2018
1 parent 81de82c commit d83210d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/cc/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ int bpf_prog_load(enum bpf_prog_type prog_type, const char *name,
union bpf_attr attr;
char *tmp_log_buf = NULL;
unsigned tmp_log_buf_size = 0;
int ret = 0;
int ret = 0, name_offset = 0;

memset(&attr, 0, sizeof(attr));

Expand Down Expand Up @@ -509,7 +509,14 @@ int bpf_prog_load(enum bpf_prog_type prog_type, const char *name,
}
}

memcpy(attr.prog_name, name, min(name_len, BPF_OBJ_NAME_LEN - 1));
if (strncmp(name, "kprobe__", 8) == 0)
name_offset = 8;
else if (strncmp(name, "tracepoint__", 12) == 0)
name_offset = 12;
else if (strncmp(name, "raw_tracepoint__", 16) == 0)
name_offset = 16;
memcpy(attr.prog_name, name + name_offset,
min(name_len - name_offset, BPF_OBJ_NAME_LEN - 1));

ret = syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
// BPF object name is not supported on older Kernels.
Expand Down

0 comments on commit d83210d

Please sign in to comment.