Skip to contentSkip to conversation

synchronization profiler

PATCH Superseded Emilio G. Cota 7 participants 20 messages Aug 13, 2018 – Aug 16, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover synchronization profiler

This series adds a synchronization profiler, similar to the one described in
https://www.usenix.org/system/files/conference/atc12/atc12-final237.pdf
, although without using perf counters.

The profiler allows us to identify what wait times in locks/condvars are, and where they are coming from. This info is very useful to identify scalability bottlenecks imposed by locks, particularly the BQL. I have patches (currently out of tree) to switch the BQL for per-CPU locks to keep track of CPU state; the profiler was really useful when doing that work.

The profiler is disabled by default, and can be enabled by configuring with --enable-sync-profiler. Overhead is pretty low though, see patch 1's commit log.

You can fetch the patches from:
https://github.com/cota/qemu/tree/sync-profiler

Note that checkpatch gives some warnings, but they are false positives.

Thanks,

Emilio

#1 lore raw

PATCH 1/3 qsp: QEMU's Synchronization Profiler

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, and in the report (see below) they will show up in different rows. See the comments at the top of qsp.c for further info on this decision and the overall design of QSP.

A report shows info about the tracked entries, sorted in descending order of total wait time. Sample output:

Type Object Call site Wait Time (s) Count Average (us)
---------------------------------------------------------------------------------------

condvar    0x557ee3090e80  cpus.c:1084              1.69207          2916        580.27
condvar    0x557ee30ceb10  cpus.c:1084              1.43442          2404        596.68
mutex      0x557ee2503540  cpus.c:1583              0.30300        636558          0.48
condvar    0x557ee2534460  cpus-common.c:216        0.13549         15513          8.73
condvar    0x557ee2534420  cpus-common.c:186        0.08927         15747          5.67
mutex      0x557ee3090a40  tcg/tcg.c:378            0.00823        120034          0.07
mutex      0x557ee3090a00  tcg/tcg.c:378            0.00820        117890          0.07
mutex      0x557ee3090ac0  tcg/tcg.c:378            0.00764        115954          0.07
mutex      0x557ee3090a80  tcg/tcg.c:378            0.00762        116573          0.07
mutex      0x557ee3090b00  tcg/tcg.c:378            0.00560         82547          0.07

---------------------------------------------------------------------------------------

Some perf numbers:

- Double-check that profiling disabled does not affect performance with `taskset -c 0 tests/atomic_add-bench -d 5 -m'. Host: AMD Opteron 6376.
- Before: 14.25 Mops/s
- After: 14.27 Mops/s (within noise range)

- Profiling overhead for `taskset -c 0 atomic_add-bench -d 5 -m' on AMD Opteron 6376:
- No profiling: 14.27 Mops/s
- W/ profiling: 3.05 Mops/s
- W/o get_clock: 6.73 Mops/s
That is, a 4.67X slowdown for mutex_lock.

The third result is the performance measured for an instrumented mutex_lock that does not call get_clock and instead just increments the number of acquisitions for each entry. With this we measure the overhead of just the instrumentation + the hash table lookup.

- `taskset -c 0 tests/atomic_add-bench -d 5 -m' on Intel Xeon E5-2690:
- W/o profiling: 33.95 Mops/s
- W/ profiling: 8.08 Mops/s
- W/o get_clock: 14.19 Mops/s
That is, a 4.20X slowdown for mutex_lock.

Synchronization primitives are not called very often during a regular QEMU run, so the overall performance impact of the profiler is quite tolerable, as the following results show.

- Boot + shut down of debian-aarch64, on Intel Xeon E5-2690, 3 runs:
-smp 1:

    - W/o profiling:
      16448.021211      task-clock (msec)         #    1.000 CPUs utilized            ( +-  0.27% )
            35,383      context-switches          #    0.002 M/sec                    ( +-  0.17% )
                 1      cpu-migrations            #    0.000 K/sec
            13,410      page-faults               #    0.815 K/sec                    ( +-  1.79% )
    47,526,630,360      cycles                    #    2.890 GHz                      ( +-  0.18% )  (83.33%)
    22,943,171,724      stalled-cycles-frontend   #   48.27% frontend cycles idle     ( +-  0.18% )  (83.35%)
    16,585,410,756      stalled-cycles-backend    #   34.90% backend  cycles idle     ( +-  0.32% )  (66.68%)
    60,962,863,668      instructions              #    1.28  insns per cycle
                                                  #    0.38  stalled cycles per insn  ( +-  0.06% )  (83.33%)
    10,910,210,349      branches                  #  663.314 M/sec                    ( +-  0.08% )  (83.33%)
       240,046,904      branch-misses             #    2.20% of all branches          ( +-  0.29% )  (83.33%)

      16.452269799 seconds time elapsed                                          ( +-  0.27% )

    - W/ profiling:
      16678.033593      task-clock (msec)         #    1.000 CPUs utilized            ( +-  0.09% )
            35,740      context-switches          #    0.002 M/sec                    ( +-  0.12% )
                 1      cpu-migrations            #    0.000 K/sec
            13,283      page-faults               #    0.796 K/sec                    ( +-  1.79% )
    48,208,446,365      cycles                    #    2.891 GHz                      ( +-  0.15% )  (83.34%)
    23,237,819,053      stalled-cycles-frontend   #   48.20% frontend cycles idle     ( +-  0.22% )  (83.34%)
    16,926,585,765      stalled-cycles-backend    #   35.11% backend  cycles idle     ( +-  0.30% )  (66.68%)
    61,620,102,560      instructions              #    1.28  insns per cycle
                                                  #    0.38  stalled cycles per insn  ( +-  0.20% )  (83.34%)
    11,015,082,852      branches                  #  660.455 M/sec                    ( +-  0.22% )  (83.32%)
       243,335,050      branch-misses             #    2.21% of all branches          ( +-  0.47% )  (83.33%)

      16.685661370 seconds time elapsed                                          ( +-  0.08% )

    That is, a 1.3% slowdown.

-smp 8:

    - W/o profiling:
      21591.674202      task-clock (msec)         #    2.512 CPUs utilized            ( +-  0.04% )
           428,423      context-switches          #    0.020 M/sec                    ( +-  0.38% )
             8,474      cpu-migrations            #    0.392 K/sec                    ( +-  1.64% )
            27,668      page-faults               #    0.001 M/sec                    ( +-  4.56% )
    58,611,751,157      cycles                    #    2.715 GHz                      ( +-  0.27% )  (83.40%)
    31,033,543,440      stalled-cycles-frontend   #   52.95% frontend cycles idle     ( +-  0.45% )  (82.98%)
    22,983,788,382      stalled-cycles-backend    #   39.21% backend  cycles idle     ( +-  0.50% )  (66.80%)
    67,020,810,260      instructions              #    1.14  insns per cycle
                                                  #    0.46  stalled cycles per insn  ( +-  0.21% )  (83.45%)
    12,050,905,600      branches                  #  558.127 M/sec                    ( +-  0.16% )  (83.40%)
       271,074,726      branch-misses             #    2.25% of all branches          ( +-  0.33% )  (83.42%)

       8.595004141 seconds time elapsed                                          ( +-  0.65% )

    - W/ profiling:
      22227.582945      task-clock (msec)         #    2.516 CPUs utilized            ( +-  0.71% )
           487,009      context-switches          #    0.022 M/sec                    ( +-  1.43% )
             9,049      cpu-migrations            #    0.407 K/sec                    ( +-  0.99% )
            25,963      page-faults               #    0.001 M/sec                    ( +-  1.70% )
    60,705,049,201      cycles                    #    2.731 GHz                      ( +-  0.52% )  (83.33%)
    32,225,054,360      stalled-cycles-frontend   #   53.08% frontend cycles idle     ( +-  0.39% )  (83.50%)
    23,943,332,206      stalled-cycles-backend    #   39.44% backend  cycles idle     ( +-  0.40% )  (66.79%)
    68,775,229,321      instructions              #    1.13  insns per cycle
                                                  #    0.47  stalled cycles per insn  ( +-  0.45% )  (83.38%)
    12,361,594,986      branches                  #  556.138 M/sec                    ( +-  0.36% )  (83.46%)
       281,775,777      branch-misses             #    2.28% of all branches          ( +-  1.16% )  (82.93%)

       8.836031859 seconds time elapsed                                          ( +-  1.07% )

    That is, a 2.7% slowdown.

- Boot + shut down of debian-aarch64, on AMD Opteron 6376, 3 runs:
-smp 1:

    - W/o profiling:
      27601.373288      task-clock (msec)         #    0.999 CPUs utilized            ( +-  0.74% )
            51,532      context-switches          #    0.002 M/sec                    ( +-  0.49% )
                 1      cpu-migrations            #    0.000 K/sec
            22,085      page-faults               #    0.800 K/sec                    ( +-  1.94% )
    63,051,935,104      cycles                    #    2.284 GHz                      ( +-  0.59% )  (83.32%)
    15,210,275,327      stalled-cycles-frontend   #   24.12% frontend cycles idle     ( +-  1.57% )  (83.33%)
    12,701,776,029      stalled-cycles-backend    #   20.14% backend  cycles idle     ( +-  0.65% )  (33.35%)
    64,895,509,291      instructions              #    1.03  insns per cycle
                                                  #    0.23  stalled cycles per insn  ( +-  0.15% )  (50.03%)
    11,598,175,695      branches                  #  420.203 M/sec                    ( +-  0.12% )  (66.69%)
       424,964,774      branch-misses             #    3.66% of all branches          ( +-  2.44% )  (83.34%)

      27.634390949 seconds time elapsed                                          ( +-  0.73% )

    - W/ profiling:
      28539.459861      task-clock (msec)         #    0.999 CPUs utilized            ( +-  0.90% )
            52,971      context-switches          #    0.002 M/sec                    ( +-  0.62% )
                 1      cpu-migrations            #    0.000 K/sec
            22,828      page-faults               #    0.800 K/sec                    ( +-  2.19% )
    65,196,667,837      cycles                    #    2.284 GHz                      ( +-  0.76% )  (83.32%)
    16,438,749,522      stalled-cycles-frontend   #   25.21% frontend cycles idle     ( +-  2.44% )  (83.34%)
    13,080,610,434      stalled-cycles-backend    #   20.06% backend  cycles idle     ( +-  1.22% )  (33.35%)
    65,744,290,786      instructions              #    1.01  insns per cycle
                                                  #    0.25  stalled cycles per insn  ( +-  0.17% )  (50.05%)
    11,760,663,051      branches                  #  412.084 M/sec                    ( +-  0.11% )  (66.69%)
       433,815,865      branch-misses             #    3.69% of all branches          ( +-  2.27% )  (83.34%)

      28.558462655 seconds time elapsed                                          ( +-  0.90% )

    That is, a 3.5% slowdown.

-smp 8:

    - W/o profiling:
      67084.039812      task-clock (msec)         #    3.075 CPUs utilized            ( +-  0.57% )
           448,562      context-switches          #    0.007 M/sec                    ( +-  1.30% )
            13,417      cpu-migrations            #    0.200 K/sec                    ( +-  1.67% )
            38,428      page-faults               #    0.573 K/sec                    ( +-  2.60% )
    92,018,881,848      cycles                    #    1.372 GHz                      ( +-  0.51% )  (83.27%)
    24,887,145,043      stalled-cycles-frontend   #   27.05% frontend cycles idle     ( +-  0.97% )  (83.31%)
    10,843,517,286      stalled-cycles-backend    #   11.78% backend  cycles idle     ( +-  0.84% )  (33.45%)
    72,663,707,013      instructions              #    0.79  insns per cycle
                                                  #    0.34  stalled cycles per insn  ( +-  0.34% )  (50.14%)
    13,148,472,626      branches                  #  196.000 M/sec                    ( +-  0.26% )  (66.68%)
       524,683,844      branch-misses             #    3.99% of all branches          ( +-  0.31% )  (83.34%)

      21.816863743 seconds time elapsed                                          ( +-  1.37% )

    - W/ profiling:
      72646.052577      task-clock (msec)         #    3.088 CPUs utilized            ( +-  0.52% )
           558,334      context-switches          #    0.008 M/sec                    ( +-  0.35% )
            16,471      cpu-migrations            #    0.227 K/sec                    ( +-  1.35% )
            40,420      page-faults               #    0.556 K/sec                    ( +-  2.31% )
    99,025,850,252      cycles                    #    1.363 GHz                      ( +-  0.19% )  (83.14%)
    28,317,752,389      stalled-cycles-frontend   #   28.60% frontend cycles idle     ( +-  0.21% )  (83.29%)
    11,370,442,683      stalled-cycles-backend    #   11.48% backend  cycles idle     ( +-  0.78% )  (33.59%)
    75,859,240,699      instructions              #    0.77  insns per cycle
                                                  #    0.37  stalled cycles per insn  ( +-  0.11% )  (50.25%)
    13,774,590,759      branches                  #  189.612 M/sec                    ( +-  0.10% )  (66.87%)
       541,354,013      branch-misses             #    3.93% of all branches          ( +-  0.13% )  (83.50%)

      23.525659377 seconds time elapsed                                          ( +-  0.90% )

    That is, a 7.8% slowdown.

Note that as -smp increases the memory footprint of the profiling data grows as well, which explains the slowdown increase as we add more guest CPUs.

---
 configure                   |   8 +
 include/qemu/qht.h          |   1 +
 include/qemu/qsp.h          |  38 +++
 include/qemu/thread-posix.h |   4 +-
 include/qemu/thread-win32.h |   5 +-
 include/qemu/thread.h       |  41 ++-
 util/qemu-thread-win32.c    |   4 +-
 util/qht.c                  |  47 +++-
 util/qsp.c                  | 545 ++++++++++++++++++++++++++++++++++++
 util/Makefile.objs          |   1 +
 10 files changed, 671 insertions(+), 23 deletions(-)
 create mode 100644 include/qemu/qsp.h
 create mode 100644 util/qsp.c
configure +8 -0
index 2a7796ea80..d7fead7c85 100755
@@ -408,6 +408,7 @@ bsd="no"
 linux="no"
 solaris="no"
 profiler="no"
+sync_profiler="no"
 cocoa="no"
 softmmu="yes"
 linux_user="no"
@@ -1163,6 +1164,8 @@ for opt do
   ;;
   --enable-profiler) profiler="yes"
   ;;
+  --enable-sync-profiler) sync_profiler="yes"
+  ;;
   --disable-cocoa) cocoa="no"
   ;;
   --enable-cocoa)
@@ -1621,6 +1624,7 @@ Advanced options (experts only):
   --tls-priority           default TLS protocol/cipher priority string
   --enable-gprof           QEMU profiling with gprof
   --enable-profiler        profiler support
+  --enable-sync-profiler   support profiling of synchronization primitives
   --enable-xen-pv-domain-build
                            xen pv domain builder
   --enable-debug-stack-usage
@@ -5893,6 +5897,7 @@ echo "gprof enabled     $gprof"
 echo "sparse enabled    $sparse"
 echo "strip binaries    $strip_opt"
 echo "profiler          $profiler"
+echo "sync profiler     $sync_profiler"
 echo "static build      $static"
 if test "$darwin" = "yes" ; then
     echo "Cocoa support     $cocoa"
@@ -6146,6 +6151,9 @@ fi
 if test "$profiler" = "yes" ; then
   echo "CONFIG_PROFILER=y" >> $config_host_mak
 fi
+if test "$sync_profiler" = "yes" ; then
+  echo "CONFIG_SYNC_PROFILER=y" >> $config_host_mak
+fi
 if test "$slirp" = "yes" ; then
   echo "CONFIG_SLIRP=y" >> $config_host_mak
   echo "CONFIG_SMBD_COMMAND=\"$smbd\"" >> $config_host_mak
include/qemu/qht.h +1 -0
index 1fb9116fa0..c9a11cc29a 100644
@@ -46,6 +46,7 @@ typedef bool (*qht_lookup_func_t)(const void *obj, const void *userp);
 typedef void (*qht_iter_func_t)(struct qht *ht, void *p, uint32_t h, void *up);
 
 #define QHT_MODE_AUTO_RESIZE 0x1 /* auto-resize when heavily loaded */
+#define QHT_MODE_RAW_MUTEXES 0x2 /* bypass the profiler (QSP) */
 
 /**
  * qht_init - Initialize a QHT
include/qemu/qsp.h new file +38 -0
new file mode 100644
index 0000000000..e36f94ab1d
@@ -0,0 +1,38 @@
+/*
+ * qsp.c - QEMU Synchronization Profiler
+ *
+ * Copyright (C) 2017, Emilio G. Cota <[email protected]>
+ *
+ * License: GNU GPL, version 2 or later.
+ *   See the COPYING file in the top-level directory.
+ *
+ * Note: this header file can *only* be included from thread.h.
+ */
+#ifndef QEMU_QSP_H
+#define QEMU_QSP_H
+
+#include "qemu/fprintf-fn.h"
+
+#ifdef CONFIG_SYNC_PROFILER
+
+void qsp_mutex_lock(QemuMutex *mutex, const char *file, unsigned line);
+int qsp_mutex_trylock(QemuMutex *mutex, const char *file, unsigned line);
+
+void qsp_rec_mutex_lock(QemuRecMutex *mutex, const char *file, unsigned line);
+int qsp_rec_mutex_trylock(QemuRecMutex *mutex, const char *file, unsigned line);
+
+void qsp_cond_wait(QemuCond *cond, QemuMutex *mutex, const char *file,
+                   unsigned line);
+
+void qsp_report(FILE *f, fprintf_function cpu_fprintf, size_t max);
+
+#else /* !CONF_SYNC_PROFILER */
+
+static inline void qsp_report(FILE *f, fprintf_function cpu_fprintf, size_t max)
+{
+    cpu_fprintf(f, "[Sync profiler not compiled]\n");
+}
+
+#endif /* !CONF_SYNC_PROFILER */
+
+#endif /* QEMU_QSP_H */
include/qemu/thread-posix.h +2 -2
index fd27b34128..c903525062 100644
@@ -6,8 +6,8 @@
 
 typedef QemuMutex QemuRecMutex;
 #define qemu_rec_mutex_destroy qemu_mutex_destroy
-#define qemu_rec_mutex_lock qemu_mutex_lock
-#define qemu_rec_mutex_trylock qemu_mutex_trylock
+#define qemu_rec_mutex_lock_impl    qemu_mutex_lock_impl
+#define qemu_rec_mutex_trylock_impl qemu_mutex_trylock_impl
 #define qemu_rec_mutex_unlock qemu_mutex_unlock
 
 struct QemuMutex {
include/qemu/thread-win32.h +3 -2
index d668d789b4..50af5dd7ab 100644
@@ -19,8 +19,9 @@ struct QemuRecMutex {
 };
 
 void qemu_rec_mutex_destroy(QemuRecMutex *mutex);
-void qemu_rec_mutex_lock(QemuRecMutex *mutex);
-int qemu_rec_mutex_trylock(QemuRecMutex *mutex);
+void qemu_rec_mutex_lock_impl(QemuRecMutex *mutex, const char *file, int line);
+int qemu_rec_mutex_trylock_impl(QemuRecMutex *mutex, const char *file,
+                                int line);
 void qemu_rec_mutex_unlock(QemuRecMutex *mutex);
 
 struct QemuCond {
include/qemu/thread.h +34 -7

65 lines not on this page · raw message

util/qemu-thread-win32.c +2 -2
index b303188a36..4a363ca675 100644
@@ -97,13 +97,13 @@ void qemu_rec_mutex_destroy(QemuRecMutex *mutex)
     DeleteCriticalSection(&mutex->lock);
 }
 
-void qemu_rec_mutex_lock(QemuRecMutex *mutex)
+void qemu_rec_mutex_lock_impl(QemuRecMutex *mutex, const char *file, int line)
 {
     assert(mutex->initialized);
     EnterCriticalSection(&mutex->lock);
 }
 
-int qemu_rec_mutex_trylock(QemuRecMutex *mutex)
+int qemu_rec_mutex_trylock_impl(QemuRecMutex *mutex, const char *file, int line)
 {
     assert(mutex->initialized);
     return !TryEnterCriticalSection(&mutex->lock);
util/qht.c +37 -10

105 lines not on this page · raw message

util/qsp.c new file +545 -0

545 lines not on this page · raw message

util/Makefile.objs +1 -0
index e1c3fed4dc..579faa2ca6 100644
@@ -3,6 +3,7 @@ util-obj-y += bufferiszero.o
 util-obj-y += lockcnt.o
 util-obj-y += aiocb.o async.o aio-wait.o thread-pool.o qemu-timer.o
 util-obj-y += main-loop.o iohandler.o
+util-obj-$(CONFIG_SYNC_PROFILER) += qsp.o
 util-obj-$(CONFIG_POSIX) += aio-posix.o
 util-obj-$(CONFIG_POSIX) += compatfd.o
 util-obj-$(CONFIG_POSIX) += event_notifier-posix.o
Signature · 1 line
2.17.1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] qsp: QEMU's Synchronization Profiler

Quoted 1 line · Emilio G. Cota

+ struct qsp_report rep;

Don't like camelcase? But that's really all that I have to remark on this lovely series.

Paolo

#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] qsp: QEMU's Synchronization Profiler

Quoted 5 lines · Paolo Bonzini
Quoted 1 line · Emilio G. Cota

+ struct qsp_report rep;

Don't like camelcase? But that's really all that I have to remark on this lovely series.

I have a strong aversion to it :-)

But if that's a deal breaker, let me know.

Thanks,

		E.
#4 lore raw

Re: [Qemu-devel] [PATCH 1/3] qsp: QEMU's Synchronization Profiler

Quoted 8 lines · Emilio G. Cota
Quoted 5 lines · Paolo Bonzini
Quoted 1 line · Emilio G. Cota

+ struct qsp_report rep;

Don't like camelcase? But that's really all that I have to remark on this lovely series.

I have a strong aversion to it :-)

I despise it as much as anyone, but CODING_STYLE demands CamelCase for "type names" (which I interpret as typedef names), and convention (not codified in CODING_STYLE) demands typedef for struct types.

Quoted 1 line

But if that's a deal breaker, let me know.

Hold your nose and go with the flow.

#5 lore raw

Re: [Qemu-devel] [PATCH 1/3] qsp: QEMU's Synchronization Profiler

In reply to Emilio G. Cota

configure for opt do · line 1168

Quoted 2 lines · Emilio G. Cota
configure +2 -0
+  --enable-sync-profiler) sync_profiler="yes"
+  ;;

Curious, not asking for a change: can this be made a runtime option instead of compile time, since there's no library dependencies? That should make this somewhat easier to use.

util/qsp.c line 293

Quoted 7 lines
util/qsp.c new file +7 -0
+
+#define QSP_GEN_VOID(type_, qsp_t_, func_, impl_)                       \
+    void func_(type_ *obj, const char *file, unsigned line)             \
+    {                                                                   \
+        struct qsp_entry *e = qsp_entry_get(obj, file, line, qsp_t_);   \
+        int64_t t;                                                      \
+                                                                        \

No qsp_init()?

util/qsp.c line 306

Quoted 13 lines
util/qsp.c new file +13 -0
+        t = get_clock();                                                \
+        impl_(obj, file, line);                                         \
+        atomic_set(&e->ns, e->ns + get_clock() - t);                    \
+        atomic_set(&e->n_acqs, e->n_acqs + 1);                          \
+    }
+
+#define QSP_GEN_RET1(type_, qsp_t_, func_, impl_)                       \
+    int func_(type_ *obj, const char *file, unsigned line)              \
+    {                                                                   \
+        struct qsp_entry *e = qsp_entry_get(obj, file, line, qsp_t_);   \
+        int64_t t;                                                      \
+        int err;                                                        \
+                                                                        \

Same here.

Quoted 20 lines
util/qsp.c new file +20 -0
+        t = get_clock();                                                \
+        err = impl_(obj, file, line);                                   \
+        atomic_set(&e->ns, e->ns + get_clock() - t);                    \
+        if (!err) {                                                     \
+            atomic_set(&e->n_acqs, e->n_acqs + 1);                      \
+        }                                                               \
+        return err;                                                     \
+    }
+
+QSP_GEN_VOID(QemuMutex, QSP_MUTEX, qsp_mutex_lock, qemu_mutex_lock_impl)
+QSP_GEN_RET1(QemuMutex, QSP_MUTEX, qsp_mutex_trylock, qemu_mutex_trylock_impl)
+
+QSP_GEN_VOID(QemuRecMutex, QSP_REC_MUTEX, qsp_rec_mutex_lock,
+             qemu_rec_mutex_lock_impl)
+QSP_GEN_RET1(QemuRecMutex, QSP_REC_MUTEX, qsp_rec_mutex_trylock,
+             qemu_rec_mutex_trylock_impl)
+
+void qsp_cond_wait(QemuCond *cond, QemuMutex *mutex, const char *file,
+                   unsigned line)
+{

util/qsp.c line 336

Quoted 10 lines
util/qsp.c new file +10 -0
+    struct qsp_entry *e;
+    int64_t t;
+
+    qsp_init();
+
+    e = qsp_entry_get(cond, file, line, QSP_CONDVAR);
+    t = get_clock();
+    qemu_cond_wait_impl(cond, mutex, file, line);
+    atomic_set(&e->ns, e->ns + get_clock() - t);
+    atomic_set(&e->n_acqs, e->n_acqs + 1);

Why not atomic_add (both here and in above macros)? Because fetching e->ns and then updating it is not "atomic" this way.

Fam

#6 lore raw

Re: [Qemu-devel] [PATCH 1/3] qsp: QEMU's Synchronization Profiler

Quoted 7 lines · Fam Zheng

configure for opt do · line 1168

Quoted 2 lines · Emilio G. Cota
configure +2 -0
+  --enable-sync-profiler) sync_profiler="yes"
+  ;;

Curious, not asking for a change: can this be made a runtime option instead of compile time, since there's no library dependencies? That should make this somewhat easier to use.

Good point. I'll do some profiling tomorrow to see how the latency of the locking primitives could be minimized (ideally, not using the profiler should just add a well-predicted branch).

Quoted 10 lines

util/qsp.c line 293

Quoted 7 lines
util/qsp.c new file +7 -0
+
+#define QSP_GEN_VOID(type_, qsp_t_, func_, impl_)                       \
+    void func_(type_ *obj, const char *file, unsigned line)             \
+    {                                                                   \
+        struct qsp_entry *e = qsp_entry_get(obj, file, line, qsp_t_);   \
+        int64_t t;                                                      \
+                                                                        \

No qsp_init()?

Quoted 15 lines

util/qsp.c line 306

Quoted 13 lines
util/qsp.c new file +13 -0
+        t = get_clock();                                                \
+        impl_(obj, file, line);                                         \
+        atomic_set(&e->ns, e->ns + get_clock() - t);                    \
+        atomic_set(&e->n_acqs, e->n_acqs + 1);                          \
+    }
+
+#define QSP_GEN_RET1(type_, qsp_t_, func_, impl_)                       \
+    int func_(type_ *obj, const char *file, unsigned line)              \
+    {                                                                   \
+        struct qsp_entry *e = qsp_entry_get(obj, file, line, qsp_t_);   \
+        int64_t t;                                                      \
+        int err;                                                        \
+                                                                        \

Same here.

qsp_init is called by qsp_get_entry.

(snip)

Quoted 8 lines
Quoted 8 lines
util/qsp.c new file +8 -0
+void qsp_cond_wait(QemuCond *cond, QemuMutex *mutex, const char *file,
+                   unsigned line)
+{
+    struct qsp_entry *e;
+    int64_t t;
+
+    qsp_init();
+
Quoted 8 lines

util/qsp.c line 336

Quoted 5 lines
util/qsp.c new file +5 -0
+    e = qsp_entry_get(cond, file, line, QSP_CONDVAR);
+    t = get_clock();
+    qemu_cond_wait_impl(cond, mutex, file, line);
+    atomic_set(&e->ns, e->ns + get_clock() - t);
+    atomic_set(&e->n_acqs, e->n_acqs + 1);

Why not atomic_add (both here and in above macros)? Because fetching e->ns and then updating it is not "atomic" this way.

This isn't a read-modify-write op; atomic_set is used here as "write_once".

Note that struct qsp_entry is only ever modified by the current thread (thread_ptr is part of the struct; yes this uses a lot more memory but that's the price of scalability). The struct might be read anytime by other threads though, so we have to use atomic_set to avoid undefined behaviour (e.g. torn reads/writes).

Thanks,

Emilio

#7 lore raw

Re: [Qemu-devel] [PATCH 1/3] qsp: QEMU's Synchronization Profiler

Quoted 25 lines · Emilio G. Cota
Quoted 9 lines

util/qsp.c line 293

Quoted 6 lines
util/qsp.c new file +6 -0
+#define QSP_GEN_VOID(type_, qsp_t_, func_, impl_)                       \
+    void func_(type_ *obj, const char *file, unsigned line)             \
+    {                                                                   \
+        struct qsp_entry *e = qsp_entry_get(obj, file, line, qsp_t_);   \
+        int64_t t;                                                      \
+                                                                        \

No qsp_init()?

Quoted 15 lines

util/qsp.c line 306

Quoted 13 lines
util/qsp.c new file +13 -0
+        t = get_clock();                                                \
+        impl_(obj, file, line);                                         \
+        atomic_set(&e->ns, e->ns + get_clock() - t);                    \
+        atomic_set(&e->n_acqs, e->n_acqs + 1);                          \
+    }
+
+#define QSP_GEN_RET1(type_, qsp_t_, func_, impl_)                       \
+    int func_(type_ *obj, const char *file, unsigned line)              \
+    {                                                                   \
+        struct qsp_entry *e = qsp_entry_get(obj, file, line, qsp_t_);   \
+        int64_t t;                                                      \
+        int err;                                                        \
+                                                                        \

Same here.

Quoted 1 line

qsp_init is called by qsp_get_entry.

Oh yes, I missed it. Then you can remove the one in qsp_cond_wait() as well for consistency. (That's where I noticed this).

Fam

#8 lore raw

Re: [Qemu-devel] [PATCH 1/3] qsp: QEMU's Synchronization Profiler

In reply to Emilio G. Cota
Quoted 5 lines · Emilio G. Cota
Quoted 4 lines · Fam Zheng
Quoted 2 lines · Emilio G. Cota
configure +2 -0
+  --enable-sync-profiler) sync_profiler="yes"
+  ;;
Quoted 7 lines
Quoted 3 lines

Curious, not asking for a change: can this be made a runtime option instead of compile time, since there's no library dependencies? That should make this somewhat easier to use.

Good point. I'll do some profiling tomorrow to see how the latency of the locking primitives could be minimized (ideally, not using the profiler should just add a well-predicted branch).

I reduced it to just a branch, but still, I measured a few percentage points (1-2%, depending on the machine) slowdown when this is a run-time option. (This is for a bootup+shutdown test of a guest.)

So I'll keep it as a build-time option, then.

Thanks,

Emilio

#9 lore raw

Re: [Qemu-devel] [PATCH 1/3] qsp: QEMU's Synchronization Profiler

Quoted 14 lines · Emilio G. Cota
Quoted 5 lines · Emilio G. Cota
Quoted 4 lines · Fam Zheng
Quoted 2 lines · Emilio G. Cota
configure +2 -0
+  --enable-sync-profiler) sync_profiler="yes"
+  ;;
Quoted 7 lines
Quoted 3 lines

Curious, not asking for a change: can this be made a runtime option instead of compile time, since there's no library dependencies? That should make this somewhat easier to use.

Good point. I'll do some profiling tomorrow to see how the latency of the locking primitives could be minimized (ideally, not using the profiler should just add a well-predicted branch).

Quoted 5 lines

I reduced it to just a branch, but still, I measured a few percentage points (1-2%, depending on the machine) slowdown when this is a run-time option. (This is for a bootup+shutdown test of a guest.)

So I'll keep it as a build-time option, then.

I looked further into this. Turns out we don't need the branch at all; we can make indirect calls via function pointers, where the pointers are set by qsp_enable/disable().

Overhead of doing things this way is within noise range, since compilers and CPUs are so good at dealing with indirect calls.

I'll send a v2 tomorrow.

Emilio

#10 lore raw

Re: [Qemu-devel] [PATCH 1/3] qsp: QEMU's Synchronization Profiler

Quoted 19 lines · Emilio G. Cota
Quoted 18 lines · Emilio G. Cota
Quoted 5 lines · Emilio G. Cota
Quoted 4 lines · Fam Zheng
Quoted 2 lines · Emilio G. Cota
configure +2 -0
+  --enable-sync-profiler) sync_profiler="yes"
+  ;;
Quoted 7 lines
Quoted 3 lines

Curious, not asking for a change: can this be made a runtime option instead of compile time, since there's no library dependencies? That should make this somewhat easier to use.

Good point. I'll do some profiling tomorrow to see how the latency of the locking primitives could be minimized (ideally, not using the profiler should just add a well-predicted branch).

I reduced it to just a branch, but still, I measured a few percentage points (1-2%, depending on the machine) slowdown when this is a run-time option. (This is for a bootup+shutdown test of a guest.)

Quoted 8 lines
Quoted 1 line

So I'll keep it as a build-time option, then.

I looked further into this. Turns out we don't need the branch at all; we can make indirect calls via function pointers, where the pointers are set by qsp_enable/disable().

Overhead of doing things this way is within noise range, since compilers and CPUs are so good at dealing with indirect calls.

Very nice finding! Thanks.

Fam

Quoted 4 lines

I'll send a v2 tomorrow.

Emilio

#11 lore raw

PATCH 2/3 monitor: show sync profiling info with 'info sync'

In reply to Emilio G. Cota
---
 monitor.c            |  7 +++++++
 hmp-commands-info.hx | 16 ++++++++++++++++
 2 files changed, 23 insertions(+)
monitor.c +7 -0
index 77861e96af..66d8d85b97 100644
@@ -1454,6 +1454,13 @@ static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
 }
 #endif
 
+static void hmp_info_sync(Monitor *mon, const QDict *qdict)
+{
+    int64_t max = qdict_get_try_int(qdict, "max", 10);
+
+    qsp_report((FILE *)mon, monitor_fprintf, max);
+}
+
 static void hmp_info_history(Monitor *mon, const QDict *qdict)
 {
     int i;
hmp-commands-info.hx +16 -0
index 70639f656a..56a3249bad 100644
@@ -297,6 +297,22 @@ STEXI
 @item info opcount
 @findex info opcount
 Show dynamic compiler opcode counters
+ETEXI
+
+    {
+        .name       = "sync",
+        .args_type  = "max:i?",
+        .params     = "[max]",
+        .help       = "show sync profiling info for "
+	              "up to max entries (default: 10). "
+		      "Entries are sorted by wait time.",
+        .cmd        = hmp_info_sync,
+    },
+
+STEXI
+@item info sync
+@findex sync
+Show sync profiling info.
 ETEXI
 
     {
Signature · 1 line
2.17.1
#12 lore raw

Re: [Qemu-devel] [PATCH 2/3] monitor: show sync profiling info with 'info sync'

Quoted 11 lines · Emilio G. Cota
hmp-commands-info.hx +3 -0
index 70639f656a..56a3249bad 100644
@@ -297,6 +297,22 @@ STEXI
 @item info opcount
 @findex info opcount
 Show dynamic compiler opcode counters
+ETEXI
+
+    {

hmp-commands-info.hx STEXI · line 312

Quoted 10 lines
hmp-commands-info.hx +10 -0
+        .name       = "sync",
+        .args_type  = "max:i?",
+        .params     = "[max]",
+        .help       = "show sync profiling info for "
+	              "up to max entries (default: 10). "
+		      "Entries are sorted by wait time.",
+        .cmd        = hmp_info_sync,
+    },
+
+STEXI

Would it make sense to add a flag to sort by average wait time, and one to coalesce all mutexes for the same call site?

Can be done separately of course.

Paolo

#13 lore raw

Re: [Qemu-devel] [PATCH 2/3] monitor: show sync profiling info with 'info sync'

Quoted 2 lines · Paolo Bonzini

On 13/08/2018 19:11, Emilio G. Cota wrote:
Would it make sense to add a flag to sort by average wait time

Done:

(qemu) help info sync-profile
info sync-profile [-m] [max] -- show sync profiling info \
for up to max entries (default: 10). By default, entries \
are sorted by total wait time; -m sorts by mean wait time.

(qemu) info sync-profile 3
Type Object Call site Wait Time (s) Count Average (us)
------------------------------------------------------------------------------------

condvar    0x560cc9909e50  cpus.c:1165          63.63428         16081       3957.11
condvar    0x560cc9909e50  cpus.c:1415           0.21074             2     105371.07
BQL mutex  0x560cc85a3fa0  util/rcu.c:269        0.20227            20      10113.60

------------------------------------------------------------------------------------

(qemu) info sync-profile -m 3
Type Object Call site Wait Time (s) Count Average (us)
------------------------------------------------------------------------------------

condvar    0x560cc9909e50  cpus.c:1415           0.21074             2     105371.07
BQL mutex  0x560cc85a3fa0  util/rcu.c:269        0.20227            21       9632.00
condvar    0x560cc9909e50  cpus.c:1165          71.92799         18167       3959.27

------------------------------------------------------------------------------------

Quoted 1 line

, and one to coalesce all mutexes for the same call site?

I am not sure I understand. Do you mean to pass a specific call site, so that we coalesce all entries related to the call site's object? Or to keep the call sites separate, but only report entries related to that specific call site's object?

Thanks,

Emilio

#14 lore raw

Re: [Qemu-devel] [PATCH 2/3] monitor: show sync profiling info with 'info sync'

Quoted 25 lines · Emilio G. Cota
Quoted 2 lines · Paolo Bonzini

On 13/08/2018 19:11, Emilio G. Cota wrote:
Would it make sense to add a flag to sort by average wait time

Done:

(qemu) help info sync-profile
info sync-profile [-m] [max] -- show sync profiling info \
for up to max entries (default: 10). By default, entries \
are sorted by total wait time; -m sorts by mean wait time.

(qemu) info sync-profile 3
Type Object Call site Wait Time (s) Count Average (us)
------------------------------------------------------------------------------------

condvar    0x560cc9909e50  cpus.c:1165          63.63428         16081       3957.11
condvar    0x560cc9909e50  cpus.c:1415           0.21074             2     105371.07
BQL mutex  0x560cc85a3fa0  util/rcu.c:269        0.20227            20      10113.60

------------------------------------------------------------------------------------

(qemu) info sync-profile -m 3
Type Object Call site Wait Time (s) Count Average (us)
------------------------------------------------------------------------------------

condvar    0x560cc9909e50  cpus.c:1415           0.21074             2     105371.07
BQL mutex  0x560cc85a3fa0  util/rcu.c:269        0.20227            21       9632.00
condvar    0x560cc9909e50  cpus.c:1165          71.92799         18167       3959.27
Quoted 8 lines

------------------------------------------------------------------------------------

Quoted 1 line

, and one to coalesce all mutexes for the same call site?

I am not sure I understand. Do you mean to pass a specific call site, so that we coalesce all entries related to the call site's object? Or to keep the call sites separate, but only report entries related to that specific call site's object?

I would guess Paolo means that whether we can merge entries that have the same call site but with different object addresses. I copied one example from the commit message of your patch 1:

Type Object Call site Wait Time (s) Count Average (us)
---------------------------------------------------------------------------------------

condvar    0x557ee3090e80  cpus.c:1084              1.69207          2916        580.27
condvar    0x557ee30ceb10  cpus.c:1084              1.43442          2404        596.68

...

IMHO merging of these two entries might be helpful when e.g. the condvar used there is dynamically created/destroyed, then in this case the object pointer might not that helpful, instead the statistics of all the entries for the same call site might tell more.

Regards,

Signature · 1 line
Peter Xu
#15 lore raw

Re: [Qemu-devel] [PATCH 2/3] monitor: show sync profiling info with 'info sync'

In reply to Emilio G. Cota
Quoted 41 lines · * Emilio G. Cota ([email protected]) wrote:
---
 monitor.c            |  7 +++++++
 hmp-commands-info.hx | 16 ++++++++++++++++
 2 files changed, 23 insertions(+)
monitor.c +7 -0
index 77861e96af..66d8d85b97 100644
@@ -1454,6 +1454,13 @@ static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
 }
 #endif
 
+static void hmp_info_sync(Monitor *mon, const QDict *qdict)
+{
+    int64_t max = qdict_get_try_int(qdict, "max", 10);
+
+    qsp_report((FILE *)mon, monitor_fprintf, max);
+}
+
 static void hmp_info_history(Monitor *mon, const QDict *qdict)
 {
     int i;
hmp-commands-info.hx +9 -0
index 70639f656a..56a3249bad 100644
@@ -297,6 +297,22 @@ STEXI
 @item info opcount
 @findex info opcount
 Show dynamic compiler opcode counters
+ETEXI
+
+    {
+        .name       = "sync",
+        .args_type  = "max:i?",
+        .params     = "[max]",
+        .help       = "show sync profiling info for "
+	              "up to max entries (default: 10). "
+		      "Entries are sorted by wait time.",

hmp-commands-info.hx STEXI · line 318

Quoted 10 lines
hmp-commands-info.hx +7 -0
+        .cmd        = hmp_info_sync,
+    },
+
+STEXI
+@item info sync
+@findex sync
+Show sync profiling info.
 ETEXI
 
     {

As long as this is just for devs I'm OK with this from the HMP side; however, if you want to automate the display or wire it to other tools then you should probably wire it up via QMP.

Dave

Quoted 3 lines
Signature · 1 line
2.17.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#16 lore raw

Re: [Qemu-devel] [PATCH 2/3] monitor: show sync profiling info with 'info sync'

In reply to Emilio G. Cota
Quoted 29 lines · Emilio G. Cota
---
 monitor.c            |  7 +++++++
 hmp-commands-info.hx | 16 ++++++++++++++++
 2 files changed, 23 insertions(+)
monitor.c +7 -0
index 77861e96af..66d8d85b97 100644
@@ -1454,6 +1454,13 @@ static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
 }
 #endif
 
+static void hmp_info_sync(Monitor *mon, const QDict *qdict)
+{
+    int64_t max = qdict_get_try_int(qdict, "max", 10);
+
+    qsp_report((FILE *)mon, monitor_fprintf, max);
+}
+
 static void hmp_info_history(Monitor *mon, const QDict *qdict)
 {
     int i;
hmp-commands-info.hx +0 -0
index 70639f656a..56a3249bad 100644

hmp-commands-info.hx STEXI · line 303

Quoted 7 lines
hmp-commands-info.hx +4 -0
@@ -297,6 +297,22 @@ STEXI
 @item info opcount
 @findex info opcount
 Show dynamic compiler opcode counters
+ETEXI
+
+    {
+        .name       = "sync",

I think "info sync-profile" would be clearer.

Quoted 5 lines
hmp-commands-info.hx +5 -0
+        .args_type  = "max:i?",
+        .params     = "[max]",
+        .help       = "show sync profiling info for "
+	              "up to max entries (default: 10). "
+		      "Entries are sorted by wait time.",

hmp-commands-info.hx STEXI · line 318

Quoted 10 lines
hmp-commands-info.hx +7 -0
+        .cmd        = hmp_info_sync,
+    },
+
+STEXI
+@item info sync
+@findex sync
+Show sync profiling info.
 ETEXI
 
     {

Please explain briefly why you think this command is not going to be useful in QMP. Recommend to do that right in your commit message. For instance, you could argue that the information provided is useful only to developers, and developers are just fine with getting it from HMP "info sync".

However, if we expect developers to further process the data, providing it as JSON (via QMP) makes sense, because is saves them the trouble of parsing your (undocumented) HMP output format.

If we decide we want to provide the functionality in QMP, I can help you with the necessary code changes.

#17 lore raw

Re: [Qemu-devel] [PATCH 2/3] monitor: show sync profiling info with 'info sync'

Quoted 6 lines · Dr. David Alan Gilbert
Quoted 1 line · * Emilio G. Cota ([email protected]) wrote:

+@item info sync

As long as this is just for devs I'm OK with this from the HMP side; however, if you want to automate the display or wire it to other tools then you should probably wire it up via QMP.

Quoted 9 lines · Markus Armbruster
Quoted 1 line · Emilio G. Cota

+@item info sync

Please explain briefly why you think this command is not going to be useful in QMP. Recommend to do that right in your commit message. For instance, you could argue that the information provided is useful only to developers, and developers are just fine with getting it from HMP "info sync".

Quoted 6 lines

However, if we expect developers to further process the data, providing it as JSON (via QMP) makes sense, because is saves them the trouble of parsing your (undocumented) HMP output format.

If we decide we want to provide the functionality in QMP, I can help you with the necessary code changes.

Thanks Dave and Markus for taking a look.

This is just for developers. This means (1) the info displayed and the output format could change in the future, and (2) it is only meant to be used from HMP "info sync-profile".

I'll include the above in the commit log, as Markus suggested.

Quoted 3 lines
Quoted 1 line

+ .name = "sync",

I think "info sync-profile" would be clearer.

Done.

Thanks,

Emilio

#18 lore raw

PATCH 3/3 qsp: track BQL callers directly

In reply to Emilio G. Cota

The BQL is acquired via qemu_mutex_lock_iothread(), which makes the profiler assign the associated wait time (i.e. most of BQL wait time) entirely to that function. This loses the original call site information, which does not help diagnose BQL contention. Fix it by tracking the callers directly when the lock profiler is enabled. While at it, add a QSP type specific to it, so that the BQL is reported as "BQL mutex".

- Before:
Type Object Call site Wait Time (s) Count Average (us)
---------------------------------------------------------------------------------------

condvar    0x557ee3090e80  cpus.c:1084              1.69207          2916        580.27
condvar    0x557ee30ceb10  cpus.c:1084              1.43442          2404        596.68
mutex      0x557ee2503540  cpus.c:1583              0.30300        636558          0.48
condvar    0x557ee2534460  cpus-common.c:216        0.13549         15513          8.73
condvar    0x557ee2534420  cpus-common.c:186        0.08927         15747          5.67
mutex      0x557ee3090a40  tcg/tcg.c:378            0.00823        120034          0.07
mutex      0x557ee3090a00  tcg/tcg.c:378            0.00820        117890          0.07
mutex      0x557ee3090ac0  tcg/tcg.c:378            0.00764        115954          0.07
mutex      0x557ee3090a80  tcg/tcg.c:378            0.00762        116573          0.07
mutex      0x557ee3090b00  tcg/tcg.c:378            0.00560         82547          0.07

---------------------------------------------------------------------------------------

- After:
Type Object Call site Wait Time (s) Count Average (us)
------------------------------------------------------------------------------------------------

condvar    0x555d4b37bb10  cpus.c:1084                       1.82472          1245       1465.64
condvar    0x555d4b33de80  cpus.c:1084                       1.22456          3105        394.38
condvar    0x555d48ee3460  cpus-common.c:216                 0.15380         18510          8.31
condvar    0x555d48ee3420  cpus-common.c:186                 0.10400         18303          5.68
BQL mutex  0x555d48eb2540  cpus.c:1272                       0.06565         77751          0.84
BQL mutex  0x555d48eb2540  target/arm/op_helper.c:837        0.04077         28317          1.44
BQL mutex  0x555d48eb2540  accel/tcg/cpu-exec.c:502          0.03935        149975          0.26
BQL mutex  0x555d48eb2540  target/arm/op_helper.c:851        0.03917         85698          0.46
BQL mutex  0x555d48eb2540  util/rcu.c:257                    0.03059             9       3399.36
BQL mutex  0x555d48eb2540  cpus-common.c:352                 0.02717         29992          0.91

------------------------------------------------------------------------------------------------

---
 include/qemu/main-loop.h | 10 +++++++++-
 include/qemu/qsp.h       |  2 ++
 cpus.c                   | 15 ++++++++++++++-
 stubs/iothread-lock.c    |  8 +++++++-
 util/qsp.c               |  4 ++++
 5 files changed, 36 insertions(+), 3 deletions(-)
include/qemu/main-loop.h +9 -1
index 721aa2416a..dc64731009 100644
@@ -276,7 +276,15 @@ bool qemu_mutex_iothread_locked(void);
  * NOTE: tools currently are single-threaded and qemu_mutex_lock_iothread
  * is a no-op there.
  */
-void qemu_mutex_lock_iothread(void);
+#ifdef CONFIG_SYNC_PROFILER
+void do_qemu_mutex_lock_iothread(const char *file, int line);
+#define qemu_mutex_lock_iothread()                      \
+    do_qemu_mutex_lock_iothread(__FILE__, __LINE__)
+#else
+void do_qemu_mutex_lock_iothread(void);
+#define qemu_mutex_lock_iothread()              \
+    do_qemu_mutex_lock_iothread()
+#endif
 
 /**
  * qemu_mutex_unlock_iothread: Unlock the main loop mutex.
include/qemu/qsp.h +2 -0
index e36f94ab1d..96a1fff1bb 100644
@@ -18,6 +18,8 @@
 void qsp_mutex_lock(QemuMutex *mutex, const char *file, unsigned line);
 int qsp_mutex_trylock(QemuMutex *mutex, const char *file, unsigned line);
 
+void qsp_bql_mutex_lock(QemuMutex *mutex, const char *file, unsigned line);
+
 void qsp_rec_mutex_lock(QemuRecMutex *mutex, const char *file, unsigned line);
 int qsp_rec_mutex_trylock(QemuRecMutex *mutex, const char *file, unsigned line);
 
cpus.c +14 -1
index b5844b7103..8ec034954b 100644
@@ -1762,12 +1762,25 @@ bool qemu_mutex_iothread_locked(void)
     return iothread_locked;
 }
 
-void qemu_mutex_lock_iothread(void)
+/*
+ * The BQL is taken from so many places that it is worth tracking the
+ * callers directly, instead of funneling them all through a single function.
+ */
+#ifdef CONFIG_SYNC_PROFILER
+void do_qemu_mutex_lock_iothread(const char *file, int line)
+{
+    g_assert(!qemu_mutex_iothread_locked());
+    qsp_bql_mutex_lock(&qemu_global_mutex, file, line);
+    iothread_locked = true;
+}
+#else
+void do_qemu_mutex_lock_iothread(void)
 {
     g_assert(!qemu_mutex_iothread_locked());
     qemu_mutex_lock(&qemu_global_mutex);
     iothread_locked = true;
 }
+#endif /* CONFIG_SYNC_PROFILER */
 
 void qemu_mutex_unlock_iothread(void)
 {
stubs/iothread-lock.c +7 -1
index 9b6db2e740..3d129f367c 100644
@@ -7,9 +7,15 @@ bool qemu_mutex_iothread_locked(void)
     return true;
 }
 
-void qemu_mutex_lock_iothread(void)
+#ifdef CONFIG_SYNC_PROFILER
+void do_qemu_mutex_lock_iothread(const char *file, int line)
 {
 }
+#else
+void do_qemu_mutex_lock_iothread(void)
+{
+}
+#endif
 
 void qemu_mutex_unlock_iothread(void)
 {
util/qsp.c +4 -0
index 908e99cccf..9f12762d36 100644
@@ -61,6 +61,7 @@
 
 enum qsp_type {
     QSP_MUTEX,
+    QSP_BQL_MUTEX,
     QSP_REC_MUTEX,
     QSP_CONDVAR,
 };
@@ -102,6 +103,7 @@ static bool qsp_initialized, qsp_initializing;
 
 static const char * const qsp_typenames[] = {
     [QSP_MUTEX]     = "mutex",
+    [QSP_BQL_MUTEX] = "BQL mutex",
     [QSP_REC_MUTEX] = "rec_mutex",
     [QSP_CONDVAR]   = "condvar",
 };
@@ -316,6 +318,8 @@ static struct qsp_entry *qsp_entry_get(const void *obj, const char *file,
 QSP_GEN_VOID(QemuMutex, QSP_MUTEX, qsp_mutex_lock, qemu_mutex_lock_impl)
 QSP_GEN_RET1(QemuMutex, QSP_MUTEX, qsp_mutex_trylock, qemu_mutex_trylock_impl)
 
+QSP_GEN_VOID(QemuMutex, QSP_BQL_MUTEX, qsp_bql_mutex_lock, qemu_mutex_lock_impl)
+
 QSP_GEN_VOID(QemuRecMutex, QSP_REC_MUTEX, qsp_rec_mutex_lock,
              qemu_rec_mutex_lock_impl)
 QSP_GEN_RET1(QemuRecMutex, QSP_REC_MUTEX, qsp_rec_mutex_trylock,
Signature · 1 line
2.17.1
#19 lore raw
In reply to Emilio G. Cota
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH 0/3] synchronization profiler

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 Switched to a new branch 'test'
ac8f1dcaca qsp: track BQL callers directly 6c0b389867 monitor: show sync profiling info with 'info sync' c43c6c8920 qsp: QEMU's Synchronization Profiler

=== OUTPUT BEGIN ===
Checking PATCH 1/3: qsp: QEMU's Synchronization Profiler...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #263:
new file mode 100644

ERROR: spaces required around that '*' (ctx:WxV)
#853: FILE: util/qsp.c:289:

+    void func_(type_ *obj, const char *file, unsigned line)             \
                      ^

ERROR: spaces required around that '*' (ctx:WxV)
#865: FILE: util/qsp.c:301:

+    int func_(type_ *obj, const char *file, unsigned line)              \
                     ^

ERROR: spaces required around that '-' (ctx:VxV)
#1028: FILE: util/qsp.c:464:

+    entry->time_s = e->ns * 1e-9;
                               ^

ERROR: spaces required around that '-' (ctx:VxV)
#1073: FILE: util/qsp.c:509:

+           "", e->time_s, e->n_acqs, e->ns_avg * 1e-3);
                                                    ^

total: 4 errors, 1 warnings, 841 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 2/3: monitor: show sync profiling info with 'info sync'... Checking PATCH 3/3: qsp: track BQL callers directly...
=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]