From: Ingo Molnar <mingo@kernel.org>
To: Zhao Lei <zhaolei@cn.fujitsu.com>
Cc: linux-kernel@vger.kernel.org, Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH 2/3] cpuacct: Simplify cpuacct_stats_show
Date: Thu, 12 May 2016 09:47:47 +0200 [thread overview]
Message-ID: <20160512074747.GA31930@gmail.com> (raw)
In-Reply-To: <9199a847ae92914ddcc0c69e75aaf3084b1ac3e0.1462901697.git.zhaolei@cn.fujitsu.com>
* Zhao Lei <zhaolei@cn.fujitsu.com> wrote:
> Merge code for each cpustat(system/user) into a loop,
> to avoid clone of code blocks.
> Only a little cleanup.
>
> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
> ---
> kernel/sched/cpuacct.c | 29 ++++++++++++++---------------
> 1 file changed, 14 insertions(+), 15 deletions(-)
I see a couple of problems with this patch:
- please Cc: all scheduler maintainers to scheduler patches.
- please fix the title of the patch: have a look at 'git log
kernel/sched/cpuacct.c' how recent titles to that code look like.
- when referring to functions in changelogs, please add '()' to separate them from
variable and other names. I.e. it's "cpuacct_stats_show()".
> static int cpuacct_stats_show(struct seq_file *sf, void *v)
> {
> struct cpuacct *ca = css_ca(seq_css(sf));
> + s64 val[CPUACCT_STAT_NSTATS];
> int cpu;
> - s64 val = 0;
> + int stat;
>
> + memset(val, 0, sizeof(val));
> for_each_possible_cpu(cpu) {
> - struct kernel_cpustat *kcpustat = per_cpu_ptr(ca->cpustat, cpu);
> - val += kcpustat->cpustat[CPUTIME_USER];
> - val += kcpustat->cpustat[CPUTIME_NICE];
> + struct kernel_cpustat *kcpustat = per_cpu_ptr(ca->cpustat,
> + cpu);
Horrible taste: in what universe is that linebreak an improvement to the code?
> + val[CPUACCT_STAT_USER] += kcpustat->cpustat[CPUTIME_USER];
Also, please put a newline between variable definitions and the first
non-definition C statement...
> + val[CPUACCT_STAT_USER] += kcpustat->cpustat[CPUTIME_NICE];
> + val[CPUACCT_STAT_SYSTEM] += kcpustat->cpustat[CPUTIME_SYSTEM];
> + val[CPUACCT_STAT_SYSTEM] += kcpustat->cpustat[CPUTIME_IRQ];
> + val[CPUACCT_STAT_SYSTEM] += kcpustat->cpustat[CPUTIME_SOFTIRQ];
Also, if you introduce a helper variable to shorten the code, you might as well
introduce one for the cpustat array itself, and skip the whole 'kcpustat->'
repetition ...
Thanks,
Ingo
next prev parent reply other threads:[~2016-05-12 7:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-10 17:43 [PATCH 0/3] cpuacct: Show all detail stats in one file Zhao Lei
2016-05-10 17:43 ` [PATCH 1/3] cpuacct: Merge cpuacct_usage_index and cpuacct_usage_index Zhao Lei
2016-05-12 7:49 ` Ingo Molnar
2016-05-10 17:43 ` [PATCH 2/3] cpuacct: Simplify cpuacct_stats_show Zhao Lei
2016-05-12 7:47 ` Ingo Molnar [this message]
2016-05-10 17:43 ` [PATCH 3/3] cpuacct: Show all detail stats in one file Zhao Lei
2016-05-11 11:39 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160512074747.GA31930@gmail.com \
--to=mingo@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=zhaolei@cn.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox