All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Subject: [Patch v6 06/13] tools/libxc: x86 common code
Date: Mon, 7 Jul 2014 18:37:55 +0100	[thread overview]
Message-ID: <1404754682-28379-7-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1404754682-28379-1-git-send-email-andrew.cooper3@citrix.com>

Save/restore records common to all x86 domain types (HVM, PV).

This is only the TSC_INFO record.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/libxc/saverestore/common_x86.c |  133 ++++++++++++++++++++++++++++++++++
 tools/libxc/saverestore/common_x86.h |   26 +++++++
 2 files changed, 159 insertions(+)
 create mode 100644 tools/libxc/saverestore/common_x86.c
 create mode 100644 tools/libxc/saverestore/common_x86.h

diff --git a/tools/libxc/saverestore/common_x86.c b/tools/libxc/saverestore/common_x86.c
new file mode 100644
index 0000000..b64b291
--- /dev/null
+++ b/tools/libxc/saverestore/common_x86.c
@@ -0,0 +1,133 @@
+#include "common_x86.h"
+
+static void cpuid_count(uint32_t leaf, uint32_t subleaf,
+                        uint32_t *eax, uint32_t *ebx,
+                        uint32_t *ecx, uint32_t *edx)
+{
+    asm volatile ("cpuid"
+                  : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
+                  : "a" (leaf), "c" (subleaf));
+}
+
+static void cpuid(uint32_t leaf,
+                  uint32_t *eax, uint32_t *ebx,
+                  uint32_t *ecx, uint32_t *edx)
+{
+    cpuid_count(leaf, 0, eax, ebx, ecx, edx);
+}
+
+static int get_processor_brand_string(char *str)
+{
+    uint32_t *parts = (uint32_t*)str;
+    uint32_t max_extd_leaf, dummy;
+
+    cpuid(0x80000000, &max_extd_leaf, &dummy, &dummy, &dummy);
+
+    if ( max_extd_leaf < 0x80000004 )
+        return -1;
+
+    cpuid(0x80000002, &parts[0], &parts[1], &parts[2],  &parts[3]);
+    cpuid(0x80000003, &parts[4], &parts[5], &parts[6],  &parts[7]);
+    cpuid(0x80000004, &parts[8], &parts[9], &parts[10], &parts[11]);
+
+    return 0;
+}
+
+int write_tsc_info(struct xc_sr_context *ctx)
+{
+    xc_interface *xch = ctx->xch;
+    struct xc_sr_rec_tsc_info tsc = { 0 };
+    struct xc_sr_record rec =
+    {
+        .type = REC_TYPE_TSC_INFO,
+        .length = sizeof(tsc),
+        .data = &tsc
+    };
+
+    if ( xc_domain_get_tsc_info(xch, ctx->domid, &tsc.mode,
+                                &tsc.nsec, &tsc.khz, &tsc.incarnation) < 0 )
+    {
+        PERROR("Unable to obtain TSC information");
+        return -1;
+    }
+
+    return write_record(ctx, &rec);
+}
+
+int handle_tsc_info(struct xc_sr_context *ctx, struct xc_sr_record *rec)
+{
+    xc_interface *xch = ctx->xch;
+    struct xc_sr_rec_tsc_info *tsc = rec->data;
+
+    if ( rec->length != sizeof(*tsc) )
+    {
+        ERROR("TSC_INFO record wrong size: length %"PRIu32", expected %zu",
+              rec->length, sizeof(*tsc));
+        return -1;
+    }
+
+    if ( xc_domain_set_tsc_info(xch, ctx->domid, tsc->mode,
+                                tsc->nsec, tsc->khz, tsc->incarnation) )
+    {
+        PERROR("Unable to set TSC information");
+        return -1;
+    }
+
+    return 0;
+}
+
+int arch_write_saving_cpu(struct xc_sr_context *ctx)
+{
+    xc_interface *xch = ctx->xch;
+    char *brand_string = alloca(49); /* 48 from cpuid, and NUL. */
+    struct xc_sr_record rec;
+
+    if ( get_processor_brand_string(brand_string) )
+    {
+        ERROR("Failed to obtain cpuid long processor brand string");
+        return -1;
+    }
+
+    brand_string[48] = '\0';
+    while ( *brand_string == ' ' ) /* Strip leading spaces. */
+        brand_string++;
+
+    rec.type = REC_TYPE_SAVING_CPU;
+    rec.length = strlen(brand_string);
+    rec.data = brand_string;
+
+    return write_record(ctx, &rec);
+}
+
+int arch_handle_saving_cpu(struct xc_sr_context *ctx, struct xc_sr_record *rec)
+{
+    xc_interface *xch = ctx->xch;
+    char *brand_string = alloca(49); /* 48 from cpuid, and NUL. */
+
+    if ( rec->length == 0 )
+        return 0;
+
+    DPRINTF("Saving cpu was '%*s'",
+            (int)rec->length, (char*)rec->data);
+
+    if ( !get_processor_brand_string(brand_string) )
+    {
+        brand_string[48] = '\0';
+        while ( *brand_string == ' ' ) /* Strip leading spaces. */
+            brand_string++;
+
+        DPRINTF("Current cpu is '%s'", brand_string);
+    }
+
+    return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/libxc/saverestore/common_x86.h b/tools/libxc/saverestore/common_x86.h
new file mode 100644
index 0000000..5971bc5
--- /dev/null
+++ b/tools/libxc/saverestore/common_x86.h
@@ -0,0 +1,26 @@
+#ifndef __COMMON_X86__H
+#define __COMMON_X86__H
+
+#include "common.h"
+
+/*
+ * Obtains a domains TSC information from Xen and writes a TSC_INFO record
+ * into the stream.
+ */
+int write_tsc_info(struct xc_sr_context *ctx);
+
+/*
+ * Parses a TSC_INFO record and applies the result to the domain.
+ */
+int handle_tsc_info(struct xc_sr_context *ctx, struct xc_sr_record *rec);
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
1.7.10.4

  parent reply	other threads:[~2014-07-07 17:37 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-07 17:37 [PATCH v6 0/13] Migration Stream v2 Andrew Cooper
2014-07-07 17:37 ` [Patch v6 01/13] docs: libxc migration stream specification Andrew Cooper
2014-07-08  3:53   ` Hongyang Yang
2014-07-08  8:48     ` Andrew Cooper
2014-07-08  8:59       ` Hongyang Yang
2014-07-08  9:36   ` David Vrabel
2014-07-08 10:48     ` Andrew Cooper
2014-07-07 17:37 ` [Patch v6 02/13] tools/python: Scripts relating to migrationv2 streams Andrew Cooper
2014-07-28 15:20   ` Ian Campbell
2014-07-28 15:38     ` Andrew Cooper
2014-07-28 15:58       ` Ian Campbell
2014-07-29 13:55         ` Jon Ludlam
2014-07-07 17:37 ` [Patch v6 03/13] [HACK] tools/libxc: save/restore v2 framework Andrew Cooper
2014-07-07 17:37 ` [Patch v6 04/13] tools/libxc: C implementation of stream format Andrew Cooper
2014-07-07 17:37 ` [Patch v6 05/13] tools/libxc: noarch common code Andrew Cooper
2014-07-07 17:37 ` Andrew Cooper [this message]
2014-07-07 17:37 ` [Patch v6 07/13] tools/libxc: x86 PV " Andrew Cooper
2014-07-07 17:37 ` [Patch v6 08/13] tools/libxc: x86 PV save code Andrew Cooper
2014-07-07 17:37 ` [Patch v6 09/13] tools/libxc: x86 PV restore code Andrew Cooper
2014-07-07 17:37 ` [Patch v6 10/13] tools/libxc: x86 HVM save code Andrew Cooper
2014-07-07 17:38 ` [Patch v6 11/13] tools/libxc: x86 HVM restore code Andrew Cooper
2014-07-18 14:38   ` Wen Congyang
2014-07-18 15:09     ` Andrew Cooper
2014-07-18 15:42       ` Paul Durrant
2014-07-18 16:13         ` Wen Congyang
2014-07-07 17:38 ` [Patch v6 12/13] tools/libxc: noarch save code Andrew Cooper
2014-07-07 17:38 ` [Patch v6 13/13] tools/libxc: noarch restore code Andrew Cooper
2014-07-08 10:50 ` [PATCH v6 0/13] Migration Stream v2 David Vrabel
2014-07-08 11:10   ` Ian Campbell
2014-07-08 16:35 ` Konrad Rzeszutek Wilk
2014-07-08 17:35   ` Andrew Cooper
2014-07-09  6:01     ` Hongyang Yang
2014-07-09  9:40       ` Andrew Cooper
2014-07-09 15:27         ` Konrad Rzeszutek Wilk
2014-07-10 10:19           ` Andrew Cooper
2014-07-28 15:01 ` Ian Campbell
2014-07-28 15:02   ` Andrew Cooper
2014-07-28 15:20     ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404754682-28379-7-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.