JuliaLang/julia

Improve task switch performance

Open

#39.680 aperta il 16 feb 2021

Vedi su GitHub
 (5 commenti) (1 reazione) (0 assegnatari)Julia (5773 fork)batch import
help wantedperformance

Metriche repository

Star
 (48.709 star)
Metriche merge PR
 (Merge medio 20g 6h) (157 PR mergiate in 30 g)

Descrizione

From discussion with @vtjnash, our current stack-switching scheme is suboptimal. Since we know the switch point in an ideal world, we'd only need to capture the ip and the stack pointer (or maybe even only the stack pointer if the ip is always at a fixed location). While some platform specific assembly is inevitable to capture these variables, we'd like to avoid adding heaps of platform specific assembly. Thus the proposed plan is:

  1. Have platform specific assembly for the sp/ip registers only
  2. For all other registers, have a snippet of LLVM IR that takes in the necessary arguments in C calling convention and forwards them to a calling convention in which all registers are preserved. Doing this for all platforms may require changes in LLVM. The GHC calling convention seems to do this on relevant platforms, but for full generality, we may want to add a preserve_none calling convention.
  3. In an offline step, ask LLVM to generate .S files from this snippet for all platforms we care about.
  4. Profit.

The nice thing about this is that we don't need to duplicate any knowledge the compiler already has (which registers need to be spilled to have the function be properly C calling conventions). Additionally, should we ever want to embed a task switch directly in Julia code, we can use the calling convention support to have it spill just the registers that it actually needs to restore.

Guida contributor