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

RISC-V: cachestat tool fails to run: "no member named 'pc' in 'struct pt_regs'" #4110

Closed
euspectre opened this issue Jul 15, 2022 · 7 comments · Fixed by #4116
Closed

RISC-V: cachestat tool fails to run: "no member named 'pc' in 'struct pt_regs'" #4110

euspectre opened this issue Jul 15, 2022 · 7 comments · Fixed by #4116

Comments

@euspectre
Copy link

root@riscv64-test:/# ./cachestat
/virtual/main.c:13:14: error: no member named 'pc' in 'struct pt_regs'
    key.ip = PT_REGS_IP(ctx);
             ^~~~~~~~~~~~~~~
/virtual/include/bcc/helpers.h:1376:29: note: expanded from macro 'PT_REGS_IP'
#define PT_REGS_IP(x) ((x)->pc)
                       ~~~  ^
1 error generated.
Traceback (most recent call last):
  File "/usr/share/bcc/tools/./cachestat", line 96, in <module>
    b = BPF(text=bpf_text)
  File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 476, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>

System: QEMU VM with riscv64 CPU, OS: Ubuntu 22.04 with kernel 5.15.0-1014-generic.

If I understand it correctly, 'epc' should be used instead of 'pc', same as in arch/riscv/include/asm/ptrace.h.

diff --git a/src/cc/export/helpers.h b/src/cc/export/helpers.h
index 71ed8c8a..0f6e59ef 100644
--- a/src/cc/export/helpers.h
+++ b/src/cc/export/helpers.h
@@ -1373,7 +1373,7 @@ int bpf_usdt_readarg_p(int argc, struct pt_regs *ctx, void *buf, u64 len) asm("l
 #define PT_REGS_FP(x) ((x)->s0) /* Works only with CONFIG_FRAME_POINTER */
 #define PT_REGS_RC(x) ((x)->a0)
 #define PT_REGS_SP(x) ((x)->sp)
-#define PT_REGS_IP(x) ((x)->pc)
+#define PT_REGS_IP(x) ((x)->epc)
 #else
 #error "bcc does not support this platform yet"
 #endif

Right?
@xmzzz, what do you think?

@chenhengqi
Copy link
Collaborator

This is because ctx should be of type struct user_regs_struct * for RISC-V.

@xmzzz
Copy link
Contributor

xmzzz commented Jul 16, 2022

I think @chenhengqi is right, you can refer to:
#4085 (comment)
Thanks ^0^

@euspectre
Copy link
Author

So, libbpf already uses struct user_regs_struct there on RISC-V and the correct field is in fact 'pc'. OK.
I checked that src/cc/libbpf/cc/libbpf/src/bpf_tracing.h does have that part.

But cachestat built from the latest sources of bcc as described at https://github.com/iovisor/bcc/blob/master/INSTALL.md#source still tries to use struct pt_regs rather than struct user_regs_struct and fails. How so? I don't understand.

Some issue in the build scripts? Or?

@chenhengqi
Copy link
Collaborator

This should be fixed in BCC, you can just copy the macros from libbpf.

xmzzz added a commit to xmzzz/bcc that referenced this issue Jul 18, 2022
Fix iovisor#4110 . With this patch, running tools/cachestat on riscv64 can
get the expected result.

Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
@xmzzz
Copy link
Contributor

xmzzz commented Jul 18, 2022

This should be fixed in BCC, you can just copy the macros from libbpf.

Hi, @euspectre . I fixed it according to @chenhengqi ‘s suggestion and it worked.

Please let me know if I'm missing anything, thanks a lot.

@euspectre
Copy link
Author

This should be fixed in BCC, you can just copy the macros from libbpf.

I see. Thanks for the explanation.

@euspectre
Copy link
Author

The fix from #4116 helps in my system too. Great!

yonghong-song pushed a commit that referenced this issue Jul 21, 2022
Fix #4110 . With this patch, running tools/cachestat on riscv64 can
get the expected result.

Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
sterchelen pushed a commit to sterchelen/bcc that referenced this issue Sep 9, 2022
Fix iovisor#4110 . With this patch, running tools/cachestat on riscv64 can
get the expected result.

Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants