replace the portable function "mwait" with monmwait. monmwait(9) has the full definition, but it essentially waits for a bit of memory to change from a particular value Reference: /n/atom/patch/applied2013/monmwait Date: Wed Sep 18 17:20:05 CES 2013 Signed-off-by: quanstro@quanstro.net --- /sys/src/nix/k10/fns.h Wed Sep 18 17:20:00 2013 +++ /sys/src/nix/k10/fns.h Wed Sep 18 17:20:00 2013 @@ -150,7 +150,7 @@ /* * archk10.c */ -void k10mwait(void*); +void monmwait(void*, uintptr); /* * i8259.c --- /sys/src/nix/k10/l64v.s Wed Sep 18 17:20:00 2013 +++ /sys/src/nix/k10/l64v.s Wed Sep 18 17:20:00 2013 @@ -369,7 +369,7 @@ /* * uintptr monmwait(void*, uintptr) */ -TEXT k10mwait(SB),1,$16 +TEXT monmwait(SB),1,$16 MOVQ val+8(FP), BX _mmstart: --- /sys/src/nix/k10/archk10.c Wed Sep 18 17:20:00 2013 +++ /sys/src/nix/k10/archk10.c Wed Sep 18 17:20:00 2013 @@ -12,8 +12,8 @@ u32int info[4]; cpuid(1, 0, info); - if(info[2] & 8) - mwait = k10mwait; + if((info[2] & 8) == 0) + panic("k10archinit: mwait required"); } static int --- /sys/src/nix/port/taslock.c Wed Sep 18 17:20:00 2013 +++ /sys/src/nix/port/taslock.c Wed Sep 18 17:20:00 2013 @@ -233,12 +233,3 @@ up->lastilock = nil; splx(pl); } - -void -portmwait(void *value) -{ - while (*(void**)value == nil) - pause(); -} - -void (*mwait)(void *) = portmwait; --- /sys/man/9/monmwait Thu Jan 1 00:00:00 1970 +++ /sys/man/9/monmwait Wed Sep 18 17:20:00 2013 @@ -0,0 +1,50 @@ +.TH MONMWAIT 9 +.SH NAME +monmwait \- wait for memory write +.SH SYNOPSIS +.ta \w'\fLvoid 'u +.B +void monmwait(void *adr, uintmem oldval) +.SH DESCRIPTION +Wait for the value pointed to by +.B adr +to change from +.B oldval +in the most power- and bus-cycle efficient way afforded by +the architecture. +.PP +Since no lock is involved, +.I monmwait +may not be used where ABA might be a problem. This function will +never miss a (persistent) change, but may return before the value has +changed, for example if interrupted, or if a “nearby” memory location +has been written. +.I Nearby +is dependent on the architecture and +implementation. On current x86 platforms, +.I nearby +means in the +same cacheline. +.PP +The minimal correct implementation would be a no-op. +On x86 machines, the implementation uses +the +.SM MONITOR +and +.SM MWAIT +instructions. +.SH EXAMPLES +Application processors can use +.I monmwait +while waiting for release to keep the fans from spooling up: +.IP +.EX +while(!active.thunderbirdsarego) + monmwait(&active.thunderbirdsarego, 0); +.EE +.PP +.SH SOURCE +.B /sys/src/nix/k10/l64v.s +.SH SEE ALSO +.IR atom (2), +.IR lock (9)