Eric,

Thanks for the explanation. What I don't understand is this statement:

> The clock thread
> can block (for example, in trying to grab a lock that's already held), 
> but that's different from being preempted

If the clock thread is blocked, it will go to sleep and relinquish the CPU 
-- and that necessarily implies preemption. What am I missing?

Thanks.

-- Sasha

On Tue, 5 Aug 2008, Eric Saxe wrote:

> Alexandra (Sasha) Fedorova wrote:
>> I am writing some code that will be called from the function ts_tick(), 
>> which is called by clock_tick(). Comments in ts_tick() say that when one 
>> releases a thread lock s/he should use "thread_unlock_nopreempt()" since 
>> "clock thread cannot be pre-empted". (See 
>> http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/disp/ts.c,
>>  
>> line 1781). 
>> My question is, if my code is called from ts_tick(), can I not acquire any 
>> adaptive mutexes? I thought that I cannot use MUTEX_ADAPTIVE 
>> (MUTEX_DEFAULT) mutex, because it might block, and, according to those 
>> comments, the thread executing clock_tick cannot be blocked. 
> Adaptive mutexes are aquired in the clock thread's context. The clock thread 
> can block (for example, in trying to grab a lock that's already held), but 
> that's different from being preempted (which could happen when dropping a 
> thread lock (see the implementation of disp_lock_exit()).
>
>> So I was going to use MUTEX_SPIN. And then, I went through 
>> clock_tick_process(), a function that calls clock_tick() (see 
>> http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/os/clock_tick.c)
>>  
>> and saw that it acquires an adaptive mutex:
>> 
>> 367  plockp = t->t_plockp;
>> 368  mutex_enter(plockp);
>> 
> Right.
>
>> I haven't found any place where plockp (or the p_lock mutex to which it 
>> points) was initialized, so I assume it's adaptive. 
> The thread is referencing the p_lock in the process structure (proc_t). I 
> don't see any explicit initialization of that lock (other than being 
> bzero()ed)....but yes, it's adaptive.
>
>> Could you please shed some light on this issue? Is it safe to use an 
>> adaptive mutex in the code called from clock_tick?
> Yes. It's safe...you probably just want to keep in mind the possibility that 
> clock might back up, if the mutexes it needs to get it's job done are 
> contended....which in general can be "painful" for the system. :)
>
> Thanks,
> -Eric
>
_______________________________________________
opensolaris-code mailing list
opensolaris-code@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to