Apr 12, 2022, 1:52:32 PM (6 months ago)
Thierry Delisle <tdelisle@…>
enum, master, pthread-emulation, qualifiedEnum

Filled in all of Chapter 4.
It's not great but it's worth discussing

1 edited


  • doc/theses/thierry_delisle_PhD/thesis/text/io.tex

    re88c2fb r3112733  
    406406Finally, the last important part of the \io subsystem is it's interface. There are multiple approaches that can be offered to programmers, each with advantages and disadvantages. The new \io subsystem can replace the C runtime's API or extend it. And in the later case the interface can go from very similar to vastly different. The following sections discuss some useful options using @read@ as an example. The standard Linux interface for C is :
    408 @ssize_t read(int fd, void *buf, size_t count);@.
     408@ssize_t read(int fd, void *buf, size_t count);@
    411 Replacing the C \glsxtrshort{api}
     411Replacing the C \glsxtrshort{api} is the more intrusive and draconian approach.
     412The goal is to convince the compiler and linker to replace any calls to @read@ to direct them to the \CFA implementation instead of glibc's.
     413This has the advantage of potentially working transparently and supporting existing binaries without needing recompilation.
     414It also offers a, presumably, well known and familiar API that C programmers can simply continue to work with.
     415However, this approach also entails a plethora of subtle technical challenges which generally boils down to making a perfect replacement.
     416If the \CFA interface replaces only \emph{some} of the calls to glibc, then this can easily lead to esoteric concurrency bugs.
     417Since the gcc ecosystems does not offer a scheme for such perfect replacement, this approach was rejected as being laudable but infeasible.
    413419\subsection{Synchronous Extension}
     420An other interface option is to simply offer an interface that is different in name only. For example:
     422@ssize_t cfa_read(int fd, void *buf, size_t count);@
     424\noindent This is much more feasible but still familiar to C programmers.
     425It comes with the caveat that any code attempting to use it must be recompiled, which can be a big problem considering the amount of existing legacy C binaries.
     426However, it has the advantage of implementation simplicity.
    415428\subsection{Asynchronous Extension}
     429It is important to mention that there is a certain irony to using only synchronous, therefore blocking, interfaces for a feature often referred to as ``non-blocking'' \io.
     430A fairly traditional way of doing this is using futures\cit{wikipedia futures}.
     431As simple way of doing so is as follows:
     433@future(ssize_t) read(int fd, void *buf, size_t count);@
     435\noindent Note that this approach is not necessarily the most idiomatic usage of futures.
     436The definition of read above ``returns'' the read content through an output parameter which cannot be synchronized on.
     437A more classical asynchronous API could look more like:
     439@future([ssize_t, void *]) read(int fd, size_t count);@
     441\noindent However, this interface immediately introduces memory lifetime challenges since the call must effectively allocate a buffer to be returned.
     442Because of the performance implications of this, the first approach is considered preferable as it is more familiar to C programmers.
    417444\subsection{Interface directly to \lstinline{io_uring}}
     445Finally, an other interface that can be relevant is to simply expose directly the underlying \texttt{io\_uring} interface. For example:
     447@array(SQE, want) cfa_io_allocate(int want);@
     449@void cfa_io_submit( const array(SQE, have) & );@
     451\noindent This offers more flexibility to users wanting to fully use all of the \texttt{io\_uring} features.
     452However, it is not the most user-friendly option.
     453It obviously imposes a strong dependency between user code and \texttt{io\_uring} but at the same time restricting users to usages that are compatible with how \CFA internally uses \texttt{io\_uring}.
Note: See TracChangeset for help on using the changeset viewer.