Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp228076pxk; Fri, 11 Sep 2020 05:24:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5oia9Rx4OZubrOz7H7Fcug4qCPYExHWDf5E6GPYu7o9dNfJJ8r/lhnZOCmPQVcSXewjvD X-Received: by 2002:a17:906:4a19:: with SMTP id w25mr1693683eju.199.1599827041533; Fri, 11 Sep 2020 05:24:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599827041; cv=none; d=google.com; s=arc-20160816; b=Gu6932cOjdmmFQyw2qerEMEeErzmbSo6sM81r39SNpZlBVtJm+qOEYW5Tfm1PrkVUj 2eikAcKMGNs/OnOBr17ST0A4ixGt2wsChi9uCf0VOLALT5ylfXOPkXEcVbUCYUVQGR/F xD165ydfNhbLW8DWZiRbF0hrYRrb7RPVtGfsjdv1POUf55BvFcYv0rZtPhwwFn0g+LAx UuczPZ1L8sWpTrKM+X6slkwlYYO7yjXdPC+L5AmnQG0YQMriC3EONNs3AW+i1cPSjQth 6VXVp4Wn64uFPidGvFx6Z2eov/HUiS8Uq2gmol2urzm9LAlcu6Jg9cPQmgSlNFjadfct yPTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references; bh=0Rf7MydqodI2yaK69QDnudDXBWv5Afr7MLdxbbZR7Jg=; b=WX3si/cvJvGv17S7K5qPq+bt9s0/4VJIIDWKLD7ivKp4VyCEg6+x4Vg1jcLNnL+r/w cozVDVbFF9XAERAwy6ce6lHKIK9E9Xz+kZsduPxSNt5XdkcKQV2pmIPJhYXBn+xaRho4 Nf8X+oT8U5BIa+z4hj0P6f1jpQaozTtR7tLqxVfN1+gztChPzYowv/ztVLbcg2Rx65Da mI88TMTImWLs+FwxAYoI8HmFyNsgL4m4+VPsIwh83qcYUXDFHV1AfyxE7M+38joCEEe6 Bf59RP6LPJSuTTJGAiyU5CQrMmOpVBIjF0x+OR4lCxy45oIwQDhMm/9rFEU+V7kr6yrh F9IQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t17si1314100ejs.91.2020.09.11.05.23.38; Fri, 11 Sep 2020 05:24:01 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725880AbgIKMV7 (ORCPT + 99 others); Fri, 11 Sep 2020 08:21:59 -0400 Received: from foss.arm.com ([217.140.110.172]:33094 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725884AbgIKMRu (ORCPT ); Fri, 11 Sep 2020 08:17:50 -0400 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 99F7A113E; Fri, 11 Sep 2020 05:17:48 -0700 (PDT) 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 4A6333F68F; Fri, 11 Sep 2020 05:17:47 -0700 (PDT) References: <20200911081745.214686199@infradead.org> <20200911082536.528661716@infradead.org> User-agent: mu4e 0.9.17; emacs 26.3 From: Valentin Schneider To: Peter Zijlstra Cc: mingo@kernel.org, vincent.guittot@linaro.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bristot@redhat.com, swood@redhat.com, Vincent Donnefort Subject: Re: [PATCH 2/2] sched/hotplug: Ensure only per-cpu kthreads run during hotplug In-reply-to: <20200911082536.528661716@infradead.org> Date: Fri, 11 Sep 2020 13:17:45 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (+Cc VincentD, who's been looking at some of this) On 11/09/20 09:17, Peter Zijlstra wrote: > In preparation for migrate_disable(), make sure only per-cpu kthreads > are allowed to run on !active CPUs. > > This is ran (as one of the very first steps) from the cpu-hotplug > task which is a per-cpu kthread and completion of the hotplug > operation only requires such tasks. > > This contraint enables the migrate_disable() implementation to wait s/contraint/constraint/ > for completion of all migrate_disable regions on this CPU at hotplug > time without fear of any new ones starting. > > This replaces the unlikely(rq->balance_callbacks) test at the tail of > context_switch with an unlikely(rq->balance_work), the fast path is > not affected. > > Signed-off-by: Peter Zijlstra (Intel) > --- > kernel/sched/core.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++- > kernel/sched/sched.h | 5 ++ > 2 files changed, 106 insertions(+), 2 deletions(-) > > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -6836,6 +6849,87 @@ static void migrate_tasks(struct rq *dea > > rq->stop = stop; > } > + > +static int __balance_push_stop(void *arg) __balance_push_cpu_stop()? _cpu_stop() seems to be the usual suffix. > +{ > + struct task_struct *p = arg; > + struct rq *rq = this_rq(); > + struct rq_flags rf; > + int cpu; > + > + raw_spin_lock_irq(&p->pi_lock); > + rq_lock(rq, &rf); > + > + if (task_rq(p) == rq && task_on_rq_queued(p)) { > + cpu = select_fallback_rq(rq->cpu, p); > + rq = __migrate_task(rq, &rf, p, cpu); > + } > + > + rq_unlock(rq, &rf); > + raw_spin_unlock_irq(&p->pi_lock); > + > + put_task_struct(p); > + > + return 0; > +} > + > +static DEFINE_PER_CPU(struct cpu_stop_work, push_work); > + > +/* > + * Ensure we only run per-cpu kthreads once the CPU goes !active. > + */ > +static bool balance_push(struct rq *rq) > +{ > + struct task_struct *push_task = rq->curr; > + > + lockdep_assert_held(&rq->lock); > + SCHED_WARN_ON(rq->cpu != smp_processor_id()); > + > + /* > + * Both the cpu-hotplug and stop task are in this class and are > + * required to complete the hotplug process. Nit: s/class/case/? I can't not read "class" as "sched_class", and those two are *not* in the same sched_class, and confusion ensues. > + */ > + if (is_per_cpu_kthread(push_task)) > + return false; > + > + get_task_struct(push_task); > + /* > + * Temporarily drop rq->lock such that we can wake-up the stop task. > + * Both preemption and IRQs are still disabled. > + */ > + raw_spin_unlock(&rq->lock); > + stop_one_cpu_nowait(rq->cpu, __balance_push_stop, push_task, > + this_cpu_ptr(&push_work)); > + /* > + * At this point need_resched() is true and we'll take the loop in > + * schedule(). The next pick is obviously going to be the stop task > + * which is_per_cpu_kthread() and will push this task away. > + */ > + raw_spin_lock(&rq->lock); > + > + return true; > +} > + > @@ -6968,6 +7064,8 @@ int sched_cpu_deactivate(unsigned int cp > */ > synchronize_rcu(); > > + balance_push_set(cpu, true); > + IIUC this is going to make every subsequent finish_lock_switch() migrate the switched-to task if it isn't a pcpu kthread. So this is going to lead to a dance of switch_to() -> switch_to() -> switch_to() -> switch_to() ... Wouldn't it be better to batch all those in a migrate_tasks() sibling that skips pcpu kthreads? > #ifdef CONFIG_SCHED_SMT > /* > * When going down, decrement the number of cores with SMT present.