1. 14 3月, 2017 4 次提交
    • P
      icount: process QEMU_CLOCK_VIRTUAL timers in vCPU thread · 6b8f0187
      Paolo Bonzini 提交于
      icount has become much slower after tcg_cpu_exec has stopped
      using the BQL.  There is also a latent bug that is masked by
      the slowness.
      
      The slowness happens because every occurrence of a QEMU_CLOCK_VIRTUAL
      timer now has to wake up the I/O thread and wait for it.  The rendez-vous
      is mediated by the BQL QemuMutex:
      
      - handle_icount_deadline wakes up the I/O thread with BQL taken
      - the I/O thread wakes up and waits on the BQL
      - the VCPU thread releases the BQL a little later
      - the I/O thread raises an interrupt, which calls qemu_cpu_kick
      - the VCPU thread notices the interrupt, takes the BQL to
        process it and waits on it
      
      All this back and forth is extremely expensive, causing a 6 to 8-fold
      slowdown when icount is turned on.
      
      One may think that the issue is that the VCPU thread is too dependent
      on the BQL, but then the latent bug comes in.  I first tried removing
      the BQL completely from the x86 cpu_exec, only to see everything break.
      The only way to fix it (and make everything slow again) was to add a dummy
      BQL lock/unlock pair.
      
      This is because in -icount mode you really have to process the events
      before the CPU restarts executing the next instruction.  Therefore, this
      series moves the processing of QEMU_CLOCK_VIRTUAL timers straight in
      the vCPU thread when running in icount mode.
      
      The required changes include:
      
      - make the timer notification callback wake up TCG's single vCPU thread
        when run from another thread.  By using async_run_on_cpu, the callback
        can override all_cpu_threads_idle() when the CPU is halted.
      
      - move handle_icount_deadline after qemu_tcg_wait_io_event, so that
        the timer notification callback is invoked after the dummy work item
        wakes up the vCPU thread
      
      - make handle_icount_deadline run the timers instead of just waking the
        I/O thread.
      
      - stop processing the timers in the main loop
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      6b8f0187
    • P
      cpus: define QEMUTimerListNotifyCB for QEMU system emulation · 3f53bc61
      Paolo Bonzini 提交于
      There is no change for now, because the callback just invokes
      qemu_notify_event.
      Reviewed-by: NEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      3f53bc61
    • P
      qemu-timer: do not include sysemu/cpus.h from util/qemu-timer.h · d2528bdc
      Paolo Bonzini 提交于
      This dependency is the wrong way, and we will need util/qemu-timer.h from
      sysemu/cpus.h in the next patch.
      Reviewed-by: NAlex Bennée <alex.bennee@linaro.org>
      Reviewed-by: NEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      d2528bdc
    • P
      qemu-timer: fix off-by-one · 33bef0b9
      Paolo Bonzini 提交于
      If the first timer is exactly at the current value of the clock, the
      deadline is met and the timer should fire.  This fixes itself on the next
      iteration of the loop without icount; with icount, however, execution
      of instructions will stop exactly at the deadline and won't proceed.
      Reviewed-by: NAlex Bennée <alex.bennee@linaro.org>
      Reviewed-by: NEdgar E. Iglesias <edgar.iglesias@xilinx.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      33bef0b9
  2. 01 3月, 2017 1 次提交
  3. 21 2月, 2017 1 次提交
  4. 22 12月, 2016 1 次提交
  5. 10 8月, 2016 1 次提交
    • G
      timer: set vm_clock disabled default · 3fdd0ee3
      Gonglei 提交于
      (commit 80dcfb85)
      Upon migration, the code use a timer based on vm_clock for 1ns
      in the future from post_load to do the event send in case host_connected
      differs between migration source and target.
      
      However, it's not guaranteed that the apic is ready to inject irqs into
      the guest, and the irq line remained high, resulting in any future interrupts
      going unnoticed by the guest as well.
      
      That's because 1) the migration coroutine is not blocked when it get EAGAIN
      while reading QEMUFile. 2) The vm_clock is enabled default currently, it doesn't
      rely on the calling of vm_start(), that means vm_clock timers can run before
      VCPUs are running.
      
      So, let's set the vm_clock disabled default, keep the initial intention of
      design for vm_clock timers.
      
      Meanwhile, change the test-aio usecase, using QEMU_CLOCK_REALTIME instead of
      QEMU_CLOCK_VIRTUAL as the block code does.
      
      CC: Paolo Bonzini <pbonzini@redhat.com>
      CC: Dr. David Alan Gilbert <dgilbert@redhat.com>
      CC: qemu-stable@nongnu.org
      Signed-off-by: NGonglei <arei.gonglei@huawei.com>
      Message-Id: <1470728955-90600-1-git-send-email-arei.gonglei@huawei.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      3fdd0ee3
  6. 07 6月, 2016 1 次提交
  7. 16 3月, 2016 1 次提交
    • P
      icount: decouple warp calls · e76d1798
      Pavel Dovgalyuk 提交于
      qemu_clock_warp function is called to update virtual clock when CPU
      is sleeping. This function includes replay checkpoint to make execution
      deterministic in icount mode.
      Record/replay module flushes async event queue at checkpoints.
      Some of the events (e.g., block devices operations) include interaction
      with hardware. E.g., APIC polled by block devices sets one of IRQ flags.
      Flag to be set depends on currently executed thread (CPU or iothread).
      Therefore in replay mode we have to process the checkpoints in the same thread
      as they were recorded.
      qemu_clock_warp function (and its checkpoint) may be called from different
      thread. This patch decouples two different execution cases of this function:
      call when CPU is sleeping from iothread and call from cpu thread to update
      virtual clock.
      First task is performed by qemu_start_warp_timer function. It sets warp
      timer event to the moment of nearest pending virtual timer.
      Second function (qemu_account_warp_timer) is called from cpu thread
      before execution of the code. It advances virtual clock by adding the length
      of period while CPU was sleeping.
      Signed-off-by: NPavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
      Message-Id: <20160310115609.4812.44986.stgit@PASHA-ISP>
      [Update docs. - Paolo]
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      e76d1798
  8. 05 2月, 2016 1 次提交
    • P
      all: Clean up includes · d38ea87a
      Peter Maydell 提交于
      Clean up includes so that osdep.h is included first and headers
      which it implies are not included manually.
      
      This commit was created with scripts/clean-includes.
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      Message-id: 1454089805-5470-16-git-send-email-peter.maydell@linaro.org
      d38ea87a
  9. 06 11月, 2015 2 次提交
  10. 22 7月, 2015 1 次提交
  11. 19 6月, 2015 1 次提交
    • P
      qemu-timer: Call clock reset notifiers on forward jumps · fb1a3a05
      Paul Donohue 提交于
      Commit 691a0c9c introduced a mechanism by which QEMU_CLOCK_HOST can
      notify other parts of the emulator when the host clock has jumped
      backward.  This is used to avoid stalling timers that were scheduled
      based on the host clock.
      
      However, if the host clock jumps forward, then timers that were
      scheduled based on the host clock may fire rapidly and cause other
      problems.  For example, the mc146818rtc periodic timer will block
      execution of the VM and consume host CPU while firing every interrupt
      for the time period that was skipped by the host clock.
      
      To correct that problem, this commit fires the reset notification if the
      host clock jumps forward by more than a hard-coded limit.  The limit is
      currently set to a value of 60 seconds, which should be small enough to
      prevent excessive timer loops, but large enough to avoid frequent resets
      in idle VMs.
      Signed-off-by: NPaul Donohue <qemu-git@PaulSD.com>
      Message-Id: <20150612140845.GD2749@TopQuark.net>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      fb1a3a05
  12. 27 1月, 2015 1 次提交
    • P
      qemu-timer.c: Trim list of included headers · 1ac0206b
      Peter Maydell 提交于
      qemu-timer.c was including a lot more headers than it needed to,
      presumably for historical reasons. In particular, it included
      ui/console.h; this now tries to pull in <pixman.h>, which will
      cause a compilation failure in --disable-tools --disable-system
      configurations when running "make check" (which builds qemu-timer.c,
      even though the linux-user binaries themselves don't need it).
      
      Fix this build failure by trimming down the set of included
      headers severely -- we only really need main-loop.h and timer.h.
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-id: 1421770600-17525-1-git-send-email-peter.maydell@linaro.org
      1ac0206b
  13. 26 1月, 2015 1 次提交
    • P
      qemu-timer: introduce timer_deinit · cd1bd53a
      Paolo Bonzini 提交于
      In some cases, a timer was set to NULL so that we could check if it is
      initialized.  Use the timer_list field instead, and add a timer_deinit
      function that NULLs it.
      
      It then makes sense that timer_del be a no-op (instead of a crasher) on
      such a de-initialized timer.  It avoids the need to poke at the timerlist
      field to check if the timers are initialized.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      cd1bd53a
  14. 14 1月, 2015 1 次提交
  15. 15 12月, 2014 1 次提交
  16. 27 11月, 2014 1 次提交
    • P
      qemu-timer: Avoid overflows when converting timeout to struct timespec · 490309fc
      Peter Maydell 提交于
      In qemu_poll_ns(), when we convert an int64_t nanosecond timeout into
      a struct timespec, we may accidentally run into overflow problems if
      the timeout is very long. This happens because the tv_sec field is a
      time_t, which is signed, so we might end up setting it to a negative
      value by mistake. This will result in what was intended to be a
      near-infinite timeout turning into an instantaneous timeout, and we'll
      busy loop. Cap the maximum timeout at INT32_MAX seconds (about 68 years)
      to avoid this problem.
      
      This specifically manifested on ARM hosts as an extreme slowdown on
      guest shutdown (when the guest reprogrammed the PL031 RTC to not
      generate alarms using a very long timeout) but could happen on other
      hosts and guests too.
      Reported-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Cc: qemu-stable@nongnu.org
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: NFam Zheng <famz@redhat.com>
      Message-id: 1416939705-1272-1-git-send-email-peter.maydell@linaro.org
      490309fc
  17. 10 5月, 2014 1 次提交
    • K
      vl.c: remove init_clocks call from main · 02ce232c
      Kirill Batuzov 提交于
      Clocks are initialized in qemu_init_main_loop. They are not needed before it.
      Initializing them twice is not only unnecessary but is harmful: it results in
      memory leak and potentially can lead to a situation where different parts of
      QEMU use different sets of timers.
      
      To avoid it remove init_clocks call from main and add an assertion to
      qemu_clock_init that corresponding clock has not been initialized yet.
      Signed-off-by: NKirill Batuzov <batuzovk@ispras.ru>
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      02ce232c
  18. 08 5月, 2014 1 次提交
  19. 17 10月, 2013 3 次提交
  20. 18 9月, 2013 3 次提交
    • P
      qemu-timer: do not take the lock in timer_pending · 3db1ee7c
      Paolo Bonzini 提交于
      We can deduce the result from expire_time, by making it always -1 if
      the timer is not in the active_timers list.  We need to check against
      negative times passed to timer_mod_ns; clamping them to zero is not
      a problem because the only clock that has a zero value at VM startup
      is QEMU_CLOCK_VIRTUAL, and it is monotonic so it cannot be non-zero.
      QEMU_CLOCK_HOST, instead, is not monotonic but it cannot go to negative
      values unless the host time is seriously screwed up and points to
      the 1960s.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      3db1ee7c
    • S
      qemu-timer: make qemu_timer_mod_ns() and qemu_timer_del() thread-safe · 978f2205
      Stefan Hajnoczi 提交于
      Introduce QEMUTimerList->active_timers_lock to protect the linked list
      of active timers.  This allows qemu_timer_mod_ns() to be called from any
      thread.
      
      Note that vm_clock is not thread-safe and its use of
      qemu_clock_has_timers() works fine today but is also not thread-safe.
      
      The purpose of this patch is to eventually let device models set or
      cancel timers from a vcpu thread without holding the global mutex.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      978f2205
    • S
      qemu-timer: drop outdated signal safety comments · da718ceb
      Stefan Hajnoczi 提交于
      host_alarm_handler() is invoked from the signal processing thread
      (currently the iothread).  Previously we did processing in a real signal
      handler with signalfd and therefore needed signal-safe timer code.
      
      Today host_alarm_handler() just marks the alarm timer as expired/pending
      and notifies the main loop using qemu_notify_event().
      
      Therefore these outdated comments about signal safety can be dropped.
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      da718ceb
  21. 23 8月, 2013 12 次提交