shithub: riscv

Download patch

ref: 50bda3d5225190cd8e2b3c7ce7aa3c1ea1759e40
parent: 4c8cfe7284b13c8b445cf278c319cad716bdbbea
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Dec 30 23:41:51 EST 2013

kernel: halt idle processors on mp system by default (from sources)

one can add:

int idle_spin = 1;

in the kernel configuration to enable the old behaviour. see the
comment at idlehands().

--- a/sys/src/9/pc/main.c
+++ b/sys/src/9/pc/main.c
@@ -31,6 +31,7 @@
 int nconf;
 uchar *sp;	/* user stack of init proc */
 int delaylink;
+int idle_spin;
 
 static void
 multibootargs(void)
@@ -1083,6 +1084,15 @@
 /*
  *  put the processor in the halt state if we've no processes to run.
  *  an interrupt will get us going again.
+ *
+ *  halting in an smp system can result in a startup latency for
+ *  processes that become ready.
+ *  if idle_spin is zero, we care more about saving energy
+ *  than reducing this latency.
+ *
+ *  the performance loss with idle_spin == 0 seems to be slight
+ *  and it reduces lock contention (thus system time and real time)
+ *  on many-core systems with large values of NPROC.
  */
 void
 idlehands(void)
@@ -1093,4 +1103,6 @@
 		halt();
 	else if(m->cpuidcx & Monitor)
 		mwait(&nrdy);
+	else if(idle_spin == 0)
+		halt();
 }
--