From patchwork Tue Aug 30 21:49:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 12959923 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 010F5ECAAA1 for ; Tue, 30 Aug 2022 21:50:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D9168000D; Tue, 30 Aug 2022 17:50:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AFF58D0001; Tue, 30 Aug 2022 17:50:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 702D78000D; Tue, 30 Aug 2022 17:50:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5FF538D0001 for ; Tue, 30 Aug 2022 17:50:28 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 41F8BA0C4C for ; Tue, 30 Aug 2022 21:50:28 +0000 (UTC) X-FDA: 79857603336.18.B5A61EE Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf21.hostedemail.com (Postfix) with ESMTP id 05D991C0040 for ; Tue, 30 Aug 2022 21:50:27 +0000 (UTC) Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-33daeaa6b8eso187674177b3.7 for ; Tue, 30 Aug 2022 14:50:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc; bh=PJDqdE16VQFkhBtAZQdE7ryguEFDkMx7mMptHwdJxIQ=; b=Ij75nFrUrPvJu2bumKHw5qB/wQ6gVxiA7JiR459fjyWwf8bAM7esU+z26b2Gs2wm+2 GJco7Z59pIbk7lAYzIUjBLlbgij5WieJsWdNVz1juJkVh+sa9UWATRgrEBqBGRWkiIgS e9fE2xkYV7tYVniZBisXLNcLv1T2Qe2o0c8hnbKmgjEZ4CuxPiv3aHRBgJXL1TW2FAU/ xTP0HeMc1J5XCTMzbl6MriSnvFIhWbWVUtAJ/9V96DnOp2vk9Hc7k6iFLgNru+svATI5 qjP0FOpFl9sx7TmiI9c+PBZgc2FqjExNp+v4DIbowFGQu7f8+ZLj1VsmDoNwIg4tHpwc B9Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc; bh=PJDqdE16VQFkhBtAZQdE7ryguEFDkMx7mMptHwdJxIQ=; b=SA+0ztiX9WgRFUxshSDtJORV0oFd8WYqa/H5Ge1ZAGWW6tW2B7wp0OxCFD1tHUQhG5 /EpKNdnM5OUg5kXS38zgjI5uV6Bem6NDAjlkHhLpSqa22QhKRJjBhuP/kgOD4GeHRvZB UAjt2c1t+spN2yK1W1UjBZXwfkaVQblCSi9RPCbPNEQj1eUtWWcxKpnqUkIkv03qXRdW LiAa7ciIO+HKjVEmO8gPNTy29O6T/vQOVzbDmgf6Q3f+wjEEHz0ExVIobSH53W0APHf6 GFqQErxx4TIc1QsXkyp3EI472cH+Cy4uO6tLLbow9VX7F4c+/NbJ2J9MSaCs7AqqlWvr EPww== X-Gm-Message-State: ACgBeo39e0r9jAz8RmBniloSxkTuubN4wCM94Ss71br8lYtYdcQ8y05w e4ZQ0WmrZrb/hDTQxaBbcbXUqlHSYTo= X-Google-Smtp-Source: AA6agR6avTM18XP2y4CdHSCV3FE6n/efM5TdzJAiOApCx+OJvVOl1HBVpl97MaszhlrgGlpdRen0jumUZ8U= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:a005:55b3:6c26:b3e4]) (user=surenb job=sendgmr) by 2002:a81:54c4:0:b0:329:d0e1:cfcf with SMTP id i187-20020a8154c4000000b00329d0e1cfcfmr15741208ywb.451.1661896227243; Tue, 30 Aug 2022 14:50:27 -0700 (PDT) Date: Tue, 30 Aug 2022 14:49:13 -0700 In-Reply-To: <20220830214919.53220-1-surenb@google.com> Mime-Version: 1.0 References: <20220830214919.53220-1-surenb@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220830214919.53220-25-surenb@google.com> Subject: [RFC PATCH 24/30] wait: Clean up waitqueue_entry initialization From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, ldufour@linux.ibm.com, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, changbin.du@intel.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, arnd@arndb.de, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, surenb@google.com, kernel-team@android.com, linux-mm@kvack.org, iommu@lists.linux.dev, kasan-dev@googlegroups.com, io-uring@vger.kernel.org, linux-arch@vger.kernel.org, xen-devel@lists.xenproject.org, linux-bcache@vger.kernel.org, linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org, Ingo Molnar ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661896228; a=rsa-sha256; cv=none; b=7YyiHP6uUQXe5yYNvWg2YN8QS9clMm4iUNULBm/lzaijO5Ti05gqXGPTIPmChQqIluAGnm cZQ5wmtmzbsoElRzTd1S8hvT/GB7qH23y9/2ud0Zbtu4Oksf1LDKYSa19+vYR3vFPuEJci MuzQiuaNM/4QIV8m1anYsMiaWx/KCT0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Ij75nFrU; spf=pass (imf21.hostedemail.com: domain of 3I4YOYwYKCIg463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3I4YOYwYKCIg463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661896228; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PJDqdE16VQFkhBtAZQdE7ryguEFDkMx7mMptHwdJxIQ=; b=2/MbwP4P0mdNiFgN95D1UtIZIJc6B2/dx+qk5GtSM1HwxypT8XNlucJF+Ywf6SbY8Jl4rg 7AXjxouP70yu8L1sESbMnP5jOUUo2RpAnKYN9j8ZbqZqo0q79epUCAPxwUHYbva3dSeY1A y0xT3N1DOO8ireBVAR5lk2VT2JNUTr0= X-Rspam-User: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Ij75nFrU; spf=pass (imf21.hostedemail.com: domain of 3I4YOYwYKCIg463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3I4YOYwYKCIg463qzns00sxq.o0yxuz69-yyw7mow.03s@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: q8mohyo79bo6858htfpq5ijzeyxj9w3j X-Rspamd-Queue-Id: 05D991C0040 X-Rspamd-Server: rspam10 X-HE-Tag: 1661896227-1357 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Kent Overstreet Cleanup for code tagging latency tracking: Add an initializer, WAIT_FUNC_INITIALIZER(), to be used by initializers for structs that include wait_queue_entries. Also, change init_wait(), init_wait_entry etc. to be a wrapper around the new __init_waitqueue_entry(); more de-duplication prep work. Signed-off-by: Kent Overstreet Cc: Ingo Molnar Cc: Peter Zijlstra --- include/linux/sbitmap.h | 6 +---- include/linux/wait.h | 52 +++++++++++++++++++--------------------- include/linux/wait_bit.h | 7 +----- kernel/sched/wait.c | 9 ------- 4 files changed, 27 insertions(+), 47 deletions(-) diff --git a/include/linux/sbitmap.h b/include/linux/sbitmap.h index 8f5a86e210b9..f696c29d9ab3 100644 --- a/include/linux/sbitmap.h +++ b/include/linux/sbitmap.h @@ -596,11 +596,7 @@ struct sbq_wait { #define DEFINE_SBQ_WAIT(name) \ struct sbq_wait name = { \ .sbq = NULL, \ - .wait = { \ - .private = current, \ - .func = autoremove_wake_function, \ - .entry = LIST_HEAD_INIT((name).wait.entry), \ - } \ + .wait = WAIT_FUNC_INITIALIZER((name).wait, autoremove_wake_function),\ } /* diff --git a/include/linux/wait.h b/include/linux/wait.h index 58cfbf81447c..91ced6a118bc 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -79,21 +79,38 @@ extern void __init_waitqueue_head(struct wait_queue_head *wq_head, const char *n # define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) DECLARE_WAIT_QUEUE_HEAD(name) #endif -static inline void init_waitqueue_entry(struct wait_queue_entry *wq_entry, struct task_struct *p) -{ - wq_entry->flags = 0; - wq_entry->private = p; - wq_entry->func = default_wake_function; +#define WAIT_FUNC_INITIALIZER(name, function) { \ + .private = current, \ + .func = function, \ + .entry = LIST_HEAD_INIT((name).entry), \ } +#define DEFINE_WAIT_FUNC(name, function) \ + struct wait_queue_entry name = WAIT_FUNC_INITIALIZER(name, function) + +#define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function) + static inline void -init_waitqueue_func_entry(struct wait_queue_entry *wq_entry, wait_queue_func_t func) +__init_waitqueue_entry(struct wait_queue_entry *wq_entry, unsigned int flags, + void *private, wait_queue_func_t func) { - wq_entry->flags = 0; - wq_entry->private = NULL; + wq_entry->flags = flags; + wq_entry->private = private; wq_entry->func = func; + INIT_LIST_HEAD(&wq_entry->entry); } +#define init_waitqueue_func_entry(_wq_entry, _func) \ + __init_waitqueue_entry(_wq_entry, 0, NULL, _func) + +#define init_waitqueue_entry(_wq_entry, _task) \ + __init_waitqueue_entry(_wq_entry, 0, _task, default_wake_function) + +#define init_wait_entry(_wq_entry, _flags) \ + __init_waitqueue_entry(_wq_entry, _flags, current, autoremove_wake_function) + +#define init_wait(wait) init_wait_entry(wait, 0) + /** * waitqueue_active -- locklessly test for waiters on the queue * @wq_head: the waitqueue to test for waiters @@ -283,8 +300,6 @@ static inline void wake_up_pollfree(struct wait_queue_head *wq_head) (!__builtin_constant_p(state) || \ state == TASK_INTERRUPTIBLE || state == TASK_KILLABLE) \ -extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags); - /* * The below macro ___wait_event() has an explicit shadow of the __ret * variable when used from the wait_event_*() macros. @@ -1170,23 +1185,6 @@ long wait_woken(struct wait_queue_entry *wq_entry, unsigned mode, long timeout); int woken_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key); int autoremove_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key); -#define DEFINE_WAIT_FUNC(name, function) \ - struct wait_queue_entry name = { \ - .private = current, \ - .func = function, \ - .entry = LIST_HEAD_INIT((name).entry), \ - } - -#define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function) - -#define init_wait(wait) \ - do { \ - (wait)->private = current; \ - (wait)->func = autoremove_wake_function; \ - INIT_LIST_HEAD(&(wait)->entry); \ - (wait)->flags = 0; \ - } while (0) - typedef int (*task_call_f)(struct task_struct *p, void *arg); extern int task_call_func(struct task_struct *p, task_call_f func, void *arg); diff --git a/include/linux/wait_bit.h b/include/linux/wait_bit.h index 7725b7579b78..267ca0fe9fd9 100644 --- a/include/linux/wait_bit.h +++ b/include/linux/wait_bit.h @@ -38,12 +38,7 @@ int wake_bit_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync #define DEFINE_WAIT_BIT(name, word, bit) \ struct wait_bit_queue_entry name = { \ .key = __WAIT_BIT_KEY_INITIALIZER(word, bit), \ - .wq_entry = { \ - .private = current, \ - .func = wake_bit_function, \ - .entry = \ - LIST_HEAD_INIT((name).wq_entry.entry), \ - }, \ + .wq_entry = WAIT_FUNC_INITIALIZER((name).wq_entry, wake_bit_function),\ } extern int bit_wait(struct wait_bit_key *key, int mode); diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c index 9860bb9a847c..b9922346077d 100644 --- a/kernel/sched/wait.c +++ b/kernel/sched/wait.c @@ -289,15 +289,6 @@ prepare_to_wait_exclusive(struct wait_queue_head *wq_head, struct wait_queue_ent } EXPORT_SYMBOL(prepare_to_wait_exclusive); -void init_wait_entry(struct wait_queue_entry *wq_entry, int flags) -{ - wq_entry->flags = flags; - wq_entry->private = current; - wq_entry->func = autoremove_wake_function; - INIT_LIST_HEAD(&wq_entry->entry); -} -EXPORT_SYMBOL(init_wait_entry); - long prepare_to_wait_event(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry, int state) { unsigned long flags;