Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1409430pxv; Fri, 2 Jul 2021 03:09:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyS3nCLwyqboz8lKO+2krnG27kOseKtMMgoTi5lhQQpERhb0Mx8SgY9GFpencWAhWbhUvMc X-Received: by 2002:a02:cbdb:: with SMTP id u27mr3581949jaq.3.1625220571135; Fri, 02 Jul 2021 03:09:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625220571; cv=none; d=google.com; s=arc-20160816; b=DKRtvcXDZSoWClfdigPEUkgJ+Blphd1FEDVBludJuCU4Sh1bYW3jGsahBvEHH22SVu TGHtL/OlIyOEKaRNiwARrHxtHuSR/wZ0AlGVxJ2Fb/jUzjhrHhIwy54LQ27Kjofy4PsO 9EV2gTxYJ4xUoSpH10JDz3QaSC1yckMso1bVFmzU7iR/N7DtAEq2Fu2pCBdeIiYklU5+ qXn/AvaqqCGUEdML7HO+pFS+L6lfaL0srhLNM+qjzUMCi0hwseHiYB1K3ELDnZhhRy37 ZA0TlxCd5QlHQkoo4Bi/ihDTtMUqvL9C6F3njRqN41hg3qpLyOzdpdDOsLJp+Va39R9/ SlWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=rddnKrgHCHvdIh+yTIlyAXtHbADTNx1+ZKRVIyqtKg8=; b=e2Y+20rVd37KTYKFs3GWoZIKv+r11wn9uS13iufPHsNJDyLXVmbMv7u0l9DC7/s9ai KlrYF4iVEp5vfLYF4Ay7j6KkwVhZD+3r/2P3MfOrbfC43xzGXW8/6Rmou9XvYC25KK5Q LgqaCMPwszvcLGzVHAlh/YrTasdNCgm4OwnIWJlzlT0mSBgd6DTef2sGlIUUoMc/IJGg xD4TT3xuQ65B00tIqAvdgOvT6J4rPspccmSIff32jBR3QL6miFtuikd+myTMG7k1w0Dq 2hgAnGeXr+AsvDsB1G22+uLGZ1GEKvfNgo3588lk+5wtcXfu7nRwjsul8TEyfamjok18 q/Jg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v18si2611201ioh.67.2021.07.02.03.09.11; Fri, 02 Jul 2021 03:09:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231134AbhGBKJ6 (ORCPT + 99 others); Fri, 2 Jul 2021 06:09:58 -0400 Received: from mga04.intel.com ([192.55.52.120]:52499 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbhGBKJ5 (ORCPT ); Fri, 2 Jul 2021 06:09:57 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10032"; a="206885880" X-IronPort-AV: E=Sophos;i="5.83,317,1616482800"; d="scan'208";a="206885880" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 03:07:12 -0700 X-IronPort-AV: E=Sophos;i="5.83,317,1616482800"; d="scan'208";a="642620284" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 03:07:08 -0700 Received: from andy by smile with local (Exim 4.94.2) (envelope-from ) id 1lzG4c-007ekE-JP; Fri, 02 Jul 2021 13:07:02 +0300 Date: Fri, 2 Jul 2021 13:07:02 +0300 From: Andy Shevchenko To: Barry Song Cc: gregkh@linuxfoundation.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, yury.norov@gmail.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@huawei.com, prime.zeng@hisilicon.com, yangyicong@huawei.com, tim.c.chen@linux.intel.com, linuxarm@huawei.com, Tian Tao Subject: Re: [PATCH v5 1/3] cpumask: introduce cpumap_print_to_buf to support large bitmask and list Message-ID: References: <20210702092559.8776-1-song.bao.hua@hisilicon.com> <20210702092559.8776-2-song.bao.hua@hisilicon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210702092559.8776-2-song.bao.hua@hisilicon.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 02, 2021 at 09:25:57PM +1200, Barry Song wrote: > From: Tian Tao > > 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