From: Paolo Bonzini <pbonzini@redhat.com>
To: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com,
mark.burton@greensocs.com, real@ispras.ru, batuzovk@ispras.ru,
maria.klimushenkova@ispras.ru, afaerber@suse.de,
fred.konrad@greensocs.com
Subject: Re: [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: adding new fields to vmstate
Date: Thu, 31 Jul 2014 16:14:55 +0200 [thread overview]
Message-ID: <53DA4F5F.5020206@redhat.com> (raw)
In-Reply-To: <20140731125424.1600.84077.stgit@PASHA-ISP.novsu.ac.ru>
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");
next prev parent reply other threads:[~2014-07-31 14:17 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-31 12:53 [Qemu-devel] [RFC PATCH v3 00/49] Deterministic replay and reverse execution Pavel Dovgalyuk
2014-07-31 12:53 ` [Qemu-devel] [RFC PATCH v3 01/49] acpi: accurate overflow check Pavel Dovgalyuk
2014-07-31 12:53 ` [Qemu-devel] [RFC PATCH v3 02/49] integratorcp: adding vmstate for save/restore Pavel Dovgalyuk
2014-07-31 12:53 ` [Qemu-devel] [RFC PATCH v3 03/49] pcspk: " Pavel Dovgalyuk
2014-07-31 12:53 ` [Qemu-devel] [RFC PATCH v3 04/49] fdc: " Pavel Dovgalyuk
2014-07-31 12:58 ` Paolo Bonzini
2014-08-01 15:43 ` Dr. David Alan Gilbert
2014-07-31 12:53 ` [Qemu-devel] [RFC PATCH v3 05/49] parallel: " Pavel Dovgalyuk
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 06/49] serial: fixing " Pavel Dovgalyuk
2014-07-31 13:00 ` Paolo Bonzini
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 07/49] kvmapic: fixing loading vmstate Pavel Dovgalyuk
2014-07-31 13:01 ` Paolo Bonzini
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 08/49] hpet: fixing saving and loading process Pavel Dovgalyuk
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 09/49] pckbd: adding new fields to vmstate Pavel Dovgalyuk
2014-07-31 13:03 ` Paolo Bonzini
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 10/49] rtl8139: " Pavel Dovgalyuk
2014-07-31 14:14 ` Paolo Bonzini [this message]
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 11/49] piix: do not raise irq while loading vmstate Pavel Dovgalyuk
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 12/49] mc146818rtc: add missed field to vmstate Pavel Dovgalyuk
2014-07-31 14:15 ` Paolo Bonzini
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 13/49] pl031: " Pavel Dovgalyuk
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 14/49] ide pci: reset status field before loading the vmstate Pavel Dovgalyuk
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 15/49] softmmu: fixing usage of cpu_st/ld* from helpers Pavel Dovgalyuk
2014-07-31 16:07 ` Alex Bennée
2014-08-26 8:00 ` Pavel Dovgaluk
2014-07-31 12:54 ` [Qemu-devel] [RFC PATCH v3 16/49] target-i386: update fp status fix Pavel Dovgalyuk
2014-07-31 16:12 ` Alex Bennée
2014-07-31 12:55 ` [Qemu-devel] [RFC PATCH v3 17/49] migration: add vmstate for int8 and char arrays Pavel Dovgalyuk
2014-07-31 12:55 ` [Qemu-devel] [RFC PATCH v3 18/49] replay: global variables and function stubs Pavel Dovgalyuk
2014-07-31 12:55 ` [Qemu-devel] [RFC PATCH v3 19/49] block: add suffix parameter to bdrv_open functions Pavel Dovgalyuk
2014-07-31 12:55 ` [Qemu-devel] [RFC PATCH v3 20/49] sysemu: system functions for replay Pavel Dovgalyuk
2014-07-31 12:55 ` [Qemu-devel] [RFC PATCH v3 21/49] replay: internal functions for replay log Pavel Dovgalyuk
2014-07-31 12:55 ` [Qemu-devel] [RFC PATCH v3 22/49] cpu: invent instruction count for accurate replay Pavel Dovgalyuk
2014-07-31 16:17 ` Alex Bennée
2014-07-31 12:55 ` [Qemu-devel] [RFC PATCH v3 23/49] target-arm: instructions counting code for replay Pavel Dovgalyuk
2014-07-31 12:55 ` [Qemu-devel] [RFC PATCH v3 24/49] target-i386: " Pavel Dovgalyuk
2014-07-31 12:55 ` [Qemu-devel] [RFC PATCH v3 25/49] replay: interrupts and exceptions Pavel Dovgalyuk
2014-07-31 12:55 ` [Qemu-devel] [RFC PATCH v3 26/49] vga: do not use virtual clock for blinking cursor Pavel Dovgalyuk
2014-07-31 12:56 ` [Qemu-devel] [RFC PATCH v3 27/49] replay: asynchronous events infrastructure Pavel Dovgalyuk
2014-07-31 12:56 ` [Qemu-devel] [RFC PATCH v3 28/49] replay: recording and replaying clock ticks Pavel Dovgalyuk
2014-07-31 12:56 ` [Qemu-devel] [RFC PATCH v3 29/49] replay: recording and replaying different timers Pavel Dovgalyuk
2014-07-31 12:56 ` [Qemu-devel] [RFC PATCH v3 30/49] replay: shutdown event Pavel Dovgalyuk
2014-07-31 12:56 ` [Qemu-devel] [RFC PATCH v3 31/49] replay: checkpoints Pavel Dovgalyuk
2014-07-31 12:56 ` [Qemu-devel] [RFC PATCH v3 32/49] vmclock: add virtual clock based on replay icount Pavel Dovgalyuk
2014-07-31 12:56 ` [Qemu-devel] [RFC PATCH v3 33/49] replay: bottom halves Pavel Dovgalyuk
2014-07-31 12:56 ` [Qemu-devel] [RFC PATCH v3 34/49] replay: replay aio requests Pavel Dovgalyuk
2014-07-31 12:56 ` [Qemu-devel] [RFC PATCH v3 35/49] replay: thread pool Pavel Dovgalyuk
2014-07-31 12:56 ` [Qemu-devel] [RFC PATCH v3 36/49] pl031: vmstate in replay mode Pavel Dovgalyuk
2014-07-31 12:56 ` [Qemu-devel] [RFC PATCH v3 37/49] replay: initialization and deinitialization Pavel Dovgalyuk
2014-07-31 12:57 ` [Qemu-devel] [RFC PATCH v3 38/49] replay: command line options Pavel Dovgalyuk
2014-07-31 12:57 ` [Qemu-devel] [RFC PATCH v3 39/49] replay: snapshotting the virtual machine Pavel Dovgalyuk
2014-07-31 12:57 ` [Qemu-devel] [RFC PATCH v3 40/49] replay: recording of the user input Pavel Dovgalyuk
2014-07-31 12:57 ` [Qemu-devel] [RFC PATCH v3 41/49] tap-win32: destroy the thread at exit Pavel Dovgalyuk
2014-07-31 12:57 ` [Qemu-devel] [RFC PATCH v3 42/49] replay: network packets record/replay Pavel Dovgalyuk
2014-07-31 12:57 ` [Qemu-devel] [RFC PATCH v3 43/49] replay: audio data record/replay Pavel Dovgalyuk
2014-07-31 12:57 ` [Qemu-devel] [RFC PATCH v3 44/49] replay: serial port Pavel Dovgalyuk
2014-07-31 12:57 ` [Qemu-devel] [RFC PATCH v3 45/49] replay: USB passthrough Pavel Dovgalyuk
2014-07-31 12:57 ` [Qemu-devel] [RFC PATCH v3 46/49] replay: replay_info command Pavel Dovgalyuk
2014-07-31 12:57 ` [Qemu-devel] [RFC PATCH v3 47/49] replay: replay_break command Pavel Dovgalyuk
2014-07-31 12:57 ` [Qemu-devel] [RFC PATCH v3 48/49] replay: replay_seek_step command Pavel Dovgalyuk
2014-07-31 12:58 ` [Qemu-devel] [RFC PATCH v3 49/49] gdbstub: reverse debugging Pavel Dovgalyuk
2014-07-31 13:08 ` Eric Blake
-- strict thread matches above, loose matches on Subject: below --
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
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=53DA4F5F.5020206@redhat.com \
--to=pbonzini@redhat.com \
--cc=Pavel.Dovgaluk@ispras.ru \
--cc=afaerber@suse.de \
--cc=batuzovk@ispras.ru \
--cc=fred.konrad@greensocs.com \
--cc=maria.klimushenkova@ispras.ru \
--cc=mark.burton@greensocs.com \
--cc=peter.crosthwaite@xilinx.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=real@ispras.ru \
/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).