Module Name: src
Committed By: maxv
Date: Tue Jun 30 16:28:17 UTC 2020
Modified Files:
src/sys/kern: subr_fault.c
src/sys/sys: fault.h
Log Message:
be one-shot by default, with room for circular
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/kern/subr_fault.c
cvs rdiff -u -r1.1 -r1.2 src/sys/sys/fault.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/subr_fault.c
diff -u src/sys/kern/subr_fault.c:1.1 src/sys/kern/subr_fault.c:1.2
--- src/sys/kern/subr_fault.c:1.1 Sun Jun 7 09:45:19 2020
+++ src/sys/kern/subr_fault.c Tue Jun 30 16:28:17 2020
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: subr_fault.c
typedef struct {
volatile bool enabled;
+ volatile bool oneshot;
volatile unsigned long nth;
volatile unsigned long cnt;
volatile unsigned long nfaults;
@@ -55,7 +56,8 @@ typedef struct {
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 @@ fault_inject(void)
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_ioc_enable(struct fault_ioc_enable
{
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 @@ fault_ioc_enable(struct fault_ioc_enable
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 @@ fault_ioc_enable(struct fault_ioc_enable
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;
Index: src/sys/sys/fault.h
diff -u src/sys/sys/fault.h:1.1 src/sys/sys/fault.h:1.2
--- src/sys/sys/fault.h:1.1 Sun Jun 7 09:45:19 2020
+++ src/sys/sys/fault.h Tue Jun 30 16:28:17 2020
@@ -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;