From: art Date: Fri, 18 Jul 2008 23:43:31 +0000 (+0000) Subject: Add a macro that clears the want_resched flag that need_resched sets. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2c9d4ccbcf9b120efddf613d0ef0d6e5a35509ec;p=openbsd Add a macro that clears the want_resched flag that need_resched sets. Right now when mi_switch picks up the same proc, we didn't clear the flag which would mean that every time we service an AST we would attempt a context switch. For some architectures, amd64 being probably the most extreme, that meant attempting to context switch for every trap and interrupt. Now we clear_resched explicitly after every context switch, even if it didn't do anything. Which also allows us to remove some more code in cpu_switchto (not done yet). miod@ ok --- diff --git a/sys/arch/alpha/include/cpu.h b/sys/arch/alpha/include/cpu.h index 5937dbdd0d4..9e393ffc3d6 100644 --- a/sys/arch/alpha/include/cpu.h +++ b/sys/arch/alpha/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.32 2008/06/26 05:42:08 ray Exp $ */ +/* $OpenBSD: cpu.h,v 1.33 2008/07/18 23:43:31 art Exp $ */ /* $NetBSD: cpu.h,v 1.45 2000/08/21 02:03:12 thorpej Exp $ */ /*- @@ -282,12 +282,14 @@ do { \ ci->ci_want_resched = 1; \ aston(curcpu()); \ } while (/*CONSTCOND*/0) +#define clear_resched(ci) (ci)->ci_want_resched = 0 #else #define need_resched(ci) \ do { \ curcpu()->ci_want_resched = 1; \ aston(curcpu()); \ } while (/*CONSTCOND*/0) +#define clear_resched(ci) curcpu()->ci_want_resched = 0 #endif /* diff --git a/sys/arch/amd64/include/cpu.h b/sys/arch/amd64/include/cpu.h index 2516fdd256b..248a9659c6e 100644 --- a/sys/arch/amd64/include/cpu.h +++ b/sys/arch/amd64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.36 2008/06/10 02:55:39 weingart Exp $ */ +/* $OpenBSD: cpu.h,v 1.37 2008/07/18 23:43:31 art Exp $ */ /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */ /*- @@ -161,6 +161,7 @@ extern struct cpu_info *cpu_info_list; * or after the current trap/syscall if in system mode. */ extern void need_resched(struct cpu_info *); +#define clear_resched(ci) (ci)->ci_want_resched = 0 #if defined(MULTIPROCESSOR) diff --git a/sys/arch/arm/include/cpu.h b/sys/arch/arm/include/cpu.h index 9aa2166b1f2..0c418dcb21f 100644 --- a/sys/arch/arm/include/cpu.h +++ b/sys/arch/arm/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.18 2007/08/14 15:18:07 deraadt Exp $ */ +/* $OpenBSD: cpu.h,v 1.19 2008/07/18 23:43:31 art Exp $ */ /* $NetBSD: cpu.h,v 1.34 2003/06/23 11:01:08 martin Exp $ */ /* @@ -256,6 +256,7 @@ extern int astpending; */ extern int want_resched; /* resched() was called */ #define need_resched(ci) (want_resched = 1, setsoftast()) +#define clear_resched(ci) want_resched = 0 /* * Give a profiling tick to the current process when the user profiling diff --git a/sys/arch/hp300/include/cpu.h b/sys/arch/hp300/include/cpu.h index 76afb0a716c..a524d1cb618 100644 --- a/sys/arch/hp300/include/cpu.h +++ b/sys/arch/hp300/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.35 2007/11/02 19:18:54 martin Exp $ */ +/* $OpenBSD: cpu.h,v 1.36 2008/07/18 23:43:31 art Exp $ */ /* $NetBSD: cpu.h,v 1.28 1998/02/13 07:41:51 scottr Exp $ */ /* @@ -92,6 +92,7 @@ struct clockframe { */ extern int want_resched; /* resched() was called */ #define need_resched(ci) { want_resched = 1; aston(); } +#define clear_resched(ci) want_resched = 0 /* * Give a profiling tick to the current process when the user profiling diff --git a/sys/arch/hppa/include/cpu.h b/sys/arch/hppa/include/cpu.h index f4b45f47d30..d80bae1d2ed 100644 --- a/sys/arch/hppa/include/cpu.h +++ b/sys/arch/hppa/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.53 2008/07/14 13:39:06 miod Exp $ */ +/* $OpenBSD: cpu.h,v 1.54 2008/07/18 23:43:31 art Exp $ */ /* * Copyright (c) 2000-2004 Michael Shalayeff @@ -151,6 +151,7 @@ extern register_t kpsw; #define signotify(p) (setsoftast()) #define need_resched(ci) (want_resched = 1, setsoftast()) +#define clear_resched(ci) want_resched = 0 #define need_proftick(p) setsoftast() #define PROC_PC(p) ((p)->p_md.md_regs->tf_iioq_head) diff --git a/sys/arch/hppa64/include/cpu.h b/sys/arch/hppa64/include/cpu.h index ddc35e3be5b..b34705b425f 100644 --- a/sys/arch/hppa64/include/cpu.h +++ b/sys/arch/hppa64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.11 2007/05/16 19:37:06 thib Exp $ */ +/* $OpenBSD: cpu.h,v 1.12 2008/07/18 23:43:31 art Exp $ */ /* * Copyright (c) 2005 Michael Shalayeff @@ -196,6 +196,7 @@ extern int cpu_hvers; #define signotify(p) (setsoftast()) #define need_resched(ci) (want_resched = 1, setsoftast()) +#define clear_resched(ci) want_resched = 0 #define need_proftick(p) setsoftast() #ifndef _LOCORE diff --git a/sys/arch/i386/include/cpu.h b/sys/arch/i386/include/cpu.h index 7632dbb53ce..62209b1acb3 100644 --- a/sys/arch/i386/include/cpu.h +++ b/sys/arch/i386/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.102 2008/06/09 20:43:43 miod Exp $ */ +/* $OpenBSD: cpu.h,v 1.103 2008/07/18 23:43:31 art Exp $ */ /* $NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos Exp $ */ /*- @@ -230,6 +230,7 @@ extern void cpu_init_idle_pcbs(void); * or after the current trap/syscall if in system mode. */ extern void need_resched(struct cpu_info *); +#define clear_resched(ci) (ci)->ci_want_resched = 0 #define CLKF_USERMODE(frame) USERMODE((frame)->if_cs, (frame)->if_eflags) #define CLKF_PC(frame) ((frame)->if_eip) diff --git a/sys/arch/m88k/include/cpu.h b/sys/arch/m88k/include/cpu.h index aa3acd6438b..2e196920d8f 100644 --- a/sys/arch/m88k/include/cpu.h +++ b/sys/arch/m88k/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.34 2008/01/13 20:20:29 miod Exp $ */ +/* $OpenBSD: cpu.h,v 1.35 2008/07/18 23:43:31 art Exp $ */ /* * Copyright (c) 1996 Nivas Madhur * Copyright (c) 1992, 1993 @@ -241,6 +241,7 @@ do { \ if (ci->ci_curproc != NULL) \ aston(ci->ci_curproc); \ } while (0) +#define clear_resched(ci) (ci)->ci_want_resched = 0 /* * Give a profiling tick to the current process when the user profiling diff --git a/sys/arch/mac68k/include/cpu.h b/sys/arch/mac68k/include/cpu.h index f3562fbdc94..4ad125df84b 100644 --- a/sys/arch/mac68k/include/cpu.h +++ b/sys/arch/mac68k/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.46 2007/11/02 19:18:54 martin Exp $ */ +/* $OpenBSD: cpu.h,v 1.47 2008/07/18 23:43:31 art Exp $ */ /* $NetBSD: cpu.h,v 1.45 1997/02/10 22:13:40 scottr Exp $ */ /* @@ -105,6 +105,7 @@ struct clockframe { */ extern int want_resched; /* resched() was called */ #define need_resched(ci) { want_resched = 1; aston(); } +#define clear_resched(ci) want_resched = 0 /* * Give a profiling tick to the current process from the softclock diff --git a/sys/arch/mips64/include/cpu.h b/sys/arch/mips64/include/cpu.h index d320ef5a309..3a5d6d96f78 100644 --- a/sys/arch/mips64/include/cpu.h +++ b/sys/arch/mips64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.24 2008/04/07 22:37:16 miod Exp $ */ +/* $OpenBSD: cpu.h,v 1.25 2008/07/18 23:43:31 art Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -409,6 +409,7 @@ extern int int_nest_cntr; * or after the current trap/syscall if in system mode. */ #define need_resched(info) { want_resched = 1; aston(); } +#define clear_resched(ci) want_resched = 0 /* * Give a profiling tick to the current process when the user profiling diff --git a/sys/arch/mvme68k/include/cpu.h b/sys/arch/mvme68k/include/cpu.h index 99f07c83839..727b8171e37 100644 --- a/sys/arch/mvme68k/include/cpu.h +++ b/sys/arch/mvme68k/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.27 2007/05/30 17:10:44 miod Exp $ */ +/* $OpenBSD: cpu.h,v 1.28 2008/07/18 23:43:31 art Exp $ */ /* * Copyright (c) 1995 Theo de Raadt @@ -115,6 +115,7 @@ struct clockframe { */ extern int want_resched; #define need_resched(ci) { want_resched = 1; aston(); } +#define clear_resched(ci) want_resched = 0 /* * Give a profiling tick to the current process when the user profiling diff --git a/sys/arch/powerpc/include/cpu.h b/sys/arch/powerpc/include/cpu.h index e95b065b37b..4a6d2ed2692 100644 --- a/sys/arch/powerpc/include/cpu.h +++ b/sys/arch/powerpc/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.37 2008/05/04 20:54:22 drahn Exp $ */ +/* $OpenBSD: cpu.h,v 1.38 2008/07/18 23:43:31 art Exp $ */ /* $NetBSD: cpu.h,v 1.1 1996/09/30 16:34:21 ws Exp $ */ /* @@ -151,6 +151,7 @@ do { \ if (ci->ci_curproc != NULL) \ aston(ci->ci_curproc); \ } while (0) +#define clear_resched(ci) (ci)->ci_want_resched = 0 #define need_proftick(p) aston(p) diff --git a/sys/arch/sh/include/cpu.h b/sys/arch/sh/include/cpu.h index 2b8a0d5d579..dd2cd3138d1 100644 --- a/sys/arch/sh/include/cpu.h +++ b/sys/arch/sh/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.13 2008/05/21 19:45:37 miod Exp $ */ +/* $OpenBSD: cpu.h,v 1.14 2008/07/18 23:43:31 art Exp $ */ /* $NetBSD: cpu.h,v 1.41 2006/01/21 04:24:12 uwe Exp $ */ /*- @@ -101,6 +101,7 @@ do { \ if (curproc != NULL) \ aston(curproc); \ } while (/*CONSTCOND*/0) +#define clear_resched(ci) want_resched = 0 /* * Give a profiling tick to the current process when the user profiling diff --git a/sys/arch/sparc/include/cpu.h b/sys/arch/sparc/include/cpu.h index 44686965093..5d44640212f 100644 --- a/sys/arch/sparc/include/cpu.h +++ b/sys/arch/sparc/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.29 2007/05/08 07:23:18 art Exp $ */ +/* $OpenBSD: cpu.h,v 1.30 2008/07/18 23:43:31 art Exp $ */ /* $NetBSD: cpu.h,v 1.24 1997/03/15 22:25:15 pk Exp $ */ /* @@ -131,6 +131,7 @@ extern void raise(int, int); */ extern int want_resched; /* resched() was called */ #define need_resched(ci) (want_resched = 1, want_ast = 1) +#define clear_resched(ci) want_resched = 0 extern int want_ast; /* diff --git a/sys/arch/sparc64/include/cpu.h b/sys/arch/sparc64/include/cpu.h index 709165826e1..a6251debd25 100644 --- a/sys/arch/sparc64/include/cpu.h +++ b/sys/arch/sparc64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.62 2008/07/04 22:03:30 kettenis Exp $ */ +/* $OpenBSD: cpu.h,v 1.63 2008/07/18 23:43:31 art Exp $ */ /* $NetBSD: cpu.h,v 1.28 2001/06/14 22:56:58 thorpej Exp $ */ /* @@ -223,6 +223,7 @@ void setsoftnet(void); * or after the current trap/syscall if in system mode. */ extern void need_resched(struct cpu_info *); +#define clear_resched(ci) (ci)->ci_want_resched = 0 /* * This is used during profiling to integrate system time. diff --git a/sys/arch/vax/include/cpu.h b/sys/arch/vax/include/cpu.h index dc6ec203a16..4dc1b5a8654 100644 --- a/sys/arch/vax/include/cpu.h +++ b/sys/arch/vax/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.26 2007/10/10 15:53:53 art Exp $ */ +/* $OpenBSD: cpu.h,v 1.27 2008/07/18 23:43:31 art Exp $ */ /* $NetBSD: cpu.h,v 1.41 1999/10/21 20:01:36 ragge Exp $ */ /* @@ -107,6 +107,7 @@ extern int bootdev; want_resched++; \ mtpr(AST_OK,PR_ASTLVL); \ } +#define clear_resched(ci) want_resched = 0 /* * Notify the current process (p) that it has a signal pending, diff --git a/sys/kern/sched_bsd.c b/sys/kern/sched_bsd.c index 2bfbadbec94..e7babbb88ed 100644 --- a/sys/kern/sched_bsd.c +++ b/sys/kern/sched_bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sched_bsd.c,v 1.16 2008/05/22 14:07:14 thib Exp $ */ +/* $OpenBSD: sched_bsd.c,v 1.17 2008/07/18 23:43:31 art Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /*- @@ -415,6 +415,8 @@ mi_switch(void) p->p_stat = SONPROC; } + clear_resched(curcpu()); + SCHED_ASSERT_LOCKED(); /*