X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=docs%2Fcomm%2Fthe-beast%2Foptimistic.html;fp=docs%2Fcomm%2Fthe-beast%2Foptimistic.html;h=4d158022e82f54dfcf3c7d3917b9e2717b405368;hp=0000000000000000000000000000000000000000;hb=0065d5ab628975892cea1ec7303f968c3338cbe1;hpb=28a464a75e14cece5db40f2765a29348273ff2d2
diff --git a/docs/comm/the-beast/optimistic.html b/docs/comm/the-beast/optimistic.html
new file mode 100644
index 0000000..4d15802
--- /dev/null
+++ b/docs/comm/the-beast/optimistic.html
@@ -0,0 +1,65 @@
+
Architectural stuff
+
+New fields in the TSO:
+
+- New global speculation-depth register; always counts the number of specuation frames
+on the stack; incremented when
+starting speculation, decremented when finishing.
+
- Profiling stuff
+
+
+
+ Speculation frames
+
+The info table for a speculation frame points to the static spec-depth configuration
+for that speculation point. (Points to, because the config is mutable, and the info
+table has to be adjacent to the (immutable) code.)
+
+
+
+ Abortion
+
+Abortion is modelled by a special asynchronous exception ThreadAbort.
+
+
+- In the scheduler, if a thread returns with ThreadBlocked, and non-zero SpecDepth, send it
+an asynchronous exception.
+
+
- In the implementation of the catch# primop, raise an asynchonous exception if
+SpecDepth is nonzero.
+
+
- Timeout, administered by scheduler. Current story: abort if a speculation frame lasts from
+one minor GC to the next. We detect this by seeing if there's a profiling frame on the stack --- a
+profiling frame is added at a minor GC in place of a speculation frame (see Online Profiling).
+
+
+
+When tearing frames off the stack, we start a new chunk at every speculation frame, as well as every
+update frame. We proceed down to the deepest speculation frame.
+
+The AP_STACK closure built for a speculation frame must be careful not to enter the
+next AP_STACK closure up, because that would re-enter a possible loop.
+
+Delivering an asynch exception to a thread that is speculating. Invariant: there can be no catch frames
+inside speculation (we abort in catch# when speculating. So the asynch exception just
+tears off frames in the standard way until it gets to a catch frame, just as it would usually do.
+
+Abortion can punish one or more of the speculation frames by decrementing their static config variables.
+
+
Synchronous exceptions
+
+Synchronous exceptions are treated similarly as before. The stack is discarded up to an update frame; the
+thunk to be updated is overwritten with "raise x", and the process continues. Until a catch frame.
+
+When we find a spec frame, we allocate a "raise x" object, and resume execution with the return address
+in the spec frame. In that way the spec frame is like a catch frame; it stops the unwinding process.
+
+It's essential that every hard failure is caught, else speculation is unsafe. In particular, divide by zero
+is hard to catch using OS support, so we test explicitly in library code. You can shoot yourself in the foot
+by writing x `div#` 0, side-stepping the test.
+
+
+
Online profiling
+
+Sampling can be more frequent than minor GC (by jiggling the end-of-block code) but cannot
+be less frequent, because GC doesn't expect to see profiling frames.
\ No newline at end of file