Re: [PATCH v4] stop_machine: Avoid a sleep and wakeup in the stop_one_cpu()
Hi Peter, What should I do next? Thanks. Cheng on 09/14/2016 10:01 AM, Cheng Chao wrote: > In case @cpu == smp_proccessor_id(), we can avoid a sleep+wakeup > by doing a preemption. > > the caller such as sched_exec can benefit from this change. > > Signed-off-by: Cheng Chao > Cc: Oleg Nesterov > Cc: Peter Zijlstra > --- > kernel/sched/core.c | 8 ++-- > kernel/stop_machine.c | 5 + > 2 files changed, 11 insertions(+), 2 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index a0086a5..283b662 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); > > diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c > index 4a1ca5f..1a24890 100644 > --- a/kernel/stop_machine.c > +++ b/kernel/stop_machine.c > @@ -126,6 +126,11 @@ int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, > void *arg) > cpu_stop_init_done(&done, 1); > if (!cpu_stop_queue_work(cpu, &work)) > return -ENOENT; > + /* > + * In case @cpu == smp_proccessor_id() we can avoid a sleep+wakeup > + * by doing a preemption. > + */ > + cond_resched(); > wait_for_completion(&done.completion); > return done.ret; > } >
Re: [PATCH v4] stop_machine: Avoid a sleep and wakeup in the stop_one_cpu()
On 09/14, Cheng Chao wrote: > > --- 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; > + } Cough ;) again, I leave this to Peter... But imo this change should be documented or perhaps even separated. It looks fine to me, but this has nothing to do with "we can avoid a sleep+wakeup by doing a preemption" from the changelog. This is another improvement, and a small note in the changelog can unconfuse the reader of git blame/log. Oleg.
[PATCH v4] stop_machine: Avoid a sleep and wakeup in the stop_one_cpu()
In case @cpu == smp_proccessor_id(), we can avoid a sleep+wakeup by doing a preemption. the caller such as sched_exec can benefit from this change. Signed-off-by: Cheng Chao Cc: Oleg Nesterov Cc: Peter Zijlstra --- kernel/sched/core.c | 8 ++-- kernel/stop_machine.c | 5 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a0086a5..283b662 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); diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index 4a1ca5f..1a24890 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -126,6 +126,11 @@ int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg) cpu_stop_init_done(&done, 1); if (!cpu_stop_queue_work(cpu, &work)) return -ENOENT; + /* +* In case @cpu == smp_proccessor_id() we can avoid a sleep+wakeup +* by doing a preemption. +*/ + cond_resched(); wait_for_completion(&done.completion); return done.ret; } -- 2.4.11