Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp989958yba; Thu, 4 Apr 2019 01:53:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwY8TjCzEYN9JW9RK3gUrf7OGNw+jjoqiPCcXnY5XrdwKH3hJNamKyvrj8DAwTEgrSvr5SU X-Received: by 2002:a17:902:2ec1:: with SMTP id r59mr5158410plb.171.1554368018811; Thu, 04 Apr 2019 01:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368018; cv=none; d=google.com; s=arc-20160816; b=bK1YHewy4gljO3vnJ+INxSrBHsYkjIdt1TXijQ0Wnd7dgjhSKcTn2xwih5jLUmUqi2 8kxEwL+hDka4IQLnuBEaK1xh03ubez/kPHp3oFx+IN6U+me0gDsNC64GIUV5QfKJZeZ1 gJCSPdT9rRLHGb8Lz/cwnbWWYiKTYprBV1mEwx1JNlwqo0DnOEDMagUfcF1JAMGIAR06 6XhObHEArdpl3Ws/vIXh/zLWG0EWZxVyfDQX7sx1qddpFeKzTMQwige+1mMNkM8V0t7h kSBXoAlobBP5wNpf9L7FPrxxOrEW7Jw6E+ZPBWo26dbqKJZKJv/GGUmYTCykpIRXF7Ft O/UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vGAU07/jsXViVdLvksxZWYlsl2MPln1+hwJH3leJixM=; b=oAQEJvwaRB7pxXYVj7oNk2QkLKCzne4wZ3ldPKtreKWuW985T7kc1Aza8ZiWo9bYvi yZioLUbkTDMRq5wByeNRwTASUxfPdpdf1Yw562G90/zQYJDocO8/RwAV0bf6Q0yPKwBq TRl3W2XjsWhLcoToRRSjO2GXsrxS0/1afmemo8X9SgXz0q0PkhSn50EC/svdiMJmUq+r NMJNybjKkvjaHTFEZyZqJIRL9KrgbiwNbJ0i75E8TV2LHYlCaRYRaWVfSggSQt1hfluJ ZKSsz1gFPAVR5bGnfdg8TTizWTpMISxrt5K5YvUn7nnQ3MijWGxa5uBMJx/OgLMswt/w WP8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QRpRBS9a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g14si7276495plo.287.2019.04.04.01.53.23; Thu, 04 Apr 2019 01:53:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QRpRBS9a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729519AbfDDIwC (ORCPT + 99 others); Thu, 4 Apr 2019 04:52:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:53872 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729494AbfDDIv4 (ORCPT ); Thu, 4 Apr 2019 04:51:56 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3A10B217D4; Thu, 4 Apr 2019 08:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554367915; bh=sdb6wbZKuO4yjNeksN4gUW26zb3h/1VB9ywLfTspJxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QRpRBS9aLHPLlfzvGbC9UfF2TMmAYHaQ3vd1C7k/Qvzd3HS8eu6NRD9ywjbTIdorx k7Bda3/ax86F+w2/gVrMhDURBeFz8vt0qR7lCwRa/ahzgKf5EdST4hftB2TyX29e9R c7maIacJ/TgHe74/oHCjiuJ0JWX1BSt814/0lEbc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Waiman Long , Thomas Gleixner , Marc Zyngier , Davidlohr Bueso , Matthew Wilcox , Andrew Morton , Alexey Dobriyan , Kees Cook , linux-fsdevel@vger.kernel.org, Davidlohr Bueso , Miklos Szeredi , Daniel Colascione , Dave Chinner , Randy Dunlap , Sasha Levin Subject: [PATCH 4.9 61/91] genirq: Avoid summation loops for /proc/stat Date: Thu, 4 Apr 2019 10:47:45 +0200 Message-Id: <20190404084538.964954273@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084535.450029272@linuxfoundation.org> References: <20190404084535.450029272@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 1136b0728969901a091f0471968b2b76ed14d9ad ] Waiman reported that on large systems with a large amount of interrupts the readout of /proc/stat takes a long time to sum up the interrupt statistics. In principle this is not a problem. but for unknown reasons some enterprise quality software reads /proc/stat with a high frequency. The reason for this is that interrupt statistics are accounted per cpu. So the /proc/stat logic has to sum up the interrupt stats for each interrupt. This can be largely avoided for interrupts which are not marked as 'PER_CPU' interrupts by simply adding a per interrupt summation counter which is incremented along with the per interrupt per cpu counter. The PER_CPU interrupts need to avoid that and use only per cpu accounting because they share the interrupt number and the interrupt descriptor and concurrent updates would conflict or require unwanted synchronization. Reported-by: Waiman Long Signed-off-by: Thomas Gleixner Reviewed-by: Waiman Long Reviewed-by: Marc Zyngier Reviewed-by: Davidlohr Bueso Cc: Matthew Wilcox Cc: Andrew Morton Cc: Alexey Dobriyan Cc: Kees Cook Cc: linux-fsdevel@vger.kernel.org Cc: Davidlohr Bueso Cc: Miklos Szeredi Cc: Daniel Colascione Cc: Dave Chinner Cc: Randy Dunlap Link: https://lkml.kernel.org/r/20190208135020.925487496@linutronix.de 8<------------- v2: Undo the unintentional layout change of struct irq_desc. include/linux/irqdesc.h | 1 + kernel/irq/chip.c | 12 ++++++++++-- kernel/irq/internals.h | 8 +++++++- kernel/irq/irqdesc.c | 7 ++++++- 4 files changed, 24 insertions(+), 4 deletions(-) Signed-off-by: Sasha Levin --- include/linux/irqdesc.h | 1 + kernel/irq/chip.c | 12 ++++++++++-- kernel/irq/internals.h | 8 +++++++- kernel/irq/irqdesc.c | 7 ++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h index c9be57931b58..bb5547a83daf 100644 --- a/include/linux/irqdesc.h +++ b/include/linux/irqdesc.h @@ -61,6 +61,7 @@ struct irq_desc { unsigned int core_internal_state__do_not_mess_with_it; unsigned int depth; /* nested irq disables */ unsigned int wake_depth; /* nested wake enables */ + unsigned int tot_count; unsigned int irq_count; /* For detecting broken IRQs */ unsigned long last_unhandled; /* Aging timer for unhandled count */ unsigned int irqs_unhandled; diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index f30110e1b8c9..9e745cc0726d 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c @@ -729,7 +729,11 @@ void handle_percpu_irq(struct irq_desc *desc) { struct irq_chip *chip = irq_desc_get_chip(desc); - kstat_incr_irqs_this_cpu(desc); + /* + * PER CPU interrupts are not serialized. Do not touch + * desc->tot_count. + */ + __kstat_incr_irqs_this_cpu(desc); if (chip->irq_ack) chip->irq_ack(&desc->irq_data); @@ -758,7 +762,11 @@ void handle_percpu_devid_irq(struct irq_desc *desc) unsigned int irq = irq_desc_get_irq(desc); irqreturn_t res; - kstat_incr_irqs_this_cpu(desc); + /* + * PER CPU interrupts are not serialized. Do not touch + * desc->tot_count. + */ + __kstat_incr_irqs_this_cpu(desc); if (chip->irq_ack) chip->irq_ack(&desc->irq_data); diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index bc226e783bd2..22e3f29a30d8 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -199,12 +199,18 @@ static inline bool irqd_has_set(struct irq_data *d, unsigned int mask) #undef __irqd_to_state -static inline void kstat_incr_irqs_this_cpu(struct irq_desc *desc) +static inline void __kstat_incr_irqs_this_cpu(struct irq_desc *desc) { __this_cpu_inc(*desc->kstat_irqs); __this_cpu_inc(kstat.irqs_sum); } +static inline void kstat_incr_irqs_this_cpu(struct irq_desc *desc) +{ + __kstat_incr_irqs_this_cpu(desc); + desc->tot_count++; +} + static inline int irq_desc_get_node(struct irq_desc *desc) { return irq_common_data_get_node(&desc->irq_common_data); diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 77977f55dff7..5e0ea17d01a6 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -109,6 +109,7 @@ static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node, desc->depth = 1; desc->irq_count = 0; desc->irqs_unhandled = 0; + desc->tot_count = 0; desc->name = NULL; desc->owner = owner; for_each_possible_cpu(cpu) @@ -880,11 +881,15 @@ unsigned int kstat_irqs_cpu(unsigned int irq, int cpu) unsigned int kstat_irqs(unsigned int irq) { struct irq_desc *desc = irq_to_desc(irq); - int cpu; unsigned int sum = 0; + int cpu; if (!desc || !desc->kstat_irqs) return 0; + if (!irq_settings_is_per_cpu_devid(desc) && + !irq_settings_is_per_cpu(desc)) + return desc->tot_count; + for_each_possible_cpu(cpu) sum += *per_cpu_ptr(desc->kstat_irqs, cpu); return sum; -- 2.19.1