From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Dumazet Subject: Re: [PATCH v2] hv_netvsc: Add per-cpu ethtool stats for netvsc Date: Wed, 13 Jun 2018 13:57:33 -0700 Message-ID: <4c853799-44e0-ff33-3555-41982d601ebb@gmail.com> References: <20180613193608.444-1-yidren@linuxonhyperv.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Yidong Ren , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "David S. Miller" , devel@linuxdriverproject.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Return-path: In-Reply-To: <20180613193608.444-1-yidren@linuxonhyperv.com> Content-Language: en-US List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: driverdev-devel-bounces@linuxdriverproject.org Sender: "devel" List-Id: netdev.vger.kernel.org On 06/13/2018 12:36 PM, Yidong Ren wrote: > From: Yidong Ren > > This patch implements following ethtool stats fields for netvsc: > cpu_tx/rx_packets/bytes > cpu_vf_tx/rx_packets/bytes ... > > + pcpu_sum = alloc_percpu(struct netvsc_ethtool_pcpu_stats); > + netvsc_get_pcpu_stats(dev, pcpu_sum); > + for_each_present_cpu(cpu) { > + struct netvsc_ethtool_pcpu_stats *this_sum = > + per_cpu_ptr(pcpu_sum, cpu); > + for (j = 0; j < ARRAY_SIZE(pcpu_stats); j++) > + data[i++] = *(u64 *)((void *)this_sum > + + pcpu_stats[j].offset); > + } > + free_percpu(pcpu_sum); > Using alloc_percpu() / free_percpu() for a short section of code makes no sense. You actually want to allocate memory local to this cpu, possibly in one chunk, not spread all over the places. kvmalloc(nr_cpu_ids * sizeof(struct netvsc_ethtool_pcpu_stats)) should be really better, since it would most of the time be satisfied by a single kmalloc()