Re: [PATCH 1/2] softirq: fix integer overflow in function show_stat()

From: Leizhen (ThunderTown)
Date: Mon Jul 24 2023 - 22:00:50 EST




On 2023/7/24 21:50, Matthew Wilcox wrote:
> On Mon, Jul 24, 2023 at 09:22:23PM +0800, thunder.leizhen@xxxxxxxxxxxxxxx wrote:
>> From: Zhen Lei <thunder.leizhen@xxxxxxxxxx>
>>
>> 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).

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.


>
> .
>

--
Regards,
Zhen Lei