From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 239ABC2BB48 for ; Tue, 15 Dec 2020 15:05:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D748622525 for ; Tue, 15 Dec 2020 15:05:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729873AbgLOPEu (ORCPT ); Tue, 15 Dec 2020 10:04:50 -0500 Received: from foss.arm.com ([217.140.110.172]:45676 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729739AbgLOPEP (ORCPT ); Tue, 15 Dec 2020 10:04:15 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BDA8E1FB; Tue, 15 Dec 2020 07:03:26 -0800 (PST) Received: from e113632-lin (e113632-lin.cambridge.arm.com [10.1.194.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9FBCB3F66B; Tue, 15 Dec 2020 07:03:25 -0800 (PST) References: <20201214155457.3430-1-jiangshanlai@gmail.com> <20201214155457.3430-11-jiangshanlai@gmail.com> User-agent: mu4e 0.9.17; emacs 26.3 From: Valentin Schneider To: Lai Jiangshan Cc: linux-kernel@vger.kernel.org, Lai Jiangshan , Qian Cai , Peter Zijlstra , Vincent Donnefort , Tejun Heo Subject: Re: [PATCH 10/10] workqueue: Fix affinity of kworkers when attaching into pool In-reply-to: <20201214155457.3430-11-jiangshanlai@gmail.com> Date: Tue, 15 Dec 2020 15:03:20 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14/12/20 15:54, Lai Jiangshan wrote: > @@ -1848,11 +1848,11 @@ static void worker_attach_to_pool(struct worker *worker, > { > mutex_lock(&wq_pool_attach_mutex); > > - /* > - * set_cpus_allowed_ptr() will fail if the cpumask doesn't have any > - * online CPUs. It'll be re-applied when any of the CPUs come up. > - */ > - set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); > + /* Is there any cpu in pool->attrs->cpumask online? */ > + if (cpumask_any_and(pool->attrs->cpumask, wq_online_cpumask) < nr_cpu_ids) if (cpumask_intersects(pool->attrs->cpumask, wq_online_cpumask)) > + WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask) < 0); > + else > + WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, cpu_possible_mask) < 0); So for that late-spawned per-CPU kworker case: the outgoing CPU should have already been cleared from wq_online_cpumask, so it gets its affinity reset to the possible mask and the subsequent wakeup will ensure it's put on an active CPU. Seems alright to me. > > /* > * The wq_pool_attach_mutex ensures %POOL_DISASSOCIATED remains