Changes in / [713905fd:b29a1e8]


Ignore:
Location:
doc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • doc/bibliography/pl.bib

    r713905fd rb29a1e8  
    21552155    title       = {Continuations and Coroutines},
    21562156    booktitle   = {Conference Record of the 1984 {ACM} Symposium on Lisp and Functional Programming},
    2157     organization= {ACM},
     2157    organization= {Association for Computing Machinery},
    21582158    month       = aug,
    21592159    year        = 1984,
     
    38553855}
    38563856
    3857 @inproceedings{Brown14,
    3858     keywords    = {non-blocking, relaxed balance, balanced binary search tree, chromatic tree, red-black tree},
    3859     contributer = {pabuhr@plg},
    3860     author      = {Trevor Brown and Faith Ellen and Eric Ruppert},
    3861     title       = {A General Technique for Non-Blocking Trees},
    3862     year        = {2014},
    3863     publisher   = {ACM},
    3864     address     = {New York, NY, USA},
    3865     booktitle   = {Proceedings of the 19th ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming},
    3866     pages       = {329-342},
    3867     numpages    = {14},
    3868     location    = {Orlando, Florida, USA},
    3869     series      = {PPoPP '14}
    3870 }
    3871 
    38723857@article{doUpon,
    38733858    keywords    = {formal verification, axiomatic semantics, control structures},
     
    38763861    title       = {A Generalized Iterative Construct and Its Semantics},
    38773862    journal     = toplas,
    3878     volume      = 9,
    3879     number      = 4,
     3863    volume      = {9},    number = {4},
    38803864    pages       = {567-581},
    3881     month       = oct,
    3882     year        = 1987,
     3865    month       = oct, year = 1987,
    38833866    comment     = {
    38843867        \begin{verbatim}
     
    38953878            od
    38963879        \end{verbatim}
     3880
    38973881        If there is an i such that Qi is true, execute Mi and terminate.
    38983882        Otherwise, if there is an i such that Pi is true, execute Li and
     
    42194203    year        = 1989,
    42204204    pages       = {60-76},
    4221     organization= {ACM}
     4205    organization= {Association for Computing Machinery}
    42224206}
    42234207
     
    44024386    year        = 1990,
    44034387    pages       = {125-135},
    4404     organization= {ACM},
     4388    organization= {Association for Computing Machinery},
    44054389    abstract    = {
    44064390        In typed object-oriented languages the subtype relation is
     
    51245108    title       = {MCSH, a Lock with the Standard Interface},
    51255109    issue_date  = {June 2023},
    5126     publisher   = {ACM},
     5110    publisher   = {Association for Computing Machinery},
    51275111    address     = {New York, NY, USA},
    51285112    volume      = 10,
     
    62496233    journal     = sigplan,
    62506234    year        = 1980,
    6251     month       = nov,
    6252     volume      = 15,
    6253     number      = 11,
    6254     pages       = {47-56},
     6235    month       = nov, volume = 15, number = 11, pages = {47-56},
    62556236    note        = {Proceedings of the ACM-SIGPLAN Symposium on the {Ada} Programming Language},
    62566237    comment     = {
     
    66126593}
    66136594
    6614 @inproceedings{Brown13,
    6615     keywords    = {multiset, non-blocking, load-link/store-conditional},
    6616     contributer = {pabuhr@plg},
    6617     author      = {Trevor Brown and Faith Ellen and Eric Ruppert},
    6618     title       = {Pragmatic Primitives for Non-Blocking Data Structures},
    6619     year        = 2013,
    6620     publisher   = {ACM},
    6621     address     = {New York, NY, USA},
    6622     booktitle   = {Proceedings of the 2013 ACM Symposium on Principles of Distributed Computing},
    6623     pages       = {13-22},
    6624     numpages    = {10},
    6625     location    = {Montr\'{e}al, Qu\'{e}bec, Canada},
    6626     series      = {PODC '13}
    6627 }
    6628 
    66296595@inproceedings{Rafkind09,
    66306596    keywords    = {accurate, C programming language, conservative, garbage collection, precise},
     
    67166682    title       = {Procedures as Persistent Data Objects},
    67176683    journal     = toplas,
    6718     volume      = 7,
    6719     number      = 4,
     6684    volume      = {7},    number = {4},
    67206685    pages       = {539-559},
    6721     month       = oct,
    6722     year        = 1985,
     6686    month       = oct, year = 1985,
    67236687    comment     = {
    67246688        PS-Algol has ``structures'', accessible only through ``pntrs''.
     
    67806744    title       = {Programming Dynamically Reconfigurable Open Systems with SALSA},
    67816745    issue_date  = {December 2001},
    6782     publisher   = {ACM},
     6746    publisher   = {Association for Computing Machinery},
    67836747    address     = {New York, NY, USA},
    67846748    volume      = 36,
     
    71417105}
    71427106
    7143 @misc{protoactor,
    7144     contributer = {pabuhr@plg},
    7145     key         = {Protoactor},
    7146     author      = {{proto.actor}},
    7147     title       = {Asynkron AB},
    7148     year        = 2023,
    7149     howpublished= {\url{https://proto.actor}},
    7150 }
    7151 
    71527107@techreport{PS-Algol,
    71537108    keywords    = {algol, persistence},
     
    71607115    month       = jun,
    71617116    year        = 1987,
     7117}
     7118
     7119@misc{protoactor,
     7120    contributer = {pabuhr@plg},
     7121    key         = {Protoactor},
     7122    author      = {{proto.actor}},
     7123    title       = {Asynkron AB},
     7124    year        = 2023,
     7125    howpublished= {\url{https://proto.actor}},
    71627126}
    71637127
     
    85238487    year        = 1990,
    85248488    month       = jan, pages = {109-124},
    8525     organization= {ACM},
     8489    organization= {Association for Computing Machinery},
    85268490    abstract    = {
    85278491        This paper disucsses the phenomenon of {\em method specialization}
     
    87848748    year        = {2020},
    87858749    issue_date  = {March 2020},
    8786     publisher   = {ACM},
     8750    publisher   = {Association for Computing Machinery},
    87878751    address     = {New York, NY, USA},
    87888752    volume      = {4},
     
    90939057    editor      = {Norman Meyrowitz},
    90949058    publisher   = sigplan,
    9095     organization= {ACM},
     9059    organization= {Association for Computing Machinery},
    90969060    address     = {Portland, Oregon},
    90979061    month       = sep,
     
    91059069    editor      = {Norman Meyrowitz},
    91069070    publisher   = sigplan,
    9107     organization= {ACM},
     9071    organization= {Association for Computing Machinery},
    91089072    address     = {Orlando, Florida},
    91099073    month       = oct,
     
    91179081    editor      = {Norman Meyrowitz},
    91189082    publisher   = sigplan,
    9119     organization= {ACM},
     9083    organization= {Association for Computing Machinery},
    91209084    address     = {San Diego, California},
    91219085    month       = sep,
     
    91299093    editor      = {Norman Meyrowitz},
    91309094    publisher   = sigplan,
    9131     organization= {ACM},
     9095    organization= {Association for Computing Machinery},
    91329096    address     = {New Orleans, Louisiana},
    91339097    month       = oct,
     
    91419105    editor      = {Norman Meyrowitz},
    91429106    publisher   = sigplan,
    9143     organization= {ACM},
     9107    organization= {Association for Computing Machinery},
    91449108    address     = {Ottawa, Canada},
    91459109    month       = oct,
     
    91539117    editor      = {Andreas Paepcke},
    91549118    publisher   = sigplan,
    9155     organization= {ACM},
     9119    organization= {Association for Computing Machinery},
    91569120    address     = {Phoenix, Arizona},
    91579121    month       = oct,
  • doc/theses/colby_parsons_MMAth/glossary.tex

    r713905fd rb29a1e8  
    3838\newabbreviation{fifo}{FIFO}{\Newterm{first-in first-out}}
    3939\newabbreviation{toctou}{TOCTOU}{\Newterm{time-of-check to time-of-use}}
    40 \newabbreviation{cas}{CAS}{\Newterm{compare-and-set (swap)}}
    41 \newabbreviation{dwcas}{DWCAS}{\Newterm{double-wide (width) compare-and-set (swap)}}
    42 \newabbreviation{dcas}{DCAS}{\Newterm{double compare-and-set (swap)}}
    43 \newabbreviation{das}{DAS}{\Newterm{double swap}}
    44 \newabbreviation{ll}{LL}{\Newterm{load linked}}
    45 \newabbreviation{sc}{SC}{\Newterm{store conditional}}
    4640
    4741\newglossaryentry{actor}{
  • doc/theses/colby_parsons_MMAth/text/actors.tex

    r713905fd rb29a1e8  
    555555In theory, this goal is not achievable, but practical results show the goal is virtually achieved.
    556556
    557 One important lesson learned while working on \uC actors~\cite{Buhr22} and through discussions with fellow student Thierry Delisle, who examined work-stealing for user-threads in his Ph.D.~\cite{Delisle22}, is \emph{not} to aggressively steal.
     557One important lesson learned while working on \uC actors~\cite{} and through discussions with fellow student Thierry Delisle, who examined work-stealing for user-threads in his Ph.D.~\cite{Delisle22}, is \emph{not} to aggressively steal.
    558558With reasonable workloads, being a thief should be a temporary state, \ie eventually work appears on the thief's ready-queues and it returns to normal operation.
    559559Furthermore, the act of \emph{looking} to find work is invasive (Heisenberg uncertainty principle), possibly disrupting multiple victims.
     
    563563The outline for lazy-stealing by a thief is: select a victim, scan its queues once, and return immediately if a queue is stolen.
    564564The thief then returns to normal operation and conducts a regular scan over its own queues looking for work, where stolen work is placed at the end of the scan.
    565 Hence, only one victim is affected and there is a reasonable delay between stealing events as the thief scans its ready queue looking for its own work before potentially stealing again.
     565Hence, only one victim is affected and there is a reasonable delay between stealing events as the thief will scan its ready queue looking for its own work before potentially stealing again.
    566566This lazy examination by the thief has a low perturbation cost for victims, while still finding work in a moderately loaded system.
    567567In all work-stealing algorithms, there is the pathological case where there is too little work and too many workers;
     
    584584\begin{cfa}
    585585struct work_queue {
    586         spinlock_t mutex_lock;                  $\C[2.75in]{// atomicity for queue operations}$
    587         copy_queue * owned_queue;               $\C{// copy queue}$
    588         copy_queue * c_queue;                   $\C{// current queue}$
    589         volatile bool being_processed;  $\C{// flag to prevent concurrent processing}$
     586        spinlock_t mutex_lock;                          $\C[2.75in]{// atomicity for queue operations}$
     587        copy_queue * owned_queue;                       $\C{// copy queue}$
     588        copy_queue * c_queue;                           $\C{// current queue}$
     589        volatile bool being_processed;          $\C{// flag to prevent concurrent processing}$
    590590};
    591 work_queue * mailboxes;                         $\C{// master array of work request queues}$
    592 work_queue ** worker_queues;            $\C{// secondary array of work queues to allow for swapping}\CRT$
     591work_queue * mailboxes;                                 $\C{// master array of work request queues}$
     592work_queue ** worker_queues;                    $\C{// secondary array of work queues to allow for swapping}\CRT$
    593593\end{cfa}
    594594A send inserts a request at the end of one of @mailboxes@.
    595 A steal swaps two pointers in \snake{worker_queues}.
     595A steal swaps two pointers in @worker_queues@.
    596596Conceptually, @worker_queues@ represents the ownership relation between mailboxes and workers.
    597597Given $M$ workers and $N$ mailboxes, each worker owns a contiguous $M$/$N$ block of pointers in @worker_queues@.
     
    599599To transfer ownership of a mailbox from one worker to another, a pointer from each of the workers' ranges are swapped.
    600600This structure provides near-complete separation of stealing and gulping/send operations.
    601 As such, operations can happen on @mailboxes@ independent of stealing, which avoids almost all contention between thief and victim threads.
     601As such, operations can happen on @mailboxes@ independent of stealing, which avoids almost all contention between thief threads and victim threads.
    602602
    603603\begin{figure}
     
    627627The thief then resumes normal execution and ceases being a thief.
    628628Hence, it iterates over its own worker queues because new messages may have arrived during stealing, including ones in the potentially stolen queue.
    629 Stealing is only repeated after the worker completes two consecutive iterations over its message queues without finding work.
     629Stealing is only repeated after the worker completes two consecutive iterations over its owned queues without finding work.
    630630\end{enumerate}
    631631
     
    637637temp = worker_queues[x];
    638638// preemption and steal
    639 transfer( local_queue, temp->c_queue );   // atomically sets being_processed
     639transfer( local_queue, temp->c_queue ); // @being_processed@ set in transfer with mutual exclusion
    640640\end{cfa}
    641641where @transfer@ gulps the work from @c_queue@ to the victim's @local_queue@ and leaves @c_queue@ empty, partitioning the mailbox.
     
    648648\end{enumerate}
    649649If the victim is preempted after the dereference, a thief can steal the mailbox pointer before the victim calls @transfer@.
    650 The thief then races ahead, transitions back to a victim, searches its mailboxes, finds the stolen non-empty mailbox, and gulps this queue.
     650The thief then races ahead, transitions back to a victim, searches its mailboxes, finds the stolen non-empty mailbox, and gulps its queue.
    651651The original victim now continues and gulps from the stolen mailbox pointed to by its dereference, even though the thief has logically subdivided this mailbox by gulping it.
    652652At this point, the mailbox has been subdivided a second time, and the victim and thief are possibly processing messages sent to the same actor, which violates mutual exclusion and the message-ordering guarantee.
     
    654654However, any form of locking here creates contention between thief and victim.
    655655
    656 The alternative to locking is allowing the race and resolving it lazily (lock-free approach).
     656The alternative to locking is allowing the race and resolving it lazily.
    657657% As mentioned, there is a race between a victim gulping and a thief stealing because gulping partitions a mailbox queue making it ineligible for stealing.
    658658% Furthermore, after a thief steals, there is moment when victim gulps but the queue no longer
     
    668668The flag indicates that a mailbox has been gulped (logically subdivided) by a worker and the gulped queue is being processed locally.
    669669The @being_processed@ flag is reset once the local processing is finished.
    670 If a worker, either victim or thief turned victim, attempts to gulp from a mailbox and finds the @being_processed@ flag set, it does not gulp and moves onto the next mailbox in its range.
     670If a worker, either victim or thief turned victim, attempts to gulp from a mailbox and find the @being_processed@ flag set, it does not gulp and moves on to the next mailbox in its range.
    671671This resolves the race no matter the winner.
    672672If the thief wins the race, it steals the mailbox and gulps, and the victim sees the flag set and skips gulping from the mailbox.
     
    675675There is a final case where the race occurs and is resolved with \emph{both} gulps occurring.
    676676Here, the winner of the race finishes processing the queue and resets the @being_processed@ flag.
    677 Then the loser unblocks and completes its gulp from the same mailbox and atomically sets the \snake{being_processed} flag.
    678 The loser is now processing messages from a temporarily shared mailbox, which is safe because the winner ignores this mailbox, if it attempts another gulp since @being_processed@ is set.
     677Then the loser unblocks and completes its gulp from the same mailbox and atomically sets the @being_processed@ flag.
     678The loser is now processing messages from a temporarily shared mailbox, which is safe because the winner will ignore this mailbox if it attempts another gulp, since @being_processed@ is set.
    679679The victim never attempts to gulp from the stolen mailbox again because its next cycle sees the swapped mailbox from the thief (which may or may not be empty at this point).
    680680This race is now the only source of contention between victim and thief as they both try to acquire a lock on the same queue during a transfer.
    681681However, the window for this race is extremely small, making this contention rare.
    682 In theory, if this race occurs multiple times consecutively, \ie a thief steals, dereferences a stolen mailbox pointer, is interrupted, and stolen from, etc., this scenario can cascade across multiple workers all attempting to gulp from one mailbox.
     682In theory, if this race occurs multiple times consecutively \ie a thief steals, dereferences stolen mailbox pointer, is interrupted and stolen from, etc., this scenario can cascade across multiple workers all attempting to gulp from one mailbox.
    683683The @being_processed@ flag ensures correctness even in this case, and the chance of a cascading scenario across multiple workers is even rarer.
    684 
    685 It is straightforward to count the number of missed gulps due to the @being_processed@ flag and this counter is added to all benchmarks presented in Section~\ref{s:actor_perf}.
    686 The results show the median count of missed gulps for each experiment is \emph{zero}, except for the repeat benchmark.
     684It is straightforward to count the number of missed gulps due to the @being_processed@ flag at runtime.
     685With the exception of the repeat benchmark, the median count of missed gulps for each number of cores for all benchmarks presented in Section~\ref{s:actor_perf} is \emph{zero}.
    687686The repeat benchmark is an example the pathological case described earlier where there is too little work and too many workers.
    688 In the repeat benchmark, one actor has the majority of the workload, and no other actor has a consistent workload, which results in rampant stealing.
    689 None of the work-stealing actor-systems examined in this work perform well on the repeat benchmark.
    690 Hence, for all non-pathological cases, the claim is made that this stealing mechanism has a (probabilistically) zero-victim-cost in practice.
     687In the repeat benchmark one actor has the majority of the workload, and no other actor has a consistent workload which results in rampant stealing.
     688None of the work stealing actor systems compared in this work perform well on the repeat benchmark.
     689Hence, the claim is made that this stealing mechanism has a (probabilistically) zero-victim-cost in practice.
    691690
    692691\subsection{Queue Pointer Swap}\label{s:swap}
    693 
    694 To atomically swap the two @worker_queues@ pointers during work stealing, a novel wait-free swap-algorithm is needed.
    695 The \gls{cas} is a read-modify-write instruction available on most modern architectures.
    696 It atomically compares two memory locations, and if the values are equal, it writes a new value into the first memory location.
    697 A software implementation of \gls{cas} is:
     692Two atomically swap two pointers in @worker_queues@, a novel wait-free swap algorithm is used.
     693The novel wait-free swap is effectively a special case of a DCAS.
     694DCAS stands for Double Compare-And-Swap, which is a more general version of the Compare-And-Swap (CAS) atomic operation~\cite{Doherty04}.
     695CAS compares is a read-modify-write operation available on most modern architectures which atomically compares an expected value with a memory location.
     696If the expected value and value in memory are equal it then writes a new value into the memory location.
     697A sample software implemention of CAS follows.
    698698\begin{cfa}
    699699// assume this routine executes atomically
    700 bool CAS( T * assn, T comp, T new ) {   // T is a basic type
    701         if ( *assn != comp ) return false;
    702         *assn = new;
     700bool CAS( val * ptr, val expected, val new ) {
     701        if ( *ptr != expected )
     702                return false;
     703        *ptr = new;
    703704        return true;
    704705}
    705706\end{cfa}
    706 However, this instruction does \emph{not} swap @assn@ and @new@, which is why compare-and-swap is a misnomer.
    707 If @T@ can be a double-wide address-type (128 bits on a 64-bit machine), called a \gls{dwcas}, then it is possible to swap two values, if and only if the two addresses are juxtaposed in memory.
    708 \begin{cfa}
    709 union Pair {
    710         struct { void * ptr1, * ptr2; };   // 64-bit pointers
    711         __int128 atom;
    712 };
    713 Pair pair1 = { addr1, addr2 }, pair2 = { addr2, addr1 };
    714 Pair top = pair1;
    715 DWCAS( top.atom, pair1.atom, pair2.atom );
    716 \end{cfa}
    717 However, this approach does not apply because the mailbox pointers are seldom juxtaposed.
    718 
    719 Only a few architectures provide a \gls{dcas}, which extends \gls{cas} to two memory locations~\cite{Doherty04}.
     707As shown CAS only operates on one memory location.
     708Where CAS operates on a single memory location and some values, DCAS operates on two memory locations.
    720709\begin{cfa}
    721710// assume this routine executes atomically
    722 bool DCAS( T * assn1, T * assn2, T comp1, T comp2, T new1, T new2 ) {
    723         if ( *assn1 == comp1 && *assn2 == comp2 ) {
    724                 *assn1 = new1;
    725                 *assn2 = new2;
     711bool DCAS( val * addr1, val * addr2, val old1, val old2, val new1, val new2 ) {
     712        if ( ( *addr1 == old1 ) && ( *addr2 == old2 ) ) {
     713                *addr1 = new1;
     714                *addr2 = new2;
    726715                return true;
    727716        }
     
    729718}
    730719\end{cfa}
    731 and can swap two values, where the comparisons are superfluous.
    732 \begin{cfa}
    733 DCAS( x, y, x, y, y, x );
    734 \end{cfa}
    735 A restrictive form of \gls{dcas} can be simulated using \gls{ll}/\gls{sc}~\cite{Brown13} or more expensive transactional memory the same progress property problems as LL/SC.
    736 (There is waning interest in transactional memory and it seems to be fading away.)
    737 
    738 Similarly, very few architectures have a true memory/memory swap instruction (Motorola M68K, SPARC 32-bit).
    739 The x86 XCHG instruction (and most other architectures with a similar instruction) only works between a register and memory location.
    740 In this case, there is a race between loading the register and performing the swap (discussed shortly).
    741 
    742 Hence, a novel swap is constructed, called \gls{das}, special cased in two ways:
    743 \begin{enumerate}
    744 \item
    745 It works on two separate memory locations, and hence, is logically the same as.
    746 \begin{cfa}
    747 bool DAS( T * assn1, T * assn2 ) {
    748         return DCAS( assn1, assn2, *assn1, *assn2, *assn2, *assn1 );
     720The DCAS implemented in this work is special cased in two ways.
     721First of all, a DCAS is more powerful than what is needed to swap two pointers.
     722A double atomic swap (DAS) is all that is needed for this work.
     723The atomic swap provided by most modern hardware requires that at least one operand is a register.
     724A DAS would relax that restriction so that both operands of the swap could be memory locations.
     725As such a DAS can be written in terms of the DCAS above as follows.
     726\begin{cfa}
     727bool DAS( val * addr1, val * addr2 ) {
     728        return DCAS( addr1, addr2, *addr1, *addr2, *addr2, *addr1 );
    749729}
    750730\end{cfa}
    751 \item
    752 The values swapped are never null pointers, so a null pointer can be used as an intermediate values during the swap.
    753 \end{enumerate}
    754 Figure~\ref{c:swap} shows the \CFA pseudocode for the \gls{das}.
    755 In detail, a thief performs the following steps to swap two pointers:
    756 \begin{enumerate}[start=0]
    757 \item
    758 stores local copies of the two pointers to be swapped.
    759 \item
    760 verifies the stored copy of the victim queue pointer, @vic_queue@, is valid.
    761 If @vic_queue@ is null, then the victim queue is part of another swap so the operation fails.
    762 No state has changed at this point so no fixup is needed.
    763 Note, @my_queue@ can never be equal to null at this point since thieves only set their own queues pointers to null when stealing.
    764 At no other point is a queue pointer set to null.
    765 Since each worker owns a disjoint range of the queue array, it is impossible for @my_queue@ to be null.
    766 \item
    767 attempts to atomically set the thief's queue pointer to null.
    768 The @CAS@ only fails if the thief's queue pointer is no longer equal to @my_queue@, which implies this thief has become a victim and its queue has been stolen.
    769 At this point, the thief-turned-victim fails, and since it has not changed any state, it just returns false.
    770 If the @CAS@ succeeds, the thief's queue pointer is now null.
    771 Nulling the pointer is safe since only thieves look at other worker's queue ranges, and whenever thieves need to dereference a queue pointer, it is checked for null.
    772 \item
    773 attempts to atomically set the victim's queue pointer to @my_queue@.
    774 If the @CAS@ succeeds, the victim's queue pointer has been set and the swap can no longer fail.
    775 If the @CAS@ fails, the thief's queue pointer must be restored to its previous value before returning.
    776 \item
    777 set the thief's queue pointer to @vic_queue@ completing the swap.
    778 \end{enumerate}
    779 
    780 \begin{figure}
    781 \begin{cfa}
    782 bool try_swap_queues( worker & this, uint victim_idx, uint my_idx ) with(this) {
    783         // Step 0: mailboxes is the shared array of all sharded queues
    784         work_queue * my_queue = mailboxes[my_idx];
    785         work_queue * vic_queue = mailboxes[victim_idx];
    786 
    787         // Step 1 If the victim queue is 0p then they are in the process of stealing so return false
    788         // 0p is Cforall's equivalent of C++'s nullptr
    789         if ( vic_queue == 0p ) return false;
    790 
    791         // Step 2 Try to set our own (thief's) queue ptr to be 0p.
    792         // If this CAS fails someone stole our (thief's) queue so return false
    793         if ( !CAS( &mailboxes[my_idx], &my_queue, 0p ) )
    794                 return false;
    795 
    796         // Step 3: Try to set victim queue ptr to be our (thief's) queue ptr.
    797         // If it fails someone stole the other queue, so fix up then return false
    798         if ( !CAS( &mailboxes[victim_idx], &vic_queue, my_queue ) ) {
    799                 mailboxes[my_idx] = my_queue; // reset queue ptr back to prev val
    800                 return false;
    801         }
    802         // Step 4: Successfully swapped.
    803         // Thief's ptr is 0p so no one will touch it
    804         // Write back without CAS is safe
    805         mailboxes[my_idx] = vic_queue;
    806         return true;
    807 }
    808 \end{cfa}
    809 \caption{DAS Concurrent}
    810 \label{c:swap}
    811 \end{figure}
    812 
    813 \begin{theorem}
    814 \gls{das} is correct in both the success and failure cases.
    815 \end{theorem}
    816 To verify sequential correctness, Figure~\ref{s:swap} shows a simplified \gls{das}.
    817 Step 1 is missing in the sequential example since it only matters in the concurrent context.
    818 By inspection, the sequential swap copies each pointer being swapped, and then the original values of each pointer are reset using the copy of the other pointer.
    819 
    820 \begin{figure}
     731The other special case is that the values being swapped will never null pointers.
     732This allows the DAS implementation presented to use null pointers as intermediate values during the swap.
     733
     734Given the wait-free swap used is novel, it is important to show that it is correct.
     735It is clear to show that the swap is wait-free since all thieves will fail or succeed in swapping the queues in a finite number of steps since there are no locks or looping.
     736There is no retry mechanism in the case of a failed swap, since a failed swap either means the work was already stolen, or that work was stolen from the thief.
     737In both cases it is apropos for a thief to give up on stealing.
     738\CFA-style pseudocode for the queue swap is presented below.
     739The swap uses compare-and-swap (@CAS@) which is just pseudocode for C's @__atomic_compare_exchange_n@.
     740A pseudocode implementation of @CAS@ is also shown below.
     741The correctness of the wait-free swap will now be discussed in detail.
     742To first verify sequential correctness, consider the equivalent sequential swap below:
     743
    821744\begin{cfa}
    822745void swap( uint victim_idx, uint my_idx ) {
     
    832755}
    833756\end{cfa}
    834 \caption{DAS Sequential}
    835 \label{s:swap}
    836 \end{figure}
    837 
    838 To verify concurrent correctness, it is necessary to show \gls{das} is wait-free, \ie all thieves fail or succeed in swapping the queues in a finite number of steps.
    839 This property is straightforward, because there are no locks or looping.
    840 As well, there is no retry mechanism in the case of a failed swap, since a failed swap either means the work is already stolen or that work is stolen from the thief.
    841 In both cases, it is apropos for a thief to give up stealing.
    842 
    843 The proof of correctness is shown through the existence of an invariant.
    844 The invariant states when a queue pointer is set to @0p@ by a thief, then the next write to the pointer can only be performed by the same thief.
     757
     758Step 1 is missing in the sequential example since it only matters in the concurrent context presented later.
     759By looking at the sequential swap it is easy to see that it is correct.
     760Temporary copies of each pointer being swapped are stored, and then the original values of each pointer are set using the copy of the other pointer.
     761
     762\begin{cfa}
     763
     764bool try_swap_queues( worker & this, uint victim_idx, uint my_idx ) with(this) {
     765        // Step 0:
     766        // mailboxes is the shared array of all sharded queues
     767        work_queue * my_queue = mailboxes[my_idx];
     768        work_queue * vic_queue = mailboxes[victim_idx];
     769
     770        // Step 1:
     771        // If the victim queue is 0p then they are in the process of stealing so return false
     772        // 0p is Cforall's equivalent of C++'s nullptr
     773        if ( vic_queue == 0p ) return false;
     774
     775        // Step 2:
     776        // Try to set our own (thief's) queue ptr to be 0p.
     777        // If this CAS fails someone stole our (thief's) queue so return false
     778        if ( !CAS( &mailboxes[my_idx], &my_queue, 0p ) )
     779                return false;
     780
     781        // Step 3:
     782        // Try to set victim queue ptr to be our (thief's) queue ptr.
     783        // If it fails someone stole the other queue, so fix up then return false
     784        if ( !CAS( &mailboxes[victim_idx], &vic_queue, my_queue ) ) {
     785                mailboxes[my_idx] = my_queue; // reset queue ptr back to prev val
     786                return false;
     787        }
     788
     789        // Step 4:
     790        // Successfully swapped.
     791        // Thief's ptr is 0p so no one will touch it
     792        // Write back without CAS is safe
     793        mailboxes[my_idx] = vic_queue;
     794        return true;
     795}
     796\end{cfa}\label{c:swap}
     797
     798Now consider the concurrent implementation of the swap.
     799\begin{enumerate}[topsep=5pt,itemsep=3pt,parsep=0pt]
     800\item
     801Step 0 is the same as the sequential example, and the thief stores local copies of the two pointers to be swapped.
     802\item
     803Step 1 verifies that the stored copy of the victim queue pointer, @vic_queue@, is valid.
     804If @vic_queue@ is equal to @0p@, then the victim queue is part of another swap so the operation fails.
     805No state has changed at this point so no fixups are needed.
     806Note, @my_queue@ can never be equal to @0p@ at this point since thieves only set their own queues pointers to @0p@ when stealing.
     807At no other point will a queue pointer be set to @0p@.
     808Since each worker owns a disjoint range of the queue array, it is impossible for @my_queue@ to be @0p@.
     809\item
     810Step 2 attempts to set the thief's queue pointer to @0p@ via @CAS@.
     811The @CAS@ will only fail if the thief's queue pointer is no longer equal to @my_queue@, which implies that this thief has become a victim and its queue has been stolen.
     812At this point the thief-turned-victim will fail and since it has not changed any state it just fails and returns false.
     813If the @CAS@ succeeds then the thief's queue pointer will now be @0p@.
     814Nulling the pointer is safe since only thieves look at other worker's queue ranges, and whenever thieves need to dereference a queue pointer they check for @0p@.
     815\item
     816Step 3 attempts to set the victim's queue pointer to be @my_queue@ via @CAS@.
     817If the @CAS@ succeeds then the victim's queue pointer has been set and swap can no longer fail.
     818If the @CAS@ fails then the thief's queue pointer must be restored to its previous value before returning.
     819\item
     820Step 4 sets the thief's queue pointer to be @vic_queue@ completing the swap.
     821\end{enumerate}
     822
     823\begin{theorem}
     824The presented swap is correct and concurrently safe in both the success and failure cases.
     825\end{theorem}
     826
     827Correctness of the swap is shown through the existence of an invariant.
     828The invariant is that when a queue pointer is set to @0p@ by a thief, then the next write to the pointer can only be performed by the same thief.
    845829To show that this invariant holds, it is shown that it is true at each step of the swap.
    846 \begin{itemize}
    847 \item
    848830Step 0 and 1 do not write and as such they cannot invalidate the invariant of any other thieves.
    849 \item
    850 In step 2, a thief attempts to write @0p@ to one of their queue pointers.
     831In step 2 a thief attempts to write @0p@ to one of their queue pointers.
    851832This queue pointer cannot be @0p@.
    852 As stated above, @my_queue@ is never equal to @0p@ since thieves only write @0p@ to queue pointers from their own queue range and all worker's queue ranges are disjoint.
    853 As such, step 2 upholds the invariant, since in a failure case no write occurs, and in the success case, the value of the queue pointer is guaranteed to not be 0p.
    854 \item
    855 In step 3, the thief attempts to write @my_queue@ to the victim's queue pointer.
    856 If the current value of the victim's queue pointer is @0p@, then the CAS fails since @vic_queue@ cannot be equal to @0p@ because of the check in step 1.
    857 Therefore, when the @CAS@ succeeds, the value of the victim's queue pointer must not be @0p@.
    858 As such, the write never overwrites a value of @0p@, hence the invariant is held in the @CAS@ of step 3.
    859 \item
    860 The write back to the thief's queue pointer that happens in the failure case of step 3 and in step 4 hold the invariant since they are the subsequent write to a @0p@ queue pointer and are being set by the same thief that set the pointer to @0p@.
    861 \end{itemize}
     833As stated above, @my_queue@ is never equal to @0p@ since thieves will only write @0p@ to queue pointers from their own queue range and all worker's queue ranges are disjoint.
     834As such step 2 upholds the invariant since in a failure case no write occurs, and in the success case, the value of the queue pointer is guaranteed to not be 0p.
     835In step 3 the thief attempts to write @my_queue@ to the victim's queue pointer.
     836If the current value of the victim's queue pointer is @0p@, then the CAS will fail since @vic_queue@ cannot be equal to @0p@ because of the check in step 1.
     837Therefore in the success case where the @CAS@ succeeds, the value of the victim's queue pointer must not be @0p@.
     838As such, the write will never overwrite a value of @0p@, hence the invariant is held in the @CAS@ of step 3.
     839The write back to the thief's queue pointer that happens in the failure case of step three and in step 4 hold the invariant since they are the subsequent write to a @0p@ queue pointer and they are being set by the same thief that set the pointer to @0p@.
    862840
    863841Given this informal proof of invariance it can be shown that the successful swap is correct.
    864 Once a thief atomically sets their queue pointer to be @0p@ in step 2, the invariant guarantees that that pointer does not change.
    865 In the success case of step 3, it is known the value of the victim's queue-pointer, which is not overwritten, must be @vic_queue@ due to the use of @CAS@.
     842Once a thief atomically sets their queue pointer to be @0p@ in step 2, the invariant guarantees that pointer will not change.
     843As such, in the success case step 3 it is known that the value of the victim's queue pointer that was overwritten must be @vic_queue@ due to the use of @CAS@.
    866844Given that pointers all have unique memory locations, this first write of the successful swap is correct since it can only occur when the pointer has not changed.
    867 By the invariant, the write back in the successful case is correct since no other worker can write to the @0p@ pointer.
    868 In the failed case of step 3, the outcome is correct in steps 1 and 2 since no writes have occurred so the program state is unchanged.
    869 Therefore, the program state is safely restored to the state it had prior to the @0p@ write in step 2, because the invariant makes the write back to the @0p@ pointer safe.
     845By the invariant the write back in the successful case is correct since no other worker can write to the @0p@ pointer.
     846
     847In the failed case the outcome is correct in steps 1 and 2 since no writes have occurred so the program state is unchanged.
     848In the failed case of step 3 the program state is safely restored to its state it had prior to the @0p@ write in step 2, thanks to the invariant that makes the write back to the @0p@ pointer safe.
    870849
    871850\begin{comment}
     
    978957% C_TODO: go through and use \paragraph to format to make it look nicer
    979958\subsection{Victim Selection}\label{s:victimSelect}
    980 
    981 In any work stealing algorithm, thieves use a heuristic to determine which victim to choose.
     959In any work stealing algorithm thieves have some heuristic to determine which victim to choose from.
    982960Choosing this algorithm is difficult and can have implications on performance.
    983 There is no one selection heuristic known to be best for all workloads.
    984 Recent work focuses on locality aware scheduling in actor systems~\cite{barghi18,wolke17}.
    985 However, while locality-aware scheduling provides good performance on some workloads, sometime randomized selection performs better on other workloads~\cite{barghi18}.
    986 Since locality aware scheduling has been explored recently, this work introduces a heuristic called \Newterm{longest victim} and compares it to randomized work stealing.
    987 
    988 The longest-victim heuristic maintains a timestamp per executor thread that is updated every time a worker attempts to steal work.
    989 \PAB{Explain the timestamp, \ie how is it formed?}
    990 Thieves then attempt to steal from the worker with the oldest timestamp.
    991 This heuristic means that if two thieves look to steal at the same time, they likely attempt to steal from the same victim.
    992 \PAB{This idea seems counter intuitive so what is the intuition?}
    993 This consequence does increase the chance at contention among thieves;
    994 however, given that workers have multiple queues, often in the tens or hundreds of queues, it is rare for two thieves to attempt stealing from the same queue.
    995 \PAB{Both of these theorems are commented out.}
    996 Furthermore, in the case they attempt to steal the same queue, at least one of them is guaranteed to successfully steal the queue as shown in Theorem~\ref{t:one_vic}.
    997 Additionally, the longest victim heuristic makes it very improbable that the no swap scenario presented in Theorem~\ref{t:vic_cycle} manifests.
    998 Given the longest victim heuristic, for a cycle to manifest it requires all workers to attempt to steal in a short timeframe.
    999 This scenario is the only way that more than one thief could choose another thief as a victim, since timestamps are only updated upon attempts to steal.
    1000 In this case, the probability of an unsuccessful swap is rare, since it is likely these steals are not important when all workers are trying to steal.
     961There is no one selection heuristic that is known to be the best on all workloads.
     962Recent work focuses on locality aware scheduling in actor systems\cite{barghi18}\cite{wolke17}.
     963However, while locality aware scheduling provides good performance on some workloads, something as simple as randomized selection performs better on other workloads\cite{barghi18}.
     964Since locality aware scheduling has been explored recently, this work introduces a heuristic called \textbf{longest victim} and compares it to randomized work stealing.
     965The longest victim heuristic maintains a timestamp per executor threads that is updated every time a worker attempts to steal work.
     966Thieves then attempt to steal from the thread with the oldest timestamp.
     967This means that if two thieves look to steal at the same time, they likely will attempt to steal from the same victim.
     968This does increase the chance at contention between thieves, however given that workers have multiple queues under them, often in the tens or hundreds of queues per worker it is rare for two queues to attempt so steal the same queue.
     969Furthermore in the case they attempt to steal the same queue at least one of them is guaranteed to successfully steal the queue as shown in Theorem \ref{t:one_vic}.
     970Additionally, the longest victim heuristic makes it very improbable that the no swap scenario presented in Theorem \ref{t:vic_cycle} manifests.
     971Given the longest victim heuristic, for a cycle to manifest it would require all workers to attempt to steal in a short timeframe.
     972This is the only way that more than one thief could choose another thief as a victim, since timestamps are only updated upon attempts to steal.
     973In this case, the probability of lack of any successful swaps is a non issue, since it is likely that these steals were not important if all workers are trying to steal.
    1001974
    1002975\section{Safety and Productivity}\label{s:SafetyProductivity}
    1003 
    1004976\CFA's actor system comes with a suite of safety and productivity features.
    1005 Most of these features are only present in \CFA's debug mode, and hence, have have zero-cost in nodebug mode.
     977Most of these features are present in \CFA's debug mode, but are removed when code is compiled in nodebug mode.
    1006978The suit of features include the following.
     979
    1007980\begin{itemize}
    1008 \item Static-typed message sends:
    1009 If an actor does not support receiving a given message type, the receive call is rejected at compile time, allowing unsupported messages to never be sent to an actor.
    1010 
    1011 \item Detection of message sends to Finished/Destroyed/Deleted actors:
    1012 All actors receive a ticket from the executor at creation that assigns them to a specific mailbox queue of a worker.
    1013 The maximum integer value of the ticket is reserved to indicate an actor is terminated, and assigned to an actor's ticket at termination.
    1014 Any subsequent message sends to this terminated actor results in an error.
    1015 
    1016 \item Actors cannot be created before the executor starts:
    1017 Since the executor distributes mailbox tickets, correctness implies it must be created before an actors so it can give out the tickets.
    1018 
    1019 \item When an executor is configured, $M >= N$.
    1020 That is, each worker must receive at least one mailbox queue, otherwise the worker spins and never does any work.
    1021 
    1022 \item Detection of unsent messages:
    1023 At program termination, a warning is printed for all deallocated messages that are not sent.
     981\item Static-typed message sends.
     982If an actor does not support receiving a given message type, the actor program is rejected at compile time, allowing unsupported messages to never be sent to actors.
     983\item Detection of message sends to Finished/Destroyed/Deleted actors.
     984All actors have a ticket that assigns them to a respective queue.
     985The maximum integer value of the ticket is reserved to indicate that an actor is dead, and subsequent message sends result in an error.
     986\item Actors made before the executor can result in undefined behaviour since an executor needs to be created beforehand so it can give out the tickets to actors.
     987As such, this is detected and an error is printed.
     988\item When an executor is created, the queues are handed out to executor threads in round robin order.
     989If there are fewer queues than executor threads, then some workers will spin and never do any work.
     990There is no reasonable use case for this behaviour so an error is printed if the number of queues is fewer than the number of executor threads.
     991\item A warning is printed when messages are deallocated without being sent.
    1024992Since the @Finished@ allocation status is unused for messages, it is used internally to detect if a message has been sent.
    1025 Deallocating a message without sending it could indicate problems in the program design.
    1026 
    1027 \item Detection of messages sent but not received:
    1028 As discussed in Section~\ref{s:executor}, once all actors have terminated, shutdown is communicated to the executor threads via a status flag.
    1029 During termination of the executor threads, each worker checks its mailbox queues for any messages.
    1030 If so, an error is reported.
    1031 Messages being sent but not received means their allocation action has not occur and their payload is not delivered.
    1032 Missed deallocations can lead to memory leaks and unreceived payloads can mean logic problems.
    1033 % Detecting can indicate a race or logic error in the user's code.
     993Deallocating a message without sending it could indicate to a user that they are touching freed memory later, or it could point out extra allocations that could be removed.
     994\item Detection of messages sent but not received
     995As discussed in Section~\ref{s:executor}, once all actors have terminated shutdown is communicated to executor threads via a status flag. Upon termination the executor threads check their queues to see if any contain messages. If they do, an error is reported. Messages being sent but not received means that their allocation action did not occur and their payload was not delivered. Missing the allocation action can lead to memory leaks and missed payloads can cause unpredictable behaviour. Detecting this can indicate a race or logic error in the user's code.
    1034996\end{itemize}
    1035997
    1036 In addition to these features, the \CFA's actor system comes with a suite of statistics that can be toggled on and off when \CFA is built.
    1037 These statistics have minimal impact on the actor system's performance since they are counted independently by each worker thread.
    1038 During shutdown of the actor system, these counters are aggregated sequentially.
     998In addition to these features, \CFA's actor system comes with a suite of statistics that can be toggled on and off.
     999These statistics have minimal impact on the actor system's performance since they are counted on a per executor threads basis.
     1000During shutdown of the actor system they are aggregated, ensuring that the only atomic instructions used by the statistics counting happen at shutdown.
    10391001The statistics measured are as follows.
     1002
    10401003\begin{description}
    10411004\item[\LstBasicStyle{\textbf{Actors Created}}]
    1042 Includes both actors made in the program main and ones made by other actors.
    1043 \item[\LstBasicStyle{\textbf{Messages Sent and Received}}]
     1005Actors created.
     1006Includes both actors made by the main and ones made by other actors.
     1007\item[\LstBasicStyle{\textbf{Messages Sent}}]
     1008Messages sent and received.
    10441009Includes termination messages send to the executor threads.
    10451010\item[\LstBasicStyle{\textbf{Gulps}}]
    1046 Gulps across all worker threads.
     1011Gulps that occurred across the executor threads.
    10471012\item[\LstBasicStyle{\textbf{Average Gulp Size}}]
    10481013Average number of messages in a gulped queue.
    10491014\item[\LstBasicStyle{\textbf{Missed gulps}}]
    1050 Missed gulps due to the current queue being processed by another worker.
     1015Occurrences where a worker missed a gulp due to the concurrent queue processing by another worker.
    10511016\item[\LstBasicStyle{\textbf{Steal attempts}}]
    1052 All worker thread attempts to steal work.
     1017Worker threads attempts to steal work.
     1018
    10531019\item[\LstBasicStyle{\textbf{Steal failures (no candidates)}}]
    1054 Work stealing failures due to selected victim not having any non-empty or non-being-processed queues.
     1020Work stealing failures due to selected victim not having any non empty or non-being-processed queues.
    10551021\item[\LstBasicStyle{\textbf{Steal failures (failed swaps)}}]
    1056 Work stealing failures due to the two-stage atomic-swap failing.
     1022Work stealing failures due to the two stage atomic swap failing.
    10571023\item[\LstBasicStyle{\textbf{Messages stolen}}]
    1058 Aggregate number of messages in stolen queues.
     1024Aggregate of the number of messages in queues as they were stolen.
    10591025\item[\LstBasicStyle{\textbf{Average steal size}}]
    1060 Average number of messages across stolen queues.
     1026Average number of messages in a stolen queue.
    10611027\end{description}
    10621028
    1063 These statistics enable a user of the \CFA's actor system to make informed choices about how to configure their executor or how to structure their actor program.
    1064 For example, if there are a lot of messages being stolen relative to the number of messages sent, it indicates that the workload is heavily imbalanced across executor threads.
    1065 Another example is if the average gulp size is very high, it indicates the executor needs more queue sharding, \ie increase $M$.
    1066 
    1067 Another productivity feature is a group of \Newterm{poison-pill} messages.
    1068 Poison-pill messages are common across actor systems, including Akka and ProtoActor~\cite{Akka,ProtoActor} to inform an actor to terminate.
     1029These statistics enable a user of \CFA's actor system to make informed choices about how to configure their executor, or how to structure their actor program.
     1030For example, if there is a lot of messages being stolen relative to the number of messages sent, it could indicate to a user that their workload is heavily imbalanced across executor threads.
     1031In another example, if the average gulp size is very high, it could indicate that the executor could use more queue sharding.
     1032
     1033Another productivity feature that is included is a group of poison-pill messages.
     1034Poison-pill messages are common across actor systems, including Akka and ProtoActor \cite{Akka,ProtoActor}.
     1035Poison-pill messages inform an actor to terminate.
    10691036In \CFA, due to the allocation of actors and lack of garbage collection, there needs to be a suite of poison-pills.
    10701037The messages that \CFA provides are @DeleteMsg@, @DestroyMsg@, and @FinishedMsg@.
    1071 These messages are supported on all actor types via inheritance.
    1072 When sent to an actor, the actor takes the corresponding allocation action after receiving the message, regardless of what the actor returns to the executor.
    1073 \PAB{What does this mean? Note that any pending messages to the actor will still be sent.
    1074 It is still the user's responsibility to ensure that an actor does not receive any messages after termination.}
     1038These messages are supported on all actor types via inheritance and when sent to an actor, the actor takes the corresponding allocation action after receiving the message.
     1039Note that any pending messages to the actor will still be sent.
     1040It is still the user's responsibility to ensure that an actor does not receive any messages after termination.
    10751041
    10761042\section{Performance}\label{s:actor_perf}
    1077 
    10781043The performance of \CFA's actor system is tested using a suite of microbenchmarks, and compared with other actor systems.
    1079 Most of the benchmarks are the same as those presented in \cite{Buhr22}, with a few additions.
     1044Most of the benchmarks are the same as those presented in \ref{}, with a few additions.
    10801045% C_TODO cite actor paper
    1081 This work compares with the following actor systems: \CFA 1.0, \uC 7.0.0, Akka Typed 2.7.0, CAF 0.18.6, and ProtoActor-Go v0.0.0-20220528090104-f567b547ea07.
    1082 Akka Classic is omitted as Akka Typed is their newest version and seems to be the direction they are headed.
    1083 The experiments are run on two popular architectures:
     1046At the time of this work the versions of the actor systems are as follows.
     1047\CFA 1.0, \uC 7.0.0, Akka Typed 2.7.0, CAF 0.18.6, and ProtoActor-Go v0.0.0-20220528090104-f567b547ea07.
     1048Akka Classic is omitted as Akka Typed is their newest version and seems to be the direction they are headed in.
     1049The experiments are run on
    10841050\begin{list}{\arabic{enumi}.}{\usecounter{enumi}\topsep=5pt\parsep=5pt\itemsep=0pt}
    10851051\item
     
    10891055\end{list}
    10901056
    1091 The benchmarks are run on 1--48 cores.
    1092 On the Intel, with 24 core sockets, there is the choice to either hopping sockets or using hyperthreads on the same socket.
    1093 Either choice causes a blip in performance, which is seen in the subsequent performance graphs.
    1094 The choice is to use hyperthreading instead of hopping sockets for experiments with more than 24 cores.
    1095 
    1096 All benchmarks are run 5 times and the median is taken.
    1097 Error bars showing the 95\% confidence intervals appear on each point in the graphs.
     1057The benchmarks are run on up to 48 cores.
     1058On the Intel, when going beyond 24 cores there is the choice to either hop sockets or to use hyperthreads.
     1059Either choice will cause a blip in performance trends, which can be seen in the following performance figures.
     1060On the Intel the choice was made to hyperthread instead of hopping sockets for experiments with more than 24 cores.
     1061
     1062All benchmarks presented are run 5 times and the median is taken.
     1063Error bars showing the 95\% confidence intervals are drawn on each point on the graphs.
    10981064If the confidence bars are small enough, they may be obscured by the point.
    1099 In this section, \uC is compared to \CFA frequently, as the actor system in \CFA is heavily based off of the \uC's actor system.
    1100 As such, the performance differences that arise are largely due to the contributions of this work.
    1101 Future work is to port some of the new \CFA work back to \uC.
    1102 
    1103 \subsection{Message Sends}
    1104 
    1105 Message sending is the key component of actor communication.
    1106 As such, latency of a single message send is the fundamental unit of fast-path performance for an actor system.
    1107 The static and dynamic microbenchmarks evaluate the average latency for a static actor/message send and a dynamic actor/message send.
    1108 In the static-send benchmark, a message and actor are allocated once and then the message is sent to the same actor 100 million (100M) times.
    1109 The average latency per message send is then calculated by dividing the duration by the number of sends.
    1110 This benchmark evaluates the cost of message sends in the actor use case where all actors and messages are allocated ahead of time and do not need to be created dynamically during execution.
    1111 The CAF static-send benchmark only sends a message 10M times to avoid extensively long run times.
    1112 
    1113 In the dynamic-send benchmark, the same experiment is used, but for each send, a new actor and message is allocated.
    1114 This benchmark evaluates the cost of message sends in the other common actor pattern where actors and messages are created on the fly as the actor program tackles a workload of variable or unknown size.
    1115 Since dynamic sends are more expensive, this benchmark repeats the actor/message creation and send 20M times (\uC, \CFA), or 2M times (Akka, CAF, ProtoActor), to give an appropriate benchmark duration.
     1065In this section \uC will be compared to \CFA frequently, as the actor system in \CFA was heavily based off \uC's actor system.
     1066As such the performance differences that arise are largely due to the contributions of this work.
    11161067
    11171068\begin{table}[t]
     
    11191070\setlength{\extrarowheight}{2pt}
    11201071\setlength{\tabcolsep}{5pt}
    1121 \caption{Static Actor/Message Performance: message send, program memory (lower is better)}
     1072
     1073\caption{Static Actor/Message Performance: message send, program memory}
    11221074\label{t:StaticActorMessagePerformance}
    1123 \PAB{Put uC++ beside \CFA.}
    11241075\begin{tabular}{*{5}{r|}r}
    11251076        & \multicolumn{1}{c|}{\CFA (100M)} & \multicolumn{1}{c|}{CAF (10M)} & \multicolumn{1}{c|}{Akka (100M)} & \multicolumn{1}{c|}{\uC (100M)} & \multicolumn{1}{c@{}}{ProtoActor (100M)} \\
     
    11321083\bigskip
    11331084
    1134 \caption{Dynamic Actor/Message Performance: message send, program memory (lower is better)}
     1085\caption{Dynamic Actor/Message Performance: message send, program memory}
    11351086\label{t:DynamicActorMessagePerformance}
    1136 \PAB{The uC++ AMD looks high. It is 65ns in the Actor paper.}
    11371087
    11381088\begin{tabular}{*{5}{r|}r}
     
    11451095\end{table}
    11461096
    1147 The results from the static/dynamic-send benchmarks are shown in Tables~\ref{t:StaticActorMessagePerformance} and \ref{t:DynamicActorMessagePerformance}, respectively.
    1148 \CFA has the best results in both benchmarks, largely due to the copy queue removing the majority of the envelope allocations.
    1149 Additionally, the receive of all messages sent in \CFA is statically known and is determined via a function pointer cast, which incurs no runtime cost.
    1150 All the other systems use virtual dispatch to find the correct behaviour at message send.
    1151 This operation actually requires two virtual dispatches, which is an additional runtime send cost.
    1152 Note that Akka also statically checks message sends, but still uses the Java virtual system.
    1153 In the static-send benchmark, all systems except CAF have static send costs that are in the same ballpark, only varying by ~70ns.
    1154 In the dynamic-send benchmark, all systems experience slower message sends, due to the memory allocations.
    1155 However, Akka and ProtoActor, slow down by two-orders of magnitude.
    1156 This difference is likely a result of Akka and ProtoActor's garbage collection, which results in performance delays for allocation-heavy workloads, whereas \uC and \CFA have explicit allocation/deallocation.
    1157 Tuning the garage collection might reduce garbage-collection cost, but this exercise is beyond the scope of this work.
     1097\subsection{Message Sends}
     1098Message sending is the key component of actor communication.
     1099As such latency of a single message send is the fundamental unit of fast-path performance for an actor system.
     1100The following two microbenchmarks evaluate the average latency for a static actor/message send and a dynamic actor/message send.
     1101Static and dynamic refer to the allocation of the message and actor.
     1102In the static send benchmark a message and actor are allocated once and then the message is sent to the same actor repeatedly until it has been sent 100 million (100M) times.
     1103The average latency per message send is then calculated by dividing the duration by the number of sends.
     1104This benchmark evaluates the cost of message sends in the actor use case where all actors and messages are allocated ahead of time and do not need to be created dynamically during execution.
     1105The CAF static send benchmark only sends a message 10M times to avoid extensively long run times.
     1106
     1107In the dynamic send benchmark the same experiment is performed, with the change that with each send a new actor and message is allocated.
     1108This evaluates the cost of message sends in the other common actor pattern where actors and message are created on the fly as the actor program tackles a workload of variable or unknown size.
     1109Since dynamic sends are more expensive, this benchmark repeats the actor/message creation and send 20M times (\uC, \CFA), or 2M times (Akka, CAF, ProtoActor), to give an appropriate benchmark duration.
     1110
     1111The results from the static/dynamic send benchmarks are shown in Figures~\ref{t:StaticActorMessagePerformance} and \ref{t:DynamicActorMessagePerformance} respectively.
     1112\CFA leads the charts in both benchmarks, largely due to the copy queue removing the majority of the envelope allocations.
     1113Additionally, the receive of all messages sent in \CFA is statically known and is determined via a function pointer cast, which incurs a compile-time cost.
     1114All the other systems use their virtual system to find the correct behaviour at message send.
     1115This requires two virtual dispatch operations, which is an additional runtime send cost that \CFA does not have.
     1116Note that Akka also statically checks message sends, but still uses their virtual system at runtime.
     1117In the static send benchmark all systems except CAF have static send costs that are in the same ballpark, only varying by ~70ns.
     1118In the dynamic send benchmark all systems experience slower message sends, as expected due to the extra allocations.
     1119However, Akka and ProtoActor, slow down by a more significant margin than the \uC and \CFA.
     1120This is likely a result of Akka and ProtoActor's garbage collection, which can suffer from hits in performance for allocation heavy workloads, whereas \uC and \CFA have explicit allocation/deallocation.
    11581121
    11591122\subsection{Work Stealing}
    1160 
    1161 \CFA's work stealing mechanism uses the longest-victim heuristic, introduced in Section~\ref{s:victimSelect}.
    1162 In this performance section, \CFA's approach is first tested in isolation on pathological unbalanced benchmarks, then with other actor systems on general benchmarks.
    1163 
    1164 Two pathological unbalanced cases are created, and compared using vanilla and randomized work stealing in \CFA.
    1165 These benchmarks adversarially takes advantage of the round-robin assignment of actors to workers by loading the receive actors on even cores and the send actors on the odd cores.
     1123\CFA's actor system has a work stealing mechanism which uses the longest victim heuristic, introduced in Section~ref{s:victimSelect}.
     1124In this performance section, \CFA with the longest victim heuristic is compared with other actor systems on the benchmark suite, and is separately compared with vanilla non-stealing \CFA and \CFA with randomized work stealing.
     1125
     1126\begin{figure}
     1127        \centering
     1128        \subfloat[AMD \CFA Balance-One Benchmark]{
     1129                \resizebox{0.5\textwidth}{!}{\input{figures/nasusCFABalance-One.pgf}}
     1130                \label{f:BalanceOneAMD}
     1131        }
     1132        \subfloat[Intel \CFA Balance-One Benchmark]{
     1133                \resizebox{0.5\textwidth}{!}{\input{figures/pykeCFABalance-One.pgf}}
     1134                \label{f:BalanceOneIntel}
     1135        }
     1136        \caption{The balance-one benchmark comparing stealing heuristics (lower is better).}
     1137\end{figure}
     1138
     1139\begin{figure}
     1140        \centering
     1141        \subfloat[AMD \CFA Balance-Multi Benchmark]{
     1142                \resizebox{0.5\textwidth}{!}{\input{figures/nasusCFABalance-Multi.pgf}}
     1143                \label{f:BalanceMultiAMD}
     1144        }
     1145        \subfloat[Intel \CFA Balance-Multi Benchmark]{
     1146                \resizebox{0.5\textwidth}{!}{\input{figures/pykeCFABalance-Multi.pgf}}
     1147                \label{f:BalanceMultiIntel}
     1148        }
     1149        \caption{The balance-multi benchmark comparing stealing heuristics (lower is better).}
     1150\end{figure}
     1151
     1152There are two benchmarks in which \CFA's work stealing is solely evaluated.
     1153The main goal of introducing work stealing to \CFA's actor system is to eliminate the pathological unbalanced cases that can present themselves in a system without some form of load balancing.
     1154The following two microbenchmarks construct two such pathological cases, and compare the work stealing variations of \CFA.
     1155The balance benchmarks adversarially takes advantage of the round robin assignment of actors to load all actors that will do work on specific cores and create 'dummy' actors that terminate after a single message send on all other cores.
    11661156The workload on the loaded cores is the same as the executor benchmark described in \ref{s:executorPerf}, but with fewer rounds.
    1167 
    11681157The balance-one benchmark loads all the work on a single core, whereas the balance-multi loads all the work on half the cores (every other core).
    11691158Given this layout, one expects the ideal speedup of work stealing in the balance-one case to be $N / N - 1$ where $N$ is the number of threads.
     
    11721161In the balance-multi experiment, the workload increases with the number of cores so an increasing or constant runtime is expected.
    11731162
    1174 \begin{figure}
    1175         \centering
    1176         \subfloat[AMD \CFA Balance-One Benchmark]{
    1177                 \resizebox{0.5\textwidth}{!}{\input{figures/nasusCFABalance-One.pgf}}
    1178                 \label{f:BalanceOneAMD}
    1179         }
    1180         \subfloat[Intel \CFA Balance-One Benchmark]{
    1181                 \resizebox{0.5\textwidth}{!}{\input{figures/pykeCFABalance-One.pgf}}
    1182                 \label{f:BalanceOneIntel}
    1183         }
    1184         \caption{The balance-one benchmark comparing stealing heuristics (lower is better).}
    1185 \end{figure}
    1186 
    1187 \begin{figure}
    1188         \centering
    1189         \subfloat[AMD \CFA Balance-Multi Benchmark]{
    1190                 \resizebox{0.5\textwidth}{!}{\input{figures/nasusCFABalance-Multi.pgf}}
    1191                 \label{f:BalanceMultiAMD}
    1192         }
    1193         \subfloat[Intel \CFA Balance-Multi Benchmark]{
    1194                 \resizebox{0.5\textwidth}{!}{\input{figures/pykeCFABalance-Multi.pgf}}
    1195                 \label{f:BalanceMultiIntel}
    1196         }
    1197         \caption{The balance-multi benchmark comparing stealing heuristics (lower is better).}
    1198 \end{figure}
    1199 
    12001163On both balance microbenchmarks slightly less than ideal speedup compared to the non stealing variation is achieved by both the random and longest victim stealing heuristics.
    12011164On the balance-multi benchmark \ref{f:BalanceMultiAMD},\ref{f:BalanceMultiIntel} the random heuristic outperforms the longest victim.
     
    12081171
    12091172\subsection{Executor}\label{s:executorPerf}
    1210 
    12111173The microbenchmarks in this section are designed to stress the executor.
    12121174The executor is the scheduler of an actor system and is responsible for organizing the interaction of executor threads to service the needs of a workload.
    1213 In the executor benchmark, 40,000 actors are created and each actor is placed into a group of 100, who send and receive 100 messages to/from each actors in their group.
     1175In the executor benchmark, 40'000 actors are created and assigned a group.
     1176Each group of actors is a group of 100 actors who send and receive 100 messages from all other actors in their group.
    12141177Each time an actor completes all their sends and receives, they are done a round.
    12151178After all groups have completed 400 rounds the system terminates.
Note: See TracChangeset for help on using the changeset viewer.