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 2:04 PM, Paul Goyette <paul%whooppee.com@localhost> wrote:
> On Sun, 30 Apr 2017, 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?
>>
>> (Thanks to riastradh@ for the idea and initial review.)
>
>
> For completeness, it turns out that the following change is needed to keep
> the rump build happy!  This is in addition to the diffs posted previously.
>
> Index: locks.c
> ===================================================================
> RCS file: /cvsroot/src/sys/rump/librump/rumpkern/locks.c,v
> retrieving revision 1.73
> diff -u -p -r1.73 locks.c
> --- locks.c     27 Jan 2017 09:50:47 -0000      1.73
> +++ locks.c     30 Apr 2017 03:16:58 -0000
> @@ -183,6 +183,17 @@ mutex_exit(kmutex_t *mtx)
>  __strong_alias(mutex_spin_exit,mutex_exit);
>
>  int
> +mutex_ownable(kmutex_t *mtx)
> +{
> +
> +#ifdef RUMP_LOCKDEBUG

You don't need the RUMP_ prefix. See sys/rump/Makefile.rump.

  ozaki-r

> +       mutex_enter(mtx);
> +       mutex_exit(mtx);
> +#endif
> +       return 1;
> +}
> +
> +int
>  mutex_owned(kmutex_t *mtx)
>  {
>
>
>
> +------------------+--------------------------+----------------------------+
> | Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:          |
> | (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee dot com   |
> | Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd dot org |
> +------------------+--------------------------+----------------------------+


Home | Main Index | Thread Index | Old Index