inteltool: Allow to set cores range for MSRs dump
Adds the ability to output MSRs dump for the specified range of CPU
cores. This makes it easier to reverse engineer server multicore
processors using the inteltool utility.
The range is set using --cpu-range <start>[-<end>] command line option:
$ sudo ./inteltool -M --cpu-range 0-7
$ sudo ./inteltool -M --cpu-range 7-15
$ sudo ./inteltool -M --cpu-range 32
$ sudo ./inteltool -M will print a register dump for all cores, just
as before.
Change-Id: I3a037cf7ac270d2b51d6e453334c358ff47b4105
Signed-off-by: Maxim Polyakov <max.senia.poliak@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/35919
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/util/inteltool/cpu.c b/util/inteltool/cpu.c
index db63d36..7425229 100644
--- a/util/inteltool/cpu.c
+++ b/util/inteltool/cpu.c
@@ -7,6 +7,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <limits.h>
#include "inteltool.h"
@@ -265,9 +266,9 @@
#endif
}
-int print_intel_core_msrs(void)
+int print_intel_msrs(unsigned int range_start, unsigned int range_end)
{
- unsigned int i, core, id, core_num = get_number_of_cores();
+ unsigned int i, core, id;
msr_t msr;
#define IA32_PLATFORM_ID 0x0017
@@ -2295,7 +2296,15 @@
close(fd_msr);
- for (core = 0; core < core_num; core++) {
+ const unsigned int cores_range_max_limit = get_number_of_cores() - 1;
+ if (range_end > cores_range_max_limit) {
+ if (range_end != UINT_MAX)
+ printf("Warning: the range exceeds the maximum core number %d!\n",
+ cores_range_max_limit);
+ range_end = cores_range_max_limit;
+ }
+
+ for (core = range_start; core <= range_end; core++) {
#ifndef __DARWIN__
char msrfilename[64];
memset(msrfilename, 0, 64);
diff --git a/util/inteltool/inteltool.c b/util/inteltool/inteltool.c
index 7cff80f..f8c5e91 100644
--- a/util/inteltool/inteltool.c
+++ b/util/inteltool/inteltool.c
@@ -10,6 +10,7 @@
#include <sys/mman.h>
#include <unistd.h>
#include <errno.h>
+#include <limits.h>
#include "inteltool.h"
#include "pcr.h"
@@ -21,6 +22,7 @@
enum long_only_opts {
LONG_OPT_PCR = 0x100,
+ LONG_OPT_RANGE = 0x101,
};
/*
@@ -516,6 +518,7 @@
" -d | --dmibar: dump northbridge DMIBAR registers\n"
" -P | --pciexpress: dump northbridge PCIEXBAR registers\n\n"
" -M | --msrs: dump CPU MSRs\n"
+ " --cpu-range <start>[-<end>]: (optional) set CPU cores range for -M (--msrs) option\n"
" -A | --ambs: dump AMB registers\n"
" -x | --sgx: dump SGX status\n"
" -t | --tme: dump TME status\n"
@@ -585,6 +588,8 @@
size_t pcr_count = 0;
uint8_t dump_pcr[MAX_PCR_PORTS];
+ unsigned int cores_range_start = 0, cores_range_end = UINT_MAX;
+
static struct option long_options[] = {
{"version", 0, 0, 'v'},
{"help", 0, 0, 'h'},
@@ -598,6 +603,7 @@
{"dmibar", 0, 0, 'd'},
{"pciexpress", 0, 0, 'P'},
{"msrs", 0, 0, 'M'},
+ {"cpu-range", required_argument, 0, LONG_OPT_RANGE},
{"ambs", 0, 0, 'A'},
{"spi", 0, 0, 's'},
{"spd", 0, 0, 'S'},
@@ -657,6 +663,24 @@
case 'M':
dump_coremsrs = 1;
break;
+ case LONG_OPT_RANGE:
+ if (strlen(optarg) == 0) {
+ print_usage(argv[0]);
+ exit(1);
+ }
+ const int sscanf_ret = sscanf(optarg, "%u-%u", &cores_range_start, &cores_range_end);
+ if (sscanf_ret == 1) {
+ /* the end of the range is not specified - only for one core */
+ cores_range_end = cores_range_start;
+ } else if (sscanf_ret != 2) {
+ print_usage(argv[0]);
+ exit(1);
+ } else if (cores_range_end < cores_range_start) {
+ printf("Error: invalid cores range <%u-%u>!\n",
+ cores_range_start, cores_range_end);
+ exit(1);
+ }
+ break;
case 'a':
dump_gpios = 1;
show_gpio_diffs = 1;
@@ -859,7 +883,7 @@
}
if (dump_coremsrs) {
- print_intel_core_msrs();
+ print_intel_msrs(cores_range_start, cores_range_end);
printf("\n\n");
}
diff --git a/util/inteltool/inteltool.h b/util/inteltool/inteltool.h
index 678aa47..4a6eba4 100644
--- a/util/inteltool/inteltool.h
+++ b/util/inteltool/inteltool.h
@@ -396,7 +396,7 @@
void unmap_physical(void *virt_addr, size_t len);
unsigned int cpuid(unsigned int op);
-int print_intel_core_msrs(void);
+int print_intel_msrs(unsigned int range_start, unsigned int range_end);
int print_mchbar(struct pci_dev *nb, struct pci_access *pacc, const char *dump_spd_file);
int print_pmbase(struct pci_dev *sb, struct pci_access *pacc);
int print_lpc(struct pci_dev *sb, struct pci_access *pacc);