Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp395880pxu; Tue, 6 Oct 2020 08:57:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEZ4qbiR+xnkl9W30EiS0DazMYbs8ifeh7BcnLP2xIC2T5uAdHG/bHSSwHtskTGv/Z2Beu X-Received: by 2002:a17:906:ad87:: with SMTP id la7mr147405ejb.85.1601999850519; Tue, 06 Oct 2020 08:57:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601999850; cv=none; d=google.com; s=arc-20160816; b=QvS1Y9Cp4aojfS35Y49iFpen0MsunHgjYxfHlai/Z3NtuY4tJgDOsLzXbxkDxelAhY V5J5YJiZCbccEIOjcAsM1a7Vpu1HFnFYQqgDqRN6zJQMFVogcm54LHvX0KwjjIIc1Hm4 K50HwNkCDdH418k/yIvoCyD9k8ucKYgafMR1mOo+hj7yUxE3z/BKKR8bKS/ZfmT10Gwg W/FMo2O/CxyQpar7pPQJEcLCdvQT5UZwjc68wbv0soG5pZfuWNFg6jaOEqr1CnDAQGXn 1/TwZnGRpA6vA7d/azm+/akMvroHPzP/eWZZPyaga5STm0W/JH7bpQedfl5kWwQDndGB jTUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=6Nn8EKpCjh+p6UQk9kj8oX2LPU7uWw7zEBBunpior+s=; b=02y6sqpBf8S9/qfD7PRb0ZDsKwbLVFUtDEKXIC4/aqRbE7eYOqhZKJwd7FdzetkUDO ssc83yvbZ2FZ+VOMN5HjDxxSXZntFet8syWx8q2P9D9vzv1jP56BVZaqhShbe1vBK1L7 oS8vIh14U4LiEZ1DqDfkUEgw8OZOU8XspL7nkqPowKxODQr0eE2Hop76j4IH5je7jSaN P32W9mJT9Fcsca74WnOVlUl7erV3kS9P/ZBmP6QQQq/AkdATYyUYqGsqoTi4NgvAq5AS 9fHH3Za21ZOt766/uw449koANwt2jzwRbk2MgOi+juN8T9/Q5KWwXA3j2z0hpBO/3HAY 4log== 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 b6si2801597ejb.204.2020.10.06.08.57.07; Tue, 06 Oct 2020 08:57:30 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726064AbgJFPzd (ORCPT + 99 others); Tue, 6 Oct 2020 11:55:33 -0400 Received: from foss.arm.com ([217.140.110.172]:50822 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725769AbgJFPzd (ORCPT ); Tue, 6 Oct 2020 11:55:33 -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 4393411B3; Tue, 6 Oct 2020 08:55:32 -0700 (PDT) Received: from e107158-lin.cambridge.arm.com (e107158-lin.cambridge.arm.com [10.1.195.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 43F3F3F66B; Tue, 6 Oct 2020 08:55:30 -0700 (PDT) Date: Tue, 6 Oct 2020 16:55:27 +0100 From: Qais Yousef To: Peter Zijlstra Cc: tglx@linutronix.de, mingo@kernel.org, linux-kernel@vger.kernel.org, bigeasy@linutronix.de, swood@redhat.com, valentin.schneider@arm.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vincent.donnefort@arm.com, tj@kernel.org Subject: Re: [PATCH -v2 12/17] sched,rt: Use cpumask_any*_distribute() Message-ID: <20201006155527.w6jck2rgk64t45wm@e107158-lin.cambridge.arm.com> References: <20201005145717.346020688@infradead.org> <20201005150922.156231026@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201005150922.156231026@infradead.org> User-Agent: NeoMutt/20171215 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/05/20 16:57, Peter Zijlstra wrote: > Replace a bunch of cpumask_any*() instances with > cpumask_any*_distribute(), by injecting this little bit of random in > cpu selection, we reduce the chance two competing balance operations > working off the same lowest_mask pick the same CPU. > > Signed-off-by: Peter Zijlstra (Intel) > --- > include/linux/cpumask.h | 6 ++++++ > kernel/sched/cpupri.c | 4 ++-- > kernel/sched/deadline.c | 2 +- > kernel/sched/rt.c | 6 +++--- > lib/cpumask.c | 18 ++++++++++++++++++ > 5 files changed, 30 insertions(+), 6 deletions(-) > [...] > --- a/kernel/sched/rt.c > +++ b/kernel/sched/rt.c > @@ -1752,8 +1752,8 @@ static int find_lowest_rq(struct task_st > return this_cpu; > } > > - best_cpu = cpumask_first_and(lowest_mask, > - sched_domain_span(sd)); > + best_cpu = cpumask_any_and_distribute(lowest_mask, > + sched_domain_span(sd)); I guess I should have done this 6 months ago and just got done with it :) 20200414150556.10920-1-qais.yousef@arm.com > if (best_cpu < nr_cpu_ids) { > rcu_read_unlock(); > return best_cpu; > @@ -1770,7 +1770,7 @@ static int find_lowest_rq(struct task_st > if (this_cpu != -1) > return this_cpu; > > - cpu = cpumask_any(lowest_mask); > + cpu = cpumask_any_distribute(lowest_mask); > if (cpu < nr_cpu_ids) > return cpu; > > --- a/lib/cpumask.c > +++ b/lib/cpumask.c > @@ -267,3 +267,21 @@ int cpumask_any_and_distribute(const str > return next; > } > EXPORT_SYMBOL(cpumask_any_and_distribute); > + > +int cpumask_any_distribute(const struct cpumask *srcp) > +{ > + int next, prev; > + > + /* NOTE: our first selection will skip 0. */ > + prev = __this_cpu_read(distribute_cpu_mask_prev); We had a discussion then that __this_cpu*() variant assumes preemption being disabled and it's safer to use this_cpu*() variant instead. Still holds true here? Thanks -- Qais Yousef > + > + next = cpumask_next(prev, srcp); > + if (next >= nr_cpu_ids) > + next = cpumask_first(srcp); > + > + if (next < nr_cpu_ids) > + __this_cpu_write(distribute_cpu_mask_prev, next); > + > + return next; > +} > +EXPORT_SYMBOL(cpumask_any_distribute); > >