Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1684687ybl; Sat, 24 Aug 2019 02:19:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAl3USiq15biONtlnb6Iot6rpQTnKCSoLVJABc52fH++dpF2V5sdO6vnTZgHAqUJxR1G6z X-Received: by 2002:a17:902:fa5:: with SMTP id 34mr9305751plz.285.1566638394064; Sat, 24 Aug 2019 02:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566638394; cv=none; d=google.com; s=arc-20160816; b=Rdf5CUVbSTVhTTckQhtw6gdSo+WF1GL6UWiXyUfogb1DT3HMlj1idZK6N7S5PCETiu myNRxK525EcNCrwyGreKtV9bfxw8Na8NBrSzAFS9eCvcpamNPzfHAhmfk0mQ5BuGKCCW vBdgPA3QplSrsCjoiZvtzEI2VPaeep6qWINASpHUCpnu+K0F5ntGpm/zDsE242ovbjkE khJ64nnXCeiky5UYoXed0yAvsL5jVYJRa9zvkJOlG92El8hKBixGbIzGPGvhv54pBCWJ gW49m/Cmtxv6Ug5rgzGyAJIDgnX56AXKvpf1XCN5IVGo1FAHR0pnY1DGyi2NpvjdFPbH gXlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=o4+B7QF+ro4NdJSwHe1HpK7tpHFqtd2Gdu4H+3JG1QA=; b=er3QU4F15cnl6nWo7PHrIFLiLplb9oTpSKQaPec+63gVZat9WtIAOcA+yk2+XGtPgd 1o51KVnKS/I7QKTpKUwvySgMEXV3v/8HpBbNeeC74LpqLvm/4gGfZdyrWFYVEViVw2mR aoIqGYPoEeRcSahg/hshZsB+N1HSFz7oWAbMpf2tT0RQt1zYQOWrGWc5OCtnpcau9Pi0 iSsVw4dSb4r96XQ0/D2bS8RwegPQYvpC5oEAikdn+rlXxtVntYLaW1Wuy68uGvbsuz/Z TQFEFbVhsCQy1vzyeEVWvyb7PZ0iYxNh2aVk8wLLPzt475j09Se/1YEVBdNxQ6sfPIGb MgkA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7si5150035pfq.93.2019.08.24.02.19.10; Sat, 24 Aug 2019 02:19:54 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726518AbfHXJQU (ORCPT + 99 others); Sat, 24 Aug 2019 05:16:20 -0400 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]:35375 "EHLO out30-45.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725616AbfHXJQU (ORCPT ); Sat, 24 Aug 2019 05:16:20 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=liangyan.peng@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0TaHmwL6_1566638158; Received: from localhost(mailfrom:liangyan.peng@linux.alibaba.com fp:SMTPD_---0TaHmwL6_1566638158) by smtp.aliyun-inc.com(127.0.0.1); Sat, 24 Aug 2019 17:16:08 +0800 From: Liangyan To: Ingo Molnar , Peter Zijlstra , Ben Segall , Valentin Schneider , linux-kernel@vger.kernel.org Cc: shanpeic@linux.alibaba.com, xlpang@linux.alibaba.com Subject: [PATCH v2] sched/fair: don't assign runtime for throttled cfs_rq Date: Sat, 24 Aug 2019 17:15:58 +0800 Message-Id: <20190824091558.86296-1-liangyan.peng@linux.alibaba.com> X-Mailer: git-send-email 2.14.4.44.g2045bb6 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. According to Ben Segall, the throttled cfs_rq can have account_cfs_rq_runtime called on it because it is throttled before idle_balance, and the idle_balance calls update_rq_clock to add time that is accounted to the task. 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 Reviewed-by: Ben Segall Reviewed-by: Valentin Schneider --- kernel/sched/fair.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index bc9cfeaac8bd..ac3ae694d850 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4470,6 +4470,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 @@ -4673,6 +4675,9 @@ static u64 distribute_cfs_runtime(struct cfs_bandwidth *cfs_b, if (!cfs_rq_throttled(cfs_rq)) goto next; + /* By the above check, this should never be true */ + WARN_ON(cfs_rq->runtime_remaining > 0); + runtime = -cfs_rq->runtime_remaining + 1; if (runtime > remaining) runtime = remaining; -- 2.14.4.44.g2045bb6