From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935424AbcCQJnC (ORCPT ); Thu, 17 Mar 2016 05:43:02 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:7292 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S932832AbcCQJm7 convert rfc822-to-8bit (ORCPT ); Thu, 17 Mar 2016 05:42:59 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="4681612" From: Zhao Lei To: "'Peter Zijlstra'" CC: , "'Tejun Heo'" , "'Yang Dongsheng'" References: <5a23ec991c5abf9b62df76be5b081a5fa895f35b.1458187654.git.zhaolei@cn.fujitsu.com> <20160317084002.GN6344@twins.programming.kicks-ass.net> In-Reply-To: <20160317084002.GN6344@twins.programming.kicks-ass.net> Subject: RE: [PATCH v3 3/3] cpuacct: split usage into user_usage and sys_usage Date: Thu, 17 Mar 2016 17:42:48 +0800 Message-ID: <00c601d18031$5e2c2800$1a847800$@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8BIT X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQHtS9c3bemq6/13SrUes9h+t3vTtQMk6dxtAvvXzWCe9Lv4gA== Content-Language: zh-cn X-yoursite-MailScanner-ID: 6EA8B489F960.AE1ED X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhaolei@cn.fujitsu.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Peter Zijlstra > -----Original Message----- > From: Peter Zijlstra [mailto:peterz@infradead.org] > Sent: Thursday, March 17, 2016 4:40 PM > To: Zhao Lei > Cc: linux-kernel@vger.kernel.org; Tejun Heo ; Yang > Dongsheng > Subject: Re: [PATCH v3 3/3] cpuacct: split usage into user_usage and sys_usage > > On Thu, Mar 17, 2016 at 12:19:44PM +0800, Zhao Lei wrote: > > +static u64 __cpuusage_read(struct cgroup_subsys_state *css, > > + enum cpuacct_usage_index index) > > { > > struct cpuacct *ca = css_ca(css); > > u64 totalcpuusage = 0; > > int i; > > > > for_each_present_cpu(i) > > + totalcpuusage += cpuacct_cpuusage_read(ca, i, index); > > > > return totalcpuusage; > > } > > Ok, so while looking over this, it mostly uses for_each_present_cpu(), > which is already dubious, but then cpuacct_stats_show() uses > for_each_online_cpu(). > > Why is this? Why not always for_each_possible_cpu()? > > Surely, if you offline a cpu, you still want its stat to be included in > your totals, otherwise your numbers will go backwards when you take a > cpu offline. > I agree with you that for_each_possible_cpu() is best choice for above code. In corrent code, 1: cpuacct.usage_percpu only include present_cpus If a cpu is hotplug out, it is not exist in above file. 2: cpuacct.usage only calculate present_cpus If a cpu is hotplug out, this value maybe decreased. 3: cpuacct.stat only calculate online cpus Obviously wrong. Above 3 is easy to fix, but better to fix above 1 and 2 together, in one word, to make ALL statics counts possible_cpu. The problem is file output, currently, # cat cpuacct.usage_percpu 689076136 1131883300 If we turn to use possible_cpu, above line will have 256 valuse, as: # cat cpuacct.usage_percpu 689076136 1131883300 0 0 0 0 0 0 0 0 ... Or we can only show present_cpu and non_present_cpu with !0 value, and we need also need output a cpuindex, as: # cat cpuacct.usage_percpu [0] 689076136 [1] 1131883300 [3] 11111111 [50] 22222222 # It will tell user more accurate information, but both solution will change current cgroup interface. So I suggest keeping current using of for_each_present_cpu, and only modify for_each_online_cpu. What is your opinion? Thanks Zhaolei