Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp410154rwb; Tue, 25 Jul 2023 18:23:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlGgDbanixutt1aA0yw6/YKav+z2zTWsqy9aqSydEC2mhGN8ucEghsw9bu8gsSSAuz4PVYFN X-Received: by 2002:a05:6a21:3806:b0:12c:2956:564 with SMTP id yi6-20020a056a21380600b0012c29560564mr398831pzb.45.1690334590630; Tue, 25 Jul 2023 18:23:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690334590; cv=none; d=google.com; s=arc-20160816; b=mR4DXjDeoS9Pw3veiMm1BLPkuIX7B4kcY4W5w/ukjmzzSWd9dAdgAwyHEWdceXNrPS 2JlAzPdA0fpU4xNVkkL0+qPew5Km5IwAfqK2F30LQHC2n0+ZeqCcXWGhQR5MQnztuzFl C8Deo/63z/U+ddJt1npWjwlVhXd69GALNC6HRWlFw+50BaxfqA8sc/U+zqjiLCfpG++O S7MNdmIMKCPLW+3DZIxmgN/Tr6B38Fa/Js/L/K2gP3fqCvGjmtLbgZCEJ9yKkFNPb2CZ shAvW9NvMdftx0gLe4f5xMFcE4hpPs1BUSfZM0g/JS9j8yjWq8ePklHzKQ11qnwQGBFj t8GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=PUz0U14lfkzYuCgq3lpTPTDzzLc+x6MIzV5BUxBFVKA=; fh=diSvNLBUd30K4Afh1MrJk34n+YKKY4xB8a/ZeM9QN8o=; b=weAW+Y+oZvGpLEMLOOhV4NcZ0oxnp3/ITBe7AeWsWE7PQ339sF3I+6vD/V+sZz2LiV 12oAZUGrjYxMB5hTQRfI04SZ07JM2+4Ugb23FvG1VttDgX15aT4IIYMGxtZ4w9mFM2Sm bSx3grHl/xIUIYSyZcikyLApuxWGXzQJ6FOGTMy+dDBchOjJIiDWYSUWomj6IIwkwO6N /70KiSux8qKk/hxsDgHEQoyuIMHjuOahkfNMQKVUF2I4qPvZVS/Vb40U6hVhrs2dhDyR ZN6dXi++vUyDHKNf9l5AlVQmrd/rM/7gNIPCPmlWoflzoFpYtuFcJAyZHYL8ijZqXrY5 PiIA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q21-20020a656a95000000b0055c14b74a40si12674849pgu.229.2023.07.25.18.22.58; Tue, 25 Jul 2023 18:23:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230137AbjGZA7W (ORCPT + 99 others); Tue, 25 Jul 2023 20:59:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjGZA7U (ORCPT ); Tue, 25 Jul 2023 20:59:20 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E15FCBC; Tue, 25 Jul 2023 17:59:18 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4R9bBp5Pnhz4f3kkW; Wed, 26 Jul 2023 08:59:14 +0800 (CST) Received: from [10.174.178.55] (unknown [10.174.178.55]) by APP4 (Coremail) with SMTP id gCh0CgBH_rHhb8Bk5rZFOw--.10487S3; Wed, 26 Jul 2023 08:59:15 +0800 (CST) Subject: Re: [PATCH 1/2] softirq: fix integer overflow in function show_stat() To: Matthew Wilcox Cc: "Paul E . McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , rcu@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Zhen Lei References: <20230724132224.916-1-thunder.leizhen@huaweicloud.com> <20230724132224.916-2-thunder.leizhen@huaweicloud.com> <6e38e31f-4413-1aff-8973-5c3d660bedea@huaweicloud.com> <3b1ba209-58c8-b2b6-115a-6c43cba80098@huaweicloud.com> From: "Leizhen (ThunderTown)" Message-ID: Date: Wed, 26 Jul 2023 08:59:13 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CM-TRANSID: gCh0CgBH_rHhb8Bk5rZFOw--.10487S3 X-Coremail-Antispam: 1UD129KBjvJXoW7Ar4kAF4ftF1kWrWDuFWfZrb_yoW5JFWfpF W7t3Wjkr4kCFyIyrn2qrn7Xr12yw48J345Zrn8C3y8AFZ5Z3sagF47Kr4Y9Fyxur1Sgw4F vayjg3s7CFyDZa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUv2b4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6r1F6r1fM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I 0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7I2V7IY0VAS 07AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c 02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_ GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7 CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAF wI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa 7IU1zuWJUUUUU== X-CM-SenderInfo: hwkx0vthuozvpl2kv046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/7/25 23:26, Matthew Wilcox wrote: > On Tue, Jul 25, 2023 at 05:09:05PM +0800, Leizhen (ThunderTown) wrote: >> On 2023/7/25 10:00, Leizhen (ThunderTown) wrote: >>> On 2023/7/24 21:50, Matthew Wilcox wrote: >>>> On Mon, Jul 24, 2023 at 09:22:23PM +0800, thunder.leizhen@huaweicloud.com wrote: >>>>> From: Zhen Lei >>>>> >>>>> The statistics function of softirq is supported by commit aa0ce5bbc2db >>>>> ("softirq: introduce statistics for softirq") in 2009. At that time, >>>>> 64-bit processors should not have many cores and would not face >>>>> significant count overflow problems. Now it's common for a processor to >>>>> have hundreds of cores. Assume that there are 100 cores and 10 >>>>> TIMER_SOFTIRQ are generated per second, then the 32-bit sum will be >>>>> overflowed after 50 days. >>>> >>>> 50 days is long enough to take a snapshot. You should always be using >>>> difference between, not absolute values, and understand that they can >>>> wrap. We only tend to change the size of a counter when it can wrap >>>> sufficiently quickly that we might miss a wrap (eg tens of seconds). >> >> Sometimes it can take a long time to view it again. For example, it is >> possible to run a complete business test for hours or even days, and >> then calculate the average. > > I've been part of teams which have done such multi-hour tests. That > isn't how monitoring was performed. Instead snapshots were taken every > minute or even more frequently, because we wanted to know how these > counters were fluctuating during the test -- were there time periods > when the number of sortirqs spiked, or was it constant during the test? > >>> Yes, I think patch 2/2 can be dropped. I reduced the number of soft >>> interrupts generated in one second, and actually 100+ or 1000 is normal. >>> But I think patch 1/2 is necessary. The sum of the output scattered values >>> does not match the output sum. To solve this problem, we only need to >>> adjust the type of a local variable. >> >> However, it is important to consider that when the local variable is changed >> to u64, the output string becomes longer. It is not clear if the user-mode >> program parses it only by u32. > > There's no need for the numbers to add up. They won't anyway, because > summing them is racy , so they'll always be a little off. Okay, thanks for the reply. I got it. I just summed it up temporarily to prove that integer overflow is possible, and there's no actual requirement. > > . > -- Regards, Zhen Lei