[CRIU] [PATCH 11/12] cpuinfo: Add "cpuinfo [dump|check]" commands, v2

Cyrill Gorcunov gorcunov at gmail.com
Wed Oct 1 07:56:41 PDT 2014


On Wed, Oct 01, 2014 at 05:51:09PM +0400, Pavel Emelyanov wrote:
> > Yes, what you've been expecting?
> 
> if (!strcmp(argv[optind]))
> 	return cpu_cap_check()
> 
> or smth like this.

updated. So if it become confusing -- feel free to merge [1;9] and
ping me to resend the rest, or pick up from attachements.
-------------- next part --------------
>From 6af96ff63ac82f9566c3cba9c116dc67698c9797 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Tue, 30 Sep 2014 18:33:40 +0400
Subject: [PATCH] cpuinfo: Add "cpuinfo [dump|check]" commands

They allow to validate cpuinfo information
without running complete dump/restore actions.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 Documentation/criu.txt     |  7 +++++++
 arch/aarch64/cpu.c         | 11 +++++++++++
 arch/arm/cpu.c             | 11 +++++++++++
 arch/x86/cpu.c             | 25 +++++++++++++++++++++++++
 arch/x86/include/asm/cpu.h |  2 ++
 crtools.c                  | 12 ++++++++++++
 include/cpu.h              |  2 ++
 7 files changed, 70 insertions(+)

diff --git a/Documentation/criu.txt b/Documentation/criu.txt
index d2feb17d0140..cf1a05d77119 100644
--- a/Documentation/criu.txt
+++ b/Documentation/criu.txt
@@ -50,6 +50,13 @@ Starts pagemap data deduplication procedure, where *criu* scans over all
 pagemap files and tries to minimalize the number of pagemap entries by
 obtaining the references from a parent pagemap image.
 
+*cpuinfo* *dump*::
+Writes information about currently running CPU and its features into an image.
+
+*cpuinfo* *check*::
+Reads information about CPU from an image file and checks if it is compatible
+with currently running CPU.
+
 OPTIONS
 -------
 *-c*::
diff --git a/arch/aarch64/cpu.c b/arch/aarch64/cpu.c
index 59f61b769c4c..f26608b46987 100644
--- a/arch/aarch64/cpu.c
+++ b/arch/aarch64/cpu.c
@@ -1,6 +1,7 @@
 #undef	LOG_PREFIX
 #define LOG_PREFIX "cpu: "
 
+#include <errno.h>
 #include "cpu.h"
 
 bool cpu_has_feature(unsigned int feature)
@@ -22,3 +23,13 @@ int cpu_validate_cpuinfo(void)
 {
 	return 0;
 }
+
+int cpu_dump_cpuinfo_single(void)
+{
+	return -ENOTSUP;
+}
+
+int cpu_validate_image_cpuinfo_single(void)
+{
+	return -ENOTSUP;
+}
diff --git a/arch/arm/cpu.c b/arch/arm/cpu.c
index 59f61b769c4c..f26608b46987 100644
--- a/arch/arm/cpu.c
+++ b/arch/arm/cpu.c
@@ -1,6 +1,7 @@
 #undef	LOG_PREFIX
 #define LOG_PREFIX "cpu: "
 
+#include <errno.h>
 #include "cpu.h"
 
 bool cpu_has_feature(unsigned int feature)
@@ -22,3 +23,13 @@ int cpu_validate_cpuinfo(void)
 {
 	return 0;
 }
+
+int cpu_dump_cpuinfo_single(void)
+{
+	return -ENOTSUP;
+}
+
+int cpu_validate_image_cpuinfo_single(void)
+{
+	return -ENOTSUP;
+}
diff --git a/arch/x86/cpu.c b/arch/x86/cpu.c
index 5ff30956d622..018f55115a86 100644
--- a/arch/x86/cpu.c
+++ b/arch/x86/cpu.c
@@ -355,3 +355,28 @@ err:
 	close_image(img);
 	return ret;
 }
+
+int cpuinfo_dump(void)
+{
+	if (cpu_init())
+		return -1;
+	if (cpu_dump_cpuinfo())
+		return -1;
+	return 0;
+}
+
+int cpuinfo_check(void)
+{
+	if (cpu_init())
+		return -1;
+
+	/*
+	 * Force to check all caps because its been
+	 * called as a special command from options.
+	 */
+	opts.cpu_cap = CPU_CAP_ALL;
+
+	if (cpu_validate_cpuinfo())
+		return -1;
+	return 0;
+}
diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
index 8dcf9b4714c6..6f49229d6396 100644
--- a/arch/x86/include/asm/cpu.h
+++ b/arch/x86/include/asm/cpu.h
@@ -201,5 +201,7 @@ extern bool cpu_has_feature(unsigned int feature);
 extern int cpu_init(void);
 extern int cpu_dump_cpuinfo(void);
 extern int cpu_validate_cpuinfo(void);
+extern int cpuinfo_dump(void);
+extern int cpuinfo_check(void);
 
 #endif /* __CR_CPU_H__ */
diff --git a/crtools.c b/crtools.c
index ddf355eca4fe..a245bbb74c34 100644
--- a/crtools.c
+++ b/crtools.c
@@ -36,6 +36,7 @@
 #include "plugin.h"
 #include "mount.h"
 #include "cgroup.h"
+#include "cpu.h"
 #include "action-scripts.h"
 
 #include "setproctitle.h"
@@ -522,6 +523,15 @@ int main(int argc, char *argv[], char *envp[])
 	if (!strcmp(argv[optind], "dedup"))
 		return cr_dedup() != 0;
 
+	if (!strcmp(argv[optind], "cpuinfo")) {
+		if (!argv[optind + 1])
+			goto usage;
+		if (!strcmp(argv[optind + 1], "dump"))
+			return cpuinfo_dump();
+		else if (!strcmp(argv[optind + 1], "check"))
+			return cpuinfo_check();
+	}
+
 	pr_msg("Error: unknown command: %s\n", argv[optind]);
 usage:
 	pr_msg("\n"
@@ -545,6 +555,8 @@ usage:
 "  page-server    launch page server\n"
 "  service        launch service\n"
 "  dedup          remove duplicates in memory dump\n"
+"  cpuinfo dump   writes cpu information into image file\n"
+"  cpuinfo check  validates cpu information read from image file\n"
 	);
 
 	if (usage_error) {
diff --git a/include/cpu.h b/include/cpu.h
index 152dc0a597ae..e94525a9e780 100644
--- a/include/cpu.h
+++ b/include/cpu.h
@@ -7,5 +7,7 @@ extern bool cpu_has_feature(unsigned int feature);
 extern int cpu_init(void);
 extern int cpu_dump_cpuinfo(void);
 extern int cpu_validate_cpuinfo(void);
+extern int cpuinfo_dump(void);
+extern int cpuinfo_check(void);
 
 #endif /* __CR_CPU_H__ */
-- 
1.9.3



More information about the CRIU mailing list