msr.c 679 B

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