summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasao Uebayashi <uebayasi@cvs.openbsd.org>2014-07-11 10:53:08 +0000
committerMasao Uebayashi <uebayasi@cvs.openbsd.org>2014-07-11 10:53:08 +0000
commit123f4b6634c6f64980c8a879dc8140fcc706d6d2 (patch)
tree8f16526685cec43a88ad22499b7316fe46507593
parent7153f32429c8f459cac9dbed87a626718d2b84b9 (diff)
CPU_BUSY_CYCLE(): A new MI statement for busy loop power reduction
The new CPU_BUSY_CYCLE() may be put in a busy loop body so that CPU can reduce power consumption, as Linux's cpu_relax() and FreeBSD's cpu_spinwait(). To start minimally, use PAUSE on i386/amd64 and empty on others. The name is chosen following the existing cpu_idle_*() functions. Naming and API may be polished later. OK kettenis@
-rw-r--r--sys/arch/alpha/include/cpu.h4
-rw-r--r--sys/arch/amd64/include/cpu.h6
-rw-r--r--sys/arch/arm/include/cpu.h4
-rw-r--r--sys/arch/hppa/include/cpu.h4
-rw-r--r--sys/arch/hppa64/include/cpu.h4
-rw-r--r--sys/arch/i386/include/cpu.h6
-rw-r--r--sys/arch/m88k/include/cpu.h4
-rw-r--r--sys/arch/mips64/include/cpu.h4
-rw-r--r--sys/arch/powerpc/include/cpu.h4
-rw-r--r--sys/arch/sh/include/cpu.h4
-rw-r--r--sys/arch/sparc/sparc/cpuvar.h4
-rw-r--r--sys/arch/sparc64/include/cpu.h4
-rw-r--r--sys/arch/vax/include/cpu.h4
13 files changed, 43 insertions, 13 deletions
diff --git a/sys/arch/alpha/include/cpu.h b/sys/arch/alpha/include/cpu.h
index 4174e051d05..ba7ae88d32c 100644
--- a/sys/arch/alpha/include/cpu.h
+++ b/sys/arch/alpha/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.52 2014/03/29 18:09:28 guenther Exp $ */
+/* $OpenBSD: cpu.h,v 1.53 2014/07/11 10:53:07 uebayasi Exp $ */
/* $NetBSD: cpu.h,v 1.45 2000/08/21 02:03:12 thorpej Exp $ */
/*-
@@ -251,6 +251,8 @@ void cpu_unidle(struct cpu_info *);
#endif /* MULTIPROCESSOR */
+#define CPU_BUSY_CYCLE() do {} while (0)
+
#define curproc curcpu()->ci_curproc
#define fpcurproc curcpu()->ci_fpcurproc
#define curpcb curcpu()->ci_curpcb
diff --git a/sys/arch/amd64/include/cpu.h b/sys/arch/amd64/include/cpu.h
index c833c97b3dd..f129aeb4330 100644
--- a/sys/arch/amd64/include/cpu.h
+++ b/sys/arch/amd64/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.84 2014/07/09 11:37:16 mlarkin Exp $ */
+/* $OpenBSD: cpu.h,v 1.85 2014/07/11 10:53:07 uebayasi Exp $ */
/* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */
/*-
@@ -207,6 +207,8 @@ void cpu_init_idle_pcbs(void);
void cpu_kick(struct cpu_info *);
void cpu_unidle(struct cpu_info *);
+#define CPU_BUSY_CYCLE() __asm volatile("pause": : : "memory")
+
#else /* !MULTIPROCESSOR */
#define MAXCPUS 1
@@ -219,6 +221,8 @@ extern struct cpu_info cpu_info_primary;
#define cpu_kick(ci)
#define cpu_unidle(ci)
+#define CPU_BUSY_CYCLE() do {} while (0)
+
#endif
/*
diff --git a/sys/arch/arm/include/cpu.h b/sys/arch/arm/include/cpu.h
index a75285cd8fc..f00363cac0c 100644
--- a/sys/arch/arm/include/cpu.h
+++ b/sys/arch/arm/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.38 2013/09/12 11:43:51 patrick Exp $ */
+/* $OpenBSD: cpu.h,v 1.39 2014/07/11 10:53:07 uebayasi Exp $ */
/* $NetBSD: cpu.h,v 1.34 2003/06/23 11:01:08 martin Exp $ */
/*
@@ -234,6 +234,8 @@ extern struct cpu_info *cpu_info[MAXCPUS];
void cpu_boot_secondary_processors(void);
#endif /* !MULTIPROCESSOR */
+#define CPU_BUSY_CYCLE() do {} while (0)
+
#define curpcb curcpu()->ci_curpcb
/*
diff --git a/sys/arch/hppa/include/cpu.h b/sys/arch/hppa/include/cpu.h
index 8a90d0b4485..4465a874c92 100644
--- a/sys/arch/hppa/include/cpu.h
+++ b/sys/arch/hppa/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.86 2013/03/31 17:07:03 deraadt Exp $ */
+/* $OpenBSD: cpu.h,v 1.87 2014/07/11 10:53:07 uebayasi Exp $ */
/*
* Copyright (c) 2000-2004 Michael Shalayeff
@@ -140,6 +140,8 @@ curcpu(void)
#define CPU_INFO_FOREACH(cii, ci) \
for (cii = 0, ci = &cpu_info[0]; cii < ncpus; cii++, ci++)
+#define CPU_BUSY_CYCLE() do {} while (0)
+
/* types */
enum hppa_cpu_type {
hpcxs, hpcxt, hpcxta, hpcxl, hpcxl2, hpcxu, hpcxu2, hpcxw
diff --git a/sys/arch/hppa64/include/cpu.h b/sys/arch/hppa64/include/cpu.h
index d40f8ea105b..92ce1cf865c 100644
--- a/sys/arch/hppa64/include/cpu.h
+++ b/sys/arch/hppa64/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.33 2013/05/31 17:00:58 tedu Exp $ */
+/* $OpenBSD: cpu.h,v 1.34 2014/07/11 10:53:07 uebayasi Exp $ */
/*
* Copyright (c) 2005 Michael Shalayeff
@@ -120,6 +120,8 @@ struct cpu_info *curcpu(void);
#define MAXCPUS 1
#define cpu_unidle(ci)
+#define CPU_BUSY_CYCLE() do {} while (0)
+
/* types */
enum hppa_cpu_type {
hpcxu, hpcxu2, hpcxw
diff --git a/sys/arch/i386/include/cpu.h b/sys/arch/i386/include/cpu.h
index fec9ff29642..91b558a2934 100644
--- a/sys/arch/i386/include/cpu.h
+++ b/sys/arch/i386/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.133 2014/03/29 18:09:29 guenther Exp $ */
+/* $OpenBSD: cpu.h,v 1.134 2014/07/11 10:53:07 uebayasi Exp $ */
/* $NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos Exp $ */
/*-
@@ -225,6 +225,8 @@ extern void cpu_init_idle_pcbs(void);
void cpu_kick(struct cpu_info *);
void cpu_unidle(struct cpu_info *);
+#define CPU_BUSY_CYCLE() __asm volatile("pause": : : "memory")
+
#else /* MULTIPROCESSOR */
#define MAXCPUS 1
@@ -237,6 +239,8 @@ void cpu_unidle(struct cpu_info *);
#define cpu_kick(ci)
#define cpu_unidle(ci)
+#define CPU_BUSY_CYCLE() do {} while (0)
+
#endif
#define aston(p) ((p)->p_md.md_astpending = 1)
diff --git a/sys/arch/m88k/include/cpu.h b/sys/arch/m88k/include/cpu.h
index fd31f548dc3..b763c039854 100644
--- a/sys/arch/m88k/include/cpu.h
+++ b/sys/arch/m88k/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.61 2014/03/29 18:09:29 guenther Exp $ */
+/* $OpenBSD: cpu.h,v 1.62 2014/07/11 10:53:07 uebayasi Exp $ */
/*
* Copyright (c) 1996 Nivas Madhur
* Copyright (c) 1992, 1993
@@ -212,6 +212,8 @@ void m88k_broadcast_ipi(int);
#endif /* MULTIPROCESSOR */
+#define CPU_BUSY_CYCLE() do {} while (0)
+
void set_cpu_number(cpuid_t);
/*
diff --git a/sys/arch/mips64/include/cpu.h b/sys/arch/mips64/include/cpu.h
index a7665714035..2629528f2c7 100644
--- a/sys/arch/mips64/include/cpu.h
+++ b/sys/arch/mips64/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.101 2014/04/04 20:52:05 miod Exp $ */
+/* $OpenBSD: cpu.h,v 1.102 2014/07/11 10:53:07 uebayasi Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -259,6 +259,8 @@ void smp_rendezvous_cpus(unsigned long, void (*)(void *), void *arg);
#define get_cpu_info(i) (&cpu_info_primary)
#endif
+#define CPU_BUSY_CYCLE() do {} while (0)
+
extern void (*md_startclock)(struct cpu_info *);
void cp0_calibrate(struct cpu_info *);
diff --git a/sys/arch/powerpc/include/cpu.h b/sys/arch/powerpc/include/cpu.h
index fdf0c48878b..8085ed5ee06 100644
--- a/sys/arch/powerpc/include/cpu.h
+++ b/sys/arch/powerpc/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.52 2014/03/29 18:09:30 guenther Exp $ */
+/* $OpenBSD: cpu.h,v 1.53 2014/07/11 10:53:07 uebayasi Exp $ */
/* $NetBSD: cpu.h,v 1.1 1996/09/30 16:34:21 ws Exp $ */
/*
@@ -141,6 +141,8 @@ void cpu_unidle(struct cpu_info *);
#endif
+#define CPU_BUSY_CYCLE() do {} while (0)
+
#define MAXCPUS PPC_MAXPROCS
extern struct cpu_info cpu_info[PPC_MAXPROCS];
diff --git a/sys/arch/sh/include/cpu.h b/sys/arch/sh/include/cpu.h
index 77d7a0078f6..9497e3d884a 100644
--- a/sys/arch/sh/include/cpu.h
+++ b/sys/arch/sh/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.26 2013/06/11 16:42:10 deraadt Exp $ */
+/* $OpenBSD: cpu.h,v 1.27 2014/07/11 10:53:07 uebayasi Exp $ */
/* $NetBSD: cpu.h,v 1.41 2006/01/21 04:24:12 uwe Exp $ */
/*-
@@ -81,6 +81,8 @@ extern struct cpu_info cpu_info_store;
#define MAXCPUS 1
#define cpu_unidle(ci)
+#define CPU_BUSY_CYCLE() do {} while (0)
+
/*
* Arguments to hardclock and gatherstats encapsulate the previous
diff --git a/sys/arch/sparc/sparc/cpuvar.h b/sys/arch/sparc/sparc/cpuvar.h
index 0208f9e2d6d..c8ae164df9e 100644
--- a/sys/arch/sparc/sparc/cpuvar.h
+++ b/sys/arch/sparc/sparc/cpuvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpuvar.h,v 1.19 2010/09/28 20:27:55 miod Exp $ */
+/* $OpenBSD: cpuvar.h,v 1.20 2014/07/11 10:53:07 uebayasi Exp $ */
/* $NetBSD: cpuvar.h,v 1.4 1997/07/06 21:14:25 pk Exp $ */
/*
@@ -96,6 +96,8 @@ struct cpu_info {
#define MAXCPUS 1
#define cpu_unidle(ci)
+#define CPU_BUSY_CYCLE() do {} while (0)
+
/*
* The cpu_softc structure. This structure maintains information about one
* currently installed CPU (there may be several of these if the machine
diff --git a/sys/arch/sparc64/include/cpu.h b/sys/arch/sparc64/include/cpu.h
index c78ee0b71ae..5bb209252fb 100644
--- a/sys/arch/sparc64/include/cpu.h
+++ b/sys/arch/sparc64/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.84 2014/03/29 18:09:30 guenther Exp $ */
+/* $OpenBSD: cpu.h,v 1.85 2014/07/11 10:53:07 uebayasi Exp $ */
/* $NetBSD: cpu.h,v 1.28 2001/06/14 22:56:58 thorpej Exp $ */
/*
@@ -206,6 +206,8 @@ void cpu_unidle(struct cpu_info *);
#define cpu_unidle(ci)
+#define CPU_BUSY_CYCLE() do {} while (0)
+
#endif
/*
diff --git a/sys/arch/vax/include/cpu.h b/sys/arch/vax/include/cpu.h
index 2f0d237bc1c..a5d500eb136 100644
--- a/sys/arch/vax/include/cpu.h
+++ b/sys/arch/vax/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.46 2013/06/30 17:04:46 miod Exp $ */
+/* $OpenBSD: cpu.h,v 1.47 2014/07/11 10:53:07 uebayasi Exp $ */
/* $NetBSD: cpu.h,v 1.41 1999/10/21 20:01:36 ragge Exp $ */
/*
@@ -71,6 +71,8 @@ extern struct cpu_info cpu_info_store;
#define MAXCPUS 1
#define cpu_unidle(ci)
+#define CPU_BUSY_CYCLE() do {} while (0)
+
struct clockframe {
int pc;
int ps;