Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "LinuxPerf"
uuid = "b4c46c6c-4fb0-484d-a11a-41bc3392d094"
version = "0.4.2"
version = "0.4.3"

[deps]
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Expand Down
42 changes: 22 additions & 20 deletions src/LinuxPerf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,29 @@ function Base.show(io::IO, e::EventType)
end
end

const SYS_perf_event_open = if Sys.ARCH === :x86_64
Clong(298)
# To support a new architecture, look for the codes corresponding to the
# `perf_event_open` and `prctl` syscalls in
# https://gpages.juszkiewicz.com.pl/syscalls-table/syscalls.html
const SYS_perf_event_open, SYS_prctl = if Sys.ARCH === :x86_64
# See also https://github.com/torvalds/linux/blob/b62cef9a5c673f1b8083159f5dc03c1c5daced2f/arch/x86/entry/syscalls/syscall_64.tbl
Clong(298), Clong(157)
elseif Sys.ARCH === :i686
Clong(336)
# See also https://github.com/torvalds/linux/blob/b62cef9a5c673f1b8083159f5dc03c1c5daced2f/arch/x86/entry/syscalls/syscall_32.tbl
Clong(336), Clong(172)
elseif Sys.ARCH === :aarch64
Clong(241)
# See also https://github.com/torvalds/linux/blob/b62cef9a5c673f1b8083159f5dc03c1c5daced2f/scripts/syscall.tbl
Clong(241), Clong(167)
elseif Sys.ARCH === :arm
Clong(364)
# See also https://github.com/torvalds/linux/blob/b62cef9a5c673f1b8083159f5dc03c1c5daced2f/arch/arm/tools/syscall.tbl
Clong(364), Clong(172)
elseif Sys.ARCH === :powerpc64le || Sys.ARCH === :ppc64le
Clong(319)
# See also https://github.com/torvalds/linux/blob/b62cef9a5c673f1b8083159f5dc03c1c5daced2f/arch/powerpc/kernel/syscalls/syscall.tbl
Clong(319), Clong(171)
elseif Sys.ARCH === :riscv64 || Sys.ARCH === :rv64
# See also https://github.com/torvalds/linux/blob/b62cef9a5c673f1b8083159f5dc03c1c5daced2f/scripts/syscall.tbl
Clong(241), Clong(167)
else
Clong(-1) # sentinel for unknown syscall ID
Clong(-1), Clong(-1) # sentinel for unknown syscall ID
end

"""
Expand Down Expand Up @@ -340,19 +351,6 @@ function Base.show(io::IO, g::EventGroup)
print(io, "\t", g.event_types[end], ")")
end

const SYS_prctl = if Sys.ARCH === :x86_64
Clong(157)
elseif Sys.ARCH === :i686
Clong(172)
elseif Sys.ARCH === :aarch64
Clong(167)
elseif Sys.ARCH === :arm
Clong(172)
elseif Sys.ARCH === :powerpc64le || Sys.ARCH === :ppc64le
Clong(171)
else
Clong(-1) # sentinel for unknown syscall ID
end
const PR_TASK_PERF_EVENTS_DISABLE = Cint(31)
const PR_TASK_PERF_EVENTS_ENABLE = Cint(32)

Expand All @@ -376,6 +374,10 @@ const PR_TASK_PERF_EVENTS_ENABLE = Cint(32)
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))
elseif Sys.ARCH === :riscv64 || Sys.ARCH === :rv64
res = Base.llvmcall("""%val = call i64 asm sideeffect "ecall", "={a0},{a7},{a0},~{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))
else
# syscall is lower overhead than calling libc's prctl
res = ccall(:syscall, Cint, (Clong, Clong...), SYS_prctl, op)
Expand Down