Figure 7 - uploaded by Gabriel Kerneis
Content may be subject to copyright.
10: Web server benchmark

10: Web server benchmark

Source publication
Full-text available
Most computer programs are concurrent ones: they need to perform several tasks at the same time. Threads and events are two common techniques to implement concurrency. Events are generally more lightweight and efficient than threads, but also more difficult to use. Additionally, they are often not powerful enough; it is then necessary to write hybr...


... This code is then automatically transformed into an equivalent standard C program written in asynchronous, event-driven style. Our previous experiments on small to medium-sized programs have shown that the translated code is at least as efficient as stack-based thread implementations, while providing a significantly smaller memory footprint [23,25]. However, CPC had never been tested on programs as large as QEMU before this case study. ...
... cps void loop(int x, cont *k) {if(x <= 0) { timeout(k); return; } printf("%d\n", x--); cpc_sleep(1, push(loop, x, k)); return; } cps void timeout(cont *k) { printf("time is over!\n"); invoke(k); return; } cps void countdown(int x, cont *k) { loop(x, k); return; } Just like lambda lifting, CPS conversion is not correct in general in an imperative call-by-value language, because variables are duplicated to be stored on the continuation. It is however correct in the case of CPC, for reasons similar to the correctness of lambda lifting[23, Chapter 5]. ...
Conference Paper
Full-text available
Coroutines and events are two common abstractions for writing concurrent programs. Because coroutines are often more convenient, but events more portable and efficient, it is natural to want to translate the former into the latter. CPC is such a source-to-source translator for C programs, based on a partial conversion into continuation-passing style (CPS conversion) of functions annotated as cooperative. In this article, we study the application of the CPC translator to QEMU, an open-source machine emulator which also uses annotated coroutine functions for concurrency. We first propose a new type of annotations to identify functions which never cooperate, and we introduce CoroCheck, a tool for the static analysis and inference of cooperation annotations. Then, we improve the CPC translator, defining CPS conversion as a calling convention for the C language, with support for indirect calls to CPS-converted function through function pointers. Finally, we apply CoroCheck and CPC to QEMU (750 000 lines of C code), fixing hundreds of missing annotations and comparing performance of the translated code with existing implementations of coroutines in QEMU. Our work shows the importance of static annotation checking to prevent actual concurrency bugs, and demonstrates that CPS conversion is a flexible, portable, and efficient compilation technique, even for very large programs written in an imperative language.