From patchwork Wed May 9 10:35:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 135247 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp5463831lji; Wed, 9 May 2018 03:35:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpTbQOfZC1Kav+MxLSCYld/k5b7eJs7OkO4wNZ7pJ5B/lHd6yqTjKZy489aDCcQ6Reuu0I4 X-Received: by 2002:a63:7046:: with SMTP id a6-v6mr36384590pgn.358.1525862133142; Wed, 09 May 2018 03:35:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525862133; cv=none; d=google.com; s=arc-20160816; b=yqNnyXNdNdyYV0AlOauD42ABEDx3VCbTUkREv8AB5q4fCLOupVYeZlpFhscNHBIfM9 RAunbyUlH7ubOf1qdcSDI7+zRJ9YzPAbiczFep/jVmLmE1F8A29xlp607pfOIT1Mxd6Z KeJkdFDM590SHmSBph6SODQcA703dx77HYHxTCqJM+vWIO3vfezSVmr6tZS8nUnDL6Ew 1eqjfWQNScIifDrq+yxJZ3Wvf5i3GSp63Jnxz3qUwLBuwIiKnKp6LBNM+ZQneLUkde1Y JjI+eenluoF497dd3iXa/AQ/2jbTEnQwDGLLwNhm3SE78grwOFG4NNPW6fEpN83BJ+Qh AZqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=5SzBrZbubm4x8fwQ1rrcy/99XzSEH3HZBVnWEOpEmFA=; b=dnd7UkiNpc50hBpJw0f6hj7pnB3wEi+noXvPPG+LC7PU9pJ4sL7U+MtSz2sajTdl7C 7eK42Z/XxZwztXjGATcx3KT6F6RGmPqrbbBg0djY59eilon5mbBZAuiIlh/EAIrm6jW2 2HHg2a5vgeq8O/eJj0+PtpyorVcPa/HGzSieJEMroIxp1BIx7+RplnoWH2wrJWp4p4VW k+wUdAGzoz2wR+uy26iTKy+QbtU3AExeoIMbHq7POdCEcDNxl82pIoF3x4/h8QWAjx3g YP5Jq5Uc9R+1AAzJc8jWS/oUOC2I2ylOatEXU/P4SnU9usZW0sCt5gGt3LhELbZdFfuf gLvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RinBfvN3; 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 r14-v6si27536164plj.341.2018.05.09.03.35.32; Wed, 09 May 2018 03:35:33 -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=RinBfvN3; 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 S934607AbeEIKfa (ORCPT + 29 others); Wed, 9 May 2018 06:35:30 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:34960 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933864AbeEIKf2 (ORCPT ); Wed, 9 May 2018 06:35:28 -0400 Received: by mail-pl0-f68.google.com with SMTP id i5-v6so4048299plt.2 for ; Wed, 09 May 2018 03:35:28 -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=5SzBrZbubm4x8fwQ1rrcy/99XzSEH3HZBVnWEOpEmFA=; b=RinBfvN36+W/1OjvAgeeOKjOuTBfMWEMXxw/cRiTVNVZ2eOFbYLcdthgG+setYzkQB 89Nl7qL9Q8nobzKvp5u16hQ2bpMfz4NGI03LTK068jY5F/5mN3FSFmjYgiHvjvl9hcH7 t9GDREUGm6b081Xokhc2TPkFitmlvA1/OBqsM= 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:in-reply-to :references; bh=5SzBrZbubm4x8fwQ1rrcy/99XzSEH3HZBVnWEOpEmFA=; b=I4HStNo6WfoEsLzpSl6VuM7wEZe/VY5EkiLpAJneLcZocrZ2UlC7FxB4NSg/YPodvr BgiU0XEZLQvoyi6RUICC0ifQFEJ6T2nITxG+WX1dKBflxDAv/s/UpkN8HDE3oS6csEVy YN0ZO899qamO3J4XPy3qNAQJXoMyKhlpM7LuXRbGvmLbszwm4ytLblx7AxjIia518XY3 TwmWkjPx2jds4lkuEyEOT6kQ7TpGyxC1x31Mx4JuROuimoDll809hFz3b5JvVAJmo9tm F7exhIBEzTBXdm2RErIGJgD4+nNzGDA2yiN6cqkWQsNVHJH6g+BOkjL8hhR7o/geQYK5 dbqQ== X-Gm-Message-State: ALQs6tCO05nrH4XbP6IMszakj7nwazCnVSSaI1TV5TbBFFQvERVPUqpP ov9wO9b7oPQbY+RvOhvkKZhb+w== X-Received: by 2002:a17:902:6903:: with SMTP id j3-v6mr24128996plk.313.1525862128260; Wed, 09 May 2018 03:35:28 -0700 (PDT) Received: from localhost ([122.167.163.112]) by smtp.gmail.com with ESMTPSA id u68sm15231152pfu.32.2018.05.09.03.35.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 May 2018 03:35:27 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Ingo Molnar , Peter Zijlstra Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH V2] sched/schedutil: Don't set next_freq to UINT_MAX Date: Wed, 9 May 2018 16:05:24 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 In-Reply-To: <2276196.ev9rMjHTR0@aspire.rjw.lan> References: <2276196.ev9rMjHTR0@aspire.rjw.lan> 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 to discard the cached value of next freq: - 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 recalculates the next frequency instead. But having special meaning for a particular value of frequency makes the code less readable and error prone. We recently fixed a bug where the UINT_MAX value was considered as valid frequency in sugov_update_single(). All we need is a flag which can be used to discard the value of sg_policy->next_freq and we already have need_freq_update for that. Lets reuse it instead of setting next_freq to UINT_MAX. Signed-off-by: Viresh Kumar --- V2: - Rebased over the fix sent by Rafael lkml.kernel.org/r/2276196.ev9rMjHTR0@aspire.rjw.lan - Remove the additional check from sugov_update_single() as well. - This is for 4.18 now instead of stable kernels. kernel/sched/cpufreq_schedutil.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index e23e84724f39..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); } @@ -305,8 +300,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, * Do not reduce the frequency if the CPU has not been idle * recently, as the reduction is likely to be premature then. */ - if (busy && next_f < sg_policy->next_freq && - sg_policy->next_freq != UINT_MAX) { + if (busy && next_f < sg_policy->next_freq) { next_f = sg_policy->next_freq; /* Reset cached freq as next_freq has changed */ @@ -671,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;