linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: John Garry <john.garry@huawei.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Jens Axboe <axboe@kernel.dk>,
	linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
	Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH V3 5/7] genirq/affinity: move group_cpus_evenly() into lib/
Date: Thu, 30 Sep 2021 08:05:02 +0800	[thread overview]
Message-ID: <YVT/Lki9OaRa8OCR@T590> (raw)
In-Reply-To: <74bcc75e-0b68-1d6b-b7f6-4681ec754257@huawei.com>

On Wed, Sep 29, 2021 at 03:40:44PM +0100, John Garry wrote:
> 
> > +/**
> > + * group_cpus_evenly - Group all CPUs evenly per NUMA/CPU locality
> > + * @numgrps: number of groups
> > + *
> > + * Return: cpumask array if successful, NULL otherwise. And each element
> > + * includes CPUs assigned to this group
> > + *
> > + * Try to put close CPUs from viewpoint of CPU and NUMA locality into
> > + * same group, and run two-stage grouping:
> > + *	1) allocate present CPUs on these groups evenly first
> > + *	2) allocate other possible CPUs on these groups evenly
> > + *
> > + * We guarantee in the resulted grouping that all CPUs are covered, and
> > + * no same CPU is assigned to different groups
> 
> nit: I'd have "no same CPU is assigned to multiple groups"

OK

> 
> > + */
> > +struct cpumask *group_cpus_evenly(unsigned int numgrps)
> 
> nit: The name group_cpus_evenly() would imply an action on some cpus, when
> it's just calculating some masks - I think "masks" should be at least
> included in the name

Naming is always the hard part in reviewing, I think cpu is more
readable, maybe group_all_cpus_evenly()?

> 
> > +{
> > +	unsigned int curgrp = 0, nr_present = 0, nr_others = 0;
> > +	cpumask_var_t *node_to_cpumask;
> > +	cpumask_var_t nmsk, npresmsk;
> > +	int ret = -ENOMEM;
> > +	struct cpumask *masks = NULL;
> > +
> > +	if (!zalloc_cpumask_var(&nmsk, GFP_KERNEL))
> > +		return NULL;
> > +
> > +	if (!zalloc_cpumask_var(&npresmsk, GFP_KERNEL))
> > +		goto fail_nmsk;
> > +
> > +	node_to_cpumask = alloc_node_to_cpumask();
> > +	if (!node_to_cpumask)
> > +		goto fail_npresmsk;
> > +
> > +	masks = kcalloc(numgrps, sizeof(*masks), GFP_KERNEL);
> > +	if (!masks)
> > +		goto fail_node_to_cpumask;
> > +
> > +	/* Stabilize the cpumasks */
> > +	cpus_read_lock();
> > +	build_node_to_cpumask(node_to_cpumask);
> > +
> > +	/* grouping present CPUs first */
> > +	ret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,
> > +				  cpu_present_mask, nmsk, masks);
> > +	if (ret < 0)
> > +		goto fail_build_affinity;
> > +	nr_present = ret;
> > +
> > +	/*
> > +	 * Allocate non present CPUs starting from the next group to be
> > +	 * handled. If the grouping of present CPUs already exhausted the
> > +	 * group space, assign the non present CPUs to the already
> > +	 * allocated out groups.
> > +	 */
> > +	if (nr_present >= numgrps)
> > +		curgrp = 0;
> > +	else
> > +		curgrp = nr_present;
> > +	cpumask_andnot(npresmsk, cpu_possible_mask, cpu_present_mask);
> > +	ret = __group_cpus_evenly(curgrp, numgrps, node_to_cpumask,
> > +				  npresmsk, nmsk, masks);
> > +	if (ret >= 0)
> > +		nr_others = ret;
> > +
> > + fail_build_affinity:
> 
> nit: Strange that success path goes through "fail" labels. Current code is
> this way, so feel free to ignore.

I'd rather not change current behavior in this patches.

> 
> > +	cpus_read_unlock();
> > +
> > +	if (ret >= 0)
> > +		WARN_ON(nr_present + nr_others < numgrps);
> > +
> > + fail_node_to_cpumask:
> > +	free_node_to_cpumask(node_to_cpumask);
> > +
> > + fail_npresmsk:
> > +	free_cpumask_var(npresmsk);
> > +
> > + fail_nmsk:
> > +	free_cpumask_var(nmsk);
> > +	if (ret < 0) {
> > +		kfree(masks);
> > +		return NULL;
> > +	}
> > +	return masks;
> > +}
> > +EXPORT_SYMBOL_GPL(group_cpus_evenly);
> 
> Are there any users which are available as modules? As I see, the only users
> are blk-mq-cpumap.c and irq/affinity.c, which I guess aren't available as
> modules.

Yeah, so far only two built-in users, I think it is fine to start with
not exporting the symbols, will change to this way in next version.


Thanks, 
Ming


  reply	other threads:[~2021-09-30  0:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28  0:55 [PATCH V3 0/7] genirq/affinity: abstract new API from managed irq affinity spread Ming Lei
2021-09-28  0:55 ` [PATCH V3 1/7] genirq/affinity: remove the 'firstvec' parameter from irq_build_affinity_masks Ming Lei
2021-09-28  0:55 ` [PATCH V3 2/7] genirq/affinity: pass affinity managed mask array to irq_build_affinity_masks Ming Lei
2021-09-28  0:55 ` [PATCH V3 3/7] genirq/affinity: don't pass irq_affinity_desc " Ming Lei
2021-09-28  0:55 ` [PATCH V3 4/7] genirq/affinity: rename irq_build_affinity_masks as group_cpus_evenly Ming Lei
2021-09-28  0:55 ` [PATCH V3 5/7] genirq/affinity: move group_cpus_evenly() into lib/ Ming Lei
2021-09-28  5:26   ` Christoph Hellwig
2021-09-29 14:40   ` John Garry
2021-09-30  0:05     ` Ming Lei [this message]
2021-09-28  0:55 ` [PATCH V3 6/7] lib/group_cpus: allow to group cpus in case of !CONFIG_SMP Ming Lei
2021-09-28  5:27   ` Christoph Hellwig
2021-09-28  0:55 ` [PATCH V3 7/7] blk-mq: build default queue map via group_cpus_evenly() Ming Lei
2021-09-28  5:27   ` Christoph Hellwig

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=YVT/Lki9OaRa8OCR@T590 \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=john.garry@huawei.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).