[CRIU] [PATCH 8/9] cpuinfo: Add "cpuinfo [dump|check]" commands
Cyrill Gorcunov
gorcunov at openvz.org
Thu Sep 25 06:03:27 PDT 2014
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 | 12 ++++++++++++
arch/arm/cpu.c | 12 ++++++++++++
arch/x86/cpu.c | 36 ++++++++++++++++++++++++++++++++++++
arch/x86/include/asm/cpu.h | 2 ++
crtools.c | 12 ++++++++++++
include/cpu.h | 2 ++
7 files changed, 83 insertions(+)
diff --git a/Documentation/criu.txt b/Documentation/criu.txt
index c10093e133c4..6464984ded18 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 3a1d4122d3ac..14cf926fe79f 100644
--- a/arch/aarch64/cpu.c
+++ b/arch/aarch64/cpu.c
@@ -1,6 +1,8 @@
#undef LOG_PREFIX
#define LOG_PREFIX "cpu: "
+#include <errno.h>
+
#include "cpu.h"
bool cpu_has_feature(unsigned int feature)
@@ -18,7 +20,17 @@ int cpu_dump_cpuinfo(void)
return 0;
}
+int cpu_dump_cpuinfo_single(void)
+{
+ return -ENOTSUP;
+}
+
int cpu_validate_image_cpuinfo(void)
{
return 0;
}
+
+int cpu_validate_image_cpuinfo_single(void)
+{
+ return -ENOTSUP;
+}
diff --git a/arch/arm/cpu.c b/arch/arm/cpu.c
index 3a1d4122d3ac..14cf926fe79f 100644
--- a/arch/arm/cpu.c
+++ b/arch/arm/cpu.c
@@ -1,6 +1,8 @@
#undef LOG_PREFIX
#define LOG_PREFIX "cpu: "
+#include <errno.h>
+
#include "cpu.h"
bool cpu_has_feature(unsigned int feature)
@@ -18,7 +20,17 @@ int cpu_dump_cpuinfo(void)
return 0;
}
+int cpu_dump_cpuinfo_single(void)
+{
+ return -ENOTSUP;
+}
+
int cpu_validate_image_cpuinfo(void)
{
return 0;
}
+
+int cpu_validate_image_cpuinfo_single(void)
+{
+ return -ENOTSUP;
+}
diff --git a/arch/x86/cpu.c b/arch/x86/cpu.c
index 1a4710d1b581..cb985f162225 100644
--- a/arch/x86/cpu.c
+++ b/arch/x86/cpu.c
@@ -358,3 +358,39 @@ err:
close(fd);
return ret;
}
+
+int cpu_dump_cpuinfo_single(void)
+{
+ int ret;
+
+ ret = cpu_init();
+ if (ret)
+ goto err;
+
+ ret = cpu_dump_cpuinfo();
+ if (ret)
+ goto err;
+err:
+ return ret;
+}
+
+int cpu_validate_image_cpuinfo_single(void)
+{
+ int ret;
+
+ ret = cpu_init();
+ if (ret)
+ goto err;
+
+ /*
+ * Force to check all caps because its been
+ * called as a special command from options.
+ */
+ opts.cpu_cap = CPU_CAP_ALL;
+
+ ret = cpu_validate_image_cpuinfo();
+ if (ret)
+ goto err;
+err:
+ return ret;
+}
diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
index 3ad4187fbd87..e3a935c7de0e 100644
--- a/arch/x86/include/asm/cpu.h
+++ b/arch/x86/include/asm/cpu.h
@@ -201,6 +201,8 @@ static inline unsigned int cpuid_edx(unsigned int op)
extern bool cpu_has_feature(unsigned int feature);
extern int cpu_init(void);
extern int cpu_dump_cpuinfo(void);
+extern int cpu_dump_cpuinfo_single(void);
extern int cpu_validate_image_cpuinfo(void);
+extern int cpu_validate_image_cpuinfo_single(void);
#endif /* __CR_CPU_H__ */
diff --git a/crtools.c b/crtools.c
index 1857f9f08246..4e1462488330 100644
--- a/crtools.c
+++ b/crtools.c
@@ -28,6 +28,7 @@
#include "files.h"
#include "sk-inet.h"
#include "net.h"
+#include "cpu.h"
#include "version.h"
#include "page-xfer.h"
#include "tty.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 cpu_dump_cpuinfo_single();
+ else if (!strcmp(argv[optind + 1], "check"))
+ return cpu_validate_image_cpuinfo_single();
+ }
+
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 from image file\n"
);
if (usage_error) {
diff --git a/include/cpu.h b/include/cpu.h
index 7dbe68f7735c..864a6defb2ca 100644
--- a/include/cpu.h
+++ b/include/cpu.h
@@ -6,6 +6,8 @@
extern bool cpu_has_feature(unsigned int feature);
extern int cpu_init(void);
extern int cpu_dump_cpuinfo(void);
+extern int cpu_dump_cpuinfo_single(void);
extern int cpu_validate_image_cpuinfo(void);
+extern int cpu_validate_image_cpuinfo_single(void);
#endif /* __CR_CPU_H__ */
--
1.9.3
More information about the CRIU
mailing list