Skip to content

Commit 5f1d175

Browse files
committed
Add fast prctl implementation for i686/armv7
This gets me down to ~5-6 instructions of overhead on x86 and armv7: ```julia julia> println(Sys.ARCH); @pstats "(instructions,branch-instructions,branch-misses)" nothing arm ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ┌ instructions 6.00e+00 100.0% │ branch-instructions 1.00e+00 100.0% # 16.7% of insns └ branch-misses 0.00e+00 100.0% # 0.0% of branch insns ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ``` ```julia julia> println(Sys.ARCH); @pstats "(instructions,branch-instructions,branch-misses)" nothing i686 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ┌ instructions 5.00e+00 100.0% │ branch-instructions 2.00e+00 100.0% # 40.0% of insns └ branch-misses 1.00e+00 100.0% # 50.0% of branch insns ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ```
1 parent e1d19cf commit 5f1d175

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/LinuxPerf.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,18 @@ const PR_TASK_PERF_EVENTS_ENABLE = Cint(32)
360360
res = Base.llvmcall("""%val = call i64 asm sideeffect "syscall", "={rax},{rax},{rdi},~{rcx},~{r11},~{memory}"(i64 %0, i64 %1)
361361
ret i64 %val""", Int64, Tuple{Int64, Int64}, SYS_prctl, Int64(op))
362362
return (res >= 0) ? nothing : throw(Base.SystemError("prctl", -res, nothing))
363+
elseif Sys.ARCH == :i686
364+
res = Base.llvmcall("""%val = call i32 asm sideeffect "int \$\$0x80", "={eax},{eax},{ebx},~{memory}"(i32 %0, i32 %1)
365+
ret i32 %val""", Int32, Tuple{Int32, Int32}, SYS_prctl, Int32(op))
366+
return (res >= 0) ? nothing : throw(Base.SystemError("prctl", -res, nothing))
363367
elseif Sys.ARCH == :aarch64
364368
res = Base.llvmcall("""%val = call i64 asm sideeffect "svc #0", "={x0},{x8},{x0},~{memory}"(i64 %0, i64 %1)
365369
ret i64 %val""", Int64, Tuple{Int64, Int64}, SYS_prctl, Int64(op))
366370
return (res >= 0) ? nothing : throw(Base.SystemError("prctl", -res, nothing))
371+
elseif Sys.ARCH == :arm
372+
res = Base.llvmcall("""%val = call i32 asm sideeffect "swi 0", "={r0},{r7},{r0},~{memory}"(i32 %0, i32 %1)
373+
ret i32 %val""", Int32, Tuple{Int32, Int32}, SYS_prctl, Int32(op))
374+
return (res >= 0) ? nothing : throw(Base.SystemError("prctl", -res, nothing))
367375
else
368376
# syscall is lower overhead than calling libc's prctl
369377
res = ccall(:syscall, Cint, (Clong, Clong...), SYS_prctl, op)

0 commit comments

Comments
 (0)