From patchwork Tue May 8 06:42:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 135132 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp4028358lji; Mon, 7 May 2018 23:42:51 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpt2jKD3ZAui645YpU5zweCNlk9E0DzgvodN2jB/FtgkTJTqEY3hCOjmM177yL4ApNhUNa6 X-Received: by 2002:a65:50c7:: with SMTP id s7-v6mr31281535pgp.192.1525761771660; Mon, 07 May 2018 23:42:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525761771; cv=none; d=google.com; s=arc-20160816; b=MnQfU1E/FovWZbK1UgYDKXIw0mnnzmK/CpA8f2gretqd1nQCPFXMK/I4BZov99oOu9 sGtvLfKGL3+E+OBVF4SrOvc39UDwtIHNgf4Vc3sg3xwv5wmidcJHujkG9bGgJWCA60gy 2He4cqmInomHUo18it+Erp3Y/U5QYDOgOB0JAa2HQbHw11hXIBQswWtn0JiSl/MQPM9W mc8v0tvyvLjVDnWZxPOJmPL3rwTuRIdZlIfnPIuWciyUz4k/MKkAlCGKohxyc4s+akf9 NHeCgYk7E6/izL49rCps3kxe15m+qkYV29xX1634uu7VRPrWddMcFxc4HahWLPWTcu4q Y8Vg== 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 :dkim-signature:arc-authentication-results; bh=cFk8+Txqjy55E/0Vaan3cj9rftBNqA/0H2Tiw/dYhiw=; b=0DBFhKmq4Q881bgidCgwPBMGCCP18MOSSbAIZ4bMM3MYJEnUXa5sB7WQYSOEsoQ4Ki gzZNlWiYuucehkBWBSkenG9e9f4FkdVuVg6SxBgd/01MP6OVpJowArWtw/MM+2E0rmdT 8KsDFNEkt0i4uY5a0Tee4DiXZRTFQHbXXDuGlwUyn/+f2KDubl7zeOzA2KWHIshKVs+C bowazSb5OZu0fScCARkO5LHmE8jbOvrU7LlyfOMRb/NHV1/XqTqLG+uieUOgTJHAFrsV CRlUkMe5suVc2b8hq9PrjLGGhXBxmMlh7Rd17RbIXxY3lF+TyHSY53Ztr6WDm4Ma9ZFj +U/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W+dsX5sE; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u186-v6si19365299pgc.67.2018.05.07.23.42.51; Mon, 07 May 2018 23:42:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W+dsX5sE; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754234AbeEHGmu (ORCPT + 10 others); Tue, 8 May 2018 02:42:50 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:39591 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754225AbeEHGms (ORCPT ); Tue, 8 May 2018 02:42:48 -0400 Received: by mail-pg0-f68.google.com with SMTP id e1-v6so9386723pga.6 for ; Mon, 07 May 2018 23:42:48 -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; bh=cFk8+Txqjy55E/0Vaan3cj9rftBNqA/0H2Tiw/dYhiw=; b=W+dsX5sEk7NCzCifiIn2S5tij/abu+klb/S7x4uPQeRX0IVeBbrUP1OsmGJAcqbTaL GNMxFUwOlm4K5yWD8qL0z89QpkvYLoSlkhuwF2i6/hzS5kVRN54OLCTRjtIjsFpN5AIH f4VlOFW3VpuavnloLqjxJ4spBl1v63JRkwM7k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=cFk8+Txqjy55E/0Vaan3cj9rftBNqA/0H2Tiw/dYhiw=; b=PIwoopRNVyAHMuVIMxnA3AGyXl0h61iZmQ9RTPIpAcfwxnb0AVqGZMXD9fVeXm5pkL Uqo5yWCl9I/Xki2EP+bO8e5X+kkWYiB2XEIwoIQzQlZ0KWKzTrdQeM6CQz2Yc6h+du1T 05dy2Sss++ZXOJ2PIsNyIPwPtO3vXQUvvRcQ9I3cMjfJ3u+99AYzkWkh2juekbv5OwuW Lrd18OjhCs1BINdZggv7bgIp/cKpNdqYdkZ86UYxhF0O5W3NYbWAJ1YVl+6DxQ2krK8y nGFeTfalBwd+aSiqpZ+Qd/HbU290mDgdP3jU3ndkWy+z0F4bJbEd+AoIouNGCDJDm4HR nlBg== X-Gm-Message-State: ALQs6tBEHUoZ/FXzG6XXOd4yHiL5xmodSR6pg6eiKnsaad1ujB3I23On X9GDZTlwEx5uMCPXOYZB64Df/A== X-Received: by 10.98.34.219 with SMTP id p88mr6794307pfj.239.1525761767946; Mon, 07 May 2018 23:42:47 -0700 (PDT) Received: from localhost ([122.167.163.112]) by smtp.gmail.com with ESMTPSA id m14-v6sm1575154pgs.72.2018.05.07.23.42.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 May 2018 23:42:47 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Ingo Molnar , Peter Zijlstra Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , claudio@evidence.eu.com, patrick.bellasi@arm.com, juri.lelli@redhat.com, joelaf@google.com, "4 . 12+" , linux-kernel@vger.kernel.org Subject: [PATCH] sched/schedutil: Don't set next_freq to UINT_MAX Date: Tue, 8 May 2018 12:12:42 +0530 Message-Id: <872c3f8690d9362820639d91a807e535f10a9a36.1525761635.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The schedutil driver sets sg_policy->next_freq to UINT_MAX on certain occasions: - In sugov_start(), when the schedutil governor is started for a group of CPUs. - And whenever we need to force a freq update before rate-limit duration, which happens when: - there is an update in cpufreq policy limits. - Or when the utilization of DL scheduling class increases. In return, get_next_freq() doesn't return a cached next_freq value but instead recalculates the next frequency. This has some side effects though and may significantly delay a required increase in frequency. In sugov_update_single() we try to avoid decreasing frequency if the CPU has not been idle recently. Consider this scenario, the available range of frequencies for a CPU are from 800 MHz to 2.5 GHz and current frequency is 800 MHz. From one of the call paths sg_policy->need_freq_update is set to true and hence sg_policy->next_freq is set to UINT_MAX. Now if the CPU had been busy, next_f will always be less than UINT_MAX, whatever the value of next_f is. And so even when we wanted to increase the frequency, we will overwrite next_f with UINT_MAX and will not change the frequency eventually. This will continue until the time CPU stays busy. This isn't cross checked with any specific test cases, but rather based on general code review. Fix that by not resetting the sg_policy->need_freq_update flag from sugov_should_update_freq() but get_next_freq() and we wouldn't need to overwrite sg_policy->next_freq anymore. Cc: 4.12+ # 4.12+ Fixes: b7eaf1aab9f8 ("cpufreq: schedutil: Avoid reducing frequency of busy CPUs prematurely") Signed-off-by: Viresh Kumar --- kernel/sched/cpufreq_schedutil.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index d2c6083304b4..daaca23697dc 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -95,15 +95,8 @@ static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time) if (sg_policy->work_in_progress) return false; - if (unlikely(sg_policy->need_freq_update)) { - sg_policy->need_freq_update = false; - /* - * This happens when limits change, so forget the previous - * next_freq value and force an update. - */ - sg_policy->next_freq = UINT_MAX; + if (unlikely(sg_policy->need_freq_update)) return true; - } delta_ns = time - sg_policy->last_freq_update_time; @@ -165,8 +158,10 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, freq = (freq + (freq >> 2)) * util / max; - if (freq == sg_policy->cached_raw_freq && sg_policy->next_freq != UINT_MAX) + if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update) return sg_policy->next_freq; + + sg_policy->need_freq_update = false; sg_policy->cached_raw_freq = freq; return cpufreq_driver_resolve_freq(policy, freq); } @@ -670,7 +665,7 @@ static int sugov_start(struct cpufreq_policy *policy) sg_policy->freq_update_delay_ns = sg_policy->tunables->rate_limit_us * NSEC_PER_USEC; sg_policy->last_freq_update_time = 0; - sg_policy->next_freq = UINT_MAX; + sg_policy->next_freq = 0; sg_policy->work_in_progress = false; sg_policy->need_freq_update = false; sg_policy->cached_raw_freq = 0;