Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp28657ybd; Fri, 28 Jun 2019 13:52:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqziWvgBElYdERPwuFR96PMt96ySCjp6Gn7hJMK6O+2bWxoc40kHkOeQ3f+tsQ+jI3pli9p8 X-Received: by 2002:a17:902:7603:: with SMTP id k3mr14066824pll.245.1561755167672; Fri, 28 Jun 2019 13:52:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561755167; cv=none; d=google.com; s=arc-20160816; b=0vZ+XiP/FVv9rFvsjXh476waW7Mi7LPhEzqAdUdiZUhY5MXzw3jBtZlg0ZfqgTKVci +kOmLJ6jF5fLvqn0qCCgDBVgCy56VGsiHMH9Cb46ifl8vNTzkRrsYcBOZtGQ2GImvO5e VqeisdGU8BOye1eFm8KCEOAWdlr7dA+g3Y8MniuJrTQNXXQ5hoUw861A6JDPJrpaub2j 2UmY2n3l2NRx7a3EMBvkYs2uDUNSmrUh0VcFA6+IKW7fb/JL0hKvBUR9thGX7HCU0Sfo 5pxqUVs3NN5k9evTe05tJY+BHA2e/Yd7+zzqbxk/ES0J3X/XoJGBDb7ItPWfj9OA+fkM UxeA== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=6diOl6tj1hryzxDVyCvlLD6GoDY4VgHLpDF7JpK6S7c=; b=z9Ix5tgHhIps9lDmS3aka8DmkjECQUHmo/Yk+Crx3hmnp8fdvMtvDCev7RLBmJQJ9p /Q2KsEAMLSsRqmDtSuu4eYOIa5fsu2WeRS+251RLOM1F4GrgIxcDe5VEJom1cfajUWfE OTYC68O1ae0sX4J3l/47okTeuLjuaGMA2P7uln5oVTPFsI82Q65twNo2EyBpOdO39UtS r5QivxgglUuTyRazFfSBYkuBh11VPLC5UTzM7SuR2HqdP7fgqGLyYCz5q43D2exSGDyL Iqn0TfJBWNHOtLRUSm+u147V+NvncZBG2mzljojTlyTL4GfhCF6jjKilW2n28/lJd3Ex /lYg== 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 y13si2912799pgq.172.2019.06.28.13.52.27; Fri, 28 Jun 2019 13:52:47 -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 S1726963AbfF1UuF (ORCPT + 99 others); Fri, 28 Jun 2019 16:50:05 -0400 Received: from shelob.surriel.com ([96.67.55.147]:38438 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726785AbfF1Utg (ORCPT ); Fri, 28 Jun 2019 16:49:36 -0400 Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1hgxo6-0007TL-Mt; Fri, 28 Jun 2019 16:49:18 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: kernel-team@fb.com, pjt@google.com, dietmar.eggemann@arm.com, peterz@infradead.org, mingo@redhat.com, morten.rasmussen@arm.com, tglx@linutronix.de, mgorman@techsingularity.net, vincent.guittot@linaro.org, Rik van Riel Subject: [PATCH 07/10] sched,cfs: fix zero length timeslice calculation Date: Fri, 28 Jun 2019 16:49:10 -0400 Message-Id: <20190628204913.10287-8-riel@surriel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190628204913.10287-1-riel@surriel.com> References: <20190628204913.10287-1-riel@surriel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The way the time slice length is currently calculated, not only do high priority tasks get longer time slices than low priority tasks, but due to fixed point math, low priority tasks could end up with a zero length time slice. This can lead to cache thrashing and other inefficiencies. Simplify the logic a little bit, and cap the minimum time slice length to sysctl_sched_min_granularity. Tasks that end up getting a time slice length too long for their relative priority will simply end up having their vruntime advanced much faster than other tasks, resulting in them receiving time slices less frequently. Signed-off-by: Rik van Riel --- kernel/sched/fair.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d48bff5118fc..8da2823401ca 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -671,22 +671,6 @@ static inline u64 calc_delta_fair(u64 delta, struct sched_entity *se) return delta; } -/* - * The idea is to set a period in which each task runs once. - * - * When there are too many tasks (sched_nr_latency) we have to stretch - * this period because otherwise the slices get too small. - * - * p = (nr <= nl) ? l : l*nr/nl - */ -static u64 __sched_period(unsigned long nr_running) -{ - if (unlikely(nr_running > sched_nr_latency)) - return nr_running * sysctl_sched_min_granularity; - else - return sysctl_sched_latency; -} - /* * We calculate the wall-time slice from the period by taking a part * proportional to the weight. @@ -695,7 +679,7 @@ static u64 __sched_period(unsigned long nr_running) */ static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se) { - u64 slice = __sched_period(cfs_rq->nr_running + !se->on_rq); + u64 slice = sysctl_sched_latency; for_each_sched_entity(se) { struct load_weight *load; @@ -712,6 +696,13 @@ static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se) } slice = __calc_delta(slice, se->load.weight, load); } + + /* + * To avoid cache thrashing, run at least sysctl_sched_min_granularity. + * The vruntime of a low priority task advances faster; those tasks + * will simply get time slices less frequently. + */ + slice = max_t(u64, slice, sysctl_sched_min_granularity); return slice; } -- 2.20.1