Message ID | 20221111130709.247-3-thunder.leizhen@huawei.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | rcu: Add RCU stall diagnosis information | expand |
On Fri, Nov 11, 2022 at 09:07:05PM +0800, Zhen Lei wrote: > Similar to kstat_cpu_irqs_sum(), it counts the sum of all software > interrupts on a specified CPU. > > Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> > --- > include/linux/kernel_stat.h | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h > index 90e2fdc17d79ff8..898076e173a928a 100644 > --- a/include/linux/kernel_stat.h > +++ b/include/linux/kernel_stat.h > @@ -67,6 +67,17 @@ static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu) > return kstat_cpu(cpu).softirqs[irq]; > } > > +static inline unsigned int kstat_cpu_softirqs_sum(int cpu) > +{ > + int i; > + unsigned int sum = 0; > + > + for (i = 0; i < NR_SOFTIRQS; i++) > + sum += kstat_softirqs_cpu(i, cpu); This should return a u64 or at least an unsigned long so that high numbers of CPUs don't overflow easily. Thanks. > + > + return sum; > +} > + > /* > * Number of interrupts per specific IRQ source, since bootup > */ > -- > 2.25.1 >
On 2022/11/14 19:42, Frederic Weisbecker wrote: > On Fri, Nov 11, 2022 at 09:07:05PM +0800, Zhen Lei wrote: >> Similar to kstat_cpu_irqs_sum(), it counts the sum of all software >> interrupts on a specified CPU. >> >> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> >> --- >> include/linux/kernel_stat.h | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >> >> diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h >> index 90e2fdc17d79ff8..898076e173a928a 100644 >> --- a/include/linux/kernel_stat.h >> +++ b/include/linux/kernel_stat.h >> @@ -67,6 +67,17 @@ static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu) >> return kstat_cpu(cpu).softirqs[irq]; >> } >> >> +static inline unsigned int kstat_cpu_softirqs_sum(int cpu) >> +{ >> + int i; >> + unsigned int sum = 0; >> + >> + for (i = 0; i < NR_SOFTIRQS; i++) >> + sum += kstat_softirqs_cpu(i, cpu); > > This should return a u64 or at least an unsigned long so that high > numbers of CPUs don't overflow easily. OK! Then I'll adjust the following types by the way. struct kernel_stat { unsigned long irqs_sum; unsigned int softirqs[NR_SOFTIRQS]; }; static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu) > > Thanks. > >> + >> + return sum; >> +} >> + >> /* >> * Number of interrupts per specific IRQ source, since bootup >> */ >> -- >> 2.25.1 >> > . >
On Mon, Nov 14, 2022 at 08:45:26PM +0800, Leizhen (ThunderTown) wrote: > > > On 2022/11/14 19:42, Frederic Weisbecker wrote: > > On Fri, Nov 11, 2022 at 09:07:05PM +0800, Zhen Lei wrote: > >> Similar to kstat_cpu_irqs_sum(), it counts the sum of all software > >> interrupts on a specified CPU. > >> > >> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> > >> --- > >> include/linux/kernel_stat.h | 11 +++++++++++ > >> 1 file changed, 11 insertions(+) > >> > >> diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h > >> index 90e2fdc17d79ff8..898076e173a928a 100644 > >> --- a/include/linux/kernel_stat.h > >> +++ b/include/linux/kernel_stat.h > >> @@ -67,6 +67,17 @@ static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu) > >> return kstat_cpu(cpu).softirqs[irq]; > >> } > >> > >> +static inline unsigned int kstat_cpu_softirqs_sum(int cpu) > >> +{ > >> + int i; > >> + unsigned int sum = 0; > >> + > >> + for (i = 0; i < NR_SOFTIRQS; i++) > >> + sum += kstat_softirqs_cpu(i, cpu); > > > > This should return a u64 or at least an unsigned long so that high > > numbers of CPUs don't overflow easily. > > OK! Then I'll adjust the following types by the way. > > struct kernel_stat { > unsigned long irqs_sum; > unsigned int softirqs[NR_SOFTIRQS]; > }; > > static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu) And I also misread kstat_softirqs_cpu() content, my bad. Although at some point the sum of all softirqs within a single CPU might overflow in an int so I guess that still applies... Thanks. > > > > > > > > Thanks. > > > >> + > >> + return sum; > >> +} > >> + > >> /* > >> * Number of interrupts per specific IRQ source, since bootup > >> */ > >> -- > >> 2.25.1 > >> > > . > > > > -- > Regards, > Zhen Lei
On 2022/11/14 20:50, Frederic Weisbecker wrote: > On Mon, Nov 14, 2022 at 08:45:26PM +0800, Leizhen (ThunderTown) wrote: >> >> >> On 2022/11/14 19:42, Frederic Weisbecker wrote: >>> On Fri, Nov 11, 2022 at 09:07:05PM +0800, Zhen Lei wrote: >>>> Similar to kstat_cpu_irqs_sum(), it counts the sum of all software >>>> interrupts on a specified CPU. >>>> >>>> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> >>>> --- >>>> include/linux/kernel_stat.h | 11 +++++++++++ >>>> 1 file changed, 11 insertions(+) >>>> >>>> diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h >>>> index 90e2fdc17d79ff8..898076e173a928a 100644 >>>> --- a/include/linux/kernel_stat.h >>>> +++ b/include/linux/kernel_stat.h >>>> @@ -67,6 +67,17 @@ static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu) >>>> return kstat_cpu(cpu).softirqs[irq]; >>>> } >>>> >>>> +static inline unsigned int kstat_cpu_softirqs_sum(int cpu) >>>> +{ >>>> + int i; >>>> + unsigned int sum = 0; >>>> + >>>> + for (i = 0; i < NR_SOFTIRQS; i++) >>>> + sum += kstat_softirqs_cpu(i, cpu); >>> >>> This should return a u64 or at least an unsigned long so that high >>> numbers of CPUs don't overflow easily. >> >> OK! Then I'll adjust the following types by the way. >> >> struct kernel_stat { >> unsigned long irqs_sum; >> unsigned int softirqs[NR_SOFTIRQS]; >> }; >> >> static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu) > > And I also misread kstat_softirqs_cpu() content, my bad. Although at some point > the sum of all softirqs within a single CPU might overflow in an int so I guess > that still applies... Yes, this was discussed before. In fact, I think unsigned int and unsigned long are all right. > > Thanks. > > >> >> >> >> >>> >>> Thanks. >>> >>>> + >>>> + return sum; >>>> +} >>>> + >>>> /* >>>> * Number of interrupts per specific IRQ source, since bootup >>>> */ >>>> -- >>>> 2.25.1 >>>> >>> . >>> >> >> -- >> Regards, >> Zhen Lei > . >
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index 90e2fdc17d79ff8..898076e173a928a 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h @@ -67,6 +67,17 @@ static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu) return kstat_cpu(cpu).softirqs[irq]; } +static inline unsigned int kstat_cpu_softirqs_sum(int cpu) +{ + int i; + unsigned int sum = 0; + + for (i = 0; i < NR_SOFTIRQS; i++) + sum += kstat_softirqs_cpu(i, cpu); + + return sum; +} + /* * Number of interrupts per specific IRQ source, since bootup */
Similar to kstat_cpu_irqs_sum(), it counts the sum of all software interrupts on a specified CPU. Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> --- include/linux/kernel_stat.h | 11 +++++++++++ 1 file changed, 11 insertions(+)