Re: [PATCH 1/5] sched,time: count actually elapsed irq & softirq time

From: Peter Zijlstra
Date: Tue Jun 21 2016 - 17:23:25 EST


On Thu, Jun 16, 2016 at 12:06:03PM -0400, riel@xxxxxxxxxx wrote:
> +static unsigned long irqtime_account_hi_update(unsigned long max_jiffies)
> {
> u64 *cpustat = kcpustat_this_cpu->cpustat;
> + unsigned long irq_jiffies;
> unsigned long flags;
> + u64 irq;
>
> local_irq_save(flags);
> + irq = this_cpu_read(cpu_hardirq_time) - cpustat[CPUTIME_IRQ];
> + irq_jiffies = min(cputime_to_jiffies(irq), max_jiffies);

cputime_to_jiffies is a division, could we not avoid that by doing
something like:

irq_jiffies = min(irq, jiffies_to_cputime(max_jiffies));
while (irq_jiffies > cputime_one_jiffy) {
irq_jiffies -= cputime_one_jiffy;
cpustat[CPUTIME_IRQ] += cputime_one_jiffy;
}

assuming that the loop is 'rare' etc.. If not, only do the division on
that same > cputime_one_jiffy condition.

> + if (irq_jiffies)
> + cpustat[CPUTIME_IRQ] += jiffies_to_cputime(irq_jiffies);
> local_irq_restore(flags);
> + return irq_jiffies;
> }