Skip to content
Snippets Groups Projects
  1. Apr 06, 2022
  2. Jun 16, 2021
  3. Sep 23, 2020
    • Stefan Hajnoczi's avatar
      qemu/atomic.h: rename atomic_ to qatomic_ · d73415a3
      Stefan Hajnoczi authored
      
      clang's C11 atomic_fetch_*() functions only take a C11 atomic type
      pointer argument. QEMU uses direct types (int, etc) and this causes a
      compiler error when a QEMU code calls these functions in a source file
      that also included <stdatomic.h> via a system header file:
      
        $ CC=clang CXX=clang++ ./configure ... && make
        ../util/async.c:79:17: error: address argument to atomic operation must be a pointer to _Atomic type ('unsigned int *' invalid)
      
      Avoid using atomic_*() names in QEMU's atomic.h since that namespace is
      used by <stdatomic.h>. Prefix QEMU's APIs with 'q' so that atomic.h
      and <stdatomic.h> can co-exist. I checked /usr/include on my machine and
      searched GitHub for existing "qatomic_" users but there seem to be none.
      
      This patch was generated using:
      
        $ git grep -h -o '\<atomic\(64\)\?_[a-z0-9_]\+' include/qemu/atomic.h | \
          sort -u >/tmp/changed_identifiers
        $ for identifier in $(</tmp/changed_identifiers); do
              sed -i "s%\<$identifier\>%q$identifier%g" \
                  $(git grep -I -l "\<$identifier\>")
          done
      
      I manually fixed line-wrap issues and misaligned rST tables.
      
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Acked-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <20200923105646.47864-1-stefanha@redhat.com>
      d73415a3
  4. Sep 17, 2020
  5. Sep 16, 2019
  6. Jan 11, 2019
  7. Aug 23, 2018
    • Emilio G. Cota's avatar
      qsp: QEMU's Synchronization Profiler · fe9959a2
      Emilio G. Cota authored
      
      The goal of this module is to profile synchronization primitives (i.e.
      mutexes, recursive mutexes and condition variables) so that scalability
      issues can be quickly diagnosed.
      
      Sync primitives are profiled by QSP based on the vaddr of the object accessed
      as well as the call site (file:line_nr). That means the same object called
      from two different call sites will be tracked in separate entries, which
      might be reported together or separately (see subsequent commit on
      call site coalescing).
      
      Some perf numbers:
      
      Host: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
      Command: taskset -c 0 tests/atomic_add-bench -d 5 -m
      
      - Before: 54.80 Mops/s
      - After:  54.75 Mops/s
      
      That is, a negligible slowdown due to the now indirect call to
      qemu_mutex_lock. Note that using a branch instead of an indirect
      call introduces a more severe slowdown (53.65 Mops/s, i.e. 2% slowdown).
      
      Enabling the profiler (with -p, added in this series) is more interesting:
      
      - No profiling: 54.75 Mops/s
      - W/ profiling: 12.53 Mops/s
      
      That is, a 4.36X slowdown.
      
      We can break down this slowdown by removing the get_clock calls or
      the entry lookup:
      
      - No profiling:     54.75 Mops/s
      - W/o get_clock:    25.37 Mops/s
      - W/o entry lookup: 19.30 Mops/s
      - W/ profiling:     12.53 Mops/s
      
      Signed-off-by: default avatarEmilio G. Cota <cota@braap.org>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      fe9959a2
  8. Jun 28, 2018
    • Peter Xu's avatar
      qemu-thread: introduce qemu-thread-common.h · f1aff7aa
      Peter Xu authored
      
      Introduce some hooks for the shared part of qemu thread between POSIX
      and Windows implementations.  Note that in qemu_mutex_unlock_impl() we
      moved the call before unlock operation which should make more sense.
      And we don't need qemu_mutex_post_unlock() hook.
      
      Put all these shared hooks into the header files.  It should be internal
      to qemu-thread but not for qemu-thread users, hence put into util/
      directory.
      
      Reviewed-by: default avatarEmilio G. Cota <cota@braap.org>
      Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
      Message-Id: <20180425025459.5258-3-peterx@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      f1aff7aa
  9. Jan 16, 2018
  10. Jul 04, 2017
  11. May 05, 2017
    • Jose Ricardo Ziviani's avatar
      trace: add qemu mutex lock and unlock trace events · 31f5a726
      Jose Ricardo Ziviani authored
      
      These trace events were very useful to help me to understand and find a
      reordering issue in vfio, for example:
      
      qemu_mutex_lock locked mutex 0x10905ad8
        vfio_region_write  (0001:03:00.0:region1+0xc0, 0x2020c, 4)
      qemu_mutex_unlock unlocked mutex 0x10905ad8
      qemu_mutex_lock locked mutex 0x10905ad8
        vfio_region_write  (0001:03:00.0:region1+0xc4, 0xa0000, 4)
      qemu_mutex_unlock unlocked mutex 0x10905ad8
      
      that also helped me to see the desired result after the fix:
      
      qemu_mutex_lock locked mutex 0x10905ad8
        vfio_region_write  (0001:03:00.0:region1+0xc0, 0x2000c, 4)
        vfio_region_write  (0001:03:00.0:region1+0xc4, 0xb0000, 4)
      qemu_mutex_unlock unlocked mutex 0x10905ad8
      
      So it could be a good idea to have these traces implemented. It's worth
      mentioning that they should be surgically enabled during the debugging,
      otherwise it can flood the trace logs with lock/unlock messages.
      
      How to use it:
      trace-event qemu_mutex_lock on|off
      trace-event qemu_mutex_unlock on|off
      or
      trace-event qemu_mutex* on|off
      
      Signed-off-by: default avatarJose Ricardo Ziviani <joserz@linux.vnet.ibm.com>
      Message-Id: <1493054398-26013-1-git-send-email-joserz@linux.vnet.ibm.com>
      Reviewed-by: default avatarFam Zheng <famz@redhat.com>
      [Also handle trylock, cond_wait and win32; trace "unlocked" while still
       in the critical section, so that "unlocked" always comes before the
       next "locked" tracepoint. - Paolo]
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      31f5a726
  12. Mar 27, 2017
    • Andrey Shedel's avatar
      win32: replace custom mutex and condition variable with native primitives · 12f8def0
      Andrey Shedel authored
      
      The multithreaded TCG implementation exposed deadlocks in the win32
      condition variables: as implemented, qemu_cond_broadcast waited on
      receivers, whereas the pthreads API it was intended to emulate does
      not. This was causing a deadlock because broadcast was called while
      holding the IO lock, as well as all possible waiters blocked on the
      same lock.
      
      This patch replaces all the custom synchronisation code for mutexes
      and condition variables with native Windows primitives (SRWlocks and
      condition variables) with the same semantics as their POSIX
      equivalents. To enable that, it requires a Windows Vista or newer host
      OS.
      
      Signed-off-by: default avatarAndrey Shedel <ashedel@microsoft.com>
      [AB: edited commit message]
      Signed-off-by: default avatarAndrew Baumann <Andrew.Baumann@microsoft.com>
      Message-Id: <20170324220141.10104-1-Andrew.Baumann@microsoft.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      12f8def0
  13. Jan 19, 2017
  14. Jan 16, 2017
  15. Oct 28, 2016
  16. Oct 24, 2016
    • Paolo Bonzini's avatar
      qemu-thread: use acquire/release to clarify semantics of QemuEvent · 374293ca
      Paolo Bonzini authored
      
      Do not use the somewhat mysterious atomic_mb_read/atomic_mb_set,
      instead make sure that the operations on QemuEvent are annotated
      with the desired acquire and release semantics.
      
      In particular, qemu_event_set wakes up the waiting thread, so it must
      be a release from the POV of the waker (compare with qemu_mutex_unlock).
      And it actually needs a full barrier, because that's the only thing that
      provides something like a "load-release".
      
      Use smp_mb_acquire until we have atomic_load_acquire and
      atomic_store_release in atomic.h.
      
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      374293ca
  17. Feb 04, 2016
  18. Sep 24, 2015
    • Paolo Bonzini's avatar
      qemu-thread: add a fast path to the Win32 QemuEvent · 7c9b2bf6
      Paolo Bonzini authored
      
      QemuEvents are used heavily by call_rcu.  We do not want them to be slow,
      but the current implementation does a kernel call on every invocation
      of qemu_event_* and won't cut it.
      
      So, wrap a Win32 manual-reset event with a fast userspace path.  The
      states and transitions are the same as for the futex and mutex/condvar
      implementations, but the slow path is different of course.  The idea
      is to reset the Win32 event lazily, as part of a test-reset-test-wait
      sequence.  Such a sequence is, indeed, how QemuEvents are used by
      RCU and other subsystems!
      
      The patch includes a formal model of the algorithm.
      
      Tested-by: default avatarStefan Weil <sw@weilnetz.de>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarStefan Weil <sw@weilnetz.de>
      7c9b2bf6
  19. Jan 13, 2015
    • Paolo Bonzini's avatar
      qemu-thread: add per-thread atexit functions · ef57137f
      Paolo Bonzini authored
      
      Destructors are the main additional feature of pthread TLS compared
      to __thread.  If we were using C++ (hint, hint!) we could have used
      thread-local objects with a destructor.  Since we are not, instead,
      we add a simple Notifier-based API.
      
      Note that the notifier must be per-thread as well.  We can add a
      global list as well later, perhaps.
      
      The Win32 implementation has some complications because a) detached
      threads used not to have a QemuThreadData; b) the main thread does
      not go through win32_start_routine, so we have to use atexit too.
      
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Reviewed-by: default avatarFam Zheng <famz@redhat.com>
      Message-id: 1417518350-6167-3-git-send-email-pbonzini@redhat.com
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      ef57137f
  20. Mar 27, 2014
  21. Mar 09, 2014
  22. Oct 17, 2013
    • Paolo Bonzini's avatar
      qemu-thread: add QemuEvent · c7c4d063
      Paolo Bonzini authored
      
      This emulates Win32 manual-reset events using futexes or conditional
      variables.  Typical ways to use them are with multi-producer,
      single-consumer data structures, to test for a complex condition whose
      elements come from different threads:
      
          for (;;) {
              qemu_event_reset(ev);
              ... test complex condition ...
              if (condition is true) {
                  break;
              }
              qemu_event_wait(ev);
          }
      
      Or more efficiently (but with some duplication):
      
          ... evaluate condition ...
          while (!condition) {
              qemu_event_reset(ev);
              ... evaluate condition ...
              if (!condition) {
                  qemu_event_wait(ev);
                  ... evaluate condition ...
              }
          }
      
      QemuEvent provides a very fast userspace path in the common case when
      no other thread is waiting, or the event is not changing state.
      
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      c7c4d063
  23. Jan 12, 2013
  24. Dec 23, 2012
  25. Dec 19, 2012
  26. Oct 31, 2012
  27. Aug 02, 2012
  28. Feb 07, 2012
  29. Dec 15, 2011
  30. Dec 12, 2011
  31. Sep 21, 2011
  32. Aug 21, 2011
  33. Mar 19, 2011
  34. Mar 13, 2011
Loading