Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp591792ybz; Wed, 15 Apr 2020 14:43:09 -0700 (PDT) X-Google-Smtp-Source: APiQypIaeHNAK202F/wvbJXvRsrqgeLNZ6AvsrAdJJT66EKw+7QuPLOMOoth+yNv8HpwGoF7OMnw X-Received: by 2002:a17:906:809:: with SMTP id e9mr6713066ejd.81.1586986988959; Wed, 15 Apr 2020 14:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586986988; cv=none; d=google.com; s=arc-20160816; b=Z+I8MAHGM2hlQMp+m0CSZm1lK8tVdIX8Hk01/KJh6Lou8rltnIzxXH89Ii0ieOMeiQ Nvn1gFabaEnBzEaXDPb44MY+6rrRklc7EIbPiqW6SZHNPq3hBBGoulRgLS3ytDeZ9wuM hG+arDRy2JLTvWWL8WpdK0LM9dvqQ4p6JqzutzNVR3eAn7I2TAGANIMvLR+aZawlkfQQ q1i+olo/D39QN0DkwLbfFj4rG5eua3l0lnyNPzGSbjhMZtD5PIJUmh9U9GyHU+9rpGpI evp/8/Dyb/+DbSXRJsubXXvsg7CDV2PL6eXQKYpT4Vpaoh3m6WHj3KlgZsQXRi0SkAvr YI3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=uu9dqzGvJIyvM2VJohiV87RYUmvuY2cvGENqB8KzYMU=; b=SDdKmWnMl0U3KbEQFuZE5n9X5tBxVhwkqAKVjD5swrUkCZBor6t84hxYK1YRymf4So SIacoWAHIjSx4vmfOj8aMsvzcPgtQGNxEyx98H78q/YLH4XGo9AaNMDyTWo7EYPkhalc p4IL8M3KKx64E/4IL8kTOlmd4kEzZ1JC6RGmaVlV1DZfk6mGDg+VJkIYs8wbud37EfaP O5FQeyqtg6qXJDejsgST5PTYYUXyBS/fST3OlSdxg8ya7ndwUl7sQ1638BeLttiqSmud 5HML0Wvbq/k1YZBv+NkRh7aU7XH8KOLq5953p4AAyV0vZyvHn63sfkdQnCKSKZ9t7T6K xqEA== 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 b7si8181727edy.494.2020.04.15.14.42.45; Wed, 15 Apr 2020 14:43:08 -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 S2436683AbgDNPHJ (ORCPT + 99 others); Tue, 14 Apr 2020 11:07:09 -0400 Received: from foss.arm.com ([217.140.110.172]:57662 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729370AbgDNPGq (ORCPT ); Tue, 14 Apr 2020 11:06:46 -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 CB45DC14; Tue, 14 Apr 2020 08:06:45 -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 B026F3F73D; Tue, 14 Apr 2020 08:06:43 -0700 (PDT) From: Qais Yousef To: Ingo Molnar , Peter Zijlstra Cc: Qais Yousef , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Andrew Morton , Thomas Gleixner , Yury Norov , Paul Turner , Alexey Dobriyan , Josh Don , Pavan Kondeti , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] cpumask: Make cpumask_any() truly random Date: Tue, 14 Apr 2020 16:05:54 +0100 Message-Id: <20200414150556.10920-3-qais.yousef@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200414150556.10920-1-qais.yousef@arm.com> References: <20200414150556.10920-1-qais.yousef@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); + + return next; +} +EXPORT_SYMBOL(cpumask_any); -- 2.17.1