lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9199a847ae92914ddcc0c69e75aaf3084b1ac3e0.1462901697.git.zhaolei@cn.fujitsu.com>
Date:	Wed, 11 May 2016 01:43:15 +0800
From:	Zhao Lei <zhaolei@...fujitsu.com>
To:	<linux-kernel@...r.kernel.org>,
	Peter Zijlstra <peterz@...radead.org>
CC:	Zhao Lei <zhaolei@...fujitsu.com>
Subject: [PATCH 2/3] cpuacct: Simplify cpuacct_stats_show

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@...fujitsu.com>
---
 kernel/sched/cpuacct.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
index 74241eb..e643483 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -243,28 +243,27 @@ static int cpuacct_percpu_seq_show(struct seq_file *m, void *V)
 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);
+		val[CPUACCT_STAT_USER]   += kcpustat->cpustat[CPUTIME_USER];
+		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];
 	}
-	val = cputime64_to_clock_t(val);
-	seq_printf(sf, "%s %lld\n", cpuacct_stat_desc[CPUACCT_STAT_USER], val);
 
-	val = 0;
-	for_each_possible_cpu(cpu) {
-		struct kernel_cpustat *kcpustat = per_cpu_ptr(ca->cpustat, cpu);
-		val += kcpustat->cpustat[CPUTIME_SYSTEM];
-		val += kcpustat->cpustat[CPUTIME_IRQ];
-		val += kcpustat->cpustat[CPUTIME_SOFTIRQ];
+	for (stat = 0; stat < CPUACCT_STAT_NSTATS; stat++) {
+		seq_printf(sf, "%s %lld\n",
+			   cpuacct_stat_desc[stat],
+			   cputime64_to_clock_t(val[stat]));
 	}
 
-	val = cputime64_to_clock_t(val);
-	seq_printf(sf, "%s %lld\n", cpuacct_stat_desc[CPUACCT_STAT_SYSTEM], val);
-
 	return 0;
 }
 
-- 
1.8.5.1



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ