public inbox for linuxppc-dev@ozlabs.org
 help / color / mirror / Atom feed
From: Shrikanth Hegde <sshegde@linux.ibm.com>
To: Yury Norov <ynorov@nvidia.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>, Nam Cao <namcao@linutronix.de>,
	"Jiri Slaby (SUSE)" <jirislaby@kernel.org>,
	Kees Cook <kees@kernel.org>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] powerpc/xive: rework xive_find_target_in_mask()
Date: Tue, 31 Mar 2026 08:29:02 +0530	[thread overview]
Message-ID: <dc0c5eff-a55a-4673-806c-00da1177dfea@linux.ibm.com> (raw)
In-Reply-To: <acqtJ2WUkg0ZtiHE@yury>

Hi Yury,

On 3/30/26 10:34 PM, Yury Norov wrote:
> On Sun, Mar 29, 2026 at 02:43:27PM +0530, Shrikanth Hegde wrote:
>> Hi Yury.
>>
>> On 3/19/26 9:06 AM, Yury Norov wrote:
>>> Switch the function to using modern cpumask API and drop most of the
>>> housekeeping code.
>>>
>>> Notice, if first >= nr_cpu_ids, for_each_cpu_wrap() iterator behaves just
>>> like for_each_cpu(), i.e. begins from 0. So even if WARN_ON() is triggered,
>>> no special handling is needed.
>>>
>>> Signed-off-by: Yury Norov <ynorov@nvidia.com>
>>> ---
>>>    arch/powerpc/sysdev/xive/common.c | 31 ++++++-------------------------
>>>    1 file changed, 6 insertions(+), 25 deletions(-)
>>>
>>> diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
>>> index e91ec9036ad8..4e05f678e171 100644
>>> --- a/arch/powerpc/sysdev/xive/common.c
>>> +++ b/arch/powerpc/sysdev/xive/common.c
>>> @@ -548,40 +548,21 @@ static void xive_dec_target_count(int cpu)
>>>    static int xive_find_target_in_mask(const struct cpumask *mask,
>>>    				    unsigned int fuzz)
>>>    {
>>> -	int cpu, first, num, i;
>>> +	int cpu, first;
>>>    	/* Pick up a starting point CPU in the mask based on  fuzz */
>>> -	num = cpumask_weight(mask);
>>> -	first = fuzz % num;
>>> -
>>> -	/* Locate it */
>>> -	cpu = cpumask_first(mask);
>>> -	for (i = 0; i < first && cpu < nr_cpu_ids; i++)
>>> -		cpu = cpumask_next(cpu, mask);
>>> -
>>> -	/* Sanity check */
>>> -	if (WARN_ON(cpu >= nr_cpu_ids))
>>> -		cpu = cpumask_first(cpu_online_mask);
>>> -
>>> -	/* Remember first one to handle wrap-around */
>>> -	first = cpu;
>>> +	fuzz %= cpumask_weight(mask);
>>> +	first = cpumask_nth(fuzz, mask);
>>> +	WARN_ON(first >= nr_cpu_ids);
>>>    	/*
>>>    	 * Now go through the entire mask until we find a valid
>>>    	 * target.
>>>    	 */
>>> -	do {
>>> -		/*
>>> -		 * We re-check online as the fallback case passes us
>>> -		 * an untested affinity mask
>>> -		 */
>>> +	for_each_cpu_wrap(cpu, mask, first) {
>>>    		if (cpu_online(cpu) && xive_try_pick_target(cpu))
>>>    			return cpu;
>>> -		cpu = cpumask_next(cpu, mask);
>>> -		/* Wrap around */
>>> -		if (cpu >= nr_cpu_ids)
>>> -			cpu = cpumask_first(mask);
>>> -	} while (cpu != first);
>>> +	}
>>>    	return -1;
>>>    }
>>
>> Only concern i have, (which could potentially leads to while(1) loop
>> today if it), is if mask is empty. atleast for_each_cpu_wrap will not
>> be a while(1) loop.
>>
>> So, IMO this is better than what we have today.
>>
>> nit: maybe a good to add a WARN_ON(cpu >= nr_cpu_ids) in the end.
>>
>> Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>
>   
> The iterator of for_each_cpu() is always >= nr_cpu_ids when it exits the
> loop because it's the exit condition. If you want to warn user before
> returning -1, just do __WARN().

Ok.

It might take a while a while to send the next version out since i am
working on getting the next version of that paravirt series out soon.



  reply	other threads:[~2026-03-31  2:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-19  3:36 [PATCH 0/2] powerpc/xive: rework xive_find_target_in_mask() Yury Norov
2026-03-19  3:36 ` [PATCH 1/2] Revert "powerpc/xive: Fix the size of the cpumask used in xive_find_target_in_mask()" Yury Norov
2026-03-20  5:57   ` Mukesh Kumar Chaurasiya
2026-03-19  3:36 ` [PATCH 2/2] powerpc/xive: rework xive_find_target_in_mask() Yury Norov
2026-03-29  9:13   ` Shrikanth Hegde
2026-03-30 17:04     ` Yury Norov
2026-03-31  2:59       ` Shrikanth Hegde [this message]
2026-03-31  5:30         ` Madhavan Srinivasan
2026-03-20  6:01 ` [PATCH 0/2] " Mukesh Kumar Chaurasiya
2026-04-08  4:29 ` Madhavan Srinivasan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dc0c5eff-a55a-4673-806c-00da1177dfea@linux.ibm.com \
    --to=sshegde@linux.ibm.com \
    --cc=chleroy@kernel.org \
    --cc=jirislaby@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=namcao@linutronix.de \
    --cc=npiggin@gmail.com \
    --cc=tglx@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=ynorov@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox