From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77D1C1953BA for ; Fri, 23 Aug 2024 20:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724446174; cv=none; b=HvwWQQtLcAw0vCkFLcFLcenQr/xQpC+2DJxyRm0Speq7EVXLJxttZJgYsK4crqBpw4GVbwVbKBjcZxNBzINs/SJI2zyO3qbGumoYSArxU0w4Sm+uLk+BH8uhMWFCJC9z9FHqxMohBzDKS+pIHnv3cHfavM1Tzu7pK7MWh0tDPVo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724446174; c=relaxed/simple; bh=fkYApqLOliW+Q8396E7qo7Gv6YIt7/8l+N5wYKTXeRs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Dbf63Mh6/y3QzmbjROHg3tEjal33bn5DKctwQEcTkNC6NL+Yo91PkldeE+dWhl/Hgwfrh/aJle27yKLXpfHhGpWjnrYTlMfnWGYSG7oWriEcAM99dNKkIIldYeDfs6ms+5F3LNrY1FBeoKnmeMgPkjzD9DTOXlaNDpK1WLsBtWs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=T/oDff3n; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="T/oDff3n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1724446170; bh=fkYApqLOliW+Q8396E7qo7Gv6YIt7/8l+N5wYKTXeRs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=T/oDff3n9QEwwbT2kyBE9WqoilqxyvEYLJ64Gf0QZtNvfWDqqzGUwAGz4r7pQep4X QX2NmFwLYAUxKzG7vSUbyhoCf7BGBidTi/djwPZJwAjb+243ahGISuUCTeqQeAo07J 24W+UNZgmdUb2BYdTzl1eWXa1MQN0VSmL40JdQNRzDUGy3yWM0WMznFBEku0nzwtxZ sIetRTHVZdsJwORo2ugYYj8apUl6YzF1bZTm9FWppMxtQ8rAMyjNdZGAA44wnLkDpm rMDKGKYIxvPOlpWe3C8Ucd7rO7zREvL2JbPew+DdzVbgTLVZ2FGjgNGJISYhcHYcCe e5cEFdjJticmQ== Received: from [IPV6:2606:6d00:100:4000:b243:804e:3bbd:91c9] (unknown [IPv6:2606:6d00:100:4000:b243:804e:3bbd:91c9]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4WrByL0hw5z1J6g; Fri, 23 Aug 2024 16:49:30 -0400 (EDT) Message-ID: Date: Fri, 23 Aug 2024 16:49:02 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v1 3/6] cpumask: Implement cpumask_{first,next}_{nor,andnot} To: Yury Norov Cc: Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org, Valentin Schneider , Mel Gorman , Steven Rostedt , Vincent Guittot , Dietmar Eggemann , Ben Segall , Rasmus Villemoes , Shuah Khan References: <20240823185946.418340-1-mathieu.desnoyers@efficios.com> <20240823185946.418340-4-mathieu.desnoyers@efficios.com> From: Mathieu Desnoyers Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024-08-23 21:18, Yury Norov wrote: > On Fri, Aug 23, 2024 at 02:59:43PM -0400, Mathieu Desnoyers wrote: >> Allow finding the first or next bit within two input cpumasks which is >> either: >> >> - both zero and zero, >> - respectively one and zero. >> >> Signed-off-by: Mathieu Desnoyers >> Cc: Yury Norov >> Cc: Rasmus Villemoes >> --- >> Changes since v0: >> - Rename "notandnot" to "nor". >> - Use __always_inline. >> --- >> include/linux/cpumask.h | 60 +++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 60 insertions(+) >> >> diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h >> index 23686bed441d..5573e75c13ec 100644 >> --- a/include/linux/cpumask.h >> +++ b/include/linux/cpumask.h >> @@ -204,6 +204,32 @@ unsigned int cpumask_first_and_and(const struct cpumask *srcp1, >> cpumask_bits(srcp3), small_cpumask_bits); >> } >> >> +/** >> + * cpumask_first_andnot - return the first cpu from *srcp1 & ~*srcp2 >> + * @src1p: the first input >> + * @src2p: the second input >> + * >> + * Returns >= nr_cpu_ids if no cpus match in both. >> + */ >> +static __always_inline >> +unsigned int cpumask_first_andnot(const struct cpumask *srcp1, const struct cpumask *srcp2) >> +{ >> + return find_first_andnot_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits); > > > Here should be a small_cpumask_bits. This is better optimized for > NR_CPUS < BITS_PER_LONG. Will fix the 4 instances here for next round. Thanks, Mathieu > >> +} >> + >> +/** >> + * cpumask_first_nor - return the first cpu from ~(*srcp1 | *srcp2) >> + * @src1p: the first input >> + * @src2p: the second input >> + * >> + * Returns >= nr_cpu_ids if no cpus match in both. >> + */ >> +static __always_inline >> +unsigned int cpumask_first_nor(const struct cpumask *srcp1, const struct cpumask *srcp2) >> +{ >> + return find_first_nor_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits); >> +} >> + >> /** >> * cpumask_last - get the last CPU in a cpumask >> * @srcp: - the cpumask pointer >> @@ -246,6 +272,40 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp) >> return find_next_zero_bit(cpumask_bits(srcp), small_cpumask_bits, n+1); >> } >> >> +/** >> + * cpumask_next_andnot - return the next cpu from *srcp1 & ~*srcp2 >> + * @n: the cpu prior to the place to search (ie. return will be > @n) >> + * @src1p: the first input >> + * @src2p: the second input >> + * >> + * Returns >= nr_cpu_ids if no cpus match in both. >> + */ >> +static __always_inline >> +unsigned int cpumask_next_andnot(int n, const struct cpumask *srcp1, const struct cpumask *srcp2) >> +{ >> + /* -1 is a legal arg here. */ >> + if (n != -1) >> + cpumask_check(n); >> + return find_next_andnot_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits, n+1); >> +} >> + >> +/** >> + * cpumask_next_nor - return the next cpu from ~(*srcp1 | *srcp2) >> + * @n: the cpu prior to the place to search (ie. return will be > @n) >> + * @src1p: the first input >> + * @src2p: the second input >> + * >> + * Returns >= nr_cpu_ids if no cpus match in both. >> + */ >> +static __always_inline >> +unsigned int cpumask_next_nor(int n, const struct cpumask *srcp1, const struct cpumask *srcp2) >> +{ >> + /* -1 is a legal arg here. */ >> + if (n != -1) >> + cpumask_check(n); >> + return find_next_nor_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits, n+1); >> +} >> + >> #if NR_CPUS == 1 >> /* Uniprocessor: there is only one valid CPU */ >> static inline unsigned int cpumask_local_spread(unsigned int i, int node) >> -- >> 2.39.2 -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com