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