Re: [PATCH v5 1/3] cpumask: introduce cpumap_print_to_buf to support large bitmask and list

From: Andy Shevchenko
Date: Fri Jul 02 2021 - 06:07:28 EST


On Fri, Jul 02, 2021 at 09:25:57PM +1200, Barry Song wrote:
> From: Tian Tao <tiantao6@xxxxxxxxxxxxx>
>
> 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_to_buf() so that those drivers can
> move to bin_attribute to support large bitmask and list. In result,
> we have to pass the corresponding parameters from bin_attribute to this
> new API.

...

> +/**
> + * cpumap_print_to_buf - copies the cpumask into the buffer either
> + * as comma-separated list of cpus or hex values of cpumask;
> + * Typically used by bin_attribute to export cpumask bitmask and
> + * list ABI.

It can be split to

* cpumap_print_to_buf - copies the cpumask into the buffer

here...

> + * @list: indicates whether the cpumap must be list
> + * true: print in decimal list format
> + * fasle: print in hexadecimal bitmask format
> + * @mask: the cpumask to copy
> + * @buf: the buffer to copy into
> + * @off: in the string from which we are copying, We copy to @buf
> + * @count: the maximum number of bytes to print

..and

*
* The function copies the cpumask into the buffer either as comma-separated
* list of cpus or hex values of cpumask; Typically used by bin_attribute to
* export cpumask bitmask and list ABI.

here.

> + *
> + * Returns the length of how many bytes have been copied.
> + */

--
With Best Regards,
Andy Shevchenko