Skip to content

Commit

Permalink
Support kfunc in vfsstat.py
Browse files Browse the repository at this point in the history
Adding kfunc return trampoline probe if available instead of
kprobe/kretprobe probes.

The kfunc trampolines are faster - less intrusive.

Below are stats for running perf bench sched pipe benchamark while
running vfsstat.py on the background for kprobes and kfuncs.

With kprobes:
         Performance counter stats for './perf bench sched pipe -l 5000000' (3 runs):

           112,520,853,574      cycles:k

                    48.674 +- 0.672 seconds time elapsed  ( +-  1.38% )

With kfuncs:
         Performance counter stats for './perf bench sched pipe -l 5000000' (3 runs):

           106,304,165,424      cycles:k

                    46.820 +- 0.197 seconds time elapsed  ( +-  0.42% )

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri authored and yonghong-song committed Feb 27, 2020
1 parent da7cac7 commit 2fa54c0
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions tools/vfsstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def usage():
usage()

# load BPF program
b = BPF(text="""
bpf_text = """
#include <uapi/linux/ptrace.h>
enum stat_types {
Expand All @@ -55,18 +55,38 @@ def usage():
u64 *leaf = stats.lookup(&key);
if (leaf) (*leaf)++;
}
"""

bpf_text_kprobe = """
void do_read(struct pt_regs *ctx) { stats_increment(S_READ); }
void do_write(struct pt_regs *ctx) { stats_increment(S_WRITE); }
void do_fsync(struct pt_regs *ctx) { stats_increment(S_FSYNC); }
void do_open(struct pt_regs *ctx) { stats_increment(S_OPEN); }
void do_create(struct pt_regs *ctx) { stats_increment(S_CREATE); }
""")
b.attach_kprobe(event="vfs_read", fn_name="do_read")
b.attach_kprobe(event="vfs_write", fn_name="do_write")
b.attach_kprobe(event="vfs_fsync", fn_name="do_fsync")
b.attach_kprobe(event="vfs_open", fn_name="do_open")
b.attach_kprobe(event="vfs_create", fn_name="do_create")
"""

bpf_text_kfunc = """
KFUNC_PROBE(vfs_read, int unused) { stats_increment(S_READ); }
KFUNC_PROBE(vfs_write, int unused) { stats_increment(S_WRITE); }
KFUNC_PROBE(vfs_fsync, int unused) { stats_increment(S_FSYNC); }
KFUNC_PROBE(vfs_open, int unused) { stats_increment(S_OPEN); }
KFUNC_PROBE(vfs_create, int unused) { stats_increment(S_CREATE); }
"""

is_support_kfunc = BPF.support_kfunc()
#is_support_kfunc = False #BPF.support_kfunc()
if is_support_kfunc:
bpf_text += bpf_text_kfunc
else:
bpf_text += bpf_text_kprobe

b = BPF(text=bpf_text)
if not is_support_kfunc:
b.attach_kprobe(event="vfs_read", fn_name="do_read")
b.attach_kprobe(event="vfs_write", fn_name="do_write")
b.attach_kprobe(event="vfs_fsync", fn_name="do_fsync")
b.attach_kprobe(event="vfs_open", fn_name="do_open")
b.attach_kprobe(event="vfs_create", fn_name="do_create")

# stat column labels and indexes
stat_types = {
Expand Down

0 comments on commit 2fa54c0

Please sign in to comment.