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

Support riscv64 #56

Merged
merged 4 commits into from
Jan 12, 2025
Merged

Support riscv64 #56

merged 4 commits into from
Jan 12, 2025

Conversation

giordano
Copy link
Contributor

Fix #55.

I can confirm tests pass locally:

     Testing Running tests...
hardware:
  branch-instructions      user, hypervisor
  branch-misses            user, hypervisor
  cache-misses             user, hypervisor
  cache-references         user, hypervisor
  cpu-cycles               user, hypervisor
  instructions             user, hypervisor
  stalled-cycles-backend   user, hypervisor
  stalled-cycles-frontend  user, hypervisor

software:
  alignment-faults         user, hypervisor
  bpf-output               user, hypervisor
  context-switches         user, hypervisor
  cpu-clock                user, hypervisor
  cpu-migrations           user, hypervisor
  dummy                    user, hypervisor
  emulation-faults         user, hypervisor
  major-faults             user, hypervisor
  minor-faults             user, hypervisor
  page-faults              user, hypervisor
  task-clock               user, hypervisor

cache:
  L1-dcache-load-misses    user, hypervisor
  L1-dcache-loads          user, hypervisor
  L1-dcache-store-misses   user, hypervisor
  L1-dcache-stores         user, hypervisor
  L1-icache-load-misses    user, hypervisor
  L1-icache-loads          user, hypervisor
  LLC-load-misses          user, hypervisor
  LLC-loads                user, hypervisor
  LLC-store-misses         user, hypervisor
  LLC-stores               user, hypervisor
  dTLB-load-misses         user, hypervisor
  dTLB-loads               user, hypervisor
  iTLB-load-misses         user, hypervisor
  iTLB-loads               user, hypervisor
Test Summary: | Pass  Total   Time
LinuxPerf     |   37     37  17.1s
     Testing LinuxPerf tests passed

Question: I presume it'd be nicer to add the llvmcall in

@inline function prctl(op)
if SYS_prctl == -1
res = ccall(:prctl, Cint, (Cint, Cint...), op)
return Base.systemerror(:prctl, res < 0)
elseif Sys.ARCH == :x86_64
res = Base.llvmcall("""%val = call i64 asm sideeffect "syscall", "={rax},{rax},{rdi},~{rcx},~{r11},~{memory}"(i64 %0, i64 %1)
ret i64 %val""", Int64, Tuple{Int64, Int64}, SYS_prctl, Int64(op))
return (res >= 0) ? nothing : throw(Base.SystemError("prctl", -res, nothing))
elseif Sys.ARCH == :i686
res = Base.llvmcall("""%val = call i32 asm sideeffect "int \$\$0x80", "={eax},{eax},{ebx},~{memory}"(i32 %0, i32 %1)
ret i32 %val""", Int32, Tuple{Int32, Int32}, SYS_prctl, Int32(op))
return (res >= 0) ? nothing : throw(Base.SystemError("prctl", -res, nothing))
elseif Sys.ARCH == :aarch64
res = Base.llvmcall("""%val = call i64 asm sideeffect "svc #0", "={x0},{x8},{x0},~{memory}"(i64 %0, i64 %1)
ret i64 %val""", Int64, Tuple{Int64, Int64}, SYS_prctl, Int64(op))
return (res >= 0) ? nothing : throw(Base.SystemError("prctl", -res, nothing))
elseif Sys.ARCH == :arm
res = Base.llvmcall("""%val = call i32 asm sideeffect "swi 0", "={r0},{r7},{r0},~{memory}"(i32 %0, i32 %1)
ret i32 %val""", Int32, Tuple{Int32, Int32}, SYS_prctl, Int32(op))
return (res >= 0) ? nothing : throw(Base.SystemError("prctl", -res, nothing))
else
# syscall is lower overhead than calling libc's prctl
res = ccall(:syscall, Cint, (Clong, Clong...), SYS_prctl, op)
return Base.systemerror(:prctl, res < 0)
end
end
?

@Zentrik
Copy link
Collaborator

Zentrik commented Jan 12, 2025

Question: I presume it'd be nicer to add the llvmcall in

Yes, if you want a slightly lower overhead.

src/LinuxPerf.jl Outdated
@@ -167,6 +167,9 @@ elseif Sys.ARCH === :arm
Clong(364)
elseif Sys.ARCH === :powerpc64le || Sys.ARCH === :ppc64le
Clong(319)
elseif Sys.ARCH === :riscv64 || Sys.ARCH === :rv64
# See syscalls table at https://jborza.com/post/2021-05-11-riscv-linux-syscalls/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is a nicer table as a reference, it has all architectures: https://gpages.juszkiewicz.com.pl/syscalls-table/syscalls.html

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely

src/LinuxPerf.jl Outdated
Clong(336)
elseif Sys.ARCH === :aarch64
# See also https://arm64.syscall.sh/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and risc use the generic syscall table in the kernel btw

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did find https://github.com/torvalds/linux/blob/b62cef9a5c673f1b8083159f5dc03c1c5daced2f/arch/arm64/tools/syscall_64.tbl (while I didn't find any symlink at all for riscv64), I was a bit hesitant to link here a generic table, but I guess that's what it is. Ok, I'll update the reference later.

@Zentrik Zentrik merged commit 995f38f into JuliaPerf:master Jan 12, 2025
1 check passed
@giordano giordano deleted the mg/riscv64 branch January 12, 2025 20:54
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.

ERROR: perf_event_open error : unknown architecture on riscv64
2 participants