FIO 运行时不同于 gettimeofday()

FIO runtime different than gettimeofday()

我正在尝试测量 FIO 基准测试的执行时间。目前,我正在这样做,将 FIO 调用包装在 gettimeofday():

之间
gettimeofday(&startFioFix, NULL);
FILE* process = popen("fio --name=randwrite --ioengine=posixaio rw=randwrite --size=100M --direct=1 --thread=1 --bs=4K", "r");
gettimeofday(&doneFioFix, NULL);

并将经过的时间计算为:

double tstart = startFioFix.tv_sec + startFioFix.tv_usec / 1000000.;
double tend = doneFioFix.tv_sec + doneFioFix.tv_usec / 1000000.;
double telapsed = (tend - tstart);

现在,问题是

  1. 经过的时间与 FIO 输出的 runt 不同(更大)。你能帮我理解为什么吗?事实上可以在 FIO 输出中看到:

    randwrite: (g=0): rw=randwrite, bs=4K-4K/4K-4K/4K-4K, ioengine=posixaio, iodepth=1
    fio-2.2.8
    Starting 1 thread
    
    randwrite: (groupid=0, jobs=1): err= 0: pid=3862: Tue Nov  1 18:07:50 2016
    write: io=102400KB, bw=91674KB/s, iops=22918, runt=  1117msec
    ...
    

    而逝去的是:

    telapsed: 1.76088 seconds
    
  2. FIO执行实际花费的时间是多少: a) FIO 给出的 runt,或者 b) getttimeofday()

  3. 经过的时间
  4. FIO 如何衡量其 runt? (可能,这个问题与 1 有关。)

PS:我尝试用 std::chrono::high_resolution_clock::now() 替换 gettimeofday(用 std::chrono::high_resolution_clock::now()),但它的行为也相同(同样,我的意思是它也比 runt)

提前感谢您的宝贵时间和协助。

要点:Linux 上的gettimeofday() 使用的时钟不一定以恒定间隔滴答作响,甚至可以向后移动(参见 http://man7.org/linux/man-pages/man2/gettimeofday.2.html and )- 这可能会使telapsed 不可靠(甚至是负面的)。

  1. 您的 gettimeofday/popen/gettimeofday 测量 (telapsed) 将是:fio 进程启动(即 Linux 上的 fork+exec)经过 + fio 初始化(例如线程创建,因为我看到 --thread,ioengine 初始化)+ fio 作业过去了(runt)+ fio 停止过去了 + 进程停止过去了)。您将其与 runt 进行比较,runttelapsed 的子组件。所有非 runt 组件都不太可能立即发生(即占用 0 微秒),因此预期 runt 将小于 telapsed。尝试使用 运行 fio 和 --debug=all 只是为了查看它除了实际提交 I/O 之外所做的所有事情。
  2. 这很难回答,因为这取决于你说 "fio execution" 时的意思以及为什么 (即这个问题很难用明确的语言解释方法)。您是否对 fio 实际花了多长时间尝试提交 I/O 给定工作 (runt) 感兴趣?您是否对您的系统 start/stop 一个新进程需要多长时间感兴趣,而该进程恰好在给定时间段 ([​​=11=]) 内尝试提交 I/O?您对提交 I/O(上述 none)花费了多少 CPU 时间感兴趣吗?因此,因为我很困惑,所以我会问你一些问题:你打算将结果用于什么以及为什么?
  3. 为什么不看源码呢? https://github.com/axboe/fio/blob/7a3b2fc3434985fa519db55e8f81734c24af274d/stat.c#L405 shows runt comes from ts->runtime[ddir]. You can see it is initialised by a call to set_epoch_time() (https://github.com/axboe/fio/blob/6be06c46544c19e513ff80e7b841b1de688ffc66/backend.c#L1664 ), is updated by update_runtime() ( https://github.com/axboe/fio/blob/6be06c46544c19e513ff80e7b841b1de688ffc66/backend.c#L371 ) 从 thread_main().
  4. 调用