Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

Slaying Latency with Linux Kernel Tracepoints

qint32 main(qint32 argc, char *argv[]){
   const int file = open("test.dat", O_RDWR | O_CREAT | O_TRUNC);

   for (int i = 0;; i++) {
       lseek(file, 0, SEEK_SET);
       QByteArray data;
       const int dataSize = 8 * 1024;
       data.fill((char)rand(), dataSize);

       QElapsedTimer writeTimer;
       writeTimer.start();
       write(file, data.data(), dataSize);
       fsync (file);
       const int elapsed = (int)writeTimer.elapsed();

       if (i > 10 && elapsed > 150) {
           qDebug("Write %d > 150ms, took %d ms", i, elapsed);
           exit(2);
       }
   }
   close(file);
}
cd /sys/kernel/debug/tracing
echo 1 > events/block/enable
echo 1 > events/ext4/enable
echo 1 > events/jbd2/enable
echo 1 > events/mmc/enable
echo 1 > tracing_on
mmcqd/0-89   [000] d..2   474.223046: block_rq_issue: 179,0 WFS 0 () 4717976 + 8 [mmcqd/0]

mmcqd/0-89   [000] ...1   474.223072: mmc_request_start: mmc0: start struct mmc_request
[c669d954]: cmd_opcode=25 cmd_arg=0x47fd98 cmd_flags=0xb5 cmd_retries=0 stop_opcode=12
stop_arg=0x0 stop_flags=0x49d stop_retries=0 sbc_opcode=23 sbc_arg=0x80000008 sbc_flags=0x15
sbc_retires=0 blocks=8 block_size=512 data_flags=0x100 can_retune=0 doing_retune=0
retune_now=0 need_retune=0 hold_retune=1 retune_period=0

<idle>-0     [000] ..s2   474.492701: mmc_request_done: mmc0: end struct mmc_request
[c669d954]: cmd_opcode=25 cmd_err=0 cmd_resp=0x900 0x0 0x0 0x0 cmd_retries=0 stop_opcode=12
stop_err=0 stop_resp=0x0 0x0 0x0 0x0 stop_retries=0 sbc_opcode=23 sbc_err=0 sbc_resp=0x0
0x0 0x0 0x0 sbc_retries=0 bytes_xfered=4096 data_err=0 can_retune=0 doing_retune=0
retune_now=0 need_retune=0 hold_retune=1 retune_period=0
echo 1 > events/sched/enable
echo 1 > events/workqueue/enable
#                              _-----=> irqs-off
#                             / _----=> need-resched
#                           | / _---=> hardirq/softirq
#                           || / _--=> preempt-depth
#                           ||| /     delay
#          TASK-PID   CPU# ||||   TIMESTAMP FUNCTION
#             | |       |   ||||       |         |
     mmcqd/0-89   [000] ...1 1384.282406: mmc_request_start: mmc0: start struct mmc_request[c669d954]: cmd_opcode=25 cmd_arg=0x480dc0 cmd_flags=0xb5 cmd_retries=0 stop_opcode=12 stop_arg=0x0 stop_flags=0x49d stop_retries=0 sbc_opcode=23 sbc_arg=0x80000008 sbc_flags=0x15 sbc_retires=0 blocks=8 block_size=512 data_flags=0x100 can_retune=0 doing_retune=0 retune_now=0 need_retune=0 hold_retune=1 retune_period=0
     mmcqd/0-89   [000] d..3 1384.282424: sched_stat_runtime: comm=mmcqd/0 pid=89 runtime=53666 [ns] vruntime=40997151704 [ns]
     mmcqd/0-89   [000] d..3 1384.282432: sched_switch: prev_comm=mmcqd/0 prev_pid=89 prev_prio=120 prev_state=S ==> next_comm=swapper/0 next_pid=0 next_prio=120
     <idle>-0     [000] d.s3 1384.466583: workqueue_queue_work: work struct=c63c21ac function=fb_flashcursor workqueue=c60a8100 req_cpu=4 cpu=0
     <idle>-0     [000] d.s3 1384.466585: workqueue_activate_work: work struct c63c21ac
     <idle>-0     [000] dns5 1384.466592: sched_wakeup: comm=kworker/0:1 pid=1572 prio=120 success=1 target_cpu=000
     <idle>-0     [000] d..3 1384.466612: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/0:1 next_pid=1572 next_prio=120
     kworker/0:1-1572 [000] ...1 1384.466616: workqueue_execute_start: work struct c63c21ac: function fb_flashcursor
     kworker/0:1-1572 [000] ...1 1384.466621: workqueue_execute_end: work struct c63c21ac
     kworker/0:1-1572 [000] d..3 1384.466626: sched_stat_runtime: comm=kworker/0:1 pid=1572 runtime=36000 [ns] vruntime=40988187704 [ns]
     kworker/0:1-1572 [000] d..3 1384.466630: sched_switch: prev_comm=kworker/0:1 prev_pid=1572 prev_prio=120 prev_state=S ==> next_comm=swapper/0 next_pid=0 next_prio=120
     <idle>-0     [000] d.s3 1384.506577: workqueue_queue_work: work struct=c64cf1f8 function=phy_state_machine workqueue=c60a8100 req_cpu=0 cpu=0
     <idle>-0     [000] d.s3 1384.506580: workqueue_activate_work: work struct c64cf1f8
     <idle>-0     [000] dns5 1384.506585: sched_wakeup: comm=kworker/0:1 pid=1572 prio=120 success=1 target_cpu=000
     <idle>-0     [000] d..3 1384.506602: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=kworker/0:1 next_pid=1572 next_prio=120
     kworker/0:1-1572 [000] ...1 1384.506606: workqueue_execute_start: work struct c64cf1f8: function phy_state_machine
     kworker/0:1-1572 [000] ...1 1384.506610: workqueue_execute_end: work struct c64cf1f8
     kworker/0:1-1572 [000] d..3 1384.506614: sched_stat_runtime: comm=kworker/0:1 pid=1572 runtime=31333 [ns] vruntime=40988219037 [ns]
     kworker/0:1-1572 [000] d..3 1384.506618: sched_switch: prev_comm=kworker/0:1 prev_pid=1572 prev_prio=120 prev_state=S ==> next_comm=swapper/0 next_pid=0 next_prio=120
     <idle>-0     [000] ..s2 1384.550637: mmc_request_done: mmc0: end struct mmc_request[c669d954]: cmd_opcode=25 cmd_err=0 cmd_resp=0x900 0xc7a4023c 0x0 0x0 cmd_retries=0 stop_opcode=12 stop_err=0 stop_resp=0x0 0x0 0x0 0x0 stop_retries=0 sbc_opcode=23 sbc_err=0 sbc_resp=0x0 0x0 0x0 0x0 sbc_retries=0 bytes_xfered=4096 data_err=0 can_retune=0 doing_retune=0 retune_now=0 need_retune=0 hold_retune=1 retune_period=0
     <idle>-0     [000] dns5 1384.550644: sched_wakeup: comm=mmcqd/0 pid=89 prio=120 success=1 target_cpu=000
     <idle>-0     [000] d..3 1384.550657: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=mmcqd/0 next_pid=89 next_prio=120

TraceCompass view of the kernel tracepoints


1 Comment

18 - Mar - 2017

Romain Pokrzywka

01_NoPhoto

Thomas McGuire

Former KDAB employee

01_NoPhoto

Andy Gryc

Co-Founder at Third Law autotech marketing

Learn Modern C++

Learn more