From patchwork Wed Jul 12 02:24:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 9835805 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 001C460363 for ; Wed, 12 Jul 2017 02:24:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7379285BA for ; Wed, 12 Jul 2017 02:24:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C946E285CA; Wed, 12 Jul 2017 02:24:24 +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=ham 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 48126285BA for ; Wed, 12 Jul 2017 02:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755862AbdGLCYX (ORCPT ); Tue, 11 Jul 2017 22:24:23 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:44798 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755516AbdGLCYW (ORCPT ); Tue, 11 Jul 2017 22:24:22 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id DA716613CC; Wed, 12 Jul 2017 02:24:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1499826261; bh=Btebcm2E1+S5OkEBamjKExh18VySOtkgf4zkZaqLN20=; h=From:To:Cc:Subject:Date:From; b=m4+4Kv/XRGEu1Vlso1KoJoetR6B90rJz68zZX+lgxCQaJaqa/uunYvzor0xAEE2kd QDdpi/0ufdZtlF4FUDTKe5eSnuI5l/QPH9gp4y+/VE7y2C+NsNXfvP9iKeARjLLdv7 5G9PlVTipnukQEcu1hzeWNGhmuVsNmtY4IUqkwFo= Received: from skannan1-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: skannan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 2A9C0612D3; Wed, 12 Jul 2017 02:24:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1499826261; bh=Btebcm2E1+S5OkEBamjKExh18VySOtkgf4zkZaqLN20=; h=From:To:Cc:Subject:Date:From; b=m4+4Kv/XRGEu1Vlso1KoJoetR6B90rJz68zZX+lgxCQaJaqa/uunYvzor0xAEE2kd QDdpi/0ufdZtlF4FUDTKe5eSnuI5l/QPH9gp4y+/VE7y2C+NsNXfvP9iKeARjLLdv7 5G9PlVTipnukQEcu1hzeWNGhmuVsNmtY4IUqkwFo= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 2A9C0612D3 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=skannan@codeaurora.org From: Saravana Kannan To: "Rafael J. Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] cpufreq: schedutil: Update cached "current frequency" when limits change Date: Tue, 11 Jul 2017 19:24:12 -0700 Message-Id: <1499826256-23491-1-git-send-email-skannan@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 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 Currently, the governor calculates the next frequency, set the current CPU frequency (policy->cur). It also assumes the current CPU frequency doesn't change if the next frequency isn't calculated again and hence caches the "current frequency". However, this isn't true when CPU min/max frequency limits are changed. So, there's room for the CPU frequency to get stuck at the wrong level if the calculated next frequency doesn't change across multiple limits updates. Fix this by updating the cached "current frequency" when limits changes the current CPU frequency. Signed-off-by: Saravana Kannan --- kernel/sched/cpufreq_schedutil.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 076a2e3..fe0b2fb 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -226,6 +226,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, busy = sugov_cpu_is_busy(sg_cpu); + raw_spin_lock(&sg_policy->update_lock); if (flags & SCHED_CPUFREQ_RT_DL) { next_f = policy->cpuinfo.max_freq; } else { @@ -240,6 +241,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, next_f = sg_policy->next_freq; } sugov_update_commit(sg_policy, time, next_f); + raw_spin_unlock(&sg_policy->update_lock); } static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) @@ -637,10 +639,14 @@ static void sugov_stop(struct cpufreq_policy *policy) static void sugov_limits(struct cpufreq_policy *policy) { struct sugov_policy *sg_policy = policy->governor_data; + unsigned long flags; if (!policy->fast_switch_enabled) { mutex_lock(&sg_policy->work_lock); cpufreq_policy_apply_limits(policy); + raw_spin_lock_irqsave(&sg_policy->update_lock, flags); + sg_policy->next_freq = policy->cur; + raw_spin_unlock_irqrestore(&sg_policy->update_lock, flags); mutex_unlock(&sg_policy->work_lock); }