Re: PREEMPT_RT and latency_trace

From: Ingo Molnar
Date: Fri Jul 08 2005 - 09:00:15 EST



* Serge Noiraud <serge.noiraud@xxxxxxxx> wrote:

> Hi,
>
> I have a big dilemna on one machine :
> I run a task with RT priority which make a loop to mesure the system
> perturbation.
> It works well except on one machine.
> On a multi-cpu, If I run the program on cpu 1, I get 23us. It's OK.
> If I run the same program on cpu 0, I get 17373us !
> If I do :
> # echo 0 >/proc/sys/kernel/preempt_max_latency

you can start/stop tracing from userspace too. Then you'll see what
happens. See the attached trace-it.c code. After having activated
user-triggered tracing, do something like this in your testcode:

for (;;) {
gettimeofday(0, 1);
gettimeofday(0, 0);
}

this should measure the maximum userspace delay on that CPU. You can
also read the TSC in the inner loop to validate the kernel tracer:

for (;;) {
gettimeofday(0, 1);
t0 = rdtsc();
t1 = rdtsc();
gettimeofday(0, 0);
if (t1-t0 > max)
print_max();
}

(you should not measure the trace start/stop functions themselves, they
can take alot of time when a maximum-latency event happens.)

Ingo

/*
* Copyright (C) 1999, Ingo Molnar <mingo@xxxxxxxxxx>
*/

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>
#include <linux/unistd.h>

int main (int argc, char **argv)
{
int ret;

if (getuid() != 0) {
fprintf(stderr, "needs to run as root.\n");
exit(1);
}
ret = system("cat /proc/sys/kernel/mcount_enabled >/dev/null 2>/dev/null");
if (ret) {
fprintf(stderr, "CONFIG_LATENCY_TRACING not enabled?\n");
exit(1);
}
system("echo 1 > /proc/sys/kernel/trace_all_cpus");
system("echo 1 > /proc/sys/kernel/trace_enabled");
system("echo 0 > /proc/sys/kernel/trace_freerunning");
system("echo 0 > /proc/sys/kernel/trace_print_at_crash");
system("echo 1 > /proc/sys/kernel/trace_user_triggered");
system("echo 0 > /proc/sys/kernel/trace_verbose");
system("echo 0 > /proc/sys/kernel/preempt_max_latency");
system("echo 0 > /proc/sys/kernel/preempt_thresh");
system("[ -e /proc/sys/kernel/wakeup_timing ] && echo 0 > /proc/sys/kernel/wakeup_timing");
system("echo 1 > /proc/sys/kernel/mcount_enabled");

gettimeofday(0, 1);
usleep(100000);
gettimeofday(0, 0);

system("cat /proc/latency_trace");

return 0;
}