[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 22/74] qsp: track BQL callers explicitly
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 22/74] qsp: track BQL callers explicitly |
Date: |
Tue, 21 Aug 2018 19:01:54 +0200 |
From: "Emilio G. Cota" <address@hidden>
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 explicitly.
Signed-off-by: Emilio G. Cota <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
cpus.c | 10 ++++++++--
include/qemu/main-loop.h | 4 +++-
include/qemu/thread.h | 1 +
stubs/iothread-lock.c | 2 +-
util/qsp.c | 6 ++++++
5 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/cpus.c b/cpus.c
index b5844b7..a5ea3ee 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1762,10 +1762,16 @@ 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 profiling the
+ * callers directly, instead of funneling them all through a single function.
+ */
+void qemu_mutex_lock_iothread_impl(const char *file, int line)
{
+ QemuMutexLockFunc bql_lock = atomic_read(&qemu_bql_mutex_lock_func);
+
g_assert(!qemu_mutex_iothread_locked());
- qemu_mutex_lock(&qemu_global_mutex);
+ bql_lock(&qemu_global_mutex, file, line);
iothread_locked = true;
}
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
index 721aa24..e59f9ae 100644
--- a/include/qemu/main-loop.h
+++ b/include/qemu/main-loop.h
@@ -276,7 +276,9 @@ 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);
+#define qemu_mutex_lock_iothread() \
+ qemu_mutex_lock_iothread_impl(__FILE__, __LINE__)
+void qemu_mutex_lock_iothread_impl(const char *file, int line);
/**
* qemu_mutex_unlock_iothread: Unlock the main loop mutex.
diff --git a/include/qemu/thread.h b/include/qemu/thread.h
index c90ea47..dacebcf 100644
--- a/include/qemu/thread.h
+++ b/include/qemu/thread.h
@@ -35,6 +35,7 @@ typedef int (*QemuRecMutexTrylockFunc)(QemuRecMutex *m, const
char *f, int l);
typedef void (*QemuCondWaitFunc)(QemuCond *c, QemuMutex *m, const char *f,
int l);
+extern QemuMutexLockFunc qemu_bql_mutex_lock_func;
extern QemuMutexLockFunc qemu_mutex_lock_func;
extern QemuMutexTrylockFunc qemu_mutex_trylock_func;
extern QemuRecMutexLockFunc qemu_rec_mutex_lock_func;
diff --git a/stubs/iothread-lock.c b/stubs/iothread-lock.c
index 9b6db2e..eb745d7 100644
--- a/stubs/iothread-lock.c
+++ b/stubs/iothread-lock.c
@@ -7,7 +7,7 @@ bool qemu_mutex_iothread_locked(void)
return true;
}
-void qemu_mutex_lock_iothread(void)
+void qemu_mutex_lock_iothread_impl(const char *file, int line)
{
}
diff --git a/util/qsp.c b/util/qsp.c
index 4dc851e..b0c2575 100644
--- a/util/qsp.c
+++ b/util/qsp.c
@@ -65,6 +65,7 @@
enum QSPType {
QSP_MUTEX,
+ QSP_BQL_MUTEX,
QSP_REC_MUTEX,
QSP_CONDVAR,
};
@@ -123,10 +124,12 @@ 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",
};
+QemuMutexLockFunc qemu_bql_mutex_lock_func = qemu_mutex_lock_impl;
QemuMutexLockFunc qemu_mutex_lock_func = qemu_mutex_lock_impl;
QemuMutexTrylockFunc qemu_mutex_trylock_func = qemu_mutex_trylock_impl;
QemuRecMutexLockFunc qemu_rec_mutex_lock_func = qemu_rec_mutex_lock_impl;
@@ -419,6 +422,7 @@ static inline void qsp_entry_record(QSPEntry *e, int64_t
delta)
return err; \
}
+QSP_GEN_VOID(QemuMutex, QSP_BQL_MUTEX, qsp_bql_mutex_lock,
qemu_mutex_lock_impl)
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)
@@ -453,6 +457,7 @@ void qsp_enable(void)
{
atomic_set(&qemu_mutex_lock_func, qsp_mutex_lock);
atomic_set(&qemu_mutex_trylock_func, qsp_mutex_trylock);
+ atomic_set(&qemu_bql_mutex_lock_func, qsp_bql_mutex_lock);
atomic_set(&qemu_rec_mutex_lock_func, qsp_rec_mutex_lock);
atomic_set(&qemu_rec_mutex_trylock_func, qsp_rec_mutex_trylock);
atomic_set(&qemu_cond_wait_func, qsp_cond_wait);
@@ -462,6 +467,7 @@ void qsp_disable(void)
{
atomic_set(&qemu_mutex_lock_func, qemu_mutex_lock_impl);
atomic_set(&qemu_mutex_trylock_func, qemu_mutex_trylock_impl);
+ atomic_set(&qemu_bql_mutex_lock_func, qemu_mutex_lock_impl);
atomic_set(&qemu_rec_mutex_lock_func, qemu_rec_mutex_lock_impl);
atomic_set(&qemu_rec_mutex_trylock_func, qemu_rec_mutex_trylock_impl);
atomic_set(&qemu_cond_wait_func, qemu_cond_wait_impl);
--
1.8.3.1
- [Qemu-devel] [PULL 11/74] net: Silence 'has no peer' messages in testing mode, (continued)
- [Qemu-devel] [PULL 11/74] net: Silence 'has no peer' messages in testing mode, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 08/74] megasas: fix sglist leak, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 12/74] hw/timer/mc146818rtc: White space clean-up, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 07/74] chardev/char-fe: Fix typos, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 13/74] hw/timer/mc146818rtc: Fix introspection problem, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 15/74] tests/device-introspection: Check that the qom-tree and qtree do not change, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 14/74] tests: Skip old versioned machine types in quick testing mode, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 24/74] vl: add -enable-sync-profile, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 20/74] qsp: add qsp_reset, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 16/74] tests/device-introspect: Test with all machines, not only with "none", Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 22/74] qsp: track BQL callers explicitly,
Paolo Bonzini <=
- [Qemu-devel] [PULL 19/74] qsp: add sort_by option to qsp_report, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 31/74] lsi_scsi: add support for PPR Extended Message, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 27/74] checkpatch: allow space in more places before a bracket, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 36/74] rcu_queue: use atomic_set in QLIST_REMOVE_RCU, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 33/74] build-sys: remove glib_subprocess check, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 18/74] qsp: QEMU's Synchronization Profiler, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 48/74] qemu-guest-agent: freeze-hook to ignore dpkg files as well, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 21/74] qsp: support call site coalescing, Paolo Bonzini, 2018/08/21