Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pull request iovisor#3691 from chenhengqi/add-mdflush #3

Merged
merged 30 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4f59913
libbpf-tools: Add mdflush
chenhengqi Nov 8, 2021
63103fa
bcc: add method to close file descriptors
terceiro Mar 22, 2022
9d06ced
tools/tcplife: Remove dead code
chenhengqi Jun 2, 2022
02f0f5a
Merge pull request #4032 from chenhengqi/cleanup-tcplife
davemarchevsky Jun 2, 2022
42a84ed
Fixed 'getElementType() is deprecated' compile warning.
Rtoax May 29, 2022
65efffe
tools/exitsnoop: Use task->real_parent instead of task->parent (#4025)
xingfeng2510 Jun 3, 2022
ae680db
tools/biolatency: Add disk filter support (#4026)
xingfeng2510 Jun 3, 2022
aad64e4
docs: Add missing entries for CGROUP_SOCK_ADDR family
chenhengqi Jun 2, 2022
9541c9c
sync with laest libbpf repo
yonghong-song Jun 3, 2022
730ced2
libbpf-tools: add support for cross compilation
May 13, 2022
67b8cfb
libbpf-tools/klockstat: Flush stdout after print_stats()
namhyung May 11, 2022
bfccfe6
libbpf-tools/klockstat: Print human friendly time stats
namhyung May 11, 2022
5e3d41e
libbpf-tools/klockstat: Add --per-thread/-P option
namhyung May 11, 2022
a184f09
libbpf-tools: Fix bio tools
chenhengqi Jun 10, 2022
70e8a9b
Merge pull request #3919 from terceiro/python-bpf-close
davemarchevsky Jun 13, 2022
45f5df4
libbpf-tools: Remove map flag BPF_F_NO_PREALLOC
chenhengqi Jun 10, 2022
8e608ed
Remove executable permissions and extra spaces for "funcinterval.8".
Rtoax Jun 14, 2022
e345542
Merge pull request #4049 from Rtoax/patch-17-funcinterval.8-x
davemarchevsky Jun 14, 2022
16eab39
Add tracepoint:skb:kfree_skb if no tcp_drop() kprobe.
Rtoax Jun 15, 2022
1c0808d
Fix: Failed to load BPF program b'trace_read_return': Permission denied
Rtoax Jun 15, 2022
37c3f97
libbpf-tools: fix tcpconnect build errors
aspsk Jun 15, 2022
e16b628
Add more hints for error kprobe.
Rtoax Jun 17, 2022
dbb7b83
Merge pull request #4055 from Rtoax/patch-21-warn-inlined
davemarchevsky Jun 17, 2022
e84e46f
sync with latest libbpf repo
chantra Jun 20, 2022
1900809
backport `struct bpf_create_map_attr`
chantra Jun 20, 2022
10e3cd4
tools/syscount: Beautify output of syscall list
xingfeng2510 Jun 21, 2022
13b5563
Merge pull request #4062 from chantra/remove_bpf_create_map
davemarchevsky Jun 21, 2022
a409bf5
Merge pull request #4050 from Rtoax/patch-18-tcpdrop-reason
davemarchevsky Jun 24, 2022
21e18d1
Merge pull request #4063 from xingfeng2510/enhance
davemarchevsky Jun 24, 2022
9627312
Merge pull request #3691 from chenhengqi/add-mdflush
davemarchevsky Jun 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/kernel-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ BPF attached to cgroups as device controller | 4.15 | [`ebc614f68736`](https://g
bpf2bpf function calls | 4.16 | [`cc8b0b92a169`](https://github.com/torvalds/linux/commit/cc8b0b92a1699bc32f7fec71daa2bfc90de43a4d)
BPF used for monitoring socket RX/TX data | 4.17 | [`4f738adba30a`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=4f738adba30a7cfc006f605707e7aee847ffefa0)
BPF attached to raw tracepoints | 4.17 | [`c4f6699dfcb8`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c4f6699dfcb8558d138fe838f741b2c10f416cf9)
BPF attached to `bind()` system call | 4.17 | [`4fbac77d2d09`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=4fbac77d2d092b475dda9eea66da674369665427)
BPF attached to `bind()` system call | 4.17 | [`4fbac77d2d09`](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=4fbac77d2d092b475dda9eea66da674369665427) [`aac3fc320d94`](https://github.com/torvalds/linux/commit/aac3fc320d9404f2665a8b1249dc3170d5fa3caf)
BPF attached to `connect()` system call | 4.17 | [`d74bad4e74ee`](https://github.com/torvalds/linux/commit/d74bad4e74ee373787a9ae24197c17b7cdc428d5)
BPF Type Format (BTF) | 4.18 | [`69b693f0aefa`](https://git.kernel.org/cgit/linux/kernel/git/davem/net-next.git/commit/?id=69b693f0aefa0ed521e8bd02260523b5ae446ad7)
AF_XDP | 4.18 | [`fbfc504a24f5`](https://git.kernel.org/cgit/linux/kernel/git/davem/net-next.git/commit/?id=fbfc504a24f53f7ebe128ab55cb5dba634f4ece8)
bpfilter | 4.18 | [`d2ba09c17a06`](https://git.kernel.org/cgit/linux/kernel/git/davem/net-next.git/commit/?id=d2ba09c17a0647f899d6c20a11bab9e6d3382f07)
Expand Down
1 change: 1 addition & 0 deletions libbpf-tools/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/llcstat
/nfsdist
/nfsslower
/mdflush
/mountsnoop
/numamove
/offcputime
Expand Down
19 changes: 18 additions & 1 deletion libbpf-tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ APPS = \
klockstat \
ksnoop \
llcstat \
mdflush \
mountsnoop \
numamove \
offcputime \
Expand Down Expand Up @@ -79,6 +80,15 @@ COMMON_OBJ = \
$(if $(ENABLE_MIN_CORE_BTFS),$(OUTPUT)/min_core_btf_tar.o) \
#

define allow-override
$(if $(or $(findstring environment,$(origin $(1))),\
$(findstring command line,$(origin $(1)))),,\
$(eval $(1) = $(2)))
endef

$(call allow-override,CC,$(CROSS_COMPILE)cc)
$(call allow-override,LD,$(CROSS_COMPILE)ld)

.PHONY: all
all: $(APPS) $(APP_ALIASES)

Expand All @@ -91,6 +101,13 @@ msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
MAKEFLAGS += --no-print-directory
endif

ifneq ($(EXTRA_CFLAGS),)
CFLAGS += $(EXTRA_CFLAGS)
endif
ifneq ($(EXTRA_LDFLAGS),)
LDFLAGS += $(EXTRA_LDFLAGS)
endif

.PHONY: clean
clean:
$(call msg,CLEAN)
Expand All @@ -103,7 +120,7 @@ $(OUTPUT) $(OUTPUT)/libbpf:
.PHONY: bpftool
bpftool:
$(Q)mkdir -p $(OUTPUT)/bpftool
$(Q)$(MAKE) OUTPUT=$(OUTPUT)/bpftool/ -C $(BPFTOOL_SRC)
$(Q)$(MAKE) ARCH= CROSS_COMPILE= OUTPUT=$(OUTPUT)/bpftool/ -C $(BPFTOOL_SRC)

$(APPS): %: $(OUTPUT)/%.o $(LIBBPF_OBJ) $(COMMON_OBJ) | $(OUTPUT)
$(call msg,BINARY,$@)
Expand Down
2 changes: 0 additions & 2 deletions libbpf-tools/biolatency.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ struct {
__uint(max_entries, MAX_ENTRIES);
__type(key, struct request *);
__type(value, u64);
__uint(map_flags, BPF_F_NO_PREALLOC);
} start SEC(".maps");

static struct hist initial_hist;
Expand All @@ -45,7 +44,6 @@ struct {
__uint(max_entries, MAX_ENTRIES);
__type(key, struct hist_key);
__type(value, struct hist);
__uint(map_flags, BPF_F_NO_PREALLOC);
} hists SEC(".maps");

static __always_inline
Expand Down
1 change: 0 additions & 1 deletion libbpf-tools/biopattern.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct {
__uint(max_entries, 64);
__type(key, u32);
__type(value, struct counter);
__uint(map_flags, BPF_F_NO_PREALLOC);
} counters SEC(".maps");

SEC("tracepoint/block/block_rq_complete")
Expand Down
1 change: 0 additions & 1 deletion libbpf-tools/biosnoop.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ struct {
__uint(max_entries, MAX_ENTRIES);
__type(key, struct request *);
__type(value, struct piddata);
__uint(map_flags, BPF_F_NO_PREALLOC);
} infobyreq SEC(".maps");

struct stage {
Expand Down
11 changes: 9 additions & 2 deletions libbpf-tools/biosnoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
start_ts = e->ts;
blk_fill_rwbs(rwbs, e->cmd_flags);
partition = partitions__get_by_dev(partitions, e->dev);
printf("%-11.6f %-14.14s %-6d %-7s %-4s %-10lld %-7d ",
printf("%-11.6f %-14.14s %-7d %-7s %-4s %-10lld %-7d ",
(e->ts - start_ts) / 1000000000.0,
e->comm, e->pid, partition ? partition->name : "Unknown", rwbs,
e->sector, e->len);
Expand Down Expand Up @@ -230,6 +230,13 @@ int main(int argc, char **argv)
obj->rodata->targ_queued = env.queued;
obj->rodata->filter_cg = env.cg;

if (fentry_can_attach("blk_account_io_start", NULL))
bpf_program__set_attach_target(obj->progs.blk_account_io_start, 0,
"blk_account_io_start");
else
bpf_program__set_attach_target(obj->progs.blk_account_io_start, 0,
"__blk_account_io_start");

err = biosnoop_bpf__load(obj);
if (err) {
fprintf(stderr, "failed to load BPF object: %d\n", err);
Expand Down Expand Up @@ -304,7 +311,7 @@ int main(int argc, char **argv)
goto cleanup;
}

printf("%-11s %-14s %-6s %-7s %-4s %-10s %-7s ",
printf("%-11s %-14s %-7s %-7s %-4s %-10s %-7s ",
"TIME(s)", "COMM", "PID", "DISK", "T", "SECTOR", "BYTES");
if (env.queued)
printf("%7s ", "QUE(ms)");
Expand Down
2 changes: 0 additions & 2 deletions libbpf-tools/biostacks.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ struct {
__uint(max_entries, MAX_ENTRIES);
__type(key, struct request *);
__type(value, struct internal_rqinfo);
__uint(map_flags, BPF_F_NO_PREALLOC);
} rqinfos SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, MAX_ENTRIES);
__type(key, struct rqinfo);
__type(value, struct hist);
__uint(map_flags, BPF_F_NO_PREALLOC);
} hists SEC(".maps");

static struct hist zero;
Expand Down
12 changes: 12 additions & 0 deletions libbpf-tools/biostacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ int main(int argc, char **argv)

obj->rodata->targ_ms = env.milliseconds;

if (fentry_can_attach("blk_account_io_start", NULL)) {
bpf_program__set_attach_target(obj->progs.blk_account_io_start, 0,
"blk_account_io_start");
bpf_program__set_attach_target(obj->progs.blk_account_io_done, 0,
"blk_account_io_done");
} else {
bpf_program__set_attach_target(obj->progs.blk_account_io_start, 0,
"__blk_account_io_start");
bpf_program__set_attach_target(obj->progs.blk_account_io_done, 0,
"__blk_account_io_done");
}

err = biostacks_bpf__load(obj);
if (err) {
fprintf(stderr, "failed to load BPF object: %d\n", err);
Expand Down
1 change: 0 additions & 1 deletion libbpf-tools/bitesize.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ struct {
__uint(max_entries, 10240);
__type(key, struct hist_key);
__type(value, struct hist);
__uint(map_flags, BPF_F_NO_PREALLOC);
} hists SEC(".maps");

static struct hist initial_hist;
Expand Down
27 changes: 23 additions & 4 deletions libbpf-tools/core_fixes.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,34 @@
*/
struct task_struct___x {
unsigned int __state;
};
} __attribute__((preserve_access_index));

static __s64 get_task_state(void *task)
/**
* commit 309dca309fc3 ("block: store a block_device pointer in struct bio")
* adds a new member bi_bdev which is a pointer to struct block_device
* see:
* https://github.com/torvalds/linux/commit/309dca309fc3
*/
struct bio___x {
struct block_device *bi_bdev;
} __attribute__((preserve_access_index));

static __always_inline __s64 get_task_state(void *task)
{
struct task_struct___x *t = task;

if (bpf_core_field_exists(t->__state))
return t->__state;
return ((struct task_struct *)task)->state;
return BPF_CORE_READ(t, __state);
return BPF_CORE_READ((struct task_struct *)task, state);
}

static __always_inline struct gendisk *get_gendisk(void *bio)
{
struct bio___x *b = bio;

if (bpf_core_field_exists(b->bi_bdev))
return BPF_CORE_READ(b, bi_bdev, bd_disk);
return BPF_CORE_READ((struct bio *)bio, bi_disk);
}

#endif /* __CORE_FIXES_BPF_H */
21 changes: 16 additions & 5 deletions libbpf-tools/klockstat.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const volatile pid_t targ_tgid = 0;
const volatile pid_t targ_pid = 0;
void *const volatile targ_lock = NULL;
const volatile int per_thread = 0;

struct {
__uint(type, BPF_MAP_TYPE_STACK_TRACE);
Expand Down Expand Up @@ -147,6 +148,10 @@ static void account(struct lockholder_info *li)
{
struct lock_stat *ls;
u64 delta;
u32 key = li->stack_id;

if (per_thread)
key = li->task_id;

/*
* Multiple threads may have the same stack_id. Even though we are
Expand All @@ -155,15 +160,19 @@ static void account(struct lockholder_info *li)
* by multiple readers at the same time. They will be accounted as
* the same lock, which is what we want, but we need to use atomics to
* avoid corruption, especially for the total_time variables.
* But it should be ok for per-thread since it's not racy anymore.
*/
ls = bpf_map_lookup_elem(&stat_map, &li->stack_id);
ls = bpf_map_lookup_elem(&stat_map, &key);
if (!ls) {
struct lock_stat fresh = {0};

bpf_map_update_elem(&stat_map, &li->stack_id, &fresh, BPF_ANY);
ls = bpf_map_lookup_elem(&stat_map, &li->stack_id);
bpf_map_update_elem(&stat_map, &key, &fresh, BPF_ANY);
ls = bpf_map_lookup_elem(&stat_map, &key);
if (!ls)
return;

if (per_thread)
bpf_get_current_comm(ls->acq_max_comm, TASK_COMM_LEN);
}

delta = li->acq_at - li->try_at;
Expand All @@ -176,7 +185,8 @@ static void account(struct lockholder_info *li)
* Potentially racy, if multiple threads think they are the max,
* so you may get a clobbered write.
*/
bpf_get_current_comm(ls->acq_max_comm, TASK_COMM_LEN);
if (!per_thread)
bpf_get_current_comm(ls->acq_max_comm, TASK_COMM_LEN);
}

delta = li->rel_at - li->acq_at;
Expand All @@ -185,7 +195,8 @@ static void account(struct lockholder_info *li)
if (delta > READ_ONCE(ls->hld_max_time)) {
WRITE_ONCE(ls->hld_max_time, delta);
WRITE_ONCE(ls->hld_max_id, li->task_id);
bpf_get_current_comm(ls->hld_max_comm, TASK_COMM_LEN);
if (!per_thread)
bpf_get_current_comm(ls->hld_max_comm, TASK_COMM_LEN);
}
}

Expand Down
Loading