1. 29 10月, 2018 1 次提交
  2. 26 9月, 2018 3 次提交
  3. 15 8月, 2018 3 次提交
    • F
      aio-posix: Improve comment around marking node deleted · 37a81812
      Fam Zheng 提交于
      The counter is for qemu_lockcnt_inc/dec sections (read side),
      qemu_lockcnt_lock/unlock is for the write side.
      Suggested-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NFam Zheng <famz@redhat.com>
      Message-Id: <20180803063917.30292-1-famz@redhat.com>
      Signed-off-by: NFam Zheng <famz@redhat.com>
      37a81812
    • F
      aio: Do aio_notify_accept only during blocking aio_poll · b37548fc
      Fam Zheng 提交于
      An aio_notify() pairs with an aio_notify_accept(). The former should
      happen in the main thread or a vCPU thread, and the latter should be
      done in the IOThread.
      
      There is one rare case that the main thread or vCPU thread may "steal"
      the aio_notify() event just raised by itself, in bdrv_set_aio_context()
      [1]. The sequence is like this:
      
          main thread                     IO Thread
          ===============================================================
          bdrv_drained_begin()
            aio_disable_external(ctx)
                                          aio_poll(ctx, true)
                                            ctx->notify_me += 2
          ...
          bdrv_drained_end()
            ...
              aio_notify()
          ...
          bdrv_set_aio_context()
            aio_poll(ctx, false)
      [1]     aio_notify_accept(ctx)
                                            ppoll() /* Hang! */
      
      [1] is problematic. It will clear the ctx->notifier event so that
      the blocked ppoll() will not return.
      
      (For the curious, this bug was noticed when booting a number of VMs
      simultaneously in RHV.  One or two of the VMs will hit this race
      condition, making the VIRTIO device unresponsive to I/O commands. When
      it hangs, Seabios is busy waiting for a read request to complete (read
      MBR), right after initializing the virtio-blk-pci device, using 100%
      guest CPU. See also https://bugzilla.redhat.com/show_bug.cgi?id=1562750
      for the original bug analysis.)
      
      aio_notify() only injects an event when ctx->notify_me is set,
      correspondingly aio_notify_accept() is only useful when ctx->notify_me
      _was_ set. Move the call to it into the "blocking" branch. This will
      effectively skip [1] and fix the hang.
      
      Furthermore, blocking aio_poll is only allowed on home thread
      (in_aio_context_home_thread), because otherwise two blocking
      aio_poll()'s can steal each other's ctx->notifier event and cause
      hanging just like described above.
      
      Cc: qemu-stable@nongnu.org
      Suggested-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NFam Zheng <famz@redhat.com>
      Message-Id: <20180809132259.18402-3-famz@redhat.com>
      Signed-off-by: NFam Zheng <famz@redhat.com>
      b37548fc
    • F
      aio-posix: Don't count ctx->notifier as progress when polling · 70232b52
      Fam Zheng 提交于
      The same logic exists in fd polling. This change is especially important
      to avoid busy loop once we limit aio_notify_accept() to blocking
      aio_poll().
      
      Cc: qemu-stable@nongnu.org
      Signed-off-by: NFam Zheng <famz@redhat.com>
      Message-Id: <20180809132259.18402-2-famz@redhat.com>
      Signed-off-by: NFam Zheng <famz@redhat.com>
      70232b52
  4. 18 5月, 2018 1 次提交
  5. 10 2月, 2018 1 次提交
  6. 06 11月, 2017 1 次提交
  7. 04 10月, 2017 1 次提交
    • S
      aio: fix assert when remove poll during destroy · f708a5e7
      Stefan Hajnoczi 提交于
      After iothread is enabled internally inside QEMU with GMainContext, we
      may encounter this warning when destroying the iothread:
      
      (qemu-system-x86_64:19925): GLib-CRITICAL **: g_source_remove_poll:
       assertion '!SOURCE_DESTROYED (source)' failed
      
      The problem is that g_source_remove_poll() does not allow to remove one
      source from array if the source is detached from its owner
      context. (peterx: which IMHO does not make much sense)
      
      Fix it on QEMU side by avoid calling g_source_remove_poll() if we know
      the object is during destruction, and we won't leak anything after all
      since the array will be gone soon cleanly even with that fd.
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: NFam Zheng <famz@redhat.com>
      Signed-off-by: NPeter Xu <peterx@redhat.com>
      Message-id: 20170928025958.1420-6-peterx@redhat.com
      [peterx: write the commit message]
      Signed-off-by: NPeter Xu <peterx@redhat.com>
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      f708a5e7
  8. 21 2月, 2017 6 次提交
  9. 01 2月, 2017 1 次提交
  10. 26 1月, 2017 1 次提交
    • S
      aio-posix: honor is_external in AioContext polling · 59c9f437
      Stefan Hajnoczi 提交于
      AioHandlers marked ->is_external must be skipped when aio_node_check()
      fails.  bdrv_drained_begin() needs this to prevent dataplane from
      submitting new I/O requests while another thread accesses the device and
      relies on it being quiesced.
      
      This patch fixes the following segfault:
      
        Program terminated with signal SIGSEGV, Segmentation fault.
        #0  0x00005577f6127dad in bdrv_io_plug (bs=0x5577f7ae52f0) at qemu/block/io.c:2650
        2650            bdrv_io_plug(child->bs);
        [Current thread is 1 (Thread 0x7ff5c4bd1c80 (LWP 10917))]
        (gdb) bt
        #0  0x00005577f6127dad in bdrv_io_plug (bs=0x5577f7ae52f0) at qemu/block/io.c:2650
        #1  0x00005577f6114363 in blk_io_plug (blk=0x5577f7b8ba20) at qemu/block/block-backend.c:1561
        #2  0x00005577f5d4091d in virtio_blk_handle_vq (s=0x5577f9ada030, vq=0x5577f9b3d2a0) at qemu/hw/block/virtio-blk.c:589
        #3  0x00005577f5d4240d in virtio_blk_data_plane_handle_output (vdev=0x5577f9ada030, vq=0x5577f9b3d2a0) at qemu/hw/block/dataplane/virtio-blk.c:158
        #4  0x00005577f5d88acd in virtio_queue_notify_aio_vq (vq=0x5577f9b3d2a0) at qemu/hw/virtio/virtio.c:1304
        #5  0x00005577f5d8aaaf in virtio_queue_host_notifier_aio_poll (opaque=0x5577f9b3d308) at qemu/hw/virtio/virtio.c:2134
        #6  0x00005577f60ca077 in run_poll_handlers_once (ctx=0x5577f79ddbb0) at qemu/aio-posix.c:493
        #7  0x00005577f60ca268 in try_poll_mode (ctx=0x5577f79ddbb0, blocking=true) at qemu/aio-posix.c:569
        #8  0x00005577f60ca331 in aio_poll (ctx=0x5577f79ddbb0, blocking=true) at qemu/aio-posix.c:601
        #9  0x00005577f612722a in bdrv_flush (bs=0x5577f7c20970) at qemu/block/io.c:2403
        #10 0x00005577f60c1b2d in bdrv_close (bs=0x5577f7c20970) at qemu/block.c:2322
        #11 0x00005577f60c20e7 in bdrv_delete (bs=0x5577f7c20970) at qemu/block.c:2465
        #12 0x00005577f60c3ecf in bdrv_unref (bs=0x5577f7c20970) at qemu/block.c:3425
        #13 0x00005577f60bf951 in bdrv_root_unref_child (child=0x5577f7a2de70) at qemu/block.c:1361
        #14 0x00005577f6112162 in blk_remove_bs (blk=0x5577f7b8ba20) at qemu/block/block-backend.c:491
        #15 0x00005577f6111b1b in blk_remove_all_bs () at qemu/block/block-backend.c:245
        #16 0x00005577f60c1db6 in bdrv_close_all () at qemu/block.c:2382
        #17 0x00005577f5e60cca in main (argc=20, argv=0x7ffea6eb8398, envp=0x7ffea6eb8440) at qemu/vl.c:4684
      
      The key thing is that bdrv_close() uses bdrv_drained_begin() and
      virtio_queue_host_notifier_aio_poll() must not be called.
      
      Thanks to Fam Zheng <famz@redhat.com> for identifying the root cause of
      this crash.
      Reported-by: NAlberto Garcia <berto@igalia.com>
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: NFam Zheng <famz@redhat.com>
      Tested-by: NAlberto Garcia <berto@igalia.com>
      Message-id: 20170124095350.16679-1-stefanha@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      59c9f437
  11. 16 1月, 2017 3 次提交
  12. 04 1月, 2017 5 次提交
    • S
      aio: self-tune polling time · 82a41186
      Stefan Hajnoczi 提交于
      This patch is based on the algorithm for the kvm.ko halt_poll_ns
      parameter in Linux.  The initial polling time is zero.
      
      If the event loop is woken up within the maximum polling time it means
      polling could be effective, so grow polling time.
      
      If the event loop is woken up beyond the maximum polling time it means
      polling is not effective, so shrink polling time.
      
      If the event loop makes progress within the current polling time then
      the sweet spot has been reached.
      
      This algorithm adjusts the polling time so it can adapt to variations in
      workloads.  The goal is to reach the sweet spot while also recognizing
      when polling would hurt more than help.
      
      Two new trace events, poll_grow and poll_shrink, are added for observing
      polling time adjustment.
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-id: 20161201192652.9509-13-stefanha@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      82a41186
    • S
      aio: add .io_poll_begin/end() callbacks · 684e508c
      Stefan Hajnoczi 提交于
      The begin and end callbacks can be used to prepare for the polling loop
      and clean up when polling stops.  Note that they may only be called once
      for multiple aio_poll() calls if polling continues to succeed.  Once
      polling fails the end callback is invoked before aio_poll() resumes file
      descriptor monitoring.
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-id: 20161201192652.9509-11-stefanha@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      684e508c
    • S
      aio: add polling mode to AioContext · 4a1cba38
      Stefan Hajnoczi 提交于
      The AioContext event loop uses ppoll(2) or epoll_wait(2) to monitor file
      descriptors or until a timer expires.  In cases like virtqueues, Linux
      AIO, and ThreadPool it is technically possible to wait for events via
      polling (i.e. continuously checking for events without blocking).
      
      Polling can be faster than blocking syscalls because file descriptors,
      the process scheduler, and system calls are bypassed.
      
      The main disadvantage to polling is that it increases CPU utilization.
      In classic polling configuration a full host CPU thread might run at
      100% to respond to events as quickly as possible.  This patch implements
      a timeout so we fall back to blocking syscalls if polling detects no
      activity.  After the timeout no CPU cycles are wasted on polling until
      the next event loop iteration.
      
      The run_poll_handlers_begin() and run_poll_handlers_end() trace events
      are added to aid performance analysis and troubleshooting.  If you need
      to know whether polling mode is being used, trace these events to find
      out.
      
      Note that the AioContext is now re-acquired before disabling notify_me
      in the non-polling case.  This makes the code cleaner since notify_me
      was enabled outside the non-polling AioContext release region.  This
      change is correct since it's safe to keep notify_me enabled longer
      (disabling is an optimization) but potentially causes unnecessary
      event_notifer_set() calls.  I think the chance of performance regression
      is small here.
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-id: 20161201192652.9509-4-stefanha@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      4a1cba38
    • S
      aio: add AioPollFn and io_poll() interface · f6a51c84
      Stefan Hajnoczi 提交于
      The new AioPollFn io_poll() argument to aio_set_fd_handler() and
      aio_set_event_handler() is used in the next patch.
      
      Keep this code change separate due to the number of files it touches.
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-id: 20161201192652.9509-3-stefanha@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      f6a51c84
    • S
      aio: add flag to skip fds to aio_dispatch() · 721671ad
      Stefan Hajnoczi 提交于
      Polling mode will not call ppoll(2)/epoll_wait(2).  Therefore we know
      there are no fds ready and should avoid looping over fd handlers in
      aio_dispatch().
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-id: 20161201192652.9509-2-stefanha@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      721671ad
  13. 09 11月, 2016 2 次提交
  14. 28 9月, 2016 1 次提交
  15. 18 7月, 2016 1 次提交
  16. 22 4月, 2016 1 次提交
  17. 17 3月, 2016 1 次提交
  18. 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
  19. 17 11月, 2015 1 次提交
  20. 09 11月, 2015 2 次提交
    • F
      aio: Introduce aio-epoll.c · fbe3fc5c
      Fam Zheng 提交于
      To minimize code duplication, epoll is hooked into aio-posix's
      aio_poll() instead of rolling its own. This approach also has both
      compile-time and run-time switchability.
      
      1) When QEMU starts with a small number of fds in the event loop, ppoll
      is used.
      
      2) When QEMU starts with a big number of fds, or when more devices are
      hot plugged, epoll kicks in when the number of fds hits the threshold.
      
      3) Some fds may not support epoll, such as tty based stdio. In this
      case, it falls back to ppoll.
      
      A rough benchmark with scsi-disk on virtio-scsi dataplane (epoll gets
      enabled from 64 onward). Numbers are in MB/s.
      
      ===============================================
                   |     master     |     epoll
                   |                |
      scsi disks # | read    randrw | read    randrw
      -------------|----------------|----------------
      1            | 86      36     | 92      45
      8            | 87      43     | 86      41
      64           | 71      32     | 70      38
      128          | 48      24     | 58      31
      256          | 37      19     | 57      28
      ===============================================
      
      To comply with aio_{disable,enable}_external, we always use ppoll when
      aio_external_disabled() is true.
      
      [Removed #ifdef CONFIG_EPOLL around AioContext epollfd field declaration
      since the field is also referenced outside CONFIG_EPOLL code.
      --Stefan]
      Signed-off-by: NFam Zheng <famz@redhat.com>
      Message-id: 1446177989-6702-4-git-send-email-famz@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      fbe3fc5c
    • F
      aio: Introduce aio_context_setup · 37fcee5d
      Fam Zheng 提交于
      This is the place to initialize platform specific bits of AioContext.
      Signed-off-by: NFam Zheng <famz@redhat.com>
      Message-id: 1446177989-6702-3-git-send-email-famz@redhat.com
      Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
      37fcee5d
  21. 24 10月, 2015 2 次提交
  22. 22 7月, 2015 1 次提交