<div dir="ltr">Hi,<br><div><br>On Wed, Feb 20, 2013 at 8:39 AM, buyitian <<a href="mailto:buyit@live.cn">buyit@live.cn</a>> wrote:<br>><br>> i am confused about my test. in one device driver,<br>> i put below code:<br>
><br>> printk("start to test test jiffies\n");<br>><br>> local_irq_save(flags);<br>><br>> jf1 = jiffies; // read jiffies first time<br>><br>> // hold cpu for about 2 seconds(do some calculation)<br>
><br>> jf2 = jiffies; // read jiffies after 2 seconds<br>><br>> local_irq_restore(flags);<br>><br>> printk("jf1:%lu, jf2:%lu\n", jf1, jf2);<br>><br>> and the output is as below:<br>
><br>> <4>[ 108.551124]start to test test jiffies<br>> <4>[ 110.367604]jf1:4294948151, jf2:4294948151<br>><br>> the jf1 and jf2 are the same value, although they are<br>> read between 2 seconds interval, i think this is because<br>
> i disabled local interrupt.<br>> but the printk timestamp is from 108.551124 to 110.367604,<br>> which is about 2 seconds. and on my platform, printk timestamp<br>> is got from the function read_sched_clock:<br>
> static u32 __read_mostly (*read_sched_clock)(void) = jiffy_sched_clock_read;<br>><br>> and function jiffy_sched_clock_read() is to read from jiffies.<br>><br>> it seems that the jiffies is frozen when local irq is disabled,<br>
> but after local_irq_restore(), the jiffies not only start<br>> to run, but also recover the lost 2 seconds.<br><br></div><div>That's correct. You disabled interrupts so the timer interrupt can't update the jiffies. Although on an SMP system, it may be possible for that timer irq to be serviced on a different core.<br>
</div><div><br>> is the jiffies updated from another cpu when irq is disabled on<br>> local cpu?<br><br></div><div>That's really HW/platform dependant.<br><br></div><div>Some systems only have a periodic timer which fires every N microseconds, and if you miss an interrupt you miss a jiffy increment. Other systems have a HW timer that has an incrementing register so that jiffies can be recovered properly when the timer IRQ is actually serviced (because the underlying HW timer still increments even though irqs are disabled).<br>
</div><div><br>--<br>Dave Hylands<br>Shuswap, BC, Canada<br><a href="http://www.davehylands.com">http://www.davehylands.com</a></div></div>