From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757921AbcILLhd (ORCPT ); Mon, 12 Sep 2016 07:37:33 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:56201 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754771AbcILLhc (ORCPT ); Mon, 12 Sep 2016 07:37:32 -0400 Date: Mon, 12 Sep 2016 13:37:27 +0200 From: Peter Zijlstra To: Cheng Chao Cc: mingo@kernel.org, oleg@redhat.com, tj@kernel.org, akpm@linux-foundation.org, chris@chris-wilson.co.uk, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] stop_machine: Make migration_cpu_stop() does useful works for CONFIG_PREEMPT_NONE Message-ID: <20160912113727.GQ10153@twins.programming.kicks-ass.net> References: <1473408834-6122-1-git-send-email-chengchao@kedacom.com> <1473497532-5440-1-git-send-email-cs.os.kernel@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1473497532-5440-1-git-send-email-cs.os.kernel@gmail.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 10, 2016 at 04:52:12PM +0800, Cheng Chao wrote: > For CONFIG_PREEMPT_NONE=y, when sched_exec() needs migration, sched_exec() > calls stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg). > > If the migration_cpu_stop() can not migrate,why do we call stop_one_cpu()? > It just makes the task TASK_UNINTERRUPTIBLE, wakes up the stopper thread, > executes migration_cpu_stop(), and the stopper thread wakes up the task. > > But in fact, all above works are almost useless(wasteful),the reason is > migration_cpu_stop() can not migrate. why? migration_cpu_stop() needs the > task is TASK_ON_RQ_QUEUED before it calls __migrate_task(). > > This patch keeps the task TASK_RUNNING instead of TASK_UNINTERRUPTIBLE, > so the migration_cpu_stop() can do useful works. OK, completely confused. What!? /me ponders.... So what you're saying is that migration_stop_cpu() doesn't work because wait_for_completion() dequeues the task. True I suppose. Not sure I like your solution, nor your implementation of the solution much though. I would much prefer an unconditional cond_resched() there, but also, I think we should do what __migrate_swap_task() does, and set wake_cpu. So something like so.. --- kernel/sched/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index ddd5f48551f1..ade772aa9610 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1063,8 +1063,12 @@ static int migration_cpu_stop(void *data) * holding rq->lock, if p->on_rq == 0 it cannot get enqueued because * we're holding p->pi_lock. */ - if (task_rq(p) == rq && task_on_rq_queued(p)) - rq = __migrate_task(rq, p, arg->dest_cpu); + if (task_rq(p) == rq) { + if (task_on_rq_queued(p)) + rq = __migrate_task(rq, p, arg->dest_cpu); + else + p->wake_cpu = arg->dest_cpu; + } raw_spin_unlock(&rq->lock); raw_spin_unlock(&p->pi_lock);