Changeset 62424af2


Ignore:
Timestamp:
Sep 9, 2022, 3:44:44 PM (22 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
4a2d728, d895e32
Parents:
264f6c9
Message:

More spell/grammer checking

Location:
doc/theses/thierry_delisle_PhD/thesis/text
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/thierry_delisle_PhD/thesis/text/core.tex

    r264f6c9 r62424af2  
    1010
    1111\section{Design Goals}
    12 As with most of the design decisions behind \CFA, an important goal is to match the expectation of the programmer according to their execution mental-model.
    13 To match expectations, the design must offer the programmer sufficient guarantees so that, as long as they respect the execution mental-model, the system also respects this model.
    14 
    15 For threading, a simple and common execution mental-model is the ``Ideal multi-tasking CPU'' :
     12As with most of the design decisions behind \CFA, an important goal is to match the expectation of the programmer according to their execution mental model.
     13To match expectations, the design must offer the programmer sufficient guarantees so that, as long as they respect the execution mental model, the system also respects this model.
     14
     15For threading, a simple and common execution mental model is the ``Ideal multi-tasking CPU'' :
    1616
    1717\begin{displayquote}[Linux CFS\cite{MAN:linux/cfs}]
    18         {[The]} ``Ideal multi-tasking CPU'' is a (non-existent  :-)) CPU that has 100\% physical power and which can run each task at precise equal speed, in parallel, each at [an equal fraction of the] speed.  For example: if there are 2 tasks running, then it runs each at 50\% physical power --- i.e., actually in parallel.
     18        {[The]} ``Ideal multi-tasking CPU'' is a (non-existent  :-)) CPU that has 100\% physical power and which can run each task at precise equal speed, in parallel, each at [an equal fraction of the] speed.  For example: if there are 2 running tasks, then it runs each at 50\% physical power --- i.e., actually in parallel.
    1919        \label{q:LinuxCFS}
    2020\end{displayquote}
     
    4040This demonstration can be made by comparing applications built in \CFA to applications built with other languages or other models.
    4141Recall programmer expectation is that the impact of the scheduler can be ignored.
    42 Therefore, if the cost of scheduling is competitive to other popular languages, the guarantee is consider achieved.
     42Therefore, if the cost of scheduling is competitive with other popular languages, the guarantee is considered achieved.
    4343More precisely the scheduler should be:
    4444\begin{itemize}
     
    5353In any running system, a \proc can stop dequeuing \ats if it starts running a \at that never blocks.
    5454Without preemption, traditional work-stealing schedulers do not have starvation freedom in this case.
    55 Now this requirement begs the question, what about preemption?
    56 Generally speaking preemption happens on the timescale of several milliseconds, which brings us to the next requirement: ``fast'' load balancing.
     55Now, this requirement begs the question, what about preemption?
     56Generally speaking, preemption happens on the timescale of several milliseconds, which brings us to the next requirement: ``fast'' load balancing.
    5757
    5858\paragraph{Fast load balancing} means that load balancing should happen faster than preemption would normally allow.
    59 For interactive applications that need to run at 60, 90, 120 frames per second, \ats having to wait for several milliseconds to run are effectively starved.
     59For interactive applications that need to run at 60, 90 or 120 frames per second, \ats having to wait for several milliseconds to run are effectively starved.
    6060Therefore load-balancing should be done at a faster pace, one that can detect starvation at the microsecond scale.
    6161With that said, this is a much fuzzier requirement since it depends on the number of \procs, the number of \ats and the general \gls{load} of the system.
     
    6969For a scheduler, having good locality, \ie, having the data local to each \gls{hthrd}, generally conflicts with fairness.
    7070Indeed, good locality often requires avoiding the movement of cache lines, while fairness requires dynamically moving a \at, and as consequence cache lines, to a \gls{hthrd} that is currently available.
    71 Note that this section discusses \emph{internal locality}, \ie, the locality of the data used by the scheduler versus \emph{external locality}, \ie, how the data used by the application is affected by scheduling.
     71Note that this section discusses \emph{internal locality}, \ie, the locality of the data used by the scheduler versus \emph{external locality}, \ie, how scheduling affects the locality of the application's data.
    7272External locality is a much more complicated subject and is discussed in the next section.
    7373
    7474However, I claim that in practice it is possible to strike a balance between fairness and performance because these goals do not necessarily overlap temporally.
    7575Figure~\ref{fig:fair} shows a visual representation of this behaviour.
    76 As mentioned, some unfairness is acceptable; therefore it is desirable to have an algorithm that prioritizes cache locality as long as thread delay does not exceed the execution mental-model.
     76As mentioned, some unfairness is acceptable; therefore it is desirable to have an algorithm that prioritizes cache locality as long as thread delay does not exceed the execution mental model.
    7777
    7878\begin{figure}
     
    8080        \input{fairness.pstex_t}
    8181        \vspace*{-10pt}
    82         \caption[Fairness vs Locality graph]{Rule of thumb Fairness vs Locality graph \smallskip\newline The importance of Fairness and Locality while a ready \at awaits running is shown as the time the ready \at waits increases, Ready Time, the chances that its data is still in cache decreases, Locality.
     82        \caption[Fairness vs Locality graph]{Rule of thumb Fairness vs Locality graph \smallskip\newline The importance of Fairness and Locality while a ready \at awaits running is shown as the time the ready \at waits increases (Ready Time) the chances that its data is still in cache decreases (Locality).
    8383        At the same time, the need for fairness increases since other \ats may have the chance to run many times, breaking the fairness model.
    8484        Since the actual values and curves of this graph can be highly variable, the graph is an idealized representation of the two opposing goals.}
     
    9494Given a large number of \procs and an even larger number of \ats, scalability measures how fast \procs can enqueue and dequeues \ats.
    9595One could expect that doubling the number of \procs would double the rate at which \ats are dequeued, but contention on the internal data structure of the scheduler can lead to worst improvements.
    96 While the ready-queue itself can be sharded to alleviate the main source of contention, auxiliary scheduling features, \eg counting ready \ats, can also be sources of contention.
     96While the ready queue itself can be sharded to alleviate the main source of contention, auxiliary scheduling features, \eg counting ready \ats, can also be sources of contention.
    9797
    9898\subsubsection{Migration Cost}
     
    108108The problem is a single point of contention when adding/removing \ats.
    109109As shown in the evaluation sections, most production schedulers do scale when adding \glspl{hthrd}.
    110 The solution to this problem is to shard the ready-queue: create multiple \emph{subqueues} forming the logical ready-queue and the subqueues are accessed by multiple \glspl{hthrd} without interfering.
     110The solution to this problem is to shard the ready queue: create multiple \emph{sub-queues} forming the logical ready queue and the sub-queues are accessed by multiple \glspl{hthrd} without interfering.
    111111
    112112Before going into the design of \CFA's scheduler, it is relevant to discuss two sharding solutions that served as the inspiration scheduler in this thesis.
     
    115115
    116116As mentioned in \ref{existing:workstealing}, a popular sharding approach for the ready-queue is work-stealing.
    117 In this approach, each \gls{proc} has its own local subqueue and \glspl{proc} only access each other's subqueue if they run out of work on their local ready-queue.
     117In this approach, each \gls{proc} has its own local sub-queue and \glspl{proc} only access each other's sub-queue if they run out of work on their local ready-queue.
    118118The interesting aspect of work stealing happens in the steady-state scheduling case, \ie all \glspl{proc} have work and no load balancing is needed.
    119119In this case, work stealing is close to optimal scheduling: it can achieve perfect locality and have no contention.
     
    122122Chapter~\ref{microbench} shows that pathological cases work stealing can lead to indefinite starvation.
    123123
    124 Based on these observation, the conclusion is that a \emph{perfect} scheduler should behave similar to work-stealing in the steady-state case, but load balance proactively when the need arises.
     124Based on these observations, the conclusion is that a \emph{perfect} scheduler should behave similarly to work-stealing in the steady-state case, but load balance proactively when the need arises.
    125125
    126126\subsection{Relaxed-FIFO}
    127127A different scheduling approach is to create a ``relaxed-FIFO'' queue, as in \cite{alistarh2018relaxed}.
    128 This approach forgoes any ownership between \gls{proc} and subqueue, and simply creates a pool of ready-queues from which \glspl{proc} pick.
     128This approach forgoes any ownership between \gls{proc} and sub-queue, and simply creates a pool of ready queues from which \glspl{proc} pick.
    129129Scheduling is performed as follows:
    130130\begin{itemize}
    131131\item
    132 All subqueues are protected by TryLocks.
    133 \item
    134 Timestamps are added to each element of a subqueue.
    135 \item
    136 A \gls{proc} randomly tests ready queues until it has acquired one or two queues.
    137 \item
    138 If two queues are acquired, the older of the two \ats at the front the acquired queues is dequeued.
    139 \item
    140 Otherwise the \ats from the single queue is dequeued.
     132All sub-queues are protected by TryLocks.
     133\item
     134Timestamps are added to each element of a sub-queue.
     135\item
     136A \gls{proc} randomly tests ready-queues until it has acquired one or two queues.
     137\item
     138If two queues are acquired, the older of the two \ats is dequeued from the front of the acquired queues.
     139\item
     140Otherwise, the \at from the single queue is dequeued.
    141141\end{itemize}
    142142The result is a queue that has both good scalability and sufficient fairness.
    143143The lack of ownership ensures that as long as one \gls{proc} is still able to repeatedly dequeue elements, it is unlikely any element will delay longer than any other element.
    144 This guarantee contrasts with work-stealing, where a \gls{proc} with a long subqueue results in unfairness for its \ats in comparison to a \gls{proc} with a short subqueue.
     144This guarantee contrasts with work-stealing, where a \gls{proc} with a long sub-queue results in unfairness for its \ats in comparison to a \gls{proc} with a short sub-queue.
    145145This unfairness persists until a \gls{proc} runs out of work and steals.
    146146
    147 An important aspects of this scheme's fairness approach is that the timestamps make it possible to evaluate how long elements have been on the queue.
     147An important aspect of this scheme's fairness approach is that the timestamps make it possible to evaluate how long elements have been in the queue.
    148148However, \glspl{proc} eagerly search for these older elements instead of focusing on specific queues, which negatively affects locality.
    149149
     
    152152
    153153\section{Relaxed-FIFO++}
    154 The inherent fairness and good performance with many \ats, makes the relaxed-FIFO queue a good candidate to form the basis of a new scheduler.
     154The inherent fairness and good performance with many \ats make the relaxed-FIFO queue a good candidate to form the basis of a new scheduler.
    155155The problem case is workloads where the number of \ats is barely greater than the number of \procs.
    156 In these situations, the wide sharding of the ready queue means most of its subqueues are empty.
    157 Furthermore, the non-empty subqueues are unlikely to hold more than one item.
    158 The consequence is that a random dequeue operation is likely to pick an empty subqueue, resulting in an unbounded number of selections.
    159 This state is generally unstable: each subqueue is likely to frequently toggle between being empty and nonempty.
    160 Indeed, when the number of \ats is \emph{equal} to the number of \procs, every pop operation is expected to empty a subqueue and every push is expected to add to an empty subqueue.
    161 In the worst case, a check of the subqueues sees all are empty or full.
     156In these situations, the wide sharding of the ready queue means most of its sub-queues are empty.
     157Furthermore, the non-empty sub-queues are unlikely to hold more than one item.
     158The consequence is that a random dequeue operation is likely to pick an empty sub-queue, resulting in an unbounded number of selections.
     159This state is generally unstable: each sub-queue is likely to frequently toggle between being empty and nonempty.
     160Indeed, when the number of \ats is \emph{equal} to the number of \procs, every pop operation is expected to empty a sub-queue and every push is expected to add to an empty sub-queue.
     161In the worst case, a check of the sub-queues sees all are empty or full.
    162162
    163163As this is the most obvious challenge, it is worth addressing first.
    164 The obvious solution is to supplement each sharded subqueue with data that indicates if the queue is empty/nonempty to simplify finding nonempty queues, \ie ready \glspl{at}.
    165 This sharded data can be organized in different forms, \eg a bitmask or a binary tree that tracks the nonempty subqueues.
     164The obvious solution is to supplement each sharded sub-queue with data that indicates if the queue is empty/nonempty to simplify finding nonempty queues, \ie ready \glspl{at}.
     165This sharded data can be organized in different forms, \eg a bitmask or a binary tree that tracks the nonempty sub-queues.
    166166Specifically, many modern architectures have powerful bitmask manipulation instructions or searching a binary tree has good Big-O complexity.
    167 However, precisely tracking nonempty subqueues is problematic.
    168 The reason is that the subqueues are initially sharded with a width presumably chosen to avoid contention.
    169 However, tracking which ready queue is nonempty is only useful if the tracking data is dense, \ie denser than the sharded subqueues.
    170 Otherwise, it does not provide useful information because reading this new data structure risks being as costly as simply picking a subqueue at random.
    171 But if the tracking mechanism \emph{is} denser than the shared subqueues, than constant updates invariably create a new source of contention.
     167However, precisely tracking nonempty sub-queues is problematic.
     168The reason is that the sub-queues are initially sharded with a width presumably chosen to avoid contention.
     169However, tracking which ready queue is nonempty is only useful if the tracking data is dense, \ie denser than the sharded sub-queues.
     170Otherwise, it does not provide useful information because reading this new data structure risks being as costly as simply picking a sub-queue at random.
     171But if the tracking mechanism \emph{is} denser than the shared sub-queues, then constant updates invariably create a new source of contention.
    172172Early experiments with this approach showed that randomly picking, even with low success rates, is often faster than bit manipulations or tree walks.
    173173
    174174The exception to this rule is using local tracking.
    175 If each \proc locally keeps track of empty subqueues, than this can be done with a very dense data structure without introducing a new source of contention.
     175If each \proc locally keeps track of empty sub-queues, then this can be done with a very dense data structure without introducing a new source of contention.
    176176However, the consequence of local tracking is that the information is incomplete.
    177 Each \proc is only aware of the last state it saw about each subqueue so this information quickly becomes stale.
     177Each \proc is only aware of the last state it saw about each sub-queue so this information quickly becomes stale.
    178178Even on systems with low \gls{hthrd} count, \eg 4 or 8, this approach can quickly lead to the local information being no better than the random pick.
    179179This result is due in part to the cost of maintaining information and its poor quality.
    180180
    181 However, using a very low cost but inaccurate approach for local tracking can actually be beneficial.
    182 If the local tracking is no more costly than a random pick, than \emph{any} improvement to the success rate, however low it is, leads to a performance benefits.
    183 This suggests to the following approach:
     181However, using a very low-cost but inaccurate approach for local tracking can still be beneficial.
     182If the local tracking is no more costly than a random pick, then \emph{any} improvement to the success rate, however low it is, leads to a performance benefit.
     183This suggests the following approach:
    184184
    185185\subsection{Dynamic Entropy}\cite{xkcd:dynamicentropy}
    186 The Relaxed-FIFO approach can be made to handle the case of mostly empty subqueues by tweaking the \glsxtrlong{prng}.
    187 The \glsxtrshort{prng} state can be seen as containing a list of all the future subqueues that will be accessed.
    188 While this concept is not particularly useful on its own, the consequence is that if the \glsxtrshort{prng} algorithm can be run \emph{backwards}, then the state also contains a list of all the subqueues that were accessed.
     186The Relaxed-FIFO approach can be made to handle the case of mostly empty sub-queues by tweaking the \glsxtrlong{prng}.
     187The \glsxtrshort{prng} state can be seen as containing a list of all the future sub-queues that will be accessed.
     188While this concept is not particularly useful on its own, the consequence is that if the \glsxtrshort{prng} algorithm can be run \emph{backwards}, then the state also contains a list of all the sub-queues that were accessed.
    189189Luckily, bidirectional \glsxtrshort{prng} algorithms do exist, \eg some Linear Congruential Generators\cite{wiki:lcg} support running the algorithm backwards while offering good quality and performance.
    190190This particular \glsxtrshort{prng} can be used as follows:
    191191\begin{itemize}
    192192\item
    193 Each \proc maintains two \glsxtrshort{prng} states, refereed to as $F$ and $B$.
    194 \item
    195 When a \proc attempts to dequeue a \at, it picks a subqueue by running $B$ backwards.
    196 \item
    197 When a \proc attempts to enqueue a \at, it runs $F$ forward picking a subqueue to enqueue to.
    198 If the enqueue is successful, the state $B$ is overwritten with the content of $F$.
     193Each \proc maintains two \glsxtrshort{prng} states, referred to as $F$ and $B$.
     194\item
     195When a \proc attempts to dequeue a \at, it picks a sub-queue by running $B$ backwards.
     196\item
     197When a \proc attempts to enqueue a \at, it runs $F$ forward picking a sub-queue to enqueue to.
     198If the enqueue is successful, state $B$ is overwritten with the content of $F$.
    199199\end{itemize}
    200200The result is that each \proc tends to dequeue \ats that it has itself enqueued.
    201 When most subqueues are empty, this technique increases the odds of finding \ats at very low cost, while also offering an improvement on locality in many cases.
     201When most sub-queues are empty, this technique increases the odds of finding \ats at a very low cost, while also offering an improvement on locality in many cases.
    202202
    203203Tests showed this approach performs better than relaxed-FIFO in many cases.
    204204However, it is still not competitive with work-stealing algorithms.
    205205The fundamental problem is that the constant randomness limits how much locality the scheduler offers.
    206 This becomes problematic both because the scheduler is likely to get cache misses on internal data-structures and because migrations become frequent.
     206This becomes problematic both because the scheduler is likely to get cache misses on internal data structures and because migrations become frequent.
    207207Therefore, the attempt to modify the relaxed-FIFO algorithm to behave more like work stealing did not pan out.
    208208The alternative is to do it the other way around.
     
    210210\section{Work Stealing++}\label{helping}
    211211To add stronger fairness guarantees to work stealing a few changes are needed.
    212 First, the relaxed-FIFO algorithm has fundamentally better fairness because each \proc always monitors all subqueues.
     212First, the relaxed-FIFO algorithm has fundamentally better fairness because each \proc always monitors all sub-queues.
    213213Therefore, the work-stealing algorithm must be prepended with some monitoring.
    214 Before attempting to dequeue from a \proc's subqueue, the \proc must make some effort to ensure other subqueues are not being neglected.
     214Before attempting to dequeue from a \proc's sub-queue, the \proc must make some effort to ensure other sub-queues are not being neglected.
    215215To make this possible, \procs must be able to determine which \at has been on the ready queue the longest.
    216216Second, the relaxed-FIFO approach needs timestamps for each \at to make this possible.
     
    219219        \centering
    220220        \input{base.pstex_t}
    221         \caption[Base \CFA design]{Base \CFA design \smallskip\newline A pool of subqueues offers the sharding, two per \glspl{proc}.
    222         Each \gls{proc} can access all of the subqueues.
     221        \caption[Base \CFA design]{Base \CFA design \smallskip\newline A pool of sub-queues offers the sharding, two per \proc.
     222        Each \gls{proc} can access all of the sub-queues.
    223223        Each \at is timestamped when enqueued.}
    224224        \label{fig:base}
     
    226226
    227227Figure~\ref{fig:base} shows the algorithm structure.
    228 This structure is similar to classic work-stealing except the subqueues are placed in an array so \procs can access them in constant time.
     228This structure is similar to classic work-stealing except the sub-queues are placed in an array so \procs can access them in constant time.
    229229Sharding width can be adjusted based on contention.
    230230Note, as an optimization, the TS of a \at is stored in the \at in front of it, so the first TS is in the array and the last \at has no TS.
    231231This organization keeps the highly accessed front TSs directly in the array.
    232 When a \proc attempts to dequeue a \at, it first picks a random remote subqueue and compares its timestamp to the timestamps of its local subqueue(s).
     232When a \proc attempts to dequeue a \at, it first picks a random remote sub-queue and compares its timestamp to the timestamps of its local sub-queue(s).
    233233The oldest waiting \at is dequeued to provide global fairness.
    234234
    235 However, this na\"ive implemented has performance problems.
     235However, this na\"ive implementation has performance problems.
    236236First, it is necessary to have some damping effect on helping.
    237237Random effects like cache misses and preemption can add spurious but short bursts of latency negating the attempt to help.
    238 These bursts can cause increased migrations and make this work stealing approach slowdown to the level of relaxed-FIFO.
     238These bursts can cause increased migrations and make this work-stealing approach slow down to the level of relaxed-FIFO.
    239239
    240240\begin{figure}
    241241        \centering
    242242        \input{base_avg.pstex_t}
    243         \caption[\CFA design with Moving Average]{\CFA design with Moving Average \smallskip\newline A moving average is added to each subqueue.}
     243        \caption[\CFA design with Moving Average]{\CFA design with Moving Average \smallskip\newline A moving average is added to each sub-queue.}
    244244        \label{fig:base-ma}
    245245\end{figure}
    246246
    247 A simple solution to this problem is to use an exponential moving average\cite{wiki:ma} (MA) instead of a raw timestamps, shown in Figure~\ref{fig:base-ma}.
    248 Note, this is more complex because the \at at the head of a subqueue is still waiting, so its wait time has not ended.
    249 Therefore, the exponential moving average is actually an exponential moving average of how long each dequeued \at has waited.
    250 To compare subqueues, the timestamp at the head must be compared to the current time, yielding the best-case wait-time for the \at at the head of the queue.
     247A simple solution to this problem is to use an exponential moving average\cite{wiki:ma} (MA) instead of a raw timestamp, as shown in Figure~\ref{fig:base-ma}.
     248Note, that this is more complex because the \at at the head of a sub-queue is still waiting, so its wait time has not ended.
     249Therefore, the exponential moving average is an average of how long each dequeued \at has waited.
     250To compare sub-queues, the timestamp at the head must be compared to the current time, yielding the best-case wait time for the \at at the head of the queue.
    251251This new waiting is averaged with the stored average.
    252 To further limit \glslink{atmig}{migrations}, a bias can be added to a local subqueue, where a remote subqueue is helped only if its moving average is more than $X$ times the local subqueue's average.
     252To further limit \glslink{atmig}{migrations}, a bias can be added to a local sub-queue, where a remote sub-queue is helped only if its moving average is more than $X$ times the local sub-queue's average.
    253253Tests for this approach indicate the choice of the weight for the moving average or the bias is not important, \ie weights and biases of similar \emph{magnitudes} have similar effects.
    254254
    255255With these additions to work stealing, scheduling can be made as fair as the relaxed-FIFO approach, avoiding the majority of unnecessary migrations.
    256256Unfortunately, the work to achieve fairness has a performance cost, especially when the workload is inherently fair, and hence, there is only short-term or no starvation.
    257 The problem is that the constant polling, \ie reads, of remote subqueues generally entail a cache miss because the TSs are constantly being updated, \ie, writes.
    258 To make things worst, remote subqueues that are very active, \ie \ats are frequently enqueued and dequeued from them, lead to higher chances that polling will incur a cache-miss.
    259 Conversely, the active subqueues do not benefit much from helping since starvation is already a non-issue.
    260 This puts this algorithm in the awkward situation of paying for a cost that is largely unnecessary.
     257The problem is that the constant polling, \ie reads, of remote sub-queues generally entails cache misses because the TSs are constantly being updated, \ie, writes.
     258To make things worst, remote sub-queues that are very active, \ie \ats are frequently enqueued and dequeued from them, lead to higher chances that polling will incur a cache-miss.
     259Conversely, the active sub-queues do not benefit much from helping since starvation is already a non-issue.
     260This puts this algorithm in the awkward situation of paying for a largely unnecessary cost.
    261261The good news is that this problem can be mitigated
    262262
    263263\subsection{Redundant Timestamps}\label{relaxedtimes}
    264 The problem with polling remote subqueues is that correctness is critical.
    265 There must be a consensus among \procs on which subqueues hold which \ats, as the \ats are in constant motion.
    266 Furthermore, since timestamps are use for fairness, it is critical to have consensus on which \at is the oldest.
    267 However, when deciding if a remote subqueue is worth polling, correctness is less of a problem.
    268 Since the only requirement is that a subqueue is eventually polled, some data staleness is acceptable.
     264The problem with polling remote sub-queues is that correctness is critical.
     265There must be a consensus among \procs on which sub-queues hold which \ats, as the \ats are in constant motion.
     266Furthermore, since timestamps are used for fairness, it is critical to have a consensus on which \at is the oldest.
     267However, when deciding if a remote sub-queue is worth polling, correctness is less of a problem.
     268Since the only requirement is that a sub-queue is eventually polled, some data staleness is acceptable.
    269269This leads to a situation where stale timestamps are only problematic in some cases.
    270 Furthermore, stale timestamps can be desirable since lower freshness requirements mean less cache invalidations.
     270Furthermore, stale timestamps can be desirable since lower freshness requirements mean fewer cache invalidations.
    271271
    272272Figure~\ref{fig:base-ts2} shows a solution with a second array containing a copy of the timestamps and average.
    273 This copy is updated \emph{after} the subqueue's critical sections using relaxed atomics.
     273This copy is updated \emph{after} the sub-queue's critical sections using relaxed atomics.
    274274\Glspl{proc} now check if polling is needed by comparing the copy of the remote timestamp instead of the actual timestamp.
    275275The result is that since there is no fencing, the writes can be buffered in the hardware and cause fewer cache invalidations.
     
    285285The correctness argument is somewhat subtle.
    286286The data used for deciding whether or not to poll a queue can be stale as long as it does not cause starvation.
    287 Therefore, it is acceptable if stale data makes queues appear older than they really are but appearing fresher can be a problem.
    288 For the timestamps, this means missing writes to the timestamp is acceptable since they make the head \at look older.
     287Therefore, it is acceptable if stale data makes queues appear older than they are but appearing fresher can be a problem.
     288For the timestamps, this means it is acceptable to miss writes to the timestamp since they make the head \at look older.
    289289For the moving average, as long as the operations are just atomic reads/writes, the average is guaranteed to yield a value that is between the oldest and newest values written.
    290 Therefore, this unprotected read of the timestamp and average satisfy the limited correctness that is required.
     290Therefore, this unprotected read of the timestamp and average satisfies the limited correctness that is required.
    291291
    292292With redundant timestamps, this scheduling algorithm achieves both the fairness and performance requirements on most machines.
    293293The problem is that the cost of polling and helping is not necessarily consistent across each \gls{hthrd}.
    294 For example, on machines with a CPU containing multiple hyperthreads and cores and multiple CPU sockets, cache misses can be satisfied from the caches on same (local) CPU, or by a CPU on a different (remote) socket.
     294For example, on machines with a CPU containing multiple hyper threads and cores and multiple CPU sockets, cache misses can be satisfied from the caches on the same (local) CPU, or by a CPU on a different (remote) socket.
    295295Cache misses satisfied by a remote CPU have significantly higher latency than from the local CPU.
    296296However, these delays are not specific to systems with multiple CPUs.
     
    313313In Figure~\ref{fig:cache-share}, all cache misses are either private to a CPU or shared with another CPU.
    314314This means latency due to cache misses is fairly consistent.
    315 In contrast, in Figure~\ref{fig:cache-noshare} misses in the L2 cache can be satisfied by either instance of L3 cache.
     315In contrast, in Figure~\ref{fig:cache-noshare} misses in the L2 cache can be satisfied by either instance of the L3 cache.
    316316However, the memory-access latency to the remote L3 is higher than the memory-access latency to the local L3.
    317317The impact of these different designs on this algorithm is that scheduling only scales well on architectures with a wide L3 cache, similar to Figure~\ref{fig:cache-share}, and less well on architectures with many narrower L3 cache instances, similar to Figure~\ref{fig:cache-noshare}.
    318 Hence, as the number of L3 instances grow, so too does the chance that the random helping causes significant cache latency.
    319 The solution is for the scheduler be aware of the cache topology.
     318Hence, as the number of L3 instances grows, so too does the chance that the random helping causes significant cache latency.
     319The solution is for the scheduler to be aware of the cache topology.
    320320
    321321\subsection{Per CPU Sharding}
     
    323323Unfortunately, there is no portable way to discover cache topology, and it is outside the scope of this thesis to solve this problem.
    324324This work uses the cache topology information from Linux's @/sys/devices/system/cpu@ directory.
    325 This leaves the challenge of matching \procs to cache structure, or more precisely identifying which subqueues of the ready queue are local to which subcomponents of the cache structure.
    326 Once a matching is generated, the helping algorithm is changed to add bias so that \procs more often help subqueues local to the same cache substructure.\footnote{
     325This leaves the challenge of matching \procs to cache structure, or more precisely identifying which sub-queues of the ready queue are local to which subcomponents of the cache structure.
     326Once a match is generated, the helping algorithm is changed to add bias so that \procs more often help sub-queues local to the same cache substructure.\footnote{
    327327Note that like other biases mentioned in this section, the actual bias value does not appear to need precise tuning.}
    328328
    329 The simplest approach for mapping subqueues to cache structure is to statically tie subqueues to CPUs.
    330 Instead of having each subqueue local to a specific \proc, the system is initialized with subqueues for each hardware hyperthread/core up front.
    331 Then \procs dequeue and enqueue by first asking which CPU id they are executing on, in order to identify which subqueues are the local ones.
     329The simplest approach for mapping sub-queues to cache structure is to statically tie sub-queues to CPUs.
     330Instead of having each sub-queue local to a specific \proc, the system is initialized with sub-queues for each hardware hyperthread/core up front.
     331Then \procs dequeue and enqueue by first asking which CPU id they are executing on, to identify which sub-queues are the local ones.
    332332\Glspl{proc} can get the CPU id from @sched_getcpu@ or @librseq@.
    333333
    334334This approach solves the performance problems on systems with topologies with narrow L3 caches, similar to Figure \ref{fig:cache-noshare}.
    335335However, it can still cause some subtle fairness problems in systems with few \procs and many \glspl{hthrd}.
    336 In this case, the large number of subqueues and the bias against subqueues tied to different cache substructures make it unlikely that every subqueue is picked.
    337 To make things worst, the small number of \procs mean that few helping attempts are made.
    338 This combination of low selection and few helping attempts allow a \at to become stranded on a subqueue for a long time until it gets randomly helped.
    339 On a system with 2 \procs, 256 \glspl{hthrd} with narrow cache sharing, and a 100:1 bias, it can actually take multiple seconds for a \at to get dequeued from a remote queue.
    340 Therefore, a more dynamic matching of subqueues to cache instance is needed.
     336In this case, the large number of sub-queues and the bias against sub-queues tied to different cache substructures make it unlikely that every sub-queue is picked.
     337To make things worst, the small number of \procs means that few helping attempts are made.
     338This combination of low selection and few helping attempts allow a \at to become stranded on a sub-queue for a long time until it gets randomly helped.
     339On a system with 2 \procs, 256 \glspl{hthrd} with narrow cache sharing, and a 100:1 bias, it can take multiple seconds for a \at to get dequeued from a remote queue.
     340Therefore, a more dynamic match of sub-queues to cache instances is needed.
    341341
    342342\subsection{Topological Work Stealing}
    343343\label{s:TopologicalWorkStealing}
    344 Therefore, the approach used in the \CFA scheduler is to have per-\proc subqueues, but have an explicit data-structure track which cache substructure each subqueue is tied to.
     344Therefore, the approach used in the \CFA scheduler is to have per-\proc sub-queues, but have an explicit data structure to track which cache substructure each sub-queue is tied to.
    345345This tracking requires some finesse because reading this data structure must lead to fewer cache misses than not having the data structure in the first place.
    346346A key element however is that, like the timestamps for helping, reading the cache instance mapping only needs to give the correct result \emph{often enough}.
    347347Therefore the algorithm can be built as follows: before enqueueing or dequeuing a \at, each \proc queries the CPU id and the corresponding cache instance.
    348 Since subqueues are tied to \procs, each \proc can then update the cache instance mapped to the local subqueue(s).
    349 To avoid unnecessary cache line invalidation, the map is only written to if the mapping changes.
     348Since sub-queues are tied to \procs, each \proc can then update the cache instance mapped to the local sub-queue(s).
     349To avoid unnecessary cache line invalidation, the map is only written-to if the mapping changes.
    350350
    351351This scheduler is used in the remainder of the thesis for managing CPU execution, but additional scheduling is needed to handle long-term blocking and unblocking, such as I/O.
  • doc/theses/thierry_delisle_PhD/thesis/text/front.tex

    r264f6c9 r62424af2  
    134134
    135135This thesis analyses multiple scheduler systems, where each system attempts to fulfill the requirements for user-level threading.
    136 The predominant technique for managing high levels of concurrency is sharding the ready-queue with one queue per \gls{kthrd} and using some form of work stealing/sharing to dynamically rebalance workload shifts.
     136The predominant technique for managing high levels of concurrency is sharding the ready queue with one queue per \gls{kthrd} and using some form of work stealing/sharing to dynamically rebalance workload shifts.
    137137Preventing kernel blocking is accomplished by transforming kernel locks and I/O operations into user-level operations that do not block the kernel thread or spin up new kernel threads to manage the blocking.
    138138Fairness is handled through preemption and/or ad-hoc solutions, which leads to coarse-grained fairness with some pathological cases.
  • doc/theses/thierry_delisle_PhD/thesis/text/intro.tex

    r264f6c9 r62424af2  
    1212
    1313This thesis analyses multiple scheduler systems, where each system attempts to fulfill the requirements for \gls{uthrding}.
    14 The predominant technique for managing high levels of concurrency is sharding the ready-queue with one queue per kernel-thread and using some form of work stealing/sharing to dynamically rebalance workload shifts.
     14The predominant technique for managing high levels of concurrency is sharding the ready queue with one queue per kernel-thread and using some form of work stealing/sharing to dynamically rebalance workload shifts.
    1515Preventing kernel blocking is accomplished by transforming kernel locks and I/O operations into user-level operations that do not block the kernel thread or spin up new kernel threads to manage the blocking.
    1616Fairness is handled through preemption and/or ad-hoc solutions, which leads to coarse-grained fairness with some pathological cases.
  • doc/theses/thierry_delisle_PhD/thesis/text/runtime.tex

    r264f6c9 r62424af2  
    44\section{C Threading}
    55
    6 \Celeven introduced threading features, such the @_Thread_local@ storage class, and libraries @stdatomic.h@ and @threads.h@.
     6\Celeven introduced threading features, such as the @_Thread_local@ storage class, and libraries @stdatomic.h@ and @threads.h@.
    77Interestingly, almost a decade after the \Celeven standard, the most recent versions of gcc, clang, and msvc do not support the \Celeven include @threads.h@, indicating no interest in the C11 concurrency approach (possibly because of the recent effort to add concurrency to \CC).
    88While the \Celeven standard does not state a threading model, the historical association with pthreads suggests implementations would adopt kernel-level threading (1:1)~\cite{ThreadModel}, as for \CC.
     
    1313\section{M:N Threading}\label{prev:model}
    1414
    15 Threading in \CFA is based on \Gls{uthrding}, where \ats are the representation of a unit of work. As such, \CFA programmers should expect these units to be fairly inexpensive, \ie programmers should be able to create a large number of \ats and switch among \ats liberally without many concerns for performance.
     15Threading in \CFA is based on \Gls{uthrding}, where \ats are the representation of a unit of work. As such, \CFA programmers should expect these units to be fairly inexpensive, \ie programmers should be able to create a large number of \ats and switch among \ats liberally without many performance concerns.
    1616
    17 The \CFA M:N threading models is implemented using many user-level threads mapped onto fewer \glspl{kthrd}.
     17The \CFA M:N threading model is implemented using many user-level threads mapped onto fewer \glspl{kthrd}.
    1818The user-level threads have the same semantic meaning as a \glspl{kthrd} in the 1:1 model: they represent an independent thread of execution with its own stack.
    19 The difference is that user-level threads do not have a corresponding object in the kernel; they are handled by the runtime in user space and scheduled onto \glspl{kthrd}, referred to as \glspl{proc} in this document. \Glspl{proc} run a \at until it context switches out, it then chooses a different \at to run.
     19The difference is that user-level threads do not have a corresponding object in the kernel; they are handled by the runtime in user space and scheduled onto \glspl{kthrd}, referred to as \glspl{proc} in this document. \Glspl{proc} run a \at until it context-switches out, it then chooses a different \at to run.
    2020
    2121\section{Clusters}
     
    4545In theory, this should not be a problem, even if the second \at waits, because the first \at is still ready to run and should be able to get CPU time to send the request.
    4646With M:N threading, while the first \at is ready, the lone \gls{proc} \emph{cannot} run the first \at if it is blocked in the \glsxtrshort{io} operation of the second \at.
    47 If this happen, the system is in a synchronization deadlock\footnote{In this example, the deadlock could be resolved if the server sends unprompted messages to the client.
     47If this happens, the system is in a synchronization deadlock\footnote{In this example, the deadlock could be resolved if the server sends unprompted messages to the client.
    4848However, this solution is neither general nor appropriate even in this simple case.}.
    4949\end{quote}
    5050
    51 Therefore, one of the objective of this work is to introduce \emph{User-Level \glsxtrshort{io}}, which like \glslink{uthrding}{User-Level \emph{Threading}}, blocks \ats rather than \glspl{proc} when doing \glsxtrshort{io} operations.
     51Therefore, one of the objectives of this work is to introduce \emph{User-Level \glsxtrshort{io}}, which like \glslink{uthrding}{User-Level \emph{Threading}}, blocks \ats rather than \glspl{proc} when doing \glsxtrshort{io} operations.
    5252This feature entails multiplexing the \glsxtrshort{io} operations of many \ats onto fewer \glspl{proc}.
    5353The multiplexing requires a single \gls{proc} to execute multiple \glsxtrshort{io} operations in parallel.
     
    6060All functions defined by this volume of POSIX.1-2017 shall be thread-safe, except that the following functions need not be thread-safe. ... (list of 70+ excluded functions)
    6161\end{quote}
    62 Only UNIX @man@ pages identify whether or not a library function is thread safe, and hence, may block on a pthreads lock or system call; hence interoperability with UNIX library functions is a challenge for an M:N threading model.
     62Only UNIX @man@ pages identify whether or not a library function is thread-safe, and hence, may block on a pthreads lock or system call; hence interoperability with UNIX library functions is a challenge for an M:N threading model.
    6363
    6464Languages like Go and Java, which have strict interoperability with C\cite{wiki:jni,go:cgo}, can control operations in C by ``sandboxing'' them, \eg a blocking function may be delegated to a \gls{kthrd}. Sandboxing may help towards guaranteeing that the kind of deadlock mentioned above does not occur.
     
    7272Therefore, it is possible calls to an unknown library function can block a \gls{kthrd} leading to deadlocks in \CFA's M:N threading model, which would not occur in a traditional 1:1 threading model.
    7373Currently, all M:N thread systems interacting with UNIX without sandboxing suffer from this problem but manage to work very well in the majority of applications.
    74 Therefore, a complete solution to this problem is outside the scope of this thesis.\footnote{\CFA does provide a pthreads emulation, so any library function using embedded pthreads locks are redirected to \CFA user-level locks. This capability further reduces the chances of blocking a \gls{kthrd}.}
     74Therefore, a complete solution to this problem is outside the scope of this thesis.\footnote{\CFA does provide a pthreads emulation, so any library function using embedded pthreads locks is redirected to \CFA user-level locks. This capability further reduces the chances of blocking a \gls{kthrd}.}
Note: See TracChangeset for help on using the changeset viewer.