From patchwork Fri Jan 12 11:31:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 124307 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1995905qgn; Fri, 12 Jan 2018 04:23:36 -0800 (PST) X-Google-Smtp-Source: ACJfBotd4+XXyhR2zXDXDHvdaKetMBJU7okdSSVCX0G27ia1R98x4ZXk1V1v7sVNF6CgaQpjGR37 X-Received: by 10.37.59.3 with SMTP id i3mr61307yba.188.1515759816755; Fri, 12 Jan 2018 04:23:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515759816; cv=none; d=google.com; s=arc-20160816; b=P52zPAA2iR2Jgw2yRgqA9JIUmMJ3w/PLPlwhSXSRG1NZ4CKhZ0ser9fP4hMHFm12uy 3FKf/tGS+BL2ZN0MiIxODHu8IZuNN/vcX1lZsUGdeINHFiCLO/aVSULTrOz6g6XBZ+xx Sda2FPKWg5290ZtH/iLvzWyOL69uig+VArgOfc06tH4Qh/3MtyYLgDdCoAbIzWdt13Da K8RxWMadzMaboB0crLxq3mofNtRDXKxcUmmRmUTTEZ8bPmemZs+fDaUEqfEVwoIo6WNb 7ET/4ye59lfshjtQbM2Qd5EI/3zeRldxOMOYkN8U2hW0cnBbF73WNt7HQlPveu3eUonZ 7QYQ== 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=iBbrg8ddpPY/CoQeckoDITlOBecmspArksZ580DcBgH+m6JXbOOqWSofwTw4hJVM+2 7XLy1XMFQOfQou23uPnX0+EwW7JhZhcFbUN2tpyG34MxWhiE/5Sv+zP1L6sADubj2of+ LuiAKsVmLGX4w1mbnSiDDIINjVAytfyDwOVvY80stcdLFES3ABnxJ5prH0EOUbyKSo/R z62y/Z0Kh2FlqPuYBjQcmGAGn7WQKKKcMfShe9Ds0tF0Q5B9iHFfSOuQxF5n4WR99hfe YoAWFLslAfIne1V88/GPv6IOuKEW6MSMpWKs6EqHn4zWJyxBiBu3dEm+QqSDf20+iVTx khcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=rhqLYj1c; 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 v4si2187895ywf.683.2018.01.12.04.23.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:23:36 -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=rhqLYj1c; 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]:36738 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZyMy-00033A-8H for patch@linaro.org; Fri, 12 Jan 2018 07:23:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZxZO-00084P-TR for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZxZN-00065g-Ll for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:22 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:43283) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eZxZN-00065E-Db for qemu-devel@nongnu.org; Fri, 12 Jan 2018 06:32:21 -0500 Received: by mail-wr0-x241.google.com with SMTP id s13so5021218wra.10 for ; Fri, 12 Jan 2018 03:32:21 -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=rhqLYj1cRJEItEnNNOVAAuT5VcjaKVYkwdJlXeL0NhYnm6/Y9KyxsE3z2+PTcwOgk2 ugdBioU3tC32RbhhvjRhn7+tQ6+bSiKMPWjn4oUmOWZJXRyYX1vlva9Irks9d67Npql+ D3m+itQIG+TNk5Bz37UwJVLfEt+RQm/nyEnyoAVGIjQnIkM5nPfVh2e26BKRq0ZsdQhD WJEVN2Ar0ASQiVLUxeirJxMgss1GsgyOlkeCeOsB/5CF2QXlkK8tHVA4x2wF3+4a6P9O teozDUTVvrLcG3SKlXNEOTmbruv50D18FKSe6D7NK6BSaaFh+A82oWNft2hL05NF2Le+ sizQ== 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=h13gTVJ/oE/4NHlIDZXaUFCXm0Cvz1PElZ1lWZzBufE3f5uHz9h5VcWAT9Ja85e06D CDZSpA5JfckM+Ye8t+hq6l82KB4iVyr+VZ0gNHKp7M4YcYbG+jxbFACMQUHrsdZxofjO q/O9KqsI82iN+u9CNoQK03lC6BWmfIV1SStcyTBOK2uRxrzGtUYtXt0+tueKyVQWZlbp 3roEkbi5WT7bG8Hz9Vb4G+yB4PfLpNj8zxKEcPlNkdPpLx0dNfAmw3HNxkzjfdeqLyCX 56PEGpAVsP68rCwWXGXFvzD6bE6pGqF9jM2C2I/wjCwIFY0OiTNkP/75r1m28VmbrDsa WHfg== X-Gm-Message-State: AKwxytcwqFXQo7fHMcRq67dCAbOpa24GG8NHfBMBQVb/TCxDIHd/TNFV 1jsy4YPr5X/C05WYDDnFO//X+SLd X-Received: by 10.223.161.198 with SMTP id v6mr969686wrv.65.1515756740032; Fri, 12 Jan 2018 03:32:20 -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 l8sm2732271wmg.46.2018.01.12.03.32.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 03:32:18 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 12 Jan 2018 12:31:15 +0100 Message-Id: <1515756676-3860-52-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1515756676-3860-1-git-send-email-pbonzini@redhat.com> References: <1515756676-3860-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:c0c::241 Subject: [Qemu-devel] [PULL 51/52] 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)"