Love Atomicity
In light of the recent "Revival of pessimistic locking" thread, I have
come to realize that the Love Threading model I've created for LibSF
386-x40 could be extended to create a Love Atomicity (LA) model which
guarantees certain code blocks in the system are run atomically.
LA would provide ISA support for global atomicity in executing code.
It would not just be a lock on data at memory locations, but would
provide facilities to suspend execution in the current core, and to
dispatch the code block to a designated core for execution atomically.
If another request is currently being executed atomically, it would
enter a queue and operate in its turn. The originating core would
then either enter into a wait state for the code block to be completed,
and to receive back the go-ahead signal, or it would immediately fail
due to the wait queue where it can spin as needed, or go on to perform
other tasks.
In assembly syntax, it would be like this:
; A parameter is provided indicating the JMP target to
; begin waiting for the go-ahead singal:
lsync offset continue
; Code goes here, that which will execute atomically on
; the designated LA CPU
continue:
; No parameter is provided, indicating this is the signal
; of the end of the code block for the designated core,
; and the target of the wait for the originating core
lsync
; After this instruction, flags, registers, parameters
; can be examined to determine the state of the request.
Upon entry into the designated core, FS and GS would be replaced
by those setup by the OS for this purpose, to immediately point
to locations for semaphore data, coordination of multiple tasks,
multiple threads, etc. And upon exit from the designated core
through the stand-alone lsync instruction, the state is restored
to what it was before.
In this way, every core can guarantee that its request is always
run atomically, and it need not be a single memory access, but can
be an entire block of code.
The LA core will sacrifice its own workload (or a portion of its own
workload, see last paragraph*) to fill the requests as they come in.
It will be known that this core is set aside for this purpose, so it
is scheduled with lesser weight in critical needs than with the other
cores.
By creating this Love Atomicity ability, no OS protocol is required
apart from initial setup and ongoing support in the case of specific
needs by the various calls. It provides a way to perform global
syncing on complex code and testing, including the ability for the
designated core to call other functions in the originating core's
instruction stream, as it basically inherits the code state and is
able to perform its work as the originating thread would've been
able to do, save the altered FS and GS registers.
* I am also considering the ability to have the originating and
designated cores swap each others workload so that the bulk of the
compute is not lost during the atomic code run, but only a small part
of it, as the protocol can simply guarantee that the code block will
always be executed atomically, on a known core, with the known FS and
GS environment.