我正在运行以下工作台来衡量拨打
所需的时间 clock_gettime(CLOCK_THREAD_CPUTIME_ID)
:
struct timespec start, end;
int nb_rep = 1E6;
clock_gettime(CLOCK_REALTIME, &start);
for (int i = 0; i < nb_rep; i++) {
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
}
clock_gettime(CLOCK_REALTIME, &end);
uint64_t ellapsed = (end.tv_sec * 1E9 + end.tv_nsec) - (start.tv_sec * 1E9 + start.tv_nsec);
printf("Time for clock_gettime(CLOCK_THREAD_CPUTIME_ID) = %" PRIu64 " nanoseconds (ellapsed = %ld)\n", ellapsed / nb_rep, ellapsed);
我正在使用sudo taskset -c 2 chrt -f 1 ./bench
运行我的替补,并得到以下结果(我的发布者是Ubunut 14.10):
我无法解释这些差异,并想知道它是否可能来自内核代码更改?我应该采取哪个方向来确定这种变化的起源?
以下是内核3.11
的perf记录/报告的输出12.21% cache_tests [kernel.kallsyms] [k] __ticket_spin_lock
10.09% cache_tests [vdso] [.] 0x00000000000007d2
6.78% cache_tests [kernel.kallsyms] [k] _raw_spin_unlock_irqrestore
6.74% cache_tests [kernel.kallsyms] [k] task_sched_runtime
6.71% cache_tests [kernel.kallsyms] [k] copy_user_generic_string
5.77% cache_tests [kernel.kallsyms] [k] native_read_tsc
5.47% cache_tests [kernel.kallsyms] [k] system_call
4.81% cache_tests [kernel.kallsyms] [k] system_call_after_swapgs
和内核3.13
23.83% cache_tests [vdso] [.] 0x00000000000007c2
5.49% cache_tests [kernel.kallsyms] [k] __acct_update_integrals
5.38% cache_tests [kernel.kallsyms] [k] context_tracking_user_exit
4.26% cache_tests [kernel.kallsyms] [k] _raw_spin_lock
4.24% cache_tests [kernel.kallsyms] [k] local_clock
4.04% cache_tests [kernel.kallsyms] [k] sched_clock_cpu
3.74% cache_tests [kernel.kallsyms] [k] rcu_eqs_enter_common.isra.47
3.41% cache_tests [kernel.kallsyms] [k] native_read_tsc
3.21% cache_tests [kernel.kallsyms] [k] rcu_eqs_exit_common.isra.48
2.90% cache_tests [kernel.kallsyms] [k] native_sched_clock
我该如何解释?