* Re: [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate
@ 2014-07-31 15:49 Pavel Dovgalyuk
2014-07-31 15:55 ` Eric Blake
2014-07-31 16:20 ` Paolo Bonzini
0 siblings, 2 replies; 5+ messages in thread
From: Pavel Dovgalyuk @ 2014-07-31 15:49 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel
Cc: peter.maydell, peter.crosthwaite, mark.burton, real, batuzovk,
maria.klimushenkova@ispras.ru, afaerber, fred.konrad
[-- Attachment #1: Type: text/plain, Size: 9685 bytes --]
We cannot calculate timers in post_load, because it requires correct value of virtual clock. And at that moment replay data structures could be not loaded yet.
Sent from mobile device
-------- Исходное сообщение --------
От: Paolo Bonzini <pbonzini@redhat.com>
Дата:31.07.2014 18:14 (GMT+04:00)
Кому: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>,qemu-devel@nongnu.org
Копия: peter.maydell@linaro.org,peter.crosthwaite@xilinx.com,mark.burton@greensocs.com,real@ispras.ru,batuzovk@ispras.ru,maria.klimushenkova@ispras.ru,eblake@redhat.com,afaerber@suse.de,fred.konrad@greensocs.com
Тема: Re: [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate
Il 31/07/2014 14:54, Pavel Dovgalyuk ha scritto:
> +static bool rtl8139_TimerExpire_needed(void *opaque)
> +{
> + RTL8139State *s = (RTL8139State *)opaque;
> + return s->TimerExpire != 0;
> +}
> +
> +static const VMStateDescription vmstate_rtl8139_TimerExpire = {
> + .name = "rtl8139/TimerExpire",
> + .version_id = 1,
> + .minimum_version_id = 1,
> + .fields = (VMStateField[]) {
> + VMSTATE_INT64(TimerExpire, RTL8139State),
> + VMSTATE_END_OF_LIST()
> + }
> +};
> +
> +static bool rtl8139_timer_needed(void *opaque)
> +{
> + RTL8139State *s = (RTL8139State *)opaque;
> + return timer_pending(s->timer);
> +}
I think this is needed only because of the complicated logic to compute
PCSTimeout on the fly when IntrStatus/IntrMask change or are read.
But we can just eliminate it, and leave the timer always set when
TimerInt is nonzero.
rtl8139_set_next_tctr_time should now be idempotent and deterministic.
Then it can be set in rtl8139_post_load.
---------------- 8< ---------------
From: Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH] rtl8139: simplify timer logic
Pavel Dovgalyuk reports that TimerExpire and the timer are not restored
correctly on the receiving end of migration.
It is not clear to me whether this is really the case, but we can take
the occasion to get rid of the complicated code that computes PCSTimeout
on the fly upon changes to IntrStatus/IntrMask. Just always keep a
timer running, it will fire every ~130 seconds at most if the interrupt
is masked with TimerInt != 0.
This makes rtl8139_set_next_tctr_time idempotent (when called with
wrap_on_overflow == false, as is the case from the post_load callback).
Not-tested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
index 90bc5ec..430eab3 100644
--- a/hw/net/rtl8139.c
+++ b/hw/net/rtl8139.c
@@ -508,7 +508,6 @@ typedef struct RTL8139State {
/* PCI interrupt timer */
QEMUTimer *timer;
- int64_t TimerExpire;
MemoryRegion bar_io;
MemoryRegion bar_mem;
@@ -520,7 +519,7 @@ typedef struct RTL8139State {
/* Writes tally counters to memory via DMA */
static void RTL8139TallyCounters_dma_write(RTL8139State *s, dma_addr_t tc_addr);
-static void rtl8139_set_next_tctr_time(RTL8139State *s, int64_t current_time);
+static void rtl8139_set_next_tctr_time(RTL8139State *s, bool wrap_on_overflow);
static void prom9346_decode_command(EEprom9346 *eeprom, uint8_t command)
{
@@ -1282,6 +1281,7 @@ static void rtl8139_reset(DeviceState *d)
s->TCTR = 0;
s->TimerInt = 0;
s->TCTR_base = 0;
+ rtl8139_set_next_tctr_time(s, false);
/* reset tally counters */
RTL8139TallyCounters_clear(&s->tally_counters);
@@ -2648,7 +2648,6 @@ static void rtl8139_IntrMask_write(RTL8139State *s, uint32_t val)
s->IntrMask = val;
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
rtl8139_update_irq(s);
}
@@ -2683,13 +2682,7 @@ static void rtl8139_IntrStatus_write(RTL8139State *s, uint32_t val)
rtl8139_update_irq(s);
s->IntrStatus = newStatus;
- /*
- * Computing if we miss an interrupt here is not that correct but
- * considered that we should have had already an interrupt
- * and probably emulated is slower is better to assume this resetting was
- * done before testing on previous rtl8139_update_irq lead to IRQ losing
- */
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+ rtl8139_set_next_tctr_time(s, true);
rtl8139_update_irq(s);
#endif
@@ -2697,8 +2690,6 @@ static void rtl8139_IntrStatus_write(RTL8139State *s, uint32_t val)
static uint32_t rtl8139_IntrStatus_read(RTL8139State *s)
{
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
-
uint32_t ret = s->IntrStatus;
DPRINTF("IntrStatus read(w) val=0x%04x\n", ret);
@@ -2881,43 +2872,25 @@ static void rtl8139_io_writew(void *opaque, uint8_t addr, uint32_t val)
}
}
-static void rtl8139_set_next_tctr_time(RTL8139State *s, int64_t current_time)
+static void rtl8139_set_next_tctr_time(RTL8139State *s, bool wrap_on_overflow)
{
- int64_t pci_time, next_time;
- uint32_t low_pci;
+ int64_t delta;
DPRINTF("entered rtl8139_set_next_tctr_time\n");
- if (s->TimerExpire && current_time >= s->TimerExpire) {
- s->IntrStatus |= PCSTimeout;
- rtl8139_update_irq(s);
- }
-
- /* Set QEMU timer only if needed that is
- * - TimerInt <> 0 (we have a timer)
- * - mask = 1 (we want an interrupt timer)
- * - irq = 0 (irq is not already active)
- * If any of above change we need to compute timer again
- * Also we must check if timer is passed without QEMU timer
- */
- s->TimerExpire = 0;
if (!s->TimerInt) {
- return;
- }
-
- pci_time = muldiv64(current_time - s->TCTR_base, PCI_FREQUENCY,
- get_ticks_per_sec());
- low_pci = pci_time & 0xffffffff;
- pci_time = pci_time - low_pci + s->TimerInt;
- if (low_pci >= s->TimerInt) {
- pci_time += 0x100000000LL;
- }
- next_time = s->TCTR_base + muldiv64(pci_time, get_ticks_per_sec(),
- PCI_FREQUENCY);
- s->TimerExpire = next_time;
-
- if ((s->IntrMask & PCSTimeout) != 0 && (s->IntrStatus & PCSTimeout) == 0) {
- timer_mod(s->timer, next_time);
+ timer_del(s->timer);
+ } else {
+ delta = muldiv64(s->TimerInt, get_ticks_per_sec(), PCI_FREQUENCY);
+ if (wrap_on_overflow &&
+ s->TCTR_base + delta >= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)) {
+ /* The value in the Timer register does not change, but
+ * we're counting up by 2^32 ticks (approx. 130 seconds).
+ */
+ s->TCTR_base += muldiv64(0x100000000LL, get_ticks_per_sec(),
+ PCI_FREQUENCY);
+ }
+ timer_mod(s->timer, s->TCTR_base + delta);
}
}
@@ -2965,14 +2938,14 @@ static void rtl8139_io_writel(void *opaque, uint8_t addr, uint32_t val)
case Timer:
DPRINTF("TCTR Timer reset on write\n");
s->TCTR_base = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
- rtl8139_set_next_tctr_time(s, s->TCTR_base);
+ rtl8139_set_next_tctr_time(s, false);
break;
case FlashReg:
DPRINTF("FlashReg TimerInt write val=0x%08x\n", val);
if (s->TimerInt != val) {
s->TimerInt = val;
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+ rtl8139_set_next_tctr_time(s, true);
}
break;
@@ -3249,7 +3222,7 @@ static uint32_t rtl8139_mmio_readl(void *opaque, hwaddr addr)
static int rtl8139_post_load(void *opaque, int version_id)
{
RTL8139State* s = opaque;
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+ rtl8139_set_next_tctr_time(s, false);
if (version_id < 4) {
s->cplus_enabled = s->CpCmd != 0;
}
@@ -3280,8 +3253,7 @@ static void rtl8139_pre_save(void *opaque)
RTL8139State* s = opaque;
int64_t current_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
- /* set IntrStatus correctly */
- rtl8139_set_next_tctr_time(s, current_time);
+ /* for migration to older versions */
s->TCTR = muldiv64(current_time - s->TCTR_base, PCI_FREQUENCY,
get_ticks_per_sec());
s->rtl8139_mmio_io_addr_dummy = 0;
@@ -3448,7 +3420,7 @@ static void rtl8139_timer(void *opaque)
s->IntrStatus |= PCSTimeout;
rtl8139_update_irq(s);
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+ rtl8139_set_next_tctr_time(s, true);
}
static void rtl8139_cleanup(NetClientState *nc)
@@ -3536,9 +3508,7 @@ static int pci_rtl8139_init(PCIDevice *dev)
s->cplus_txbuffer_len = 0;
s->cplus_txbuffer_offset = 0;
- s->TimerExpire = 0;
s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, rtl8139_timer, s);
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
add_boot_device_path(s->conf.bootindex, d, "/ethernet-phy@0");
[-- Attachment #2: Type: text/html, Size: 13894 bytes --]
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate
2014-07-31 15:49 [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate Pavel Dovgalyuk
@ 2014-07-31 15:55 ` Eric Blake
2014-07-31 16:20 ` Paolo Bonzini
1 sibling, 0 replies; 5+ messages in thread
From: Eric Blake @ 2014-07-31 15:55 UTC (permalink / raw)
To: Pavel Dovgalyuk, Paolo Bonzini, qemu-devel
Cc: peter.maydell, peter.crosthwaite, mark.burton, real, batuzovk,
maria.klimushenkova@ispras.ru, afaerber, fred.konrad
[-- Attachment #1: Type: text/plain, Size: 557 bytes --]
[meta-comment]
On 07/31/2014 09:49 AM, Pavel Dovgalyuk wrote:
> We cannot calculate timers in post_load, because it requires correct value of virtual clock. And at that moment replay data structures could be not loaded yet.
>
>
> Sent from mobile device
Your mobile device is breaking threading. It would be nice to stick to
standards-compliant mailers, for the sake of reviewers trying to read
your messages in threaded context.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 539 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate
2014-07-31 15:49 [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate Pavel Dovgalyuk
2014-07-31 15:55 ` Eric Blake
@ 2014-07-31 16:20 ` Paolo Bonzini
1 sibling, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2014-07-31 16:20 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel
Cc: peter.maydell, peter.crosthwaite, mark.burton, real, batuzovk,
maria.klimushenkova@ispras.ru, afaerber, fred.konrad
Il 31/07/2014 17:49, Pavel Dovgalyuk ha scritto:
> We cannot calculate timers in post_load, because it requires correct
> value of virtual clock. And at that moment replay data structures could
> be not loaded yet.
Then this patch (and similarly others in this early part of the series)
should be properly named "work around deficiencies of replay", not "add
new fields to vmstate".
Replay of course has to do _more_ things than migration. However,
anything that makes replay _different_ from migration, for things that
migration already does, is not going to fly. It means instant bitrot,
and will not be accepted without very good justification.
timers_state is serialized before everything else for a reason. If you
need to serialize more state for replay to work, add it to a subsection
of timers_state that is only included during record.
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [RFC PATCH v3 00/49] Deterministic replay and reverse execution
@ 2014-07-31 12:53 Pavel Dovgalyuk
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate Pavel Dovgalyuk
0 siblings, 1 reply; 5+ messages in thread
From: Pavel Dovgalyuk @ 2014-07-31 12:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, peter.crosthwaite, mark.burton, real, batuzovk,
maria.klimushenkova, pavel.dovgaluk, pbonzini, afaerber,
fred.konrad
This set of patches is related to the reverse execution and deterministic
replay of qemu execution Our implementation of deterministic replay can
be used for deterministic and reverse debugging of guest code through gdb
remote interface.
Execution recording writes non-deterministic events log, which can be later
used for replaying the execution anywhere and for unlimited number of times.
It also supports checkpointing for faster rewinding during reverse debugging.
Execution replaying reads the log and replays all non-deterministic events
including external input, hardware clocks, and interrupts.
Reverse execution has the following features:
* Deterministically replays whole system execution and all contents of the memory,
state of the hadrware devices, clocks, and screen of the VM.
* Writes execution log into the file for latter replaying for multiple times
on different machines.
* Supports i386, x86_64, and ARM hardware platforms.
* Performs deterministic replay of all operations with keyboard, mouse, network adapters,
audio devices, serial interfaces, and physical USB devices connected to the emulator.
* Provides support for gdb reverse debugging commands like reverse-step and reverse-continue.
* Supports auto-checkpointing for convenient reverse debugging.
Usage of the record/replay:
* First, record the execution, by adding '-record fname=replay.bin' to the
command line.
* Then you can replay it for the multiple times by using another command
line option: '-replay fname=replay.bin'
* Virtual machine should have at least one virtual disk, which is used to
store checkpoints. If you want to enable automatic checkpointing, simply
add ',period=XX' to record options, where XX is the checkpointing period
in seconds.
* Using of the network adapters in record/replay mode is possible with
the following command-line options:
- '-net user' (or another host adapter) in record mode
- '-net replay' in replay mode. Every host network adapter should be
replaced by 'replay' when replaying the execution.
* Reverse debugging can be used through gdb remote interface.
reverse-stepi and reverse-continue commands are supported. Other reverse
commands should also work, because they reuse these ones.
* Monitor is extended by the following commands:
- replay_info - prints information about replay mode and current step
(number of instructions executed)
- replay_break - sets "breakpoint" at the specified instructions count.
- replay_seek - rewinds (using the checkpoints, if possible) to the
specified step of replay log.
Paper with short description of deterministic replay implementation:
http://www.computer.org/csdl/proceedings/csmr/2012/4666/00/4666a553-abs.html
Modifications of qemu include:
* adding missed fields of the virtual devices' states to the vmstate
structures to allow deterministic saving and restoring the VM state
* adding virtual clock-based timers to vmstate structures, because virtual
clock is the part of the virtual machine state
* modification of block layer to support automatic creation of the overlay
files to store the changes and snapshots while recording
* disabling of system reset while loading VM state to avoid generating of
interrupts by reset handlers
* adding warpers for clock and time functions to save their return
values in the log
* saving different asynchronous events (e.g. system shutdown) into the log
* synchronization of the bottom halves execution
* synchronization of the threads from thread pool
* recording/replaying user input (mouse and keyboard), input from virtual
serial ports, incoming network packets, input from connected USB devices
* adding HMP/QMP commands to monitor for controlling replay execution
v3 changes:
* Fixed bug with replay of the aio write operations.
* Added virtual clock based on replay icount.
* Removed duplicated saving of interrupt_request CPU field.
* Fixed some coding style issues.
* Renamed QMP commands for controlling reverse execution (as suggested by Eric Blake)
* Replay mode and submode implemented as QAPI enumerations (as suggested by Eric Blake)
* Added description and example for replay-info command (as suggested by Eric Blake)
* Added information about the current breakpoint to the output of replay-info (as suggested by Eric Blake)
* Updated version id for HPET vmstate (as suggested by Paolo Bonzini)
* Removed static fields from parallel vmstate (as suggested by Paolo Bonzini)
* New vmstate fields for mc146818rtc, pckbd, kvmapic, serial, fdc, rtl8139 moved to subsection (as suggested by Paolo Bonzini)
* Disabled textmode cursor blinking, when virtual machine is stopped (as suggested by Paolo Bonzini)
* Extracted saving of exception_index to separate patch (as suggested by Paolo Bonzini)
v2 changes:
* Patches are split to be reviewable and bisectable (as suggested by Kirill Batuzov)
* Added QMP versions of replay commands (as suggested by Eric Blake)
* Removed some optional features of replay to make patches cleaner
* Minor changes and code cleanup were made
---
Pavel Dovgalyuk (49):
acpi: accurate overflow check
integratorcp: adding vmstate for save/restore
pcspk: adding vmstate for save/restore
fdc: adding vmstate for save/restore
parallel: adding vmstate for save/restore
serial: fixing vmstate for save/restore
kvmapic: fixing loading vmstate
hpet: fixing saving and loading process
pckbd: adding new fields to vmstate
rtl8139: adding new fields to vmstate
piix: do not raise irq while loading vmstate
mc146818rtc: add missed field to vmstate
pl031: add missed field to vmstate
ide pci: reset status field before loading the vmstate
softmmu: fixing usage of cpu_st/ld* from helpers
target-i386: update fp status fix
migration: add vmstate for int8 and char arrays
replay: global variables and function stubs
block: add suffix parameter to bdrv_open functions
sysemu: system functions for replay
replay: internal functions for replay log
cpu: invent instruction count for accurate replay
target-arm: instructions counting code for replay
target-i386: instructions counting code for replay
replay: interrupts and exceptions
vga: do not use virtual clock for blinking cursor
replay: asynchronous events infrastructure
replay: recording and replaying clock ticks
replay: recording and replaying different timers
replay: shutdown event
replay: checkpoints
vmclock: add virtual clock based on replay icount
replay: bottom halves
replay: replay aio requests
replay: thread pool
pl031: vmstate in replay mode
replay: initialization and deinitialization
replay: command line options
replay: snapshotting the virtual machine
replay: recording of the user input
tap-win32: destroy the thread at exit
replay: network packets record/replay
replay: audio data record/replay
replay: serial port
replay: USB passthrough
replay: replay_info command
replay: replay_break command
replay: replay_seek_step command
gdbstub: reverse debugging
Makefile.target | 1
arch_init.c | 8
async.c | 46 ++
audio/audio.c | 14 +
audio/audio_win_int.h | 3
audio/winwaveaudio.c | 167 +++++++--
block.c | 140 ++++++-
block/blkdebug.c | 2
block/blkverify.c | 5
block/cow.c | 2
block/qcow.c | 2
block/qcow2.c | 10 -
block/qed.c | 2
block/raw-posix.c | 6
block/raw-win32.c | 4
block/sheepdog.c | 4
block/vmdk.c | 8
block/vvfat.c | 2
blockdev.c | 14 -
cpu-exec.c | 34 +-
cpus.c | 101 +++++
dma-helpers.c | 10 -
exec.c | 12 +
gdbstub.c | 79 +++-
hmp-commands.hx | 41 ++
hw/acpi/core.c | 7
hw/arm/integratorcp.c | 38 ++
hw/audio/pcspk.c | 18 +
hw/block/fdc.c | 85 ++++
hw/block/virtio-blk.c | 10 -
hw/char/parallel.c | 20 +
hw/char/serial.c | 264 ++++++++++++--
hw/display/vga.c | 6
hw/i386/kvmvapic.c | 22 +
hw/ide/ahci.c | 4
hw/ide/atapi.c | 9
hw/ide/core.c | 18 +
hw/ide/pci.c | 11 +
hw/input/pckbd.c | 53 +++
hw/intc/apic_common.c | 56 +++
hw/net/rtl8139.c | 50 +++
hw/pci-host/piix.c | 22 +
hw/timer/arm_timer.c | 2
hw/timer/hpet.c | 15 -
hw/timer/mc146818rtc.c | 37 ++
hw/timer/pl031.c | 38 ++
hw/usb/hcd-uhci.c | 2
hw/usb/host-libusb.c | 551 +++++++++++++++++++----------
include/block/aio.h | 18 +
include/block/block.h | 22 +
include/block/thread-pool.h | 4
include/exec/cpu-defs.h | 2
include/exec/cpu_ldst_template.h | 31 +-
include/exec/exec-all.h | 31 ++
include/hw/host-libusb.h | 105 ++++++
include/hw/i386/apic_internal.h | 2
include/migration/vmstate.h | 13 +
include/qemu-common.h | 3
include/qemu/main-loop.h | 1
include/qemu/timer.h | 48 ++-
include/qom/cpu.h | 3
include/sysemu/char.h | 25 +
include/sysemu/cpus.h | 1
include/sysemu/sysemu.h | 2
include/ui/input.h | 2
main-loop.c | 5
monitor.c | 58 +++
net/Makefile.objs | 1
net/clients.h | 3
net/dump.c | 6
net/hub.c | 1
net/net-replay.c | 68 ++++
net/net.c | 7
net/slirp.c | 14 +
net/socket.c | 35 ++
net/tap-win32.c | 25 +
net/tap.c | 24 +
net/vde.c | 14 +
qapi-schema.json | 102 +++++
qemu-char.c | 56 +++
qemu-img.c | 6
qemu-io-cmds.c | 2
qemu-io.c | 7
qemu-nbd.c | 2
qemu-options.hx | 30 ++
qemu-timer.c | 52 ++-
qmp-commands.hx | 75 ++++
replay/Makefile.objs | 12 +
replay/replay-audio.c | 228 ++++++++++++
replay/replay-char.c | 100 +++++
replay/replay-debug.c | 154 ++++++++
replay/replay-events.c | 382 ++++++++++++++++++++
replay/replay-icount.c | 130 +++++++
replay/replay-input.c | 107 ++++++
replay/replay-internal.c | 159 ++++++++
replay/replay-internal.h | 224 ++++++++++++
replay/replay-net.c | 191 ++++++++++
replay/replay-qmp.c | 58 +++
replay/replay-time.c | 183 ++++++++++
replay/replay-usb.c | 188 ++++++++++
replay/replay.c | 718 ++++++++++++++++++++++++++++++++++++++
replay/replay.h | 214 +++++++++++
savevm.c | 33 +-
slirp/slirp.c | 9
softmmu_template.h | 18 +
stubs/Makefile.objs | 1
stubs/replay.c | 47 ++
target-arm/Makefile.objs | 1
target-arm/helper.h | 3
target-arm/replay_helper.c | 38 ++
target-arm/translate.c | 62 +++
target-i386/Makefile.objs | 1
target-i386/cpu.c | 1
target-i386/cpu.h | 8
target-i386/fpu_helper.c | 5
target-i386/helper.h | 3
target-i386/machine.c | 2
target-i386/replay_helper.c | 38 ++
target-i386/translate.c | 93 ++++-
tests/test-thread-pool.c | 7
thread-pool.c | 53 ++-
trace-events | 2
translate-all.c | 15 +
ui/input.c | 80 +++-
util/iov.c | 4
vl.c | 122 ++++++
vmstate.c | 6
127 files changed, 6102 insertions(+), 559 deletions(-)
create mode 100755 include/hw/host-libusb.h
create mode 100755 net/net-replay.c
create mode 100755 replay/Makefile.objs
create mode 100755 replay/replay-audio.c
create mode 100755 replay/replay-char.c
create mode 100755 replay/replay-debug.c
create mode 100755 replay/replay-events.c
create mode 100755 replay/replay-icount.c
create mode 100755 replay/replay-input.c
create mode 100755 replay/replay-internal.c
create mode 100755 replay/replay-internal.h
create mode 100755 replay/replay-net.c
create mode 100755 replay/replay-qmp.c
create mode 100755 replay/replay-time.c
create mode 100755 replay/replay-usb.c
create mode 100755 replay/replay.c
create mode 100755 replay/replay.h
create mode 100755 stubs/replay.c
create mode 100755 target-arm/replay_helper.c
create mode 100755 target-i386/replay_helper.c
--
Pavel Dovgalyuk
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate
2014-07-31 12:53 [Qemu-devel] [RFC PATCH v3 00/49] Deterministic replay and reverse execution Pavel Dovgalyuk
@ 2014-07-31 12:54 ` Pavel Dovgalyuk
2014-07-31 14:14 ` Paolo Bonzini
0 siblings, 1 reply; 5+ messages in thread
From: Pavel Dovgalyuk @ 2014-07-31 12:54 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, peter.crosthwaite, mark.burton, real, batuzovk,
maria.klimushenkova, pavel.dovgaluk, pbonzini, afaerber,
fred.konrad
This patch adds virtual clock-dependent timers to VMState to allow correct
saving and restoring the state of RTL8139 network controller.
Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
---
hw/net/rtl8139.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
index 90bc5ec..b560c81 100644
--- a/hw/net/rtl8139.c
+++ b/hw/net/rtl8139.c
@@ -3246,10 +3246,17 @@ static uint32_t rtl8139_mmio_readl(void *opaque, hwaddr addr)
return val;
}
+static int rtl8139_pre_load(void *opaque)
+{
+ RTL8139State *s = opaque;
+ s->TimerExpire = 0;
+ timer_del(s->timer);
+ return 0;
+}
+
static int rtl8139_post_load(void *opaque, int version_id)
{
RTL8139State* s = opaque;
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
if (version_id < 4) {
s->cplus_enabled = s->CpCmd != 0;
}
@@ -3275,6 +3282,38 @@ static const VMStateDescription vmstate_rtl8139_hotplug_ready ={
}
};
+static bool rtl8139_TimerExpire_needed(void *opaque)
+{
+ RTL8139State *s = (RTL8139State *)opaque;
+ return s->TimerExpire != 0;
+}
+
+static const VMStateDescription vmstate_rtl8139_TimerExpire = {
+ .name = "rtl8139/TimerExpire",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_INT64(TimerExpire, RTL8139State),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static bool rtl8139_timer_needed(void *opaque)
+{
+ RTL8139State *s = (RTL8139State *)opaque;
+ return timer_pending(s->timer);
+}
+
+static const VMStateDescription vmstate_rtl8139_timer = {
+ .name = "rtl8139/timer",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_TIMER(timer, RTL8139State),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
static void rtl8139_pre_save(void *opaque)
{
RTL8139State* s = opaque;
@@ -3289,8 +3328,9 @@ static void rtl8139_pre_save(void *opaque)
static const VMStateDescription vmstate_rtl8139 = {
.name = "rtl8139",
- .version_id = 4,
+ .version_id = 5,
.minimum_version_id = 3,
+ .pre_load = rtl8139_pre_load,
.post_load = rtl8139_post_load,
.pre_save = rtl8139_pre_save,
.fields = (VMStateField[]) {
@@ -3371,6 +3411,12 @@ static const VMStateDescription vmstate_rtl8139 = {
.vmsd = &vmstate_rtl8139_hotplug_ready,
.needed = rtl8139_hotplug_ready_needed,
}, {
+ .vmsd = &vmstate_rtl8139_TimerExpire,
+ .needed = rtl8139_TimerExpire_needed,
+ }, {
+ .vmsd = &vmstate_rtl8139_timer,
+ .needed = rtl8139_timer_needed,
+ }, {
/* empty */
}
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate Pavel Dovgalyuk
@ 2014-07-31 14:14 ` Paolo Bonzini
0 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2014-07-31 14:14 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel
Cc: peter.maydell, peter.crosthwaite, mark.burton, real, batuzovk,
maria.klimushenkova, afaerber, fred.konrad
Il 31/07/2014 14:54, Pavel Dovgalyuk ha scritto:
> +static bool rtl8139_TimerExpire_needed(void *opaque)
> +{
> + RTL8139State *s = (RTL8139State *)opaque;
> + return s->TimerExpire != 0;
> +}
> +
> +static const VMStateDescription vmstate_rtl8139_TimerExpire = {
> + .name = "rtl8139/TimerExpire",
> + .version_id = 1,
> + .minimum_version_id = 1,
> + .fields = (VMStateField[]) {
> + VMSTATE_INT64(TimerExpire, RTL8139State),
> + VMSTATE_END_OF_LIST()
> + }
> +};
> +
> +static bool rtl8139_timer_needed(void *opaque)
> +{
> + RTL8139State *s = (RTL8139State *)opaque;
> + return timer_pending(s->timer);
> +}
I think this is needed only because of the complicated logic to compute
PCSTimeout on the fly when IntrStatus/IntrMask change or are read.
But we can just eliminate it, and leave the timer always set when
TimerInt is nonzero.
rtl8139_set_next_tctr_time should now be idempotent and deterministic.
Then it can be set in rtl8139_post_load.
---------------- 8< ---------------
From: Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH] rtl8139: simplify timer logic
Pavel Dovgalyuk reports that TimerExpire and the timer are not restored
correctly on the receiving end of migration.
It is not clear to me whether this is really the case, but we can take
the occasion to get rid of the complicated code that computes PCSTimeout
on the fly upon changes to IntrStatus/IntrMask. Just always keep a
timer running, it will fire every ~130 seconds at most if the interrupt
is masked with TimerInt != 0.
This makes rtl8139_set_next_tctr_time idempotent (when called with
wrap_on_overflow == false, as is the case from the post_load callback).
Not-tested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
index 90bc5ec..430eab3 100644
--- a/hw/net/rtl8139.c
+++ b/hw/net/rtl8139.c
@@ -508,7 +508,6 @@ typedef struct RTL8139State {
/* PCI interrupt timer */
QEMUTimer *timer;
- int64_t TimerExpire;
MemoryRegion bar_io;
MemoryRegion bar_mem;
@@ -520,7 +519,7 @@ typedef struct RTL8139State {
/* Writes tally counters to memory via DMA */
static void RTL8139TallyCounters_dma_write(RTL8139State *s, dma_addr_t tc_addr);
-static void rtl8139_set_next_tctr_time(RTL8139State *s, int64_t current_time);
+static void rtl8139_set_next_tctr_time(RTL8139State *s, bool wrap_on_overflow);
static void prom9346_decode_command(EEprom9346 *eeprom, uint8_t command)
{
@@ -1282,6 +1281,7 @@ static void rtl8139_reset(DeviceState *d)
s->TCTR = 0;
s->TimerInt = 0;
s->TCTR_base = 0;
+ rtl8139_set_next_tctr_time(s, false);
/* reset tally counters */
RTL8139TallyCounters_clear(&s->tally_counters);
@@ -2648,7 +2648,6 @@ static void rtl8139_IntrMask_write(RTL8139State *s, uint32_t val)
s->IntrMask = val;
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
rtl8139_update_irq(s);
}
@@ -2683,13 +2682,7 @@ static void rtl8139_IntrStatus_write(RTL8139State *s, uint32_t val)
rtl8139_update_irq(s);
s->IntrStatus = newStatus;
- /*
- * Computing if we miss an interrupt here is not that correct but
- * considered that we should have had already an interrupt
- * and probably emulated is slower is better to assume this resetting was
- * done before testing on previous rtl8139_update_irq lead to IRQ losing
- */
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+ rtl8139_set_next_tctr_time(s, true);
rtl8139_update_irq(s);
#endif
@@ -2697,8 +2690,6 @@ static void rtl8139_IntrStatus_write(RTL8139State *s, uint32_t val)
static uint32_t rtl8139_IntrStatus_read(RTL8139State *s)
{
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
-
uint32_t ret = s->IntrStatus;
DPRINTF("IntrStatus read(w) val=0x%04x\n", ret);
@@ -2881,43 +2872,25 @@ static void rtl8139_io_writew(void *opaque, uint8_t addr, uint32_t val)
}
}
-static void rtl8139_set_next_tctr_time(RTL8139State *s, int64_t current_time)
+static void rtl8139_set_next_tctr_time(RTL8139State *s, bool wrap_on_overflow)
{
- int64_t pci_time, next_time;
- uint32_t low_pci;
+ int64_t delta;
DPRINTF("entered rtl8139_set_next_tctr_time\n");
- if (s->TimerExpire && current_time >= s->TimerExpire) {
- s->IntrStatus |= PCSTimeout;
- rtl8139_update_irq(s);
- }
-
- /* Set QEMU timer only if needed that is
- * - TimerInt <> 0 (we have a timer)
- * - mask = 1 (we want an interrupt timer)
- * - irq = 0 (irq is not already active)
- * If any of above change we need to compute timer again
- * Also we must check if timer is passed without QEMU timer
- */
- s->TimerExpire = 0;
if (!s->TimerInt) {
- return;
- }
-
- pci_time = muldiv64(current_time - s->TCTR_base, PCI_FREQUENCY,
- get_ticks_per_sec());
- low_pci = pci_time & 0xffffffff;
- pci_time = pci_time - low_pci + s->TimerInt;
- if (low_pci >= s->TimerInt) {
- pci_time += 0x100000000LL;
- }
- next_time = s->TCTR_base + muldiv64(pci_time, get_ticks_per_sec(),
- PCI_FREQUENCY);
- s->TimerExpire = next_time;
-
- if ((s->IntrMask & PCSTimeout) != 0 && (s->IntrStatus & PCSTimeout) == 0) {
- timer_mod(s->timer, next_time);
+ timer_del(s->timer);
+ } else {
+ delta = muldiv64(s->TimerInt, get_ticks_per_sec(), PCI_FREQUENCY);
+ if (wrap_on_overflow &&
+ s->TCTR_base + delta >= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)) {
+ /* The value in the Timer register does not change, but
+ * we're counting up by 2^32 ticks (approx. 130 seconds).
+ */
+ s->TCTR_base += muldiv64(0x100000000LL, get_ticks_per_sec(),
+ PCI_FREQUENCY);
+ }
+ timer_mod(s->timer, s->TCTR_base + delta);
}
}
@@ -2965,14 +2938,14 @@ static void rtl8139_io_writel(void *opaque, uint8_t addr, uint32_t val)
case Timer:
DPRINTF("TCTR Timer reset on write\n");
s->TCTR_base = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
- rtl8139_set_next_tctr_time(s, s->TCTR_base);
+ rtl8139_set_next_tctr_time(s, false);
break;
case FlashReg:
DPRINTF("FlashReg TimerInt write val=0x%08x\n", val);
if (s->TimerInt != val) {
s->TimerInt = val;
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+ rtl8139_set_next_tctr_time(s, true);
}
break;
@@ -3249,7 +3222,7 @@ static uint32_t rtl8139_mmio_readl(void *opaque, hwaddr addr)
static int rtl8139_post_load(void *opaque, int version_id)
{
RTL8139State* s = opaque;
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+ rtl8139_set_next_tctr_time(s, false);
if (version_id < 4) {
s->cplus_enabled = s->CpCmd != 0;
}
@@ -3280,8 +3253,7 @@ static void rtl8139_pre_save(void *opaque)
RTL8139State* s = opaque;
int64_t current_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
- /* set IntrStatus correctly */
- rtl8139_set_next_tctr_time(s, current_time);
+ /* for migration to older versions */
s->TCTR = muldiv64(current_time - s->TCTR_base, PCI_FREQUENCY,
get_ticks_per_sec());
s->rtl8139_mmio_io_addr_dummy = 0;
@@ -3448,7 +3420,7 @@ static void rtl8139_timer(void *opaque)
s->IntrStatus |= PCSTimeout;
rtl8139_update_irq(s);
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+ rtl8139_set_next_tctr_time(s, true);
}
static void rtl8139_cleanup(NetClientState *nc)
@@ -3536,9 +3508,7 @@ static int pci_rtl8139_init(PCIDevice *dev)
s->cplus_txbuffer_len = 0;
s->cplus_txbuffer_offset = 0;
- s->TimerExpire = 0;
s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, rtl8139_timer, s);
- rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
add_boot_device_path(s->conf.bootindex, d, "/ethernet-phy@0");
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-07-31 16:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-31 15:49 [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate Pavel Dovgalyuk
2014-07-31 15:55 ` Eric Blake
2014-07-31 16:20 ` Paolo Bonzini
-- strict thread matches above, loose matches on Subject: below --
2014-07-31 12:53 [Qemu-devel] [RFC PATCH v3 00/49] Deterministic replay and reverse execution Pavel Dovgalyuk
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate Pavel Dovgalyuk
2014-07-31 14:14 ` Paolo Bonzini
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).