Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch cpu_need_resched():
details: https://anonhg.NetBSD.org/src/rev/0d4a8e253469
branches: trunk
changeset: 461343:0d4a8e253469
user: ad <ad%NetBSD.org@localhost>
date: Sat Nov 23 19:40:34 2019 +0000
description:
cpu_need_resched():
- Remove all code that should be MI, leaving the bare minimum under arch/.
- Make the required actions very explicit.
- Pass in LWP pointer for convenience.
- When a trap is required on another CPU, have the IPI set it locally.
- Expunge cpu_did_resched().
diffstat:
sys/arch/aarch64/aarch64/cpu_machdep.c | 58 +++++--------------------
sys/arch/alpha/alpha/machdep.c | 22 +++-----
sys/arch/amiga/include/cpu.h | 5 +-
sys/arch/arm/arm/arm_machdep.c | 65 ++++++----------------------
sys/arch/arm/arm32/genassym.cf | 3 +-
sys/arch/atari/include/cpu.h | 5 +-
sys/arch/cesfic/include/cpu.h | 5 +-
sys/arch/evbcf/include/cpu.h | 6 +-
sys/arch/hp300/include/cpu.h | 5 +-
sys/arch/hppa/hppa/hppa_machdep.c | 24 +++------
sys/arch/ia64/include/cpu.h | 6 +-
sys/arch/luna68k/include/cpu.h | 5 +-
sys/arch/mac68k/include/cpu.h | 5 +-
sys/arch/mips/mips/cpu_subr.c | 68 ++++++++---------------------
sys/arch/mips/mips/ipifuncs.c | 12 +++-
sys/arch/mvme68k/include/cpu.h | 5 +-
sys/arch/news68k/include/cpu.h | 5 +-
sys/arch/next68k/include/cpu.h | 5 +-
sys/arch/powerpc/booke/e500_intr.c | 11 +++-
sys/arch/powerpc/include/booke/intr.h | 3 +-
sys/arch/powerpc/include/cpu.h | 4 +-
sys/arch/powerpc/powerpc/genassym.cf | 3 +-
sys/arch/powerpc/powerpc/powerpc_machdep.c | 65 ++++++++--------------------
sys/arch/riscv/riscv/genassym.cf | 3 +-
sys/arch/riscv/riscv/riscv_machdep.c | 66 +++++++---------------------
sys/arch/sh3/include/cpu.h | 10 +--
sys/arch/sparc/include/cpu.h | 7 +-
sys/arch/sparc64/include/cpu.h | 3 +-
sys/arch/sparc64/sparc64/genassym.cf | 3 +-
sys/arch/sparc64/sparc64/machdep.c | 20 +++----
sys/arch/sun68k/include/cpu.h | 3 +-
sys/arch/usermode/dev/cpu.c | 7 +-
sys/arch/usermode/include/cpu.h | 3 +-
sys/arch/vax/include/cpu.h | 5 +-
sys/arch/x68k/include/cpu.h | 5 +-
sys/arch/x86/include/cpu.h | 8 +--
sys/arch/x86/include/intrdefs.h | 6 +-
sys/arch/x86/x86/cpu.c | 9 ++-
sys/arch/x86/x86/ipi.c | 46 ++++++++++++++------
sys/arch/x86/x86/x86_machdep.c | 62 ++++++++++-----------------
sys/arch/xen/include/intrdefs.h | 5 +-
sys/arch/xen/x86/cpu.c | 8 +-
sys/arch/xen/x86/xen_ipi.c | 21 +++++++--
43 files changed, 263 insertions(+), 432 deletions(-)
diffs (truncated from 1697 to 300 lines):
diff -r eadf40ff994f -r 0d4a8e253469 sys/arch/aarch64/aarch64/cpu_machdep.c
--- a/sys/arch/aarch64/aarch64/cpu_machdep.c Sat Nov 23 18:57:36 2019 +0000
+++ b/sys/arch/aarch64/aarch64/cpu_machdep.c Sat Nov 23 19:40:34 2019 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: cpu_machdep.c,v 1.7 2019/11/21 19:57:23 ad Exp $ */
+/* $NetBSD: cpu_machdep.c,v 1.8 2019/11/23 19:40:34 ad Exp $ */
/*-
- * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * Copyright (c) 2014, 2019 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(1, "$NetBSD: cpu_machdep.c,v 1.7 2019/11/21 19:57:23 ad Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu_machdep.c,v 1.8 2019/11/23 19:40:34 ad Exp $");
#include "opt_multiprocessor.h"
@@ -124,7 +124,8 @@
if (softints == 0) {
#ifdef __HAVE_PREEMPTION
if (ci->ci_want_resched & RESCHED_KPREEMPT) {
- ci->ci_want_resched &= ~RESCHED_KPREEMPT;
+ atomic_and_uint(&ci->ci_want_resched,
+ ~RESCHED_KPREEMPT);
splsched();
kpreempt(-2);
}
@@ -233,60 +234,25 @@
}
void
-cpu_need_resched(struct cpu_info *ci, int flags)
+cpu_need_resched(struct cpu_info *ci, struct lwp *l, int flags)
{
- struct lwp * const l = ci->ci_data.cpu_onproc;
-#ifdef MULTIPROCESSOR
- struct cpu_info * const cur_ci = curcpu();
-#endif
-
KASSERT(kpreempt_disabled());
- ci->ci_want_resched |= flags;
-
- if (__predict_false((l->l_pflag & LP_INTR) != 0)) {
- /*
- * No point doing anything, it will switch soon.
- * Also here to prevent an assertion failure in
- * kpreempt() due to preemption being set on a
- * soft interrupt LWP.
- */
- return;
- }
-
- if (__predict_false(l == ci->ci_data.cpu_idlelwp)) {
-#ifdef MULTIPROCESSOR
- /*
- * If the other CPU is idling, it must be waiting for an
- * interrupt. So give it one.
- */
- if (__predict_false(ci != cur_ci))
- intr_ipi_send(ci->ci_kcpuset, IPI_NOP);
-#endif
- return;
- }
-
-#ifdef MULTIPROCESSOR
- atomic_or_uint(&ci->ci_want_resched, flags);
-#else
- ci->ci_want_resched |= flags;
-#endif
-
- if (flags & RESCHED_KPREEMPT) {
+ if ((flags & RESCHED_KPREEMPT) != 0) {
#ifdef __HAVE_PREEMPTION
- atomic_or_uint(&l->l_dopreempt, DOPREEMPT_ACTIVE);
- if (ci != cur_ci) {
+ if ((flags & RESCHED_REMOTE) != 0) {
intr_ipi_send(ci->ci_kcpuset, IPI_KPREEMPT);
}
#endif
return;
}
- setsoftast(ci); /* force call to ast() */
+ if ((flags & RESCHED_REMOTE) != 0) {
#ifdef MULTIPROCESSOR
- if (ci != cur_ci && (flags & RESCHED_IMMED)) {
intr_ipi_send(ci->ci_kcpuset, IPI_AST);
+#endif
+ } else {
+ setsoftast(ci); /* force call to ast() */
}
-#endif
}
void
diff -r eadf40ff994f -r 0d4a8e253469 sys/arch/alpha/alpha/machdep.c
--- a/sys/arch/alpha/alpha/machdep.c Sat Nov 23 18:57:36 2019 +0000
+++ b/sys/arch/alpha/alpha/machdep.c Sat Nov 23 19:40:34 2019 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: machdep.c,v 1.354 2019/04/05 14:12:14 thorpej Exp $ */
+/* $NetBSD: machdep.c,v 1.355 2019/11/23 19:40:34 ad Exp $ */
/*-
- * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 1999, 2000, 2019 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -67,7 +67,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.354 2019/04/05 14:12:14 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.355 2019/11/23 19:40:34 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1866,19 +1866,15 @@
* or after the current trap/syscall if in system mode.
*/
void
-cpu_need_resched(struct cpu_info *ci, int flags)
+cpu_need_resched(struct cpu_info *ci, struct lwp *l, int flags)
{
+ if ((flags & RESCHED_IDLE) == 0) {
+ if ((flags & RESCHED_REMOTE) != 0) {
#if defined(MULTIPROCESSOR)
- bool immed = (flags & RESCHED_IMMED) != 0;
+ alpha_send_ipi(ci->ci_cpuid, ALPHA_IPI_AST);
#endif /* defined(MULTIPROCESSOR) */
-
- aston(ci->ci_data.cpu_onproc);
- ci->ci_want_resched = 1;
- if (ci->ci_data.cpu_onproc != ci->ci_data.cpu_idlelwp) {
-#if defined(MULTIPROCESSOR)
- if (immed && ci != curcpu()) {
- alpha_send_ipi(ci->ci_cpuid, 0);
+ } else {
+ aston(l);
}
-#endif /* defined(MULTIPROCESSOR) */
}
}
diff -r eadf40ff994f -r 0d4a8e253469 sys/arch/amiga/include/cpu.h
--- a/sys/arch/amiga/include/cpu.h Sat Nov 23 18:57:36 2019 +0000
+++ b/sys/arch/amiga/include/cpu.h Sat Nov 23 19:40:34 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.82 2018/08/22 01:05:21 msaitoh Exp $ */
+/* $NetBSD: cpu.h,v 1.83 2019/11/23 19:40:34 ad Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@@ -77,9 +77,8 @@
* Preempt the current process if in interrupt from user mode,
* or after the current trap/syscall if in system mode.
*/
-#define cpu_need_resched(ci,flags) do { \
+#define cpu_need_resched(ci,l,flags) do { \
__USE(flags); \
- ci->ci_want_resched = 1; \
setsoftast(); \
} while (/*CONSTCOND*/0)
diff -r eadf40ff994f -r 0d4a8e253469 sys/arch/arm/arm/arm_machdep.c
--- a/sys/arch/arm/arm/arm_machdep.c Sat Nov 23 18:57:36 2019 +0000
+++ b/sys/arch/arm/arm/arm_machdep.c Sat Nov 23 19:40:34 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arm_machdep.c,v 1.55 2019/04/06 03:06:24 thorpej Exp $ */
+/* $NetBSD: arm_machdep.c,v 1.56 2019/11/23 19:40:34 ad Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
#include <sys/param.h>
-__KERNEL_RCSID(0, "$NetBSD: arm_machdep.c,v 1.55 2019/04/06 03:06:24 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm_machdep.c,v 1.56 2019/11/23 19:40:34 ad Exp $");
#include <sys/exec.h>
#include <sys/proc.h>
@@ -223,67 +223,38 @@
}
void
-cpu_need_resched(struct cpu_info *ci, int flags)
+cpu_need_resched(struct cpu_info *ci, struct lwp *l, int flags)
{
- struct lwp * const l = ci->ci_data.cpu_onproc;
- const bool immed = (flags & RESCHED_IMMED) != 0;
-#ifdef MULTIPROCESSOR
- struct cpu_info * const cur_ci = curcpu();
- u_long ipi = IPI_NOP;
-#endif
- if (__predict_false((l->l_pflag & LP_INTR) != 0)) {
- /*
- * No point doing anything, it will switch soon.
- * Also here to prevent an assertion failure in
- * kpreempt() due to preemption being set on a
- * soft interrupt LWP.
- */
- return;
- }
- if (ci->ci_want_resched && !immed)
- return;
-
- if (l == ci->ci_data.cpu_idlelwp) {
+ if (flags & RESCHED_IDLE) {
#ifdef MULTIPROCESSOR
/*
* If the other CPU is idling, it must be waiting for an
* event. So give it one.
*/
- if (ci != cur_ci)
- goto send_ipi;
+ if (flags & RESCHED_REMOTE) {
+ intr_ipi_send(ci->ci_kcpuset, IPI_NOP);
+ }
#endif
return;
}
-#ifdef MULTIPROCESSOR
- atomic_swap_uint(&ci->ci_want_resched, 1);
-#else
- ci->ci_want_resched = 1;
-#endif
if (flags & RESCHED_KPREEMPT) {
#ifdef __HAVE_PREEMPTION
- atomic_or_uint(&l->l_dopreempt, DOPREEMPT_ACTIVE);
- if (ci == cur_ci) {
+ if (flags & RESCHED_REMOTE) {
+ intr_ipi_send(ci->ci_kcpuset, IPI_KPREEMPT);
+ } else {
atomic_or_uint(&ci->ci_astpending, __BIT(1));
- } else {
- ipi = IPI_KPREEMPT;
- goto send_ipi;
}
#endif /* __HAVE_PREEMPTION */
return;
}
+ if (flags & RESCHED_REMOTE) {
#ifdef MULTIPROCESSOR
- if (ci == cur_ci || !immed) {
+ intr_ipi_send(ci->ci_kcpuset, IPI_AST);
+#endif /* MULTIPROCESSOR */
+ } else {
setsoftast(ci);
- return;
}
- ipi = IPI_AST;
-
- send_ipi:
- intr_ipi_send(ci->ci_kcpuset, ipi);
-#else
- setsoftast(ci);
-#endif /* MULTIPROCESSOR */
}
bool
@@ -312,14 +283,6 @@
#endif
#ifdef __HAVE_PREEMPTION
-void
-cpu_set_curpri(int pri)
-{
- kpreempt_disable();
- curcpu()->ci_schedstate.spc_curpriority = pri;
- kpreempt_enable();
-}
-
bool
cpu_kpreempt_enter(uintptr_t where, int s)
{
diff -r eadf40ff994f -r 0d4a8e253469 sys/arch/arm/arm32/genassym.cf
--- a/sys/arch/arm/arm32/genassym.cf Sat Nov 23 18:57:36 2019 +0000
+++ b/sys/arch/arm/arm32/genassym.cf Sat Nov 23 19:40:34 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.80 2018/10/18 09:01:52 skrll Exp $
+# $NetBSD: genassym.cf,v 1.81 2019/11/23 19:40:34 ad Exp $
# Copyright (c) 1982, 1990 The Regents of the University of California.
# All rights reserved.
@@ -225,7 +225,6 @@
define CI_CURLWP offsetof(struct cpu_info, ci_curlwp)
define CI_CPL offsetof(struct cpu_info, ci_cpl)
define CI_ASTPENDING offsetof(struct cpu_info, ci_astpending)
-define CI_WANT_RESCHED offsetof(struct cpu_info, ci_want_resched)
define CI_INTR_DEPTH offsetof(struct cpu_info, ci_intr_depth)
define CI_MTX_COUNT offsetof(struct cpu_info, ci_mtx_count)
define CI_UNDEFSAVE offsetof(struct cpu_info, ci_undefsave[0])
diff -r eadf40ff994f -r 0d4a8e253469 sys/arch/atari/include/cpu.h
--- a/sys/arch/atari/include/cpu.h Sat Nov 23 18:57:36 2019 +0000
Home |
Main Index |
Thread Index |
Old Index