From patchwork Mon Mar 9 14:11:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 5967911 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CD51FBF440 for ; Mon, 9 Mar 2015 14:12:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D1E86202EB for ; Mon, 9 Mar 2015 14:12:13 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9E65C201C0 for ; Mon, 9 Mar 2015 14:12:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 18A936E11F; Mon, 9 Mar 2015 07:12:10 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp-outbound-2.vmware.com (smtp-outbound-2.vmware.com [208.91.2.13]) by gabe.freedesktop.org (Postfix) with ESMTP id 7AE7D6E11F for ; Mon, 9 Mar 2015 07:12:08 -0700 (PDT) Received: from sc9-mailhost3.vmware.com (sc9-mailhost3.vmware.com [10.113.161.73]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id B49C52829B; Mon, 9 Mar 2015 07:12:06 -0700 (PDT) Received: from EX13-CAS-010.vmware.com (EX13-CAS-010.vmware.com [10.113.191.62]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id AE06340362; Mon, 9 Mar 2015 07:12:06 -0700 (PDT) Received: from localhost.localdomain (10.113.160.246) by EX13-MBX-024.vmware.com (10.113.191.44) with Microsoft SMTP Server (TLS) id 15.0.913.22; Mon, 9 Mar 2015 07:12:05 -0700 From: Thomas Hellstrom To: , , Subject: [PATCH] drm/ttm: Add lockdep annotation to the TTM lock Date: Mon, 9 Mar 2015 07:11:39 -0700 Message-ID: <1425910299-3429-1-git-send-email-thellstrom@vmware.com> X-Mailer: git-send-email 2.1.0 MIME-Version: 1.0 X-Originating-IP: [10.113.160.246] X-ClientProxiedBy: EX13-CAS-013.vmware.com (10.113.191.65) To EX13-MBX-024.vmware.com (10.113.191.44) Cc: Thomas Hellstrom X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adds, to the extent possible, lockdep annotation to the TTM lock. Also removes some unused TTM lock code. Signed-off-by: Thomas Hellstrom Acked-by: Sinclair Yeh --- drivers/gpu/drm/ttm/ttm_lock.c | 73 ++++++++++++++++-------------------------- include/drm/ttm/ttm_lock.h | 13 +++++++- 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_lock.c b/drivers/gpu/drm/ttm/ttm_lock.c index 6a95454..0e662af 100644 --- a/drivers/gpu/drm/ttm/ttm_lock.c +++ b/drivers/gpu/drm/ttm/ttm_lock.c @@ -42,8 +42,12 @@ #define TTM_VT_LOCK (1 << 3) #define TTM_SUSPEND_LOCK (1 << 4) -void ttm_lock_init(struct ttm_lock *lock) +void __ttm_lock_init(struct ttm_lock *lock, const char *name, + struct lock_class_key *key) { +#ifdef CONFIG_DEBUG_LOCK_ALLOC + lockdep_init_map(&lock->dep_map, name, key, 0); +#endif spin_lock_init(&lock->lock); init_waitqueue_head(&lock->queue); lock->rw = 0; @@ -51,10 +55,11 @@ void ttm_lock_init(struct ttm_lock *lock) lock->kill_takers = false; lock->signal = SIGKILL; } -EXPORT_SYMBOL(ttm_lock_init); +EXPORT_SYMBOL(__ttm_lock_init); void ttm_read_unlock(struct ttm_lock *lock) { + lock_release(&lock->dep_map, 1, _RET_IP_); spin_lock(&lock->lock); if (--lock->rw == 0) wake_up_all(&lock->queue); @@ -84,60 +89,25 @@ int ttm_read_lock(struct ttm_lock *lock, bool interruptible) { int ret = 0; + lock_acquire(&lock->dep_map, 0, 0, 1, 1, NULL, _RET_IP_); if (interruptible) ret = wait_event_interruptible(lock->queue, __ttm_read_lock(lock)); else wait_event(lock->queue, __ttm_read_lock(lock)); - return ret; -} -EXPORT_SYMBOL(ttm_read_lock); - -static bool __ttm_read_trylock(struct ttm_lock *lock, bool *locked) -{ - bool block = true; - - *locked = false; - - spin_lock(&lock->lock); - if (unlikely(lock->kill_takers)) { - send_sig(lock->signal, current, 0); - spin_unlock(&lock->lock); - return false; - } - if (lock->rw >= 0 && lock->flags == 0) { - ++lock->rw; - block = false; - *locked = true; - } else if (lock->flags == 0) { - block = false; - } - spin_unlock(&lock->lock); - - return !block; -} -int ttm_read_trylock(struct ttm_lock *lock, bool interruptible) -{ - int ret = 0; - bool locked; - - if (interruptible) - ret = wait_event_interruptible - (lock->queue, __ttm_read_trylock(lock, &locked)); + if (ret) + lock_release(&lock->dep_map, 0, _RET_IP_); else - wait_event(lock->queue, __ttm_read_trylock(lock, &locked)); - - if (unlikely(ret != 0)) { - BUG_ON(locked); - return ret; - } + lock_acquired(&lock->dep_map, _RET_IP_); - return (locked) ? 0 : -EBUSY; + return ret; } +EXPORT_SYMBOL(ttm_read_lock); void ttm_write_unlock(struct ttm_lock *lock) { + lock_release(&lock->dep_map, 1, _RET_IP_); spin_lock(&lock->lock); lock->rw = 0; wake_up_all(&lock->queue); @@ -170,6 +140,8 @@ int ttm_write_lock(struct ttm_lock *lock, bool interruptible) { int ret = 0; + lock_acquire(&lock->dep_map, 0, 0, 0, 1, NULL, _RET_IP_); + if (interruptible) { ret = wait_event_interruptible(lock->queue, __ttm_write_lock(lock)); @@ -180,7 +152,12 @@ int ttm_write_lock(struct ttm_lock *lock, bool interruptible) spin_unlock(&lock->lock); } } else - wait_event(lock->queue, __ttm_read_lock(lock)); + wait_event(lock->queue, __ttm_write_lock(lock)); + + if (ret) + lock_release(&lock->dep_map, 0, _RET_IP_); + else + lock_acquired(&lock->dep_map, _RET_IP_); return ret; } @@ -233,6 +210,8 @@ int ttm_vt_lock(struct ttm_lock *lock, { int ret = 0; + might_lock(lock); + if (interruptible) { ret = wait_event_interruptible(lock->queue, __ttm_vt_lock(lock)); @@ -241,6 +220,7 @@ int ttm_vt_lock(struct ttm_lock *lock, lock->flags &= ~TTM_VT_LOCK_PENDING; wake_up_all(&lock->queue); spin_unlock(&lock->lock); + lock_release(&lock->dep_map, 0, _RET_IP_); return ret; } } else @@ -265,6 +245,7 @@ EXPORT_SYMBOL(ttm_vt_lock); int ttm_vt_unlock(struct ttm_lock *lock) { + return ttm_ref_object_base_unref(lock->vt_holder, lock->base.hash.key, TTM_REF_USAGE); } @@ -297,6 +278,8 @@ static bool __ttm_suspend_lock(struct ttm_lock *lock) void ttm_suspend_lock(struct ttm_lock *lock) { + might_lock(lock); + wait_event(lock->queue, __ttm_suspend_lock(lock)); } EXPORT_SYMBOL(ttm_suspend_lock); diff --git a/include/drm/ttm/ttm_lock.h b/include/drm/ttm/ttm_lock.h index 2902beb..fb8fda2 100644 --- a/include/drm/ttm/ttm_lock.h +++ b/include/drm/ttm/ttm_lock.h @@ -75,6 +75,9 @@ struct ttm_lock { bool kill_takers; int signal; struct ttm_object_file *vt_holder; +#ifdef CONFIG_DEBUG_LOCK_ALLOC + struct lockdep_map dep_map; +#endif }; @@ -84,7 +87,8 @@ struct ttm_lock { * @lock: Pointer to a struct ttm_lock * Initializes the lock. */ -extern void ttm_lock_init(struct ttm_lock *lock); +extern void __ttm_lock_init(struct ttm_lock *lock, const char *name, + struct lock_class_key *key); /** * ttm_read_unlock @@ -244,4 +248,11 @@ static inline void ttm_lock_set_kill(struct ttm_lock *lock, bool val, lock->signal = signal; } +#define ttm_lock_init(lock) \ +do { \ + static struct lock_class_key __key; \ + \ + __ttm_lock_init((lock), #lock, &__key); \ +} while (0) + #endif