bornfree
bornfree

Reputation: 2538

How can I measure scheduling latency in linux kernel?

I want to compare scheduling latency between two linux kernel versions. Here is what I have tried so far:

  1. Configured Ftrace on both the kernels
  2. Turned on the sched events in tracing.
  3. Enabled the wakeup tracer.

However, wakeup shows results of only highest priority process and not my c program. I tried using nice and capturing it from the trace. Still it shows log for other equally high process. Am I missing some other step here to capture log of my process? Is there a better way to set priority of my process to highest by modifying the source code of my program instead of using nice when launching it?

The next step I tried was disabling the wakeup tracer and just enabling the sched events. The log that I got looks something like this

0 1dNh3 3us+: sched wakeup : task hald : 1952 [120] success=1

−0 1d..3 7us! : sched switch : task swapper : 0 [140] (R) ==>
hald : 1952 [120]

The + and ! shows delay (referred ftrace kernel doc to know the number). Does it mean that sched wakeup has a latency of '+' and sched witch '!' microseconds respectively?

Are there other ways of comparing linux scheduling latency?

Upvotes: 1

Views: 1824

Answers (1)

marton-l-toth
marton-l-toth

Reputation: 59

  • setting priority: the setpriority() system call does more or less the same as the nice command; in both cases increasing prio is only allowed for root.
  • as for measuring, I wrote the following simple program (public domain, use at your own risk) which has two processes sending short pipe messages to each other $1*1024 times.It will not give an exact value of "scheduling latency", but I think it is useful for comparison. (It prints 1024*$1 and 15*$1 only for sanity check, run with "time" to measure duration & CPU usage.)

Code:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main2() {
    int a; 
    while(1) {
            if (read(0, &a, 4)!=4) exit(1);
            if (a==-1) exit(0);
            write(1,"01"+(!(a&63) && (a&1023)),1);
    }}

int main(int ac, char** av) {
    int i,j,k = (ac>1 ? atoi(av[1]) : 10) << 10;
    int pipe0[2], pipe1[2];
    pipe(pipe0); pipe(pipe1);
    int pid = fork(); switch(pid) {
            case -1: perror("fork"); return 1;
            case 0: 
                     close(0); dup2(pipe1[0], 0); 
                     close(1); dup2(pipe0[1], 1);
                     return main2();
            default: break;
    }
    int sum = 0; char c;
    for (i=0; i<k; i++) {
            write(pipe1[1], &i, 4);
            read(pipe0[0], &c, 1); sum += c&1;
    }
    i=-1; write(pipe1[1], &i, 4);
    printf("%d %d\n", k, sum);
}

Upvotes: 1

Related Questions