From patchwork Tue Jan 16 14:17:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 124733 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp1044865lje; Tue, 16 Jan 2018 07:09:11 -0800 (PST) X-Google-Smtp-Source: ACJfBovvf4rrV4UaMxUHJih3InoYEUS6HfPaGaCSBfl8bIZwJiLeW03lOdMYNklM9KC6NC2M3yG3 X-Received: by 10.37.134.17 with SMTP id y17mr18667139ybk.307.1516115351675; Tue, 16 Jan 2018 07:09:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516115351; cv=none; d=google.com; s=arc-20160816; b=pbdcR0MRIayPpbaoxvN+4abriFqRildyiAW61g7WCyfcsqDZ7VuhRdBEh8FW1cMjmM eyA4f0jY6ODI2b8Vra1yC0M6OL1cjTBLmulax2mqGo3ZJYyZH7IB6EQBk5/JKYZMwZqQ SZ7VtKN5pCOR77hmHTy3HlTlN0yXz087EQLH2MDrvDl6/9QvFMRp8ko0tUxLNQ0TAFUM 5xg1o6eKWOo0txQzDNof22+0RH0M3q+xVR9SgqcN3B4E2WuoTFR1UFImlRyU3D0UDTeu 7RjZAllEflNsPCFEVds0L7Rb8DYDBgarIZSD/ASLUsLYswpkt6SRoL0s1kpkgtWfKJOb +Xjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=ji3zYJr0a36HKOJ9HE/PLOaJVocmgHMoxyHaRzyhj0g=; b=y5SEfdW7ZC7mDkfXCjU7E1AGIp1r7bwJgmh5mQjTXh4XNWg8WoZKMivbsohvRoq1ZW 8YRr58FRLGx7nUkIU+G6k+Ri1SfhRvLhDUDnJn2QxfIOPSCxCuvrkR/JaUhxS0n7C/Qw 48NmQNq9D2L2PsimqKkRaDFXMMkegS8bZS/GV6jPY5NDll3KaOPy7BOnUXDOM4TA2UQ+ +u+1WPLdeq9FZLIfQb1F2SAlafWEHBWn3HavdDnPpC1t3tPKsrPR7Ho5dMH9X+/Xn1DK qrRl64mB0FZGOBuAVpS9qUOPwdLKcyQZ8xCS/PLM7191SLbVyxInKt2uVe3zl0ut+qGu LdPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=T4hzDXSi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 64si570012ybs.248.2018.01.16.07.09.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 16 Jan 2018 07:09:11 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=T4hzDXSi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:39615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebSrO-00032W-QB for patch@linaro.org; Tue, 16 Jan 2018 10:09:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51056) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebS4k-0003ky-NU for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebS4j-0005aD-De for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:54 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:42430) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebS4j-0005Zc-4J for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:53 -0500 Received: by mail-wm0-x243.google.com with SMTP id b141so8774386wme.1 for ; Tue, 16 Jan 2018 06:18:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ji3zYJr0a36HKOJ9HE/PLOaJVocmgHMoxyHaRzyhj0g=; b=T4hzDXSilPiOMrLQL5TjgKyRhn9zDMByq/0OnhwfhhivCJvLcEKbUCoLzKkznvCgSm DP26VZEv2jEHlDVgzq1xuXIReblBalsA4stazqdpY7N5gx063IdZpN6S+bZMv1K9n+WB xWjsYWI3FZn3B61VPoyu+0aLbEwTHFWW1lqKY+FivCLfMVUOXQn236AQZ88JWAJFF4UZ RoPqSFAmunTvd1SAJ8ZA33jvD5+pVYfRSMa3uc3dnMyQZ+X+0Hu9Smvnr/AzGstvGFj0 WO4X6wUbVrjLTU7CKmb7YjX7Axzp9qpKhmWu3dYNl2P0VJ7g7v+iSEvfcTVh38SANtuW 90ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ji3zYJr0a36HKOJ9HE/PLOaJVocmgHMoxyHaRzyhj0g=; b=BpLk05BpMpD/8+LGWeAkWp4Qx+CXrb/KVd1mqAQTlSLL9uASbjT55nDeI2h1JIf4+J Ln3/Jci741vztSE+++XZpRiM3NKmNY8q2gbJf0bX1M1xld5H3rWymQYpF792bpaMIPZT 1f/aQUm2T650PEPdBz/yIwIdKL6rP16aC9mYY0zXQqCYAyUHHWIrAmc2LCkJEXNogzOZ wkq9Za+ynx1OqinJYriv7PaanchkFMYlJhxfW9S+BnTJ64juHZ/kKW9T7vkW4uLnNgPa DsOYGqEP8WRrn/nZcBq4qwCUI56jYX2JOsuX/a6fTv0pi8Pm94YPjfFK13VW98chjyso TmYA== X-Gm-Message-State: AKwxytdC1+eKe6aPI085KCJkWwQutMowpXjC1fHn22+sN/hTl582mMHU hb34+edqPllN6j50OqbbPXUqcX/M X-Received: by 10.28.143.204 with SMTP id r195mr14099806wmd.51.1516112331684; Tue, 16 Jan 2018 06:18:51 -0800 (PST) Received: from 640k.lan (dynamic-adsl-78-12-229-84.clienti.tiscali.it. [78.12.229.84]) by smtp.gmail.com with ESMTPSA id u10sm1537758wrg.6.2018.01.16.06.18.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jan 2018 06:18:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 15:17:32 +0100 Message-Id: <1516112253-14480-51-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516112253-14480-1-git-send-email-pbonzini@redhat.com> References: <1516112253-14480-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PULL 50/51] util/qemu-thread-*: add qemu_lock, locked and unlock trace events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée Signed-off-by: Alex Bennée Signed-off-by: Paolo Bonzini --- include/qemu/thread.h | 39 +++++++++++++++++++++++++++++++++++---- util/qemu-thread-posix.c | 21 ++++++++++++--------- util/qemu-thread-win32.c | 20 +++++++++++--------- util/trace-events | 7 ++++--- 4 files changed, 62 insertions(+), 25 deletions(-) -- 1.8.3.1 diff --git a/include/qemu/thread.h b/include/qemu/thread.h index 9910f49..9af4e94 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -22,9 +22,31 @@ typedef struct QemuThread QemuThread; void qemu_mutex_init(QemuMutex *mutex); void qemu_mutex_destroy(QemuMutex *mutex); -void qemu_mutex_lock(QemuMutex *mutex); -int qemu_mutex_trylock(QemuMutex *mutex); -void qemu_mutex_unlock(QemuMutex *mutex); +int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int line); +void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file, const int line); +void qemu_mutex_unlock_impl(QemuMutex *mutex, const char *file, const int line); + +#define qemu_mutex_lock(mutex) \ + qemu_mutex_lock_impl(mutex, __FILE__, __LINE__) +#define qemu_mutex_trylock(mutex) \ + qemu_mutex_trylock_impl(mutex, __FILE__, __LINE__) +#define qemu_mutex_unlock(mutex) \ + qemu_mutex_unlock_impl(mutex, __FILE__, __LINE__) + +static inline void (qemu_mutex_lock)(QemuMutex *mutex) +{ + qemu_mutex_lock(mutex); +} + +static inline int (qemu_mutex_trylock)(QemuMutex *mutex) +{ + return qemu_mutex_trylock(mutex); +} + +static inline void (qemu_mutex_unlock)(QemuMutex *mutex) +{ + qemu_mutex_unlock(mutex); +} /* Prototypes for other functions are in thread-posix.h/thread-win32.h. */ void qemu_rec_mutex_init(QemuRecMutex *mutex); @@ -39,7 +61,16 @@ void qemu_cond_destroy(QemuCond *cond); */ void qemu_cond_signal(QemuCond *cond); void qemu_cond_broadcast(QemuCond *cond); -void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex); +void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, + const char *file, const int line); + +#define qemu_cond_wait(cond, mutex) \ + qemu_cond_wait_impl(cond, mutex, __FILE__, __LINE__) + +static inline void (qemu_cond_wait)(QemuCond *cond, QemuMutex *mutex) +{ + qemu_cond_wait(cond, mutex); +} void qemu_sem_init(QemuSemaphore *sem, int init); void qemu_sem_post(QemuSemaphore *sem); diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 959a570..b789cf3 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -57,26 +57,28 @@ void qemu_mutex_destroy(QemuMutex *mutex) error_exit(err, __func__); } -void qemu_mutex_lock(QemuMutex *mutex) +void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file, const int line) { int err; assert(mutex->initialized); + trace_qemu_mutex_lock(mutex, file, line); + err = pthread_mutex_lock(&mutex->lock); if (err) error_exit(err, __func__); - trace_qemu_mutex_locked(mutex); + trace_qemu_mutex_locked(mutex, file, line); } -int qemu_mutex_trylock(QemuMutex *mutex) +int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int line) { int err; assert(mutex->initialized); err = pthread_mutex_trylock(&mutex->lock); if (err == 0) { - trace_qemu_mutex_locked(mutex); + trace_qemu_mutex_locked(mutex, file, line); return 0; } if (err != EBUSY) { @@ -85,15 +87,16 @@ int qemu_mutex_trylock(QemuMutex *mutex) return -EBUSY; } -void qemu_mutex_unlock(QemuMutex *mutex) +void qemu_mutex_unlock_impl(QemuMutex *mutex, const char *file, const int line) { int err; assert(mutex->initialized); - trace_qemu_mutex_unlocked(mutex); err = pthread_mutex_unlock(&mutex->lock); if (err) error_exit(err, __func__); + + trace_qemu_mutex_unlock(mutex, file, line); } void qemu_rec_mutex_init(QemuRecMutex *mutex) @@ -152,14 +155,14 @@ void qemu_cond_broadcast(QemuCond *cond) error_exit(err, __func__); } -void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex) +void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const char *file, const int line) { int err; assert(cond->initialized); - trace_qemu_mutex_unlocked(mutex); + trace_qemu_mutex_unlock(mutex, file, line); err = pthread_cond_wait(&cond->cond, &mutex->lock); - trace_qemu_mutex_locked(mutex); + trace_qemu_mutex_locked(mutex, file, line); if (err) error_exit(err, __func__); } diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 94f3491..ab60c0d 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -56,30 +56,32 @@ void qemu_mutex_destroy(QemuMutex *mutex) InitializeSRWLock(&mutex->lock); } -void qemu_mutex_lock(QemuMutex *mutex) +void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file, const int line) { assert(mutex->initialized); + trace_qemu_mutex_lock(mutex, file, line); + AcquireSRWLockExclusive(&mutex->lock); - trace_qemu_mutex_locked(mutex); + trace_qemu_mutex_locked(mutex, file, line); } -int qemu_mutex_trylock(QemuMutex *mutex) +int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int line) { int owned; assert(mutex->initialized); owned = TryAcquireSRWLockExclusive(&mutex->lock); if (owned) { - trace_qemu_mutex_locked(mutex); + trace_qemu_mutex_locked(mutex, file, line); return 0; } return -EBUSY; } -void qemu_mutex_unlock(QemuMutex *mutex) +void qemu_mutex_unlock_impl(QemuMutex *mutex, const char *file, const int line) { assert(mutex->initialized); - trace_qemu_mutex_unlocked(mutex); + trace_qemu_mutex_unlock(mutex, file, line); ReleaseSRWLockExclusive(&mutex->lock); } @@ -140,12 +142,12 @@ void qemu_cond_broadcast(QemuCond *cond) WakeAllConditionVariable(&cond->var); } -void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex) +void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const char *file, const int line) { assert(cond->initialized); - trace_qemu_mutex_unlocked(mutex); + trace_qemu_mutex_unlock(mutex, file, line); SleepConditionVariableSRW(&cond->var, &mutex->lock, INFINITE, 0); - trace_qemu_mutex_locked(mutex); + trace_qemu_mutex_locked(mutex, file, line); } void qemu_sem_init(QemuSemaphore *sem, int init) diff --git a/util/trace-events b/util/trace-events index 025499f..515e625 100644 --- a/util/trace-events +++ b/util/trace-events @@ -56,6 +56,7 @@ lockcnt_futex_wait(const void *lockcnt, int val) "lockcnt %p waiting on %d" lockcnt_futex_wait_resume(const void *lockcnt, int new) "lockcnt %p after wait: %d" lockcnt_futex_wake(const void *lockcnt) "lockcnt %p waking up one waiter" -# util/qemu-thread-posix.c -qemu_mutex_locked(void *lock) "locked mutex %p" -qemu_mutex_unlocked(void *lock) "unlocked mutex %p" +# util/qemu-thread.c +qemu_mutex_lock(void *mutex, const char *file, const int line) "waiting on mutex %p (%s:%d)" +qemu_mutex_locked(void *mutex, const char *file, const int line) "taken mutex %p (%s:%d)" +qemu_mutex_unlock(void *mutex, const char *file, const int line) "released mutex %p (%s:%d)"