On 08/12/20(Tue) 14:39, Visa Hankala wrote:
> On Mon, Dec 07, 2020 at 03:25:00PM -0300, Martin Pieuchot wrote:
> > Simple diff below to add the rw_lock_held() as well as a read & write
> > version.
> >
> > This allows us to reduce the difference with NetBSD in UVM by adding the
> > following checks:
> >
> > KASSERT(rw_write_held(amap->am_lock));
> >
> > ok?
> >
> > Index: sys/rwlock.h
> > ===================================================================
> > RCS file: /cvs/src/sys/sys/rwlock.h,v
> > retrieving revision 1.26
> > diff -u -p -r1.26 rwlock.h
> > --- sys/rwlock.h 16 Jul 2019 01:40:49 -0000 1.26
> > +++ sys/rwlock.h 7 Dec 2020 18:22:03 -0000
> > @@ -168,6 +168,11 @@ int rw_enter(struct rwlock *, int);
> > void rw_exit(struct rwlock *);
> > int rw_status(struct rwlock *);
> >
> > +#define rw_read_held(rwl) (rw_status(rwl) == RW_READ)
> > +#define rw_write_held(rwl) (rw_status(rwl) == RW_WRITE)
> > +#define rw_lock_held(rwl) (rw_write_held(rwl) ||
> > rw_read_held(rwl))
>
> I think rw_lock_held() should invoke rw_status() only once. This would
> reduce the overhead. It could even be a proper C function.
As below?
Index: sys/rwlock.h
===================================================================
RCS file: /cvs/src/sys/sys/rwlock.h,v
retrieving revision 1.26
diff -u -p -r1.26 rwlock.h
--- sys/rwlock.h 16 Jul 2019 01:40:49 -0000 1.26
+++ sys/rwlock.h 14 Dec 2020 13:35:41 -0000
@@ -168,6 +168,29 @@ int rw_enter(struct rwlock *, int);
void rw_exit(struct rwlock *);
int rw_status(struct rwlock *);
+static inline int
+rw_read_held(struct rwlock *rwl)
+{
+ return (rw_status(rwl) == RW_READ);
+}
+
+static inline int
+rw_write_held(struct rwlock *rwl)
+{
+ return (rw_status(rwl) == RW_WRITE);
+}
+
+static inline int
+rw_lock_held(struct rwlock *rwl)
+{
+ int status;
+
+ status = rw_status(rwl);
+
+ return (status == RW_READ || status == RW_WRITE);
+}
+
+
void _rrw_init_flags(struct rrwlock *, const char *, int,
const struct lock_type *);
int rrw_enter(struct rrwlock *, int);