Changeset c3f7dd9
- Timestamp:
- Jul 10, 2023, 3:45:12 PM (17 months ago)
- Branches:
- master
- Children:
- 04c31f4
- Parents:
- 555c599 (diff), 713905fd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 6 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
doc/bibliography/pl.bib
r555c599 rc3f7dd9 2155 2155 title = {Continuations and Coroutines}, 2156 2156 booktitle = {Conference Record of the 1984 {ACM} Symposium on Lisp and Functional Programming}, 2157 organization= {A ssociation for Computing Machinery},2157 organization= {ACM}, 2158 2158 month = aug, 2159 2159 year = 1984, … … 3855 3855 } 3856 3856 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 3857 3872 @article{doUpon, 3858 3873 keywords = {formal verification, axiomatic semantics, control structures}, … … 3861 3876 title = {A Generalized Iterative Construct and Its Semantics}, 3862 3877 journal = toplas, 3863 volume = {9}, number = {4}, 3878 volume = 9, 3879 number = 4, 3864 3880 pages = {567-581}, 3865 month = oct, year = 1987, 3881 month = oct, 3882 year = 1987, 3866 3883 comment = { 3867 3884 \begin{verbatim} … … 3878 3895 od 3879 3896 \end{verbatim} 3880 3881 3897 If there is an i such that Qi is true, execute Mi and terminate. 3882 3898 Otherwise, if there is an i such that Pi is true, execute Li and … … 4203 4219 year = 1989, 4204 4220 pages = {60-76}, 4205 organization= {A ssociation for Computing Machinery}4221 organization= {ACM} 4206 4222 } 4207 4223 … … 4386 4402 year = 1990, 4387 4403 pages = {125-135}, 4388 organization= {A ssociation for Computing Machinery},4404 organization= {ACM}, 4389 4405 abstract = { 4390 4406 In typed object-oriented languages the subtype relation is … … 5108 5124 title = {MCSH, a Lock with the Standard Interface}, 5109 5125 issue_date = {June 2023}, 5110 publisher = {A ssociation for Computing Machinery},5126 publisher = {ACM}, 5111 5127 address = {New York, NY, USA}, 5112 5128 volume = 10, … … 6233 6249 journal = sigplan, 6234 6250 year = 1980, 6235 month = nov, volume = 15, number = 11, pages = {47-56}, 6251 month = nov, 6252 volume = 15, 6253 number = 11, 6254 pages = {47-56}, 6236 6255 note = {Proceedings of the ACM-SIGPLAN Symposium on the {Ada} Programming Language}, 6237 6256 comment = { … … 6593 6612 } 6594 6613 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 6595 6629 @inproceedings{Rafkind09, 6596 6630 keywords = {accurate, C programming language, conservative, garbage collection, precise}, … … 6682 6716 title = {Procedures as Persistent Data Objects}, 6683 6717 journal = toplas, 6684 volume = {7}, number = {4}, 6718 volume = 7, 6719 number = 4, 6685 6720 pages = {539-559}, 6686 month = oct, year = 1985, 6721 month = oct, 6722 year = 1985, 6687 6723 comment = { 6688 6724 PS-Algol has ``structures'', accessible only through ``pntrs''. … … 6744 6780 title = {Programming Dynamically Reconfigurable Open Systems with SALSA}, 6745 6781 issue_date = {December 2001}, 6746 publisher = {A ssociation for Computing Machinery},6782 publisher = {ACM}, 6747 6783 address = {New York, NY, USA}, 6748 6784 volume = 36, … … 7105 7141 } 7106 7142 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 7107 7152 @techreport{PS-Algol, 7108 7153 keywords = {algol, persistence}, … … 7115 7160 month = jun, 7116 7161 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}},7126 7162 } 7127 7163 … … 8487 8523 year = 1990, 8488 8524 month = jan, pages = {109-124}, 8489 organization= {A ssociation for Computing Machinery},8525 organization= {ACM}, 8490 8526 abstract = { 8491 8527 This paper disucsses the phenomenon of {\em method specialization} … … 8748 8784 year = {2020}, 8749 8785 issue_date = {March 2020}, 8750 publisher = {A ssociation for Computing Machinery},8786 publisher = {ACM}, 8751 8787 address = {New York, NY, USA}, 8752 8788 volume = {4}, … … 9057 9093 editor = {Norman Meyrowitz}, 9058 9094 publisher = sigplan, 9059 organization= {A ssociation for Computing Machinery},9095 organization= {ACM}, 9060 9096 address = {Portland, Oregon}, 9061 9097 month = sep, … … 9069 9105 editor = {Norman Meyrowitz}, 9070 9106 publisher = sigplan, 9071 organization= {A ssociation for Computing Machinery},9107 organization= {ACM}, 9072 9108 address = {Orlando, Florida}, 9073 9109 month = oct, … … 9081 9117 editor = {Norman Meyrowitz}, 9082 9118 publisher = sigplan, 9083 organization= {A ssociation for Computing Machinery},9119 organization= {ACM}, 9084 9120 address = {San Diego, California}, 9085 9121 month = sep, … … 9093 9129 editor = {Norman Meyrowitz}, 9094 9130 publisher = sigplan, 9095 organization= {A ssociation for Computing Machinery},9131 organization= {ACM}, 9096 9132 address = {New Orleans, Louisiana}, 9097 9133 month = oct, … … 9105 9141 editor = {Norman Meyrowitz}, 9106 9142 publisher = sigplan, 9107 organization= {A ssociation for Computing Machinery},9143 organization= {ACM}, 9108 9144 address = {Ottawa, Canada}, 9109 9145 month = oct, … … 9117 9153 editor = {Andreas Paepcke}, 9118 9154 publisher = sigplan, 9119 organization= {A ssociation for Computing Machinery},9155 organization= {ACM}, 9120 9156 address = {Phoenix, Arizona}, 9121 9157 month = oct, -
doc/theses/colby_parsons_MMAth/glossary.tex
r555c599 rc3f7dd9 38 38 \newabbreviation{fifo}{FIFO}{\Newterm{first-in first-out}} 39 39 \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}} 40 46 41 47 \newglossaryentry{actor}{ -
doc/theses/colby_parsons_MMAth/text/actors.tex
r555c599 rc3f7dd9 555 555 In theory, this goal is not achievable, but practical results show the goal is virtually achieved. 556 556 557 One 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.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. 558 558 With 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. 559 559 Furthermore, the act of \emph{looking} to find work is invasive (Heisenberg uncertainty principle), possibly disrupting multiple victims. … … 563 563 The outline for lazy-stealing by a thief is: select a victim, scan its queues once, and return immediately if a queue is stolen. 564 564 The 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 will scanits ready queue looking for its own work before potentially stealing again.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. 566 566 This lazy examination by the thief has a low perturbation cost for victims, while still finding work in a moderately loaded system. 567 567 In all work-stealing algorithms, there is the pathological case where there is too little work and too many workers; … … 584 584 \begin{cfa} 585 585 struct work_queue { 586 spinlock_t mutex_lock; 587 copy_queue * owned_queue; 588 copy_queue * c_queue; 589 volatile bool being_processed; 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}$ 590 590 }; 591 work_queue * mailboxes; 592 work_queue ** worker_queues; 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$ 593 593 \end{cfa} 594 594 A send inserts a request at the end of one of @mailboxes@. 595 A steal swaps two pointers in @worker_queues@.595 A steal swaps two pointers in \snake{worker_queues}. 596 596 Conceptually, @worker_queues@ represents the ownership relation between mailboxes and workers. 597 597 Given $M$ workers and $N$ mailboxes, each worker owns a contiguous $M$/$N$ block of pointers in @worker_queues@. … … 599 599 To transfer ownership of a mailbox from one worker to another, a pointer from each of the workers' ranges are swapped. 600 600 This 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 threadsand victim threads.601 As such, operations can happen on @mailboxes@ independent of stealing, which avoids almost all contention between thief and victim threads. 602 602 603 603 \begin{figure} … … 627 627 The thief then resumes normal execution and ceases being a thief. 628 628 Hence, 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 ownedqueues without finding work.629 Stealing is only repeated after the worker completes two consecutive iterations over its message queues without finding work. 630 630 \end{enumerate} 631 631 … … 637 637 temp = worker_queues[x]; 638 638 // preemption and steal 639 transfer( local_queue, temp->c_queue ); // @being_processed@ set in transfer with mutual exclusion639 transfer( local_queue, temp->c_queue ); // atomically sets being_processed 640 640 \end{cfa} 641 641 where @transfer@ gulps the work from @c_queue@ to the victim's @local_queue@ and leaves @c_queue@ empty, partitioning the mailbox. … … 648 648 \end{enumerate} 649 649 If 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 its queue.650 The thief then races ahead, transitions back to a victim, searches its mailboxes, finds the stolen non-empty mailbox, and gulps this queue. 651 651 The 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. 652 652 At 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. … … 654 654 However, any form of locking here creates contention between thief and victim. 655 655 656 The alternative to locking is allowing the race and resolving it lazily .656 The alternative to locking is allowing the race and resolving it lazily (lock-free approach). 657 657 % 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. 658 658 % Furthermore, after a thief steals, there is moment when victim gulps but the queue no longer … … 668 668 The flag indicates that a mailbox has been gulped (logically subdivided) by a worker and the gulped queue is being processed locally. 669 669 The @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 find the @being_processed@ flag set, it does not gulp and moves onto the next mailbox in its range.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. 671 671 This resolves the race no matter the winner. 672 672 If the thief wins the race, it steals the mailbox and gulps, and the victim sees the flag set and skips gulping from the mailbox. … … 675 675 There is a final case where the race occurs and is resolved with \emph{both} gulps occurring. 676 676 Here, 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 @being_processed@flag.678 The 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.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. 679 679 The 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). 680 680 This 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. 681 681 However, 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 stolen mailbox pointer, is interruptedand stolen from, etc., this scenario can cascade across multiple workers all attempting to gulp from one mailbox.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. 683 683 The @being_processed@ flag ensures correctness even in this case, and the chance of a cascading scenario across multiple workers is even rarer. 684 It is straightforward to count the number of missed gulps due to the @being_processed@ flag at runtime. 685 With 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}. 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. 686 687 The repeat benchmark is an example the pathological case described earlier where there is too little work and too many workers. 687 In the repeat benchmark one actor has the majority of the workload, and no other actor has a consistent workloadwhich results in rampant stealing.688 None of the work stealing actor systems compared in this work perform well on the repeat benchmark.689 Hence, the claim is made that this stealing mechanism has a (probabilistically) zero-victim-cost in practice.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. 690 691 691 692 \subsection{Queue Pointer Swap}\label{s:swap} 692 Two atomically swap two pointers in @worker_queues@, a novel wait-free swap algorithm is used. 693 The novel wait-free swap is effectively a special case of a DCAS. 694 DCAS stands for Double Compare-And-Swap, which is a more general version of the Compare-And-Swap (CAS) atomic operation~\cite{Doherty04}. 695 CAS compares is a read-modify-write operation available on most modern architectures which atomically compares an expected value with a memory location. 696 If the expected value and value in memory are equal it then writes a new value into the memory location. 697 A sample software implemention of CAS follows. 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: 698 698 \begin{cfa} 699 699 // assume this routine executes atomically 700 bool CAS( val * ptr, val expected, val new ) { 701 if ( *ptr != expected ) 702 return false; 703 *ptr = new; 700 bool CAS( T * assn, T comp, T new ) { // T is a basic type 701 if ( *assn != comp ) return false; 702 *assn = new; 704 703 return true; 705 704 } 706 705 \end{cfa} 707 As shown CAS only operates on one memory location. 708 Where CAS operates on a single memory location and some values, DCAS operates on two memory locations. 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}. 709 720 \begin{cfa} 710 721 // assume this routine executes atomically 711 bool DCAS( val * addr1, val * addr2, val old1, val old2, val new1, valnew2 ) {712 if ( ( *addr1 == old1 ) && ( *addr2 == old2 )) {713 *a ddr1 = new1;714 *a ddr2 = new2;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; 715 726 return true; 716 727 } … … 718 729 } 719 730 \end{cfa} 720 The DCAS implemented in this work is special cased in two ways. 721 First of all, a DCAS is more powerful than what is needed to swap two pointers. 722 A double atomic swap (DAS) is all that is needed for this work. 723 The atomic swap provided by most modern hardware requires that at least one operand is a register. 724 A DAS would relax that restriction so that both operands of the swap could be memory locations. 725 As such a DAS can be written in terms of the DCAS above as follows. 726 \begin{cfa} 727 bool DAS( val * addr1, val * addr2 ) { 728 return DCAS( addr1, addr2, *addr1, *addr2, *addr2, *addr1 ); 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 ); 729 749 } 730 750 \end{cfa} 731 The other special case is that the values being swapped will never null pointers. 732 This allows the DAS implementation presented to use null pointers as intermediate values during the swap. 733 734 Given the wait-free swap used is novel, it is important to show that it is correct. 735 It 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. 736 There 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. 737 In both cases it is apropos for a thief to give up on stealing. 738 \CFA-style pseudocode for the queue swap is presented below. 739 The swap uses compare-and-swap (@CAS@) which is just pseudocode for C's @__atomic_compare_exchange_n@. 740 A pseudocode implementation of @CAS@ is also shown below. 741 The correctness of the wait-free swap will now be discussed in detail. 742 To first verify sequential correctness, consider the equivalent sequential swap below: 743 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} 744 821 \begin{cfa} 745 822 void swap( uint victim_idx, uint my_idx ) { … … 755 832 } 756 833 \end{cfa} 757 758 Step 1 is missing in the sequential example since it only matters in the concurrent context presented later. 759 By looking at the sequential swap it is easy to see that it is correct. 760 Temporary 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 764 bool 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 798 Now consider the concurrent implementation of the swap. 799 \begin{enumerate}[topsep=5pt,itemsep=3pt,parsep=0pt] 800 \item 801 Step 0 is the same as the sequential example, and the thief stores local copies of the two pointers to be swapped. 802 \item 803 Step 1 verifies that the stored copy of the victim queue pointer, @vic_queue@, is valid. 804 If @vic_queue@ is equal to @0p@, then the victim queue is part of another swap so the operation fails. 805 No state has changed at this point so no fixups are needed. 806 Note, @my_queue@ can never be equal to @0p@ at this point since thieves only set their own queues pointers to @0p@ when stealing. 807 At no other point will a queue pointer be set to @0p@. 808 Since each worker owns a disjoint range of the queue array, it is impossible for @my_queue@ to be @0p@. 809 \item 810 Step 2 attempts to set the thief's queue pointer to @0p@ via @CAS@. 811 The @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. 812 At this point the thief-turned-victim will fail and since it has not changed any state it just fails and returns false. 813 If the @CAS@ succeeds then the thief's queue pointer will now be @0p@. 814 Nulling 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 816 Step 3 attempts to set the victim's queue pointer to be @my_queue@ via @CAS@. 817 If the @CAS@ succeeds then the victim's queue pointer has been set and swap can no longer fail. 818 If the @CAS@ fails then the thief's queue pointer must be restored to its previous value before returning. 819 \item 820 Step 4 sets the thief's queue pointer to be @vic_queue@ completing the swap. 821 \end{enumerate} 822 823 \begin{theorem} 824 The presented swap is correct and concurrently safe in both the success and failure cases. 825 \end{theorem} 826 827 Correctness of the swap is shown through the existence of an invariant. 828 The 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. 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. 829 845 To show that this invariant holds, it is shown that it is true at each step of the swap. 846 \begin{itemize} 847 \item 830 848 Step 0 and 1 do not write and as such they cannot invalidate the invariant of any other thieves. 831 In step 2 a thief attempts to write @0p@ to one of their queue pointers. 849 \item 850 In step 2, a thief attempts to write @0p@ to one of their queue pointers. 832 851 This queue pointer cannot be @0p@. 833 As 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. 834 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. 835 In step 3 the thief attempts to write @my_queue@ to the victim's queue pointer. 836 If 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. 837 Therefore in the success case where the @CAS@ succeeds, the value of the victim's queue pointer must not be @0p@. 838 As such, the write will never overwrite a value of @0p@, hence the invariant is held in the @CAS@ of step 3. 839 The 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@. 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} 840 862 841 863 Given this informal proof of invariance it can be shown that the successful swap is correct. 842 Once a thief atomically sets their queue pointer to be @0p@ in step 2, the invariant guarantees that pointer willnot change.843 As such, in the success case step 3 it is known that the value of the victim's queue pointer that was overwrittenmust be @vic_queue@ due to the use of @CAS@.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@. 844 866 Given 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. 845 By the invariant the write back in the successful case is correct since no other worker can write to the @0p@ pointer. 846 847 In the failed case the outcome is correct in steps 1 and 2 since no writes have occurred so the program state is unchanged. 848 In 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. 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. 849 870 850 871 \begin{comment} … … 957 978 % C_TODO: go through and use \paragraph to format to make it look nicer 958 979 \subsection{Victim Selection}\label{s:victimSelect} 959 In any work stealing algorithm thieves have some heuristic to determine which victim to choose from. 980 981 In any work stealing algorithm, thieves use a heuristic to determine which victim to choose. 960 982 Choosing this algorithm is difficult and can have implications on performance. 961 There is no one selection heuristic that is known to be the best on all workloads. 962 Recent work focuses on locality aware scheduling in actor systems\cite{barghi18}\cite{wolke17}. 963 However, while locality aware scheduling provides good performance on some workloads, something as simple as randomized selection performs better on other workloads\cite{barghi18}. 964 Since locality aware scheduling has been explored recently, this work introduces a heuristic called \textbf{longest victim} and compares it to randomized work stealing. 965 The longest victim heuristic maintains a timestamp per executor threads that is updated every time a worker attempts to steal work. 966 Thieves then attempt to steal from the thread with the oldest timestamp. 967 This means that if two thieves look to steal at the same time, they likely will attempt to steal from the same victim. 968 This 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. 969 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}. 970 Additionally, the longest victim heuristic makes it very improbable that the no swap scenario presented in Theorem \ref{t:vic_cycle} manifests. 971 Given the longest victim heuristic, for a cycle to manifest it would require all workers to attempt to steal in a short timeframe. 972 This 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. 973 In 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. 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. 974 1001 975 1002 \section{Safety and Productivity}\label{s:SafetyProductivity} 1003 976 1004 \CFA's actor system comes with a suite of safety and productivity features. 977 Most of these features are present in \CFA's debug mode, but are removed when code is compiledin nodebug mode.1005 Most of these features are only present in \CFA's debug mode, and hence, have have zero-cost in nodebug mode. 978 1006 The suit of features include the following. 979 980 1007 \begin{itemize} 981 \item Static-typed message sends. 982 If 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. 984 All actors have a ticket that assigns them to a respective queue. 985 The 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. 987 As 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. 989 If there are fewer queues than executor threads, then some workers will spin and never do any work. 990 There 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. 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. 992 1024 Since the @Finished@ allocation status is unused for messages, it is used internally to detect if a message has been sent. 993 Deallocating 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 995 As 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. 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. 996 1034 \end{itemize} 997 1035 998 In addition to these features, \CFA's actor system comes with a suite of statistics that can be toggled on and off.999 These statistics have minimal impact on the actor system's performance since they are counted on a per executor threads basis.1000 During shutdown of the actor system they are aggregated, ensuring that the only atomic instructions used by the statistics counting happen at shutdown.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. 1001 1039 The statistics measured are as follows. 1002 1003 1040 \begin{description} 1004 1041 \item[\LstBasicStyle{\textbf{Actors Created}}] 1005 Actors created. 1006 Includes both actors made by the main and ones made by other actors. 1007 \item[\LstBasicStyle{\textbf{Messages Sent}}] 1008 Messages sent and received. 1042 Includes both actors made in the program main and ones made by other actors. 1043 \item[\LstBasicStyle{\textbf{Messages Sent and Received}}] 1009 1044 Includes termination messages send to the executor threads. 1010 1045 \item[\LstBasicStyle{\textbf{Gulps}}] 1011 Gulps that occurred across the executor threads.1046 Gulps across all worker threads. 1012 1047 \item[\LstBasicStyle{\textbf{Average Gulp Size}}] 1013 1048 Average number of messages in a gulped queue. 1014 1049 \item[\LstBasicStyle{\textbf{Missed gulps}}] 1015 Occurrences where a worker missed a gulp due to the concurrent queue processingby another worker.1050 Missed gulps due to the current queue being processed by another worker. 1016 1051 \item[\LstBasicStyle{\textbf{Steal attempts}}] 1017 Worker threads attempts to steal work. 1018 1052 All worker thread attempts to steal work. 1019 1053 \item[\LstBasicStyle{\textbf{Steal failures (no candidates)}}] 1020 Work stealing failures due to selected victim not having any non 1054 Work stealing failures due to selected victim not having any non-empty or non-being-processed queues. 1021 1055 \item[\LstBasicStyle{\textbf{Steal failures (failed swaps)}}] 1022 Work stealing failures due to the two stage atomicswap failing.1056 Work stealing failures due to the two-stage atomic-swap failing. 1023 1057 \item[\LstBasicStyle{\textbf{Messages stolen}}] 1024 Aggregate of the number of messages in queues as they were stolen.1058 Aggregate number of messages in stolen queues. 1025 1059 \item[\LstBasicStyle{\textbf{Average steal size}}] 1026 Average number of messages in a stolen queue.1060 Average number of messages across stolen queues. 1027 1061 \end{description} 1028 1062 1029 These 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. 1030 For 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. 1031 In another example, if the average gulp size is very high, it could indicate that the executor could use more queue sharding. 1032 1033 Another productivity feature that is included is a group of poison-pill messages. 1034 Poison-pill messages are common across actor systems, including Akka and ProtoActor \cite{Akka,ProtoActor}. 1035 Poison-pill messages inform an actor to terminate. 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. 1036 1069 In \CFA, due to the allocation of actors and lack of garbage collection, there needs to be a suite of poison-pills. 1037 1070 The messages that \CFA provides are @DeleteMsg@, @DestroyMsg@, and @FinishedMsg@. 1038 These 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. 1039 Note that any pending messages to the actor will still be sent. 1040 It is still the user's responsibility to ensure that an actor does not receive any messages after termination. 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.} 1041 1075 1042 1076 \section{Performance}\label{s:actor_perf} 1077 1043 1078 The performance of \CFA's actor system is tested using a suite of microbenchmarks, and compared with other actor systems. 1044 Most of the benchmarks are the same as those presented in \ ref{}, with a few additions.1079 Most of the benchmarks are the same as those presented in \cite{Buhr22}, with a few additions. 1045 1080 % C_TODO cite actor paper 1046 At 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. 1048 Akka Classic is omitted as Akka Typed is their newest version and seems to be the direction they are headed in. 1049 The experiments are run on 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: 1050 1084 \begin{list}{\arabic{enumi}.}{\usecounter{enumi}\topsep=5pt\parsep=5pt\itemsep=0pt} 1051 1085 \item … … 1055 1089 \end{list} 1056 1090 1057 The benchmarks are run on up to48 cores.1058 On the Intel, w hen going beyond 24 cores there is the choice to either hop sockets or to use hyperthreads.1059 Either choice will cause a blip in performance trends, which can be seen in the following performance figures.1060 On the Intel the choice was made to hyperthreadinstead of hopping sockets for experiments with more than 24 cores.1061 1062 All benchmarks presentedare run 5 times and the median is taken.1063 Error bars showing the 95\% confidence intervals a re drawn on each point on the graphs.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. 1064 1098 If the confidence bars are small enough, they may be obscured by the point. 1065 In this section \uC will be compared to \CFA frequently, as the actor system in \CFA was heavily based off \uC's actor system. 1066 As such the performance differences that arise are largely due to the contributions of this work. 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. 1067 1116 1068 1117 \begin{table}[t] … … 1070 1119 \setlength{\extrarowheight}{2pt} 1071 1120 \setlength{\tabcolsep}{5pt} 1072 1073 \caption{Static Actor/Message Performance: message send, program memory} 1121 \caption{Static Actor/Message Performance: message send, program memory (lower is better)} 1074 1122 \label{t:StaticActorMessagePerformance} 1123 \PAB{Put uC++ beside \CFA.} 1075 1124 \begin{tabular}{*{5}{r|}r} 1076 1125 & \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)} \\ … … 1083 1132 \bigskip 1084 1133 1085 \caption{Dynamic Actor/Message Performance: message send, program memory }1134 \caption{Dynamic Actor/Message Performance: message send, program memory (lower is better)} 1086 1135 \label{t:DynamicActorMessagePerformance} 1136 \PAB{The uC++ AMD looks high. It is 65ns in the Actor paper.} 1087 1137 1088 1138 \begin{tabular}{*{5}{r|}r} … … 1095 1145 \end{table} 1096 1146 1097 \subsection{Message Sends} 1098 Message sending is the key component of actor communication. 1099 As such latency of a single message send is the fundamental unit of fast-path performance for an actor system. 1100 The following two microbenchmarks evaluate the average latency for a static actor/message send and a dynamic actor/message send. 1101 Static and dynamic refer to the allocation of the message and actor. 1102 In 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. 1103 The average latency per message send is then calculated by dividing the duration by the number of sends. 1104 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. 1105 The CAF static send benchmark only sends a message 10M times to avoid extensively long run times. 1106 1107 In the dynamic send benchmark the same experiment is performed, with the change that with each send a new actor and message is allocated. 1108 This 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. 1109 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. 1110 1111 The 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. 1113 Additionally, 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. 1114 All the other systems use their virtual system to find the correct behaviour at message send. 1115 This requires two virtual dispatch operations, which is an additional runtime send cost that \CFA does not have. 1116 Note that Akka also statically checks message sends, but still uses their virtual system at runtime. 1117 In the static send benchmark all systems except CAF have static send costs that are in the same ballpark, only varying by ~70ns. 1118 In the dynamic send benchmark all systems experience slower message sends, as expected due to the extra allocations. 1119 However, Akka and ProtoActor, slow down by a more significant margin than the \uC and \CFA. 1120 This 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. 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. 1121 1158 1122 1159 \subsection{Work Stealing} 1123 \CFA's actor system has a work stealing mechanism which uses the longest victim heuristic, introduced in Section~ref{s:victimSelect}. 1124 In 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 1152 There are two benchmarks in which \CFA's work stealing is solely evaluated. 1153 The 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. 1154 The following two microbenchmarks construct two such pathological cases, and compare the work stealing variations of \CFA. 1155 The 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. 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. 1156 1166 The workload on the loaded cores is the same as the executor benchmark described in \ref{s:executorPerf}, but with fewer rounds. 1167 1157 1168 The 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). 1158 1169 Given 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. … … 1161 1172 In the balance-multi experiment, the workload increases with the number of cores so an increasing or constant runtime is expected. 1162 1173 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 1163 1200 On 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. 1164 1201 On the balance-multi benchmark \ref{f:BalanceMultiAMD},\ref{f:BalanceMultiIntel} the random heuristic outperforms the longest victim. … … 1171 1208 1172 1209 \subsection{Executor}\label{s:executorPerf} 1210 1173 1211 The microbenchmarks in this section are designed to stress the executor. 1174 1212 The 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. 1175 In the executor benchmark, 40'000 actors are created and assigned a group. 1176 Each group of actors is a group of 100 actors who send and receive 100 messages from all other actors in their group. 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. 1177 1214 Each time an actor completes all their sends and receives, they are done a round. 1178 1215 After all groups have completed 400 rounds the system terminates. -
src/InitTweak/FixInitNew.cpp
r555c599 rc3f7dd9 22 22 #include "AST/SymbolTable.hpp" 23 23 #include "AST/Type.hpp" 24 #include "CodeGen/GenType.h" // for genPrettyType 25 #include "CodeGen/OperatorTable.h" 26 #include "Common/PassVisitor.h" // for PassVisitor, WithStmtsToAdd 24 #include "CodeGen/OperatorTable.h" // for isConstructor, isCtorDtor, isD... 27 25 #include "Common/SemanticError.h" // for SemanticError 28 26 #include "Common/ToString.hpp" // for toCString … … 33 31 #include "ResolvExpr/Resolver.h" // for findVoidExpression 34 32 #include "ResolvExpr/Unify.h" // for typesCompatible 35 #include "SymTab/Autogen.h" // for genImplicitCall36 33 #include "SymTab/GenImplicitCall.hpp" // for genImplicitCall 37 #include "SymTab/Indexer.h" // for Indexer38 #include "SymTab/Mangler.h" // for Mangler39 #include "SynTree/LinkageSpec.h" // for C, Spec, Cforall, isBuiltin40 #include "SynTree/Attribute.h" // for Attribute41 #include "SynTree/Constant.h" // for Constant42 #include "SynTree/Declaration.h" // for ObjectDecl, FunctionDecl, Decl...43 #include "SynTree/Expression.h" // for UniqueExpr, VariableExpr, Unty...44 #include "SynTree/Initializer.h" // for ConstructorInit, SingleInit45 #include "SynTree/Label.h" // for Label, operator<46 #include "SynTree/Mutator.h" // for mutateAll, Mutator, maybeMutate47 #include "SynTree/Statement.h" // for ExprStmt, CompoundStmt, Branch...48 #include "SynTree/Type.h" // for Type, Type::StorageClasses49 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution, operator<<50 #include "SynTree/DeclReplacer.h" // for DeclReplacer51 #include "SynTree/Visitor.h" // for acceptAll, maybeAccept52 #include "Validate/FindSpecialDecls.h" // for dtorStmt, dtorStructDestroy53 34 54 35 extern bool ctordtorp; // print all debug -
tests/exceptions/.expect/fibonacci_nonlocal.txt
r555c599 rc3f7dd9 1 0 2 1 3 1 4 0 5 2 6 4 7 20 1 0 0 2 1 1 3 1 1 4 2 2 5 3 3 6 5 5 7 8 8 8 13 13 -
tests/exceptions/fibonacci_nonlocal.cfa
r555c599 rc3f7dd9 9 9 // Author : Colby Parsons 10 10 // Created On : Thu July 6 07:29:37 2023 11 // Last Modified By : Colby Parsons12 // Last Modified On : Thu Jul y 6 07:29:37202313 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 6 21:49:04 2023 13 // Update Count : 18 14 14 // 15 15 … … 18 18 #include <stdlib.hfa> 19 19 20 exception fib_num { 21 int num; 22 }; 20 exception fib_num {}; 23 21 vtable(fib_num) fib_num_vt; 24 25 exception fib_2_num { 26 int num1, num2; 27 }; 28 vtable(fib_2_num) fib_2_num_vt; 22 fib_num except{ &fib_num_vt }; 29 23 30 24 coroutine Fibonacci { int fn; }; // used for communication 31 25 32 26 void main( Fibonacci & fib ) with( fib ) { // called on first resume 33 int fn1, fn2; // retained between resumes 34 try{ 35 fn = 0; fn1 = fn; // 1st case 36 poll( fib ); 37 suspend; // restart last resume 38 fn = 1; fn2 = fn1; fn1 = fn; // 2nd case 39 poll( fib ); 40 suspend; // restart last resume 41 for () { 42 fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case 43 poll( fib ); 44 suspend; // restart last resume 45 } // for 46 } catchResume ( fib_num * e ) { 47 fn1 = e->num; 48 fn2 = e->num; 49 fn = fn1 + fn2; 50 } catchResume ( fib_2_num * e ) { 51 fn1 = e->num1; 52 fn2 = e->num1; 53 fn = fn1 + fn2; 54 } 27 int fn1, fn2; // retained between resumes 28 try { 29 poll( fib ); 30 suspend; // restart last resume 31 } catchResume ( fib_num * e ) { 32 fn = 0; fn1 = fn; // 1st case 33 } 34 try { 35 poll( fib ); 36 suspend; // restart last resume 37 } catchResume ( fib_num * e ) { 38 fn = 1; fn2 = fn1; fn1 = fn; // 2nd case 39 } 40 try { 41 for () { 42 poll( fib ); 43 suspend; // restart last resume 44 } // for 45 } catchResume ( fib_num * e ) { 46 fn = fn1 + fn2; fn2 = fn1; fn1 = fn; // general case 47 } 55 48 } 56 49 57 50 int main() { 58 51 Fibonacci f1, f2; 59 for ( 3 ) { // print N Fibonacci values 60 sout | resume( f1 ).fn; 61 } // for 62 for ( i; 3 ) { 63 fib_num except{ &fib_num_vt, i }; 64 resumeAt( f1, except ); 65 sout | resume( f1 ).fn; 66 } 67 { 68 fib_2_num except{ &fib_2_num_vt, 10, 12 }; 69 resumeAt( f1, except ); 70 } 71 sout | resume( f1 ).fn; 52 for ( i; 8 ) { 53 resumeAt( f1, except ); resumeAt( f2, except ); 54 sout | wd( 5, resume( f1 ).fn ) | wd( 5, resume( f2 ).fn ); 55 } 72 56 } 73 57 74 58 // Local Variables: // 75 // tab-width: 4 // 76 // compile-command: "cfa fibonacci.cfa" // 59 // compile-command: "cfa fibonacci_nonlocal.cfa" // 77 60 // End: //
Note: See TracChangeset
for help on using the changeset viewer.