From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932457AbbFEAFk (ORCPT ); Thu, 4 Jun 2015 20:05:40 -0400 Received: from mga14.intel.com ([192.55.52.115]:11325 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752187AbbFEACx (ORCPT ); Thu, 4 Jun 2015 20:02:53 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,555,1427785200"; d="scan'208";a="502988110" From: Vikas Shivappa To: linux-kernel@vger.kernel.org Cc: vikas.shivappa@intel.com, x86@kernel.org, hpa@zytor.com, tglx@linutronix.de, mingo@kernel.org, tj@kernel.org, peterz@infradead.org, matt.fleming@intel.com, will.auld@intel.com, kanaka.d.juvva@intel.com, vikas.shivappa@linux.intel.com Subject: [PATCH 01/10] cpumask: Introduce cpumask_any_online_but Date: Thu, 4 Jun 2015 17:01:28 -0700 Message-Id: <1433462497-27087-2-git-send-email-vikas.shivappa@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1433462497-27087-1-git-send-email-vikas.shivappa@linux.intel.com> References: <1433462497-27087-1-git-send-email-vikas.shivappa@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is currently no cpumask helper function to pick a "random" cpu from a mask which is also online. cpumask_any_online_but() does that which is similar to cpumask_any_but() but also returns a cpu that is online. Signed-off-by: Vikas Shivappa --- include/linux/cpumask.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 27e285b..f2d7e8a 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -548,6 +548,24 @@ static inline void cpumask_copy(struct cpumask *dstp, #define cpumask_of(cpu) (get_cpu_mask(cpu)) /** + * cpumask_any_online_but - return a "random" and online cpu in a cpumask, + * but not this one + * @mask: the input mask to search + * @cpu: the cpu to ignore + * + * Returns >= nr_cpu_ids if no cpus set. +*/ +static inline unsigned int cpumask_any_online_but(const struct cpumask *mask, + unsigned int cpu) +{ + cpumask_t tmp; + + cpumask_and(&tmp, cpu_online_mask, mask); + cpumask_clear_cpu(cpu, &tmp); + return cpumask_any(&tmp); +} + +/** * cpumask_parse_user - extract a cpumask from a user string * @buf: the buffer to extract from * @len: the length of the buffer -- 1.9.1