Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2908817lqp; Mon, 25 Mar 2024 12:43:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWYFWEiPNha7k5cipEePKi+25wlL7ZU0D2z6UlIijH1wnJ0od326IV8NTn7Xl2f6bU5egBa38tdyxlCE8757FZqiP9wtr+Zk974XiMZ0A== X-Google-Smtp-Source: AGHT+IFQeDW3U+7t9WHZ41lbfqCFFGLubyE1AUWWt108oR4n+Ujh9zsGBfyFdcOh33hF2Jd7mo5w X-Received: by 2002:a05:6122:4211:b0:4c8:e5a0:4222 with SMTP id cm17-20020a056122421100b004c8e5a04222mr5850996vkb.12.1711395811611; Mon, 25 Mar 2024 12:43:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711395811; cv=pass; d=google.com; s=arc-20160816; b=T4lj7r1aALrtVLPs9NoqbU0BlyClQtpYwauEADsLodLDMJ/5YzJg/QvWIWqSIk6x5a Pj4ovRFuLvGEATkEvzdtDoVZaruPo8z3i+JSdUneE5+9ri2yvgz+zUVqVgDAo32C6yU0 BkejSdMDCNtAhd5ucF+5O937RMkTPtZ49aaF2DyQhTh/JAG7r6cdrfW5AKlN6BR5waSy Z5uJUoUHl9VD1iX5aoXGEzrS4pVXw9ew00V3OIHhQhrjlCkWpBSqAsDCM/gAvAUk8tgo SMy+07Ewi6aiuecJGQ3RwsoQDqoJxb9pY6Zw6d7a8l2ZFalKIUW8ztbrTbpkGaoHdBy6 eepA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:sender:dkim-signature; bh=/GNuMW47+QhhyncApcMkdyIFe1uqQGtbO15QL9ZbpIE=; fh=IFzp5zY5pkAFe6eCSfO4xHZro5XNbXVrIAEvO9RAdUE=; b=Sqp/rKe/9UqYtcwwXXiU1cP8dlN0uhmDtEGvRWVcEd+Hp3koGMBu41zSddgm06ijNc zxWoATsBcUJ8eOctDKm/QiasXIHCthrFe3LOhvyhDn7I392i+csYbYHy49JH2zmXirBN 2xrgsuh/skuhRIwaOZe+tdRx7cEBNNG2c18Pm4Jv7M9Xf2ChTQz5ERbQb89eQUqIs1Q1 jc+ks8dZi2yt3Coi4I+FyuQQYOmzIRoQRaX3qt6iRLEqbYGPl/WZSBYYOjuMoPNM8Clm 0c0/Rk7gjMszyGopfWtFpRSNpAKnJ2Yy1+mUqap1K/rQ6tKwXD1k8pBZENmRFXOpjkpD O7Rg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cxCTXOh8; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-117843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117843-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o5-20020ad45c85000000b0069691a54db9si2246210qvh.595.2024.03.25.12.43.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 12:43:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117843-linux.lists.archive=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=cxCTXOh8; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-117843-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117843-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 49B071C61F21 for ; Mon, 25 Mar 2024 19:43:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01EC41C29F; Mon, 25 Mar 2024 19:43:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cxCTXOh8" Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 850263399F for ; Mon, 25 Mar 2024 19:42:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711395779; cv=none; b=hM8Qq3Ig/xo+L1y4iYy7MYq4aN8LACUrVExQ40lHukuCg8YFB2waJhBFxbIfo0QQ6QzXsRhOLCPggg0VDNpuh97sDG5/nbRcTeejc3PzN42kOcGa4/zhwOHw+45lCJOweFwby7nuvXXXE7ZnjfcRJDOBZsFC8p8w7+XWkTNii6Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711395779; c=relaxed/simple; bh=clBK7WyFrTer33UcCZksOAeIE0Ht+WdYbjn6omkCaZg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KIRoGLEgjPfYPsnPLi5icXcuNGdFI/sm/LMILMWvKGHBBiFiB0Wb+NS05Ko5ZbjGBCEp5qvP1pMUW9h4NaCcVq3Xv17N0JmwWV9JI9AQmxKmPSGgIQOEcq9SZRKayUNtZ7U9IjKswiocXuj52ruJtJA+x+9w7JdsPj/j/V4Ogs8= 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=cxCTXOh8; arc=none smtp.client-ip=209.85.215.173 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-pg1-f173.google.com with SMTP id 41be03b00d2f7-5bdbe2de25fso3228228a12.3 for ; Mon, 25 Mar 2024 12:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711395777; x=1712000577; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=/GNuMW47+QhhyncApcMkdyIFe1uqQGtbO15QL9ZbpIE=; b=cxCTXOh82apf606ipnrgCYiquC9a7mNgKBWRNUx637KKKI8w21qOZFGexP+ubSjdSJ 8XQ+6Q9b91M2kT6h6PV2f5lM7qTfGWM8lP2ea1pwyFI0lg6H42/9DULDUdpf2nY87f6/ mASO6J8o1dCxSI24fyEMnFxxJ5k9Wq6TvOS+BnKWsbzpj7JmPBwScybV2jhtU5f85xDZ Bxj91SyLP462aggxtjCMp2YM/llVUzY/izKzl58BkMZIhc+CJrTEHv+v7eZthZu1evMp fs2bkyB2eXkaf8bWiIgfYB8jN7aEBIYezCY7KFEmn09LLvu3IZXSb1j7U9ghlgvJLmpR 3guA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711395777; x=1712000577; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/GNuMW47+QhhyncApcMkdyIFe1uqQGtbO15QL9ZbpIE=; b=Eo9EDf6adtNsuwBBttcZfI5bDuB9WvF0UeP7tgfcbZuw042Pe3MlqSP7dOPn2zidTp 9cVNowKHO/TFMwY4LV+0o8bpC2PYGLsdi5LB2Le57L2jglPujgscD7OVBOXsBwXgitHz WjKA9gqDfTm48qFgkl/SQUzyhQu368T4hlHNrWa0DLIOP31LnzwXqLNfBNNAEUx3Dchk n2YjY4HMyEfi6slkBnoRgJej73UsjgC3cbyfhY2BA+sb90kfdDENfsHqSIMvglYN5T22 yDExT83xrmBw7bZaFv73whqxz2Nm4shCwXakrFL37V7WIlFS1VNSR06kCId3gj8UL4kf iIEg== X-Forwarded-Encrypted: i=1; AJvYcCXscZHjxmxjnaCELw0TAgrqnMbt2oTdcWRL5+HXkW2FHr0SMqQt4W1AuIAFNFarL/MJMLOt9vKGTpyiZjbux7Y5c+61x1/WkF06Xq99 X-Gm-Message-State: AOJu0YxgVEpBK1erBzoOD1CLuqcqYqK3OksysQ005iTrEhRYl++v7fDC VFlPB7xRsKZeO2zQ8iCjACVf4dzLvsdhF1YYCaAZt/ZYuYh8xw0Y X-Received: by 2002:a17:902:d542:b0:1dc:ce6e:bf06 with SMTP id z2-20020a170902d54200b001dcce6ebf06mr11844953plf.0.1711395776757; Mon, 25 Mar 2024 12:42:56 -0700 (PDT) Received: from localhost (dhcp-141-239-158-86.hawaiiantel.net. [141.239.158.86]) by smtp.gmail.com with ESMTPSA id m12-20020a170902bb8c00b001e0449adfaesm5057733pls.191.2024.03.25.12.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 12:42:56 -0700 (PDT) Sender: Tejun Heo Date: Mon, 25 Mar 2024 09:42:55 -1000 From: Tejun Heo To: Allen Pais Cc: jiangshanlai@gmail.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] kernel: Introduce enable_and_queue_work() convenience function Message-ID: References: <20240325180201.6027-1-apais@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240325180201.6027-1-apais@linux.microsoft.com> Hello, The function comment felt a bit too verbose. I applied the following compacted version to wq/for-6.10 which hopefully still contains all the necessary information. Please let me know if you disagree. Thanks. --- 8< ---- From 474a549ff4c989427a14fdab851e562c8a63fe24 Mon Sep 17 00:00:00 2001 From: Allen Pais Date: Mon, 25 Mar 2024 18:02:01 +0000 Subject: [PATCH] workqueue: Introduce enable_and_queue_work() convenience function The enable_and_queue_work() function is introduced to streamline the process of enabling and queuing a work item on a specific workqueue. This function combines the functionalities of enable_work() and queue_work() in a single call, providing a concise and convenient API for enabling and queuing work items. The function accepts a target workqueue and a work item as parameters. It first attempts to enable the work item using enable_work(). A successful enable operation means that the work item was previously disabled and is now marked as eligible for execution. If the enable operation is successful, the work item is then queued on the specified workqueue using queue_work(). The function returns true if the work item was successfully enabled and queued, and false otherwise. Note: This function may lead to unnecessary spurious wake-ups in cases where the work item is expected to be dormant but enable/disable are called frequently. Spurious wake-ups refer to the condition where worker threads are woken up without actual work to be done. Callers should be aware of this behavior and may need to employ additional synchronization mechanisms to avoid these overheads if such wake-ups are not desired. This addition aims to enhance code readability and maintainability by providing a unified interface for the common use case of enabling and queuing work items on a workqueue. tj: Made the function comment more compact. Signed-off-by: Allen Pais Signed-off-by: Tejun Heo --- include/linux/workqueue.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index bfcf8d38f4b1..2df1188c0f96 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -682,6 +682,32 @@ static inline bool schedule_work(struct work_struct *work) return queue_work(system_wq, work); } +/** + * enable_and_queue_work - Enable and queue a work item on a specific workqueue + * @wq: The target workqueue + * @work: The work item to be enabled and queued + * + * This function combines the operations of enable_work() and queue_work(), + * providing a convenient way to enable and queue a work item in a single call. + * It invokes enable_work() on @work and then queues it if the disable depth + * reached 0. Returns %true if the disable depth reached 0 and @work is queued, + * and %false otherwise. + * + * Note that @work is always queued when disable depth reaches zero. If the + * desired behavior is queueing only if certain events took place while @work is + * disabled, the user should implement the necessary state tracking and perform + * explicit conditional queueing after enable_work(). + */ +static inline bool enable_and_queue_work(struct workqueue_struct *wq, + struct work_struct *work) +{ + if (enable_work(work)) { + queue_work(wq, work); + return true; + } + return false; +} + /* * Detect attempt to flush system-wide workqueues at compile time when possible. * Warn attempt to flush system-wide workqueues at runtime. -- 2.44.0