From: Alexander Graf <agraf@suse.de>
To: qemu-ppc@nongnu.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 073/118] spapr: Add support for time base offset migration
Date: Wed, 4 Jun 2014 14:44:14 +0200 [thread overview]
Message-ID: <1401885899-16524-74-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1401885899-16524-1-git-send-email-agraf@suse.de>
From: Alexey Kardashevskiy <aik@ozlabs.ru>
This allows guests to have a different timebase origin from the host.
This is needed for migration, where a guest can migrate from one host
to another and the two hosts might have a different timebase origin.
However, the timebase seen by the guest must not go backwards, and
should go forwards only by a small amount corresponding to the time
taken for the migration.
This is only supported for recent POWER hardware which has the TBU40
(timebase upper 40 bits) register. That includes POWER6, 7, 8 but not
970.
This adds kvm_access_one_reg() to access a special register which is not
in env->spr. This requires kvm_set_one_reg/kvm_get_one_reg patch.
The feature must be present in the host kernel.
This bumps vmstate_spapr::version_id and enables new vmstate_ppc_timebase
only for it. Since the vmstate_spapr::minimum_version_id remains
unchanged, migration from older QEMU is supported but without
vmstate_ppc_timebase.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
hw/ppc/ppc.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++
hw/ppc/spapr.c | 4 +--
include/hw/ppc/spapr.h | 1 +
target-ppc/cpu-qom.h | 16 ++++++++++
target-ppc/kvm.c | 5 ++++
trace-events | 3 ++
6 files changed, 106 insertions(+), 2 deletions(-)
diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index 71df471..bec82cd 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -29,9 +29,11 @@
#include "sysemu/cpus.h"
#include "hw/timer/m48t59.h"
#include "qemu/log.h"
+#include "qemu/error-report.h"
#include "hw/loader.h"
#include "sysemu/kvm.h"
#include "kvm_ppc.h"
+#include "trace.h"
//#define PPC_DEBUG_IRQ
//#define PPC_DEBUG_TB
@@ -49,6 +51,8 @@
# define LOG_TB(...) do { } while (0)
#endif
+#define NSEC_PER_SEC 1000000000LL
+
static void cpu_ppc_tb_stop (CPUPPCState *env);
static void cpu_ppc_tb_start (CPUPPCState *env);
@@ -829,6 +833,81 @@ static void cpu_ppc_set_tb_clk (void *opaque, uint32_t freq)
cpu_ppc_store_purr(cpu, 0x0000000000000000ULL);
}
+static void timebase_pre_save(void *opaque)
+{
+ PPCTimebase *tb = opaque;
+ uint64_t ticks = cpu_get_real_ticks();
+ PowerPCCPU *first_ppc_cpu = POWERPC_CPU(first_cpu);
+
+ if (!first_ppc_cpu->env.tb_env) {
+ error_report("No timebase object");
+ return;
+ }
+
+ tb->time_of_the_day_ns = get_clock_realtime();
+ /*
+ * tb_offset is only expected to be changed by migration so
+ * there is no need to update it from KVM here
+ */
+ tb->guest_timebase = ticks + first_ppc_cpu->env.tb_env->tb_offset;
+}
+
+static int timebase_post_load(void *opaque, int version_id)
+{
+ PPCTimebase *tb_remote = opaque;
+ CPUState *cpu;
+ PowerPCCPU *first_ppc_cpu = POWERPC_CPU(first_cpu);
+ int64_t tb_off_adj, tb_off, ns_diff;
+ int64_t migration_duration_ns, migration_duration_tb, guest_tb, host_ns;
+ unsigned long freq;
+
+ if (!first_ppc_cpu->env.tb_env) {
+ error_report("No timebase object");
+ return -1;
+ }
+
+ freq = first_ppc_cpu->env.tb_env->tb_freq;
+ /*
+ * Calculate timebase on the destination side of migration.
+ * The destination timebase must be not less than the source timebase.
+ * We try to adjust timebase by downtime if host clocks are not
+ * too much out of sync (1 second for now).
+ */
+ host_ns = get_clock_realtime();
+ ns_diff = MAX(0, host_ns - tb_remote->time_of_the_day_ns);
+ migration_duration_ns = MIN(NSEC_PER_SEC, ns_diff);
+ migration_duration_tb = muldiv64(migration_duration_ns, freq, NSEC_PER_SEC);
+ guest_tb = tb_remote->guest_timebase + MIN(0, migration_duration_tb);
+
+ tb_off_adj = guest_tb - cpu_get_real_ticks();
+
+ tb_off = first_ppc_cpu->env.tb_env->tb_offset;
+ trace_ppc_tb_adjust(tb_off, tb_off_adj, tb_off_adj - tb_off,
+ (tb_off_adj - tb_off) / freq);
+
+ /* Set new offset to all CPUs */
+ CPU_FOREACH(cpu) {
+ PowerPCCPU *pcpu = POWERPC_CPU(cpu);
+ pcpu->env.tb_env->tb_offset = tb_off_adj;
+ }
+
+ return 0;
+}
+
+const VMStateDescription vmstate_ppc_timebase = {
+ .name = "timebase",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .minimum_version_id_old = 1,
+ .pre_save = timebase_pre_save,
+ .post_load = timebase_post_load,
+ .fields = (VMStateField []) {
+ VMSTATE_UINT64(guest_timebase, PPCTimebase),
+ VMSTATE_INT64(time_of_the_day_ns, PPCTimebase),
+ VMSTATE_END_OF_LIST()
+ },
+};
+
/* Set up (once) timebase frequency (in Hz) */
clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t freq)
{
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 57e9578..fba8686 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -817,7 +817,7 @@ static int spapr_vga_init(PCIBus *pci_bus)
static const VMStateDescription vmstate_spapr = {
.name = "spapr",
- .version_id = 1,
+ .version_id = 2,
.minimum_version_id = 1,
.minimum_version_id_old = 1,
.fields = (VMStateField []) {
@@ -825,7 +825,7 @@ static const VMStateDescription vmstate_spapr = {
/* RTC offset */
VMSTATE_UINT64(rtc_offset, sPAPREnvironment),
-
+ VMSTATE_PPC_TIMEBASE_V(tb, sPAPREnvironment, 2),
VMSTATE_END_OF_LIST()
},
};
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 5fdac1e..9f8bb89 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -29,6 +29,7 @@ typedef struct sPAPREnvironment {
target_ulong entry_point;
uint32_t next_irq;
uint64_t rtc_offset;
+ struct PPCTimebase tb;
bool has_graphics;
uint32_t epow_irq;
diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h
index 47dc8e6..d926d93 100644
--- a/target-ppc/cpu-qom.h
+++ b/target-ppc/cpu-qom.h
@@ -120,6 +120,22 @@ int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
int cpuid, void *opaque);
#ifndef CONFIG_USER_ONLY
extern const struct VMStateDescription vmstate_ppc_cpu;
+
+typedef struct PPCTimebase {
+ uint64_t guest_timebase;
+ int64_t time_of_the_day_ns;
+} PPCTimebase;
+
+extern const struct VMStateDescription vmstate_ppc_timebase;
+
+#define VMSTATE_PPC_TIMEBASE_V(_field, _state, _version) { \
+ .name = (stringify(_field)), \
+ .version_id = (_version), \
+ .size = sizeof(PPCTimebase), \
+ .vmsd = &vmstate_ppc_timebase, \
+ .flags = VMS_STRUCT, \
+ .offset = vmstate_offset_value(_state, _field, PPCTimebase), \
+}
#endif
#endif
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 0744f51..ca31027 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -35,6 +35,7 @@
#include "hw/sysbus.h"
#include "hw/ppc/spapr.h"
#include "hw/ppc/spapr_vio.h"
+#include "hw/ppc/ppc.h"
#include "sysemu/watchdog.h"
#include "trace.h"
@@ -865,6 +866,8 @@ int kvm_arch_put_registers(CPUState *cs, int level)
DPRINTF("Warning: Unable to set VPA information to KVM\n");
}
}
+
+ kvm_set_one_reg(cs, KVM_REG_PPC_TB_OFFSET, &env->tb_env->tb_offset);
#endif /* TARGET_PPC64 */
}
@@ -1089,6 +1092,8 @@ int kvm_arch_get_registers(CPUState *cs)
DPRINTF("Warning: Unable to get VPA information from KVM\n");
}
}
+
+ kvm_get_one_reg(cs, KVM_REG_PPC_TB_OFFSET, &env->tb_env->tb_offset);
#endif
}
diff --git a/trace-events b/trace-events
index ffe6e62..ea6c5fd 100644
--- a/trace-events
+++ b/trace-events
@@ -1195,6 +1195,9 @@ spapr_iommu_get(uint64_t liobn, uint64_t ioba, uint64_t ret, uint64_t tce) "liob
spapr_iommu_xlate(uint64_t liobn, uint64_t ioba, uint64_t tce, unsigned perm, unsigned pgsize) "liobn=%"PRIx64" 0x%"PRIx64" -> 0x%"PRIx64" perm=%u mask=%x"
spapr_iommu_new_table(uint64_t liobn, void *tcet, void *table, int fd) "liobn=%"PRIx64" tcet=%p table=%p fd=%d"
+# hw/ppc/ppc.c
+ppc_tb_adjust(uint64_t offs1, uint64_t offs2, int64_t diff, int64_t seconds) "adjusted from 0x%"PRIx64" to 0x%"PRIx64", diff %"PRId64" (%"PRId64"s)"
+
# util/hbitmap.c
hbitmap_iter_skip_words(const void *hb, void *hbi, uint64_t pos, unsigned long cur) "hb %p hbi %p pos %"PRId64" cur 0x%lx"
hbitmap_reset(void *hb, uint64_t start, uint64_t count, uint64_t sbit, uint64_t ebit) "hb %p items %"PRIu64",%"PRIu64" bits %"PRIu64"..%"PRIu64
--
1.8.1.4
next prev parent reply other threads:[~2014-06-04 12:46 UTC|newest]
Thread overview: 94+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-04 12:43 [Qemu-devel] [PULL 00/118] ppc patch queue 2014-06-04 Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 001/118] target-ppc: Fix target_disas Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 002/118] monitor: QEMU Monitor Instruction Disassembly Incorrect for PowerPC LE Mode Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 003/118] Fix typo in eTSEC Ethernet controller Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 004/118] spapr_nvram: Correct max nvram size Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 005/118] target-ppc: extract register length calculation in gdbstub Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 006/118] target-ppc: gdbstub allow byte swapping for reading/writing registers Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 007/118] target-ppc: Create versionless CPU class per family if KVM Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 008/118] target-ppc: Move alias lookup after class lookup Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 009/118] target-ppc: Remove redundant POWER7 declarations Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 010/118] spapr-pci: remove io ports workaround Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 011/118] spapr_pci: Fix number of returned vectors in ibm, change-msi Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 012/118] target-ppc: Eliminate Magic Number MSR Masks Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 013/118] target-ppc: Remove PVR check from migration Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 014/118] mac99: Added FW_CFG_PPC_BUSFREQ to match CLOCKFREQ and TBFREQ already there Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 015/118] libdecnumber: Introduce libdecnumber Code Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 016/118] libdecnumber: Eliminate #include *Symbols.h Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 017/118] libdecnumber: Prepare libdecnumber for QEMU include structure Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 018/118] libdecnumber: Modify dconfig.h to Integrate with QEMU Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 019/118] libdecnumber: Change gstdint.h to stdint.h Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 020/118] libdecnumber: Eliminate redundant declarations Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 021/118] libdecnumber: Eliminate Unused Variable in decSetSubnormal Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 022/118] target-ppc: Enable Building of libdecnumber Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 023/118] libdecnumber: Introduce decNumberFrom[U]Int64 Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 024/118] libdecnumber: Introduce decNumberIntegralToInt64 Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 025/118] libdecnumber: Fix decNumberSetBCD Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 026/118] target-ppc: Define FPR Pointer Type for Helpers Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 027/118] target-ppc: Introduce Generator Macros for DFP Arithmetic Forms Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 028/118] target-ppc: Introduce Decoder Macros for DFP Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 029/118] target-ppc: Introduce DFP Helper Utilities Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 030/118] target-ppc: Introduce DFP Post Processor Utilities Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 031/118] target-ppc: Introduce DFP Add Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 032/118] target-ppc: Introduce DFP Subtract Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 033/118] target-ppc: Introduce DFP Multiply Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 034/118] target-ppc: Introduce DFP Divide Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 035/118] target-ppc: Introduce DFP Compares Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 036/118] target-ppc: Introduce DFP Test Data Class Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 037/118] target-ppc: Introduce DFP Test Data Group Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 038/118] target-ppc: Introduce DFP Test Exponent Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 039/118] target-ppc: Introduce DFP Test Significance Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 040/118] target-ppc: Introduce DFP Quantize Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 041/118] target-ppc: Introduce DFP Reround Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 042/118] target-ppc: Introduce DFP Round to Integer Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 043/118] target-ppc: Introduce DFP Convert to Long/Extended Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 044/118] target-ppc: Introduce Round to DFP Short/Long Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 045/118] target-ppc: Introduce DFP Convert to Fixed Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 046/118] " Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 047/118] target-ppc: Introduce DFP Decode DPD to BCD Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 048/118] target-ppc: Introduce DFP Encode BCD to DPD Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 049/118] target-ppc: Introduce DFP Extract Biased Exponent Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 050/118] target-ppc: Introduce DFP Insert " Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 051/118] target-ppc: Introduce DFP Shift Significand Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 052/118] spapr_pci: fix MSI limit Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 053/118] util: Add S-Box and InvS-Box Arrays to Common AES Utils Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 054/118] util: Add AES ShiftRows and InvShiftRows Tables Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 055/118] util: Add InvMixColumns Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 056/118] target-i386: Use Common ShiftRows and InvShiftRows Tables Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 057/118] target-arm: Use Common Tables in AES Instructions Alexander Graf
2014-06-04 12:43 ` [Qemu-devel] [PULL 058/118] target-ppc: Refactor " Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 059/118] KVM: PPC: Don't secretly add 1T segment feature to CPU Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 060/118] PPC: e500: some pci related cleanup Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 061/118] PPC: e500: implement PCI INTx routing Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 062/118] PPC: Fix TCG chunks that don't free their temps Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 063/118] PPC: Fail on leaking temporaries Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 064/118] PPC: Make all e500 CPUs SVR aware Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 065/118] PPC: Add definitions for GIVORs Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 066/118] PPC: Fix SPR access control of L1CFG0 Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 067/118] PPC: Add L1CFG1 SPR emulation Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 068/118] PPC: Properly emulate L1CSR0 and L1CSR1 Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 069/118] PPC: Add dcbtls emulation Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 070/118] PPC: e500: Expose kernel load address in dt Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 071/118] PPC: Add u-boot firmware for e500 Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 072/118] PPC: e500: Move to u-boot as firmware Alexander Graf
2014-06-04 12:44 ` Alexander Graf [this message]
2014-06-04 12:44 ` [Qemu-devel] [PULL 074/118] spapr: Add ibm, chip-id property in device tree Alexander Graf
2014-06-04 12:44 ` [Qemu-devel] [PULL 075/118] macio: handle non-block ATAPI DMA transfers Alexander Graf
2014-06-20 14:29 ` Mark Cave-Ayland
2014-06-20 19:17 ` BALATON Zoltan
2014-06-20 19:27 ` Mark Cave-Ayland
2014-06-21 0:57 ` BALATON Zoltan
2014-06-23 16:31 ` Alexander Graf
2014-06-23 19:26 ` BALATON Zoltan
2014-06-23 22:41 ` Mark Cave-Ayland
2014-06-24 10:35 ` Kevin Wolf
2014-06-24 10:53 ` BALATON Zoltan
2014-06-24 11:02 ` Alexander Graf
2014-06-24 11:22 ` Kevin Wolf
2014-06-24 11:27 ` Alexander Graf
2014-06-24 12:07 ` Kevin Wolf
2014-06-24 12:10 ` Alexander Graf
2014-06-25 20:17 ` Mark Cave-Ayland
2014-06-25 21:48 ` BALATON Zoltan
2014-06-23 21:30 ` BALATON Zoltan
2014-06-05 19:10 ` [Qemu-devel] [PULL 00/118] ppc patch queue 2014-06-04 Peter Maydell
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=1401885899-16524-74-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=aik@ozlabs.ru \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).