Re: Clock Watching the Scheduler 2.2.10unip

Robert Redelmeier (redelm@ev1.net)
Tue, 28 Sep 1999 19:02:39 -0700


Richard B. Johnson wrote in part:

> Strange. I routinely handle 50,000 interrupts per second.

This sounds barely possible even on a loaded 100baseTX net
(100Mb/s ~ 10kint/s) but high. Unless you've set HZ 'way high.
Is this some real-time application?

> > #include <stdio.h>
> > #include <asm/msr.h>
> > #include <linux/config.h>
> > main () {
> > unsigned long i, c, t ;
> > for (i = 0; i < 500; i++ ) {
> > c = t = 0 ;
> > rdtscl(t);
> > do {
> > c = t ;
> > rdtscl(t);
> > } while ((t-c) < 90) ;
> > printf(" %lu\n",(t-c+32)&-64);
> > }
> > }
> >
>
> Could you please explain how this has anything to do with interrupts?
> I see you looping on the cpu clock for an abitrary count (< 90), and
> doing this another abitrary amount (500), and printing some abitrary
> manipulation of the last residual.

It is a bit tricky so I'm happy to explain: the while < 90 is
to throw away any non-interrupted loops. a pair of rdtsc's
usually take only 32 cycles, but I'm allowing something for
loop overhead. Feel free to change this to 0 and look at the
printout!

The 500 count is indeed arbitrary. I just wanted to count 500
interrupts. The (t-c+32)&-64 is a rounding to the nearest 64
of the cycle count for the interrupt service. Makes the uniq -c
work better as a histogram.

> It's true. I just don't get it. Are you thinking that the kernel's
> preemption of your task is an interrupt? Even though the preemption

On x86 at least, all preemption _must_ happen by an interrupt or
syscall. There are at least HZ (=100) interrupts per second.
I have no syscalls in my inner loop.

> occurs, sometimes using an interrupt, it is hardly an interrupt.
> When you are trying to write stuff to the terminal, if the buffer's
> full, you lose, you are preempted (sleep). What you seem to me
> measuring is the effect of overloading your output buffer.

I thought of this and avoided it. Of course there's tons of
overhead with printf. So note that I reload my base cycle
counter (c).

-- Robert

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/