From patchwork Tue Feb 27 19:10:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Allen Pais X-Patchwork-Id: 207392 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2915302dyb; Tue, 27 Feb 2024 11:21:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUdVRBVOzLdSMhHpdhgO6ZXcOBwyjA7xDhv6UgIC+XNWCo3pELLYOYdXoNvBAs5NaZeVNY6F4YSEBXmqMy9B1SjvF8GgA== X-Google-Smtp-Source: AGHT+IH9jgCXFJ8NM0kyN7InqVRfbYYICU20GkLU1wZGO8GLG6tU+YUw1PKhswWEZN9V2H0HSNQs X-Received: by 2002:a17:90a:4a07:b0:29a:b31e:2801 with SMTP id e7-20020a17090a4a0700b0029ab31e2801mr5656846pjh.1.1709061699284; Tue, 27 Feb 2024 11:21:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709061699; cv=pass; d=google.com; s=arc-20160816; b=CAlMoigg+QuiyUVKx4+WYWmna1oA96B5/Wrlord6W6ZDZYwNB194Fl8NtSwjBFVdsm wmJhDkwUXDHGg0qXTgCtPoDf5fKJsXIQwj3rounmMCkeLPxWX0ktj2S/0nsDKbdzWMY1 7uGCF/VmGY1nSZSVvw9xXikB7gSj1Lrha/E1FVrH2cIMyaixw5Sgmf5W/7m/zDUgcC6O wNmjw7WG+IlVYT7plxcpG04XPdUDv3uSAzu2t5bvkLOAsCLmc1XPtWbEclYC6bGN1IDL zj5iAXf1QW1F/XCTTN6G+xjDXtKBnSXtzgvrmvQ8OJPfx8oR/pES27QZAvj7geEDsurV 3FQQ== 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=dHXV9Ly1sQdf88TxoYBnR+fTtJ69EeUYd8QJVu9nB3c=; fh=jl9/kuBYo3Gn2BBz0zErs9UPETds1jCciNhLeHU6Px8=; b=ebeHw2lswH+d9aVGRCH8hlesqi7VmszvRQN2WyX9SqfTYTvLOfqoVwq2A019Nld6fh B52TDDbK65I1fe3MYxJc2J55MT77KVoNlcw9R8Tg2KiMkDmpvebTWX8NTt5VONnl26ub 3nW0g/cqQAJGPGMXncBonMq0I/6TdkFwKu63oNEH/8eZ3T258DJ+/qoU8RAs4MRh8roM aMQnTYt9nFRGMKbRzofwZSIUyjX+U3/mDFJnbPcQSEfl9oDFMjYBWtjHC8K+QqzUggZR 78IoZXr6iMwJDsfXs/EGcF6PXiRcgNNDQcFfaMenjOtTrKSx/uB3q6x+LZu+1DmhFU6y 8yxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="sTzif/MS"; 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-83900-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83900-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id mh7-20020a17090b4ac700b0029ae3ccf94asi1421036pjb.149.2024.02.27.11.21.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 11:21:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83900-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="sTzif/MS"; 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-83900-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83900-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9CE2F2907E7 for ; Tue, 27 Feb 2024 19:10:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7529E51C5A; Tue, 27 Feb 2024 19:10:47 +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="sTzif/MS" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FDE34E1DC for ; Tue, 27 Feb 2024 19:10:43 +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=1709061044; cv=none; b=o1VCD0NtE4YFuoYxKm4NGrZNVg6QqhFlBL3dHy8StcKhw5HgrwloqG/Vp/tnB8UqV/FSEm26UZLDvXVN8Rs/gVSIJCeh2QIA8+Roh3lkJB7qdydjQV8Yt8IS0kZt5wVZSu84cM3ozG1T0bWO2KnEr9Nr2FZfkHIxq3bvsoiRnl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709061044; c=relaxed/simple; bh=3qEYpQVEQQyEhmIlwWXIEf3W8r2LJW7QkiNvHIxXCrI=; h=From:To:Cc:Subject:Date:Message-Id; b=us3WBlDYCkby1GwL0lgD68eNMx9xkUFd67RscmMhaP2nbGiubNV1yuOa/UHHbNChG+xR27+DVGGOmvHsGfFoZFWrRwbBF/uzbBzezin1dt+KhzL3Ch76KPAng8MwJv+JpJ4286L++lnXzbAQPrHC16KmyACCPFx9ujQllknaEwY= 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=sTzif/MS; 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 40FFA20B74C0; Tue, 27 Feb 2024 11:10:43 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 40FFA20B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1709061043; bh=dHXV9Ly1sQdf88TxoYBnR+fTtJ69EeUYd8QJVu9nB3c=; h=From:To:Cc:Subject:Date:From; b=sTzif/MSkVNv8hfb34KLtstgLFoccFhLMRoDXk/yZE5pvXTry6feyZkczkwJtaWvu ncpE62+t9eMoOR7SqoK8Cj36Iz68+nnABl2HN5ONUG8D+cM2TomaEwFj6HpqeBdxla s5yrQZrXcIKNHr25Nk0B3EuNEAoSQrIbP0iEb0Pg= From: Allen Pais To: tj@kernel.org Cc: jiangshanlai@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v2] workqueue: Introduce from_work() helper for cleaner callback declarations Date: Tue, 27 Feb 2024 19:10:37 +0000 Message-Id: <20240227191037.5839-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: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792081080287570385 X-GMAIL-MSGID: 1792081080287570385 To streamline the transition from tasklets to worqueues, a new helper function, from_work(), is introduced. This helper, inspired by existing from_() patterns, utilizes container_of() and eliminates the redundancy of declaring variable types, leading to more concise and readable code. The modified code snippet demonstrates the enhanced clarity achieved with from_wq(): void callback(struct work_struct *w) { - struct some_data_structure *local = container_of(w, struct some_data_structure, work); + struct some_data_structure *local = from_work(local, w, work); This change aims to facilitate a smoother transition and uphold code quality standards. Based on: git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git disable_work-v3 Signed-off-by: Allen Pais --- include/linux/workqueue.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index 7710cd52f7f0..aedfb81f9c49 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -527,6 +527,9 @@ alloc_workqueue(const char *fmt, unsigned int flags, int max_active, ...); #define create_singlethread_workqueue(name) \ alloc_ordered_workqueue("%s", __WQ_LEGACY | WQ_MEM_RECLAIM, name) +#define from_work(var, callback_work, work_fieldname) \ + container_of(callback_work, typeof(*var), work_fieldname) + extern void destroy_workqueue(struct workqueue_struct *wq); struct workqueue_attrs *alloc_workqueue_attrs(void);