From patchwork Fri Aug 26 18:40:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Muckle X-Patchwork-Id: 9301909 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CE21A608A7 for ; Fri, 26 Aug 2016 18:42:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C353229648 for ; Fri, 26 Aug 2016 18:42:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B50C42964A; Fri, 26 Aug 2016 18:42:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98CA62964A for ; Fri, 26 Aug 2016 18:42:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753708AbcHZSmW (ORCPT ); Fri, 26 Aug 2016 14:42:22 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:36685 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750869AbcHZSlu (ORCPT ); Fri, 26 Aug 2016 14:41:50 -0400 Received: by mail-pf0-f181.google.com with SMTP id h186so30994007pfg.3 for ; Fri, 26 Aug 2016 11:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Jnj0W2Ss2QxnDaeQbjoIGo+Dp3Xkocp8jXjzcT84lmM=; b=YGvVp7zaD/I9ASbsrvwOJRwdEl9sN15e7cSNbg6MMqHe3Wb9CuDlE0rR+kzE/ihqRw aHRW4Q7huHHi5WdsrSbQBzIA1OUlhT9E6CU5F0w2tdzDUrM3LpaChnaAeQt5uhiZFmUj bdmxCyQNTW2kq/hPvIdf+vULlE4FLpEOsyLTs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Jnj0W2Ss2QxnDaeQbjoIGo+Dp3Xkocp8jXjzcT84lmM=; b=Pej2Fh/sIDLYNxqK0ut5H4diMEuXP2qm9FwJdtQUPNLdVG7Bvd44mGYQGtva0i5Uig Y3k8RFA5xz6/kUSITd2gOSsPFls8F6hamTHFOVketB8wZevlBWvXOhKwppNn0lXMcrf8 p1J0kv1+L4uFuLJXg9Tf2Xl+YyTLYbxBWEEwLN0xEpMKzLZbe5x1D8DJAd2D2sVnIb40 XIxv66lNxEkEf4Dx2iVaR/kafL3L/An1rz4F3AGlfJkWhHGca3avEZZgqHFU5fGff7AB HyOKG5nmd/EDjxvMqIVIAK39TWyiqvdly+KCOA+rItAB/w0CFLr9hOEXVXK7desQj9Ej fefg== X-Gm-Message-State: AE9vXwNX4FWbIM44R4eP1QM51wAK4PK8F86oeAdHqBpT1dJzvjBNuAHZjJ1VTOGwutE4NvMZ X-Received: by 10.98.192.12 with SMTP id x12mr8499415pff.54.1472236861698; Fri, 26 Aug 2016 11:41:01 -0700 (PDT) Received: from graphite.smuckle.net (cpe-76-167-105-107.san.res.rr.com. [76.167.105.107]) by smtp.gmail.com with ESMTPSA id g27sm30480541pfd.47.2016.08.26.11.41.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Aug 2016 11:41:01 -0700 (PDT) From: Steve Muckle X-Google-Original-From: Steve Muckle To: Peter Zijlstra , Ingo Molnar , "Rafael J . Wysocki" Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Vincent Guittot , Morten Rasmussen , Dietmar Eggemann , Juri Lelli , Patrick Bellasi , Steve Muckle Subject: [PATCH 2/2] sched: cpufreq: use rt_avg as estimate of required RT CPU capacity Date: Fri, 26 Aug 2016 11:40:48 -0700 Message-Id: <1472236848-17038-3-git-send-email-smuckle@linaro.org> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1472236848-17038-1-git-send-email-smuckle@linaro.org> References: <1472236848-17038-1-git-send-email-smuckle@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A policy of going to fmax on any RT activity will be detrimental for power on many platforms. Often RT accounts for only a small amount of CPU activity so sending the CPU frequency to fmax is overkill. Worse still, some platforms may not be able to even complete the CPU frequency change before the RT activity has already completed. Cpufreq governors have not treated RT activity this way in the past so it is not part of the expected semantics of the RT scheduling class. The DL class offers guarantees about task completion and could be used for this purpose. Modify the schedutil algorithm to instead use rt_avg as an estimate of RT utilization of the CPU. Based on previous work by Vincent Guittot . Signed-off-by: Steve Muckle --- kernel/sched/cpufreq_schedutil.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index cb8a77b1ef1b..89094a466250 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -146,13 +146,21 @@ static unsigned int get_next_freq(struct sugov_cpu *sg_cpu, unsigned long util, static void sugov_get_util(unsigned long *util, unsigned long *max) { - struct rq *rq = this_rq(); - unsigned long cfs_max; + int cpu = smp_processor_id(); + struct rq *rq = cpu_rq(cpu); + unsigned long max_cap, rt; + s64 delta; - cfs_max = arch_scale_cpu_capacity(NULL, smp_processor_id()); + max_cap = arch_scale_cpu_capacity(NULL, cpu); - *util = min(rq->cfs.avg.util_avg, cfs_max); - *max = cfs_max; + delta = rq_clock(rq) - rq->age_stamp; + if (unlikely(delta < 0)) + delta = 0; + rt = div64_u64(rq->rt_avg, sched_avg_period() + delta); + rt = (rt * max_cap) >> SCHED_CAPACITY_SHIFT; + + *util = min(rq->cfs.avg.util_avg + rt, max_cap); + *max = max_cap; } static void sugov_update_single(struct update_util_data *hook, u64 time, @@ -167,7 +175,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, if (!sugov_should_update_freq(sg_policy, time)) return; - if (flags & SCHED_CPUFREQ_RT_DL) { + if (flags & SCHED_CPUFREQ_DL) { next_f = policy->cpuinfo.max_freq; } else { sugov_get_util(&util, &max); @@ -186,7 +194,7 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 last_freq_update_time = sg_policy->last_freq_update_time; unsigned int j; - if (flags & SCHED_CPUFREQ_RT_DL) + if (flags & SCHED_CPUFREQ_DL) return max_f; for_each_cpu(j, policy->cpus) { @@ -209,7 +217,7 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, if (delta_ns > TICK_NSEC) continue; - if (j_sg_cpu->flags & SCHED_CPUFREQ_RT_DL) + if (j_sg_cpu->flags & SCHED_CPUFREQ_DL) return max_f; j_util = j_sg_cpu->util; @@ -467,7 +475,7 @@ static int sugov_start(struct cpufreq_policy *policy) if (policy_is_shared(policy)) { sg_cpu->util = 0; sg_cpu->max = 0; - sg_cpu->flags = SCHED_CPUFREQ_RT; + sg_cpu->flags = SCHED_CPUFREQ_DL; sg_cpu->last_update = 0; sg_cpu->cached_raw_freq = 0; cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util,