linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: yi li <liyi.dev@gmail.com>
To: Gregory Haskins <ghaskins@novell.com>
Cc: linux-rt-users@vger.kernel.org
Subject: Re: A question about cpu_idle()
Date: Thu, 22 Oct 2009 12:30:06 +0800	[thread overview]
Message-ID: <a0e7fce50910212130h385cdbe1ucbb4fe00233eb0bb@mail.gmail.com> (raw)
In-Reply-To: <4ADE5A2B0200005A00057082@sinclair.provo.novell.com>

On Wed, Oct 21, 2009 at 12:47 PM, Gregory Haskins <ghaskins@novell.com> wrote:
>>>> On 10/20/2009 at 11:07 PM, in message
> <a0e7fce50910202007l587d2cfcu91b455ff0486110b@mail.gmail.com>, yi li
> <liyi.dev@gmail.com> wrote:
>> Hi RT users,
>>
>> While reading patch-2.6.31.4-rt14, there is a patch for cpu_idle()
>> which I cannot understand.
>>
>> Could anyone kindly enough to tell me what is patch used for?
>
> Hi Yi,
>
> I believe that logic is ensuring that the task is put to sleep instead of simply being preempted.  The difference is that a preemption leaves the task on the RQ, whereas calling schedule() may or may not leave the caller on the RQ, depending on the status of current->state.  The local_irq_disable+__preempt_enable_no_resched dance is a way of legally calling schedule() while effectively preventing preemption (since interrupts-off also disables preemption).  The difference is that its legal to call __schedule() with interrupts off, but you can't with preempt_disable().
>
> Long story short, the enable_no_resched() + schedule() pattern is only ever used when you want to make sure the task fully sleeps.  However without this patch to disable interrupts, the original code appears racy and thus probably had issues achieving its intended goal.
>
> HTH,
> -Greg
>

Thanks Greg for the kind reply.

But due to my limited knowledge on PREEMPT_RT, I still not fully understand.

Given schedule() is defined as:

asmlinkage void __sched schedule(void)
{
need_resched:
	local_irq_disable();
	__schedule();
	local_irq_enable();

	if (need_resched())
		goto need_resched;
}

Comparing bellow two code sequences:

1)
preempt_enable_no_resched();
schedule();
preempt_disable();


2)
local_irq_disable();
__preempt_enable_no_resched();
__schedule();
preempt_disable();
local_irq_enable();

It seems to me, the main difference is to change the order of
"preempt_enable_no_sched() / local_irq_disable()":
i.e, from:

"preempt_enable_no_sched();
/* Yi: will some race condition happens here? */
 local_irq_disable();
__schedule();"

to:

"local_irq_disable(); /* Yi: disables irq effectively disables preemption?  */
preempt_enable_no_sched();
__schedule();"

Regards,
-Yi

>>
>>
>> diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
>> index ebefb54..c8d0ece 100644
>> --- a/arch/x86/kernel/process_64.c
>> +++ b/arch/x86/kernel/process_64.c
>> @@ -152,9 +152,11 @@ void cpu_idle(void)
>>                 }
>>
>>                 tick_nohz_restart_sched_tick();
>> -               preempt_enable_no_resched();
>> -               schedule();
>> +               local_irq_disable();
>> +               __preempt_enable_no_resched();
>> +               __schedule();
>>                 preempt_disable();
>> +               local_irq_enable();
>>         }
>>  }
>>
>> Regards,
>> -Yi
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2009-10-22  4:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-21  3:07 A question about cpu_idle() yi li
2009-10-21  4:47 ` Gregory Haskins
2009-10-22  4:30   ` yi li [this message]
2009-10-22 12:34     ` Gregory Haskins
2009-10-22 16:24       ` yi li
2009-10-22 18:59         ` Gregory Haskins
2009-10-24 10:04           ` yi li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a0e7fce50910212130h385cdbe1ucbb4fe00233eb0bb@mail.gmail.com \
    --to=liyi.dev@gmail.com \
    --cc=ghaskins@novell.com \
    --cc=linux-rt-users@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).