[Cbe-oss-dev] [PATCH 1/5] MARS: yield in workload queue wait busy loop

Kazunori Asayama asayama at sm.sony.co.jp
Thu Jul 17 02:36:30 EST 2008


Arnd Bergmann wrote:
> I would hope that you can do something simpler, involving either futex
> or mailbox but not both, and no extra threads.
> A futex has the advantage that you can use it as a blocking call in either
> direction (PPU to SPU and SPU to PPU), while you typically want to avoid
> having the SPU blocked on a mailbox.
> Then again, a futex_wait on the SPU running MARS prevents you from running
> other tasks in the same SPU context, MARS should probably do that only
> when it runs out of things to work on.
> 
> As an example, I think you can do a ring buffer between PPU and SPU like
> follows:
> 
> * Have a data buffer of up to 65536 objects (bytes) that is only written
> to by one side.
> * Have one 32 bit value with two offsets into that buffer, one for reader
> and writer respectively.
> * Use atomic updates on the offset when data is read or written in the
> buffer.
> * only when writing to a full buffer or reading from an empty buffer, you
> need to wait. The PPU can wait by calling futex_wait or reading from an empty
> mailbox, or by writing to a full mailbox. The SPU can wait by calling
> futex_wait, scheduling another MARS task or doing some other stop-and-signal
> call.
> * When writing to an empty buffer or reading from a full buffer, notify
> the other side.

I suppose your mailbox method doesn't work in MARS case.

First, a MARS task can be loaded into any of SPE contexts in a MARS
runtime environment (MARS context) by the MARS kernel, and by MARS task
switching, the MARS task can move to another SPE context. That is, a PPE
thread which is waiting for the sync object can't determine whose 
mailboxes the PPE thread should read (...and MARS task switching can 
occure while the PPE thread is blocking at read operation on the mailboxes).

Second, if multiple synchronization objects are used by one MARS task
and separate PPE threads wait for each of the sync objects, the 
mailboxes of the SPE context corresponding to the MARS task can be 
accessed by the multiple PPE threads at the same time. So a notification 
for one of the sync objects may received by an unexpected PPE thread.

These were reasons why I thought a kind of dispatcher would be needed.

-- 
(ASAYAMA Kazunori
   (asayama at sm.sony.co.jp))
t





More information about the cbe-oss-dev mailing list