Changes in / [c8ec58e:73d0a84c]
- Location:
- doc/theses/colby_parsons_MMAth/text
- Files:
-
- 7 edited
-
CFA_concurrency.tex (modified) (2 diffs)
-
CFA_intro.tex (modified) (3 diffs)
-
actors.tex (modified) (21 diffs)
-
channels.tex (modified) (8 diffs)
-
conclusion.tex (modified) (1 diff)
-
mutex_stmt.tex (modified) (13 diffs)
-
waituntil.tex (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/colby_parsons_MMAth/text/CFA_concurrency.tex
rc8ec58e r73d0a84c 12 12 \VRef[Listing]{l:cfa_thd_init} shows a typical examples of creating a \CFA user-thread type, and then as declaring processor ($N$) and thread objects ($M$). 13 13 \begin{cfa}[caption={Example of \CFA user thread and processor creation},label={l:cfa_thd_init}] 14 @thread@ my_thread { $\C{// user thread type (like structure )}$14 @thread@ my_thread { $\C{// user thread type (like structure}$ 15 15 ... // arbitrary number of field declarations 16 16 }; … … 21 21 @processor@ p[2]; $\C{// add 2 processors = 3 total with starting processor}$ 22 22 { 23 @my_thread@ t[2], * t3 = new(); $\C{// create 2 stack allocated, 1 dynamic allocated user threads}$23 @my_thread@ t[2], * t3 = new(); $\C{// create 3 user threads, running in routine main}$ 24 24 ... // execute concurrently 25 delete( t3 ); $\C{// wait for t 3to end and deallocate}$26 } // wait for threads t[0] and t[1]to end and deallocate25 delete( t3 ); $\C{// wait for thread to end and deallocate}$ 26 } // wait for threads to end and deallocate 27 27 } // deallocate additional kernel threads 28 28 \end{cfa} -
doc/theses/colby_parsons_MMAth/text/CFA_intro.tex
rc8ec58e r73d0a84c 9 9 \CFA is a layer over C, is transpiled\footnote{Source to source translator.} to C, and is largely considered to be an extension of C. 10 10 Beyond C, it adds productivity features, extended libraries, an advanced type-system, and many control-flow/concurrency constructions. 11 However, \CFA stays true to the C programming style, with most code revolving around @struct@ s and routines, and respects the same rules as C.11 However, \CFA stays true to the C programming style, with most code revolving around @struct@'s and routines, and respects the same rules as C. 12 12 \CFA is not object oriented as it has no notion of @this@ (receiver) and no structures with methods, but supports some object oriented ideas including constructors, destructors, and limited nominal inheritance. 13 13 While \CFA is rich with interesting features, only the subset pertinent to this work is discussed here. … … 17 17 References in \CFA are a layer of syntactic sugar over pointers to reduce the number of syntactic ref/deref operations needed with pointer usage. 18 18 Pointers in \CFA differ from C and \CC in their use of @0p@ instead of C's @NULL@ or \CC's @nullptr@. 19 References can contain 0p in \CFA, which is the equivalent of a null reference.20 19 Examples of references are shown in \VRef[Listing]{l:cfa_ref}. 21 20 … … 65 64 This feature is also implemented in Pascal~\cite{Pascal}. 66 65 It can exist as a stand-alone statement or wrap a routine body to expose aggregate fields. 67 If exposed fields share a name, the type system will attempt to disambiguate them based on type.68 If the type system is unable to disambiguate the fields then the user must qualify those names to avoid a compilation error.69 66 Examples of the @with@ statement are shown in \VRef[Listing]{l:cfa_with}. 70 67 -
doc/theses/colby_parsons_MMAth/text/actors.tex
rc8ec58e r73d0a84c 7 7 Actors are an indirect concurrent feature that abstracts threading away from a programmer, and instead provides \gls{actor}s and messages as building blocks for concurrency. 8 8 Hence, actors are in the realm of \gls{impl_concurrency}, where programmers write concurrent code without dealing with explicit thread creation or interaction. 9 Actor message-passing is similar to channels, but with more abstraction, so there is no shared data to protect, making actors amenable toa distributed environment.9 Actor message-passing is similar to channels, but with more abstraction, so there is no shared data to protect, making actors amenable in a distributed environment. 10 10 Actors are often used for high-performance computing and other data-centric problems, where the ease of use and scalability of an actor system provides an advantage over channels. 11 11 … … 14 14 15 15 \section{Actor Model} 16 The \Newterm{actor model} is a concurrent paradigm where an actor is used as the fundamental building-block for computation, and the data for computation is distributed to actors in the form of messages~\cite{Hewitt73}.16 The \Newterm{actor model} is a concurrent paradigm where computation is broken into units of work called actors, and the data for computation is distributed to actors in the form of messages~\cite{Hewitt73}. 17 17 An actor is composed of a \Newterm{mailbox} (message queue) and a set of \Newterm{behaviours} that receive from the mailbox to perform work. 18 18 Actors execute asynchronously upon receiving a message and can modify their own state, make decisions, spawn more actors, and send messages to other actors. … … 22 22 For example, mutual exclusion and locking are rarely relevant concepts in an actor model, as actors typically only operate on local state. 23 23 24 \subsection{Classic Actor System} 25 An implementation of the actor model with a theatre (group) of actors is called an \Newterm{actor system}. 26 Actor systems largely follow the actor model, but can differ in some ways. 27 28 In an actor system, an actor does not have a thread. 24 An actor does not have a thread. 29 25 An actor is executed by an underlying \Newterm{executor} (kernel thread-pool) that fairly invokes each actor, where an actor invocation processes one or more messages from its mailbox. 30 26 The default number of executor threads is often proportional to the number of computer cores to achieve good performance. 31 27 An executor is often tunable with respect to the number of kernel threads and its scheduling algorithm, which optimize for specific actor applications and workloads \see{Section~\ref{s:ActorSystem}}. 32 28 29 \subsection{Classic Actor System} 30 An implementation of the actor model with a community of actors is called an \Newterm{actor system}. 31 Actor systems largely follow the actor model, but can differ in some ways. 33 32 While the semantics of message \emph{send} is asynchronous, the implementation may be synchronous or a combination. 34 The default semantics for message \emph{receive} is \gls{fifo}, so an actor receives messages from its mailbox in temporal (arrival) order .35 %however, messages sent among actors arrive in any order.33 The default semantics for message \emph{receive} is \gls{fifo}, so an actor receives messages from its mailbox in temporal (arrival) order; 34 however, messages sent among actors arrive in any order. 36 35 Some actor systems provide priority-based mailboxes and/or priority-based message-selection within a mailbox, where custom message dispatchers search among or within a mailbox(es) with a predicate for specific kinds of actors and/or messages. 37 Some actor systems provide a shared mailbox where multiple actors receive from a common mailbox~\cite{Akka}, which is contrary to the no-sharing design of the basic actor-model (and may requireadditional locking).38 For non-\gls{fifo} service, some notion of fairness (eventual progress) should exist, otherwise messages have a high latency or starve, \ie are never received.39 %Finally, some actor systems provide multiple typed-mailboxes, which then lose the actor-\lstinline{become} mechanism \see{Section~\ref{s:SafetyProductivity}}.36 Some actor systems provide a shared mailbox where multiple actors receive from a common mailbox~\cite{Akka}, which is contrary to the no-sharing design of the basic actor-model (and requires additional locking). 37 For non-\gls{fifo} service, some notion of fairness (eventual progress) must exist, otherwise messages have a high latency or starve, \ie never received. 38 Finally, some actor systems provide multiple typed-mailboxes, which then lose the actor-\lstinline{become} mechanism \see{Section~\ref{s:SafetyProductivity}}. 40 39 %While the definition of the actor model provides no restrictions on message ordering, actor systems tend to guarantee that messages sent from a given actor $i$ to actor $j$ arrive at actor $j$ in the order they were sent. 41 40 Another way an actor system varies from the model is allowing access to shared global-state. … … 61 60 Figure \ref{f:inverted_actor} shows an actor system designed as \Newterm{message-centric}, where a set of messages are scheduled and run on underlying executor threads~\cite{uC++,Nigro21}. 62 61 This design is \Newterm{inverted} because actors belong to a message queue, whereas in the classic approach a message queue belongs to each actor. 63 Now a message send must quer y the actor to know which message queue to post the message to.62 Now a message send must queries the actor to know which message queue to post the message. 64 63 Again, the simplest design has a single global queue of messages accessed by the executor threads, but this approach has the same contention problem by the executor threads. 65 64 Therefore, the messages (mailboxes) are sharded and executor threads schedule each message, which points to its corresponding actor. … … 177 176 @actor | str_msg | int_msg;@ $\C{// cascade sends}$ 178 177 @actor | int_msg;@ $\C{// send}$ 179 @actor | finished_msg;@ $\C{// send => terminate actor ( builtin Poison-Pill)}$178 @actor | finished_msg;@ $\C{// send => terminate actor (deallocation deferred)}$ 180 179 stop_actor_system(); $\C{// waits until actors finish}\CRT$ 181 180 } // deallocate actor, int_msg, str_msg … … 493 492 Each executor thread iterates over its own message queues until it finds one with messages. 494 493 At this point, the executor thread atomically \gls{gulp}s the queue, meaning it moves the contents of message queue to a local queue of the executor thread. 495 Gulping moves the contents of the message queue as a batch rather than removing individual elements.496 494 An example of the queue gulping operation is shown in the right side of Figure \ref{f:gulp}, where an executor thread gulps queue 0 and begins to process it locally. 497 495 This step allows the executor thread to process the local queue without any atomics until the next gulp. … … 525 523 526 524 Since the copy queue is an array, envelopes are allocated first on the stack and then copied into the copy queue to persist until they are no longer needed. 527 For many workloads, the copy queues reallocate andgrow in size to facilitate the average number of messages in flight and there are no further dynamic allocations.525 For many workloads, the copy queues grow in size to facilitate the average number of messages in flight and there are no further dynamic allocations. 528 526 The downside of this approach is that more storage is allocated than needed, \ie each copy queue is only partially full. 529 527 Comparatively, the individual envelope allocations of a list-based queue mean that the actor system always uses the minimum amount of heap space and cleans up eagerly. … … 564 562 To ensure sequential actor execution and \gls{fifo} message delivery in a message-centric system, stealing requires finding and removing \emph{all} of an actor's messages, and inserting them consecutively in another message queue. 565 563 This operation is $O(N)$ with a non-trivial constant. 566 The only way for work stealing to become practical is to shard each worker's message queue \see{Section~\ref{s:executor}}, which also reduces contention, and to steal queues to eliminate queue searching.564 The only way for work stealing to become practical is to shard each worker's message queue, which also reduces contention, and to steal queues to eliminate queue searching. 567 565 568 566 Given queue stealing, the goal of the presented stealing implementation is to have an essentially zero-contention-cost stealing mechanism. … … 578 576 579 577 The outline for lazy-stealing by a thief is: select a victim, scan its queues once, and return immediately if a queue is stolen. 580 The thief then assumes it snormal operation of scanning over its own queues looking for work, where stolen work is placed at the end of the scan.578 The thief then assumes it normal operation of scanning over its own queues looking for work, where stolen work is placed at the end of the scan. 581 579 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. 582 580 This lazy examination by the thief has a low perturbation cost for victims, while still finding work in a moderately loaded system. … … 638 636 % Note that a thief never exceeds its $M$/$N$ worker range because it is always exchanging queues with other workers. 639 637 If no appropriate victim mailbox is found, no swap is attempted. 640 Note that since the mailbox checks happen non-atomically, the thieves effectively guess which mailbox is ripe for stealing.641 The thief may read stale data and can end up stealing an ineligible or empty mailbox.642 This is not a correctness issue and is addressed in Section~\ref{s:steal_prob}, but the steal will likely not be productive.643 These unproductive steals are uncommon, but do occur with some frequency, and are a tradeoff that is made to achieve minimal victim contention.644 638 645 639 \item … … 650 644 \end{enumerate} 651 645 652 \subsection{Stealing Problem} \label{s:steal_prob}646 \subsection{Stealing Problem} 653 647 Each queue access (send or gulp) involving any worker (thief or victim) is protected using spinlock @mutex_lock@. 654 648 However, to achieve the goal of almost zero contention for the victim, it is necessary that the thief does not acquire any queue spinlocks in the stealing protocol. … … 709 703 None of the work-stealing actor-systems examined in this work perform well on the repeat benchmark. 710 704 Hence, for all non-pathological cases, the claim is made that this stealing mechanism has a (probabilistically) zero-victim-cost in practice. 711 Future work on the work stealing system could include a backoff mechanism after failed steals to further address the pathological cases.712 705 713 706 \subsection{Queue Pointer Swap}\label{s:swap} … … 716 709 The \gls{cas} is a read-modify-write instruction available on most modern architectures. 717 710 It atomically compares two memory locations, and if the values are equal, it writes a new value into the first memory location. 718 A s equential specification of \gls{cas} is:711 A software implementation of \gls{cas} is: 719 712 \begin{cfa} 720 713 // assume this routine executes atomically … … 762 755 763 756 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. 764 There are lock-free implemetions of DCAS, or more generally K-word CAS (also known as MCAS or CASN)~\cite{Harris02} and LLX/SCX~\cite{Brown14} that can be used to provide the desired atomic swap capability.765 However, these lock-free implementations were not used as it is advantageous in the work stealing case to let an attempted atomic swap fail instead of retrying.766 757 Hence, a novel atomic swap specific to the actor use case is simulated, called \gls{qpcas}. 767 Note that this swap is \emph{not} lock-free.768 758 The \gls{qpcas} is effectively a \gls{dcas} special cased in a few ways: 769 759 \begin{enumerate} … … 776 766 \end{cfa} 777 767 \item 778 The values swapped are never null pointers, so a null pointer can be used as an intermediate value during the swap. As such, null is effectively used as a lock for the swap.768 The values swapped are never null pointers, so a null pointer can be used as an intermediate value during the swap. 779 769 \end{enumerate} 780 770 Figure~\ref{f:qpcasImpl} shows the \CFA pseudocode for the \gls{qpcas}. … … 872 862 The concurrent proof of correctness is shown through the existence of an invariant. 873 863 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. 874 This is effictively a mutual exclusion condition for the later write.875 864 To show that this invariant holds, it is shown that it is true at each step of the swap. 876 865 \begin{itemize} … … 1022 1011 The intuition behind this heuristic is that the slowest worker receives help via work stealing until it becomes a thief, which indicates that it has caught up to the pace of the rest of the workers. 1023 1012 This heuristic should ideally result in lowered latency for message sends to victim workers that are overloaded with work. 1024 It must be acknowledged that this linear search could cause a lot of cache coherence traffic.1025 Future work on this heuristic could include introducing a search that has less impact on caching.1026 1013 A negative side-effect of this heuristic is that if multiple thieves steal at the same time, they likely steal from the same victim, which increases the chance of contention. 1027 1014 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. … … 1041 1028 \CFA's actor system comes with a suite of safety and productivity features. 1042 1029 Most of these features are only present in \CFA's debug mode, and hence, have zero-cost in no-debug mode. 1043 The suit eof features include the following.1030 The suit of features include the following. 1044 1031 \begin{itemize} 1045 1032 \item Static-typed message sends: 1046 If an actor does not support receiving a given message type, the receive call is rejected at compile time, preventing unsupported messages from beingsent to an actor.1033 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. 1047 1034 1048 1035 \item Detection of message sends to Finished/Destroyed/Deleted actors: … … 1055 1042 1056 1043 \item When an executor is configured, $M >= N$. 1057 That is, each worker must receive at least one mailbox queue, since otherwise a worker cannot receive any work without a queue pull messages from.1044 That is, each worker must receive at least one mailbox queue, otherwise the worker spins and never does any work. 1058 1045 1059 1046 \item Detection of unsent messages: … … 1113 1100 \begin{list}{\arabic{enumi}.}{\usecounter{enumi}\topsep=5pt\parsep=5pt\itemsep=0pt} 1114 1101 \item 1115 Supermicro SYS--6029U--TR4 Intel Xeon Gold 5220R 24--core socket, hyper-threading $\times$ 2 sockets ( 96 process\-ing units), running Linux v5.8.0--59--generic1116 \item 1117 Supermicro AS--1123US--TR4 AMD EPYC 7662 64--core socket, hyper-threading $\times$ 2 sockets (256 processing units) , running Linux v5.8.0--55--generic1102 Supermicro SYS--6029U--TR4 Intel Xeon Gold 5220R 24--core socket, hyper-threading $\times$ 2 sockets (48 process\-ing units) 2.2GHz, running Linux v5.8.0--59--generic 1103 \item 1104 Supermicro AS--1123US--TR4 AMD EPYC 7662 64--core socket, hyper-threading $\times$ 2 sockets (256 processing units) 2.0 GHz, running Linux v5.8.0--55--generic 1118 1105 \end{list} 1119 1106 … … 1125 1112 All benchmarks are run 5 times and the median is taken. 1126 1113 Error bars showing the 95\% confidence intervals appear on each point in the graphs. 1127 The confidence intervals are calculated using bootstrapping to avoid normality assumptions.1128 1114 If the confidence bars are small enough, they may be obscured by the data point. 1129 1115 In this section, \uC is compared to \CFA frequently, as the actor system in \CFA is heavily based off of \uC's actor system. -
doc/theses/colby_parsons_MMAth/text/channels.tex
rc8ec58e r73d0a84c 20 20 Neither Go nor \CFA channels have the restrictions of the early channel-based concurrent systems. 21 21 22 Other popular languages and libraries that provide channels include C++ Boost~\cite{boost:channel}, Rust~\cite{rust:channel}, Haskell~\cite{haskell:channel}, OCaml~\cite{ocaml:channel}, and Kotlin~\cite{kotlin:channel}.22 Other popular languages and libraries that provide channels include C++ Boost~\cite{boost:channel}, Rust~\cite{rust:channel}, Haskell~\cite{haskell:channel}, and OCaml~\cite{ocaml:channel}. 23 23 Boost channels only support asynchronous (non-blocking) operations, and Rust channels are limited to only having one consumer per channel. 24 24 Haskell channels are unbounded in size, and OCaml channels are zero-size. 25 25 These restrictions in Haskell and OCaml are likely due to their functional approach, which results in them both using a list as the underlying data structure for their channel. 26 26 These languages and libraries are not discussed further, as their channel implementation is not comparable to the bounded-buffer style channels present in Go and \CFA. 27 Kotlin channels are comparable to Go and \CFA, but unfortunately they were not identified as a comparator until after presentation of this thesis and are omitted due to time constraints.28 27 29 28 \section{Producer-Consumer Problem} … … 32 31 In the problem, threads interact with a buffer in two ways: producing threads insert values into the buffer and consuming threads remove values from the buffer. 33 32 In general, a buffer needs protection to ensure a producer only inserts into a non-full buffer and a consumer only removes from a non-empty buffer (synchronization). 34 As well, a buffer needs protection from concurrent access by multiple producers or consumers attempting to insert or remove simultaneously , which is often provided by MX.33 As well, a buffer needs protection from concurrent access by multiple producers or consumers attempting to insert or remove simultaneously (MX). 35 34 36 35 \section{Channel Size}\label{s:ChannelSize} … … 42 41 Fixed sized (bounded) implies the communication is mostly asynchronous, \ie the producer can proceed up to the buffer size and vice versa for the consumer with respect to removal, at which point the producer/consumer would wait. 43 42 \item 44 Infinite sized (unbounded) implies the communication is asymmetrically asynchronous, \ie the producer never waits but the consumer waits when the buffer is empty. 43 Infinite sized (unbounded) implies the communication is asynchronous, \ie the producer never waits but the consumer waits when the buffer is empty. 44 Since memory is finite, all unbounded buffers are ultimately bounded; 45 this restriction must be part of its implementation. 45 46 \end{enumerate} 46 47 … … 49 50 However, like MX, a buffer should ensure every value is eventually removed after some reasonable bounded time (no long-term starvation). 50 51 The simplest way to prevent starvation is to implement the buffer as a queue, either with a cyclic array or linked nodes. 51 While \gls{fifo} is not required for producer-consumer problem correctness, it is a desired property in channels as it provides predictable and often relied upon channel ordering behaviour to users.52 52 53 53 \section{First-Come First-Served} 54 As pointed out, a bounded buffer implementation often provides MX among multiple producers or consumers.54 As pointed out, a bounded buffer requires MX among multiple producers or consumers. 55 55 This MX should be fair among threads, independent of the \gls{fifo} buffer being fair among values. 56 56 Fairness among threads is called \gls{fcfs} and was defined by Lamport~\cite[p.~454]{Lamport74}. … … 66 66 67 67 \section{Channel Implementation}\label{s:chan_impl} 68 The programming languages Go, Kotlin, and Erlangprovide user-level threading where the primary communication mechanism is channels.69 These languageshave user-level threading and preemptive scheduling, and both use channels for communication.70 Go and Kotlin providemultiple homogeneous channels; each have a single associated type.68 Currently, only the Go and Erlang programming languages provide user-level threading where the primary communication mechanism is channels. 69 Both Go and Erlang have user-level threading and preemptive scheduling, and both use channels for communication. 70 Go provides multiple homogeneous channels; each have a single associated type. 71 71 Erlang, which is closely related to actor systems, provides one heterogeneous channel per thread (mailbox) with a typed receive pattern. 72 Go and Kotlin encourageusers to communicate via channels, but provides them as an optional language feature.72 Go encourages users to communicate via channels, but provides them as an optional language feature. 73 73 On the other hand, Erlang's single heterogeneous channel is a fundamental part of the threading system design; using it is unavoidable. 74 Similar to Go and Kotlin, \CFA's channels are offered as an optional language feature.74 Similar to Go, \CFA's channels are offered as an optional language feature. 75 75 76 76 While iterating on channel implementation, experiments were conducted that varied the producer-consumer algorithm and lock type used inside the channel. … … 83 83 The Go channel implementation utilizes cooperation among threads to achieve good performance~\cite{go:chan}. 84 84 This cooperation only occurs when producers or consumers need to block due to the buffer being full or empty. 85 After a producer blocks it must wait for a consumer to signal it and vice versa.86 The consumer or producer that signals a blocked thread is called the signalling thread.87 85 In these cases, a blocking thread stores their relevant data in a shared location and the signalling thread completes the blocking thread's operation before waking them; 88 86 \ie the blocking thread has no work to perform after it unblocks because the signalling threads has done this work. … … 90 88 First, each thread interacting with the channel only acquires and releases the internal channel lock once. 91 89 As a result, contention on the internal lock is decreased; only entering threads compete for the lock since unblocking threads do not reacquire the lock. 92 The other advantage of Go's wait-morphing approach is that it eliminates the need to waitfor signalled threads to run.90 The other advantage of Go's wait-morphing approach is that it eliminates the bottleneck of waiting for signalled threads to run. 93 91 Note that the property of acquiring/releasing the lock only once can also be achieved with a different form of cooperation, called \Newterm{baton passing}. 94 92 Baton passing occurs when one thread acquires a lock but does not release it, and instead signals a thread inside the critical section, conceptually ``passing'' the mutual exclusion from the signalling thread to the signalled thread. … … 96 94 the wait-morphing approach has threads cooperate by completing the signalled thread's operation, thus removing a signalled thread's need for mutual exclusion after unblocking. 97 95 While baton passing is useful in some algorithms, it results in worse channel performance than the Go approach. 98 In the baton-passing approach, all threads need to wait for the signalled thread to unblockand run before other operations on the channel can proceed, since the signalled thread holds mutual exclusion;96 In the baton-passing approach, all threads need to wait for the signalled thread to reach the front of the ready queue, context switch, and run before other operations on the channel can proceed, since the signalled thread holds mutual exclusion; 99 97 in the wait-morphing approach, since the operation is completed before the signal, other threads can continue to operate on the channel without waiting for the signalled thread to run. 100 98 -
doc/theses/colby_parsons_MMAth/text/conclusion.tex
rc8ec58e r73d0a84c 20 20 \item Channels with comparable performance to Go, which have safety and productivity features including deadlock detection and an easy-to-use exception-based channel @close@ routine. 21 21 \item An in-memory actor system, which achieves the lowest latency message send of systems tested due to the novel copy-queue data structure. 22 \item As well, the actor system has built-in detection of six common actor errors, with excellent performance compared to other systems across all benchmarks presented in this thesis.23 \item A @waituntil@ statement, which tackles the hard problem of allowing a thread wait synchronously for an arbitrary set of concurrent resources.22 \item As well, the actor system has built-in detection of six common actor errors, with excellent performance compared to other systems across all benchmarks. 23 \item A @waituntil@ statement, which tackles the hard problem of allowing a thread to safely wait synchronously for an arbitrary set of concurrent resources. 24 24 \end{enumerate} 25 25 -
doc/theses/colby_parsons_MMAth/text/mutex_stmt.tex
rc8ec58e r73d0a84c 83 83 \end{figure} 84 84 85 Like Java, \CFA monitors have \Newterm{multi-acquire} (reentrant locking)semantics so the thread in the monitor may acquire it multiple times without deadlock, allowing recursion and calling of other MX functions.85 Like Java, \CFA monitors have \Newterm{multi-acquire} semantics so the thread in the monitor may acquire it multiple times without deadlock, allowing recursion and calling of other MX functions. 86 86 For robustness, \CFA monitors ensure the monitor lock is released regardless of how an acquiring function ends, normal or exceptional, and returning a shared variable is safe via copying before the lock is released. 87 87 Monitor objects can be passed through multiple helper functions without acquiring mutual exclusion, until a designated function associated with the object is called. … … 104 104 } 105 105 \end{cfa} 106 The \CFA monitor implementation ensures multi-lock acquisition is done in a deadlock-free manner regardless of the number of MX parameters and monitor arguments via resource ordering. 107 It it important to note that \CFA monitors do not attempt to solve the nested monitor problem~\cite{Lister77}. 106 The \CFA monitor implementation ensures multi-lock acquisition is done in a deadlock-free manner regardless of the number of MX parameters and monitor arguments. It it important to note that \CFA monitors do not attempt to solve the nested monitor problem~\cite{Lister77}. 108 107 109 108 \section{\lstinline{mutex} statement} … … 166 165 In detail, the mutex statement has a clause and statement block, similar to a conditional or loop statement. 167 166 The clause accepts any number of lockable objects (like a \CFA MX function prototype), and locks them for the duration of the statement. 168 The locks are acquired in a deadlock-free manner and released regardless of how control-flow exits the statement. 169 Note that this deadlock-freedom has some limitations \see{\VRef{s:DeadlockAvoidance}}. 167 The locks are acquired in a deadlock free manner and released regardless of how control-flow exits the statement. 170 168 The mutex statement provides easy lock usage in the common case of lexically wrapping a CS. 171 169 Examples of \CFA mutex statement are shown in \VRef[Listing]{l:cfa_mutex_ex}. … … 212 210 Like Java, \CFA introduces a new statement rather than building from existing language features, although \CFA has sufficient language features to mimic \CC RAII locking. 213 211 This syntactic choice makes MX explicit rather than implicit via object declarations. 214 Hence, it is eas y for programmers and language tools to identify MX points in a program, \eg scan for all @mutex@ parameters and statements in a body of code; similar scanning can be done with Java's @synchronized@.212 Hence, it is easier for programmers and language tools to identify MX points in a program, \eg scan for all @mutex@ parameters and statements in a body of code. 215 213 Furthermore, concurrent safety is provided across an entire program for the complex operation of acquiring multiple locks in a deadlock-free manner. 216 214 Unlike Java, \CFA's mutex statement and \CC's @scoped_lock@ both use parametric polymorphism to allow user defined types to work with this feature. … … 233 231 thread$\(_2\)$ : sout | "uvw" | "xyz"; 234 232 \end{cfa} 235 any of the outputs can appear :233 any of the outputs can appear, included a segment fault due to I/O buffer corruption: 236 234 \begin{cquote} 237 235 \small\tt … … 262 260 mutex( sout ) { // acquire stream lock for sout for block duration 263 261 sout | "abc"; 264 sout | "uvw" | "xyz";262 mutex( sout ) sout | "uvw" | "xyz"; // OK because sout lock is recursive 265 263 sout | "def"; 266 264 } // implicitly release sout lock 267 265 \end{cfa} 266 The inner lock acquire is likely to occur through a function call that does a thread-safe print. 268 267 269 268 \section{Deadlock Avoidance}\label{s:DeadlockAvoidance} … … 310 309 For fewer than 7 locks ($2^3-1$), the sort is unrolled performing the minimum number of compare and swaps for the given number of locks; 311 310 for 7 or more locks, insertion sort is used. 312 It is assumed to be rare to hold more than 6 locks at a time. 313 For 6 or fewer locks the algorithm is fast and executes in $O(1)$ time. 314 Furthermore, lock addresses are unique across program execution, even for dynamically allocated locks, so the algorithm is safe across the entire program execution, as long as lifetimes of objects are appropriately managed. 315 For example, deleting a lock and allocating another one could give the new lock the same address as the deleted one, however deleting a lock in use by another thread is a programming error irrespective of the usage of the @mutex@ statement. 311 Since it is extremely rare to hold more than 6 locks at a time, the algorithm is fast and executes in $O(1)$ time. 312 Furthermore, lock addresses are unique across program execution, even for dynamically allocated locks, so the algorithm is safe across the entire program execution. 316 313 317 314 The downside to the sorting approach is that it is not fully compatible with manual usages of the same locks outside the @mutex@ statement, \ie the lock are acquired without using the @mutex@ statement. … … 341 338 \end{cquote} 342 339 Comparatively, if the @scoped_lock@ is used and the same locks are acquired elsewhere, there is no concern of the @scoped_lock@ deadlocking, due to its avoidance scheme, but it may livelock. 343 The convenience and safety of the @mutex@ statement, \ie guaranteed lock release with exceptions, should encourage programmers to always use it for locking, mitigating most deadlock scenariosversus combining manual locking with the mutex statement.340 The convenience and safety of the @mutex@ statement, \ie guaranteed lock release with exceptions, should encourage programmers to always use it for locking, mitigating any deadlock scenario versus combining manual locking with the mutex statement. 344 341 Both \CC and the \CFA do not provide any deadlock guarantees for nested @scoped_lock@s or @mutex@ statements. 345 342 To do so would require solving the nested monitor problem~\cite{Lister77}, which currently does not have any practical solutions. … … 347 344 \section{Performance} 348 345 Given the two multi-acquisition algorithms in \CC and \CFA, each with differing advantages and disadvantages, it interesting to compare their performance. 349 Comparison with Java was not conducted, since the synchronized statement only takes a single object and does not provide deadlock avoidance or prevention.346 Comparison with Java is not possible, since it only takes a single lock. 350 347 351 348 The comparison starts with a baseline that acquires the locks directly without a mutex statement or @scoped_lock@ in a fixed ordering and then releases them. … … 359 356 Each variation is run 11 times on 2, 4, 8, 16, 24, 32 cores and with 2, 4, and 8 locks being acquired. 360 357 The median is calculated and is plotted alongside the 95\% confidence intervals for each point. 361 The confidence intervals are calculated using bootstrapping to avoid normality assumptions.362 358 363 359 \begin{figure} … … 392 388 } 393 389 \end{cfa} 394 \caption{Deadlock avoidance benchmark \CFApseudocode}390 \caption{Deadlock avoidance benchmark pseudocode} 395 391 \label{l:deadlock_avoid_pseudo} 396 392 \end{figure} … … 400 396 % sudo dmidecode -t system 401 397 \item 402 Supermicro AS--1123US--TR4 AMD EPYC 7662 64--core socket, hyper-threading $\times$ 2 sockets (256 processing units) , TSO memory model, running Linux v5.8.0--55--generic, gcc--10 compiler398 Supermicro AS--1123US--TR4 AMD EPYC 7662 64--core socket, hyper-threading $\times$ 2 sockets (256 processing units) 2.0 GHz, TSO memory model, running Linux v5.8.0--55--generic, gcc--10 compiler 403 399 \item 404 Supermicro SYS--6029U--TR4 Intel Xeon Gold 5220R 24--core socket, hyper-threading $\times$ 2 sockets ( 96 processing units), TSO memory model, running Linux v5.8.0--59--generic, gcc--10 compiler400 Supermicro SYS--6029U--TR4 Intel Xeon Gold 5220R 24--core socket, hyper-threading $\times$ 2 sockets (48 processing units) 2.2GHz, TSO memory model, running Linux v5.8.0--59--generic, gcc--10 compiler 405 401 \end{list} 406 402 %The hardware architectures are different in threading (multithreading vs hyper), cache structure (MESI or MESIF), NUMA layout (QPI vs HyperTransport), memory model (TSO vs WO), and energy/thermal mechanisms (turbo-boost). … … 415 411 For example, on the AMD machine with 32 threads and 8 locks, the benchmarks would occasionally livelock indefinitely, with no threads making any progress for 3 hours before the experiment was terminated manually. 416 412 It is likely that shorter bouts of livelock occurred in many of the experiments, which would explain large confidence intervals for some of the data points in the \CC data. 417 In Figures~\ref{f:mutex_bench8_AMD} and \ref{f:mutex_bench8_Intel} there is the counter-intuitive result of the @mutex@statement performing better than the baseline.413 In Figures~\ref{f:mutex_bench8_AMD} and \ref{f:mutex_bench8_Intel} there is the counter-intuitive result of the mutex statement performing better than the baseline. 418 414 At 7 locks and above the mutex statement switches from a hard coded sort to insertion sort, which should decrease performance. 419 415 The hard coded sort is branch-free and constant-time and was verified to be faster than insertion sort for 6 or fewer locks. 420 Part of the difference in throughput compared to baseline is due to the delay spent in the insertion sort, which decreases contention on the locks. 421 This was verified to be part of the difference in throughput by experimenting with varying NCS delays in the baseline; however it only comprises a small portion of difference. 422 It is possible that the baseline is slowed down or the @mutex@ is sped up by other factors that are not easily identifiable. 416 It is likely the increase in throughput compared to baseline is due to the delay spent in the insertion sort, which decreases contention on the locks. 417 423 418 424 419 \begin{figure} -
doc/theses/colby_parsons_MMAth/text/waituntil.tex
rc8ec58e r73d0a84c 168 168 Go's @select@ has the same exclusive-or semantics as the ALT primitive from Occam and associated code blocks for each clause like ALT and Ada. 169 169 However, unlike Ada and ALT, Go does not provide guards for the \lstinline[language=go]{case} clauses of the \lstinline[language=go]{select}. 170 As such, the exponential blowup can be seen comparing Go and \uC in Figure~\ ref{f:AdaMultiplexing}.170 As such, the exponential blowup can be seen comparing Go and \uC in Figure~\label{f:AdaMultiplexing}. 171 171 Go also provides a timeout via a channel and a @default@ clause like Ada @else@ for asynchronous multiplexing. 172 172 … … 519 519 In following example, either channel @C1@ or @C2@ must be satisfied but nothing can be done for at least 1 or 3 seconds after the channel read, respectively. 520 520 \begin{cfa}[deletekeywords={timeout}] 521 waituntil( i << C1 ) {} and waituntil( timeout( 1`s ) ){}522 or waituntil( i << C2 ) {} and waituntil( timeout( 3`s ) ){}521 waituntil( i << C1 ); and waituntil( timeout( 1`s ) ); 522 or waituntil( i << C2 ); and waituntil( timeout( 3`s ) ); 523 523 \end{cfa} 524 524 If only @C2@ is satisfied, \emph{both} timeout code-blocks trigger because 1 second occurs before 3 seconds. … … 542 542 Now the unblocked WUT is guaranteed to have a satisfied resource and its code block can safely executed. 543 543 The insertion circumvents the channel buffer via the wait-morphing in the \CFA channel implementation \see{Section~\ref{s:chan_impl}}, allowing @waituntil@ channel unblocking to not be special-cased. 544 Note that all channel operations are fair and no preference is given between @waituntil@ and direct channel operations when unblocking.545 544 546 545 Furthermore, if both @and@ and @or@ operators are used, the @or@ operations stop behaving like exclusive-or due to the race among channel operations, \eg:
Note:
See TracChangeset
for help on using the changeset viewer.