Re: keventd_create_kthread

From: Rusty Russell
Date: Wed Feb 18 2004 - 18:17:01 EST


In message <20040218004648.7471bb37.akpm@xxxxxxxx> you write:
> wait_task_inactive() will return due to the preemption?
>
> perhaps wait_task_inactive() should wait until the target task leaves state
> TASK_RUNNING.

That's not enough: it can set that and then get preemted. It really
want to return when the task is off the runqueue. The original
wait_task_inactive() does an incredible complicated and AFAICT useless
dance wrt not locking and disabling preempt explicitly. Ingo, how's
this replacement? (And who wrote this code?)

/*
* wait_task_inactive - wait for a thread to unschedule.
*
* The caller must ensure that the task *will* unschedule sometime soon,
* else this function might spin for a *long* time. This function can't
* be called with interrupts off, or it may introduce deadlock with
* smp_call_function() if an IPI is sent by the same process we are
* waiting to become inactive.
*/
void wait_task_inactive(task_t * p)
{
unsigned long flags;
runqueue_t *rq;

repeat:
rq = task_rq_lock(p, &flags);
/* Must be off runqueue entirely, not preempted. */
if (unlikely(p->array)) {
task_rq_unlock(rq, &flags);
cpu_relax();
/* If it's preempted: yield. It could be a while. */
if (!task_running(p))
yield();
goto repeat;
}
task_rq_unlock(rq, &flags);
}

Untested BTW.

Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/