Re: [PATCH 4/4] irqtime: drop local_irq_save/restore from irqtime_account_irq

Frederic Weisbecker
2016-07-08T14:01:52Z

On Fri, Jul 08, 2016 at 09:19:47AM -0400, Rik van Riel wrote:
> On Fri, 2016-07-08 at 14:30 +0200, Frederic Weisbecker wrote:
> > > + if (irqtype == HARDIRQ_OFFSET) {
> > > + bool leaving_hardirq = hardirq_count();
> > > + delta = sched_clock_cpu(cpu) -
> > > __this_cpu_read(hardirq_start_time);
> > > + __this_cpu_add(hardirq_start_time, delta);
> > > + if (leaving_hardirq) {
> > > + hardirq_time_write_begin();
> > > + __this_cpu_add(cpu_hardirq_time, delta);
> > > + hardirq_time_write_end();
> > > + }
> >
> > This doesn't seem to work with nesting hardirqs.
> >
> > Thanks.
>
> Where does it break?
>
> enter hardirq A -> hardirq_start_time = now
>
> enter hardirq B -> hardirq_start_time = now,
>                    account already elapsed time
>
> leave hardirq B -> account elapsed time, set
>                    hardirq_start_time = now
>
> leave hardirq A -> account elapsed time
>
> What am I missing, except a softirq-style do-while
> loop to account for hardirq A being interrupted by
> hardirq B while updating the statistics?

How about:

enter hardirq A -> delta = sched_clock_cpu(cpu) - __this_cpu_read(hardirq_start_time);
enter hardirq B -> delta = sched_clock_cpu(cpu) - __this_cpu_read(hardirq_start_time);
__this_cpu_add(hardirq_start_time, delta);
...
exit hardirq B
__this_cpu_add(hardirq_start_time, delta);

Also seqcount writers can't nest.