Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1850561rbb; Tue, 27 Feb 2024 03:20:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXW+lu2UNFS/J5a/sSMy1NtRWMIcArZc0I0wxTsVxl1KrmG4WJti+mY7O3c/NhZLAKiiSvQCsKxixtyTjQ98ozWdhgToOm5aAtg2AYBxA== X-Google-Smtp-Source: AGHT+IFzpjK1bKyPlrrQllEtV5zC+myUY8s947ZzwSZl+qGvB9S4F+deAretFe2k+c+LJMEsNFg2 X-Received: by 2002:a17:906:4e8a:b0:a43:b988:66e9 with SMTP id v10-20020a1709064e8a00b00a43b98866e9mr726576eju.38.1709032823554; Tue, 27 Feb 2024 03:20:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709032823; cv=pass; d=google.com; s=arc-20160816; b=ZjUCv+/jgonhOUO2Le+tqyUKF7cMulIE6RR5byi8ut6DlAIZzZLVnfseY2SOzrUxF3 G40KDuyZQXG0QRX/y0FOt2qMDbKtOolgzZjAgHPc3fN1Utl0YYAfCsNS/ufElj4DvPpE YEH7v0/BqBxKA6QizUgGZFbH6vlnv9icvAtOq6HDexxn2jzbNsRkYd5VUMpg9w91n8p5 cui0G0nSbTBAQp2Gnyzl4suqXPFUW9q1jXuqCWvcbc3mtptEN+9wmTTfLcdrNlKv7zV2 HsDkLoHtl9hzTDJjTHvHLj2/ob/q8mjgCQkbm4mqKba3ABus6JUEnWgT7loiDc/cgFIZ 2bGA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=Ep8dMZzmk15xqlqQL7RaK3mkeF/5/DFYGYZbEAf2sXs=; fh=BxZc6UigdHKWum767gvPMSYb0IR4WuWmcYGUHcBeGS0=; b=Z1eJRRFaNy67AgU3+UuUTfyc+aNY5/Ag+MAujJDbl+6/mYQGd77gyy9txEnG6yXj/+ 1G5sydyRi5F3vhVORlc4iR8sIP1oQckkSGGpn9LniERtCeHxXBGNzqYroRauHiHvXFJU 4x0Wv4Tvxt7GxT/qzmKTEsyTRA1Cr3/yQLMQDJ8/KUW/ACZHPwmY0G5BXud05IgrfFMD qKWZ/YjChlc6CaZ2OmPGfHeI67vT0LR4VDsMhwZNeaJa7d6lDKT2OIQ9I33C1qjhHbfZ fmpoklFwUEmHJsnI8UlqmGs2X62SeegUQDBAZJVKZtQYPDd0Rc7BeFiOX/OMqELqKX5M PU3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=x1yqMzDr; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-83116-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83116-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v6-20020a1709061dc600b00a3ee0c7101fsi614328ejh.1050.2024.02.27.03.20.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 03:20:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83116-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=x1yqMzDr; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-83116-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83116-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 269311F23709 for ; Tue, 27 Feb 2024 11:20:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91759139584; Tue, 27 Feb 2024 11:20:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="x1yqMzDr" Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F7452A8C1; Tue, 27 Feb 2024 11:20:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709032815; cv=none; b=ptQrWN19+0PqkwXoHAZMFrw2iFF2sYMADfCEm30GGlFsrwWAsJ3al2WfBTlqQvktppOVZx5UuQTXWVRS/Tmx0jWylrc3i0nDc6pKX5tYhxR33aTL4b6YU3+rmV5Msx+qfiyklq6pivlfzvV/A1EpaSDEUNH61TRxYIf1ZiV5aPw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709032815; c=relaxed/simple; bh=kdPMwJOhfJgg9gGm+J+k23KPey7iTw4bgo1JgzYNRwc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ovpzm591lP2m9ey7EgoaELQ7S4TNoPBNy6d3BErfzp8ZunK9TZLlzcchpU2FzJFxu1ERrFSkJW3AkB2y8FcuqkHikdkcryq0ufXZTNxMHboU9861FHR0vgD1k9SoLoU16/0DTevMulSnsPSmptdzAsi1YdF5U21oeMZyV3iTCcg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=x1yqMzDr; arc=none smtp.client-ip=115.124.30.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1709032804; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=Ep8dMZzmk15xqlqQL7RaK3mkeF/5/DFYGYZbEAf2sXs=; b=x1yqMzDr2lT01JeB/L60w3/wEY6ufBlomdmj+d59DifYCmNlub89c5m1CCjlrzRp7evZCpYfau5ZulZpsVtifU3V/uHteJSTY6aDNIGnsSqLW01GTIgGoZRV7HuDS8+/5qY3VhND0Fqbm4nsrShoKxdbr9+jS5Qce3rcLHwJXoM= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R421e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=yaoma@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0W1MauK8_1709032801; Received: from 30.178.67.122(mailfrom:yaoma@linux.alibaba.com fp:SMTPD_---0W1MauK8_1709032801) by smtp.aliyun-inc.com; Tue, 27 Feb 2024 19:20:02 +0800 Message-ID: Date: Tue, 27 Feb 2024 19:20:00 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCHv10 3/4] genirq: Avoid summation loops for /proc/interrupts Content-Language: en-US To: Thomas Gleixner , dianders@chromium.org, liusong@linux.alibaba.com, akpm@linux-foundation.org, pmladek@suse.com, kernelfans@gmail.com, deller@gmx.de, npiggin@gmail.com, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, jan.kiszka@siemens.com Cc: linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org References: <20240226020939.45264-1-yaoma@linux.alibaba.com> <20240226020939.45264-4-yaoma@linux.alibaba.com> <87le769s0w.ffs@tglx> From: Bitao Hu In-Reply-To: <87le769s0w.ffs@tglx> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, On 2024/2/27 17:26, Thomas Gleixner wrote: > On Mon, Feb 26 2024 at 10:09, Bitao Hu wrote: >> We could use the irq_desc::tot_count member to avoid the summation >> loop for interrupts which are not marked as 'PER_CPU' interrupts in >> 'show_interrupts'. This could reduce the time overhead of reading >> /proc/interrupts. > > "Could" is not really a technical term. Either we do or we do not. Also > please provide context for your change and avoid the 'We'. OK. > >> --- a/include/linux/irqdesc.h >> +++ b/include/linux/irqdesc.h >> @@ -121,6 +121,8 @@ static inline void irq_unlock_sparse(void) { } >> extern struct irq_desc irq_desc[NR_IRQS]; >> #endif >> >> +extern bool irq_is_nmi(struct irq_desc *desc); >> + > > If at all this wants to be in kernel/irq/internal.h. There is zero > reason to expose this globally. > >> -static bool irq_is_nmi(struct irq_desc *desc) >> +bool irq_is_nmi(struct irq_desc *desc) >> { >> return desc->istate & IRQS_NMI; >> } > > If at all this really wants to be a static inline in internals.h, but > instead of blindly copying code this can be done smarter: > > unsigned int kstat_irq_desc(struct irq_desc *desc) > { > unsigned int sum = 0; > int cpu; > > if (!irq_settings_is_per_cpu_devid(desc) && > !irq_settings_is_per_cpu(desc) && > !irq_is_nmi(desc)) > return data_race(desc->tot_count); > > for_each_possible_cpu(cpu) > sum += data_race(*per_cpu_ptr(desc->kstat_irqs, cpu)); > return sum; > } > > and then let kstat_irqs() and show_interrupts() use it. See? I have a concern. kstat_irqs() uses for_each_possible_cpu() for summation. However, show_interrupts() uses for_each_online_cpu(), which means it only outputs interrupt statistics for online cpus. If we use for_each_possible_cpu() in show_interrupts() to calculate 'any_count', there could be a problem with the following scenario: If an interrupt has a count of zero on online cpus but a non-zero count on possible cpus, then 'any_count' would not be zero, and the statistics for that interrupt would be output, which is not the desired behavior for show_interrupts(). Therefore, I think it's not good to have kstat_irqs() and show_interrupts() both use the same logic. What do you think? > > With that a proper changelog would be: > > show_interrupts() unconditionally accumulates the per CPU interrupt > statistics to determine whether an interrupt was ever raised. > > This can be avoided for all interrupts which are not strictly per CPU > and not of type NMI because those interrupts provide already an > accumulated counter. The required logic is already implemented in > kstat_irqs(). > > Split the inner access logic out of kstat_irqs() and use it for > kstat_irqs() and show_interrupts() to avoid the accumulation loop > when possible. > Best Regards, Bitao Hu