@@ -155,6 +155,38 @@ The record body contains the following fields:
| `buffer` | The shared info (`length` being architecture |
| | dependent[4]) |
+### TSC_INFO
+
+```
+ 0 1 2 3 4 5 6 7 octet
++-------+-------+-------+-------+-------+-------+-------+-------+
+| type == 3 | instance == 0 |
++-------------------------------+-------------------------------+
+| length == 20 |
++-------------------------------+-------------------------------+
+| mode | khz |
++-------------------------------+-------------------------------+
+| nsec |
++-------------------------------+-------------------------------+
+| incarnation |
++-------------------------------+
+```
+
+The record body contains the following fields:
+
+| Field | Description |
+|---------------|-----------------------------------------------|
+| `mode` | 0x00000000: Default (emulate if necessary) |
+| | 0x00000001: Always emulate |
+| | 0x00000002: Never emulate |
+| | |
+| `khz` | The TSC frequency in kHz |
+| | |
+| `nsec` | Elapsed time in nanoseconds |
+| | |
+| `incarnation` | Incarnation (counter indicating how many |
+| | times the TSC value has been set) |
+
* * *
[1] See https://xenbits.xen.org/gitweb/?p=xen.git;a=blob;f=docs/designs/non-cooperative-migration.md
@@ -136,6 +136,17 @@ static void dump_shared_info(void)
#undef GET_FIELD_PTR
}
+static void dump_tsc_info(void)
+{
+ struct domain_context_tsc_info *t;
+
+ GET_PTR(t);
+
+ printf(" TSC_INFO: mode: %u incarnation: %u\n"
+ " khz %u nsec: %"PRIu64"\n",
+ t->mode, t->incarnation, t->khz, t->nsec);
+}
+
static void dump_end(void)
{
struct domain_context_end *e;
@@ -225,6 +236,7 @@ int main(int argc, char **argv)
{
case DOMAIN_CONTEXT_START: dump_start(); break;
case DOMAIN_CONTEXT_SHARED_INFO: dump_shared_info(); break;
+ case DOMAIN_CONTEXT_TSC_INFO: dump_tsc_info(); break;
case DOMAIN_CONTEXT_END: dump_end(); break;
default:
printf("Unknown type %u: skipping\n", rec->type);
@@ -26,6 +26,7 @@
#include <xen/symbols.h>
#include <xen/keyhandler.h>
#include <xen/guest_access.h>
+#include <xen/save.h>
#include <asm/io.h>
#include <asm/iocap.h>
#include <asm/msr.h>
@@ -2451,6 +2452,35 @@ int tsc_set_info(struct domain *d,
return 0;
}
+static int save_tsc_info(struct domain *d, struct domain_ctxt_state *c,
+ bool dry_run)
+{
+ struct domain_context_tsc_info t = {};
+
+ if ( !dry_run )
+ tsc_get_info(d, &t.mode, &t.nsec, &t.khz, &t.incarnation);
+
+ return domain_save_ctxt_rec(c, DOMAIN_CONTEXT_TSC_INFO, 0, &t, sizeof(t));
+}
+
+static int load_tsc_info(struct domain *d, struct domain_ctxt_state *c)
+{
+ struct domain_context_tsc_info t;
+ unsigned int i;
+ int rc;
+
+ rc = domain_load_ctxt_rec(c, DOMAIN_CONTEXT_TSC_INFO, &i, &t, sizeof(t));
+ if ( rc )
+ return rc;
+
+ if ( i ) /* expect only a single instance */
+ return -ENXIO;
+
+ return tsc_set_info(d, t.mode, t.nsec, t.khz, t.incarnation);
+}
+
+DOMAIN_REGISTER_CTXT_TYPE(TSC_INFO, save_tsc_info, load_tsc_info);
+
/* vtsc may incur measurable performance degradation, diagnose with this */
static void dump_softtsc(unsigned char key)
{
@@ -50,6 +50,7 @@ enum {
DOMAIN_CONTEXT_END,
DOMAIN_CONTEXT_START,
DOMAIN_CONTEXT_SHARED_INFO,
+ DOMAIN_CONTEXT_TSC_INFO,
/* New types go here */
DOMAIN_CONTEXT_NR_TYPES
};
@@ -69,6 +70,13 @@ struct domain_context_shared_info {
uint8_t buffer[XEN_FLEX_ARRAY_DIM];
};
+struct domain_context_tsc_info {
+ uint32_t mode;
+ uint32_t khz;
+ uint64_t nsec;
+ uint32_t incarnation;
+};
+
/* Terminating entry */
struct domain_context_end {};