Module Name: src
Committed By: ad
Date: Sat Mar 14 18:08:40 UTC 2020
Modified Files:
src/sys/arch/arm/arm32: bus_dma.c
src/sys/arch/mips/mips: bus_dma.c
src/sys/arch/x86/x86: bus_dma.c
src/sys/compat/linux/common: linux_futex.c
src/sys/dev/nvmm/x86: nvmm_x86_svm.c nvmm_x86_vmx.c
src/sys/dev/pci/qat: qatvar.h
src/sys/external/bsd/drm2/include/linux: sched.h
src/sys/kern: kern_ktrace.c kern_synch.c subr_copy.c vfs_bio.c
src/sys/miscfs/genfs: genfs_io.c
src/sys/nfs: nfs_syscalls.c
src/sys/rump/librump/rumpkern: scheduler.c
src/sys/sys: sched.h
src/sys/ufs/ext2fs: ext2fs_lookup.c
src/sys/ufs/lfs: ulfs_dirhash.c ulfs_lookup.c
src/sys/ufs/ufs: ufs_dirhash.c ufs_lookup.c
src/sys/uvm: uvm_amap.c
Log Message:
- Hide the details of SPCF_SHOULDYIELD and related behind a couple of small
functions: preempt_point() and preempt_needed().
- preempt(): if the LWP has exceeded its timeslice in kernel, strip it of
any priority boost gained earlier from blocking.
To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/sys/arch/arm/arm32/bus_dma.c
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/mips/mips/bus_dma.c
cvs rdiff -u -r1.81 -r1.82 src/sys/arch/x86/x86/bus_dma.c
cvs rdiff -u -r1.37 -r1.38 src/sys/compat/linux/common/linux_futex.c
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/nvmm/x86/nvmm_x86_svm.c
cvs rdiff -u -r1.50 -r1.51 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/pci/qat/qatvar.h
cvs rdiff -u -r1.13 -r1.14 src/sys/external/bsd/drm2/include/linux/sched.h
cvs rdiff -u -r1.175 -r1.176 src/sys/kern/kern_ktrace.c
cvs rdiff -u -r1.342 -r1.343 src/sys/kern/kern_synch.c
cvs rdiff -u -r1.12 -r1.13 src/sys/kern/subr_copy.c
cvs rdiff -u -r1.289 -r1.290 src/sys/kern/vfs_bio.c
cvs rdiff -u -r1.89 -r1.90 src/sys/miscfs/genfs/genfs_io.c
cvs rdiff -u -r1.161 -r1.162 src/sys/nfs/nfs_syscalls.c
cvs rdiff -u -r1.50 -r1.51 src/sys/rump/librump/rumpkern/scheduler.c
cvs rdiff -u -r1.87 -r1.88 src/sys/sys/sched.h
cvs rdiff -u -r1.88 -r1.89 src/sys/ufs/ext2fs/ext2fs_lookup.c
cvs rdiff -u -r1.17 -r1.18 src/sys/ufs/lfs/ulfs_dirhash.c
cvs rdiff -u -r1.41 -r1.42 src/sys/ufs/lfs/ulfs_lookup.c
cvs rdiff -u -r1.38 -r1.39 src/sys/ufs/ufs/ufs_dirhash.c
cvs rdiff -u -r1.150 -r1.151 src/sys/ufs/ufs/ufs_lookup.c
cvs rdiff -u -r1.116 -r1.117 src/sys/uvm/uvm_amap.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/arm/arm32/bus_dma.c
diff -u src/sys/arch/arm/arm32/bus_dma.c:1.120 src/sys/arch/arm/arm32/bus_dma.c:1.121
--- src/sys/arch/arm/arm32/bus_dma.c:1.120 Sat Feb 22 08:22:09 2020
+++ src/sys/arch/arm/arm32/bus_dma.c Sat Mar 14 18:08:38 2020
@@ -1,7 +1,7 @@
-/* $NetBSD: bus_dma.c,v 1.120 2020/02/22 08:22:09 skrll Exp $ */
+/* $NetBSD: bus_dma.c,v 1.121 2020/03/14 18:08:38 ad Exp $ */
/*-
- * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996, 1997, 1998, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -36,7 +36,7 @@
#include "opt_cputypes.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.120 2020/02/22 08:22:09 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.121 2020/03/14 18:08:38 ad Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -1790,10 +1790,8 @@ _bus_dma_uiomove(void *buf, struct uio *
continue;
cnt = MIN(resid, iov->iov_len);
- if (!VMSPACE_IS_KERNEL_P(vm) &&
- (curlwp->l_cpu->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
- != 0) {
- preempt();
+ if (!VMSPACE_IS_KERNEL_P(vm)) {
+ preempt_point();
}
if (direction == UIO_READ) {
error = copyout_vmspace(vm, cp, iov->iov_base, cnt);
Index: src/sys/arch/mips/mips/bus_dma.c
diff -u src/sys/arch/mips/mips/bus_dma.c:1.39 src/sys/arch/mips/mips/bus_dma.c:1.40
--- src/sys/arch/mips/mips/bus_dma.c:1.39 Fri Mar 13 03:49:39 2020
+++ src/sys/arch/mips/mips/bus_dma.c Sat Mar 14 18:08:38 2020
@@ -1,7 +1,7 @@
-/* $NetBSD: bus_dma.c,v 1.39 2020/03/13 03:49:39 thorpej Exp $ */
+/* $NetBSD: bus_dma.c,v 1.40 2020/03/14 18:08:38 ad Exp $ */
/*-
- * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997, 1998, 2001, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -32,7 +32,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.39 2020/03/13 03:49:39 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.40 2020/03/14 18:08:38 ad Exp $");
#define _MIPS_BUS_DMA_PRIVATE
@@ -1291,10 +1291,8 @@ _bus_dma_uiomove(void *buf, struct uio *
continue;
cnt = MIN(resid, iov->iov_len);
- if (!VMSPACE_IS_KERNEL_P(vm) &&
- (curlwp->l_cpu->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
- != 0) {
- preempt();
+ if (!VMSPACE_IS_KERNEL_P(vm)) {
+ preempt_point();
}
if (direction == UIO_READ) {
error = copyout_vmspace(vm, cp, iov->iov_base, cnt);
Index: src/sys/arch/x86/x86/bus_dma.c
diff -u src/sys/arch/x86/x86/bus_dma.c:1.81 src/sys/arch/x86/x86/bus_dma.c:1.82
--- src/sys/arch/x86/x86/bus_dma.c:1.81 Thu Nov 14 16:23:52 2019
+++ src/sys/arch/x86/x86/bus_dma.c Sat Mar 14 18:08:38 2020
@@ -1,7 +1,7 @@
-/* $NetBSD: bus_dma.c,v 1.81 2019/11/14 16:23:52 maxv Exp $ */
+/* $NetBSD: bus_dma.c,v 1.82 2020/03/14 18:08:38 ad Exp $ */
/*-
- * Copyright (c) 1996, 1997, 1998, 2007 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996, 1997, 1998, 2007, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.81 2019/11/14 16:23:52 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.82 2020/03/14 18:08:38 ad Exp $");
/*
* The following is included because _bus_dma_uiomove is derived from
@@ -1064,10 +1064,8 @@ _bus_dma_uiomove(void *buf, struct uio *
continue;
cnt = MIN(resid, iov->iov_len);
- if (!VMSPACE_IS_KERNEL_P(vm) &&
- (curlwp->l_cpu->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
- != 0) {
- preempt();
+ if (!VMSPACE_IS_KERNEL_P(vm)) {
+ preempt_point();
}
if (direction == UIO_READ) {
error = copyout_vmspace(vm, cp, iov->iov_base, cnt);
Index: src/sys/compat/linux/common/linux_futex.c
diff -u src/sys/compat/linux/common/linux_futex.c:1.37 src/sys/compat/linux/common/linux_futex.c:1.38
--- src/sys/compat/linux/common/linux_futex.c:1.37 Mon Apr 10 15:04:32 2017
+++ src/sys/compat/linux/common/linux_futex.c Sat Mar 14 18:08:38 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_futex.c,v 1.37 2017/04/10 15:04:32 dholland Exp $ */
+/* $NetBSD: linux_futex.c,v 1.38 2020/03/14 18:08:38 ad Exp $ */
/*-
* Copyright (c) 2005 Emmanuel Dreyfus, all rights reserved.
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: linux_futex.c,v 1.37 2017/04/10 15:04:32 dholland Exp $");
+__KERNEL_RCSID(1, "$NetBSD: linux_futex.c,v 1.38 2020/03/14 18:08:38 ad Exp $");
#include <sys/param.h>
#include <sys/time.h>
@@ -45,6 +45,7 @@ __KERNEL_RCSID(1, "$NetBSD: linux_futex.
#include <sys/kmem.h>
#include <sys/kernel.h>
#include <sys/atomic.h>
+#include <sys/sched.h>
#include <compat/linux/common/linux_types.h>
#include <compat/linux/common/linux_emuldata.h>
@@ -801,7 +802,7 @@ release_futexes(struct lwp *l)
if (!--limit)
break;
- yield(); /* XXX why? */
+ preempt_point();
}
if (pending)
Index: src/sys/dev/nvmm/x86/nvmm_x86_svm.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.56 src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.57
--- src/sys/dev/nvmm/x86/nvmm_x86_svm.c:1.56 Fri Feb 21 00:26:22 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86_svm.c Sat Mar 14 18:08:39 2020
@@ -1,7 +1,7 @@
-/* $NetBSD: nvmm_x86_svm.c,v 1.56 2020/02/21 00:26:22 joerg Exp $ */
+/* $NetBSD: nvmm_x86_svm.c,v 1.57 2020/03/14 18:08:39 ad Exp $ */
/*
- * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
+ * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.56 2020/02/21 00:26:22 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.57 2020/03/14 18:08:39 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1441,10 +1441,7 @@ svm_vcpu_run(struct nvmm_machine *mach,
}
/* If no reason to return to userland, keep rolling. */
- if (curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD) {
- break;
- }
- if (curcpu()->ci_data.cpu_softints != 0) {
+ if (preempt_needed()) {
break;
}
if (curlwp->l_flag & LW_USERRET) {
Index: src/sys/dev/nvmm/x86/nvmm_x86_vmx.c
diff -u src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.50 src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.51
--- src/sys/dev/nvmm/x86/nvmm_x86_vmx.c:1.50 Thu Mar 12 13:01:59 2020
+++ src/sys/dev/nvmm/x86/nvmm_x86_vmx.c Sat Mar 14 18:08:39 2020
@@ -1,7 +1,7 @@
-/* $NetBSD: nvmm_x86_vmx.c,v 1.50 2020/03/12 13:01:59 tnn Exp $ */
+/* $NetBSD: nvmm_x86_vmx.c,v 1.51 2020/03/14 18:08:39 ad Exp $ */
/*
- * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
+ * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.50 2020/03/12 13:01:59 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_vmx.c,v 1.51 2020/03/14 18:08:39 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -2063,10 +2063,7 @@ vmx_vcpu_run(struct nvmm_machine *mach,
}
/* If no reason to return to userland, keep rolling. */
- if (curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD) {
- break;
- }
- if (curcpu()->ci_data.cpu_softints != 0) {
+ if (preempt_needed()) {
break;
}
if (curlwp->l_flag & LW_USERRET) {
Index: src/sys/dev/pci/qat/qatvar.h
diff -u src/sys/dev/pci/qat/qatvar.h:1.1 src/sys/dev/pci/qat/qatvar.h:1.2
--- src/sys/dev/pci/qat/qatvar.h:1.1 Wed Nov 20 09:37:46 2019
+++ src/sys/dev/pci/qat/qatvar.h Sat Mar 14 18:08:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: qatvar.h,v 1.1 2019/11/20 09:37:46 hikaru Exp $ */
+/* $NetBSD: qatvar.h,v 1.2 2020/03/14 18:08:39 ad Exp $ */
/*
* Copyright (c) 2019 Internet Initiative Japan, Inc.
@@ -889,7 +889,7 @@ struct qat_softc {
* and the configroot threads, which is running for qat_init(),
* takes kernel_lock and the uvm_scheduler is not working at that point.
*/
-#define QAT_YIELD() yield()
+#define QAT_YIELD() preempt_point()
extern int qat_dump;
Index: src/sys/external/bsd/drm2/include/linux/sched.h
diff -u src/sys/external/bsd/drm2/include/linux/sched.h:1.13 src/sys/external/bsd/drm2/include/linux/sched.h:1.14
--- src/sys/external/bsd/drm2/include/linux/sched.h:1.13 Sat Sep 28 15:13:08 2019
+++ src/sys/external/bsd/drm2/include/linux/sched.h Sat Mar 14 18:08:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sched.h,v 1.13 2019/09/28 15:13:08 christos Exp $ */
+/* $NetBSD: sched.h,v 1.14 2020/03/14 18:08:39 ad Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -87,8 +87,7 @@ static inline void
cond_resched(void)
{
- if (curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
- preempt();
+ preempt_point();
}
#endif /* _LINUX_SCHED_H_ */
Index: src/sys/kern/kern_ktrace.c
diff -u src/sys/kern/kern_ktrace.c:1.175 src/sys/kern/kern_ktrace.c:1.176
--- src/sys/kern/kern_ktrace.c:1.175 Fri Feb 21 00:26:22 2020
+++ src/sys/kern/kern_ktrace.c Sat Mar 14 18:08:39 2020
@@ -1,7 +1,7 @@
-/* $NetBSD: kern_ktrace.c,v 1.175 2020/02/21 00:26:22 joerg Exp $ */
+/* $NetBSD: kern_ktrace.c,v 1.176 2020/03/14 18:08:39 ad Exp $ */
/*-
- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.175 2020/02/21 00:26:22 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.176 2020/03/14 18:08:39 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -720,7 +720,7 @@ ktr_io(lwp_t *l, int fd, enum uio_rw rw,
*/
ktraddentry(l, kte, KTA_WAITOK | KTA_LARGE);
if (resid > 0) {
- if (curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD) {
+ if (preempt_needed()) {
(void)ktrenter(l);
preempt();
ktrexit(l);
Index: src/sys/kern/kern_synch.c
diff -u src/sys/kern/kern_synch.c:1.342 src/sys/kern/kern_synch.c:1.343
--- src/sys/kern/kern_synch.c:1.342 Sun Feb 23 16:27:09 2020
+++ src/sys/kern/kern_synch.c Sat Mar 14 18:08:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_synch.c,v 1.342 2020/02/23 16:27:09 ad Exp $ */
+/* $NetBSD: kern_synch.c,v 1.343 2020/03/14 18:08:39 ad Exp $ */
/*-
* Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009, 2019, 2020
@@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.342 2020/02/23 16:27:09 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.343 2020/03/14 18:08:39 ad Exp $");
#include "opt_kstack.h"
#include "opt_dtrace.h"
@@ -306,8 +306,7 @@ wakeup(wchan_t ident)
/*
* General yield call. Puts the current LWP back on its run queue and
- * performs a voluntary context switch. Should only be called when the
- * current LWP explicitly requests it (eg sched_yield(2)).
+ * performs a context switch.
*/
void
yield(void)
@@ -329,7 +328,12 @@ yield(void)
/*
* General preemption call. Puts the current LWP back on its run queue
- * and performs an involuntary context switch.
+ * and performs an involuntary context switch. Different from yield()
+ * in that:
+ *
+ * - It's counted differently (involuntary vs. voluntary).
+ * - Realtime threads go to the head of their runqueue vs. tail for yield().
+ * - Priority boost is retained unless LWP has exceeded timeslice.
*/
void
preempt(void)
@@ -342,14 +346,57 @@ preempt(void)
KASSERT(lwp_locked(l, l->l_cpu->ci_schedstate.spc_lwplock));
KASSERT(l->l_stat == LSONPROC);
- /* Involuntary - keep kpriority boost. */
- l->l_pflag |= LP_PREEMPTING;
spc_lock(l->l_cpu);
+ /* Involuntary - keep kpriority boost unless a CPU hog. */
+ if ((l->l_cpu->ci_schedstate.spc_flags & SPCF_SHOULDYIELD) != 0) {
+ l->l_kpriority = false;
+ }
+ l->l_pflag |= LP_PREEMPTING;
mi_switch(l);
KERNEL_LOCK(l->l_biglocks, l);
}
/*
+ * A breathing point for long running code in kernel.
+ */
+void
+preempt_point(void)
+{
+ lwp_t *l = curlwp;
+ int needed;
+
+ KPREEMPT_DISABLE(l);
+ needed = l->l_cpu->ci_schedstate.spc_flags & SPCF_SHOULDYIELD;
+#ifndef __HAVE_FAST_SOFTINTS
+ needed |= l->l_cpu->ci_data.cpu_softints;
+#endif
+ KPREEMPT_ENABLE(l);
+
+ if (__predict_false(needed)) {
+ preempt();
+ }
+}
+
+/*
+ * Check the SPCF_SHOULDYIELD flag.
+ */
+bool
+preempt_needed(void)
+{
+ lwp_t *l = curlwp;
+ int needed;
+
+ KPREEMPT_DISABLE(l);
+ needed = l->l_cpu->ci_schedstate.spc_flags & SPCF_SHOULDYIELD;
+#ifndef __HAVE_FAST_SOFTINTS
+ needed |= l->l_cpu->ci_data.cpu_softints;
+#endif
+ KPREEMPT_ENABLE(l);
+
+ return (bool)needed;
+}
+
+/*
* Handle a request made by another agent to preempt the current LWP
* in-kernel. Usually called when l_dopreempt may be non-zero.
*
Index: src/sys/kern/subr_copy.c
diff -u src/sys/kern/subr_copy.c:1.12 src/sys/kern/subr_copy.c:1.13
--- src/sys/kern/subr_copy.c:1.12 Sat Feb 22 21:59:30 2020
+++ src/sys/kern/subr_copy.c Sat Mar 14 18:08:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_copy.c,v 1.12 2020/02/22 21:59:30 chs Exp $ */
+/* $NetBSD: subr_copy.c,v 1.13 2020/03/14 18:08:39 ad Exp $ */
/*-
* Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008, 2019
@@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_copy.c,v 1.12 2020/02/22 21:59:30 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_copy.c,v 1.13 2020/03/14 18:08:39 ad Exp $");
#define __UFETCHSTORE_PRIVATE
#define __UCAS_PRIVATE
@@ -123,9 +123,7 @@ uiomove(void *buf, size_t n, struct uio
if (cnt > n)
cnt = n;
if (!VMSPACE_IS_KERNEL_P(vm)) {
- if (curcpu()->ci_schedstate.spc_flags &
- SPCF_SHOULDYIELD)
- preempt();
+ preempt_point();
}
if (uio->uio_rw == UIO_READ) {
Index: src/sys/kern/vfs_bio.c
diff -u src/sys/kern/vfs_bio.c:1.289 src/sys/kern/vfs_bio.c:1.290
--- src/sys/kern/vfs_bio.c:1.289 Fri Feb 21 02:04:40 2020
+++ src/sys/kern/vfs_bio.c Sat Mar 14 18:08:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_bio.c,v 1.289 2020/02/21 02:04:40 riastradh Exp $ */
+/* $NetBSD: vfs_bio.c,v 1.290 2020/03/14 18:08:39 ad Exp $ */
/*-
* Copyright (c) 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -123,7 +123,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.289 2020/02/21 02:04:40 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.290 2020/03/14 18:08:39 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_bufcache.h"
@@ -1378,8 +1378,7 @@ allocbuf(buf_t *bp, int size, int preser
* Need to trim overall memory usage.
*/
while (buf_canrelease()) {
- if (curcpu()->ci_schedstate.spc_flags &
- SPCF_SHOULDYIELD) {
+ if (preempt_needed()) {
mutex_exit(&bufcache_lock);
preempt();
mutex_enter(&bufcache_lock);
Index: src/sys/miscfs/genfs/genfs_io.c
diff -u src/sys/miscfs/genfs/genfs_io.c:1.89 src/sys/miscfs/genfs/genfs_io.c:1.90
--- src/sys/miscfs/genfs/genfs_io.c:1.89 Sat Mar 14 15:34:24 2020
+++ src/sys/miscfs/genfs/genfs_io.c Sat Mar 14 18:08:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: genfs_io.c,v 1.89 2020/03/14 15:34:24 ad Exp $ */
+/* $NetBSD: genfs_io.c,v 1.90 2020/03/14 18:08:39 ad Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.89 2020/03/14 15:34:24 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.90 2020/03/14 18:08:39 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1047,8 +1047,7 @@ retry:
* a preempt point.
*/
- if ((l->l_cpu->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
- != 0) {
+ if (preempt_needed()) {
nextoff = pg->offset; /* visit this page again */
rw_exit(slock);
preempt();
Index: src/sys/nfs/nfs_syscalls.c
diff -u src/sys/nfs/nfs_syscalls.c:1.161 src/sys/nfs/nfs_syscalls.c:1.162
--- src/sys/nfs/nfs_syscalls.c:1.161 Sun Feb 3 03:19:28 2019
+++ src/sys/nfs/nfs_syscalls.c Sat Mar 14 18:08:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: nfs_syscalls.c,v 1.161 2019/02/03 03:19:28 mrg Exp $ */
+/* $NetBSD: nfs_syscalls.c,v 1.162 2020/03/14 18:08:39 ad Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_syscalls.c,v 1.161 2019/02/03 03:19:28 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_syscalls.c,v 1.162 2020/03/14 18:08:39 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -635,10 +635,8 @@ nfssvc_nfsd(struct nfssvc_copy_ops *ops,
for (;;) {
bool dummy;
- if ((curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
- != 0) {
- preempt();
- }
+ preempt_point();
+
if (nfsd->nfsd_slp == NULL) {
mutex_enter(&nfsd_lock);
while (nfsd->nfsd_slp == NULL &&
Index: src/sys/rump/librump/rumpkern/scheduler.c
diff -u src/sys/rump/librump/rumpkern/scheduler.c:1.50 src/sys/rump/librump/rumpkern/scheduler.c:1.51
--- src/sys/rump/librump/rumpkern/scheduler.c:1.50 Sat Feb 15 18:12:15 2020
+++ src/sys/rump/librump/rumpkern/scheduler.c Sat Mar 14 18:08:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: scheduler.c,v 1.50 2020/02/15 18:12:15 ad Exp $ */
+/* $NetBSD: scheduler.c,v 1.51 2020/03/14 18:08:39 ad Exp $ */
/*
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.50 2020/02/15 18:12:15 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.51 2020/03/14 18:08:39 ad Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@@ -597,3 +597,16 @@ sched_dequeue(struct lwp *l)
panic("sched_dequeue not implemented");
}
+
+void
+preempt_point(void)
+{
+
+}
+
+bool
+preempt_needed(void)
+{
+
+ return false;
+}
Index: src/sys/sys/sched.h
diff -u src/sys/sys/sched.h:1.87 src/sys/sys/sched.h:1.88
--- src/sys/sys/sched.h:1.87 Sun Jan 12 22:03:23 2020
+++ src/sys/sys/sched.h Sat Mar 14 18:08:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sched.h,v 1.87 2020/01/12 22:03:23 ad Exp $ */
+/* $NetBSD: sched.h,v 1.88 2020/03/14 18:08:39 ad Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2007, 2008, 2019, 2020
@@ -268,6 +268,8 @@ void sched_print_runqueue(void (*pr)(co
/* Dispatching */
bool kpreempt(uintptr_t);
void preempt(void);
+bool preempt_needed(void);
+void preempt_point(void);
void yield(void);
void mi_switch(struct lwp *);
void updatertime(lwp_t *, const struct bintime *);
Index: src/sys/ufs/ext2fs/ext2fs_lookup.c
diff -u src/sys/ufs/ext2fs/ext2fs_lookup.c:1.88 src/sys/ufs/ext2fs/ext2fs_lookup.c:1.89
--- src/sys/ufs/ext2fs/ext2fs_lookup.c:1.88 Tue Aug 23 06:40:25 2016
+++ src/sys/ufs/ext2fs/ext2fs_lookup.c Sat Mar 14 18:08:40 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ext2fs_lookup.c,v 1.88 2016/08/23 06:40:25 christos Exp $ */
+/* $NetBSD: ext2fs_lookup.c,v 1.89 2020/03/14 18:08:40 ad Exp $ */
/*
* Modified for NetBSD 1.2E
@@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ext2fs_lookup.c,v 1.88 2016/08/23 06:40:25 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ext2fs_lookup.c,v 1.89 2020/03/14 18:08:40 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -418,8 +418,8 @@ ext2fs_lookup(void *v)
searchloop:
while (results->ulr_offset < endsearch) {
- if (curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
- preempt();
+ preempt_point();
+
/*
* If necessary, get the next directory block.
*/
Index: src/sys/ufs/lfs/ulfs_dirhash.c
diff -u src/sys/ufs/lfs/ulfs_dirhash.c:1.17 src/sys/ufs/lfs/ulfs_dirhash.c:1.18
--- src/sys/ufs/lfs/ulfs_dirhash.c:1.17 Mon Jun 20 01:53:38 2016
+++ src/sys/ufs/lfs/ulfs_dirhash.c Sat Mar 14 18:08:40 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ulfs_dirhash.c,v 1.17 2016/06/20 01:53:38 dholland Exp $ */
+/* $NetBSD: ulfs_dirhash.c,v 1.18 2020/03/14 18:08:40 ad Exp $ */
/* from NetBSD: ufs_dirhash.c,v 1.37 2014/12/20 00:28:05 christos Exp */
/*
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ulfs_dirhash.c,v 1.17 2016/06/20 01:53:38 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ulfs_dirhash.c,v 1.18 2020/03/14 18:08:40 ad Exp $");
/*
* This implements a hash-based lookup scheme for ULFS directories.
@@ -214,10 +214,8 @@ ulfsdirhash_build(struct inode *ip)
bmask = VFSTOULFS(vp->v_mount)->um_mountp->mnt_stat.f_iosize - 1;
pos = 0;
while (pos < ip->i_size) {
- if ((curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
- != 0) {
- preempt();
- }
+ preempt_point();
+
/* If necessary, get the next directory block. */
if ((pos & bmask) == 0) {
if (bp != NULL)
Index: src/sys/ufs/lfs/ulfs_lookup.c
diff -u src/sys/ufs/lfs/ulfs_lookup.c:1.41 src/sys/ufs/lfs/ulfs_lookup.c:1.42
--- src/sys/ufs/lfs/ulfs_lookup.c:1.41 Sat Jun 10 05:29:36 2017
+++ src/sys/ufs/lfs/ulfs_lookup.c Sat Mar 14 18:08:40 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ulfs_lookup.c,v 1.41 2017/06/10 05:29:36 maya Exp $ */
+/* $NetBSD: ulfs_lookup.c,v 1.42 2020/03/14 18:08:40 ad Exp $ */
/* from NetBSD: ufs_lookup.c,v 1.135 2015/07/11 11:04:48 mlelstv */
/*
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ulfs_lookup.c,v 1.41 2017/06/10 05:29:36 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ulfs_lookup.c,v 1.42 2020/03/14 18:08:40 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_lfs.h"
@@ -292,8 +292,8 @@ ulfs_lookup(void *v)
searchloop:
while (results->ulr_offset < endsearch) {
- if (curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
- preempt();
+ preempt_point();
+
/*
* If necessary, get the next directory block.
*/
Index: src/sys/ufs/ufs/ufs_dirhash.c
diff -u src/sys/ufs/ufs/ufs_dirhash.c:1.38 src/sys/ufs/ufs/ufs_dirhash.c:1.39
--- src/sys/ufs/ufs/ufs_dirhash.c:1.38 Sun Mar 8 00:23:59 2020
+++ src/sys/ufs/ufs/ufs_dirhash.c Sat Mar 14 18:08:40 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_dirhash.c,v 1.38 2020/03/08 00:23:59 chs Exp $ */
+/* $NetBSD: ufs_dirhash.c,v 1.39 2020/03/14 18:08:40 ad Exp $ */
/*
* Copyright (c) 2001, 2002 Ian Dowse. All rights reserved.
@@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_dirhash.c,v 1.38 2020/03/08 00:23:59 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_dirhash.c,v 1.39 2020/03/14 18:08:40 ad Exp $");
/*
* This implements a hash-based lookup scheme for UFS directories.
@@ -212,10 +212,8 @@ ufsdirhash_build(struct inode *ip)
bmask = VFSTOUFS(vp->v_mount)->um_mountp->mnt_stat.f_iosize - 1;
pos = 0;
while (pos < ip->i_size) {
- if ((curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
- != 0) {
- preempt();
- }
+ preempt_point();
+
/* If necessary, get the next directory block. */
if ((pos & bmask) == 0) {
if (bp != NULL)
Index: src/sys/ufs/ufs/ufs_lookup.c
diff -u src/sys/ufs/ufs/ufs_lookup.c:1.150 src/sys/ufs/ufs/ufs_lookup.c:1.151
--- src/sys/ufs/ufs/ufs_lookup.c:1.150 Sun May 5 15:07:12 2019
+++ src/sys/ufs/ufs/ufs_lookup.c Sat Mar 14 18:08:40 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_lookup.c,v 1.150 2019/05/05 15:07:12 christos Exp $ */
+/* $NetBSD: ufs_lookup.c,v 1.151 2020/03/14 18:08:40 ad Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.150 2019/05/05 15:07:12 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_lookup.c,v 1.151 2020/03/14 18:08:40 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_ffs.h"
@@ -453,8 +453,8 @@ ufs_lookup(void *v)
searchloop:
while (results->ulr_offset < endsearch) {
- if (curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
- preempt();
+ preempt_point();
+
/*
* If necessary, get the next directory block.
*/
Index: src/sys/uvm/uvm_amap.c
diff -u src/sys/uvm/uvm_amap.c:1.116 src/sys/uvm/uvm_amap.c:1.117
--- src/sys/uvm/uvm_amap.c:1.116 Mon Feb 24 12:38:57 2020
+++ src/sys/uvm/uvm_amap.c Sat Mar 14 18:08:40 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_amap.c,v 1.116 2020/02/24 12:38:57 rin Exp $ */
+/* $NetBSD: uvm_amap.c,v 1.117 2020/03/14 18:08:40 ad Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.116 2020/02/24 12:38:57 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_amap.c,v 1.117 2020/03/14 18:08:40 ad Exp $");
#include "opt_uvmhist.h"
@@ -764,8 +764,8 @@ amap_wipeout(struct vm_amap *amap)
anon->an_link = tofree;
tofree = anon;
}
- if (curlwp->l_cpu->ci_schedstate.spc_flags & SPCF_SHOULDYIELD) {
- preempt();
+ if ((lcv & 31) == 31) {
+ preempt_point();
}
}