From: Denys Vlasenko <dvlasenk@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org,
Frederic Weisbecker <fweisbec@gmail.com>,
Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>,
Fernando Luis Vazquez Cao <fernando_b1@lab.ntt.co.jp>,
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Arjan van de Ven <arjan@linux.intel.com>,
Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH 3/3] nohz: Fix iowait overcounting if iowait task migrates
Date: Thu, 24 Apr 2014 20:38:45 +0200 [thread overview]
Message-ID: <53595A35.1070602@redhat.com> (raw)
In-Reply-To: <20140424070726.GY26782@laptop.programming.kicks-ass.net>
On 04/24/2014 09:07 AM, Peter Zijlstra wrote:
> On Wed, Apr 23, 2014 at 09:00:36PM +0200, Denys Vlasenko wrote:
>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>> index 9cae286..08dd220 100644
>> --- a/kernel/sched/core.c
>> +++ b/kernel/sched/core.c
>> @@ -4255,6 +4255,9 @@ EXPORT_SYMBOL_GPL(yield_to);
>> */
>> void __sched io_schedule(void)
>> {
>> +#ifdef CONFIG_NO_HZ_COMMON
>> + int cpu_on_entry = smp_processor_id();
>> +#endif
>> struct rq *rq = raw_rq();
>>
>> delayacct_blkio_start();
>> @@ -4263,13 +4266,23 @@ void __sched io_schedule(void)
>> current->in_iowait = 1;
>> schedule();
>> current->in_iowait = 0;
>> +#ifdef CONFIG_NO_HZ_COMMON
>> + if (atomic_dec_and_test(&rq->nr_iowait)) {
>> + if (smp_processor_id() != cpu_on_entry)
>> + tick_nohz_iowait_to_idle(cpu_on_entry);
>> + }
>> +#else
>> atomic_dec(&rq->nr_iowait);
>> +#endif
>> delayacct_blkio_end();
>> }
>> EXPORT_SYMBOL(io_schedule);
>>
>> long __sched io_schedule_timeout(long timeout)
>> {
>> +#ifdef CONFIG_NO_HZ_COMMON
>> + int cpu_on_entry = smp_processor_id();
>> +#endif
>> struct rq *rq = raw_rq();
>> long ret;
>>
>> @@ -4279,7 +4292,14 @@ long __sched io_schedule_timeout(long timeout)
>> current->in_iowait = 1;
>> ret = schedule_timeout(timeout);
>> current->in_iowait = 0;
>> +#ifdef CONFIG_NO_HZ_COMMON
>> + if (atomic_dec_and_test(&rq->nr_iowait)) {
>> + if (smp_processor_id() != cpu_on_entry)
>> + tick_nohz_iowait_to_idle(cpu_on_entry);
>> + }
>> +#else
>> atomic_dec(&rq->nr_iowait);
>> +#endif
>> delayacct_blkio_end();
>> return ret;
>> }
>
> Why do you insist on writing the same (buggy, see later) code twice?
I don't insist on such a thing. I am modifying existing code
which already has these nearly-identical functions.
I agree with you that they beg for common code being moved into
a shared helper function.
> Its buggy because the smp_processor_id() is used in preemptible context,
> its further buggy because the raw_rq() does it again and could get a rq
> on a different cpu.
>
> What you want is something like:
>
> static inline void io_wait_start(struct rq *rq)
> {
> atomic_inc(&rq->nr_iowait);
> current->in_iowait = 1;
> }
>
> static inline void io_wait_end(struct rq *rq)
> {
> current->in_iowait = 0;
> #ifdef CONFIG_NO_HZ_COMMON
> if (atomic_dec_and_test(&rq->nr_iowait) &&
> cpu_of(rq) != raw_smp_processor_id()) {
> tick_nohz_iowait_end(cpu_of(rq));
> }
> #else
> atomic_dec(&rq->nr_iowait);
> #endif
> }
Thanks, will use this in the next patchset.
next prev parent reply other threads:[~2014-04-24 18:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-23 19:00 [PATCH 1/3] nohz: Only update sleeptime stats locally Denys Vlasenko
2014-04-23 19:00 ` [PATCH 2/3] nohz: Synchronize sleep time stats with memory barriers Denys Vlasenko
2014-04-24 0:16 ` Frederic Weisbecker
2014-04-24 18:36 ` Denys Vlasenko
2014-04-23 19:00 ` [PATCH 3/3] nohz: Fix iowait overcounting if iowait task migrates Denys Vlasenko
2014-04-24 0:37 ` Frederic Weisbecker
2014-04-24 7:07 ` Peter Zijlstra
2014-04-24 18:38 ` Denys Vlasenko [this message]
2014-04-24 8:19 ` Hidetoshi Seto
2014-04-24 18:43 ` Denys Vlasenko
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=53595A35.1070602@redhat.com \
--to=dvlasenk@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=arjan@linux.intel.com \
--cc=fernando_b1@lab.ntt.co.jp \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=peterz@infradead.org \
--cc=seto.hidetoshi@jp.fujitsu.com \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.