Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4144063ybl; Mon, 26 Aug 2019 06:13:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpdWi6rV4rjkdN8/S7LFmWLShF3xamlRtFyVkP/BaCd908oNkmiGpxxqbTcRzkyKLWKugH X-Received: by 2002:a62:f204:: with SMTP id m4mr20650322pfh.7.1566825226256; Mon, 26 Aug 2019 06:13:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566825226; cv=none; d=google.com; s=arc-20160816; b=dutBStGa3AMKKEU9kWM8dDC65TAMIpr1HO1dJ3/eYAW+2vHhhwfKmxj4+dx+O3s4Nx UgtLhvECtapEoKW4TDH6u8DgXGnDqGn2zzLN7jhxUNPDLDti/4EpkHX9GEYXzetk4jJR +PI84gaV6HuDdgKEwEXWsul2CWfhO2zdUmM4wEyUumDgSr9dtMwND5VNHhFgRh/RtEKd 42HCepVDe+G0pVIR+xxIIp0g7FJnV3FGUxZ9r3RSgnaRXTfPKQ4trMbYE/xmNT0o5kKR I7LPSOVM6pe3ijYOvX/bKmMVVGm9LrAGlDa1QqKjTQezCLtpLy6Mrk+WDCpsNYojHrw5 u6rQ== 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=vt39fgKmCok2tc81l2m9TCZwYcnZHHWpgCfnRBgaWWo=; b=SaGuHlFnyUTQw2MbOjc7IfQ5VBwwFC6cRrrMp2jK1SKOxVIF2Dsi3/e9U8R3ctPhVk quBBxlQcfi2hs3k7frJpg7JDw/so0/TvtNuygxqf+30xzCujAOlctnpu2Fq33kMnYE/4 f4KV8LC5fmDI92bdvLUw3x6h7jpg40pNNA3aLP4Ty2oTVXDJpTGJxd/ATKCqhW6vFfiz BpqWAQQBlYsAynd/5BhUKgzuLg6D2bclf/wLhqxJJxmeZjo+UbsxdAVTTRi2hcyN0ryU JMGYn9oWbFkfBGRyPy5gSdQBK6PX6oEHlWpzta16UORnVTlyx67Ul2ZGi4qC5z8DwKjP KBCA== 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 a13si8603950pgt.217.2019.08.26.06.13.30; Mon, 26 Aug 2019 06:13:46 -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 S1731821AbfHZMQw (ORCPT + 99 others); Mon, 26 Aug 2019 08:16:52 -0400 Received: from out30-57.freemail.mail.aliyun.com ([115.124.30.57]:51962 "EHLO out30-57.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731810AbfHZMQv (ORCPT ); Mon, 26 Aug 2019 08:16:51 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07487;MF=liangyan.peng@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0TaW1GMf_1566821793; Received: from localhost(mailfrom:liangyan.peng@linux.alibaba.com fp:SMTPD_---0TaW1GMf_1566821793) by smtp.aliyun-inc.com(127.0.0.1); Mon, 26 Aug 2019 20:16:41 +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 v3] sched/fair: don't assign runtime for throttled cfs_rq Date: Mon, 26 Aug 2019 20:16:33 +0800 Message-Id: <20190826121633.6538-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, then other cfs_rqs attached to this cfs_b 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; }. The runtime here will change to a large number and consume all cfs_b->runtime in this cfs_b period. 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 until that distribute_cfs_runtime is called. 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..500f5db0de0b 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 */ + SCHED_WARN_ON(cfs_rq->runtime_remaining > 0); + runtime = -cfs_rq->runtime_remaining + 1; if (runtime > remaining) runtime = remaining; -- 2.14.4.44.g2045bb6