Received: by 10.192.165.148 with SMTP id m20csp3948778imm; Mon, 7 May 2018 23:43:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpo7eNIlSarst8De0bMljSPDc+TYnpW2GKmsr5U3WtTv8ww+ZIsjusAyJLgDV9GaKbqLuL/ X-Received: by 2002:a17:902:9a8c:: with SMTP id w12-v6mr40957389plp.333.1525761808985; Mon, 07 May 2018 23:43:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525761808; cv=none; d=google.com; s=arc-20160816; b=NSW2/fo5MCdb3RiQwId1M0LQyrGzjAX5P7/aiLl8GnBnAzgXTI6xDRmWdwyuRgCmoo whBq4Ien1y6gWEzd8xWIpAJnpBtWjbGvZSBtw1qcrHnLEMAcvSmMRHAgiipCn4WuUuYR s1lVEPNpTM0Ck7axDH6Tx85hCVeuKbG6RbDqtKJTT2sfchJIxeOWVrdQGD8Ll7Mklvl2 h2htl0ggDzlMdGnVUcmN/7buEA1vCMSUJ5YEhZVkYLBbEHr+Qx9f7ck6Zzs8hwmlR/8l gmLddPsC8n9mlgq782t7RwGNKOK1VyMwZaEOuhDlv0A/imDQ2eqX3tq7V3XccJx1BFFI s1og== 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=0FWfZ2mFGYT5GTGWQdEPaA2fZjtmAaBGbazPT6TyX3lJgZfzk+AxMQC7eO3TAOjzqT hGw2M+RTX+zA0cIguGeiknMBpbThWWa539scSxpCyp1kWvtK9ihC3OQsk3X9L+C8XbZZ 3gXrYQhsGf3GIFEO+WOw2n2GH9nAIxFBjA+ot5Bq0d0HT7+YyuGYUm9hqguSRO4d/NrC +qCoQUS0PnJYFeziubKmLA2thPfq69HqknPB3/dDWzkVIh8ZcDK6HD4sdcn+4aAYYn4G 9bZDy3i/9cTGWjwVizwCdvNMTDj3TNgssvGIkcyzyebqYTd5KKhpHjSKLPcEJ2U+P7aB Y0LQ== 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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 e2si24591270pfm.220.2018.05.07.23.43.15; Mon, 07 May 2018 23:43:28 -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; dkim=pass header.i=@linaro.org header.s=google header.b=W+dsX5sE; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754263AbeEHGmv (ORCPT + 99 others); Tue, 8 May 2018 02:42:51 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:46103 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754111AbeEHGms (ORCPT ); Tue, 8 May 2018 02:42:48 -0400 Received: by mail-pg0-f67.google.com with SMTP id z4-v6so20719954pgu.13 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=JxOuYTeykLOEzkIdD9jyc505IOazgcfPH7bZY7DdQJC5BTxcm1UmkkMM0AWnsWHDuf MQhB9KkfStIbrgVzBk0BglRj9SjegYA0heFwPcAfyAgKWU72hzOe/i1EZ2s22nkUDI9u FJ8wnTre2pwTxOW363JPLM+IqjtgQ55qeeXCCYCs4g+LU2FX7zPKm5D7V5KqagDD++xF IZWvs6slGN32va9wnKItVBcAy5rXjOnEojcZNP/A4lGjEJ5wsJVE5pS8VztWNDzRRSEt +8ulBzfDTx6cogTHdtdxRWIPS+zzI/czBZJcwAK/z1pJfK32QrBt+r1jK8lcKV1zlzOg QDKw== X-Gm-Message-State: ALQs6tBze43V19o0sewwtmBENBCSnQCokih9UZK+ihm385NomR2Z1H4i zSyKU6p0keo57MYxcUcGeHe22Q== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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; -- 2.15.0.194.g9af6a3dea062