mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Badole, Vishal" <vishal.badole@amd.com>
To: "Guo, Wangyang" <wangyang.guo@intel.com>,
	"tglx@kernel.org" <tglx@kernel.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "bp@alien8.de" <bp@alien8.de>,
	"Li, Tianyou" <tianyou.li@intel.com>,
	"tim.c.chen@linux.intel.com" <tim.c.chen@linux.intel.com>,
	"Liang, Dan" <dan.liang@intel.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH v7] lib/group_cpus: Snapshot cluster masks to keep grouping hotplug invariant
Date: Fri, 13 Nov 2026 18:57:49 +0530	[thread overview]
Message-ID: <56bbcaaa-32ec-447b-a0c4-42305b80ed07@amd.com> (raw)
In-Reply-To: <MW4PR11MB6982C90C849A81DBFEB95A7B92702@MW4PR11MB6982.namprd11.prod.outlook.com>


Hello Wangyang,
Thanks for reviewing this patch.

On 11/12/2026 7:50 AM, Guo, Wangyang wrote:
> On Wed, 11 Nov 2026 01:46:11, Vishal Badole <Vishal.Badole@amd.com> wrote:
>>   static int alloc_cluster_groups(unsigned int ncpus,
>>   				unsigned int ngroups,
>>   				struct cpumask *node_cpumask,
>> @@ -299,6 +380,9 @@ static int alloc_cluster_groups(unsigned int ncpus,
>>   	const struct cpumask **clusters;
>>   	struct node_groups *cluster_groups;
>>
>> +	if (!cluster_snapshot)
>> +		goto no_cluster;
>> +
>>   	cpumask_copy(msk, node_cpumask);
>>
>>   	/* Probe how many clusters in this node. */
>> @@ -307,7 +391,7 @@ static int alloc_cluster_groups(unsigned int ncpus,
>>   		if (cpu >= nr_cpu_ids)
>>   			break;
>>
>> -		cluster_mask = topology_cluster_cpumask(cpu);
>> +		cluster_mask = cluster_snapshot[cpu];
>>   		if (!cpumask_weight(cluster_mask))
>>   			goto no_cluster;
>>   		/* Clean out CPUs on the same cluster. */
>> @@ -322,7 +406,7 @@ static int alloc_cluster_groups(unsigned int ncpus,
>>   	/* Allocate memory based on cluster number. */
>>   	clusters = kzalloc_objs(*clusters, ncluster);
>>   	if (!clusters)
>> -		goto no_cluster;
>> +		return -ENOMEM;
>>   	cluster_groups = kzalloc_objs(struct node_groups, ncluster);
>>   	if (!cluster_groups)
>>   		goto fail_cluster_groups;
>> @@ -331,7 +415,7 @@ static int alloc_cluster_groups(unsigned int ncpus,
>>   	cpumask_copy(msk, node_cpumask);
>>   	for (n = 0; n < ncluster; n++) {
>>   		cpu = cpumask_first(msk);
>> -		cluster_mask = topology_cluster_cpumask(cpu);
>> +		cluster_mask = cluster_snapshot[cpu];
>>   		nc = cpumask_weight_and(cluster_mask, node_cpumask);
>>   		clusters[n] = cluster_mask;
>>   		cluster_groups[n].id = n;
>> @@ -347,6 +431,7 @@ static int alloc_cluster_groups(unsigned int ncpus,
>>
>>    fail_cluster_groups:
>>   	kfree(clusters);
>> +	return -ENOMEM;
>>    no_cluster:
>>   	return 0;
>>   }
>> @@ -354,9 +439,9 @@ static int alloc_cluster_groups(unsigned int ncpus,
>>   /*
>>    * Try group CPUs evenly for cluster locality within a NUMA node.
>>    *
>> - * Return: true if success, false otherwise.
>> + * Return: cluster count on success, 0 if inapplicable, or -ENOMEM on failure.
>>    */
>> -static bool __try_group_cluster_cpus(unsigned int ncpus,
>> +static int __try_group_cluster_cpus(unsigned int ncpus,
>>   				     unsigned int ngroups,
>>   				     struct cpumask *node_cpumask,
>>   				     struct cpumask *masks,
>> @@ -365,18 +450,17 @@ static bool __try_group_cluster_cpus(unsigned int ncpus,
>>   {
>>   	struct node_groups *cluster_groups;
>>   	const struct cpumask **clusters;
>> -	unsigned int ncluster;
>> -	bool ret = false;
>> +	int ncluster;
>>   	cpumask_var_t nmsk;
>>   	unsigned int i, nc;
> 
> If we could move "if (!cluster_snapshot)" from alloc_cluster_groups() to
> here, the unnecessary cpumask alloc/free could be avoid if snapshot if
> unavailable.
> 
Noted; I’ll address this in the next patch revision.

>>   	if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL))
>> -		goto fail_nmsk_alloc;
>> +		return -ENOMEM;
>>
>>   	ncluster = alloc_cluster_groups(ncpus, ngroups, node_cpumask, nmsk,
>>   					&clusters, &cluster_groups);
>>
>> -	if (ncluster == 0)
>> +	if (ncluster <= 0)
>>   		goto fail_no_clusters;
>>
>>   	for (i = 0; i < ncluster; i++) {
>> @@ -392,13 +476,11 @@ static bool __try_group_cluster_cpus(unsigned int ncpus,
>>   		assign_cpus_to_groups(nc, nmsk, nv, masks, curgrp, last_grp);
>>   	}
>>
>> -	ret = true;
>>   	kfree(cluster_groups);
>>   	kfree(clusters);
>>    fail_no_clusters:
>>   	free_cpumask_var(nmsk);
>> - fail_nmsk_alloc:
>> -	return ret;
>> +	return ncluster;
>>   }
>>


      reply	other threads:[~2026-11-13 13:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 17:45 Vishal Badole
2026-11-11  8:52 ` Andrew Morton
2026-11-12  2:20 ` Guo, Wangyang
2026-11-13 13:27   ` Badole, Vishal [this message]

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=56bbcaaa-32ec-447b-a0c4-42305b80ed07@amd.com \
    --to=vishal.badole@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=dan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@kernel.org \
    --cc=tianyou.li@intel.com \
    --cc=tim.c.chen@linux.intel.com \
    --cc=wangyang.guo@intel.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

all inboxes | Powered by JetHome®