File: msr.c

package info (click to toggle)
mcelog 104-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 996 kB
  • ctags: 1,508
  • sloc: ansic: 7,739; sh: 481; makefile: 87
file content (61 lines) | stat: -rw-r--r-- 1,411 bytes parent folder | download
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
#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);
			exit(1);
		}
	}
	if (pread(fd, &data, sizeof data, msr) != sizeof data) {
		SYSERRprintf("Cannot read MSR_ERROR_CONTROL from %s\n", fpath);
		exit(1);
	}
	data |= bit;
	if (pwrite(fd, &data, sizeof data, msr) != sizeof data) {
		SYSERRprintf("Cannot write MSR_ERROR_CONTROL to %s\n", fpath);
		exit(1);
	}
	if (pread(fd, &data, sizeof data, msr) != sizeof data) {
		SYSERRprintf("Cannot re-read MSR_ERROR_CONTROL from %s\n", fpath);
		exit(1);
	}
	if ((data & bit) == 0)
		Lprintf("No DIMM detection available on cpu %d (normal in virtual environments)\n", cpu);
	close(fd);
}

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:
		msr = 0x17f;	/* MSR_ERROR_CONTROL */
		bit = 0x2;	/* MemError Log Enable */
		break;
	default:
		return;
	}

	for (cpu = 0; cpu < ncpus; cpu++)
		domsr(cpu, msr, bit);
}