Skip to content

Commit

Permalink
Merge branch 'iovisor:master' into yf_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kknjh authored Jan 1, 2025
2 parents d370c42 + 3845f7f commit a89f1fc
Show file tree
Hide file tree
Showing 53 changed files with 884 additions and 335 deletions.
12 changes: 12 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
bcc (0.32.0-1) unstable; urgency=low

* Support for kernel up to 6.11.
* bcc tool update: wakeuptime, readahead, shmsnoop, offcputime, cachestat, cachetop, hardirqs
* libbpf tool update: futexctn, profile, readhead, softirqs, hardirqs
* Multiple enhancements for memleak, better error path checking, adding mremap uprobe
* Support get pid/tgid in pid namespaces (cpudist, profile)
* multiple pid filtering support: profile, offcputime
* detect whether elf binary is PIE even if the binary is marked as DYN
* Fix several compilation issues with llvm20
* doc update, other bug fixes and tools improvement.

bcc (0.31.0-1) unstable; urgency=low

* Support for kernel up to 6.9.
Expand Down
1 change: 0 additions & 1 deletion examples/cpp/KModRetExample.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <iomanip>
#include <string>

#include <error.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
Expand Down
3 changes: 2 additions & 1 deletion examples/networking/sockmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
BPF_SOCKHASH(sock_hash, struct sock_key, MAX_SOCK_OPS_MAP_ENTRIES);
static __always_inline void bpf_sock_ops_ipv4(struct bpf_sock_ops *skops) {
volatile __u32 remote_ip4 = skops->remote_ip4;
struct sock_key skk = {
.remote_ip4 = skops->remote_ip4,
.remote_ip4 = remote_ip4,
.local_ip4 = skops->local_ip4,
.local_port = skops->local_port,
.remote_port = bpf_ntohl(skops->remote_port),
Expand Down
2 changes: 2 additions & 0 deletions libbpf-tools/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@
/wakeuptime
/xfsdist
/xfsslower
/zfsdist
/zfsslower
7 changes: 5 additions & 2 deletions libbpf-tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ LIBBLAZESYM_SRC := $(abspath blazesym/target/release/libblazesym.a)
INCLUDES := -I$(OUTPUT) -I../src/cc/libbpf/include/uapi
CFLAGS := -g -O2 -Wall -Wmissing-field-initializers -Werror -Werror=undef
BPFCFLAGS := -g -O2 -Wall -Werror=undef
BPFCFLAGS_softirqs := $(BPFCFLAGS) -mcpu=v3
INSTALL ?= install
prefix ?= /usr/local
bindir := $(prefix)/bin
Expand Down Expand Up @@ -100,8 +101,8 @@ APPS = \
# export variables that are used in Makefile.btfgen as well.
export OUTPUT BPFTOOL ARCH BTFHUB_ARCHIVE APPS

FSDIST_ALIASES = btrfsdist ext4dist nfsdist xfsdist f2fsdist bcachefsdist
FSSLOWER_ALIASES = btrfsslower ext4slower nfsslower xfsslower f2fsslower bcachefsslower
FSDIST_ALIASES = btrfsdist ext4dist nfsdist xfsdist f2fsdist bcachefsdist zfsdist
FSSLOWER_ALIASES = btrfsslower ext4slower nfsslower xfsslower f2fsslower bcachefsslower zfsslower
SIGSNOOP_ALIAS = killsnoop
APP_ALIASES = $(FSDIST_ALIASES) $(FSSLOWER_ALIASES) ${SIGSNOOP_ALIAS}

Expand Down Expand Up @@ -200,6 +201,8 @@ $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(OUTPUT) $(BPFTOOL)
$(call msg,GEN-SKEL,$@)
$(Q)$(BPFTOOL) gen skeleton $< > $@

$(OUTPUT)/softirqs.bpf.o: BPFCFLAGS = $(BPFCFLAGS_softirqs)

$(OUTPUT)/%.bpf.o: %.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(ARCH)/vmlinux.h | $(OUTPUT)
$(call msg,BPF,$@)
$(Q)$(CLANG) $(BPFCFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) \
Expand Down
14 changes: 13 additions & 1 deletion libbpf-tools/fsdist.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum fs_type {
XFS,
F2FS,
BCACHEFS,
ZFS,
};

static struct fs_config {
Expand Down Expand Up @@ -86,6 +87,13 @@ static struct fs_config {
[F_FSYNC] = "bch2_fsync",
[F_GETATTR] = "bch2_getattr",
}},
[ZFS] = { "zfs", {
[F_READ] = "zpl_iter_read",
[F_WRITE] = "zpl_iter_write",
[F_OPEN] = "zpl_open",
[F_FSYNC] = "zpl_fsync",
[F_GETATTR] = NULL, /* not supported */
}},
};

static char *file_op_names[] = {
Expand Down Expand Up @@ -126,7 +134,7 @@ static const struct argp_option opts[] = {
{ "timestamp", 'T', NULL, 0, "Print timestamp", 0 },
{ "milliseconds", 'm', NULL, 0, "Millisecond histogram", 0 },
{ "pid", 'p', "PID", 0, "Process ID to trace", 0 },
{ "type", 't', "Filesystem", 0, "Which filesystem to trace, [btrfs/ext4/nfs/xfs/f2fs/bcachefs]", 0 },
{ "type", 't', "Filesystem", 0, "Which filesystem to trace, [btrfs/ext4/nfs/xfs/f2fs/bcachefs/zfs]", 0 },
{ "verbose", 'v', NULL, 0, "Verbose debug output", 0 },
{ NULL, 'h', NULL, OPTION_HIDDEN, "Show the full help", 0 },
{},
Expand Down Expand Up @@ -159,6 +167,8 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
fs_type = F2FS;
} else if (!strcmp(arg, "bcachefs")) {
fs_type = BCACHEFS;
} else if (!strcmp(arg, "zfs")) {
fs_type = ZFS;
} else {
warn("invalid filesystem\n");
argp_usage(state);
Expand Down Expand Up @@ -217,6 +227,8 @@ static void alias_parse(char *prog)
fs_type = F2FS;
} else if (strstr(name, "bcachefsdist")){
fs_type = BCACHEFS;
} else if (strstr(name, "zfsdist")) {
fs_type = ZFS;
}
}

Expand Down
13 changes: 12 additions & 1 deletion libbpf-tools/fsslower.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum fs_type {
XFS,
F2FS,
BCACHEFS,
ZFS,
};

static struct fs_config {
Expand Down Expand Up @@ -83,6 +84,12 @@ static struct fs_config {
[F_OPEN] = "bch2_open",
[F_FSYNC] = "bch2_fsync",
}},
[ZFS] = { "zfs", {
[F_READ] = "zpl_iter_read",
[F_WRITE] = "zpl_iter_write",
[F_OPEN] = "zpl_open",
[F_FSYNC] = "zpl_fsync",
}},
};

static char file_op[] = {
Expand Down Expand Up @@ -120,7 +127,7 @@ static const struct argp_option opts[] = {
{ "duration", 'd', "DURATION", 0, "Total duration of trace in seconds", 0 },
{ "pid", 'p', "PID", 0, "Process ID to trace", 0 },
{ "min", 'm', "MIN", 0, "Min latency to trace, in ms (default 10)", 0 },
{ "type", 't', "Filesystem", 0, "Which filesystem to trace, [btrfs/ext4/nfs/xfs/f2fs/bcachefs]", 0 },
{ "type", 't', "Filesystem", 0, "Which filesystem to trace, [btrfs/ext4/nfs/xfs/f2fs/bcachefs/zfs]", 0 },
{ "verbose", 'v', NULL, 0, "Verbose debug output", 0 },
{ NULL, 'h', NULL, OPTION_HIDDEN, "Show the full help", 0 },
{},
Expand Down Expand Up @@ -163,6 +170,8 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
fs_type = F2FS;
} else if (!strcmp(arg, "bcachefs")) {
fs_type = BCACHEFS;
} else if (!strcmp(arg, "zfs")) {
fs_type = ZFS;
} else {
warn("invalid filesystem\n");
argp_usage(state);
Expand Down Expand Up @@ -201,6 +210,8 @@ static void alias_parse(char *prog)
fs_type = F2FS;
} else if (strstr(name, "bcachefsslower")){
fs_type = BCACHEFS;
} else if (!strcmp(name, "zfsslower")) {
fs_type = ZFS;
}
}

Expand Down
9 changes: 4 additions & 5 deletions libbpf-tools/gethostlatency.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,11 @@ static void handle_lost_events(void *ctx, int cpu, __u64 lost_cnt)

static int get_libc_path(char *path)
{
FILE *f;
char proc_path[PATH_MAX + 32] = {};
char buf[PATH_MAX] = {};
char map_fname[PATH_MAX] = {};
char proc_path[PATH_MAX] = {};
char *filename;
float version;
FILE *f;

if (libc_path) {
memcpy(path, libc_path, strlen(libc_path));
Expand All @@ -139,8 +138,8 @@ static int get_libc_path(char *path)
if (target_pid == 0) {
f = fopen("/proc/self/maps", "r");
} else {
snprintf(map_fname, sizeof(map_fname), "/proc/%d/maps", target_pid);
f = fopen(map_fname, "r");
snprintf(buf, sizeof(buf), "/proc/%d/maps", target_pid);
f = fopen(buf, "r");
}
if (!f)
return -errno;
Expand Down
13 changes: 13 additions & 0 deletions libbpf-tools/hardirqs.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const volatile bool filter_cg = false;
const volatile bool targ_dist = false;
const volatile bool targ_ns = false;
const volatile bool do_count = false;
const volatile int targ_cpu = -1;

struct {
__uint(type, BPF_MAP_TYPE_CGROUP_ARRAY);
Expand All @@ -38,10 +39,19 @@ struct {

static struct info zero;

static __always_inline bool is_target_cpu() {
if (targ_cpu < 0)
return true;

return targ_cpu == bpf_get_smp_processor_id();
}

static int handle_entry(int irq, struct irqaction *action)
{
if (filter_cg && !bpf_current_task_under_cgroup(&cgroup_map, 0))
return 0;
if (!is_target_cpu())
return 0;

if (do_count) {
struct irq_key key = {};
Expand Down Expand Up @@ -76,6 +86,9 @@ static int handle_exit(int irq, struct irqaction *action)
if (filter_cg && !bpf_current_task_under_cgroup(&cgroup_map, 0))
return 0;

if (!is_target_cpu())
return 0;

tsp = bpf_map_lookup_elem(&start, &key);
if (!tsp)
return 0;
Expand Down
13 changes: 13 additions & 0 deletions libbpf-tools/hardirqs.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ struct env {
bool verbose;
char *cgroupspath;
bool cg;
int targ_cpu;
} env = {
.interval = 99999999,
.times = 99999999,
.targ_cpu = -1,
};

static volatile bool exiting;
Expand All @@ -47,12 +49,14 @@ const char argp_program_doc[] =
" hardirqs -d # show hard irq event time as histograms\n"
" hardirqs 1 10 # print 1 second summaries, 10 times\n"
" hardirqs -c CG # Trace process under cgroupsPath CG\n"
" hardirqs --cpu 1 # only stat irq on cpu 1\n"
" hardirqs -NT 1 # 1s summaries, nanoseconds, and timestamps\n";

static const struct argp_option opts[] = {
{ "count", 'C', NULL, 0, "Show event counts instead of timing", 0 },
{ "distributed", 'd', NULL, 0, "Show distributions as histograms", 0 },
{ "cgroup", 'c', "/sys/fs/cgroup/unified", 0, "Trace process in cgroup path", 0 },
{ "cpu", 's', "CPU", 0, "Only stat irq on selected cpu", 0 },
{ "timestamp", 'T', NULL, 0, "Include timestamp on output", 0 },
{ "nanoseconds", 'N', NULL, 0, "Output in nanoseconds", 0 },
{ "verbose", 'v', NULL, 0, "Verbose debug output", 0 },
Expand All @@ -77,6 +81,14 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
case 'C':
env.count = true;
break;
case 's':
errno = 0;
env.targ_cpu = atoi(arg);
if (errno || env.targ_cpu < 0) {
fprintf(stderr, "invalid cpu: %s\n", arg);
argp_usage(state);
}
break;
case 'c':
env.cgroupspath = arg;
env.cg = true;
Expand Down Expand Up @@ -218,6 +230,7 @@ int main(int argc, char **argv)

obj->rodata->filter_cg = env.cg;
obj->rodata->do_count = env.count;
obj->rodata->targ_cpu = env.targ_cpu;

/* initialize global data (filtering options) */
if (!env.count) {
Expand Down
18 changes: 16 additions & 2 deletions libbpf-tools/javagc.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,39 @@ static int get_jvmso_path(char *path)
size_t seg_start, seg_end, seg_off;
FILE *f;
int i = 0;
bool found = false;

if (env.pid == -1) {
fprintf(stderr, "not specify pid, see --pid.\n");
return -1;
}

sprintf(buf, "/proc/%d/maps", env.pid);
f = fopen(buf, "r");
if (!f)
if (!f) {
fprintf(stderr, "open %s failed: %m\n", buf);
return -1;
}

while (fscanf(f, "%zx-%zx %s %zx %*s %*d%[^\n]\n",
&seg_start, &seg_end, mode, &seg_off, line) == 5) {
i = 0;
while (isblank(line[i]))
i++;
if (strstr(line + i, "libjvm.so")) {
found = true;
strcpy(path, line + i);
break;
}
}

strcpy(path, line + i);
fclose(f);

if (!found) {
fprintf(stderr, "Not found libjvm.so.\n");
return -ENOENT;
}

return 0;
}

Expand Down
16 changes: 15 additions & 1 deletion libbpf-tools/memleak.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static int gen_alloc_exit2(void *ctx, u64 address)
info.size = *size;
bpf_map_delete_elem(&sizes, &tid);

if (address != 0) {
if (address != 0 && address != MAP_FAILED) {
info.timestamp_ns = bpf_ktime_get_ns();

info.stack_id = bpf_get_stackid(ctx, &stack_traces, stack_flags);
Expand Down Expand Up @@ -223,6 +223,20 @@ int BPF_UPROBE(munmap_enter, void *address)
return gen_free_enter(address);
}

SEC("uprobe")
int BPF_UPROBE(mremap_enter, void *old_address, size_t old_size, size_t new_size, int flags)
{
gen_free_enter(old_address);

return gen_alloc_enter(new_size);
}

SEC("uretprobe")
int BPF_URETPROBE(mremap_exit)
{
return gen_alloc_exit(ctx);
}

SEC("uprobe")
int BPF_UPROBE(posix_memalign_enter, void **memptr, size_t alignment, size_t size)
{
Expand Down
Loading

0 comments on commit a89f1fc

Please sign in to comment.