Note that wrmsr writes the same MSR value to *all* cores. Signed-off-by: Barret Rhoden <[email protected]> --- tests/rdmsr.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/wrmsr.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 tests/rdmsr.c create mode 100644 tests/wrmsr.c
diff --git a/tests/rdmsr.c b/tests/rdmsr.c new file mode 100644 index 000000000000..cad6a2d9ec73 --- /dev/null +++ b/tests/rdmsr.c @@ -0,0 +1,52 @@ +/* Copyright (c) 2016 Google Inc. + * Barret Rhoden <[email protected]> + * See LICENSE for details. + * + * Usage: rdmsr MSR + * + * This will read MSR on all cores. + * + * e.g. rdmsr 0x199 */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <assert.h> +#include <unistd.h> +#include <parlib/sysinfo.h> + +int main(int argc, char **argv) +{ + uint32_t msr; + int fd; + uint64_t *buf; + size_t buf_sz; + ssize_t ret; + int num_cores; + + if (argc < 2) { + printf("Usage: %s MSR\n", argv[0]); + exit(-1); + } + msr = strtoul(argv[1], 0, 0); + num_cores = get_num_pcores(); + fd = open("#arch/msr", O_RDWR); + if (fd < 0) { + perror("open"); + exit(-1); + } + buf_sz = num_cores * sizeof(uint64_t); + buf = malloc(buf_sz); + assert(buf); + ret = pread(fd, buf, buf_sz, msr); + if (ret < 0) { + perror("pread"); + exit(-1); + } + for (int i = 0; i < num_cores; i++) + printf("Core %3d, MSR 0x%08x: 0x%016llx\n", i, msr, buf[i]); + return 0; +} diff --git a/tests/wrmsr.c b/tests/wrmsr.c new file mode 100644 index 000000000000..5f6554d78046 --- /dev/null +++ b/tests/wrmsr.c @@ -0,0 +1,45 @@ +/* Copyright (c) 2016 Google Inc. + * Barret Rhoden <[email protected]> + * See LICENSE for details. + * + * Usage: wrmsr MSR VAL + * + * This will write VAL to *all cores* MSR. + * + * e.g. wrmsr 0x199 0x100002600 */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <assert.h> +#include <unistd.h> + +int main(int argc, char **argv) +{ + uint32_t msr; + uint64_t val; + int fd; + ssize_t ret; + + if (argc < 3) { + printf("Usage: %s MSR VAL\n", argv[0]); + exit(-1); + } + msr = strtoul(argv[1], 0, 0); + val = strtoul(argv[2], 0, 0); + + fd = open("#arch/msr", O_RDWR); + if (fd < 0) { + perror("open"); + exit(-1); + } + ret = pwrite(fd, &val, sizeof(val), msr); + if (ret < 0) { + perror("pwrite"); + exit(-1); + } + return 0; +} -- 2.7.0.rc3.207.g0ac5344 -- You received this message because you are subscribed to the Google Groups "Akaros" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
