Skip to contentSkip to conversation

How to measure i386 timer interrupt overhead

DISCUSSION Chuck Ebbert 2 participants 2 messages Dec 7, 2004

lore
Share & tools
lore
#0 lore raw

If this program actually works, then the SMP timer interrupt on this system takes 1200-1420 cycles, with 448 of 945 taking 1200-1219 cycles. (All the normal interrupts are bound to CPU 0.)

Is this a valid test program?

$ taskset 2 ./t 6800 332490000 | sort -g | uniq -c | grep -v '^      [1-9]'
Elasped time: 945 ticks (assuming Hz = 1000)
   9731 0
     35 10
    224 1200
    204 1210
     16 1220
     14 1270
     65 1300
    131 1310
     33 1320
     14 1370
     20 1380
     22 1420
$ cat t.c
/* Measure i386 timer overhead by timing loops with TSC and
 * subtracting out the minimum time.  Rounds to granularity 10.
 * (Run this on an otherwise idle system.)
 */
#include <stdio.h>
#define HZ              1000
#define NUM_TESTS       (11000 + 1)
unsigned long long t0, t1, t2, t3;
unsigned long long sample[NUM_TESTS], min = 1000000;
unsigned int loop_iters, tsc_per_tick, i, j;
main (int argc, char **argv) {
        if (argc < 3) {
                fprintf(stderr, "Usage: %s <loop_size> <CPU Hz>\n", argv[0]);
                exit(1);
        }
        loop_iters   = atoi(argv[1]);
        tsc_per_tick = atoll(argv[2]) / HZ;
restart:
        asm volatile ("rdtsc" : "=A"(t0));
        for (i = 0; i < NUM_TESTS; i++) {
                asm volatile ("rdtsc" : "=A"(t1));
                for (j = 0; j < loop_iters; j++)
                        /* empty */;
                asm volatile ("rdtsc" : "=A"(t2));
                sample[i] = t2 - t1;
        }
        asm volatile ("rdtsc" : "=A"(t3));
        if (t3 < t0)
                goto restart;
        for (i = 1; i < NUM_TESTS; i++) { /* skip first sample */
                if (min > sample[i])
                        min = sample[i];
        }
        for (i = 1; i < NUM_TESTS; i++)
                printf("%llu\n", (sample[i] - min) / 10 * 10);
        fprintf(stderr, "Elasped time: %d ticks (assuming Hz = %d)\n",
                        (int)((t3 - t0) / tsc_per_tick), HZ);
}

--Chuck Ebbert 06-Dec-04 22:03:04

#1 lore raw
Quoted 3 lines

If this program actually works, then the SMP timer interrupt on this system takes 1200-1420 cycles, with 448 of 945 taking 1200-1219 cycles. (All the normal interrupts are bound to CPU 0.)

Did you intend to measure the cycles, ticks(jiffies) or usec overhead?

Jan Engelhardt

Signature · 1 line
ENOSPC