mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [RFC] Thread Migration Preemption - v4
Date: Sun, 15 Jul 2007 00:23:56 +0400	[thread overview]
Message-ID: <20070714202356.GA137@tv-sign.ru> (raw)
In-Reply-To: <20070714184237.GI6975@Krystal>

On 07/14, Mathieu Desnoyers wrote:
>
> @@ -4891,10 +4948,42 @@ static int migration_thread(void *data)
>  		list_del_init(head->next);
>  
>  		spin_unlock(&rq->lock);
> -		__migrate_task(req->task, cpu, req->dest_cpu);
> +		migrated = __migrate_task(req->task, cpu, req->dest_cpu);
>  		local_irq_enable();
> -
> -		complete(&req->done);
> +		if (!migrated) {
> +			/*
> +			 * If the process has not been migrated, let it run
> +			 * until it reaches a migration_check() so it can
> +			 * wake us up.
> +			 */
> +			spin_lock_irq(&rq->lock);
> +			head = &rq->migration_queue;
> +			list_add(&req->list, head);
> +			if (req->task->se.on_rq
> +					|| !task_migrate_count(req->task)) {
> +				/*
> +				 * The process is on the runqueue, it could
> +				 * exit its critical section at any moment,
> +				 * don't race with it and retry actively.
> +				 * Also, if the thread is not on the runqueue
> +				 * and has a zero migration count
> +				 * (__migrate_task failed because cpus allowed
> +				 * changed), just retry.
> +				 */
> +				spin_unlock_irq(&rq->lock);
> +				continue;

Again, this can deadlock. migration_thread() is SCHED_FIFO, and it shares the
same CPU with req->task. We are doing a busy-wait loop, req->task may have no
chance to finish its critical section.

> +			}
> +			set_tsk_thread_flag(req->task, TIF_NEED_MIGRATE);
> +			set_current_state(TASK_INTERRUPTIBLE);
> +			spin_unlock_irq(&rq->lock);
> +			/*
> +			 * Wait for the process currently in its critical
> +			 * section.
> +			 */
> +			wake_up_process(req->task);
> +			schedule();

As Peter pointed out, we hold up all other migration requests.

And worse, this can hang forever (until another req comes). do_check_migrate()
can wake_up() the wrong rq.

set_current_state(TASK_INTERRUPTIBLE) is bogus, we can miss a wakeup from
(say) sched_migrate_task().

Oleg.


  parent reply	other threads:[~2007-07-14 20:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-06  6:02 [RFC] Thread Migration Preemption Oleg Nesterov
2007-07-06 14:23 ` Mathieu Desnoyers
2007-07-06 14:56   ` Oleg Nesterov
2007-07-11  4:49     ` [RFC] Thread Migration Preemption - v2 Mathieu Desnoyers
2007-07-11 16:36       ` Oleg Nesterov
2007-07-14 18:27         ` Mathieu Desnoyers
2007-07-14 19:56           ` Oleg Nesterov
2007-07-14 18:40         ` [RFC] Thread Migration Preemption - v3 Mathieu Desnoyers
2007-07-14 18:42         ` [RFC] Thread Migration Preemption - v4 Mathieu Desnoyers
2007-07-14 19:14           ` Peter Zijlstra
2007-07-14 20:25             ` Mathieu Desnoyers
2007-07-14 19:30           ` Peter Zijlstra
2007-07-14 20:26             ` Mathieu Desnoyers
2007-07-14 20:23           ` Oleg Nesterov [this message]
2007-07-14 20:33             ` Mathieu Desnoyers
2007-07-14 20:42               ` Oleg Nesterov

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=20070714202356.GA137@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@polymtl.ca \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.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

all inboxes | Powered by JetHome®