Message ID | 20240228181850.5895-1-apais@linux.microsoft.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-85523-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3526068dyb; Wed, 28 Feb 2024 10:19:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUZW94N9CGs9IKYnZsauHtwmnTc6BU729Svd2JLo437fh+9lUJBzo+aR6pGLJaJ2K5AQD4xHVfpRk+l1lb1+fX3Jfw1Hg== X-Google-Smtp-Source: AGHT+IFBroA7rW489tmAY/OCCB2NQChWje336H/e3rAV+BaZdEgMGUiBGcAFA1sW7I6zOc05F2gS X-Received: by 2002:a05:620a:4108:b0:787:f8fe:6608 with SMTP id j8-20020a05620a410800b00787f8fe6608mr367741qko.49.1709144354258; Wed, 28 Feb 2024 10:19:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709144354; cv=pass; d=google.com; s=arc-20160816; b=yrg1YDe6IybaJbBHyoy68TUUDpRh8g2dcdLBLLYL7iLJWQEmcgrc8bordlk47SOMSQ nFpGCkKzzv/nkkOzpHkwlF8F9ObK7F3JDexBmlXaJSRTmI7ZIkG9YZHmZZjL78YG2naC uInCFMc5/FgKvGE71hiau1hWD3L85uWYycBvBRwwYMsp8IqOULrCL2KtVGf7wodjQ/cq gLnczaIUJnHFc9PVnvfvoph1FzIjXurd3URDoGSPeBB0b/4oJmXL5baNHR0sDQumffhY 0UrCySvC2pq7PbiCGuZpXY10qvV5jJC6+D/nekFnK0LHzln+3E1PNyevDvc4708jAJVW KMFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=yYZPAWRso4kZ0IbrwPw0ArpV7c3Fq15yCkQN2Ac6BqQ=; fh=jl9/kuBYo3Gn2BBz0zErs9UPETds1jCciNhLeHU6Px8=; b=EsrhipOZ5wHX4IlvdkICl4tR4nzIShSUAhT0SkL0XHzP854WyqM9O09Ojbx5yhm0XO g1r/KRdnG7drFNi7crYlSnoO2Ho/UcIUJhnVfCcbbX6J5kh/meCA4Bx/AfuZChoFkXuC XTsWnEuvegHaeSMyvQF5INneGndKSgUajEShI5mtDB0EekOsmOM6Vc7hsGI11npvw2c4 hNn+FkeqLl2ZDpN8AXmWM7esmjaYXjrd0pA31p3A8RmvIDAb7By+oM+m0Dt8vZPWRmQq Gtcwq01ETkH/32IRl3+jfZNuuwQKMtpVz8F4amBlNDKETnvlwRHZeDyKDa5Ask1mMKCw BxOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=aJKdUie4; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-85523-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85523-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h21-20020a37de15000000b0078770e84db6si47866qkj.511.2024.02.28.10.19.14 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 10:19:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85523-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=@linux.microsoft.com header.s=default header.b=aJKdUie4; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-85523-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85523-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com 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 105361C22B97 for <ouuuleilei@gmail.com>; Wed, 28 Feb 2024 18:19:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C864B4087E; Wed, 28 Feb 2024 18:19:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="aJKdUie4" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CCBE34084C for <linux-kernel@vger.kernel.org>; Wed, 28 Feb 2024 18:18:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709144339; cv=none; b=MIe7fzFvli5hfc8KeJPHbcA5wMeiGZDcOh3dvBkwhjSy90HJtRV/ch697rdszFoTdPPbIHFpLwSpKJEfIFLxNULufEyCj2aOjTV9N3LXYVrCax4NhuQ/i/tGgg9bCXjp5km4xT+ehhIKQ/GrvN6gbYWmMNbGNCaj6dBgGRr2LB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709144339; c=relaxed/simple; bh=ctQuxA/YbpcInqTpD6+LUKnEtN3IvRYl52XsonnTBRw=; h=From:To:Cc:Subject:Date:Message-Id; b=N7l1fRtOzcH2TKUbPqGlIWj7/EzwDHBz6Qr7RIl5fm+KPSWNRjVHek4lB23ICRXgfJCx9p5MTuXeW3WADSIyd7BZvOuWA3pjBoI886qFzZA8HUk3vES2fgozX/tdzp2UPJeEfS/UuQgxT2Ph2FWX9kMjC/BPTvHftGw3Z3TzhFU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=aJKdUie4; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: from apais-vm1.0synte4vioeebbvidf5q0vz2ua.xx.internal.cloudapp.net (unknown [52.183.86.224]) by linux.microsoft.com (Postfix) with ESMTPSA id 7357E20B74C0; Wed, 28 Feb 2024 10:18:57 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7357E20B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1709144337; bh=yYZPAWRso4kZ0IbrwPw0ArpV7c3Fq15yCkQN2Ac6BqQ=; h=From:To:Cc:Subject:Date:From; b=aJKdUie4ndiI+3TiPDgJ2JFkI1p84w+PHi++1EUxFy5pgJlfjYP6f64Cvi5HvZ9e6 JJOTsAmJuHY+uli/YfEZc2r18f82up0hLmHDweFvDU2kfmalLCchD6fiOq/eMjBKor aDe0VRqoDGWUExmgCzjs67uw1aSy26Nrb/sEQSII= From: Allen Pais <apais@linux.microsoft.com> To: tj@kernel.org Cc: jiangshanlai@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH] kernel: Introduce enable_and_queue_work() convenience function Date: Wed, 28 Feb 2024 18:18:50 +0000 Message-Id: <20240228181850.5895-1-apais@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792167749983571456 X-GMAIL-MSGID: 1792167749983571456 |
Series |
kernel: Introduce enable_and_queue_work() convenience function
|
|
Commit Message
Allen Pais
Feb. 28, 2024, 6:18 p.m. UTC
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(). 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.
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.
Signed-off-by: Allen Pais <allen.lkml@gmail.com>
---
include/linux/workqueue.h | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
Comments
On Wed, Feb 28, 2024 at 06:18:50PM +0000, Allen Pais wrote: > 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(). 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. > > 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. > > Signed-off-by: Allen Pais <allen.lkml@gmail.com> I'll apply this together with the rest of the series once v6.10-rc1 opens. Thanks.
>> 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(). 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. >> >> 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. >> >> Signed-off-by: Allen Pais <allen.lkml@gmail.com> > > I'll apply this together with the rest of the series once v6.10-rc1 opens. Thank you. Meanwhile, I will go ahead and prepare the conversion with Based on this change. Thanks. > > Thanks. > > -- > tejun
On Thu, Feb 29, 2024 at 2:18 AM Allen Pais <apais@linux.microsoft.com> wrote: > > 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(). 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. > > 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. > > Signed-off-by: Allen Pais <allen.lkml@gmail.com> > --- > include/linux/workqueue.h | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h > index aedfb81f9c49..31bbd38ef8c8 100644 > --- a/include/linux/workqueue.h > +++ b/include/linux/workqueue.h > @@ -678,6 +678,29 @@ 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 attempts to enable the specified work item using enable_work(). > + * If the enable operation is successful, the work item is then queued on the Could you please specify what "successful" means and also please document it that it might cause unnecessary spurious wake-ups and the caller should prepare for it if it is not desired. Thanks Lai PS: I'm afraid it can cause unnecessary spurious wake-ups in cases where the work item is expected to be dormant ordinarily but disable/enable() are called often for maintenance. However, the user can resort to other synchronization in this case rather than just disable/enable() only to avoid the wake-ups overheads. > + * provided workqueue using queue_work(). It returns %true if the work item was > + * successfully enabled and queued, and %false otherwise. > + * > + * 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. > + */ > +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.17.1 >
> > > > +/** > > + * 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 attempts to enable the specified work item using enable_work(). > > + * If the enable operation is successful, the work item is then queued on the > > Could you please specify what "successful" means and also please > document it that it might cause unnecessary spurious wake-ups and > the caller should prepare for it if it is not desired. Thank you for the review. I will work on documenting it. Thanks. > Thanks > Lai > > PS: > > I'm afraid it can cause unnecessary spurious wake-ups in cases > where the work item is expected to be dormant ordinarily but disable/enable() > are called often for maintenance. However, the user can resort to other > synchronization in this case rather than just disable/enable() only to avoid the > wake-ups overheads. > > > > > + * provided workqueue using queue_work(). It returns %true if the work item was > > + * successfully enabled and queued, and %false otherwise. > > + * > > + * 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. > > + */ > > +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.17.1 > > >
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index aedfb81f9c49..31bbd38ef8c8 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -678,6 +678,29 @@ 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 attempts to enable the specified work item using enable_work(). + * If the enable operation is successful, the work item is then queued on the + * provided workqueue using queue_work(). It returns %true if the work item was + * successfully enabled and queued, and %false otherwise. + * + * 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. + */ +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.