Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2111854rbb; Tue, 27 Feb 2024 10:58:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUNH4eHns+mCcmHwINGwL8pfCcOY3Z8kAN2mVAeOOyKqyL5FZTnf0Ds810FFVNjPCDT8Kp0EhUUY98aUWtjhm2rYXujuG3b4i2CHPCMtQ== X-Google-Smtp-Source: AGHT+IFKBumFLbQQnY0J7G6l2HHcNhCjkYMQt1qZ1Tjj+ABU3pDoYJnvRhuBCkgNB01ZfPsXEDXa X-Received: by 2002:a81:b1c2:0:b0:607:8306:6b0f with SMTP id p185-20020a81b1c2000000b0060783066b0fmr3038982ywh.18.1709060309592; Tue, 27 Feb 2024 10:58:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709060309; cv=pass; d=google.com; s=arc-20160816; b=UfG8iAN8NRJErTSp3fgWE19QKEP6zsmC74S36w7QvrmRyacKAB8ow+kK5C91BqZq48 HibgI7n3j+tbPrKt7IywuDq/L9RbxxKmKCwOvNTJ0TUoFhd9Pub7oOfyzIe9WTN3/H+h q1hPdqB/YdnNV/x9PRyw0K9lfnd/Zy8xhFPMCIhbaV52JyeuG1mJJcA+Hs1cl/zj8VRZ rfz7JZWKLhM0tNHTCrJE/PnHvrRC0yoYkbZABtROT8y8ZWLKp4lgijxK3V1zCM/ymLPm hra6Me+zuJ+1U6uNCZVeIzZwxY9P534/T90zjhvwbeeeVaxl5WY1YY2WwTfTJYTIdYFm dnog== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83873-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j8-20020ac874c8000000b0042e8d55fcdcsi3797107qtr.92.2024.02.27.10.58.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 10:58:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83873-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=@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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83873-linux.lists.archive=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 711371C285FC for ; Tue, 27 Feb 2024 18:57:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2AD5E524CA; Tue, 27 Feb 2024 18:56:36 +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: 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); -- 2.17.1