tech-kern archive

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

Re: New diagnostic routine - mutex_ownable()



On Sun, Apr 30, 2017 at 08:49:04AM +0800, Paul Goyette wrote:
> While working on getting the localcount(9) stuff whipped into shape, I ran
> across a situation where it is desirable to ensure that the current
> process/lwp does not already own a mutex.
> 
> We cannot use !mutex_owned() since that doesn't return the desired result
> for a spin mutex, so I'm proposing to add a new routine called
> mutex_ownable().  This does nothing in normal kernels, but for LOCKDEBUG
> kernels it does a mutex_enter() followed immediately by mutex_exit(). If the
> current process already owns the mutex, the system will panic with a
> "locking against myself" error; otherwise mutex_ownable() just returns 1,
> enabling its use as
> 
> 	KASSERT(mutex_ownable(mtx));
> 
> Diffs are attached (including man-page and sets-list updates).
> 
> Comments?  Any reason why this cannot be committed?

I have an alternate proposal for the same purpose, but not much of a
suggestion for yours.

I find it weird to have two names which kinda mean the same thing but
also don't, and it's not immediate what the difference is, but not sure
if I can come up with better names.

I feel like we mostly care about adaptive mutexes, how about this
alternate suggestion?

mutex_adaptive_owned(kmutex_t * mtx)
{
	if (mtx == NULL)
		return 0;

	KASSERT(MUTEX_ADAPTIVE_P(mtx));
	return MUTEX_OWNER(mtx->mtx_owner) == (uintptr_t)curlwp;
}


Home | Main Index | Thread Index | Old Index