From patchwork Tue Feb 27 18:56:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Allen Pais X-Patchwork-Id: 207382 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2901839dyb; Tue, 27 Feb 2024 10:58:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVV/Ge8rQQMs95FBdcBDjI+sVPjbPx3NJu7MKnFK78XUX7Ca5v5QTnLKZb0xjWKmdB7BiDaV2OO9UEo3p3ZLu+0B46dOg== X-Google-Smtp-Source: AGHT+IGIlQqMb2gC9aYLojm8EuyxZW18N2v7gZxjCnutmvcyncJv4ZQuOmR+nuVsAJDdLeW0thGe X-Received: by 2002:a81:83c5:0:b0:607:834f:b4c4 with SMTP id t188-20020a8183c5000000b00607834fb4c4mr2963929ywf.29.1709060317658; Tue, 27 Feb 2024 10:58:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709060317; cv=pass; d=google.com; s=arc-20160816; b=VT5696Dz72AKJCIqyUBZN4uG2XLejicYa6vRE2q8NiLVu5NLafPydVl/HDiBTiw/bq rYWFrXh+1OSlD+LB+0Ukx9sGsiqQR2oOid9XLgU+NjUDaUyROoDWdk1BjtNp9G4viH1Q Zw/OK+sT0xI1YYH50WNNbffFelUTJ2v9o2lIxHGDARBFQyz2SdlTre4jDcb/vsDCVp2e 87FUanKkaChLuTFy2EeB4fzbq7M81XiFJuCXP9yCcHErxOK10GKJ/XYpB44ZBbug/AeS ae/qUUqfd42aiDN4T5FqL6w7kFKoXLcryD8Bt9NFOOeXHiypAGo8FBQdPE7ShgHjSwUZ glDw== 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=hjIha+4EvMKgXzvaM61LnapsbtfyQREDPod4KbKYY3E=; fh=jl9/kuBYo3Gn2BBz0zErs9UPETds1jCciNhLeHU6Px8=; b=uvdbPBsxp2n7oHoTsaBmUS2h59yWJYYfBwjWKeQyABdQBnz/mGJKZ7Po90pz9zDe2C xTvhPtmqIQIdUfqoN9wkw37CQtutQ1dMZQGGb+Xc4XzkFVveLoP35GbGySJbzE97PXhh tA0cpevqspyYxLeFAv8Z0EzHvkyYZR+GOYE4ctFc9Mt0RO9JwOle9C8qZGow5WW5J3SK n09ZtHuvUM28Jc9gXPO6XC5aIH1aziWClb7HLcq+GIQBW/cyC7bpYVlm4GF/iHnmaNt/ 1+XwCkkMF+mvkft6zC6b3wMSTdQOI1LMRHbyE4yPVSmZk/9zo9TT5NRU63Jwax32T/1y f5pw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=jXlmAAsc; 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-83873-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83873-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. [147.75.199.223]) by mx.google.com with ESMTPS id g13-20020ac8480d000000b0042e6a4c0739si7736130qtq.668.2024.02.27.10.58.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:58:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83873-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=jXlmAAsc; 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-83873-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83873-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 858C51C25A5A for ; Tue, 27 Feb 2024 18:57:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E75E351C34; Tue, 27 Feb 2024 18:56:37 +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="jXlmAAsc" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E10651E894 for ; Tue, 27 Feb 2024 18:56:33 +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=1709060195; cv=none; b=qz4Rj+tvQSnhy2Upq1nTJYp8LGLQasCoaAScwUx3xkKR2KNm4tRaenRePrj6iFH9fMsA+1yKLFL9YzEx6CWHGZ4lMTkwpYvBeXQT8TMA7r9nT/FkUho0ZnIa4Ei6NS623FAb/d/adXtz1Wbv5g3ZxDHKDMyY+qenVt4XBOg1BAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709060195; c=relaxed/simple; bh=UXncBGwnse3Lf/ZpvQhF29fpzY+ggkT8z673ohmk6vw=; h=From:To:Cc:Subject:Date:Message-Id; b=Lg6GRMj3muvD2qIWfVTokCflL5mzYs2PUa55LuolzGpHutgrLMx5Jk1svtVe9eWN5xJfO3805eaojMQH+Ni3Ln+70feeTHjTWKGnIoRG3D/ni56N3PSD2QIpKz9g3gTF5BRz1yZL5fd5BJvubALb3rIfc42t83KcXZKazMc/plQ= 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=jXlmAAsc; 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 633D220B74C0; Tue, 27 Feb 2024 10:56:33 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 633D220B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1709060193; bh=hjIha+4EvMKgXzvaM61LnapsbtfyQREDPod4KbKYY3E=; h=From:To:Cc:Subject:Date:From; b=jXlmAAsc8rO+0m1Ed3UVOii7tOupyq550Yt5fAA42MAj6EK0+p8J43rMSITZPd6Fv zPnJZiLnk8dfkFF90Iujali54ySZzgdCigcvrBkWrKF31pWggyqpjH32XB+QLBhfIx 84A7i3CRhqx0LBJfqdqkwXE8SO6A9xKGVZ6cPU9g= From: Allen Pais To: tj@kernel.org Cc: jiangshanlai@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH] workqueue: Introduce from_wq() helper for cleaner callback declarations Date: Tue, 27 Feb 2024 18:56:28 +0000 Message-Id: <20240227185628.5336-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: 1792079631206530281 X-GMAIL-MSGID: 1792079631206530281 To streamline the transition from tasklets to worqueues, a new helper function, from_wq(), 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_wq(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..aa61009c6fd6 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_wq(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);