From patchwork Mon Jan 7 15:12:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 10750719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6314017D2 for ; Mon, 7 Jan 2019 15:13:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52536289C4 for ; Mon, 7 Jan 2019 15:13:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45E6828AB8; Mon, 7 Jan 2019 15:13:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2563289C4 for ; Mon, 7 Jan 2019 15:13:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729504AbfAGPNN (ORCPT ); Mon, 7 Jan 2019 10:13:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55042 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726918AbfAGPNN (ORCPT ); Mon, 7 Jan 2019 10:13:13 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A7E4289ADB; Mon, 7 Jan 2019 15:13:12 +0000 (UTC) Received: from llong.com (dhcp-17-223.bos.redhat.com [10.18.17.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3941E65F71; Mon, 7 Jan 2019 15:13:11 +0000 (UTC) From: Waiman Long To: Andrew Morton , Alexey Dobriyan , Luis Chamberlain , Kees Cook , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, Davidlohr Bueso , Miklos Szeredi , Daniel Colascione , Dave Chinner , Randy Dunlap , Waiman Long Subject: [PATCH 1/2] /proc/stat: Extract irqs counting code into show_stat_irqs() Date: Mon, 7 Jan 2019 10:12:57 -0500 Message-Id: <1546873978-27797-2-git-send-email-longman@redhat.com> In-Reply-To: <1546873978-27797-1-git-send-email-longman@redhat.com> References: <1546873978-27797-1-git-send-email-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 07 Jan 2019 15:13:12 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The code that generates the "intr" line of /proc/stat is now moved from show_stat() into a new function - show_stat_irqs(). There is no functional change. Signed-off-by: Waiman Long Reviewed-by: Kees Cook --- fs/proc/stat.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/fs/proc/stat.c b/fs/proc/stat.c index 535eda7..4b06f1b 100644 --- a/fs/proc/stat.c +++ b/fs/proc/stat.c @@ -79,12 +79,38 @@ static u64 get_iowait_time(int cpu) #endif +static u64 compute_stat_irqs_sum(void) +{ + int i; + u64 sum = 0; + + for_each_possible_cpu(i) { + sum += kstat_cpu_irqs_sum(i); + sum += arch_irq_stat_cpu(i); + } + sum += arch_irq_stat(); + return sum; +} + +/* + * Print out the "intr" line of /proc/stat. + */ +static void show_stat_irqs(struct seq_file *p) +{ + int i; + + seq_put_decimal_ull(p, "intr ", compute_stat_irqs_sum()); + for_each_irq_nr(i) + seq_put_decimal_ull(p, " ", kstat_irqs_usr(i)); + + seq_putc(p, '\n'); +} + static int show_stat(struct seq_file *p, void *v) { int i, j; u64 user, nice, system, idle, iowait, irq, softirq, steal; u64 guest, guest_nice; - u64 sum = 0; u64 sum_softirq = 0; unsigned int per_softirq_sums[NR_SOFTIRQS] = {0}; struct timespec64 boottime; @@ -105,8 +131,6 @@ static int show_stat(struct seq_file *p, void *v) steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL]; guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST]; guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE]; - sum += kstat_cpu_irqs_sum(i); - sum += arch_irq_stat_cpu(i); for (j = 0; j < NR_SOFTIRQS; j++) { unsigned int softirq_stat = kstat_softirqs_cpu(j, i); @@ -115,7 +139,6 @@ static int show_stat(struct seq_file *p, void *v) sum_softirq += softirq_stat; } } - sum += arch_irq_stat(); seq_put_decimal_ull(p, "cpu ", nsec_to_clock_t(user)); seq_put_decimal_ull(p, " ", nsec_to_clock_t(nice)); @@ -154,14 +177,10 @@ static int show_stat(struct seq_file *p, void *v) seq_put_decimal_ull(p, " ", nsec_to_clock_t(guest_nice)); seq_putc(p, '\n'); } - seq_put_decimal_ull(p, "intr ", (unsigned long long)sum); - - /* sum again ? it could be updated? */ - for_each_irq_nr(j) - seq_put_decimal_ull(p, " ", kstat_irqs_usr(j)); + show_stat_irqs(p); seq_printf(p, - "\nctxt %llu\n" + "ctxt %llu\n" "btime %llu\n" "processes %lu\n" "procs_running %lu\n"