Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1269862rdb; Fri, 16 Feb 2024 10:07:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX4WrL5UgfRm7/pArzamaxP8lGi1i5zBs65EXVB2mWzi3ORyx45ROZBpqvflT3Ke8OhrXvnXE0urUNye+PTZMN71LhETOynaywbTiJfZw== X-Google-Smtp-Source: AGHT+IEXQxdgO4xlBWxfM+SbOxjW06Bi1fRIeS+83eiSkLyYNlYuODFBKnSEglhmfszrbDSeEwfS X-Received: by 2002:a17:90a:1648:b0:299:305e:68fa with SMTP id x8-20020a17090a164800b00299305e68famr3044983pje.8.1708106830017; Fri, 16 Feb 2024 10:07:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708106830; cv=pass; d=google.com; s=arc-20160816; b=L7fKwqHqzAYxcE/qkaAPqA4fEQqodKnzOxAt8GCAwuzCCYmJiD+YZgplXzXPQkTUQv cR8cKycje+ysPA6g3OazOh/38Qb6CwZj0xFfAZKG3ij7Wt6pTdx4yjWydffnPtt96/mA PEk6M3OYiK1kBMC3p8EGX85wJ3ts2Q2cU35MCrkNWB9N7u8bmtOr95yDaiaEs01ABeDC 4nbVEEeR/J5vRYCvwVGg2EIRWU8Fy1zy8iRAHHvkGJ82w6mhIvmpkE/j+qfuYdj0bKph gj5+1wkrMiepa1WjmFXKDfV7fYhtPor+YG3vtXK+70SLts2FLxHCm/cWXX7Kr60EDiVR xniA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:sender:dkim-signature; bh=+DS0DtBclwHzHSMAZjstaKCNqredx4H7iHvNpCWzDbo=; fh=tnBKLP+Cab9VO74Scjv8u5Unca1J6Gt7YBI7xPnWQm4=; b=wTIYB/pCEmzCpJRt+SU+rI8Ftr1gYf7rzTD4erZbcuET9+ruucg5+7Rf1EuvPzQkSt A7NkcI7QGAW0960R/8ozsLKWv7+ZOWnGqM5etlVA3JLEvZmXcR6G6lJmGcsH+jreMYAM OBlokWT49Ut297jN7F5VAMEdrQAxnpYcGav8eIQljTNaIYMOV+o8PK4/XnMIvM749gxe kpc7PWaOkL/qs47x4ACuc/oC71dq8DYPdwvRaE1asRy9d4x2/15HDaKqV4nW4aSOETiR ct+fQEP8uHXjKOkhVV8BhKPPkvtiWhRo/sv2vS5W391/+GibZoEn5TB8xnPAuH2e2PNA AEBg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gQzNUwIJ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-69122-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69122-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id gv22-20020a17090b11d600b0029929e66a2fsi293132pjb.147.2024.02.16.10.07.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 10:07:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69122-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gQzNUwIJ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-69122-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69122-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AE19E2831DE for ; Fri, 16 Feb 2024 18:07:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C6A4135A50; Fri, 16 Feb 2024 18:06:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gQzNUwIJ" Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 783051353FD for ; Fri, 16 Feb 2024 18:06:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106783; cv=none; b=R0BANBPeLyD06Pys2yXsNUjaUSwRrADmqwA8oDzJLPLIoaNfAq+RsViBbxirHGV7pTtEpEXKJ2neL3rEEs9Lc+Ck75nlevjiP552uNL8vD5T0Yceh2BD0S3eN5528nFsvYKxSoYFwd0mJIUd3c8IEQkORJfDbYLf8kMYG/3Najw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106783; c=relaxed/simple; bh=8S4nvCiX9SIcGhxtmUUofNJcQBOMVPXacIdRA1r1JaM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GkNH4nn0ytvHGko4rgDIjkNGaCBV8EC9olGo5kLVfkINxSU1ckFJ8opTbaqecifGljS9yJCN9yTSSoZlgZCMSFW87F6Y8wieUDV8OptizHjI9Pai9N+3L4nHTfKIjhr26EdyYvaItxVzFIyQlplZ5JQUf67pWLFdVRVaeUq1eUc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gQzNUwIJ; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1d93edfa76dso8831135ad.1 for ; Fri, 16 Feb 2024 10:06:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708106780; x=1708711580; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=+DS0DtBclwHzHSMAZjstaKCNqredx4H7iHvNpCWzDbo=; b=gQzNUwIJtOqsqMNUMZllVTcJ+u2MFrWH+aUoQn0zdRVKVac/UZmyuSs5pnkMgq+d7k E4PtgNzdBmoLR1Spdqz2KBd4HKr7bS0UdDTe8x/hHLaZcUU8/wgUmFhqstU7ZQqGkDfh tj52XI4CYAcyIJ4Rpku32aRJXZILKiFDtqAcd9jBIhA+CsP9ccs4HWNgrUvQmoqywYzp 6U2OzopvxifY03ioYbdOXjTgqCXHgio3Fl6F98WZ9jwxVxViEwSA3M8FbYu8pfX7y+qN gY2d4q54SA1T6kK/zf6Cu/PJeZER0q8xrE5dtbO/38z7KOlESXFDqJxThtpAhbOA1K74 XUaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708106780; x=1708711580; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+DS0DtBclwHzHSMAZjstaKCNqredx4H7iHvNpCWzDbo=; b=KqM8SpcOJugr6YaHfCjQntKNghP+domhfutgSDHE5cp3ybEaluezGU66Z3mkP0tt/T yawj59oDJKE13AaIJ2rbtqYxCHcTX4AFJi6IJ+HtFwzTP9iVG1IVsbPs3CzbuFFU5WsQ /qOFqJ2wQdg7LCkzchuSNDapfV6wIMlRgHQ23Y5gBee2Km2l4IWXk9jHCRuO2Phrbfbd 9prPcL9pxGQTNhCozOJE4Pmw1ywyLMUcIxEc3vGlOw+6ux2GF90wR1QDApzi6bTDh2YZ 9G8Ilhe80F5dQhfocbDJnJIPXH0OrLRiR3Pa0BjgGyA/iLRSkKimFDCVI0jxYn3bZoQw VPEw== X-Forwarded-Encrypted: i=1; AJvYcCU0H2Ll2ANiUx1M9heTeEVCVEX860XgMSbojzKx1+CBnEY/ID3oHvZiweed6eY7PsQh8Hm1FwugcsJ6omAHGLt9KLSPL8ZflOlBzFWV X-Gm-Message-State: AOJu0YxjvzmO60WjwQUToR3SjSL7RT26TRZA45COzG5u2YzBoXkYkx4h wt7czOPq3fwmnlg78L5CooFbXyf4e6yWqpwesaqMnYIap9d6z9Sj X-Received: by 2002:a17:903:904:b0:1db:a6b8:6b23 with SMTP id ll4-20020a170903090400b001dba6b86b23mr3323978plb.27.1708106780472; Fri, 16 Feb 2024 10:06:20 -0800 (PST) Received: from localhost (dhcp-141-239-158-86.hawaiiantel.net. [141.239.158.86]) by smtp.gmail.com with ESMTPSA id jc15-20020a17090325cf00b001db54324488sm161468plb.38.2024.02.16.10.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 10:06:20 -0800 (PST) Sender: Tejun Heo From: Tejun Heo To: jiangshanlai@gmail.com Cc: torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, allen.lkml@gmail.com, kernel-team@meta.com, Tejun Heo Subject: [PATCH 04/17] workqueue: Reorganize flush and cancel[_sync] functions Date: Fri, 16 Feb 2024 08:04:45 -1000 Message-ID: <20240216180559.208276-5-tj@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216180559.208276-1-tj@kernel.org> References: <20240216180559.208276-1-tj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit They are currently a bit disorganized with flush and cancel functions mixed. Reoranize them so that flush functions come first, cancel next and cancel_sync last. This way, we won't have to add prototypes for internal functions for the planned disable/enable support. This is pure code reorganization. No functional changes. Signed-off-by: Tejun Heo --- kernel/workqueue.c | 136 ++++++++++++++++++++++----------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 7e2af79bfa62..962061dca05c 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4061,6 +4061,65 @@ bool flush_work(struct work_struct *work) } EXPORT_SYMBOL_GPL(flush_work); +/** + * flush_delayed_work - wait for a dwork to finish executing the last queueing + * @dwork: the delayed work to flush + * + * Delayed timer is cancelled and the pending work is queued for + * immediate execution. Like flush_work(), this function only + * considers the last queueing instance of @dwork. + * + * Return: + * %true if flush_work() waited for the work to finish execution, + * %false if it was already idle. + */ +bool flush_delayed_work(struct delayed_work *dwork) +{ + local_irq_disable(); + if (del_timer_sync(&dwork->timer)) + __queue_work(dwork->cpu, dwork->wq, &dwork->work); + local_irq_enable(); + return flush_work(&dwork->work); +} +EXPORT_SYMBOL(flush_delayed_work); + +/** + * flush_rcu_work - wait for a rwork to finish executing the last queueing + * @rwork: the rcu work to flush + * + * Return: + * %true if flush_rcu_work() waited for the work to finish execution, + * %false if it was already idle. + */ +bool flush_rcu_work(struct rcu_work *rwork) +{ + if (test_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(&rwork->work))) { + rcu_barrier(); + flush_work(&rwork->work); + return true; + } else { + return flush_work(&rwork->work); + } +} +EXPORT_SYMBOL(flush_rcu_work); + +static bool __cancel_work(struct work_struct *work, bool is_dwork) +{ + unsigned long flags; + int ret; + + do { + ret = try_to_grab_pending(work, is_dwork, &flags); + } while (unlikely(ret == -EAGAIN)); + + if (unlikely(ret < 0)) + return false; + + set_work_pool_and_clear_pending(work, get_work_pool_id(work)); + local_irq_restore(flags); + return ret; +} + struct cwt_wait { wait_queue_entry_t wait; struct work_struct *work; @@ -4139,6 +4198,15 @@ static bool __cancel_work_sync(struct work_struct *work, bool is_dwork) return ret; } +/* + * See cancel_delayed_work() + */ +bool cancel_work(struct work_struct *work) +{ + return __cancel_work(work, false); +} +EXPORT_SYMBOL(cancel_work); + /** * cancel_work_sync - cancel a work and wait for it to finish * @work: the work to cancel @@ -4163,74 +4231,6 @@ bool cancel_work_sync(struct work_struct *work) } EXPORT_SYMBOL_GPL(cancel_work_sync); -/** - * flush_delayed_work - wait for a dwork to finish executing the last queueing - * @dwork: the delayed work to flush - * - * Delayed timer is cancelled and the pending work is queued for - * immediate execution. Like flush_work(), this function only - * considers the last queueing instance of @dwork. - * - * Return: - * %true if flush_work() waited for the work to finish execution, - * %false if it was already idle. - */ -bool flush_delayed_work(struct delayed_work *dwork) -{ - local_irq_disable(); - if (del_timer_sync(&dwork->timer)) - __queue_work(dwork->cpu, dwork->wq, &dwork->work); - local_irq_enable(); - return flush_work(&dwork->work); -} -EXPORT_SYMBOL(flush_delayed_work); - -/** - * flush_rcu_work - wait for a rwork to finish executing the last queueing - * @rwork: the rcu work to flush - * - * Return: - * %true if flush_rcu_work() waited for the work to finish execution, - * %false if it was already idle. - */ -bool flush_rcu_work(struct rcu_work *rwork) -{ - if (test_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(&rwork->work))) { - rcu_barrier(); - flush_work(&rwork->work); - return true; - } else { - return flush_work(&rwork->work); - } -} -EXPORT_SYMBOL(flush_rcu_work); - -static bool __cancel_work(struct work_struct *work, bool is_dwork) -{ - unsigned long flags; - int ret; - - do { - ret = try_to_grab_pending(work, is_dwork, &flags); - } while (unlikely(ret == -EAGAIN)); - - if (unlikely(ret < 0)) - return false; - - set_work_pool_and_clear_pending(work, get_work_pool_id(work)); - local_irq_restore(flags); - return ret; -} - -/* - * See cancel_delayed_work() - */ -bool cancel_work(struct work_struct *work) -{ - return __cancel_work(work, false); -} -EXPORT_SYMBOL(cancel_work); - /** * cancel_delayed_work - cancel a delayed work * @dwork: delayed_work to cancel -- 2.43.2