On Mon, Feb 24, 2014 at 08:04:25PM +0100, Daniel Lezcano wrote:
> >+            /*
> >+             * Since we fell out of the loop above, we know
> >+             * TIF_NEED_RESCHED must be set, propagate it into
> >+             * PREEMPT_NEED_RESCHED.
> >+             *
> >+             * This is required because for polling idle loops we will
> >+             * not have had an IPI to fold the state for us.
> >+             */
> >+            preempt_set_need_resched();
> >             tick_nohz_idle_exit();
> >             schedule_preempt_disabled();
> 
> So IIUC, the mainloop has two states: one where it is blocked on a HLT/WFI
> instruction (or about to enter/ exit this state) and another one outside of
> this blocking section.

Almost; on x86 we have an monitor/mwait construct that blocks waiting
for a cacheline write. We point it at the thread_info->flags line. So
the TIF_NEED_RESCHED write from the other CPU wakes us up.

So no need to send an IPI after we write that flag.

> When the idle task is blocked on HLT/WFI, it needs the IPI-reschedule in
> order to be woken up and rescheduled. But if it is outside this section, the
> idle task is not waiting for an interrupt and an expensive IPI can be saved
> by just setting the TS_POLLING flag, the scheduler will check this flag and
> won't send the IPI.
> 
> But 'set_preempt_need_resched' is called from the IPI handler. So if no IPI
> is sent because the idle task is in polling state, we have to set it
> ourself.
> 
> Now, the difference between the old code with 'tif_need_resched()' is
> because we don't need to check it because it is always true.
> 
> Am I right ?

Yah, also it closes a very narrow window where TIF_NEED_RESCHED wasn't
set at the end of the while (!need_resched()) but is at the top.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to