From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 7944248B381 for ; Tue, 5 May 2026 16:17:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777997834; cv=none; b=VUP7V5DHf52gAGa4M7FhLW3HWmLqosBr87o8Y9mt7wr1hoshNw8N+A0/ZFlpV54yZoPQf0Ani6rG40W+are9g7vffc3E98HtHj2WGnxlMgq/F90axbTVf9WFr6i3jamdGnmfskMSl/qgv3lpO0qPoWKXySC1bjcmLxWFDG9DbQE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777997834; c=relaxed/simple; bh=Y8t6evXuiYIEPgBAMbdxb4luVE7UVXeswhOFsG8e/dY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W2iJitO/C6aLStAJ1sreYW1uwgUlHE6YFFztohcQUfpGaArR63g2+Tatk3Qhva8/O0r+ZAiEdiTQGM/2g21rmJdaxopt1MsgqodOk5Fd6zkCwKqmc0HiJVINOLUp6q0Akv5QI4op+sHQDqPmoBjyD/dkaxecaDTmBy649vttCQk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=CZlJc+Xt; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="CZlJc+Xt" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-488b0046078so47454205e9.1 for ; Tue, 05 May 2026 09:17:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1777997828; x=1778602628; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9hBwLPBEABIssiJEAR9YdFBTOOOzaUf1al7knzdrrA0=; b=CZlJc+XtxcFgixdfUnazDdk7JkTQELir7c24f+EMylSgj4ox3rpTQww3Sz4lCp42sL SsCtry2jH33iPmSJIKbNGCBx4ZAwpdKM+tk7KdP+yMuommy8In0hTzNXhT2BuuiZC/Nk zZN4cb5hE0yxphCKPrgMKfiEineCffycCvkNu/OtZO8wbkmBftn/zRO4/ySp3IQXRAYq 0C8jbcXhqbDo179GuiV+my8azOd9obkfZnM42gJPrMXaFPye3E4YzipMm/6y9O30SPz7 Ex7Iur3kmg8lsvpWdF85Vu+c83dhXFEyabGyjoASraQwpnR14FCyoaXaYKqdoY4dNqtt 5jpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777997828; x=1778602628; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=9hBwLPBEABIssiJEAR9YdFBTOOOzaUf1al7knzdrrA0=; b=hK+g9OHSsQkS3O618/Lf58FT8/rDaYh4tKE8sVeZjzH5589HRAR+N0PV9yTN3TbQ8+ cs8YGZeUGUm7eHHfdutVUvuk9G3Bjt6BxnW+6EIbQRYPHX/q23F91zm6+Ilk8s+Huicz XSM/zcQNz2cvWSBosFuXqsGd2W2hxDBrjEDlnJnxgscMZTF/Y3vwU0SiYs/k7w1F4ySH Qg6ouyd4o/q6J8pmvgI6H10vR6JIVoCooEvQmbhWZPXOiGKEX8qHiZLvAWjyZ8unQUwL Jnyn340taQqM/Dwosc/V6HCAwQcD6YjriOQHR5xX4cLsRvFz72eXj0mybaD6tCqi4jv/ ukgA== X-Gm-Message-State: AOJu0Yy8lMAxMbh3CQPPH30CepTkhoZGe9s1Jh28OjNnwlsXvNRh8Iwk TDQ9OfmP/bn0YSaB5/lQD9eXiTjqL3/VVleCJiwTnwp6Rc8dAZcL2GrVEyw+DAVfWUCWfcsTbXw v1aiI0zM= X-Gm-Gg: AeBDievD0cx5HxBMYiGAGS8VAB/gycSXHkMI6tQegMcix+wnojzYnF2Y3oAL21R3P5A RWrVBCuAyw8vvlPGi6R92ejmYQg/3xPu2LhNz46lPOxUDjjOO+hb3TwG9ZyYJHyEdc2AU+zrGTb wzArr+ZqQFHrkIVTlQa8v93taQ4hygwvjz8+s3pzuKlk3iSGmulDLk0HCBGLsC2qDbGlVp7yeT1 N9mR7T5PVXbqYSVAOi64Jlxl9sqV2ZYGHm7le7V8CJ0jS4/GeVjiuF29kZOEY6nPJ3HPkeKs9om hDvEuxD9wkKp4YCP/2u7Yerb9H0KEn5oH0hsntxdYjSX26FlOUGHH1lwSlzQyPUVWxGOXT4V+Gb KkcGMf1uPxff4iTltB0jlBTam1zvfBJgK540a/QkNMCaZ1Wl//Wx3zjHbiRFh+qKO4wIrWro3Ll sW5jYQhbptvF66ONi4g1acoHreOPV3swS6eacSPG+ossvRQvgC+cL/NjKaxcgCeuRDguM0 X-Received: by 2002:a05:600c:530c:b0:488:c744:49b with SMTP id 5b1f17b1804b1-48d107465a9mr126160025e9.7.1777997828337; Tue, 05 May 2026 09:17:08 -0700 (PDT) Received: from localhost.localdomain ([2a00:6d43:105:c401:e307:1a37:2e76:ce91]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a82301adesm400997535e9.10.2026.05.05.09.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 09:17:07 -0700 (PDT) From: Marco Crivellari To: linux-kernel@vger.kernel.org Cc: Tejun Heo , Lai Jiangshan , Frederic Weisbecker , Sebastian Andrzej Siewior , Marco Crivellari , Michal Hocko Subject: [RFC PATCH 2/2] workqueue: Add WQ_PREFER_PERCPU and system_prefer_percpu_wq Date: Tue, 5 May 2026 18:16:58 +0200 Message-ID: <20260505161658.401998-3-marco.crivellari@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260505161658.401998-1-marco.crivellari@suse.com> References: <20260505161658.401998-1-marco.crivellari@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit There may be situations where local execution is not strictly needed for correctness, but it is preferred for performance gains. The Workqueue API currently do not distinguish between these two instances. So add WQ_PREFER_PERCPU and system_prefer_percpu_wq, so that it would be the first choice for workload who don't strictly need local execution for correctness but only to maintain locality. Link: https://lore.kernel.org/all/20250221112003.1dSuoGyc@linutronix.de/ Suggested-by: Tejun Heo Signed-off-by: Marco Crivellari --- include/linux/workqueue.h | 7 +++++++ kernel/workqueue.c | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index f46379d937c9..be65df3dea5b 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -404,6 +404,7 @@ enum wq_flags { */ WQ_POWER_EFFICIENT = 1 << 7, WQ_PERCPU = 1 << 8, /* bound to a specific cpu */ + WQ_PREFER_PERCPU = 1 << 9, /* prefer local cpu, but it doesn't require it */ __WQ_DESTROYING = 1 << 15, /* internal: workqueue is destroying */ __WQ_DRAINING = 1 << 16, /* internal: workqueue is draining */ @@ -460,6 +461,9 @@ enum wq_consts { * * system_bh[_highpri]_wq are convenience interface to softirq. BH work items * are executed in the queueing CPU's BH context in the queueing order. + * + * system_prefer_percpu_wq is for work items which prefer to be local but + * doesn't require it */ extern struct workqueue_struct *system_wq; /* use system_percpu_wq, this will be removed */ extern struct workqueue_struct *system_percpu_wq; @@ -473,6 +477,7 @@ extern struct workqueue_struct *system_freezable_power_efficient_wq; extern struct workqueue_struct *system_bh_wq; extern struct workqueue_struct *system_bh_highpri_wq; extern struct workqueue_struct *system_dfl_long_wq; +extern struct workqueue_struct *system_prefer_percpu_wq; void workqueue_softirq_action(bool highpri); void workqueue_softirq_dead(unsigned int cpu); @@ -873,6 +878,8 @@ extern void __warn_flushing_systemwide_wq(void) _wq == system_freezable_wq) || \ (__builtin_constant_p(_wq == system_power_efficient_wq) && \ _wq == system_power_efficient_wq) || \ + (__builtin_constant_p(_wq == system_prefer_percpu_wq) && \ + _wq == system_prefer_percpu_wq) || \ (__builtin_constant_p(_wq == system_freezable_power_efficient_wq) && \ _wq == system_freezable_power_efficient_wq)) \ __warn_flushing_systemwide_wq(); \ diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 5f747f241a5f..abba222a2d58 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -545,6 +545,8 @@ struct workqueue_struct *system_bh_highpri_wq; EXPORT_SYMBOL_GPL(system_bh_highpri_wq); struct workqueue_struct *system_dfl_long_wq __ro_after_init; EXPORT_SYMBOL_GPL(system_dfl_long_wq); +struct workqueue_struct *system_prefer_percpu_wq __ro_after_init; +EXPORT_SYMBOL_GPL(system_prefer_percpu_wq); static int worker_thread(void *__worker); static void workqueue_sysfs_unregister(struct workqueue_struct *wq); @@ -8029,11 +8031,13 @@ void __init workqueue_init_early(void) system_bh_highpri_wq = alloc_workqueue("events_bh_highpri", WQ_BH | WQ_HIGHPRI | WQ_PERCPU, 0); system_dfl_long_wq = alloc_workqueue("events_dfl_long", WQ_UNBOUND, WQ_MAX_ACTIVE); + system_prefer_percpu_wq = alloc_workqueue("events_prefer_percpu", WQ_PREFER_PERCPU, 0); BUG_ON(!system_wq || !system_percpu_wq|| !system_highpri_wq || !system_long_wq || !system_unbound_wq || !system_freezable_wq || !system_dfl_wq || !system_power_efficient_wq || !system_freezable_power_efficient_wq || - !system_bh_wq || !system_bh_highpri_wq || !system_dfl_long_wq); + !system_bh_wq || !system_bh_highpri_wq || !system_dfl_long_wq || + !system_prefer_percpu_wq); } static void __init wq_cpu_intensive_thresh_init(void) -- 2.53.0