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