2 * This file is part of msrtool.
4 * Copyright (c) 2008 Peter Stuge <peter@stuge.se>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <sys/types.h>
29 static int msr_fd[MAX_CORES] = {-1, -1, -1, -1, -1, -1, -1, -1};
31 int linux_probe(const struct sysdef *system) {
33 return 0 == stat("/dev/cpu/0/msr", &st);
36 int linux_open(uint8_t cpu, enum SysModes mode) {
51 if (cpu >= MAX_CORES) {
52 fprintf(stderr, "%s: only cores 0-%d are supported. requested=%d\n", __func__, MAX_CORES, cpu);
55 if (snprintf(fn, sizeof(fn), "/dev/cpu/%d/msr", cpu) == -1) {
56 fprintf(stderr, "%s: snprintf: %s\n", __func__, strerror(errno));
59 msr_fd[cpu] = open(fn, fmode);
60 if (-1 == msr_fd[cpu]) {
61 fprintf(stderr, "open(%s): %s\n", fn, strerror(errno));
67 int linux_close(uint8_t cpu) {
69 if (cpu >= MAX_CORES) {
70 fprintf(stderr, "%s: only cores 0-%d are supported. requested=%d\n", __func__, MAX_CORES, cpu);
73 ret = close(msr_fd[cpu]);
78 int linux_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val) {
80 if (lseek(msr_fd[cpu], addr, SEEK_SET) == -1) {
81 SYSERROR(lseek, addr);
84 if (read(msr_fd[cpu], &tmp, 8) != 8) {