Compiler support for lightweight context switching
2013; Association for Computing Machinery; Volume: 9; Issue: 4 Linguagem: Inglês
10.1145/2400682.2400695
ISSN1544-3973
AutoresStephen K. Dolan, Servesh Muralidharan, David Gregg,
Tópico(s)Real-Time Systems Scheduling
ResumoWe propose a new language-neutral primitive for the LLVM compiler, which provides efficient context switching and message passing between lightweight threads of control. The primitive, called S wapstack , can be used by any language implementation based on LLVM to build higher-level language structures such as continuations, coroutines, and lightweight threads. As part of adding the primitives to LLVM, we have also added compiler support for passing parameters across context switches. Our modified LLVM compiler produces highly efficient code through a combination of exposing the context switching code to existing compiler optimizations, and adding novel compiler optimizations to further reduce the cost of context switches. To demonstrate the generality and efficiency of our primitives, we add one-shot continuations to C++, and provide a simple fiber library that allows millions of fibers to run on multiple cores, with a work-stealing scheduler and fast inter-fiber sychronization. We argue that compiler-supported lightweight context switching can be significantly faster than using a library to switch between contexts, and provide experimental evidence to support the position.
Referência(s)