Skip to contentSkip to conversation

Q: a bogus task_running() check in try_to_wake_up() ?

DISCUSSION Oleg Nesterov 2 participants 3 messages Jul 15, 2007 – Jul 18, 2007

lore
Share & tools
lore
#0 lore raw

try_to_wake_up:

	if (p->se.on_rq)
		goto out_running;

	...

	if (unlikely(task_running(rq, p)))
		goto out_activate;

How it possible that rq->curr has on_rq == 0 ?

AFAICS, this can only happen if this task is rq->idle. But idle threads should not sleep, we have a special "scheduling from the idle thread!" check in schedule().

Thanks in advance,

Oleg.

#1 lore raw
Quoted 10 lines · Oleg Nesterov

try_to_wake_up:

	if (p->se.on_rq)
		goto out_running;

	...

	if (unlikely(task_running(rq, p)))
		goto out_activate;
Quoted 5 lines

How it possible that rq->curr has on_rq == 0 ?

AFAICS, this can only happen if this task is rq->idle. But idle threads should not sleep, we have a special "scheduling from the idle thread!" check in schedule().

it's also possible if an arch uses __ARCH_WANT_INTERRUPTS_ON_CTXSW, right?

[ btw., we dont have a special "scheduling from the idle thread" check
in schedule() anymore, it's now in kernel/sched_idletask.c :-) ]

Ingo

#2 lore raw
Quoted 13 lines · Ingo Molnar
Quoted 10 lines · Oleg Nesterov

try_to_wake_up:

	if (p->se.on_rq)
		goto out_running;

	...

	if (unlikely(task_running(rq, p)))
		goto out_activate;
Quoted 8 lines
Quoted 5 lines

How it possible that rq->curr has on_rq == 0 ?

AFAICS, this can only happen if this task is rq->idle. But idle threads should not sleep, we have a special "scheduling from the idle thread!" check in schedule().

it's also possible if an arch uses __ARCH_WANT_INTERRUPTS_ON_CTXSW, right?

Ah, got it. I guess you meant __ARCH_WANT_UNLOCKED_CTXSW though.

In that case schedule() drops rq->lock before the context switch, but doesn't clear ->oncpu. So, task_running(p) means we must not activate "p" on another CPU, otherwise it could be scheduled before the switch-in-progress completes.

Thanks a lot!

Oleg.