How to find the kernel latency for an application?

Viewed 103

After long research on my own, I have come to ask for help here.

I want to measure the latency of the kernel for an application.

For example, I have a C-based application, when I run it I want to measure the time it takes for the kernel to schedule it.

I have used the time.h library in my C application but it tells me the time it takes for the execution of the application and not how much time the kernel is taking to schedule it.

PS: I have been using PREEMPT_RT patch, and my kernel is already PREEMPTIVE, if that information is somehow useful for you to answer.

1 Answers

The bcc tools (https://github.com/iovisor/bcc) have the runqlat tool which reports the scheduler latency. It can report the scheduler latency for the whole system or on a per-process basis.

Here is an example:

    # ./runqlat 
Tracing run queue latency... Hit Ctrl-C to end.
^C
     usecs               : count     distribution
         0 -> 1          : 233      |***********                             |
         2 -> 3          : 742      |************************************    |
         4 -> 7          : 203      |**********                              |
         8 -> 15         : 173      |********                                |
        16 -> 31         : 24       |*                                       |
        32 -> 63         : 0        |                                        |
        64 -> 127        : 30       |*                                       |
       128 -> 255        : 6        |                                        |
       256 -> 511        : 3        |                                        |
       512 -> 1023       : 5        |                                        |
      1024 -> 2047       : 27       |*                                       |
      2048 -> 4095       : 30       |*                                       |
      4096 -> 8191       : 20       |                                        |
      8192 -> 16383      : 29       |*                                       |
     16384 -> 32767      : 809      |****************************************|
     32768 -> 65535      : 64       |***                                     |

To get the scheduler latency for a process the -p switch needs to be specified. The -m switch specifies milliseconds instead of microseconds.

# ./runqlat -mp 4505 1
Tracing run queue latency... Hit Ctrl-C to end.

     msecs               : count     distribution
         0 -> 1          : 1        |*                                       |
         2 -> 3          : 2        |***                                     |
         4 -> 7          : 1        |*                                       |
         8 -> 15         : 0        |                                        |
        16 -> 31         : 25       |****************************************|
        32 -> 63         : 3        |****                                    |
Related