Source-Changes-HG archive

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

[src/trunk]: src/sys be one-shot by default, with room for circular



details:   https://anonhg.NetBSD.org/src/rev/59d7a83947ea
branches:  trunk
changeset: 973427:59d7a83947ea
user:      maxv <maxv%NetBSD.org@localhost>
date:      Tue Jun 30 16:28:17 2020 +0000

description:
be one-shot by default, with room for circular

diffstat:

 sys/kern/subr_fault.c |  19 ++++++++++++++-----
 sys/sys/fault.h       |   6 ++++--
 2 files changed, 18 insertions(+), 7 deletions(-)

diffs (96 lines):

diff -r 792e1374e6ba -r 59d7a83947ea sys/kern/subr_fault.c
--- a/sys/kern/subr_fault.c     Tue Jun 30 16:22:55 2020 +0000
+++ b/sys/kern/subr_fault.c     Tue Jun 30 16:28:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_fault.c,v 1.1 2020/06/07 09:45:19 maxv Exp $      */
+/*     $NetBSD: subr_fault.c,v 1.2 2020/06/30 16:28:17 maxv Exp $      */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_fault.c,v 1.1 2020/06/07 09:45:19 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_fault.c,v 1.2 2020/06/30 16:28:17 maxv Exp $");
 
 #include <sys/module.h>
 #include <sys/param.h>
@@ -48,6 +48,7 @@
 
 typedef struct {
        volatile bool enabled;
+       volatile bool oneshot;
        volatile unsigned long nth;
        volatile unsigned long cnt;
        volatile unsigned long nfaults;
@@ -55,7 +56,8 @@
 
 static fault_t fault_global __cacheline_aligned = {
        .enabled = false,
-       .nth = 2,
+       .oneshot = false,
+       .nth = FAULT_NTH_MIN,
        .cnt = 0,
        .nfaults = 0
 };
@@ -84,6 +86,11 @@
                        return false;
        }
 
+       if (atomic_load_relaxed(&f->oneshot)) {
+               if (__predict_true(atomic_load_relaxed(&f->nfaults) > 0))
+                       return false;
+       }
+
        cnt = atomic_inc_ulong_nv(&f->cnt);
        if (__predict_false(cnt % atomic_load_relaxed(&f->nth) == 0)) {
                atomic_inc_ulong(&f->nfaults);
@@ -112,9 +119,9 @@
 {
        fault_t *f;
 
-       if (args->mode != FAULT_MODE_NTH)
+       if (args->mode != FAULT_MODE_NTH_ONESHOT)
                return EINVAL;
-       if (args->nth < 2)
+       if (args->nth < FAULT_NTH_MIN)
                return EINVAL;
 
        switch (args->scope) {
@@ -124,6 +131,7 @@
                        mutex_exit(&fault_global_lock);
                        return EEXIST;
                }
+               fault_global.oneshot = true;
                atomic_store_relaxed(&fault_global.nth, args->nth);
                fault_global.cnt = 0;
                fault_global.nfaults = 0;
@@ -139,6 +147,7 @@
                        f = kmem_zalloc(sizeof(*f), KM_SLEEP);
                        lwp_setspecific(fault_lwp_key, f);
                }
+               f->oneshot = true;
                atomic_store_relaxed(&f->nth, args->nth);
                f->cnt = 0;
                f->nfaults = 0;
diff -r 792e1374e6ba -r 59d7a83947ea sys/sys/fault.h
--- a/sys/sys/fault.h   Tue Jun 30 16:22:55 2020 +0000
+++ b/sys/sys/fault.h   Tue Jun 30 16:28:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fault.h,v 1.1 2020/06/07 09:45:19 maxv Exp $   */
+/*     $NetBSD: fault.h,v 1.2 2020/06/30 16:28:17 maxv Exp $   */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -41,7 +41,9 @@
 #define FAULT_SCOPE_GLOBAL     0
 #define FAULT_SCOPE_LWP                1
 
-#define FAULT_MODE_NTH         0
+#define FAULT_MODE_NTH_ONESHOT 0
+
+#define FAULT_NTH_MIN          2
 
 struct fault_ioc_enable {
        int scope;



Home | Main Index | Thread Index | Old Index