From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EEBBC433FE for ; Fri, 4 Mar 2022 07:08:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238156AbiCDHIu (ORCPT ); Fri, 4 Mar 2022 02:08:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238677AbiCDHIR (ORCPT ); Fri, 4 Mar 2022 02:08:17 -0500 Received: from lgeamrelo11.lge.com (lgeamrelo11.lge.com [156.147.23.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 66285190B58 for ; Thu, 3 Mar 2022 23:07:07 -0800 (PST) Received: from unknown (HELO lgemrelse6q.lge.com) (156.147.1.121) by 156.147.23.51 with ESMTP; 4 Mar 2022 16:07:07 +0900 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: byungchul.park@lge.com Received: from unknown (HELO localhost.localdomain) (10.177.244.38) by 156.147.1.121 with ESMTP; 4 Mar 2022 16:07:07 +0900 X-Original-SENDERIP: 10.177.244.38 X-Original-MAILFROM: byungchul.park@lge.com From: Byungchul Park To: torvalds@linux-foundation.org Cc: damien.lemoal@opensource.wdc.com, linux-ide@vger.kernel.org, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, mingo@redhat.com, linux-kernel@vger.kernel.org, peterz@infradead.org, will@kernel.org, tglx@linutronix.de, rostedt@goodmis.org, joel@joelfernandes.org, sashal@kernel.org, daniel.vetter@ffwll.ch, chris@chris-wilson.co.uk, duyuyang@gmail.com, johannes.berg@intel.com, tj@kernel.org, tytso@mit.edu, willy@infradead.org, david@fromorbit.com, amir73il@gmail.com, bfields@fieldses.org, gregkh@linuxfoundation.org, kernel-team@lge.com, linux-mm@kvack.org, akpm@linux-foundation.org, mhocko@kernel.org, minchan@kernel.org, hannes@cmpxchg.org, vdavydov.dev@gmail.com, sj@kernel.org, jglisse@redhat.com, dennis@kernel.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, vbabka@suse.cz, ngupta@vflare.org, linux-block@vger.kernel.org, paolo.valente@linaro.org, josef@toxicpanda.com, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, jack@suse.com, jlayton@kernel.org, dan.j.williams@intel.com, hch@infradead.org, djwong@kernel.org, dri-devel@lists.freedesktop.org, airlied@linux.ie, rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, hamohammed.sa@gmail.com Subject: [PATCH v4 07/24] dept: Apply Dept to rwlock Date: Fri, 4 Mar 2022 16:06:26 +0900 Message-Id: <1646377603-19730-8-git-send-email-byungchul.park@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1646377603-19730-1-git-send-email-byungchul.park@lge.com> References: <1646377603-19730-1-git-send-email-byungchul.park@lge.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Makes Dept able to track dependencies by rwlock. Signed-off-by: Byungchul Park --- include/linux/lockdep.h | 25 ++++++++++++++++---- include/linux/rwlock.h | 52 ++++++++++++++++++++++++++++++++++++++++++ include/linux/rwlock_api_smp.h | 8 +++---- include/linux/rwlock_types.h | 7 ++++++ 4 files changed, 83 insertions(+), 9 deletions(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 6653a4f..b93a707 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -600,16 +600,31 @@ static inline void print_irqtrace_events(struct task_struct *curr) dept_spin_unlock(&(l)->dmap, i); \ } while (0) -#define rwlock_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) +#define rwlock_acquire(l, s, t, i) \ +do { \ + lock_acquire_exclusive(l, s, t, NULL, i); \ + dept_rwlock_wlock(&(l)->dmap, s, t, NULL, "write_unlock", i); \ +} while (0) #define rwlock_acquire_read(l, s, t, i) \ do { \ - if (read_lock_is_recursive()) \ + if (read_lock_is_recursive()) { \ lock_acquire_shared_recursive(l, s, t, NULL, i); \ - else \ + dept_rwlock_rlock(&(l)->dmap, s, t, NULL, "read_unlock", i, 0);\ + } else { \ lock_acquire_shared(l, s, t, NULL, i); \ + dept_rwlock_rlock(&(l)->dmap, s, t, NULL, "read_unlock", i, 1);\ + } \ +} while (0) +#define rwlock_release(l, i) \ +do { \ + lock_release(l, i); \ + dept_rwlock_wunlock(&(l)->dmap, i); \ +} while (0) +#define rwlock_release_read(l, i) \ +do { \ + lock_release(l, i); \ + dept_rwlock_runlock(&(l)->dmap, i); \ } while (0) - -#define rwlock_release(l, i) lock_release(l, i) #define seqcount_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) #define seqcount_acquire_read(l, s, t, i) lock_acquire_shared_recursive(l, s, t, NULL, i) diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h index 8f416c5..768ad9e 100644 --- a/include/linux/rwlock.h +++ b/include/linux/rwlock.h @@ -28,6 +28,58 @@ do { *(lock) = __RW_LOCK_UNLOCKED(lock); } while (0) #endif +#ifdef CONFIG_DEPT +#define DEPT_EVT_RWLOCK_R 1UL +#define DEPT_EVT_RWLOCK_W (1UL << 1) +#define DEPT_EVT_RWLOCK_RW (DEPT_EVT_RWLOCK_R | DEPT_EVT_RWLOCK_W) + +#define dept_rwlock_wlock(m, ne, t, n, e_fn, ip) \ +do { \ + if (t) { \ + dept_ecxt_enter(m, DEPT_EVT_RWLOCK_W, ip, __func__, e_fn, ne);\ + dept_ask_event(m); \ + } else if (n) { \ + dept_skip(m); \ + } else { \ + dept_wait(m, DEPT_EVT_RWLOCK_RW, ip, __func__, ne); \ + dept_ecxt_enter(m, DEPT_EVT_RWLOCK_W, ip, __func__, e_fn, ne);\ + dept_ask_event(m); \ + } \ +} while (0) +#define dept_rwlock_rlock(m, ne, t, n, e_fn, ip, q) \ +do { \ + if (t) { \ + dept_ecxt_enter(m, DEPT_EVT_RWLOCK_R, ip, __func__, e_fn, ne);\ + dept_ask_event(m); \ + } else if (n) { \ + dept_skip(m); \ + } else { \ + dept_wait(m, (q) ? DEPT_EVT_RWLOCK_RW : DEPT_EVT_RWLOCK_W, ip, __func__, ne);\ + dept_ecxt_enter(m, DEPT_EVT_RWLOCK_R, ip, __func__, e_fn, ne);\ + dept_ask_event(m); \ + } \ +} while (0) +#define dept_rwlock_wunlock(m, ip) \ +do { \ + if (!dept_unskip_if_skipped(m)) { \ + dept_event(m, DEPT_EVT_RWLOCK_W, ip, __func__); \ + dept_ecxt_exit(m, ip); \ + } \ +} while (0) +#define dept_rwlock_runlock(m, ip) \ +do { \ + if (!dept_unskip_if_skipped(m)) { \ + dept_event(m, DEPT_EVT_RWLOCK_R, ip, __func__); \ + dept_ecxt_exit(m, ip); \ + } \ +} while (0) +#else +#define dept_rwlock_wlock(m, ne, t, n, e_fn, ip) do { } while (0) +#define dept_rwlock_rlock(m, ne, t, n, e_fn, ip, q) do { } while (0) +#define dept_rwlock_wunlock(m, ip) do { } while (0) +#define dept_rwlock_runlock(m, ip) do { } while (0) +#endif + #ifdef CONFIG_DEBUG_SPINLOCK extern void do_raw_read_lock(rwlock_t *lock) __acquires(lock); extern int do_raw_read_trylock(rwlock_t *lock); diff --git a/include/linux/rwlock_api_smp.h b/include/linux/rwlock_api_smp.h index dceb0a5..a222cf1 100644 --- a/include/linux/rwlock_api_smp.h +++ b/include/linux/rwlock_api_smp.h @@ -228,7 +228,7 @@ static inline void __raw_write_unlock(rwlock_t *lock) static inline void __raw_read_unlock(rwlock_t *lock) { - rwlock_release(&lock->dep_map, _RET_IP_); + rwlock_release_read(&lock->dep_map, _RET_IP_); do_raw_read_unlock(lock); preempt_enable(); } @@ -236,7 +236,7 @@ static inline void __raw_read_unlock(rwlock_t *lock) static inline void __raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags) { - rwlock_release(&lock->dep_map, _RET_IP_); + rwlock_release_read(&lock->dep_map, _RET_IP_); do_raw_read_unlock(lock); local_irq_restore(flags); preempt_enable(); @@ -244,7 +244,7 @@ static inline void __raw_read_unlock(rwlock_t *lock) static inline void __raw_read_unlock_irq(rwlock_t *lock) { - rwlock_release(&lock->dep_map, _RET_IP_); + rwlock_release_read(&lock->dep_map, _RET_IP_); do_raw_read_unlock(lock); local_irq_enable(); preempt_enable(); @@ -252,7 +252,7 @@ static inline void __raw_read_unlock_irq(rwlock_t *lock) static inline void __raw_read_unlock_bh(rwlock_t *lock) { - rwlock_release(&lock->dep_map, _RET_IP_); + rwlock_release_read(&lock->dep_map, _RET_IP_); do_raw_read_unlock(lock); __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); } diff --git a/include/linux/rwlock_types.h b/include/linux/rwlock_types.h index 1948442..74804b7 100644 --- a/include/linux/rwlock_types.h +++ b/include/linux/rwlock_types.h @@ -5,11 +5,18 @@ # error "Do not include directly, include spinlock_types.h" #endif +#ifdef CONFIG_DEPT +# define RW_DMAP_INIT(lockname) .dmap = { .name = #lockname, .skip_cnt = ATOMIC_INIT(0) }, +#else +# define RW_DMAP_INIT(lockname) +#endif + #ifdef CONFIG_DEBUG_LOCK_ALLOC # define RW_DEP_MAP_INIT(lockname) \ .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_CONFIG, \ + RW_DMAP_INIT(lockname) \ } #else # define RW_DEP_MAP_INIT(lockname) -- 1.9.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6FDD2C43217 for ; Fri, 4 Mar 2022 07:07:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8D6E510F53A; Fri, 4 Mar 2022 07:07:09 +0000 (UTC) Received: from lgeamrelo11.lge.com (lgeamrelo11.lge.com [156.147.23.51]) by gabe.freedesktop.org (Postfix) with ESMTP id 6B12B10F503 for ; Fri, 4 Mar 2022 07:07:07 +0000 (UTC) Received: from unknown (HELO lgemrelse6q.lge.com) (156.147.1.121) by 156.147.23.51 with ESMTP; 4 Mar 2022 16:07:07 +0900 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: byungchul.park@lge.com Received: from unknown (HELO localhost.localdomain) (10.177.244.38) by 156.147.1.121 with ESMTP; 4 Mar 2022 16:07:07 +0900 X-Original-SENDERIP: 10.177.244.38 X-Original-MAILFROM: byungchul.park@lge.com From: Byungchul Park To: torvalds@linux-foundation.org Subject: [PATCH v4 07/24] dept: Apply Dept to rwlock Date: Fri, 4 Mar 2022 16:06:26 +0900 Message-Id: <1646377603-19730-8-git-send-email-byungchul.park@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1646377603-19730-1-git-send-email-byungchul.park@lge.com> References: <1646377603-19730-1-git-send-email-byungchul.park@lge.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hamohammed.sa@gmail.com, jack@suse.cz, peterz@infradead.org, daniel.vetter@ffwll.ch, amir73il@gmail.com, david@fromorbit.com, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk, bfields@fieldses.org, linux-ide@vger.kernel.org, adilger.kernel@dilger.ca, joel@joelfernandes.org, cl@linux.com, will@kernel.org, duyuyang@gmail.com, sashal@kernel.org, paolo.valente@linaro.org, damien.lemoal@opensource.wdc.com, willy@infradead.org, hch@infradead.org, airlied@linux.ie, mingo@redhat.com, djwong@kernel.org, vdavydov.dev@gmail.com, rientjes@google.com, dennis@kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, ngupta@vflare.org, johannes.berg@intel.com, jack@suse.com, dan.j.williams@intel.com, josef@toxicpanda.com, rostedt@goodmis.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, jglisse@redhat.com, viro@zeniv.linux.org.uk, tglx@linutronix.de, mhocko@kernel.org, vbabka@suse.cz, melissa.srw@gmail.com, sj@kernel.org, tytso@mit.edu, rodrigosiqueiramelo@gmail.com, kernel-team@lge.com, gregkh@linuxfoundation.org, jlayton@kernel.org, linux-kernel@vger.kernel.org, penberg@kernel.org, minchan@kernel.org, hannes@cmpxchg.org, tj@kernel.org, akpm@linux-foundation.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Makes Dept able to track dependencies by rwlock. Signed-off-by: Byungchul Park --- include/linux/lockdep.h | 25 ++++++++++++++++---- include/linux/rwlock.h | 52 ++++++++++++++++++++++++++++++++++++++++++ include/linux/rwlock_api_smp.h | 8 +++---- include/linux/rwlock_types.h | 7 ++++++ 4 files changed, 83 insertions(+), 9 deletions(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 6653a4f..b93a707 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -600,16 +600,31 @@ static inline void print_irqtrace_events(struct task_struct *curr) dept_spin_unlock(&(l)->dmap, i); \ } while (0) -#define rwlock_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) +#define rwlock_acquire(l, s, t, i) \ +do { \ + lock_acquire_exclusive(l, s, t, NULL, i); \ + dept_rwlock_wlock(&(l)->dmap, s, t, NULL, "write_unlock", i); \ +} while (0) #define rwlock_acquire_read(l, s, t, i) \ do { \ - if (read_lock_is_recursive()) \ + if (read_lock_is_recursive()) { \ lock_acquire_shared_recursive(l, s, t, NULL, i); \ - else \ + dept_rwlock_rlock(&(l)->dmap, s, t, NULL, "read_unlock", i, 0);\ + } else { \ lock_acquire_shared(l, s, t, NULL, i); \ + dept_rwlock_rlock(&(l)->dmap, s, t, NULL, "read_unlock", i, 1);\ + } \ +} while (0) +#define rwlock_release(l, i) \ +do { \ + lock_release(l, i); \ + dept_rwlock_wunlock(&(l)->dmap, i); \ +} while (0) +#define rwlock_release_read(l, i) \ +do { \ + lock_release(l, i); \ + dept_rwlock_runlock(&(l)->dmap, i); \ } while (0) - -#define rwlock_release(l, i) lock_release(l, i) #define seqcount_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) #define seqcount_acquire_read(l, s, t, i) lock_acquire_shared_recursive(l, s, t, NULL, i) diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h index 8f416c5..768ad9e 100644 --- a/include/linux/rwlock.h +++ b/include/linux/rwlock.h @@ -28,6 +28,58 @@ do { *(lock) = __RW_LOCK_UNLOCKED(lock); } while (0) #endif +#ifdef CONFIG_DEPT +#define DEPT_EVT_RWLOCK_R 1UL +#define DEPT_EVT_RWLOCK_W (1UL << 1) +#define DEPT_EVT_RWLOCK_RW (DEPT_EVT_RWLOCK_R | DEPT_EVT_RWLOCK_W) + +#define dept_rwlock_wlock(m, ne, t, n, e_fn, ip) \ +do { \ + if (t) { \ + dept_ecxt_enter(m, DEPT_EVT_RWLOCK_W, ip, __func__, e_fn, ne);\ + dept_ask_event(m); \ + } else if (n) { \ + dept_skip(m); \ + } else { \ + dept_wait(m, DEPT_EVT_RWLOCK_RW, ip, __func__, ne); \ + dept_ecxt_enter(m, DEPT_EVT_RWLOCK_W, ip, __func__, e_fn, ne);\ + dept_ask_event(m); \ + } \ +} while (0) +#define dept_rwlock_rlock(m, ne, t, n, e_fn, ip, q) \ +do { \ + if (t) { \ + dept_ecxt_enter(m, DEPT_EVT_RWLOCK_R, ip, __func__, e_fn, ne);\ + dept_ask_event(m); \ + } else if (n) { \ + dept_skip(m); \ + } else { \ + dept_wait(m, (q) ? DEPT_EVT_RWLOCK_RW : DEPT_EVT_RWLOCK_W, ip, __func__, ne);\ + dept_ecxt_enter(m, DEPT_EVT_RWLOCK_R, ip, __func__, e_fn, ne);\ + dept_ask_event(m); \ + } \ +} while (0) +#define dept_rwlock_wunlock(m, ip) \ +do { \ + if (!dept_unskip_if_skipped(m)) { \ + dept_event(m, DEPT_EVT_RWLOCK_W, ip, __func__); \ + dept_ecxt_exit(m, ip); \ + } \ +} while (0) +#define dept_rwlock_runlock(m, ip) \ +do { \ + if (!dept_unskip_if_skipped(m)) { \ + dept_event(m, DEPT_EVT_RWLOCK_R, ip, __func__); \ + dept_ecxt_exit(m, ip); \ + } \ +} while (0) +#else +#define dept_rwlock_wlock(m, ne, t, n, e_fn, ip) do { } while (0) +#define dept_rwlock_rlock(m, ne, t, n, e_fn, ip, q) do { } while (0) +#define dept_rwlock_wunlock(m, ip) do { } while (0) +#define dept_rwlock_runlock(m, ip) do { } while (0) +#endif + #ifdef CONFIG_DEBUG_SPINLOCK extern void do_raw_read_lock(rwlock_t *lock) __acquires(lock); extern int do_raw_read_trylock(rwlock_t *lock); diff --git a/include/linux/rwlock_api_smp.h b/include/linux/rwlock_api_smp.h index dceb0a5..a222cf1 100644 --- a/include/linux/rwlock_api_smp.h +++ b/include/linux/rwlock_api_smp.h @@ -228,7 +228,7 @@ static inline void __raw_write_unlock(rwlock_t *lock) static inline void __raw_read_unlock(rwlock_t *lock) { - rwlock_release(&lock->dep_map, _RET_IP_); + rwlock_release_read(&lock->dep_map, _RET_IP_); do_raw_read_unlock(lock); preempt_enable(); } @@ -236,7 +236,7 @@ static inline void __raw_read_unlock(rwlock_t *lock) static inline void __raw_read_unlock_irqrestore(rwlock_t *lock, unsigned long flags) { - rwlock_release(&lock->dep_map, _RET_IP_); + rwlock_release_read(&lock->dep_map, _RET_IP_); do_raw_read_unlock(lock); local_irq_restore(flags); preempt_enable(); @@ -244,7 +244,7 @@ static inline void __raw_read_unlock(rwlock_t *lock) static inline void __raw_read_unlock_irq(rwlock_t *lock) { - rwlock_release(&lock->dep_map, _RET_IP_); + rwlock_release_read(&lock->dep_map, _RET_IP_); do_raw_read_unlock(lock); local_irq_enable(); preempt_enable(); @@ -252,7 +252,7 @@ static inline void __raw_read_unlock_irq(rwlock_t *lock) static inline void __raw_read_unlock_bh(rwlock_t *lock) { - rwlock_release(&lock->dep_map, _RET_IP_); + rwlock_release_read(&lock->dep_map, _RET_IP_); do_raw_read_unlock(lock); __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); } diff --git a/include/linux/rwlock_types.h b/include/linux/rwlock_types.h index 1948442..74804b7 100644 --- a/include/linux/rwlock_types.h +++ b/include/linux/rwlock_types.h @@ -5,11 +5,18 @@ # error "Do not include directly, include spinlock_types.h" #endif +#ifdef CONFIG_DEPT +# define RW_DMAP_INIT(lockname) .dmap = { .name = #lockname, .skip_cnt = ATOMIC_INIT(0) }, +#else +# define RW_DMAP_INIT(lockname) +#endif + #ifdef CONFIG_DEBUG_LOCK_ALLOC # define RW_DEP_MAP_INIT(lockname) \ .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_CONFIG, \ + RW_DMAP_INIT(lockname) \ } #else # define RW_DEP_MAP_INIT(lockname) -- 1.9.1