On Thu, Mar 17, 2016 at 05:42:48PM +0800, Zhao Lei wrote: > > 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:
Only if you're in a VM or something daft like that. Real hardware will limit possible to the number of CPUs that are actually possible (usually the same as present, but physical hotplug and an empty socket can see possible > present). And if VM people are annoyed by the silly amount of CPUs, they can limit the number with the possible_cpus= boot parameter. > # cat cpuacct.usage_percpu > 689076136 1131883300 0 0 0 0 0 0 0 0 ... Such is life, if you actually had 256 CPUs (some people do) you'd get the same output. > 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 Can't do that, it changes the ABI. > So I suggest keeping current using of for_each_present_cpu, > and only modify for_each_online_cpu. > > What is your opinion? I think they should all be possible, present too can loose bits with hotplug.