aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/man/man9/arch.97
-rw-r--r--sys/include/arch/amd64/cpu.h7
-rw-r--r--sys/kern/kern_sched.c8
3 files changed, 16 insertions, 6 deletions
diff --git a/share/man/man9/arch.9 b/share/man/man9/arch.9
index 3285208..adbc437 100644
--- a/share/man/man9/arch.9
+++ b/share/man/man9/arch.9
@@ -95,6 +95,13 @@ The macro
calls an internal function that fetches the
cpu_info structure for the BSP.
+The macro
+.Ft hint_spinwait()
+hints the processor that it is currently
+in a spin-wait loop. This greatly reduces the
+processor’s power consumption and improves
+the performance of the spin-wait loop.
+
The function these macros call must return a pointer
to a
.Ft cpu_info
diff --git a/sys/include/arch/amd64/cpu.h b/sys/include/arch/amd64/cpu.h
index c72c106..e6f2de0 100644
--- a/sys/include/arch/amd64/cpu.h
+++ b/sys/include/arch/amd64/cpu.h
@@ -37,6 +37,13 @@
#include <sys/queue.h>
#include <machine/tss.h>
#include <machine/msr.h>
+/*
+ * XXX: We are not using the PAUSE instruction for the sake of
+ * ensuring compatibility... PAUSE is F3 90, REP NOP is
+ * F3 90... REP NOP will be read as a PAUSE on processors
+ * that support it.
+ */
+#define hint_spinwait() __ASMV("rep; nop")
#define this_cpu() amd64_this_cpu()
#define get_bsp() amd64_get_bsp()
diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
index da4c6c5..4f17ddf 100644
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -32,6 +32,7 @@
#include <sys/types.h>
#include <sys/cdefs.h>
#include <sys/spinlock.h>
+#include <machine/cpu.h>
#include <assert.h>
/*
@@ -59,17 +60,12 @@ sched_enqueue_ci(struct cpu_info *ci)
/*
* Processor awaiting tasks to be assigned will be here spinning.
- *
- * XXX: We are not using the PAUSE instruction for the sake of
- * ensuring compatibility... PAUSE is F3 90, REP NOP is
- * F3 90... REP NOP will be read as a PAUSE on processors
- * that support it.
*/
__noreturn static void
sched_enter(void)
{
for (;;) {
- __ASMV("rep; nop");
+ hint_spinwait();
}
}