KEMBAR78
Basic RISC-V support by shipilev · Pull Request #644 · async-profiler/async-profiler · GitHub
Skip to content

Conversation

@shipilev
Copy link
Contributor

@shipilev shipilev commented Sep 2, 2022

This PR adds the support for building and running on riscv64 platforms. I have built and tested it on HiFive Unmatched board running Ubuntu 22.04, and ran async-profiler with JMH -prof async and bleeding edge mainline JDK 20 build. The flamegraphs seem to make sense: it resolves C2 native code well, resolves compiled code well, etc.

riscv64-async

I tested with -Xint, -XX:TieredStopAtLevel=1 (C1), default (C2).

I still call this support "basic", because it is not tested beyound toy examples, and some features (like stub pops) are stubbed out.

@apangin
Copy link
Member

apangin commented Sep 5, 2022

Thanks, that sounds interesting. I'll take a look.

How do you see the future maintenance of RISC-V port? Currently, I can't guarantee that ongoing development will keep the port functioning or even buildable.

@shipilev
Copy link
Contributor Author

shipilev commented Sep 5, 2022

How do you see the future maintenance of RISC-V port? Currently, I can't guarantee that ongoing development will keep the port functioning or even buildable.

I can take a look at it every once in a while, or maybe someone from RISC-V community takes on that role too. I wonder if there is a way to integrate the support for these arches under heavy "It would probably build, it would probably work, but it is not tested well" caveat warnings.

@luhenry
Copy link
Contributor

luhenry commented Sep 5, 2022

We could have a minimum of cross-compilation even if we don't run any tests. I'm happy to take a look at it in the future (working on Java on RISC-V now).

@RealFYang
Copy link

RealFYang commented Nov 28, 2022

Hi,

Let me revive this please.

Turns out that @zifeihan from my team has real-world working experience with the async-profiler tool.
He is currently working on investigating and enabling open-source Java performance tools on linux-riscv platform.
I think async-profiler riscv port will be a good start point. He will be responsible for future ongoing development of the
riscv port and will keep the port functioning.

@zifeihan: Could you please post your extra changes needed for the latest codebase and the test results?
@apangin : Could we have a reivew for this please? Thanks.

@zifeihan
Copy link

zifeihan commented Nov 28, 2022

@shipilev Hello aleksey, Following extra change is needed to make this buildable with latest async-profiler code:

diff --git a/src/arch.h b/src/arch.h
index 46842fd..5f1c6df 100644
--- a/src/arch.h
+++ b/src/arch.h
@@ -128,6 +128,7 @@ const int BREAKPOINT_OFFSET = 0;
 const int SYSCALL_SIZE = sizeof(instruction_t);
 const int FRAME_PC_SLOT = 1;    // return address is at -1 from FP
 const int ADJUST_RET = 0;       // No need for adjustments
+const int PROBE_SP_LIMIT = 0;
 const int PLT_HEADER_SIZE = 24; // Best guess from examining readelf
 const int PLT_ENTRY_SIZE = 24;  // ...same...
 const int PERF_REG_PC = 0;      // PERF_REG_RISCV_PC

Could you please add this into this PR? Thanks. And this is the detailed test output using latest async-profiler codebase on Linux-riscv64 platform:

zifeihan@ubuntu:~/async-profiler$ uname -a
Linux ubuntu 5.11.0-1028-generic #31-Ubuntu SMP Wed Jan 12 18:50:58 UTC 2022 riscv64 riscv64 riscv64 GNU/Linux
zifeihan@ubuntu:~/async-profiler$ make test
test/smoke-test.sh
+ '[' -z /home/zifeihan/jdk-bin/jdk ']'
++ dirname test/smoke-test.sh
+ cd test
+ '[' Target.class -ot Target.java ']'
+ FILENAME=/tmp/java.trace
+ /home/zifeihan/jdk-bin/jdk/bin/java Target
+ JAVAPID=1057017
+ sleep 1
Starting...
+ ../profiler.sh -f /tmp/java.trace -o collapsed -d 5 1057017
Profiling started
Profiling for 5 seconds
Done
+ kill 1057017
+ assert_string 'Target.main;Target.method1 '
+ grep -q 'Target.main;Target.method1 ' /tmp/java.trace
+ assert_string 'Target.main;Target.method2 '
+ grep -q 'Target.main;Target.method2 ' /tmp/java.trace
+ assert_string 'Target.main;Target.method3;java/io/File'
+ grep -q 'Target.main;Target.method3;java/io/File' /tmp/java.trace
test/thread-smoke-test.sh
+ '[' -z /home/zifeihan/jdk-bin/jdk ']'
++ dirname test/thread-smoke-test.sh
+ cd test
+ '[' ThreadsTarget.class -ot ThreadsTarget.java ']'
+ FILENAME=/tmp/java.trace
+ /home/zifeihan/jdk-bin/jdk/bin/java -agentpath:../build/libasyncProfiler.so=start,event=cpu,collapsed,threads,file=/tmp/java.trace ThreadsTarget
Profiling started
+ assert_string '\[ThreadEarlyEnd tid=[0-9]\+\];.*ThreadsTarget.methodForThreadEarlyEnd;.*'
+ grep -q '\[ThreadEarlyEnd tid=[0-9]\+\];.*ThreadsTarget.methodForThreadEarlyEnd;.*' /tmp/java.trace
+ assert_string '\[RenamedThread tid=[0-9]\+\];.*ThreadsTarget.methodForRenamedThread;.*'
+ grep -q '\[RenamedThread tid=[0-9]\+\];.*ThreadsTarget.methodForRenamedThread;.*' /tmp/java.trace
test/alloc-smoke-test.sh
+ '[' -z /home/zifeihan/jdk-bin/jdk ']'
++ dirname test/alloc-smoke-test.sh
+ cd test
+ '[' AllocatingTarget.class -ot AllocatingTarget.java ']'
+ FILENAME=/tmp/java.trace
+ /home/zifeihan/jdk-bin/jdk/bin/java AllocatingTarget
+ JAVAPID=1057094
+ sleep 1
+ ../profiler.sh -f /tmp/java.trace -o collapsed -d 5 -e alloc -t 1057094
Profiling started
Profiling for 5 seconds
Done
+ kill 1057094
+ assert_string '\[AllocThread-1 tid=[0-9]\+\];.*AllocatingTarget.allocate;.*java.lang.Integer\[\]'
+ grep -q '\[AllocThread-1 tid=[0-9]\+\];.*AllocatingTarget.allocate;.*java.lang.Integer\[\]' /tmp/java.trace
+ assert_string '\[AllocThread-2 tid=[0-9]\+\];.*AllocatingTarget.allocate;.*int\[\]'
+ grep -q '\[AllocThread-2 tid=[0-9]\+\];.*AllocatingTarget.allocate;.*int\[\]' /tmp/java.trace
test/load-library-test.sh
+ '[' -z /home/zifeihan/jdk-bin/jdk ']'
++ dirname test/load-library-test.sh
+ cd test
+ '[' LoadLibraryTest.class -ot LoadLibraryTest.java ']'
+ FILENAME=/tmp/java.trace
+ JAVAPID=1057141
+ sleep 1
+ /home/zifeihan/jdk-bin/jdk/bin/java -agentpath:../build/libasyncProfiler.so LoadLibraryTest
+ ../profiler.sh -f /tmp/java.trace -o collapsed -d 5 -i 1ms 1057141
Profiling started
Profiling for 5 seconds
Done
+ kill 1057141
+ assert_string Java_sun_management
+ grep -q Java_sun_management /tmp/java.trace
test/fdtransfer-smoke-test.sh
++ uname -s
+ UNAME_S=Linux
+ '[' Linux '!=' Linux ']'
+ '[' -z /home/zifeihan/jdk-bin/jdk ']'
++ dirname test/fdtransfer-smoke-test.sh
+ cd test
+ '[' Target.class -ot Target.java ']'
+ FILENAME=/tmp/java.trace
+ /home/zifeihan/jdk-bin/jdk/bin/java Target
+ JAVAPID=1057183
+ sleep 1
Starting...
+ sudo ../profiler.sh -f /tmp/java.trace -o collapsed -e cpu -i 1ms --fdtransfer -d 5 1057183
Profiling started
Profiling for 5 seconds
^@Done
+ kill 1057183
+ assert_string 'Target.main;Target.method1 '
+ grep -q 'Target.main;Target.method1 ' /tmp/java.trace
+ assert_string 'Target.main;Target.method2 '
+ grep -q 'Target.main;Target.method2 ' /tmp/java.trace
+ assert_string 'Target.main;Target.method3;java/io/File'
+ grep -q 'Target.main;Target.method3;java/io/File' /tmp/java.trace
+ assert_string sys_getdents
+ grep -q sys_getdents /tmp/java.trace
echo "All tests passed"
All tests passed

And I have also collected the sampling results for several test items from specjvm2008 and compared with results on linux-aarch64 platform. Sampling results look good. @apangin : Could you please take a look at these changes? Thanks

@shipilev
Copy link
Contributor Author

@shipilev Hello aleksey, Following extra change is needed to make this buildable with latest async-profiler code:

Added!

@apangin
Copy link
Member

apangin commented Nov 29, 2022

Hi and thank you for working on this.

I have nothing against the content, however, the project does not accept external code contributions at this moment. This is temporary. I'll get back to you as soon as I resolve the blockers. I appreciate your patience.

@shipilev shipilev force-pushed the basic-riscv64-support branch from 6a0e2ee to 1fc609c Compare November 25, 2023 08:09
@apangin apangin merged commit 752b79e into async-profiler:master Nov 26, 2023
apangin added a commit that referenced this pull request Nov 26, 2023
@apangin
Copy link
Member

apangin commented Nov 26, 2023

Thank you for the contribution. I merged the PR with the minor follow-up fixes.
Verified in QEMU that make test passes.

@zifeihan
Copy link

Hi, it's great to see this merged. I also performed make test on LicheePI-4A board. Result looks good. I'll keep an eye on the async-profiler upstream code update, and try to keep the riscv part up to date.

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 this pull request may close these issues.

5 participants