From: Xie XiuQi <xiexiuqi@huawei.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: <mingo@redhat.com>, <linux-kernel@vger.kernel.org>,
<cj.chengjian@huawei.com>
Subject: Re: [PATCH] sched: fix a potential divide error
Date: Thu, 25 Apr 2019 11:52:28 +0800 [thread overview]
Message-ID: <14cdc45e-7a6f-5e1f-e877-10503180ac4e@huawei.com> (raw)
In-Reply-To: <20190423184458.GW4038@hirez.programming.kicks-ass.net>
Hi Peter,
Thanks for your comments.
On 2019/4/24 2:44, Peter Zijlstra wrote:
> On Sat, Apr 20, 2019 at 04:34:16PM +0800, Xie XiuQi wrote:
>> We meet a divide error on 3.10.0 kernel, the error message is bellow:
>
> That is a _realllllllyyyy_ old kernel. I would urge you to upgrade.
I will.
>
>> [499992.287996] divide error: 0000 [#1] SMP
>
>> sched_clock_cpu may not be consistent bwtwen cpus. If a task migrate
>> to another cpu, the se.exec_start was set to that cpu's rq_clock_task
>> by update_stats_curr_start(). Which may not be monotonic.
>>
>> update_stats_curr_start
>> <- set_next_entity
>> <- set_curr_task_fair
>> <- sched_move_task
>
> That is not in fact a cross-cpu migration path. But I see the point.
> Also many migration paths do in fact preserve monotonicity, even when
> the clock is busted, but you're right, not all of them.
>
>> So, if now - p->last_task_numa_placement is -1, then (*period + 1) is
>> 0, and divide error was triggerred at the div operation:
>> task_numa_placement:
>> runtime = numa_get_avg_runtime(p, &period);
>> f_weight = div64_u64(runtime << 16, period + 1); // divide error here
>>
>> In this patch, we make sure period is not less than 0 to avoid this
>> divide error.
>>
>> Signed-off-by: Xie XiuQi <xiexiuqi@huawei.com>
>> Cc: stable@vger.kernel.org
>> ---
>> kernel/sched/fair.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>> index 40bd1e27b1b7..f2abb258fc85 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -2007,6 +2007,10 @@ static u64 numa_get_avg_runtime(struct task_struct *p, u64 *period)
>> if (p->last_task_numa_placement) {
>> delta = runtime - p->last_sum_exec_runtime;
>> *period = now - p->last_task_numa_placement;
>> +
>> + /* Avoid backward, and prevent potential divide error */
>> + if ((s64)*period < 0)
>> + *period = 0;
>> } else {
>> delta = p->se.avg.load_sum;
>> *period = LOAD_AVG_MAX;
>
> Yeah, I suppose that is indeed correct.
>
> I'll try and come up with a better Changelog tomorrow.
Thanks.
--
Thanks,
Xie XiuQi
next prev parent reply other threads:[~2019-04-25 3:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-20 8:34 [PATCH] sched: fix a potential divide error Xie XiuQi
2019-04-23 18:44 ` Peter Zijlstra
2019-04-25 3:52 ` Xie XiuQi [this message]
2019-04-25 8:00 ` Peter Zijlstra
2019-04-25 8:16 ` Xie XiuQi
2019-04-25 18:01 ` [tip:sched/urgent] sched/numa: Fix a possible divide-by-zero tip-bot for Xie XiuQi
2019-04-25 18:04 ` tip-bot for Xie XiuQi
2019-04-25 17:59 ` [PATCH] sched: fix a potential divide error Ingo Molnar
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=14cdc45e-7a6f-5e1f-e877-10503180ac4e@huawei.com \
--to=xiexiuqi@huawei.com \
--cc=cj.chengjian@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).