Changeset f496046 for doc/theses/colby_parsons_MMAth/text/actors.tex
- Timestamp:
- Jul 31, 2023, 12:04:38 PM (11 months ago)
- Branches:
- master
- Children:
- d3c3261
- Parents:
- 14c0f7b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/colby_parsons_MMAth/text/actors.tex
r14c0f7b rf496046 578 578 579 579 In more detail, the \CFA work-stealing algorithm begins by iterating over its message queues twice without finding any work before it tries to steal a queue from another worker. 580 Stealing a queue is done wait-free (\ie no busy waiting)with a few atomic instructions that only create contention with other stealing workers not the victim.580 Stealing a queue is done atomically with a few atomic instructions that only create contention with other stealing workers not the victim. 581 581 The complexity in the implementation is that victim gulping does not take the mailbox queue; 582 582 rather it atomically transfers the mailbox nodes to another queue leaving the mailbox empty, as discussed in Section~\ref{s:executor}. … … 700 700 \subsection{Queue Pointer Swap}\label{s:swap} 701 701 702 To atomically swap the two @worker_queues@ pointers during work stealing, a novel wait-freeswap-algorithm is needed.702 To atomically swap the two @worker_queues@ pointers during work stealing, a novel atomic swap-algorithm is needed. 703 703 The \gls{cas} is a read-modify-write instruction available on most modern architectures. 704 704 It atomically compares two memory locations, and if the values are equal, it writes a new value into the first memory location. … … 737 737 } 738 738 \end{cfa} 739 and can swap two values, where the comparisons are superfluous.739 \gls{dcas} can be used to swap two values; for this use case the comparisons are superfluous. 740 740 \begin{cfa} 741 741 DCAS( x, y, x, y, y, x ); 742 742 \end{cfa} 743 743 A restrictive form of \gls{dcas} can be simulated using \gls{ll}/\gls{sc}~\cite{Brown13} or more expensive transactional memory with the same progress property problems as LL/SC. 744 (There is waning interest in transactional memory and it seems to be fading away.)744 % (There is waning interest in transactional memory and it seems to be fading away.) 745 745 746 746 Similarly, very few architectures have a true memory/memory swap instruction (Motorola M68K, SPARC 32-bit). … … 749 749 750 750 Either a true memory/memory swap instruction or a \gls{dcas} would provide the ability to atomically swap two memory locations, but unfortunately neither of these instructions are supported on the architectures used in this work. 751 Hence, a novel atomic swap for this use case is simulated, called \gls{dcasw}.752 The \gls{ dcasw} is effectively a \gls{dcas} special cased in twoways:751 Hence, a novel atomic swap specific to the actor use case is simulated, called \gls{qpcas}. 752 The \gls{qpcas} is effectively a \gls{dcas} special cased in a few ways: 753 753 \begin{enumerate} 754 754 \item 755 755 It works on two separate memory locations, and hence, is logically the same as. 756 756 \begin{cfa} 757 bool DCASW( T * dst, T * src ) {757 bool QPCAS( T * dst, T * src ) { 758 758 return DCAS( dest, src, *dest, *src, *src, *dest ); 759 759 } … … 762 762 The values swapped are never null pointers, so a null pointer can be used as an intermediate value during the swap. 763 763 \end{enumerate} 764 Figure~\ref{f: dcaswImpl} shows the \CFA pseudocode for the \gls{dcasw}.764 Figure~\ref{f:qpcasImpl} shows the \CFA pseudocode for the \gls{qpcas}. 765 765 In detail, a thief performs the following steps to swap two pointers: 766 766 \begin{enumerate}[start=0] … … 770 770 verifies the stored copy of the victim queue pointer, @vic_queue@, is valid. 771 771 If @vic_queue@ is null, then the victim queue is part of another swap so the operation fails. 772 No state has changed at this point so no fixup is needed. 773 Note, @my_queue@ can never be equal to null at this point since thieves only set their own queues pointers to null when stealing. 774 At no other point is a queue pointer set to null. 775 Since each worker owns a disjoint range of the queue array, it is impossible for @my_queue@ to be null. 776 Note, this algorithm is simplified due to each worker owning a disjoint range, allowing only the @vic_queue@ to be checked for null. 777 This was not listed as a special case of this algorithm, since this requirement can be avoided by modifying Step 1 of Figure~\ref{f:dcaswImpl} to also check @my_queue@ for null. 778 Further discussion of this generalization is omitted since it is not needed for the presented application. 772 No state has changed at this point so the thief just returns. 773 Note, thieves only set their own queues pointers to null when stealing, and queue pointers are not set to null anywhere else. 774 As such, it is impossible for @my_queue@ to be null since each worker owns a disjoint range of the queue array. 775 Hence, only @vic_queue@ is checked for null. 779 776 \item 780 777 attempts to atomically set the thief's queue pointer to null. … … 782 779 At this point, the thief-turned-victim fails, and since it has not changed any state, it just returns false. 783 780 If the @CAS@ succeeds, the thief's queue pointer is now null. 784 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. 781 Only thieves look at other worker's queue ranges, and whenever thieves need to dereference a queue pointer, it is checked for null. 782 A thief can only see the null queue pointer when looking for queues to steal or attempting a queue swap. 783 If looking for queues, the thief will skip the null pointer, thus only the queue swap case needs to be considered for correctness. 784 785 785 \item 786 786 attempts to atomically set the victim's queue pointer to @my_queue@. … … 788 788 If the @CAS@ fails, the thief's queue pointer must be restored to its previous value before returning. 789 789 \item 790 set the thief's queue pointer to @vic_queue@ completing the swap.790 sets the thief's queue pointer to @vic_queue@ completing the swap. 791 791 \end{enumerate} 792 792 … … 820 820 } 821 821 \end{cfa} 822 \caption{ DCASWConcurrent}823 \label{f: dcaswImpl}822 \caption{QPCAS Concurrent} 823 \label{f:qpcasImpl} 824 824 \end{figure} 825 825 826 826 \begin{theorem} 827 \gls{ dcasw} is correct in both the success and failure cases.827 \gls{qpcas} is correct in both the success and failure cases. 828 828 \end{theorem} 829 To verify sequential correctness, Figure~\ref{f:seqSwap} shows a simplified \gls{ dcasw}.829 To verify sequential correctness, Figure~\ref{f:seqSwap} shows a simplified \gls{qpcas}. 830 830 Step 1 is missing in the sequential example since it only matters in the concurrent context. 831 831 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. … … 845 845 } 846 846 \end{cfa} 847 \caption{ DCASWSequential}847 \caption{QPCAS Sequential} 848 848 \label{f:seqSwap} 849 849 \end{figure} 850 850 851 To verify concurrent correctness, it is necessary to show \gls{dcasw} is wait-free, \ie all thieves fail or succeed in swapping the queues in a finite number of steps.852 This propertyis straightforward, because there are no locks or looping.853 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.854 In both cases, it is apropos for a thief to give up stealing.855 856 The proof of correctness is shown through the existence of an invariant.851 % All thieves fail or succeed in swapping the queues in a finite number of steps. 852 % This is straightforward, because there are no locks or looping. 853 % 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. 854 % In both cases, it is apropos for a thief to give up stealing. 855 856 The concurrent proof of correctness is shown through the existence of an invariant. 857 857 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. 858 858 To show that this invariant holds, it is shown that it is true at each step of the swap. … … 877 877 Once a thief atomically sets their queue pointer to be @0p@ in step 2, the invariant guarantees that that pointer does not change. 878 878 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@. 879 Given that the 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.879 Given that the pointers all have unique memory locations (a pointer is never swapped with itself), this first write of the successful swap is correct since it can only occur when the pointer has not changed. 880 880 By the invariant, the write back in the successful case is correct since no other worker can write to the @0p@ pointer. 881 881 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. 882 882 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. 883 Note that the assumption of the pointers having unique memory locations prevents the ABA problem in this usage of \gls{dcasw}, but it is not needed for correctness of the general \gls{dcasw} operation.883 Note that the pointers having unique memory locations prevents the ABA problem. 884 884 885 885 \begin{comment} … … 905 905 First it is important to state that a thief does not attempt to steal from themselves. 906 906 As such, the victim here is not also a thief. 907 Stepping through the code in \ref{f: dcaswImpl}, for all thieves, steps 0-1 succeed since the victim is not stealing and has no queue pointers set to be @0p@.907 Stepping through the code in \ref{f:qpcasImpl}, for all thieves, steps 0-1 succeed since the victim is not stealing and has no queue pointers set to be @0p@. 908 908 Similarly, for all thieves, step 2 succeed since no one is stealing from any of the thieves. 909 909 In step 3, the first thief to @CAS@ wins the race and successfully swaps the queue pointer.
Note: See TracChangeset
for help on using the changeset viewer.