2 #include "../port/lib.h"
13 if(m->cpuiddx & Acpif)
14 if(strcmp(m->cpuidid, "GenuineIntel") == 0){
22 cputemprd0(Chan*, void *a, long n, vlong offset)
31 if((regs[0] & 1) == 0)
35 * magic undocumented msr. tj(max) is 100 or 85.
38 d = X86MODEL(m->cpuidax);
39 d |= (m->cpuidax>>12) & 0xf0;
40 if((d == 0xf && (m->cpuidax & 0xf)>1) || d == 0xe){
41 if(rdmsr(0xee, &emsr) == 0){
48 if(rdmsr(0x19c, &emsr) < 0)
58 if((msr & 0x30) == 0x30)
60 snprint(buf, sizeof buf, "%ld±%uld%s\n", t, res, s);
61 return readstr(offset, a, n, buf);
63 return readstr(offset, a, n, "-1±-1 unsupported\n");
67 intelcputemprd(Chan *c, void *va, long n, vlong offset)
76 for(i = 0; i < conf.nmach; i++){
79 r = cputemprd0(c, a, n, offset);
95 amd0ftemprd(Chan*, void *a, long n, vlong offset)
101 p = pcimatch(0, 0x1022, 0x1103);
103 return readstr(offset, a, n, "-1±-1 unsupported\n");
108 e = buf + sizeof buf;
109 for(j = 0; j < max; j++){
110 pcicfgw32(p, 0xe4, pcicfgr32(p, 0xe4) & ~4 | j<<2);
111 i = pcicfgr32(p, 0xe4);
112 if(X86STEPPING(m->cpuidax) == 2)
120 s = seprint(s, e, "%ld±%uld%s\n", t, 1l, "");
122 return readstr(offset, a, n, buf);
126 amd10temprd(Chan*, void *a, long n, vlong offset)
128 char *s, *e, *r, *buf;
129 long i, t, c, nb, cores[MAXMACH];
133 for(p = 0; p = pcimatch(p, 0x1022, 0x1203); ){
134 cores[nb++] = 1 + ((pcicfgr32(p, 0xe8) & 0x3000)>>12);
135 if(nb == nelem(cores))
139 return readstr(offset, a, n, "-1±-1 unsupported\n");
140 buf = smalloc(MAXMACH*4*32);
142 e = buf + MAXMACH*4*32;
145 for(p = 0; p = pcimatch(p, 0x1022, 0x1203); nb++){
146 i = pcicfgr32(p, 0xa4) & 0x7fffffff;
153 * only one value per nb; repeat per core
155 while(c++ < conf.nmach && cores[nb]--)
156 s = seprint(s, e, "%ld%s±0.5%s\n", t, r, "");
158 i = readstr(offset, a, n, buf);
167 addarchfile("cputemp", 0444, intelcputemprd, nil);
168 if(X86FAMILY(m->cpuidax) == 0x0f && !strcmp(m->cpuidid, "AuthenticAMD"))
169 addarchfile("cputemp", 0444, amd0ftemprd, nil);
170 if(X86FAMILY(m->cpuidax) == 0x10 && !strcmp(m->cpuidid, "AuthenticAMD"))
171 addarchfile("cputemp", 0444, amd10temprd, nil);