| 107 | } |
| 108 | |
| 109 | static int open_and_seek(int cpu, unsigned long msr, int mode, int *fd) |
| 110 | { |
| 111 | char dev[32]; |
| 112 | char temp_string[50]; |
| 113 | |
| 114 | snprintf(dev, sizeof(dev), "/dev/cpu/%d/msr", cpu); |
| 115 | *fd = open(dev, mode); |
| 116 | |
| 117 | if (*fd < 0) { |
| 118 | snprintf(temp_string, sizeof(temp_string), "open(\"%s\")", dev); |
| 119 | perror(temp_string); |
| 120 | return -1; |
| 121 | } |
| 122 | |
| 123 | if (lseek(*fd, msr, SEEK_SET) == (off_t)-1) { |
| 124 | snprintf(temp_string, sizeof(temp_string), "lseek(%lu)", msr); |
| 125 | perror(temp_string); |
| 126 | close(*fd); |
| 127 | return -1; |
| 128 | } |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | static msr_t rdmsr_from_cpu(int cpu, unsigned long addr) |
| 134 | { |
no test coverage detected