From 207de1d51439254d44a0061d17760081f8e4a9b7 Mon Sep 17 00:00:00 2001 From: Artur Grabowski Date: Sat, 22 Nov 2008 18:12:33 +0000 Subject: The last parts of cpu_unidle. i386, amd64 and sparc64 In short, make cpu_unidle do what signotify used to do and make signotify use cpu_unidle. Also, include a cpu_unidle in need_resched, it won't change much right now but will be needed in the future. --- sys/arch/amd64/amd64/machdep.c | 23 +++++++++++++++++------ sys/arch/amd64/include/cpu.h | 6 +++++- sys/arch/i386/i386/machdep.c | 28 ++++++++++++++++------------ sys/arch/i386/include/cpu.h | 6 +++++- sys/arch/sparc64/include/cpu.h | 6 ++++-- sys/arch/sparc64/sparc64/cpu.c | 9 +++++++-- sys/arch/sparc64/sparc64/ipifuncs.c | 8 +++----- sys/arch/sparc64/sparc64/machdep.c | 8 ++------ 8 files changed, 59 insertions(+), 35 deletions(-) (limited to 'sys') diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index 418903872c9..ca00b33cfdc 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.84 2008/10/09 19:04:18 kettenis Exp $ */ +/* $OpenBSD: machdep.c,v 1.85 2008/11/22 18:12:32 art Exp $ */ /* $NetBSD: machdep.c,v 1.3 2003/05/07 22:58:18 fvdl Exp $ */ /*- @@ -726,11 +726,17 @@ void signotify(struct proc *p) { aston(p); + cpu_unidle(p->p_cpu); +} + #ifdef MULTIPROCESSOR - if (p->p_cpu != curcpu() && p->p_cpu != NULL) - x86_send_ipi(p->p_cpu, X86_IPI_NOP); -#endif +void +cpu_unidle(struct cpu_info *ci) +{ + if (ci != curcpu()) + x86_send_ipi(ci, X86_IPI_NOP); } +#endif int waittime = -1; struct pcb dumppcb; @@ -1743,8 +1749,13 @@ void need_resched(struct cpu_info *ci) { ci->ci_want_resched = 1; - if ((ci)->ci_curproc != NULL) - aston((ci)->ci_curproc); + + /* There's a risk we'll be called before the idle threads start */ + if (ci->ci_curproc) { + aston(ci->ci_curproc); + if (ci != curcpu()) + cpu_unidle(ci); + } } /* diff --git a/sys/arch/amd64/include/cpu.h b/sys/arch/amd64/include/cpu.h index 8bbe67e6ebc..2c21acf44d3 100644 --- a/sys/arch/amd64/include/cpu.h +++ b/sys/arch/amd64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.38 2008/10/15 23:23:46 deraadt Exp $ */ +/* $OpenBSD: cpu.h,v 1.39 2008/11/22 18:12:32 art Exp $ */ /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */ /*- @@ -184,6 +184,8 @@ extern struct cpu_info *cpu_info[MAXCPUS]; void cpu_boot_secondary_processors(void); void cpu_init_idle_pcbs(void); +void cpu_unidle(struct cpu_info *); + #else /* !MULTIPROCESSOR */ #define MAXCPUS 1 @@ -193,6 +195,8 @@ extern struct cpu_info cpu_info_primary; #define curcpu() (&cpu_info_primary) +#define cpu_unidle(ci) + #endif /* diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index 673299a6e6f..45ae08f2b63 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.438 2008/11/14 20:43:54 weingart Exp $ */ +/* $OpenBSD: machdep.c,v 1.439 2008/11/22 18:12:32 art Exp $ */ /* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */ /*- @@ -2340,11 +2340,17 @@ void signotify(struct proc *p) { aston(p); + cpu_unidle(p->p_cpu); +} + #ifdef MULTIPROCESSOR - if (p->p_cpu != curcpu() && p->p_cpu != NULL) - i386_send_ipi(p->p_cpu, I386_IPI_NOP); -#endif +void +cpu_unidle(struct cpu_info *ci) +{ + if (ci != curcpu()) + i386_send_ipi(ci, I386_IPI_NOP); } +#endif int waittime = -1; struct pcb dumppcb; @@ -3243,16 +3249,14 @@ cpu_initclocks(void) void need_resched(struct cpu_info *ci) { - struct proc *p; - ci->ci_want_resched = 1; - /* - * Need to catch the curproc in case it's cleared just - * between the check and the aston(). - */ - if ((p = ci->ci_curproc) != NULL) - aston(p); + /* There's a risk we'll be called before the idle threads start */ + if (ci->ci_curproc) { + aston(ci->ci_curproc); + if (ci != curcpu()) + cpu_unidle(ci); + } } /* Allocate an IDT vector slot within the given range. diff --git a/sys/arch/i386/include/cpu.h b/sys/arch/i386/include/cpu.h index 48fd4f35843..56e1263eb20 100644 --- a/sys/arch/i386/include/cpu.h +++ b/sys/arch/i386/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.105 2008/10/15 23:23:47 deraadt Exp $ */ +/* $OpenBSD: cpu.h,v 1.106 2008/11/22 18:12:32 art Exp $ */ /* $NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos Exp $ */ /*- @@ -205,6 +205,8 @@ extern struct cpu_info *cpu_info[MAXCPUS]; extern void cpu_boot_secondary_processors(void); extern void cpu_init_idle_pcbs(void); +void cpu_unidle(struct cpu_info *); + #else /* MULTIPROCESSOR */ #define MAXCPUS 1 @@ -214,6 +216,8 @@ extern void cpu_init_idle_pcbs(void); #define CPU_IS_PRIMARY(ci) 1 +#define cpu_unidle(ci) + #endif #define aston(p) ((p)->p_md.md_astpending = 1) diff --git a/sys/arch/sparc64/include/cpu.h b/sys/arch/sparc64/include/cpu.h index bd1a79ffcb8..3db5b3d1506 100644 --- a/sys/arch/sparc64/include/cpu.h +++ b/sys/arch/sparc64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.69 2008/10/15 23:23:50 deraadt Exp $ */ +/* $OpenBSD: cpu.h,v 1.70 2008/11/22 18:12:32 art Exp $ */ /* $NetBSD: cpu.h,v 1.28 2001/06/14 22:56:58 thorpej Exp $ */ /* @@ -183,7 +183,7 @@ void cpu_boot_secondary_processors(void); void sparc64_send_ipi(int, void (*)(void), u_int64_t, u_int64_t); void sparc64_broadcast_ipi(void (*)(void), u_int64_t, u_int64_t); -void smp_signotify(struct proc *); +void cpu_unidle(struct cpu_info *); #else @@ -197,6 +197,8 @@ void smp_signotify(struct proc *); #define CPU_INFO_UNIT(ci) 0 #define MAXCPUS 1 +#define cpu_unidle(ci) + #endif /* diff --git a/sys/arch/sparc64/sparc64/cpu.c b/sys/arch/sparc64/sparc64/cpu.c index 3678a7fafad..64505401d1b 100644 --- a/sys/arch/sparc64/sparc64/cpu.c +++ b/sys/arch/sparc64/sparc64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.50 2008/10/15 23:23:50 deraadt Exp $ */ +/* $OpenBSD: cpu.c,v 1.51 2008/11/22 18:12:32 art Exp $ */ /* $NetBSD: cpu.c,v 1.13 2001/05/26 21:27:15 chs Exp $ */ /* @@ -751,8 +751,13 @@ void need_resched(struct cpu_info *ci) { ci->ci_want_resched = 1; - if (ci->ci_curproc != NULL) + + /* There's a risk we'll be called before the idle threads start */ + if (ci->ci_curproc) { aston(ci->ci_curproc); + if (ci != curcpu()) + cpu_unidle(ci); + } } /* diff --git a/sys/arch/sparc64/sparc64/ipifuncs.c b/sys/arch/sparc64/sparc64/ipifuncs.c index becf4316b7b..4903c71065c 100644 --- a/sys/arch/sparc64/sparc64/ipifuncs.c +++ b/sys/arch/sparc64/sparc64/ipifuncs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ipifuncs.c,v 1.11 2008/07/21 10:07:14 kettenis Exp $ */ +/* $OpenBSD: ipifuncs.c,v 1.12 2008/11/22 18:12:32 art Exp $ */ /* $NetBSD: ipifuncs.c,v 1.8 2006/10/07 18:11:36 rjs Exp $ */ /*- @@ -233,11 +233,9 @@ smp_tlb_flush_ctx(int ctx) } void -smp_signotify(struct proc *p) +cpu_unidle(struct cpu_info *ci) { - struct cpu_info *ci = p->p_cpu; - - if (db_active) + if (ci == curcpu() || db_active || ((ci->ci_flags & CPUF_RUNNING) == 0)) return; if (CPU_ISSUN4V) diff --git a/sys/arch/sparc64/sparc64/machdep.c b/sys/arch/sparc64/sparc64/machdep.c index d2944df1b8c..e4e66bd6860 100644 --- a/sys/arch/sparc64/sparc64/machdep.c +++ b/sys/arch/sparc64/sparc64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.112 2008/06/27 17:22:15 miod Exp $ */ +/* $OpenBSD: machdep.c,v 1.113 2008/11/22 18:12:32 art Exp $ */ /* $NetBSD: machdep.c,v 1.108 2001/07/24 19:30:14 eeh Exp $ */ /*- @@ -669,11 +669,7 @@ void signotify(struct proc *p) { aston(p); -#ifdef MULTIPROCESSOR - /* Send IPI if necessary. */ - if (p->p_cpu != curcpu() && p->p_cpu != NULL) - smp_signotify(p); -#endif + cpu_unidle(p->p_cpu); } int waittime = -1; -- cgit v1.2.3