lkml.org 
[lkml]   [1999]   [Jul]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectMeasured overhead of timer interrupts
> > Do you really want to spend 1% CPU servicing timer interrupts just so
> > _occasionally_ a program can get a short sleep to 2ms accuracy?
>
> Did you measure the difference? I believe I tried to actually measure
> that and failed.

Ok, I just measured it, and it is more than I expected. The code is
attached at the end. (You can use it for measuring other interrupt
overheads too).

If I disable interrupts using cli(),
I consistently get:

low: 0000002e, high 0000002e, total 1b6b0b00, lost 00000000
Percentage cycles lost: 0.000000%
With interrupts enabled, network interface disabled, task run as top
priority SCHED_FIFO, and I checked only timer interrupts occur during
the test:

At 100Hz, on a single 300MHz Pentium II, 440LX:

low: 0000002e, high 0000a0e7, total 1b758d4f, lost 000a824f
Percentage cycles lost: 0.149498%
low: 0000002e, high 0000a08c, total 1b7528ee, lost 000a1dee
Percentage cycles lost: 0.143928%
low: 0000002e, high 00009fdb, total 1b749e93, lost 00099393
Percentage cycles lost: 0.136250%
low: 0000002e, high 00009ff9, total 1b7517b1, lost 000a0cb1
Percentage cycles lost: 0.142971%
low: 0000002e, high 0000a0e0, total 1b74c678, lost 0009bb78
Percentage cycles lost: 0.138464%
low: 0000002e, high 0000a18f, total 1b7533b8, lost 000a28b8
Percentage cycles lost: 0.144526%
low: 0000002e, high 0000a0f8, total 1b749561, lost 00098a61
Percentage cycles lost: 0.135739%
low: 0000002e, high 0000a441, total 1b752bbc, lost 000a20bc
Percentage cycles lost: 0.144083%
low: 0000002e, high 0000a156, total 1b7526b8, lost 000a1bb8
Percentage cycles lost: 0.143805%
low: 0000002e, high 0000a0b1, total 1b75194e, lost 000a0e4e
Percentage cycles lost: 0.143061%
This counts the overhead of timer interrupts and anything that happens
in return path of timer interrupts.

Summary: Single 300MHz Pentium II on 440LX chipset.
Average timer interrupt overhead at 100Hz: 0.14225%
Average cycles per timer interrupt: 41240.6
Average time per timer interrupt: 137.47

Extrapolating to 1024Hz, expect 1.4566% time to go servicing the timer
interrupts.

Quite how this translates to "reasonable 486+ its definitely a non
issue" I can't see. Maybe 486s are faster than Pentium IIs?

enjoy,
-- Jamie

/* Measure overhead taken by kernel from a running process.
x86 with rdtsc and cmov instructions required. Version 1.
Copyright (C) 1999 Jamie Lokier.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

#define LOOP 10000000 /* You may have to reduce this to avoid overflow. */
/* Define CLI to disable interrupts. sync() your disks first! */
/* Define SCHED to run at high priority. sync() your disks first! */
#include <stdio.h>
#include <sys/io.h>
#include <sched.h>
int main ()
{
unsigned int dummy, low, high, total;
#ifdef SCHED
struct sched_param param;
memset (&param, 0, sizeof (param));
param.sched_priority = sched_get_priority_max (SCHED_FIFO);
sched_setscheduler (getpid (), SCHED_FIFO, &param);
#endif

#ifdef CLI
iopl (3); __asm__ volatile ("cli");
#endif

__asm__ volatile ("
pushl %%ebp
rdtsc
0: movl %%eax,%%ebp
rdtsc
subl %%eax,%%ebp
cmpl %%ebp,%%esi
cmovbl %%ebp,%%esi
cmpl %%ebp,%%edi
cmoval %%ebp,%%edi
decl %%ecx
cmovel %%ecx,%%esi
cmovel %%ebx,%%edi
cmovel %%eax,%%ebx
cmpl %4,%%ecx
jnz 0b
subl %%ebx,%%eax
popl %%ebp"
: "=c" (dummy), "=S" (low), "=D" (high), "=a" (total)
: "i" (-LOOP), "c" (50), "b" (0xffffffff)
: "ebx", "edx");
#ifdef CLI
__asm__ volatile ("sti"); iopl (0);
#endif

low = -low;
high = -high;
printf ("low: %08x, high %08x, total %08x, lost %08x\n"
"Percentage cycles lost: %0.6f%%\n",
low, high, total, (total - low * LOOP),
(total - low * (double) LOOP) / total * 100);
}
-
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/

\
 
 \ /
  Last update: 2005-03-22 13:53    [from the cache]
©2003-2011 Jasper Spaans