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 12757C43219 for ; Fri, 4 Mar 2022 07:09:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238702AbiCDHJv (ORCPT ); Fri, 4 Mar 2022 02:09:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235317AbiCDHIm (ORCPT ); Fri, 4 Mar 2022 02:08:42 -0500 Received: from lgeamrelo11.lge.com (lgeamrelo12.lge.com [156.147.23.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 81E2B190B62 for ; Thu, 3 Mar 2022 23:07:08 -0800 (PST) Received: from unknown (HELO lgemrelse6q.lge.com) (156.147.1.121) by 156.147.23.52 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 08/24] dept: Apply Dept to wait_for_completion()/complete() Date: Fri, 4 Mar 2022 16:06:27 +0900 Message-Id: <1646377603-19730-9-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 wait_for_completion()/complete(). Signed-off-by: Byungchul Park --- include/linux/completion.h | 42 ++++++++++++++++++++++++++++++++++++++++-- kernel/sched/completion.c | 12 ++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/include/linux/completion.h b/include/linux/completion.h index 51d9ab0..a1ad5a8 100644 --- a/include/linux/completion.h +++ b/include/linux/completion.h @@ -26,14 +26,48 @@ struct completion { unsigned int done; struct swait_queue_head wait; + struct dept_map dmap; }; +#ifdef CONFIG_DEPT +#define dept_wfc_init(m, k, s, n) dept_map_init(m, k, s, n) +#define dept_wfc_reinit(m) dept_map_reinit(m) +#define dept_wfc_wait(m, ip) \ +do { \ + dept_ask_event(m); \ + dept_wait(m, 1UL, ip, __func__, 0); \ +} while (0) +#define dept_wfc_complete(m, ip) dept_event(m, 1UL, ip, __func__) +#define dept_wfc_enter(m, ip) dept_ecxt_enter(m, 1UL, ip, "completion_context_enter", "complete", 0) +#define dept_wfc_exit(m, ip) dept_ecxt_exit(m, ip) +#else +#define dept_wfc_init(m, k, s, n) do { (void)(n); (void)(k); } while (0) +#define dept_wfc_reinit(m) do { } while (0) +#define dept_wfc_wait(m, ip) do { } while (0) +#define dept_wfc_complete(m, ip) do { } while (0) +#define dept_wfc_enter(m, ip) do { } while (0) +#define dept_wfc_exit(m, ip) do { } while (0) +#endif + +#ifdef CONFIG_DEPT +#define WFC_DEPT_MAP_INIT(work) .dmap = { .name = #work, .skip_cnt = ATOMIC_INIT(0) } +#else +#define WFC_DEPT_MAP_INIT(work) +#endif + +#define init_completion(x) \ + do { \ + static struct dept_key __dkey; \ + __init_completion(x, &__dkey, #x); \ + } while (0) + #define init_completion_map(x, m) init_completion(x) static inline void complete_acquire(struct completion *x) {} static inline void complete_release(struct completion *x) {} #define COMPLETION_INITIALIZER(work) \ - { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait) } + { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait), \ + WFC_DEPT_MAP_INIT(work) } #define COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) \ (*({ init_completion_map(&(work), &(map)); &(work); })) @@ -81,9 +115,12 @@ static inline void complete_release(struct completion *x) {} * This inline function will initialize a dynamically created completion * structure. */ -static inline void init_completion(struct completion *x) +static inline void __init_completion(struct completion *x, + struct dept_key *dkey, + const char *name) { x->done = 0; + dept_wfc_init(&x->dmap, dkey, 0, name); init_swait_queue_head(&x->wait); } @@ -97,6 +134,7 @@ static inline void init_completion(struct completion *x) static inline void reinit_completion(struct completion *x) { x->done = 0; + dept_wfc_reinit(&x->dmap); } extern void wait_for_completion(struct completion *); diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c index a778554..6e31cc0 100644 --- a/kernel/sched/completion.c +++ b/kernel/sched/completion.c @@ -29,6 +29,7 @@ void complete(struct completion *x) { unsigned long flags; + dept_wfc_complete(&x->dmap, _RET_IP_); raw_spin_lock_irqsave(&x->wait.lock, flags); if (x->done != UINT_MAX) @@ -58,6 +59,7 @@ void complete_all(struct completion *x) { unsigned long flags; + dept_wfc_complete(&x->dmap, _RET_IP_); lockdep_assert_RT_in_threaded_ctx(); raw_spin_lock_irqsave(&x->wait.lock, flags); @@ -112,17 +114,23 @@ void complete_all(struct completion *x) } static long __sched -wait_for_common(struct completion *x, long timeout, int state) +_wait_for_common(struct completion *x, long timeout, int state) { return __wait_for_common(x, schedule_timeout, timeout, state); } static long __sched -wait_for_common_io(struct completion *x, long timeout, int state) +_wait_for_common_io(struct completion *x, long timeout, int state) { return __wait_for_common(x, io_schedule_timeout, timeout, state); } +#define wait_for_common(x, t, s) \ +({ dept_wfc_wait(&(x)->dmap, _RET_IP_); _wait_for_common(x, t, s); }) + +#define wait_for_common_io(x, t, s) \ +({ dept_wfc_wait(&(x)->dmap, _RET_IP_); _wait_for_common_io(x, t, s); }) + /** * wait_for_completion: - waits for completion of a task * @x: holds the state of this particular completion -- 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 3DC35C433FE for ; Fri, 4 Mar 2022 07:08:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1A13A10F591; Fri, 4 Mar 2022 07:07:35 +0000 (UTC) Received: from lgeamrelo11.lge.com (lgeamrelo12.lge.com [156.147.23.52]) by gabe.freedesktop.org (Postfix) with ESMTP id 7FD2410F53A 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.52 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 08/24] dept: Apply Dept to wait_for_completion()/complete() Date: Fri, 4 Mar 2022 16:06:27 +0900 Message-Id: <1646377603-19730-9-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 wait_for_completion()/complete(). Signed-off-by: Byungchul Park --- include/linux/completion.h | 42 ++++++++++++++++++++++++++++++++++++++++-- kernel/sched/completion.c | 12 ++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/include/linux/completion.h b/include/linux/completion.h index 51d9ab0..a1ad5a8 100644 --- a/include/linux/completion.h +++ b/include/linux/completion.h @@ -26,14 +26,48 @@ struct completion { unsigned int done; struct swait_queue_head wait; + struct dept_map dmap; }; +#ifdef CONFIG_DEPT +#define dept_wfc_init(m, k, s, n) dept_map_init(m, k, s, n) +#define dept_wfc_reinit(m) dept_map_reinit(m) +#define dept_wfc_wait(m, ip) \ +do { \ + dept_ask_event(m); \ + dept_wait(m, 1UL, ip, __func__, 0); \ +} while (0) +#define dept_wfc_complete(m, ip) dept_event(m, 1UL, ip, __func__) +#define dept_wfc_enter(m, ip) dept_ecxt_enter(m, 1UL, ip, "completion_context_enter", "complete", 0) +#define dept_wfc_exit(m, ip) dept_ecxt_exit(m, ip) +#else +#define dept_wfc_init(m, k, s, n) do { (void)(n); (void)(k); } while (0) +#define dept_wfc_reinit(m) do { } while (0) +#define dept_wfc_wait(m, ip) do { } while (0) +#define dept_wfc_complete(m, ip) do { } while (0) +#define dept_wfc_enter(m, ip) do { } while (0) +#define dept_wfc_exit(m, ip) do { } while (0) +#endif + +#ifdef CONFIG_DEPT +#define WFC_DEPT_MAP_INIT(work) .dmap = { .name = #work, .skip_cnt = ATOMIC_INIT(0) } +#else +#define WFC_DEPT_MAP_INIT(work) +#endif + +#define init_completion(x) \ + do { \ + static struct dept_key __dkey; \ + __init_completion(x, &__dkey, #x); \ + } while (0) + #define init_completion_map(x, m) init_completion(x) static inline void complete_acquire(struct completion *x) {} static inline void complete_release(struct completion *x) {} #define COMPLETION_INITIALIZER(work) \ - { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait) } + { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait), \ + WFC_DEPT_MAP_INIT(work) } #define COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) \ (*({ init_completion_map(&(work), &(map)); &(work); })) @@ -81,9 +115,12 @@ static inline void complete_release(struct completion *x) {} * This inline function will initialize a dynamically created completion * structure. */ -static inline void init_completion(struct completion *x) +static inline void __init_completion(struct completion *x, + struct dept_key *dkey, + const char *name) { x->done = 0; + dept_wfc_init(&x->dmap, dkey, 0, name); init_swait_queue_head(&x->wait); } @@ -97,6 +134,7 @@ static inline void init_completion(struct completion *x) static inline void reinit_completion(struct completion *x) { x->done = 0; + dept_wfc_reinit(&x->dmap); } extern void wait_for_completion(struct completion *); diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c index a778554..6e31cc0 100644 --- a/kernel/sched/completion.c +++ b/kernel/sched/completion.c @@ -29,6 +29,7 @@ void complete(struct completion *x) { unsigned long flags; + dept_wfc_complete(&x->dmap, _RET_IP_); raw_spin_lock_irqsave(&x->wait.lock, flags); if (x->done != UINT_MAX) @@ -58,6 +59,7 @@ void complete_all(struct completion *x) { unsigned long flags; + dept_wfc_complete(&x->dmap, _RET_IP_); lockdep_assert_RT_in_threaded_ctx(); raw_spin_lock_irqsave(&x->wait.lock, flags); @@ -112,17 +114,23 @@ void complete_all(struct completion *x) } static long __sched -wait_for_common(struct completion *x, long timeout, int state) +_wait_for_common(struct completion *x, long timeout, int state) { return __wait_for_common(x, schedule_timeout, timeout, state); } static long __sched -wait_for_common_io(struct completion *x, long timeout, int state) +_wait_for_common_io(struct completion *x, long timeout, int state) { return __wait_for_common(x, io_schedule_timeout, timeout, state); } +#define wait_for_common(x, t, s) \ +({ dept_wfc_wait(&(x)->dmap, _RET_IP_); _wait_for_common(x, t, s); }) + +#define wait_for_common_io(x, t, s) \ +({ dept_wfc_wait(&(x)->dmap, _RET_IP_); _wait_for_common_io(x, t, s); }) + /** * wait_for_completion: - waits for completion of a task * @x: holds the state of this particular completion -- 1.9.1