1 /* SPDX-License-Identifier: GPL-2.0-only */
12 static int msr_fd
[MAX_CORES
] = {-1, -1, -1, -1, -1, -1, -1, -1};
14 int linux_probe(const struct sysdef
*system
) {
16 return 0 == stat("/dev/cpu/0/msr", &st
);
19 int linux_open(uint8_t cpu
, enum SysModes mode
) {
34 if (cpu
>= MAX_CORES
) {
35 fprintf(stderr
, "%s: only cores 0-%d are supported. requested=%d\n", __func__
, MAX_CORES
, cpu
);
38 if (snprintf(fn
, sizeof(fn
), "/dev/cpu/%d/msr", cpu
) == -1) {
39 fprintf(stderr
, "%s: snprintf: %s\n", __func__
, strerror(errno
));
42 msr_fd
[cpu
] = open(fn
, fmode
);
43 if (-1 == msr_fd
[cpu
]) {
44 fprintf(stderr
, "open(%s): %s\n", fn
, strerror(errno
));
50 int linux_close(uint8_t cpu
) {
52 if (cpu
>= MAX_CORES
) {
53 fprintf(stderr
, "%s: only cores 0-%d are supported. requested=%d\n", __func__
, MAX_CORES
, cpu
);
56 ret
= close(msr_fd
[cpu
]);
61 int linux_rdmsr(uint8_t cpu
, uint32_t addr
, struct msr
*val
) {
63 if (lseek(msr_fd
[cpu
], addr
, SEEK_SET
) == -1) {
64 SYSERROR(lseek
, addr
);
67 if (read(msr_fd
[cpu
], &tmp
, 8) != 8) {