msr.c 643 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. int main(int argc, char **argv) {
  12. int cpu, fd;
  13. long long msr;
  14. char msr_file_name[64];
  15. if (argc != 2)
  16. return 1;
  17. errno = 0;
  18. cpu = strtol(argv[1], (char **) NULL, 10);
  19. if (errno)
  20. return 1;
  21. sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu);
  22. fd = open(msr_file_name, O_RDONLY);
  23. if (fd == -1) {
  24. perror("Failed to open");
  25. return 1;
  26. }
  27. pread(fd, &msr, sizeof(msr), 0x199);
  28. printf("msr 0x199: 0x%llx\n", msr);
  29. return 0;
  30. }