Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2307589ybl; Thu, 15 Aug 2019 09:42:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqylzTefZklLPysZuPPMTjxHZRkwbaThHcNGqbN5njNNZpoXUuRk4YxuQ6tpenVZNfBg4hos X-Received: by 2002:a17:902:28a4:: with SMTP id f33mr4949804plb.50.1565887375320; Thu, 15 Aug 2019 09:42:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565887375; cv=none; d=google.com; s=arc-20160816; b=wKTBE5XGKmYdo8sMkJlvD6RFZ4iqZJ4AMZA9/yckXSgjmTQZ5ynsEUQWslNHuwTGoL fusnUD7P+2Zjyq26eJfdFGf/FAEIeGh5H8s6sSaWnCR2B7PkAuGt917RmZJrh1IzqTZH yLDk1YKY8nmLYaCBhYy3CdG6jDpZjBGPJUVyybtrohHkTLyXYcKP9bZtmwNGq8GqxxyY adojR3mk78EnTeDnWaWSFsrUNKxUn4ouddNEijljK2KXR9QdNws0Xzq7ZyljomGUM+9x 9Frne4f/VyAtuybGeFB/Wq58bTJ/EhuZ+Lw6ATvLmRxX5bueC6BrDWuGw47cgnByjnfb Cjdw== 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; bh=MwRU86QghK4JKneigOjayBjp+QPs2/ri+HxF0dqH1vc=; b=MGUi+NPY0NOz6RsHSFnpMBB6k/5SIetP3LPtW6iYusuD46YWl9VZNvNCKHfRlwip3t xT3M5EfT7YE8hZcJ47CBxorZlFoKCKk14I5o/Lah5bs77kCqMZqpS/8M6GyM8h97I7Y0 brNfRhdmV75CCZrgNPMsivS3fCcDCvCgeyDqVcERhG0c05OK2M9yMofYuYsPvsHGHP5o RK4e3fWtrpXzaINLp2hrcxEcf3Ykwi4I/7MgzFeC8E5e9R1aebG+VcC8k8SB71jI/g/x VjwxwwieFJJ3uIfLqsd7klJ812JXypynt3lLJnCODxM8TOMTtIvqSCg6SBXAbEzxSxgl /QvA== 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 b3si2256200pld.224.2019.08.15.09.42.40; Thu, 15 Aug 2019 09:42:55 -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 S1731269AbfHOQgr (ORCPT + 99 others); Thu, 15 Aug 2019 12:36:47 -0400 Received: from foss.arm.com ([217.140.110.172]:46420 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728348AbfHOQgr (ORCPT ); Thu, 15 Aug 2019 12:36:47 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 620AA28; Thu, 15 Aug 2019 09:36:46 -0700 (PDT) Received: from [10.1.194.37] (e113632-lin.cambridge.arm.com [10.1.194.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 25F4A3F706; Thu, 15 Aug 2019 09:36:44 -0700 (PDT) Subject: Re: [PATCH] sched/fair: don't assign runtime for throttled cfs_rq To: Liangyan , Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org Cc: shanpeic@linux.alibaba.com, xlpang@linux.alibaba.com References: <20190814180021.165389-1-liangyan.peng@linux.alibaba.com> From: Valentin Schneider Message-ID: <2994a6ee-9238-5285-3227-cb7084a834c8@arm.com> Date: Thu, 15 Aug 2019 17:36:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190814180021.165389-1-liangyan.peng@linux.alibaba.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14/08/2019 19:00, Liangyan wrote: > do_sched_cfs_period_timer() will refill cfs_b runtime and call > distribute_cfs_runtime() to unthrottle cfs_rq, sometimes cfs_b->runtime > will allocate all quota to one cfs_rq incorrectly. > This will cause other cfs_rq can't get runtime and will be throttled. > We find that one throttled cfs_rq has non-negative > cfs_rq->runtime_remaining and cause an unexpetced cast from s64 to u64 > in snippet: distribute_cfs_runtime() { > runtime = -cfs_rq->runtime_remaining + 1; }. > This cast will cause that runtime will be a large number and > cfs_b->runtime will be subtracted to be zero at last. > I'm a complete CFS bandwidth noob but let me give this a try... -Wconversion does pick this up (turning this thing on made me understand why it's not on by default) kernel/sched/fair.c: In function ‘distribute_cfs_runtime’: kernel/sched/fair.c:4633:13: warning: conversion to ‘u64’ {aka ‘long long unsigned int’} from ‘s64’ {aka ‘long long int’} may change the sign of the result [-Wsign-conversion] runtime = -cfs_rq->runtime_remaining + 1; ^ kernel/sched/fair.c:4638:29: warning: conversion to ‘long long unsigned int’ from ‘s64’ {aka ‘long long int’} may change the sign of the result [-Wsign-conversion] cfs_rq->runtime_remaining += runtime; ^~ The thing is we have a !cfs_rq_throttled() check just before the snippet you're calling out, so AFAICT cfs_rq->runtime_remaining has to be <= 0 there (otherwise this cfs_rq wouldn't be throttled). I doubt you can get this to fire, but just to be sure... -----8<----- diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index bbd90adabe2a..836948a3ae23 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4630,6 +4630,8 @@ static u64 distribute_cfs_runtime(struct cfs_bandwidth *cfs_b, u64 remaining) if (!cfs_rq_throttled(cfs_rq)) goto next; + WARN_ON(cfs_rq->runtime_remaining > 0); + runtime = -cfs_rq->runtime_remaining + 1; if (runtime > remaining) runtime = remaining; ----->8----- Other than those signed/unsigned shenanigans, I only see one other scenario that leads to a cfs_rq getting allocated all the remaining runtime: its .runtime_remaining just has to be greater or equal (in absolute value) than the remaining runtime. If that's happening consistently, I suppose that could be due to long delays between update_curr_fair() calls, but I can't think right why that would happen. > This commit prevents cfs_rq to be assgined new runtime if it has been > throttled to avoid the above incorrect type cast. > > Signed-off-by: Liangyan > --- > kernel/sched/fair.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 81fd8a2a605b..b14d67d28138 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -4068,6 +4068,8 @@ static void __account_cfs_rq_runtime(struct cfs_rq *cfs_rq, u64 delta_exec) > if (likely(cfs_rq->runtime_remaining > 0)) > return; > > + if (cfs_rq->throttled) > + return; > /* > * if we're unable to extend our runtime we resched so that the active > * hierarchy can be throttled >