From: Kees Cook <keescook@chromium•org>
To: Peter Zijlstra <peterz@infradead•org>
Cc: juri.lelli@redhat•com, mark.rutland@arm•com, heiko@sntech•de,
geert+renesas@glider•be, catalin.marinas@arm•com,
bsegall@google•com, will@kernel•org, mpe@ellerman•id.au,
linux@armlinux•org.uk, dietmar.eggemann@arm•com,
ben.dooks@codethink•co.uk, mgorman@suse•de, cl@rock-chips•com,
huangtao@rock-chips•com, anshuman.khandual@arm•com,
rostedt@goodmis•org, tglx@linutronix•de, surenb@google•com,
mingo@redhat•com, allison@lohutok•net,
linux-arm-kernel@lists•infradead.org, wad@chromium•org,
gregkh@linuxfoundation•org, linux-kernel@vger•kernel.org,
luto@amacapital•net, george_davis@mentor•com,
sudeep.holla@arm•com, akpm@linux-foundation•org, info@metux•net,
kstewart@linuxfoundation•org
Subject: Re: [PATCH v1 1/1] sched/fair: do not preempt current task if it is going to call schedule()
Date: Thu, 5 Mar 2020 09:30:30 -0800 [thread overview]
Message-ID: <202003050929.DD4DB3529@keescook> (raw)
In-Reply-To: <20200305095803.GW2596@hirez.programming.kicks-ass.net>
On Thu, Mar 05, 2020 at 10:58:03AM +0100, Peter Zijlstra wrote:
> On Thu, Mar 05, 2020 at 04:16:11PM +0800, cl@rock-chips•com wrote:
> > From: Liang Chen <cl@rock-chips•com>
> >
> > when we create a kthread with ktrhead_create_on_cpu(),the child thread
> > entry is ktread.c:ktrhead() which will be preempted by the parent after
> > call complete(done) while schedule() is not called yet,then the parent
> > will call wait_task_inactive(child) but the child is still on the runqueue,
> > so the parent will schedule_hrtimeout() for 1 jiffy,it will waste a lot of
> > time,especially on startup.
> >
> > parent child
> > ktrhead_create_on_cpu()
> > wait_fo_completion(&done) -----> ktread.c:ktrhead()
> > |----- complete(done);--wakeup and preempted by parent
> > kthread_bind() <------------| |-> schedule();--dequeue here
> > wait_task_inactive(child) |
> > schedule_hrtimeout(1 jiffy) -|
> >
> > So we hope the child just wakeup parent but not preempted by parent, and the
> > child is going to call schedule() soon,then the parent will not call
> > schedule_hrtimeout(1 jiffy) as the child is already dequeue.
> >
> > The same issue for ktrhead_park()&&kthread_parkme().
> > This patch can save 120ms on rk312x startup with CONFIG_HZ=300.
>
> > diff --git a/kernel/kthread.c b/kernel/kthread.c
> > index b262f47046ca..8a4e4c9cdc22 100644
> > --- a/kernel/kthread.c
> > +++ b/kernel/kthread.c
> > @@ -199,8 +199,10 @@ static void __kthread_parkme(struct kthread *self)
> > if (!test_bit(KTHREAD_SHOULD_PARK, &self->flags))
> > break;
> >
> > + set_tsk_going_to_sched(current);
> > complete(&self->parked);
> > schedule();
> > + clear_tsk_going_to_sched(current);
> > }
> > __set_current_state(TASK_RUNNING);
> > }
> > @@ -245,8 +247,10 @@ static int kthread(void *_create)
> > /* OK, tell user we're spawned, wait for stop or wakeup */
> > __set_current_state(TASK_UNINTERRUPTIBLE);
> > create->result = current;
> > + set_tsk_going_to_sched(current);
> > complete(done);
> > schedule();
> > + clear_tsk_going_to_sched(current);
> >
> > ret = -EINTR;
> > if (!test_bit(KTHREAD_SHOULD_STOP, &self->flags)) {
>
> Were you looking for this? I think it does the same without having
> fallen from the ugly tree...
>
> diff --git a/kernel/kthread.c b/kernel/kthread.c
> index b262f47046ca..62699ff414f4 100644
> --- a/kernel/kthread.c
> +++ b/kernel/kthread.c
> @@ -199,8 +199,10 @@ static void __kthread_parkme(struct kthread *self)
> if (!test_bit(KTHREAD_SHOULD_PARK, &self->flags))
> break;
>
> + preempt_disable()
> complete(&self->parked);
> - schedule();
> + schedule_preempt_disabled();
> + preempt_enable();
> }
> __set_current_state(TASK_RUNNING);
> }
> @@ -245,8 +247,10 @@ static int kthread(void *_create)
> /* OK, tell user we're spawned, wait for stop or wakeup */
> __set_current_state(TASK_UNINTERRUPTIBLE);
> create->result = current;
> + preempt_disable()
> complete(done);
> - schedule();
> + schedule_preempt_disabled();
> + preempt_enable();
>
> ret = -EINTR;
> if (!test_bit(KTHREAD_SHOULD_STOP, &self->flags)) {
That's much nicer, yes! :) As I said, I don't know much about the
scheduler. ;)
--
Kees Cook
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists•infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-03-05 17:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-05 8:16 [PATCH v1 0/1] wait_task_inactive() spend too much time on system startup cl
2020-03-05 8:16 ` [PATCH v1 1/1] sched/fair: do not preempt current task if it is going to call schedule() cl
2020-03-05 8:43 ` Kees Cook
2020-03-05 9:58 ` Peter Zijlstra
2020-03-05 17:30 ` Kees Cook [this message]
2020-03-05 13:22 ` kbuild test robot
2020-03-05 13:33 ` kbuild test robot
2020-03-05 13:33 ` kbuild test robot
2020-03-05 13:59 ` kbuild test robot
2020-03-05 14:38 ` kbuild test robot
2020-03-05 15:14 ` [kbuild-all] " Li, Philip
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=202003050929.DD4DB3529@keescook \
--to=keescook@chromium$(echo .)org \
--cc=akpm@linux-foundation$(echo .)org \
--cc=allison@lohutok$(echo .)net \
--cc=anshuman.khandual@arm$(echo .)com \
--cc=ben.dooks@codethink$(echo .)co.uk \
--cc=bsegall@google$(echo .)com \
--cc=catalin.marinas@arm$(echo .)com \
--cc=cl@rock-chips$(echo .)com \
--cc=dietmar.eggemann@arm$(echo .)com \
--cc=geert+renesas@glider$(echo .)be \
--cc=george_davis@mentor$(echo .)com \
--cc=gregkh@linuxfoundation$(echo .)org \
--cc=heiko@sntech$(echo .)de \
--cc=huangtao@rock-chips$(echo .)com \
--cc=info@metux$(echo .)net \
--cc=juri.lelli@redhat$(echo .)com \
--cc=kstewart@linuxfoundation$(echo .)org \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linux@armlinux$(echo .)org.uk \
--cc=luto@amacapital$(echo .)net \
--cc=mark.rutland@arm$(echo .)com \
--cc=mgorman@suse$(echo .)de \
--cc=mingo@redhat$(echo .)com \
--cc=mpe@ellerman$(echo .)id.au \
--cc=peterz@infradead$(echo .)org \
--cc=rostedt@goodmis$(echo .)org \
--cc=sudeep.holla@arm$(echo .)com \
--cc=surenb@google$(echo .)com \
--cc=tglx@linutronix$(echo .)de \
--cc=wad@chromium$(echo .)org \
--cc=will@kernel$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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