I am trying to benchmark open system call with my code that read timestamp counter
overhead = measure_tsc_overhead();
int i;
unsigned long t0;
synch_tsc();
t0 = rdtscll();
input_fd = open ("input.txt", O_RDONLY);
if (input_fd == -1) {
perror ("open");
retu 2;
}
printf("open syscall overhead is %ldn",(rdtscllp() - t0 - overhead));
functions used have following definitions
static inline void synch_tsc(void)
{
asm volatile("cpuid" : : : "%rax", "%rbx", "%rcx", "%rdx");
}
static inline unsigned long rdtscll(void)
{
unsigned int a, d;
asm volatile("rdtsc" : "=a" (a), "=d" (d) : : "%rbx", "%rcx");
retu ((unsigned long) a) | (((unsigned long) d) << 32);
}
static inline unsigned long rdtscllp(void)
{
unsigned int a, d;
asm volatile("rdtscp" : "=a" (a), "=d" (d) : : "%rbx", "%rcx");
retu ((unsigned long) a) | (((unsigned long) d) << 32);
}
static unsigned long measure_tsc_overhead(void)
{
unsigned long t0, t1, overhead = ~0UL;
int i;
for (i = 0; i < N; i++) {
t0 = rdtscll();
asm volatile("");
t1 = rdtscllp();
if (t1 - t0 < overhead)
overhead = t1 - t0;
}
retu overhead;
}
I am getting following overheads for different runs
open syscall overhead is 24497
open syscall overhead is 13523
open syscall overhead is 9025
open syscall overhead is 5784
open syscall overhead is 26390
My conce is the huge variation in overheads.
what is the reason for such variation?
If this variation is normal (may be due to some cache) what value represents my actual result?
