[coreboot] New patch to review for coreboot: 23a3206 msrtool: CPU probe functions call cpuid only once

Anton Kochkov (anton.kochkov@gmail.com) gerrit at coreboot.org
Sat Jul 21 05:33:27 CEST 2012


Anton Kochkov (anton.kochkov at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/1259

-gerrit

commit 23a32066e98c3e90651e51ccc5adf7c34b16558f
Author: Anton Kochkov <anton.kochkov at gmail.com>
Date:   Sat Jul 21 07:29:48 2012 +0400

    msrtool: CPU probe functions call cpuid only once
    
    Fixed CPU probing by calling cpuid only once
    and then using result as argument for all probe
    functions.
    
    Change-Id: Icd615636207499cfa46b8b99bf819ef8ca2d97c0
    Signed-off-by: Anton Kochkov <anton.kochkov at gmail.com>
---
 util/msrtool/cs5536.c               |    2 +-
 util/msrtool/geodegx2.c             |    3 +-
 util/msrtool/geodelx.c              |    3 +-
 util/msrtool/intel_core1.c          |    3 +-
 util/msrtool/intel_core2_early.c    |    3 +-
 util/msrtool/intel_core2_later.c    |    3 +-
 util/msrtool/intel_nehalem.c        |    3 +-
 util/msrtool/intel_pentium3.c       |    3 +-
 util/msrtool/intel_pentium3_early.c |    3 +-
 util/msrtool/intel_pentium4_early.c |    3 +-
 util/msrtool/intel_pentium4_later.c |    3 +-
 util/msrtool/k8.c                   |    3 +-
 util/msrtool/msrtool.c              |    7 +++-
 util/msrtool/msrtool.h              |   49 +++++++++++++++++------------------
 14 files changed, 41 insertions(+), 50 deletions(-)

diff --git a/util/msrtool/cs5536.c b/util/msrtool/cs5536.c
index 666a93a..aa3a0e8 100644
--- a/util/msrtool/cs5536.c
+++ b/util/msrtool/cs5536.c
@@ -19,7 +19,7 @@
 
 #include "msrtool.h"
 
-int cs5536_probe(const struct targetdef *target) {
+int cs5536_probe(const struct cpuid_t *id, const struct targetdef *target) {
 	return (NULL != pci_dev_find(0x1022, 0x2090));
 }
 
diff --git a/util/msrtool/geodegx2.c b/util/msrtool/geodegx2.c
index ae5d887..b617c29 100644
--- a/util/msrtool/geodegx2.c
+++ b/util/msrtool/geodegx2.c
@@ -20,8 +20,7 @@
 
 #include "msrtool.h"
 
-int geodegx2_probe(const struct targetdef *target) {
-	struct cpuid_t *id = cpuid();
+int geodegx2_probe(const struct cpuid_t *id, const struct targetdef *target) {
 	return 5 == id->family && 5 == id->model;
 }
 
diff --git a/util/msrtool/geodelx.c b/util/msrtool/geodelx.c
index 063e031..1d644f3 100644
--- a/util/msrtool/geodelx.c
+++ b/util/msrtool/geodelx.c
@@ -19,8 +19,7 @@
 
 #include "msrtool.h"
 
-int geodelx_probe(const struct targetdef *target) {
-	struct cpuid_t *id = cpuid();
+int geodelx_probe(const struct cpuid_t *id, const struct targetdef *target) {
 	return 5 == id->family && 10 == id->model;
 }
 
diff --git a/util/msrtool/intel_core1.c b/util/msrtool/intel_core1.c
index 1ebc7df..07c9de6 100644
--- a/util/msrtool/intel_core1.c
+++ b/util/msrtool/intel_core1.c
@@ -19,8 +19,7 @@
 
 #include "msrtool.h"
 
-int intel_core1_probe(const struct targetdef *target) {
-	struct cpuid_t *id = cpuid();
+int intel_core1_probe(const struct cpuid_t *id, const struct targetdef *target) {
 	return ((0x6 == id->family) && (0xe == id->model));
 }
 
diff --git a/util/msrtool/intel_core2_early.c b/util/msrtool/intel_core2_early.c
index 674d7db..ed02198 100644
--- a/util/msrtool/intel_core2_early.c
+++ b/util/msrtool/intel_core2_early.c
@@ -19,8 +19,7 @@
 
 #include "msrtool.h"
 
-int intel_core2_early_probe(const struct targetdef *target) {
-	struct cpuid_t *id = cpuid();
+int intel_core2_early_probe(const struct cpuid_t *id, const struct targetdef *target) {
 	return ((0x6 == id->family) && (0xf == id->model));
 }
 
diff --git a/util/msrtool/intel_core2_later.c b/util/msrtool/intel_core2_later.c
index 1c06c43..40f6723 100644
--- a/util/msrtool/intel_core2_later.c
+++ b/util/msrtool/intel_core2_later.c
@@ -19,8 +19,7 @@
 
 #include "msrtool.h"
 
-int intel_core2_later_probe(const struct targetdef *target) {
-	struct cpuid_t *id = cpuid();
+int intel_core2_later_probe(const struct cpuid_t *id, const struct targetdef *target) {
 	return ((0x6 == id->family)&(0x17 == id->model));
 }
 
diff --git a/util/msrtool/intel_nehalem.c b/util/msrtool/intel_nehalem.c
index e69fe57..f1afa17 100644
--- a/util/msrtool/intel_nehalem.c
+++ b/util/msrtool/intel_nehalem.c
@@ -19,8 +19,7 @@
 
 #include "msrtool.h"
 
-int intel_nehalem_probe(const struct targetdef *target) {
-	struct cpuid_t *id = cpuid();
+int intel_nehalem_probe(const struct cpuid_t *id, const struct targetdef *target) {
 	return ((0x6 == id->family) && (
 		(0x1a == id->model) ||
 		(0x1e == id->model) ||
diff --git a/util/msrtool/intel_pentium3.c b/util/msrtool/intel_pentium3.c
index 442ae3d..b39ca99 100644
--- a/util/msrtool/intel_pentium3.c
+++ b/util/msrtool/intel_pentium3.c
@@ -19,8 +19,7 @@
 
 #include "msrtool.h"
 
-int intel_pentium3_probe(const struct targetdef *target) {
-	struct cpuid_t *id = cpuid();
+int intel_pentium3_probe(const struct cpuid_t *id, const struct targetdef *target) {
 	return ((0x6 == id->family) && (
 		(0xa == id->model) ||
 		(0xb == id->model)
diff --git a/util/msrtool/intel_pentium3_early.c b/util/msrtool/intel_pentium3_early.c
index ced3037..edd294b 100644
--- a/util/msrtool/intel_pentium3_early.c
+++ b/util/msrtool/intel_pentium3_early.c
@@ -19,8 +19,7 @@
 
 #include "msrtool.h"
 
-int intel_pentium3_early_probe(const struct targetdef *target) {
-	struct cpuid_t *id = cpuid();
+int intel_pentium3_early_probe(const struct cpuid_t *id, const struct targetdef *target) {
 	return ((0x6 == id->family) && (
 		(0x7 == id->model) ||
 		(0x8 == id->model)
diff --git a/util/msrtool/intel_pentium4_early.c b/util/msrtool/intel_pentium4_early.c
index cb6c53e..087c42b 100644
--- a/util/msrtool/intel_pentium4_early.c
+++ b/util/msrtool/intel_pentium4_early.c
@@ -19,8 +19,7 @@
 
 #include "msrtool.h"
 
-int intel_pentium4_early_probe(const struct targetdef *target) {
-	struct cpuid_t *id = cpuid();
+int intel_pentium4_early_probe(const struct cpuid_t *id, const struct targetdef *target) {
 	return ((0xf == id->family) && (0x2 == id->model));
 }
 
diff --git a/util/msrtool/intel_pentium4_later.c b/util/msrtool/intel_pentium4_later.c
index 7c077ee..d8d592e 100644
--- a/util/msrtool/intel_pentium4_later.c
+++ b/util/msrtool/intel_pentium4_later.c
@@ -19,8 +19,7 @@
 
 #include "msrtool.h"
 
-int intel_pentium4_later_probe(const struct targetdef *target) {
-	struct cpuid_t *id = cpuid();
+int intel_pentium4_later_probe(const struct cpuid_t *id, const struct targetdef *target) {
 	return ((0xf == id->family) && (
 		(0x3 == id->model) ||
 		(0x4 == id->model)
diff --git a/util/msrtool/k8.c b/util/msrtool/k8.c
index 6d2500d..66114db 100644
--- a/util/msrtool/k8.c
+++ b/util/msrtool/k8.c
@@ -19,8 +19,7 @@
 
 #include "msrtool.h"
 
-int k8_probe(const struct targetdef *target) {
-	struct cpuid_t *id = cpuid();
+int k8_probe(const struct cpuid_t *id, const struct targetdef *target) {
 	return 0xF == id->family;
 }
 
diff --git a/util/msrtool/msrtool.c b/util/msrtool/msrtool.c
index 433fc32..6f66234 100644
--- a/util/msrtool/msrtool.c
+++ b/util/msrtool/msrtool.c
@@ -270,6 +270,7 @@ int main(int argc, char *argv[]) {
 	int ret = 1;
 	const struct sysdef *s;
 	const struct targetdef *t;
+	const struct cpuid_t *id;
 	uint8_t tn, listmsrs = 0, listknown = 0, input = 0;
 	uint32_t addr = 0;
 	const char *streamfn = NULL, *difffn = NULL;
@@ -354,14 +355,16 @@ int main(int argc, char *argv[]) {
 	if (targets)
 		for (tn = 0; tn < targets_found; tn++)
 			printf_quiet("Forced target %s: %s\n", targets[tn]->name, targets[tn]->prettyname);
-	else
+	else {
+		id = cpuid();
 		for (t = alltargets; !TARGET_ISEOT(*t); t++) {
 			printf_verbose("Probing for target %s: %s\n", t->name, t->prettyname);
-			if (!t->probe(t))
+			if (!t->probe(id, t))
 				continue;
 			printf_quiet("Detected target %s: %s\n", t->name, t->prettyname);
 			add_target(t);
 		}
+	}
 
 	printf_quiet("\n");
 	fflush(stdout);
diff --git a/util/msrtool/msrtool.h b/util/msrtool/msrtool.h
index 73671e5..7bee97d 100644
--- a/util/msrtool/msrtool.h
+++ b/util/msrtool/msrtool.h
@@ -97,10 +97,21 @@ struct msrdef {
 
 #define MAX_CORES 8
 
+typedef enum { VENDOR_INTEL = 1, VENDOR_AMD = 2 } vendor_t;
+
+struct cpuid_t {
+	uint8_t family;
+	uint8_t model;
+	uint8_t stepping;
+	uint8_t ext_family;
+	uint8_t ext_model;
+	vendor_t vendor;
+};
+
 struct targetdef {
 	const char *name;
 	const char *prettyname;
-	int (*probe)(const struct targetdef *target);
+	int (*probe)(const struct cpuid_t *id, const struct targetdef *target);
 	const struct msrdef *msrs;
 };
 
@@ -126,18 +137,6 @@ struct sysdef {
 #define SYSTEM_EOT .name = NULL
 #define SYSTEM_ISEOT(s) (NULL == (s).name)
 
-typedef enum { VENDOR_INTEL = 1, VENDOR_AMD = 2 } vendor_t;
-
-struct cpuid_t {
-	uint8_t family;
-	uint8_t model;
-	uint8_t stepping;
-	uint8_t ext_family;
-	uint8_t ext_model;
-	vendor_t vendor;
-};
-
-
 extern const struct sysdef *sys;
 
 extern uint8_t targets_found;
@@ -201,51 +200,51 @@ extern int freebsd_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val);
 /** target externs **/
 
 /* geodegx2.c */
-extern int geodegx2_probe(const struct targetdef *t);
+extern int geodegx2_probe(const struct cpuid_t *id, const struct targetdef *t);
 extern const struct msrdef geodegx2_msrs[];
 
 /* geodelx.c */
-extern int geodelx_probe(const struct targetdef *t);
+extern int geodelx_probe(const struct cpuid_t *id, const struct targetdef *t);
 extern const struct msrdef geodelx_msrs[];
 
 /* cs5536.c */
-extern int cs5536_probe(const struct targetdef *t);
+extern int cs5536_probe(const struct cpuid_t *id, const struct targetdef *t);
 extern const struct msrdef cs5536_msrs[];
 
 /* k8.c */
-extern int k8_probe(const struct targetdef *t);
+extern int k8_probe(const struct cpuid_t *id, const struct targetdef *t);
 extern const struct msrdef k8_msrs[];
 
 /* intel_pentium3_early.c */
-extern int intel_pentium3_early_probe(const struct targetdef *t);
+extern int intel_pentium3_early_probe(const struct cpuid_t *id, const struct targetdef *t);
 extern const struct msrdef intel_pentium3_early_msrs[];
 
 /* intel_pentium3.c */
-extern int intel_pentium3_probe(const struct targetdef *t);
+extern int intel_pentium3_probe(const struct cpuid_t *id, const struct targetdef *t);
 extern const struct msrdef intel_pentium3_msrs[];
 
 /* intel_core1.c */
-extern int intel_core1_probe(const struct targetdef *t);
+extern int intel_core1_probe(const struct cpuid_t *id, const struct targetdef *t);
 extern const struct msrdef intel_core1_msrs[];
 
 /* intel_core2_early.c */
-extern int intel_core2_early_probe(const struct targetdef *t);
+extern int intel_core2_early_probe(const struct cpuid_t *id, const struct targetdef *t);
 extern const struct msrdef intel_core2_early_msrs[];
 
 /* intel_core2_later.c */
-extern int intel_core2_later_probe(const struct targetdef *t);
+extern int intel_core2_later_probe(const struct cpuid_t *id, const struct targetdef *t);
 extern const struct msrdef intel_core2_later_msrs[];
 
 /* intel_pentium4_early.c */
-extern int intel_pentium4_early_probe(const struct targetdef *t);
+extern int intel_pentium4_early_probe(const struct cpuid_t *id, const struct targetdef *t);
 extern const struct msrdef intel_pentium4_early_msrs[];
 
 /* intel_pentium4_later.c */
-extern int intel_pentium4_later_probe(const struct targetdef *t);
+extern int intel_pentium4_later_probe(const struct cpuid_t *id, const struct targetdef *t);
 extern const struct msrdef intel_pentium4_later_msrs[];
 
 /* intel_nehalem.c */
-extern int intel_nehalem_probe(const struct targetdef *t);
+extern int intel_nehalem_probe(const struct cpuid_t *id, const struct targetdef *t);
 extern const struct msrdef intel_nehalem_msrs[];
 
 #endif /* MSRTOOL_H */




More information about the coreboot mailing list