Skip to content

Commit

Permalink
bpf: make test py_test_tools_smoke pass on arm64
Browse files Browse the repository at this point in the history
Changes include:
  . Add PT_REGS_FP to access base(FP) register in x64
  . Use macros, intead of directly ctx-><reg_name>
    in a few places
  . Let userspace fill in the value of PAGE_SIZE.
    Otherwise, arm64 needs additional headers to
    get this value for kernel.
  . In tools/wakeuptime.py, arm64 and x86_64 have
    the same stack walker mechanism. But they
    have different symbol/macro to represent
    kernel start address.
With these changes, the test py_test_tools_smoke
can pass on arm64.

Signed-off-by: Yonghong Song <[email protected]>
  • Loading branch information
yonghong-song committed Oct 27, 2017
1 parent 740c407 commit eb6ddc0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/cc/export/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ int bpf_usdt_readarg_p(int argc, struct pt_regs *ctx, void *buf, u64 len) asm("l
#define PT_REGS_PARM4(ctx) ((ctx)->cx)
#define PT_REGS_PARM5(ctx) ((ctx)->r8)
#define PT_REGS_PARM6(ctx) ((ctx)->r9)
#define PT_REGS_FP(ctx) ((ctx)->bp) /* Works only with CONFIG_FRAME_POINTER */
#define PT_REGS_RC(ctx) ((ctx)->ax)
#define PT_REGS_IP(ctx) ((ctx)->ip)
#define PT_REGS_SP(ctx) ((ctx)->sp)
Expand Down
2 changes: 1 addition & 1 deletion tools/lib/ucalls.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
#ifdef SYSCALLS
int syscall_entry(struct pt_regs *ctx) {
u64 pid = bpf_get_current_pid_tgid();
u64 *valp, ip = ctx->ip, val = 0;
u64 *valp, ip = PT_REGS_IP(ctx), val = 0;
PID_FILTER
#ifdef LATENCY
struct syscall_entry_t data = {};
Expand Down
2 changes: 2 additions & 0 deletions tools/memleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from bcc import BPF
from time import sleep
from datetime import datetime
import resource
import argparse
import subprocess
import os
Expand Down Expand Up @@ -366,6 +367,7 @@ def run_command_get_pid(command):

bpf_source = bpf_source.replace("SHOULD_PRINT", "1" if trace_all else "0")
bpf_source = bpf_source.replace("SAMPLE_EVERY_N", str(sample_every_n))
bpf_source = bpf_source.replace("PAGE_SIZE", str(resource.getpagesize()))

size_filter = ""
if min_size is not None and max_size is not None:
Expand Down
10 changes: 8 additions & 2 deletions tools/wakeuptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,19 @@ def signal_ignore(signal, frame):
static u64 get_frame(u64 *bp) {
if (*bp) {
// The following stack walker is x86_64 specific
// The following stack walker is x86_64/arm64 specific
u64 ret = 0;
if (bpf_probe_read(&ret, sizeof(ret), (void *)(*bp+8)))
return 0;
if (bpf_probe_read(bp, sizeof(*bp), (void *)*bp))
return 0;
#ifdef __x86_64__
if (ret < __START_KERNEL_map)
#elif __aarch64__
if (ret < VA_START)
#else
#error "Unsupported architecture for stack walker"
#endif
return 0;
return ret;
}
Expand Down Expand Up @@ -121,7 +127,7 @@ def signal_ignore(signal, frame):
bpf_probe_read(&key.target, sizeof(key.target), p->comm);
bpf_get_current_comm(&key.waker, sizeof(key.waker));
bp = ctx->bp;
bp = PT_REGS_FP(ctx);
// unrolled loop (MAXDEPTH):
if (!(key.ret[depth++] = get_frame(&bp))) goto out;
Expand Down

0 comments on commit eb6ddc0

Please sign in to comment.