| 493 | }; |
| 494 | |
| 495 | int print_amd_msrs(void) |
| 496 | { |
| 497 | unsigned int i, id; |
| 498 | msr_t msr; |
| 499 | |
| 500 | typedef struct { |
| 501 | unsigned int model; |
| 502 | const msr_entry_t *global_msrs; |
| 503 | unsigned int num_global_msrs; |
| 504 | } cpu_t; |
| 505 | |
| 506 | cpu_t cpulist[] = { |
| 507 | { CPUID_TURIN_C1, common_msrs, ARRAY_SIZE(common_msrs) }, |
| 508 | { CPUID_PHOENIX_A2, common_msrs, ARRAY_SIZE(common_msrs) }, |
| 509 | }; |
| 510 | |
| 511 | cpu_t *cpu = NULL; |
| 512 | |
| 513 | /* Get CPU family, model and stepping */ |
| 514 | id = cpuid(1); |
| 515 | for (i = 0; i < ARRAY_SIZE(cpulist); i++) { |
| 516 | if(cpulist[i].model == id) { |
| 517 | cpu = &cpulist[i]; |
| 518 | break; |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | if (!cpu) { |
| 523 | printf("Error: Dumping MSRs on this CPU (0x%06x) is not (yet) supported.\n", id); |
| 524 | return -1; |
| 525 | } |
| 526 | |
| 527 | #ifndef __DARWIN__ |
| 528 | fd_msr = open("/dev/cpu/0/msr", O_RDWR); |
| 529 | if (fd_msr < 0) { |
| 530 | perror("Error while opening /dev/cpu/0/msr"); |
| 531 | printf("Did you run 'modprobe msr'?\n"); |
| 532 | return -1; |
| 533 | } |
| 534 | #endif |
| 535 | |
| 536 | printf("\n===================== MSRs =====================\n"); |
| 537 | |
| 538 | for (i = 0; i < cpu->num_global_msrs; i++) { |
| 539 | msr = rdmsr(cpu->global_msrs[i].number); |
| 540 | printf(" MSR 0x%08X = 0x%08X:0x%08X (%s)\n", |
| 541 | cpu->global_msrs[i].number, msr.hi, msr.lo, |
| 542 | cpu->global_msrs[i].name); |
| 543 | } |
| 544 | |
| 545 | #ifndef __DARWIN__ |
| 546 | close(fd_msr); |
| 547 | |
| 548 | if (msr_readerror) |
| 549 | printf("\n(*) Some MSRs could not be read. The marked values are unreliable.\n"); |
| 550 | #endif |
| 551 | return 0; |
| 552 | } |