1 #include <math.h> 2 #include <unistd.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <sys/types.h> 6 #include <sys/stat.h> 7 #include <fcntl.h> 8 #include <sys/timeb.h> 9 #include <sched.h> 10 #include <errno.h> 11 12 13 int main(int argc, char **argv) { 14 int cpu, fd; 15 long long msr; 16 char msr_file_name[64]; 17 18 if (argc != 2) 19 return 1; 20 21 errno = 0; 22 cpu = strtol(argv[1], (char **) NULL, 10); 23 24 if (errno) 25 return 1; 26 27 sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu); 28 fd = open(msr_file_name, O_RDONLY); 29 30 if (fd == -1) { 31 perror("Failed to open"); 32 return 1; 33 } 34 35 pread(fd, &msr, sizeof(msr), 0x199); 36 37 printf("msr 0x199: 0x%llx\n", msr); 38 return 0; 39 } 40