Source-Changes-HG archive

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

[src/trunk]: src/sys Add a rw_owner_running() for the pagedaemon.



details:   https://anonhg.NetBSD.org/src/rev/3cc48c2de449
branches:  trunk
changeset: 848235:3cc48c2de449
user:      ad <ad%NetBSD.org@localhost>
date:      Tue Jan 21 20:29:51 2020 +0000

description:
Add a rw_owner_running() for the pagedaemon.

diffstat:

 sys/kern/kern_rwlock.c |  27 +++++++++++++++++++++++++--
 sys/sys/rwlock.h       |   3 ++-
 2 files changed, 27 insertions(+), 3 deletions(-)

diffs (62 lines):

diff -r ab999f45a7b1 -r 3cc48c2de449 sys/kern/kern_rwlock.c
--- a/sys/kern/kern_rwlock.c    Tue Jan 21 20:04:30 2020 +0000
+++ b/sys/kern/kern_rwlock.c    Tue Jan 21 20:29:51 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_rwlock.c,v 1.62 2020/01/20 18:48:15 ad Exp $      */
+/*     $NetBSD: kern_rwlock.c,v 1.63 2020/01/21 20:29:51 ad Exp $      */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2019, 2020
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.62 2020/01/20 18:48:15 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.63 2020/01/21 20:29:51 ad Exp $");
 
 #include "opt_lockdebug.h"
 
@@ -792,3 +792,26 @@
 
        return (void *)(owner & RW_THREAD);
 }
+
+/*
+ * rw_owner_running:
+ *
+ *     Return true if a RW lock is unheld, or write held and the owner is
+ *     running on a CPU.  For the pagedaemon.
+ */
+bool
+rw_owner_running(const krwlock_t *rw)
+{
+#ifdef MULTIPROCESSOR
+       uintptr_t owner;
+       bool rv;
+
+       kpreempt_disable();
+       owner = rw->rw_owner;
+       rv = (owner & RW_THREAD) == 0 || rw_oncpu(owner);
+       kpreempt_enable();
+       return rv;
+#else
+       return rw_owner(rw) == curlwp;
+#endif
+}
diff -r ab999f45a7b1 -r 3cc48c2de449 sys/sys/rwlock.h
--- a/sys/sys/rwlock.h  Tue Jan 21 20:04:30 2020 +0000
+++ b/sys/sys/rwlock.h  Tue Jan 21 20:29:51 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rwlock.h,v 1.14 2020/01/21 04:09:10 thorpej Exp $      */
+/*     $NetBSD: rwlock.h,v 1.15 2020/01/21 20:29:51 ad Exp $   */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -84,6 +84,7 @@
 void   rw_vector_exit(krwlock_t *);
 int    rw_vector_tryenter(krwlock_t *, const krw_t);
 void   _rw_init(krwlock_t *, uintptr_t);
+bool   rw_owner_running(const krwlock_t *);
 #endif /* __RWLOCK_PRIVATE */
 
 struct krwlock {



Home | Main Index | Thread Index | Old Index