tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Modules loading modules?



On Aug,Sunday 1 2010, at 3:53 PM, Antti Kantee wrote:

> On Sun Aug 01 2010 at 06:10:07 -0700, Paul Goyette wrote:
>> One question:  Since an adaptive kmutex_t already includes an owner 
>> field, would we really need to have another copy of it in the rmutex_t 
>> structure?
> 
> Good point.  I think it's ok to do:
> 
>  if (mutex_owned(mtx))
>    cnt++
>  else
>    lock

When I did locking for dm driver, it was said by rmind@ that mutex_owned should 
not be used for any locking decisions and should be used only for diagnostic 
purposes. What I would in this case is add two new routines to module_framework 
-> 

module_lock()
module_unlock()

These two will then do something like this.

kmutex_t module_lock;
uint32_t refcnt;
lwp_t mod_lwp;
condvar_t cv;


module_lock() {

mutex_enter(module_lock);
start
if (refcnt == 0) {
        refcnt++;
        mod_lwp = curlwp;
else {
        if (mod_lwp == curlwp)
                refcnt++;
        else {
                cv_wait(cv);
                goto start
        }
}

mutex_exit(module_lock);
}


mudule_unlock() {
  mutex_enter(module_lock);
        KASSERT(mod_lwp != curlwp); /* module_unlock should be only called from 
lwp which called module_lock */
        
        refcnt--;
        
        if (refcnt == 0) {
                mod_lwp = 0;
                cv_broadcast(cv);
        }

  mutex_exit(module_lock);
}

This way module_lock can be called multiple times by one lwp and will sleep for 
everyone else. 

Regards

Adam.



Home | Main Index | Thread Index | Old Index