
multicore s30

semaphore
sync

how to block the current process

it needs to stop itself. then, how to "resume"?

when a processor stops, it can only be wake up by
the external signal, such as interrupt.

a new instruction "wait for interrupt (wfi)"

it behaves like it interrupt itself and goes
into sleep state.

RetAds = next PC,  stop execution

when interrupt occurs it behaves like it returns 
from an interrupt and starts execution

PC = RetAds, continue execution

with this instruction we can implement semaphore
as follows:

wait(sem)
  M[sem]--       decrement count
  if( M[sem] < 0 )
    enqueue current process
    block current process

block the current process is achieved by "wfi"

signal(sem)
  if( M[sem] < 1 ) M[sem]++    increment count
  if( M[sem] <= 0 )
    p = dequeue()
    send interrupt to p

send interrupt to p, is a new instruction 
"intx p"  where p is the core number 0.. NC-1

what will happen if "intx p" is send to core that
is not in "wfi"?

for a consistent meaning, core p should behave as it
is interrupted.  however, to simplify it, we can just
ignore core p if it is not in "wfi". you have to
be careful not to send "intx" to the core that is
already stop the execution as it will continue to
execute the unknown instruction.


process synchronisation

we assume all-process synchronisation.  each process
execute "sync" instruction and send itself into sleep.
when all cores execute "sync", every core will be 
wake up to continue.

if only some process need to be sync, the mechanism
to do it will be more complicate. we need to know
which process and how many of them want to be 
sync.  

we can sync a pair of process using semaphore.
Also, if some process has been stop, it will not 
participate in sync.

trap 23   wfi
trap 24   intx p  (p in R[1])
trap 25   sync

20 Apr 2016


    