Ways of Implementing a System Call
Another super-efficient way of implementing a system call is described in Alexia Massalin&#x27;s PhD classic thesis on the Synthesis Kernel:<p><a href="http:&#x2F;&#x2F;citeseerx.ist.psu.edu&#x2F;viewdoc&#x2F;download?doi=10.1.1.29.4871&amp;rep=rep1&amp;type=pdf" rel="nofollow">http:&#x2F;&#x2F;citeseerx.ist.psu.edu&#x2F;viewdoc&#x2F;download?doi=10.1.1.29....</a><p>&gt;Synthesis: An Efficient Implementation of Fundamental Operating System Services<p>&gt;This dissertation shows that operating systems can provide fundamental services
an order of magnitude more efficiently than traditional implementations. It describes the
implementation of a new operating system kernel, Synthesis, that achieves this level of
performance.<p>&gt;The Synthesis kernel combines several new techniques to provide high performance
without sacrificing the expressive power or security of the system. The new ideas include:<p>&gt;- Run-time code synthesis -- a systematic way of creating executable machine code
at runtime to optimize frequently-used kernel routines | queues, buffers, context
switchers, interrupt handlers, and system call dispatchers | for specific situations,
greatly reducing their execution time.<p>&gt;- Fine-grain scheduling -- a new process-scheduling technique based on the idea of
feedback that performs frequent scheduling actions and policy adjustments (at submillisecond intervals) resulting in an adaptive, self-tuning system that can support
real-time data streams.<p>&gt;- Lock-free optimistic synchronization is shown to be a practical, efficient alternative to
lock-based synchronization methods for the implementation of multiprocessor operating system kernels.<p>&gt;- An extensible kernel design that provides for simple expansion to support new kernel
services and hardware devices while allowing a tight coupling between the kernel and
the applications, blurring the distinction between user and kernel services.<p>&gt;The result is a significant performance improvement over traditional operating system implementations in addition to providing new services.<p>Previous discussion on HN:<p>The Synthesis Kernel (1988) [pdf] (usenix.org)<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=15076642" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=15076642</a><p><a href="https:&#x2F;&#x2F;www.usenix.org&#x2F;legacy&#x2F;publications&#x2F;compsystems&#x2F;1988&#x2F;win_pu.pdf" rel="nofollow">https:&#x2F;&#x2F;www.usenix.org&#x2F;legacy&#x2F;publications&#x2F;compsystems&#x2F;1988&#x2F;...</a><p>It’s Time for a Modern Synthesis Kernel (regehr.org)<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=20337231" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=20337231</a><p><a href="https:&#x2F;&#x2F;blog.regehr.org&#x2F;archives&#x2F;1676" rel="nofollow">https:&#x2F;&#x2F;blog.regehr.org&#x2F;archives&#x2F;1676</a><p>&gt;Alexia Massalin’s 1992 PhD thesis has long been one of my favorites. It promotes the view that operating systems can be much more efficient than then-current operating systems via runtime code generation, lock-free synchronization, and fine-grained scheduling. In this piece we’ll only look at runtime code generation, which can be cleanly separated from the other aspects of this work.<p>Valerie Henson&#x27;s commentary on the Synthesis kernel (2008) (lwn.net)<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=10441995" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=10441995</a><p><a href="https:&#x2F;&#x2F;lwn.net&#x2F;Articles&#x2F;270081&#x2F;" rel="nofollow">https:&#x2F;&#x2F;lwn.net&#x2F;Articles&#x2F;270081&#x2F;</a><p>KHB: Synthesis: An Efficient Implementation of Fundamental Operating Systems Services<p>&gt;When I was but a wee computer science student at New Mexico Tech, a graduate student in OS handed me an inch-thick print-out and told me that if I was really interested in operating systems, I had to read this. It was something about a completely lock-free operating system optimized using run-time code generation, written from scratch in assembly running on a homemade two-CPU SMP with a two-word compare-and-swap instruction - you know, nothing fancy. The print-out I was holding was Alexia (formerly Henry) Massalin&#x27;s PhD thesis, Synthesis: An Efficient Implementation of Fundamental Operating Systems Services (html version here). Dutifully, I read the entire 158 pages. At the end, I realized that I understood not a word of it, right up to and including the cartoon of a koala saying &quot;QUA!&quot; at the end. Okay, I exaggerate - lock-free algorithms had been a hobby of mine for the previous few months - but the main point I came away with was that there was a lot of cool stuff in operating systems that I had yet to learn.<p>&gt;Every year or two after that, I&#x27;d pick up my now bedraggled copy of &quot;Synthesis&quot; and reread it, and every time I would understand a little bit more. First came the lock-free algorithms, then the run-time code generation, then quajects. The individual techniques were not always new in and of themselves, but in Synthesis they were developed, elaborated, and implemented throughout a fully functioning UNIX-style operating system. I still don&#x27;t understand all of Synthesis, but I understand enough now to realize that my grad student friend was right: anyone really interested in operating systems should read this thesis.<p>Other interesting mentions:<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=19598385" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=19598385</a><p>&gt;Massalin&#x27;s Synthesis kernel [10] stands out to me as another example that for me crosses the boundaries and is both outstanding engineering and art in challenging the ideas of how systems could be built in ways that make me look at it just as much because of the beauty of it as because of the practical ideas. (The main thing it brought was the idea of making the kernel adapt to its clients by generating custom code for system calls; to me it is art because it turned the idea of a kernel as something static on its head; and conceptually we&#x27;re still just scraping the very surface of dynamic code generation in kernels that Massalin&#x27;s thesis started playing with). There are many works like that, where the specific implementations are irrelevant - nobody uses the Synthesis kernel - but where the ideas are as important as any expressed in more overt or &quot;intentional&quot; art.<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=20507155" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=20507155</a><p>&gt;ggm: It feels to me like if you can do runtime code call checks, and confirm which actual calls you make, then stripping the bits of libc and associated libraries out, being left with only the strictly required calls, and then by extension the syscalls, and then by extension the kernel elements, is actually possible a lot of the time. So, library -&gt; reduced library -&gt; reduced calls -&gt; reduced syscalls -&gt; reduced kernel state is a sequence or set or something, of applied minimisations which can be done, if you can predict all the call paths in your code and their dependencies.<p>&gt;NelsonMinar: That sounds a little like the ideas in the Synthesis kernel, the idea of the kernel JIT-compiling itself to optimize your code path.