From patchwork Fri Feb 16 18:04:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 202284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp689562dyb; Fri, 16 Feb 2024 10:07:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVItjz4U/T+fka8kicnycVIXC7a2JgAgLEK8TA8NZtoLb5270fjD0/mh8dCoIp0jB0ZeR/afI9We6CCPcteH24qTHp1fA== X-Google-Smtp-Source: AGHT+IHHNG0Dv5sN6qe3WSGe/h5Xq1ZSKjxX38VRTLkSq5b7WZvEy5wEQ5kE7ALkghdDpvGVR7cp X-Received: by 2002:a05:6870:2b04:b0:21e:8603:cf20 with SMTP id ld4-20020a0568702b0400b0021e8603cf20mr78488oab.52.1708106842351; Fri, 16 Feb 2024 10:07:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708106842; cv=pass; d=google.com; s=arc-20160816; b=muVhawCaIsNJz2cM62BSWOBZ3nePjihsqdx1hAqDqG+4cDWq/GnwuGiA5wB870xJEA li7gGD7kVGEtng52fpZnkOfxxgXra6HTNHS0JPCDf6ZZ1xqyMP+dZt208kMG0dv2OpGC 5BbRS6wEiXM1A7KgKmmkL4x7mMOxtjUxbMVdQ9bBltVcfVSnLDP6Q0emzkVrfI9PZsnM ZraKp59FMG2BqOwR0vP2rSyjstRxnsLfyJKFxIhcfvxu4mK/S10yh2Z7RLRaSXz6UP4k ohTfS/ZSq+aC4j9+D7E5qojiXA29Dnn0LRbXRVEK7RiUcettaEooUXhu/R8R4JzCdbnL Vi9Q== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69122-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x7-20020a1f7c07000000b004c0ae4d3fc8si189418vkc.307.2024.02.16.10.07.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 10:07:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69122-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69122-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0A0D11C219A6 for ; Fri, 16 Feb 2024 18:07:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3727C135A6F; Fri, 16 Feb 2024 18:06:26 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791079840590441401 X-GMAIL-MSGID: 1791079840590441401 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