2010/1/26 John Baldwin <j...@freebsd.org>:
> On Tuesday 26 January 2010 3:09:32 pm M. Warner Losh wrote:
>> In message: <c6a8f7a7-f0a9-4f63-b61e-ddc5332dc...@mac.com>
>>             Marcel Moolenaar <xcl...@mac.com> writes:
>> : Maybe what is in order right now is a description (using pseudo
>> : code if you like) of what exactly needs to happen with the 3rd
>> : argument, when and how (i.e. what must be atomic and what does
>> : not have to be atomic).
>>
>> I believe the proper pseudo code should be:
>>
>> cpu_switch(struct thread *old, struct thread *new, struct mutext *mtx)
>> {
>>       /* Save the registers to the pcb */
>>       old->td_lock = mtx;
>> #if defined(SMP) && defined(SCHED_ULE)
>>       /* s/long/int/ if sizeof(long) != sizeof(void *) */
>>       /* as we have no 'void *' version of the atomics */
>>       while (atomic_load_acq_long(&new->td_lock) == (long)&blocked_lock)
>>               continue;
>> #endif
>>       /* Switch to new context */
>> }
>
> FYI, that is what the '_ptr' variants of atomic ops are for.  I do think that
> the 'acq' membar on the load is needed to ensure the CPU doesn't try to
> speculatively read any of the 'new' thread's PCB until it sees the update to
> td_lock.

I think it is more important to store the old lock via a rel barrier instead:

- old->td_lock = mtx;
+ atomic_store_rel_ptr(&old->td_lock, mtx);

Thanks,
Attilio


-- 
Peace can only be achieved by understanding - A. Einstein
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to