File msr-tools-xen_physical_msr_support.patch of Package msr-tools
From: Jan Beulich <JBeulich@novell.com>
msr-tools: Provide access to physical msr Xen interface via parameter
Xen provides /dev/cpu/X/msr where virtual CPU msr access is emulated.
/dev/xen/cpu/X/msr is passed to the physical CPUs.
Provide access to both via -P parameter.
Signed-off-by: Thomas Renninger <trenn@suse.de>
CC: H. Peter Anvin <hpa@linux.intel.com>
---
rdmsr.c | 11 +++++++++--
wrmsr.c | 12 ++++++++++--
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/rdmsr.c b/rdmsr.c
index 3f5e2b3..f0543b8 100644
--- a/rdmsr.c
+++ b/rdmsr.c
@@ -42,15 +42,18 @@ static const struct option long_options[] = {
{"zero-pad", 0, 0, '0'},
{"raw", 0, 0, 'r'},
{"all", 0, 0, 'a'},
+ {"phys-cpu", 1, 0, 'P'},
{"processor", 1, 0, 'p'},
{"cpu", 1, 0, 'p'},
{"bitfield", 1, 0, 'f'},
{0, 0, 0, 0}
};
-static const char short_options[] = "hVxXdoruc0ap:f:";
+static const char short_options[] = "hVxXdoruc0aP:p:f:";
static const char *proc_stat = "/proc/stat";
+static const char *msr_file_pattern = "/dev/cpu/%d/msr";
+
/* Number of decimal digits for a certain number of bits */
/* (int) ceil(log(2^n)/log(10)) */
static const int decdigits[] = {
@@ -89,6 +92,7 @@ static void usage(void)
" --raw -r Raw binary output\n"
" --all -a all processors\n"
" --processor # -p Select processor number (default 0)\n"
+ " --phys-cpu # -P Select (Xen) physical processor = number\n"
" --bitfield h:l -f Output bits [h:l] only\n", program);
}
@@ -107,7 +111,7 @@ static void rdmsr_on_cpu(const struct format *fmt, uint32_t reg, int cpu)
char msr_file_name[64];
unsigned int bits;
- sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu);
+ sprintf(msr_file_name, msr_file_pattern, cpu);
fd = open(msr_file_name, O_RDONLY);
if (fd < 0) {
if (errno == ENXIO) {
@@ -332,6 +336,9 @@ int main(int argc, char *argv[])
case 'a':
cpu = -1;
break;
+ case 'P':
+ msr_file_pattern = "/dev/xen/cpu/%d/msr";
+ /* fall through */
case 'p':
arg = strtoul(optarg, &endarg, 0);
if (*endarg || arg > 255) {
diff --git a/wrmsr.c b/wrmsr.c
index 9800841..cb4a7e4 100644
--- a/wrmsr.c
+++ b/wrmsr.c
@@ -33,12 +33,16 @@ static const struct option long_options[] = {
{"version", 0, 0, 'V'},
{"all", 0, 0, 'a'},
{"processor", 1, 0, 'p'},
+ {"phys-cpu", 1, 0, 'P'},
{"cpu", 1, 0, 'p'},
{0, 0, 0, 0}
};
-static const char short_options[] = "hVap:";
+static const char short_options[] = "hVaP:p:";
static const char *proc_stat = "/proc/stat";
+
+static const char *msr_file_pattern = "/dev/cpu/%d/msr";
+
const char *program;
static void usage(void)
@@ -47,6 +51,7 @@ static void usage(void)
" --help -h Print this help\n"
" --version -V Print current version\n"
" --all -a all processors\n"
+ " --phys-cpu # -P Select (Xen) physical processor = number\n"
" --processor # -p Select processor number (default 0)\n",
program);
}
@@ -56,7 +61,7 @@ static void wrmsr_on_cpu(uint32_t reg, uint64_t data, int cpu)
int fd;
char msr_file_name[64];
- sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu);
+ sprintf(msr_file_name, msr_file_pattern, cpu);
fd = open(msr_file_name, O_WRONLY);
if (fd < 0) {
if (errno == ENXIO) {
@@ -141,6 +146,9 @@ int main(int argc, char *argv[])
case 'a':
cpu = -1;
break;
+ case 'P':
+ msr_file_pattern = "/dev/xen/cpu/%d/msr";
+ /* fall through */
case 'p':
arg = strtoul(optarg, &endarg, 0);
if (*endarg || arg > 255) {