我正在尝试使用读取时间戳计数器
的代码对开放系统调用进行基准测试Wrong identity.
Array
(
[cc] => 92
[in] => 1234566
[lg] => en
[lc] => PK
[id] => >zv?+?????w!l?v?5b?
[mistyped] => 6
[network_radio_type] => 1
[simnum] => 1
[s] =>
[copiedrc] => 1
[hasinrc] => 1
[rcmatch] => 1
[pid] => 579
[extexist] => 1
[extstate] => 1
)
stdClass Object
(
[status] => fail
[reason] => incorrect
[sms_length] => 6
[voice_length] => 6
[sms_wait] => 0
[voice_wait] => 0
)
使用的函数具有以下定义
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");
return 2;
}
printf("open syscall overhead is %ld\n",(rdtscllp() - t0 - overhead));
我正在为不同的运行获得以下开销
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");
return ((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");
return ((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;
}
return overhead;
}
我担心的是管理费用的巨大差异。
这种变化的原因是什么?
如果这种变化是正常的(可能是由于某些缓存),哪个值代表我的实际结果?