Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2928547pxb; Tue, 12 Jan 2021 01:59:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVt8qigecxanT1GUhgiW4gH0NLqy1eQNIG+0yr7NUgR5GmCoIWDaaDNH73rRfYbAU5KK62 X-Received: by 2002:a17:906:b306:: with SMTP id n6mr2585316ejz.473.1610445585429; Tue, 12 Jan 2021 01:59:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610445585; cv=none; d=google.com; s=arc-20160816; b=ZUJo3LPSlwBIZOjDNSs1XdFVGog2EourCBmAieZpedYijnBuFhUsxFyTm71xbZUCD1 mJNfXE4f5cZq5Ot5gk4UFFLf6uZ+XCad/W4v7//KZ+WNZOxsyMl0NbBgeMbIg0GktQtt 6AbiY/2L/CVi1wM/kUIChLqbxBe7OdyXU721KVw2npflxBZ8pwjo+bHXkpLvluw7mjWF qGGOKwFGzfkpeabdpziwvcmQ3Ut9v+WUveDgInyUBOzdEUm+aaZ7FllTHRXQn26Hql+6 gi4ra57o464hxDwnQHkIhJl6L0dK+i3CXpBDIV+uAVjobO9V49/hUok/MqgBobEhX0WY l/8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from; bh=fKV+od2p8CA/MRp/UfR6wlQzM7zx6RS+ip88ynW+fcQ=; b=uPM/Tlz1NjBNPMqn/OKUbT+ziqInF9PoH4Tr+hwS/JQjUvStq+k9GJO4g1D7+OW+6d xoySoLaBneuQWkGZfslOsIgpbh79QcATaqhtTMF7jLdl7wwBK9cbcN8e2GhP5IXWFwCA 2MwHUPFm4dpAPWwn84JTpolVkimbgakB6BxpBdDrrv0x/L/9UHBcTkY2IFyMJ7Zhcwv8 XGsT6tjpMTcmlRraCkaZNUaRlPRW/yW4t3YhsWXviE90H5UBdGZBjuENiHx9zQJBY2FN hPFlsspR+0MYLImushjeF5VXZ4Zv8NHuxUOiqISmtY+HhhatquP58KNUkN7knTbw4M2C 3tGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q4si658027eji.465.2021.01.12.01.59.21; Tue, 12 Jan 2021 01:59:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390099AbhALAYi (ORCPT + 99 others); Mon, 11 Jan 2021 19:24:38 -0500 Received: from foss.arm.com ([217.140.110.172]:37320 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390769AbhAKWsc (ORCPT ); Mon, 11 Jan 2021 17:48:32 -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 89F1E31B; Mon, 11 Jan 2021 14:47:46 -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 028F23F70D; Mon, 11 Jan 2021 14:47:44 -0800 (PST) From: Valentin Schneider To: Peter Zijlstra Cc: Thomas Gleixner , Lai Jiangshan , linux-kernel@vger.kernel.org, Qian Cai , Vincent Donnefort , Dexuan Cui , Lai Jiangshan , Paul McKenney , Vincent Guittot , Steven Rostedt , Jens Axboe Subject: Re: [PATCH -tip V3 0/8] workqueue: break affinity initiatively In-Reply-To: References: <20201226025117.2770-1-jiangshanlai@gmail.com> <87o8hv7pnd.fsf@nanos.tec.linutronix.de> User-Agent: Notmuch/0.21 (http://notmuchmail.org) Emacs/26.3 (x86_64-pc-linux-gnu) Date: Mon, 11 Jan 2021 22:47:39 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/01/21 21:23, Peter Zijlstra wrote: > On Mon, Jan 11, 2021 at 07:21:06PM +0000, Valentin Schneider wrote: >> I'm less fond of the workqueue pcpu flag toggling, but it gets us what >> we want: allow those threads to run on !active CPUs during online, but >> move them away before !online during offline. >> >> Before I get ahead of myself, do we *actually* require that first part >> for workqueue kthreads? I'm thinking (raise alarm) we could try another >> approach of making them pcpu kthreads that don't abide by the !active && >> online rule. > > There is code that really requires percpu workqueues to be percpu. Such > code will flush the percpu workqueue on hotplug and never hit the unbind > scenario. > > Other code uses those same percpu workqueues and only uses it as a > performance enhancer, it likes things to stay local, but if not, meh.. > And these users are what got us the weird ass semantics of workqueue. > > Sadly workqueue itself can't tell them apart. > Oh well... FWIW now that I've unconfused myself, that does look okay. >> > --- >> > include/linux/kthread.h | 3 +++ >> > kernel/kthread.c | 25 ++++++++++++++++++++++++- >> > kernel/sched/core.c | 2 +- >> > kernel/sched/sched.h | 4 ++-- >> > kernel/smpboot.c | 1 + >> > kernel/workqueue.c | 12 +++++++++--- >> > 6 files changed, 40 insertions(+), 7 deletions(-) >> > >> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c >> > index 15d2562118d1..e71f9e44789e 100644 >> > --- a/kernel/sched/core.c >> > +++ b/kernel/sched/core.c >> > @@ -7277,7 +7277,7 @@ static void balance_push(struct rq *rq) >> > * Both the cpu-hotplug and stop task are in this case and are >> > * required to complete the hotplug process. >> > */ >> > - if (is_per_cpu_kthread(push_task) || is_migration_disabled(push_task)) { >> > + if (rq->idle == push_task || is_per_cpu_kthread(push_task) || is_migration_disabled(push_task)) { >> >> I take it the p->set_child_tid thing you were complaining about on IRC >> is what prevents us from having the idle task seen as a pcpu kthread? > > Yes, to to_kthread() only tests PF_KTHREAD and then assumes > p->set_child_tid points to struct kthread, _however_ init_task has > PF_KTHREAD set, but a NULL ->set_child_tid. > > This then means the idle thread for the boot CPU will malfunction with > to_kthread() and will certainly not have KTHREAD_IS_PER_CPU set. Per > construction (fork_idle()) none of the other idle threads will have that > cured either. > > For fun and giggles, init (pid-1) will have PF_KTHREAD set for a while > as well, until we exec /sbin/init. > > Anyway, idle will fail kthread_is_per_cpu(), and hence without the > above, we'll try and push the idle task away, which results in much > fail. > Quite! >> Also, shouldn't this be done before the previous set_cpus_allowed_ptr() >> call (in the same function)? > > Don't see why; we need nr_cpus_allowed == 1, so best do it after, right? > Duh, yes. >> That is, if we patch >> __set_cpus_allowed_ptr() to also use kthread_is_per_cpu(). > > That seems wrong. > It is, apologies. >> > list_add_tail(&worker->node, &pool->workers); >> > worker->pool = pool;