Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp593727ybz; Wed, 15 Apr 2020 14:45:43 -0700 (PDT) X-Google-Smtp-Source: APiQypJaoxzplgr0L4P/JDOWFuPOyvonlFgIv+lOFN6fqDkEDLRcZoR71N6i3g7WDhBzS/N4ZHaV X-Received: by 2002:aa7:d0cf:: with SMTP id u15mr16197300edo.233.1586987143061; Wed, 15 Apr 2020 14:45:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586987143; cv=none; d=google.com; s=arc-20160816; b=JCK/z1HRXC20ZLZ9HuLYktihPUebeX6oVtb790UYXBGrNlJWuUagBmRvI/pJOJu9ei zWVTeL0tCmZizMspO+KG06HFZz2wBpWNhBIoHg0VdIcLx9zhkRWMyhLqJIe9Om31qwfH Wy/RS0CpS7Pr2FYctdECgOUZU6OV0dC3oLZiTCO5EVZDyrYJVnOA1Kob9AFTxr4SxAC7 L5VGIDPC40Wzc5OVhjc5kI8AFvWmfmtMDJkk7v2Ni7niJ5QDZe1ODoOLEr8WyH4/QlKW b3neZkY8/75pdOHPVDmG95OjRJ+vDi69HqpHM4MYJSFni7I1LLZMiZEgNkfRhCAbG4Q6 weYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=/b8eRcYg3AVpYVU6HMtZLMBC3jwKf9IUSV9lUe7fb9w=; b=lRdM5i1ZViTGdRw5G1ujmdxpJB3iRDe4PcCsu13mmKYvURkpkX0FkCxX4f76zEMuMy eoKtoTE/NhrgFfkJa5pV4ShjuD4cFjYGZuJoKhVCiXOcGYsUHFb+11PUkVjFHbq8Efdp /gsWqxK25YfvsNErMqeNn16OfinGMXYMMTNPG4lndmQGbZ53ERJ3ZlPqgOJMvsTjdGTg 0/8QIkCAsTIHgeV+KOwNHgrLNkiJZZs5QilS5n9z5mC9v6ekmh1mB0OhadX7tUUFzP/7 UoLVBdN9EnuCVBG4Znt3dcBipgXZXnfsQciInZ6IVOvG1zggAL9GpLzDRa8CotiPyp6J pOtw== 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 u16si3961211edd.86.2020.04.15.14.45.19; Wed, 15 Apr 2020 14:45:43 -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 S2391351AbgDNQUD (ORCPT + 99 others); Tue, 14 Apr 2020 12:20:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:57656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391002AbgDNQUA (ORCPT ); Tue, 14 Apr 2020 12:20:00 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7708720678; Tue, 14 Apr 2020 16:19:58 +0000 (UTC) Date: Tue, 14 Apr 2020 12:19:56 -0400 From: Steven Rostedt To: Qais Yousef Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Andrew Morton , Thomas Gleixner , Yury Norov , Paul Turner , Alexey Dobriyan , Josh Don , Pavan Kondeti , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] cpumask: Make cpumask_any() truly random Message-ID: <20200414121956.3687d6e9@gandalf.local.home> In-Reply-To: <20200414150556.10920-3-qais.yousef@arm.com> References: <20200414150556.10920-1-qais.yousef@arm.com> <20200414150556.10920-3-qais.yousef@arm.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 14 Apr 2020 16:05:54 +0100 Qais Yousef wrote: > Commit 46a87b3851f0 ("sched/core: Distribute tasks within affinity masks") > added a new cpumask_any_and_distribute() which truly returns a random > cpu within the mask. > > Previous patch renamed the function to cpumask_any_and(), so that old > users can take advantage of the new randomness behavior. > > Build up on that, and let cpumask_any() truly random too by re-using the > logic from cpumask_any_and(). > > Signed-off-by: Qais Yousef > CC: Juri Lelli > CC: Vincent Guittot > CC: Dietmar Eggemann > CC: Steven Rostedt > CC: Ben Segall > CC: Mel Gorman > CC: Andrew Morton > CC: Thomas Gleixner > CC: Yury Norov > CC: Paul Turner > CC: Alexey Dobriyan > CC: Josh Don > CC: Pavan Kondeti > CC: linux-kernel@vger.kernel.org > --- > include/linux/cpumask.h | 14 ++++++-------- > lib/cpumask.c | 24 ++++++++++++++++++++++++ > 2 files changed, 30 insertions(+), 8 deletions(-) > > diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h > index e4d6d140a67c..7fb25d256043 100644 > --- a/include/linux/cpumask.h > +++ b/include/linux/cpumask.h > @@ -194,6 +194,11 @@ static inline unsigned int cpumask_local_spread(unsigned int i, int node) > return 0; > } > > +static inline int cpumask_any(const struct cpumask *src1p) > +{ > + return 0; > +} > + > static inline int cpumask_any_and(const struct cpumask *src1p, > const struct cpumask *src2p) > { > @@ -251,6 +256,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp) > int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *); > int cpumask_any_but(const struct cpumask *mask, unsigned int cpu); > unsigned int cpumask_local_spread(unsigned int i, int node); > +int cpumask_any(const struct cpumask *srcp); > int cpumask_any_and(const struct cpumask *src1p, const struct cpumask *src2p); > > /** > @@ -600,14 +606,6 @@ static inline void cpumask_copy(struct cpumask *dstp, > bitmap_copy(cpumask_bits(dstp), cpumask_bits(srcp), nr_cpumask_bits); > } > > -/** > - * cpumask_any - pick a "random" cpu from *srcp > - * @srcp: the input cpumask > - * > - * Returns >= nr_cpu_ids if no cpus set. > - */ > -#define cpumask_any(srcp) cpumask_first(srcp) > - > /** > * cpumask_first_and - return the first cpu from *srcp1 & *srcp2 > * @src1p: the first input > diff --git a/lib/cpumask.c b/lib/cpumask.c > index b527a153b023..bcac63e45374 100644 > --- a/lib/cpumask.c > +++ b/lib/cpumask.c > @@ -259,3 +259,27 @@ int cpumask_any_and(const struct cpumask *src1p, const struct cpumask *src2p) > return next; > } > EXPORT_SYMBOL(cpumask_any_and); > + > +/** > + * cpumask_any - pick a "random" cpu from *srcp > + * @srcp: the input cpumask > + * > + * Returns >= nr_cpu_ids if no cpus set. > + */ > +int cpumask_any(const struct cpumask *srcp) > +{ > + int next, prev; > + > + /* NOTE: our first selection will skip 0. */ > + prev = __this_cpu_read(distribute_cpu_mask_prev); > + > + 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); Do we care if this gets preempted and migrated to a new CPU where we read "prev" from one distribute_cpu_mask_prev on one CPU and write it to another CPU? -- Steve > + > + return next; > +} > +EXPORT_SYMBOL(cpumask_any);