forked from andikleen/mcelog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msr.c
64 lines (59 loc) · 1.46 KB
/
msr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "mcelog.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
static void domsr(int cpu, int msr, int bit)
{
char fpath[32];
unsigned long long data;
int fd;
sprintf(fpath, "/dev/cpu/%d/msr", cpu);
fd = open(fpath, O_RDWR);
if (fd == -1) {
switch (errno) {
case ENOENT:
SYSERRprintf("Warning: cpu %d offline?, imc_log not set\n", cpu);
return;
default:
SYSERRprintf("Cannot open %s to set imc_log\n", fpath);
return;
}
}
if (pread(fd, &data, sizeof data, msr) != sizeof data) {
SYSERRprintf("Cannot read MSR_ERROR_CONTROL from %s\n", fpath);
goto out;
}
data |= bit;
if (pwrite(fd, &data, sizeof data, msr) != sizeof data) {
SYSERRprintf("Cannot write MSR_ERROR_CONTROL to %s\n", fpath);
goto out;
}
if (pread(fd, &data, sizeof data, msr) != sizeof data) {
SYSERRprintf("Cannot re-read MSR_ERROR_CONTROL from %s\n", fpath);
goto out;
}
if ((data & bit) == 0)
Lprintf("No DIMM detection available on cpu %d (normal in virtual environments)\n", cpu);
out:
close(fd);
}
/* XXX: assumes all CPUs are already onlined. */
void set_imc_log(int cputype)
{
int cpu, ncpus = sysconf(_SC_NPROCESSORS_CONF);
int msr, bit;
switch (cputype) {
case CPU_SANDY_BRIDGE_EP:
case CPU_IVY_BRIDGE_EPEX:
case CPU_HASWELL_EPEX:
msr = 0x17f; /* MSR_ERROR_CONTROL */
bit = 0x2; /* MemError Log Enable */
break;
default:
return;
}
for (cpu = 0; cpu < ncpus; cpu++)
domsr(cpu, msr, bit);
}