# HG changeset patch # User Ron Minnich # Date 1321472734 28800 # Node ID 1d4536eaa715faaaf698cc163d5e02f6572673f8 # Parent 3c0c5b103513863d9507118c3190f2c8d012190b Fix bad implementation of cpuid probing for mwait The implementation of monitor/mwait was correct but the code to read CPUID 5 was badly wrong. This change fixes the broken code, as well as cleaning up some other problems pointed out by Nemo and Charles. Thanks to them for their persistence in showing the bug existed and in finding what the bug was. R=nixiedev, nemo CC=nix-dev http://codereview.appspot.com/5374057 Committer: Noah Evans diff -r 3c0c5b103513 -r 1d4536eaa715 sys/src/nix/k10/archk10.c --- a/sys/src/nix/k10/archk10.c Wed Nov 09 15:52:20 2011 +0000 +++ b/sys/src/nix/k10/archk10.c Wed Nov 16 11:45:34 2011 -0800 @@ -30,7 +30,7 @@ /* is mnonitor supported? */ if (m->cpuinfo[1][2] & 8) { - cpuid(5, 0, &m->monitorsize); + cpuid(5, 0, m->cpuinfo[2]); mwait = k10mwait; } diff -r 3c0c5b103513 -r 1d4536eaa715 sys/src/nix/k10/dat.h --- a/sys/src/nix/k10/dat.h Wed Nov 09 15:52:20 2011 +0000 +++ b/sys/src/nix/k10/dat.h Wed Nov 16 11:45:34 2011 -0800 @@ -131,11 +131,10 @@ */ struct MCPU { - u32int cpuinfo[2][4]; /* CPUID Functions 0 & 1 */ + u32int cpuinfo[3][4]; /* CPUID Functions 0, 1, and 5 (n.b.: 2-4 are invalid) */ int ncpuinfos; /* number of standard entries */ int ncpuinfoe; /* number of extended entries */ int isintelcpu; /* */ - u32int monitorsize; /* size of monitor area. If non-zero, monitor is supported */ }; /* diff -r 3c0c5b103513 -r 1d4536eaa715 sys/src/nix/k10/devarch.c --- a/sys/src/nix/k10/devarch.c Wed Nov 09 15:52:20 2011 +0000 +++ b/sys/src/nix/k10/devarch.c Wed Nov 16 11:45:34 2011 -0800 @@ -526,13 +526,13 @@ cpuidread(Chan*, void *a, long n, vlong off) { char str[64]; - int nstr = sizeof(str), ns = 0; + int nstr, ns; int i; - for(i = 0; i < 4; i++) + nstr = sizeof(str); + for(i = ns = 0; i < 4; i++) ns += snprint(str+ns, nstr-ns, "%08x ", m->cpuinfo[1][i]); - ns += snprint(str+ns, nstr-ns, "%08x ", m->monitorsize); return readstr(off, a, n, str); }