lkml.org 
[lkml]   [2004]   [Feb]   [18]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
FromRusty Russell <>
SubjectRe: keventd_create_kthread
DateThu, 19 Feb 2004 10:12:01 +1100
In message <20040218004648.7471bb37.akpm@osdl.org> 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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:01    [from the cache]
©2003-2008