The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* Why we need to call cpu_idle() with preemption disabled
@ 2010-03-16  9:01 Wu Zhangjin
  2010-03-16 15:04 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Wu Zhangjin @ 2010-03-16  9:01 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Steven Rostedt, linux-kernel

Hi, Thomas

Just traced the preemption latency of 2.6.33-rt7 on my Yeeloong netbook
with the preemptoff tracer of Ftrace and found it is very big in
cpu_idle(), more than 1000 us.

And found that we have called cpu_idle() in init/main.c with preemption
disabled? why we need to do it? can we simply call it with preemption
enabled?

diff --git a/init/main.c b/init/main.c
index 48393c0..437ac34 100644
--- a/init/main.c
+++ b/init/main.c
@@ -428,9 +428,8 @@ static noinline void __init_refok rest_init(void)
         */
        init_idle_bootup_task(current);
        preempt_enable_and_schedule();
-       preempt_disable();
 
-       /* Call into cpu_idle with preempt disabled */
+       /* There is no reason for calling cpu_idle with preemption
disabled */
        cpu_idle();
 }

After removing that preempt_disable() and the related operations around
the calling to __schedule() in the cpu_idle(), the result becomes around
200 us, which is acceptable for I have enabled several Ftrace tracers.

Best Regards,
	Wu Zhangjin


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: Why we need to call cpu_idle() with preemption disabled
  2010-03-16  9:01 Why we need to call cpu_idle() with preemption disabled Wu Zhangjin
@ 2010-03-16 15:04 ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2010-03-16 15:04 UTC (permalink / raw)
  To: wuzhangjin; +Cc: Thomas Gleixner, linux-kernel

On Tue, 2010-03-16 at 17:01 +0800, Wu Zhangjin wrote:
> Hi, Thomas
> 
> Just traced the preemption latency of 2.6.33-rt7 on my Yeeloong netbook
> with the preemptoff tracer of Ftrace and found it is very big in
> cpu_idle(), more than 1000 us.
> 
> And found that we have called cpu_idle() in init/main.c with preemption
> disabled? why we need to do it? can we simply call it with preemption
> enabled?
> 
> diff --git a/init/main.c b/init/main.c
> index 48393c0..437ac34 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -428,9 +428,8 @@ static noinline void __init_refok rest_init(void)
>          */
>         init_idle_bootup_task(current);
>         preempt_enable_and_schedule();
> -       preempt_disable();
>  
> -       /* Call into cpu_idle with preempt disabled */
> +       /* There is no reason for calling cpu_idle with preemption
> disabled */
>         cpu_idle();
>  }
> 
> After removing that preempt_disable() and the related operations around
> the calling to __schedule() in the cpu_idle(), the result becomes around
> 200 us, which is acceptable for I have enabled several Ftrace tracers.

The preempt disable is needed for idle since cpu_idle() expects
preemption to be disabled.

But this can cause the latency tracer to do show false latencies. What
you need to add in arch/mips/kernel/process.c: cpu_idle()

+			stop_critical_timings();
			if (cpu_wait)
				(*cpu_wait)();
+			start_critical_timings();


This two functions tell the latency tracer to ignore the time spent in
idle, while idle will wake up when an interrupt happens anyway.

-- Steve



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-03-16 15:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-16  9:01 Why we need to call cpu_idle() with preemption disabled Wu Zhangjin
2010-03-16 15:04 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox