Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2144071iof; Tue, 7 Jun 2022 21:13:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCUHJQaevjO3VlCBuX0og7hWTWMKnKuMnuOrcXu9ZXPdjMNCbDHvxp9JyUBDaTMeLg9DA6 X-Received: by 2002:a17:902:db0f:b0:166:42b5:c819 with SMTP id m15-20020a170902db0f00b0016642b5c819mr30381362plx.96.1654661594149; Tue, 07 Jun 2022 21:13:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654661594; cv=none; d=google.com; s=arc-20160816; b=sbRgWIjYDK4HAftFR454UL5vhVf3V4WTSZ6JQHuB2BT6638gNqKo426d1cJziPM8pC 1izM+X8SwfDO1z1cuzC1J1uGDKbrimaMEDsn4RDbGTjYKj7nVn4T1cGqdo/8rkm7Jv0k 56Xu447mqZwqndiSzjw2kKxGF3U/fcaDh25rQNaqhpYfyhu9Qz0qEEMzkkTTcPjz5l63 lUBwKmvB1GeBERyrof2GoF0a2UUG2Ehc4y/8LLDrMSEnKpLryk/gXLeWIbPB09vLq0xQ 3XeZrWt1BM9rnS/brHviD/8uWBywYvwhQdxsPEX4+L31o3GJLXpU7E6Mc5ToFZa02HJ3 aNyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MCZi9lKw/BTaTZT3PPRVjrbLrCGUAiHnkxFKDMAvVVE=; b=0SN/Dr1Y7aSDMsp+ItoPPxwkRXyYGkfNRszDRTNU0+W8R2uqOtoKcY9P/Y2SiVuJnP YWdhUWrtkVjRS8rIzOydriLiQxvCtFvC/OONW839dicTs3uEieJdkXp3VvUxReKMKSLx qeqMFhDqYpmTzIrIL3ZzgkxtjDQaJaZSux6vdRRNuJM127OKHjNurx1pe/588Qo72hBf s7JVahuU5RLpNmHBMcXYCRbKCQlGy2ueGlFDzztkAhLlL6SutO+cSSf+pRkIx+JATFAc rELVPBXjmUPw1GMHgt0pYMQzqJRDSZbiKuyRPImfcEfydXtWJdQSXXquQ5DqJykKJ5sf q8AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FRNyUVjr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x71-20020a63864a000000b003fda16081basi12249127pgd.265.2022.06.07.21.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:13:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FRNyUVjr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7A1CD423ACC; Tue, 7 Jun 2022 20:53:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377050AbiFGUtw (ORCPT + 99 others); Tue, 7 Jun 2022 16:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357383AbiFGTuK (ORCPT ); Tue, 7 Jun 2022 15:50:10 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CF137CB0A; Tue, 7 Jun 2022 11:19:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id BC5CACE2439; Tue, 7 Jun 2022 18:19:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B20BFC385A2; Tue, 7 Jun 2022 18:19:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654625964; bh=r3DLkc6jEcY3i0/3z56pH0qiShiXBiSeWD+DV9othKc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FRNyUVjrQtzplj4Xk7QsZBIMZwHYgN0PsT1ZyrY45tm3Lt3n5ifhC6mhKgxRo5Hh0 swb957JCiETIk6fuGZHC6aKVHYKC6xG03EiqMYGpZbXbIAWYRcpCzPBxGsmmfFCACR Eza6kWnub55GzY3IzpdTUPJupdUHz3lLyFg6Rh1o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rex-BC Chen , Viresh Kumar , Jia-wei Chang , Matthias Brugger , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.17 206/772] cpufreq: Avoid unnecessary frequency updates due to mismatch Date: Tue, 7 Jun 2022 18:56:38 +0200 Message-Id: <20220607164955.103958181@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164948.980838585@linuxfoundation.org> References: <20220607164948.980838585@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Viresh Kumar [ Upstream commit f55ae08c89873e140c7cac2a7fa161d31a0d60cf ] For some platforms, the frequency returned by hardware may be slightly different from what is provided in the frequency table. For example, hardware may return 499 MHz instead of 500 MHz. In such cases it is better to avoid getting into unnecessary frequency updates, as we may end up switching policy->cur between the two and sending unnecessary pre/post update notifications, etc. This patch has chosen allows the hardware frequency and table frequency to deviate by 1 MHz for now, we may want to increase it a bit later on if someone still complains. Reported-by: Rex-BC Chen Signed-off-by: Viresh Kumar Tested-by: Jia-wei Chang Reviewed-by: Matthias Brugger Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/cpufreq/cpufreq.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 80f535cc8a75..fbaa8e6c7d23 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -28,6 +28,7 @@ #include #include #include +#include #include static LIST_HEAD(cpufreq_policy_list); @@ -1707,6 +1708,16 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b return new_freq; if (policy->cur != new_freq) { + /* + * For some platforms, the frequency returned by hardware may be + * slightly different from what is provided in the frequency + * table, for example hardware may return 499 MHz instead of 500 + * MHz. In such cases it is better to avoid getting into + * unnecessary frequency updates. + */ + if (abs(policy->cur - new_freq) < HZ_PER_MHZ) + return policy->cur; + cpufreq_out_of_sync(policy, new_freq); if (update) schedule_work(&policy->update); -- 2.35.1