linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Song Bao Hua (Barry Song)" <song.bao.hua@hisilicon.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: "andriy.shevchenko@linux.intel.com" 
	<andriy.shevchenko@linux.intel.com>,
	"yury.norov@gmail.com" <yury.norov@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"dave.hansen@intel.com" <dave.hansen@intel.com>,
	"linux@rasmusvillemoes.dk" <linux@rasmusvillemoes.dk>,
	"rafael@kernel.org" <rafael@kernel.org>,
	"rdunlap@infradead.org" <rdunlap@infradead.org>,
	"agordeev@linux.ibm.com" <agordeev@linux.ibm.com>,
	"sbrivio@redhat.com" <sbrivio@redhat.com>,
	"jianpeng.ma@intel.com" <jianpeng.ma@intel.com>,
	"valentin.schneider@arm.com" <valentin.schneider@arm.com>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"bristot@redhat.com" <bristot@redhat.com>,
	"guodong.xu@linaro.org" <guodong.xu@linaro.org>,
	tangchengchang <tangchengchang@huawei.com>,
	"Zengtao (B)" <prime.zeng@hisilicon.com>,
	yangyicong <yangyicong@huawei.com>,
	"tim.c.chen@linux.intel.com" <tim.c.chen@linux.intel.com>,
	Linuxarm <linuxarm@huawei.com>,
	"tiantao (H)" <tiantao6@hisilicon.com>,
	"Jonathan Cameron" <jonathan.cameron@huawei.com>
Subject: RE: [PATCH v9 1/5] cpumask: introduce cpumap_print_list/bitmask_to_buf to support large bitmask and list
Date: Tue, 10 Aug 2021 13:24:49 +0000	[thread overview]
Message-ID: <6e04c09ce1714b35bd740fbf6a9ce654@hisilicon.com> (raw)
In-Reply-To: YQ03ixksDJyVwCEv@kroah.com



> -----Original Message-----
> From: Song Bao Hua (Barry Song)
> Sent: Saturday, August 7, 2021 7:39 AM
> To: 'Greg KH' <gregkh@linuxfoundation.org>
> Cc: andriy.shevchenko@linux.intel.com; yury.norov@gmail.com;
> linux-kernel@vger.kernel.org; akpm@linux-foundation.org;
> dave.hansen@intel.com; linux@rasmusvillemoes.dk; rafael@kernel.org;
> rdunlap@infradead.org; agordeev@linux.ibm.com; sbrivio@redhat.com;
> jianpeng.ma@intel.com; valentin.schneider@arm.com; peterz@infradead.org;
> bristot@redhat.com; guodong.xu@linaro.org; tangchengchang
> <tangchengchang@huawei.com>; Zengtao (B) <prime.zeng@hisilicon.com>;
> yangyicong <yangyicong@huawei.com>; tim.c.chen@linux.intel.com; Linuxarm
> <linuxarm@huawei.com>; tiantao (H) <tiantao6@hisilicon.com>; Jonathan Cameron
> <jonathan.cameron@huawei.com>
> Subject: RE: [PATCH v9 1/5] cpumask: introduce
> cpumap_print_list/bitmask_to_buf to support large bitmask and list
> 
> 
> 
> > -----Original Message-----
> > From: Greg KH [mailto:gregkh@linuxfoundation.org]
> > Sent: Saturday, August 7, 2021 1:22 AM
> > To: Song Bao Hua (Barry Song) <song.bao.hua@hisilicon.com>
> > Cc: andriy.shevchenko@linux.intel.com; yury.norov@gmail.com;
> > linux-kernel@vger.kernel.org; akpm@linux-foundation.org;
> > dave.hansen@intel.com; linux@rasmusvillemoes.dk; rafael@kernel.org;
> > rdunlap@infradead.org; agordeev@linux.ibm.com; sbrivio@redhat.com;
> > jianpeng.ma@intel.com; valentin.schneider@arm.com; peterz@infradead.org;
> > bristot@redhat.com; guodong.xu@linaro.org; tangchengchang
> > <tangchengchang@huawei.com>; Zengtao (B) <prime.zeng@hisilicon.com>;
> > yangyicong <yangyicong@huawei.com>; tim.c.chen@linux.intel.com; Linuxarm
> > <linuxarm@huawei.com>; tiantao (H) <tiantao6@hisilicon.com>; Jonathan
> Cameron
> > <jonathan.cameron@huawei.com>
> > Subject: Re: [PATCH v9 1/5] cpumask: introduce
> > cpumap_print_list/bitmask_to_buf to support large bitmask and list
> >
> > On Fri, Aug 06, 2021 at 11:02:47PM +1200, Barry Song wrote:
> > > From: Tian Tao <tiantao6@hisilicon.com>
> > >
> > > The existing cpumap_print_to_pagebuf() is used by cpu topology and other
> > > drivers to export hexadecimal bitmask and decimal list to userspace by
> > > sysfs ABI.
> > >
> > > Right now, those drivers are using a normal attribute for this kind of
> > > ABIs. A normal attribute typically has show entry as below:
> > >
> > > static ssize_t example_dev_show(struct device *dev,
> > >                 struct device_attribute *attr, char *buf)
> > > {
> > > 	...
> > > 	return cpumap_print_to_pagebuf(true, buf, &pmu_mmdc->cpu);
> > > }
> > > show entry of attribute has no offset and count parameters and this
> > > means the file is limited to one page only.
> > >
> > > cpumap_print_to_pagebuf() API works terribly well for this kind of
> > > normal attribute with buf parameter and without offset, count:
> > >
> > > static inline ssize_t
> > > cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask)
> > > {
> > > 	return bitmap_print_to_pagebuf(list, buf, cpumask_bits(mask),
> > > 				       nr_cpu_ids);
> > > }
> > >
> > > The problem is once we have many cpus, we have a chance to make bitmask
> > > or list more than one page. Especially for list, it could be as complex
> > > as 0,3,5,7,9,...... We have no simple way to know it exact size.
> > >
> > > It turns out bin_attribute is a way to break this limit. bin_attribute
> > > has show entry as below:
> > > static ssize_t
> > > example_bin_attribute_show(struct file *filp, struct kobject *kobj,
> > >              struct bin_attribute *attr, char *buf,
> > >              loff_t offset, size_t count)
> > > {
> > > 	...
> > > }
> > >
> > > With the new offset and count parameters, this makes sysfs ABI be able
> > > to support file size more than one page. For example, offset could be
> > > >= 4096.
> > >
> > > This patch introduces cpumap_print_bitmask/list_to_buf() and their bitmap
> > > infrastructure bitmap_print_bitmask/list_to_buf() so that those drivers
> > > can move to bin_attribute to support large bitmask and list. At the same
> > > time, we have to pass those corresponding parameters such as offset, count
> > > from bin_attribute to this new API.
> > >
> > > Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
> > > Cc: Andrew Morton <akpm@linux-foundation.org>
> > > Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > Cc: Randy Dunlap <rdunlap@infradead.org>
> > > Cc: Stefano Brivio <sbrivio@redhat.com>
> > > Cc: Alexander Gordeev <agordeev@linux.ibm.com>
> > > Cc: "Ma, Jianpeng" <jianpeng.ma@intel.com>
> > > Cc: Yury Norov <yury.norov@gmail.com>
> > > Cc: Valentin Schneider <valentin.schneider@arm.com>
> > > Cc: Peter Zijlstra <peterz@infradead.org>
> > > Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
> > > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > > Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
> > > ---
> > >  include/linux/bitmap.h  |   6 +++
> > >  include/linux/cpumask.h |  38 +++++++++++++++
> > >  lib/bitmap.c            | 103 ++++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 147 insertions(+)
> > >
> > > diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
> > > index a36cfcec4e77..37f36dad18bd 100644
> > > --- a/include/linux/bitmap.h
> > > +++ b/include/linux/bitmap.h
> > > @@ -227,6 +227,12 @@ unsigned int bitmap_ord_to_pos(const unsigned long
> > *bitmap, unsigned int ord, un
> > >  int bitmap_print_to_pagebuf(bool list, char *buf,
> > >  				   const unsigned long *maskp, int nmaskbits);
> > >
> > > +extern int bitmap_print_bitmask_to_buf(char *buf, const unsigned long
> > *maskp,
> > > +				      int nmaskbits, loff_t off, size_t count);
> > > +
> > > +extern int bitmap_print_list_to_buf(char *buf, const unsigned long *maskp,
> > > +				      int nmaskbits, loff_t off, size_t count);
> > > +
> >
> > Why are you adding bitmap_print_list_to_buf() when no one uses it in
> > this patch series?
> >
> > Did I miss it somewhere?
> 
> Yes. It is used in every patch except the last one from Yury
> which is only extending comment.
> 
> drivers/base/topology.c:
> +static ssize_t name##_list_read(struct file *file, struct kobject *kobj,	\
> +				struct bin_attribute *attr, char *buf,		\
> +				loff_t off, size_t count)			\
> +{										\
> +	struct device *dev = kobj_to_dev(kobj);					\
> +										\
> +	return cpumap_print_list_to_buf(buf, topology_##mask(dev->id),		\
> +					off, count);				\
>  }
> 
> 
> drivers/base/node.c:
> +static inline ssize_t cpulist_read(struct file *file, struct kobject *kobj,
> +				   struct bin_attribute *attr, char *buf,
> +				   loff_t off, size_t count)
>  {
> -	...
> +	cpumask_and(mask, cpumask_of_node(node_dev->dev.id), cpu_online_mask);
> +	n = cpumap_print_list_to_buf(buf, mask, off, count);
> +	free_cpumask_var(mask);
> 
> >

And correspondingly, Linux has bitmask and list ABIs for cpus, eg:

root@ubuntu:/sys/devices/system/cpu/cpu0/topology# cat core_siblings
ff
root@ubuntu:/sys/devices/system/cpu/cpu0/topology# cat core_siblings_list
0-7

and for nodes, eg:
root@ubuntu:/sys/devices/system/node/node0# cat cpumap
ff
root@ubuntu:/sys/devices/system/node/node0# cat cpulist
0-7


> > thanks,
> >
> > greg k-h
> 

Thanks
Barry


  parent reply	other threads:[~2021-08-10 13:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06 11:02 [PATCH v9 0/5] use bin_attribute to break the size limitation of cpumap ABI Barry Song
2021-08-06 11:02 ` [PATCH v9 1/5] cpumask: introduce cpumap_print_list/bitmask_to_buf to support large bitmask and list Barry Song
2021-08-06 13:22   ` Greg KH
2021-08-06 19:39     ` Song Bao Hua (Barry Song)
2021-08-10 13:24     ` Song Bao Hua (Barry Song) [this message]
2021-08-06 11:02 ` [PATCH v9 2/5] lib: test_bitmap: add bitmap_print_bitmask/list_to_buf test cases Barry Song
2021-08-06 17:51   ` kernel test robot
2021-08-06 18:04     ` Andy Shevchenko
2021-08-06 19:47       ` Max Filippov
2021-08-06 11:02 ` [PATCH v9 3/5] topology: use bin_attribute to break the size limitation of cpumap ABI Barry Song
2021-08-06 11:02 ` [PATCH v9 4/5] drivers/base/node.c: " Barry Song
2021-08-06 11:02 ` [PATCH v9 5/5] bitmap: extend comment to bitmap_print_bitmask/list_to_buf Barry Song
2021-08-12  4:44 ` [PATCH v9 0/5] use bin_attribute to break the size limitation of cpumap ABI Barry Song
2021-08-13  8:32   ` Greg KH

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=6e04c09ce1714b35bd740fbf6a9ce654@hisilicon.com \
    --to=song.bao.hua@hisilicon.com \
    --cc=agordeev@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bristot@redhat.com \
    --cc=dave.hansen@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=guodong.xu@linaro.org \
    --cc=jianpeng.ma@intel.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=linuxarm@huawei.com \
    --cc=peterz@infradead.org \
    --cc=prime.zeng@hisilicon.com \
    --cc=rafael@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=sbrivio@redhat.com \
    --cc=tangchengchang@huawei.com \
    --cc=tiantao6@hisilicon.com \
    --cc=tim.c.chen@linux.intel.com \
    --cc=valentin.schneider@arm.com \
    --cc=yangyicong@huawei.com \
    --cc=yury.norov@gmail.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;
as well as URLs for NNTP newsgroup(s).