Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp847545imm; Thu, 5 Jul 2018 09:55:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfR6h7EasCmV//MZKKUQet/iciQYgrWkr/dLx9VcH29uwQJTC+eDMtqL93sLygdogAfOeSO X-Received: by 2002:a17:902:2864:: with SMTP id e91-v6mr6824384plb.240.1530809728402; Thu, 05 Jul 2018 09:55:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530809728; cv=none; d=google.com; s=arc-20160816; b=ZV2iRiCN4zixzuItxFf5x0ACa6QzR7ewcpOgMJdS9Q5td7mlCzbYOaJJPfCPcPtC7j PZ2CFzi9BTRJsSgn0mAUwOzKwr6ywDz1KPsvX3IMX+m3IRa81XGhwM5wM0kj6j5CBWWe JzU9B8lxkPVvrXnLboYymfeECbfjZbVV+1QJJwg70HW2O2ci3D3R+viflFBcKPVYs+xO kVsJcZDw7GhvfvOriWitPtm7RVskrIiGFrh1bP2Vtg5OVyOHEFQMuQex3ba8yrcdGDp4 NMYIZCloIBANO4hR0ig8DJFfLU+upgMFwyJri6176LCG31+76sKx4tLuKBiRvtYV0FjY nx4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=eIewUzsz1DQi8WwBOHCcO5kijT2zoRyGeGcRuo5TI2k=; b=higKxkDpfzGupvEHuXCMiimmInENj6hzkiSLl73FVGUSbcJPojwcWf9c+2VdiLIWVS BmRJnBVALdvOIz0JV0Kloz/euSST0jUdVvGv8fqIFni9hbU5Irn0khB+zStjpFUBK7Oe S84zasGJzVyl9CJJAJvJAtEsdsyGG04ULEfITNgmWRH9zZmN5zJsk9aidqOquIq5wxd9 0JKPjaAYXRftGq5xzY1o0FJIRr0mn/TsyZPpHLc6KF34QgQzE05d2aWjByK6rXouPd+S cPJCSlIjSU4W7uosyIWVGSsy/8+17JfM0L1mtHFzW7ymSzlCwFtBoIn4BKoV3nTl/h4Y cc/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r5-v6si6158491pgr.491.2018.07.05.09.55.01; Thu, 05 Jul 2018 09:55:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753982AbeGEQyK (ORCPT + 99 others); Thu, 5 Jul 2018 12:54:10 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:54008 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753941AbeGEQyF (ORCPT ); Thu, 5 Jul 2018 12:54:05 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 21A7D7A9; Thu, 5 Jul 2018 09:54:05 -0700 (PDT) Received: from [10.1.206.36] (e113632-lin.cambridge.arm.com [10.1.206.36]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2D5D43F5BA; Thu, 5 Jul 2018 09:54:04 -0700 (PDT) Subject: Re: [PATCH] sched/fair: Avoid divide by zero when rebalancing domains To: Matt Fleming Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Ingo Molnar , Mike Galbraith References: <20180704142455.16035-1-matt@codeblueprint.co.uk> <55afee27-4143-e08c-b254-0d68a05d5ee6@arm.com> <20180705132726.GB3864@codeblueprint.co.uk> From: Valentin Schneider Message-ID: <94149109-a54c-fc5d-7b56-e786c8de5b94@arm.com> Date: Thu, 5 Jul 2018 17:54:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180705132726.GB3864@codeblueprint.co.uk> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/07/18 14:27, Matt Fleming wrote: > On Thu, 05 Jul, at 11:10:42AM, Valentin Schneider wrote: >> Hi, >> >> On 04/07/18 15:24, Matt Fleming wrote: >>> It's possible that the CPU doing nohz idle balance hasn't had its own >>> load updated for many seconds. This can lead to huge deltas between >>> rq->avg_stamp and rq->clock when rebalancing, and has been seen to >>> cause the following crash: >>> >>> divide error: 0000 [#1] SMP >>> Call Trace: >>> [] update_sd_lb_stats+0xe8/0x560 My confusion comes from not seeing where that crash happens. Would you mind sharing the associated line number? I can feel the "how did I not see this" from there but it can't be helped :( >>> [] find_busiest_group+0x2d/0x4b0 >>> [] load_balance+0x170/0x950 >>> [] rebalance_domains+0x13f/0x290 >>> [] __do_softirq+0xec/0x300 >>> [] irq_exit+0xfa/0x110 >>> [] reschedule_interrupt+0xc9/0xd0 >>> >> >> Do you have some sort of reproducer for that crash? If not I guess I can cook >> something up with a quiet userspace & rt-app, though I've never seen that one >> on arm64. > > Unfortunately no, I don't have a reproduction case. Would love to have > one to verify the patch though. > >>> Make sure we update the rq clock and load before balancing. >>> >>> Cc: Ingo Molnar >>> Cc: Mike Galbraith >>> Cc: Peter Zijlstra >>> Signed-off-by: Matt Fleming >>> --- >>> kernel/sched/fair.c | 10 ++++++++++ >>> 1 file changed, 10 insertions(+) >>> >>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >>> index 2f0a0be4d344..2c81662c858a 100644 >>> --- a/kernel/sched/fair.c >>> +++ b/kernel/sched/fair.c >>> @@ -9597,6 +9597,16 @@ static bool _nohz_idle_balance(struct rq *this_rq, unsigned int flags, >>> */ >>> smp_mb(); >>> >>> + /* >>> + * Ensure this_rq's clock and load are up-to-date before we >>> + * rebalance since it's possible that they haven't been >>> + * updated for multiple schedule periods, i.e. many seconds. >>> + */ >>> + raw_spin_lock_irq(&this_rq->lock); >>> + update_rq_clock(this_rq); >>> + cpu_load_update_idle(this_rq); >>> + raw_spin_unlock_irq(&this_rq->lock); >>> + >> >> I'm failing to understand why the updates further down below are seemingly >> not enough. After we've potentially done >> >> update_rq_clock(rq); >> cpu_load_update_idle(rq); >> >> for all nohz cpus != this_cpu, we still end up doing: >> >> if (idle != CPU_NEWLY_IDLE) { >> update_blocked_averages(this_cpu); >> has_blocked_load |= this_rq->has_blocked_load; >> } >> >> which should properly update this_rq's clock and load before we attempt to do >> any balancing on it. > > But cpu_load_update_idle() and update_blocked_averages() are not the same > thing. > Right, we don't do any rq->cpu_load[] update for this_rq in the current nohz code (i.e. by using update_blocked_averages()), which I think we do want to do. I'm just miserably failing to find how not doing this leads to a div by 0.