Fast gettimeofday(2) and clock_gettime(2)

Robert N. M. Watson rwatson at freebsd.org
Mon Jun 11 09:22:34 UTC 2012


On 11 Jun 2012, at 10:18, Konstantin Belousov wrote:

>> 3) For the purposes of adaptive mutexes in userspace, it really would be 
>> quite
>>   nice to know whether remote threads are running or not, in the same way
>>   that cheap access to remote thread run state in the kernel makes for much
>>   more efficient adaptive spinning.  I wonder if we could use this 
>>   mechanism
>>   for that purpose as well.  I guess for now, at least, you're using a 
>>   single
>>   global page, but in the future, per-process pages might be quite
>>   beneficial.
> 
> The per-process page looks almost undoable. I think that what could be
> made working, although with some hacks, is per-CPU page, and the page
> content update on context switch. This could benefit trivial system calls
> like getpid(), getppid() and others, but obviously cause increased context
> switch latency.
> 
> Per-CPU page would then solve the proposal of having an indicator of
> other threads running. I am not sure how much do we care of the potential
> information leak there.

FYI, the FreeBSD/MIPS kernel already makes use of an MD per-thread page using a reserved TLB entry switched on each kernel context switch. Interestingly, this model effectively conflicts (semantically) with the higher-level MI per-CPU mechanism. It would be nice to unify across the layers within the kernel, even if not all the way to userspace.

Robert


More information about the freebsd-arch mailing list