Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp200703rdb; Tue, 5 Dec 2023 03:05:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGn2JxaK5x0VxGFIIByVA8OeHarGKgW6JM2QngZFSPfk9RSP3hMhwwAE1+W2ve2s7Ry85qW X-Received: by 2002:a05:6358:8187:b0:170:261a:7097 with SMTP id r7-20020a056358818700b00170261a7097mr4738721rwk.41.1701774325127; Tue, 05 Dec 2023 03:05:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701774325; cv=none; d=google.com; s=arc-20160816; b=VFHdpj7lBJ6eSVmFfQU99oIkj29o3Fx6HjHHDmRIQ0OnCaJio/8/GyZmc9eB66gRNS PA3uBcrvUjI+dQN32zO0UxPUJoA/cxQIl0qSfT2+nv0qfD4H3oKmhnM6AN1YqN1s4QLF ya8RsFRrZ+YOY11mXQLUtw1cN15gAT5YNKRTAAkYSGvwWL546ErupWBxKuAvXYjJvy1g DEk9Kp5jSVJ7sg5th6sYZSawPllhGPpYq1Y0x6kKuKUsnIYGOF55L2yhDdGGCrTMhpqe JOMSYTVzTBv+FwXkOqbxAZtQbgnllekr/GoNgyua+kAXtcFDlxlBGm0k7dfPR1mrqwpq Xz1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=cMtq6Y2xSOAWWSCX70TfqFkesenlMtoSRokeOX7N2ng=; fh=hC71Rrl99SmtSl/zeBysx3EbkUo7EYtK/s+TQ1bhG+U=; b=Y/sGfO645sswhqYWWqVdYDtefF6N5T2ddpm3fbmUgBm9Ld3Mzv0A0U4bNtqf4Z0cE9 UdZA4NEwvdKP9MMHGz1X3e7ZFkNN1i8QoS2ivMTdE9QMKo3+OWLqMPeVRzprPO3DEsLB KE5/P+l4elHthRalxyhh7mCjxEW33DCQSyNbBoJ8wrF2l1zOAB8TbY3Y2qlq/qI3XDBc BIlmeBi/lgVNkA1q+/dypFhIdZexujdT1nVN6lz5jqhmzLZedVwDJUx3SD/IJJE7T59M EAOcjberx1JHnc1nhSm1I9qpvYbCdXxH0g+2cLlgB7BcpPSQRzH7AmpPc8b95NgMwHj/ qfRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id y33-20020a634961000000b005b896ecd1efsi9702502pgk.172.2023.12.05.03.05.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 03:05:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 34CA980BE2EC; Tue, 5 Dec 2023 03:05:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376630AbjLELFK (ORCPT + 99 others); Tue, 5 Dec 2023 06:05:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346615AbjLELFG (ORCPT ); Tue, 5 Dec 2023 06:05:06 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 48A0912C; Tue, 5 Dec 2023 03:05:11 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A48AE139F; Tue, 5 Dec 2023 03:05:57 -0800 (PST) Received: from localhost (ionvoi01-desktop.cambridge.arm.com [10.2.78.69]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ACC663F5A1; Tue, 5 Dec 2023 03:05:10 -0800 (PST) Date: Tue, 5 Dec 2023 11:05:09 +0000 From: Ionela Voinescu To: Sumit Gupta Cc: Beata Michalska , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, sudeep.holla@arm.covm, will@kernel.org, catalin.marinas@arm.com, viresh.kumar@linaro.org, rafael@kernel.org, yang@os.amperecomputing.com, linux-tegra@vger.kernel.org Subject: Re: [PATCH v2 2/2] cpufreq: Wire-up arch-flavored freq info into cpufreq_verify_current_freq Message-ID: References: <20231127160838.1403404-1-beata.michalska@arm.com> <20231127160838.1403404-3-beata.michalska@arm.com> <3e6077bb-907c-057f-0896-d0a5814a4229@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3e6077bb-907c-057f-0896-d0a5814a4229@nvidia.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 05 Dec 2023 03:05:22 -0800 (PST) Hi Sumit, On Friday 01 Dec 2023 at 18:32:10 (+0530), Sumit Gupta wrote: > Hi Ionela, > > > > --- a/drivers/cpufreq/cpufreq.c > > > +++ b/drivers/cpufreq/cpufreq.c > > > @@ -1756,7 +1756,8 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b > > > { > > > unsigned int new_freq; > > > > > > - new_freq = cpufreq_driver->get(policy->cpu); > > > + new_freq = arch_freq_get_on_cpu(policy->cpu); > > > + new_freq = new_freq ?: cpufreq_driver->get(policy->cpu); > > > > Given that arch_freq_get_on_cpu() is an average frequency, it does not > > seem right to me to trigger the sync & update process of > > cpufreq_verify_current_freq() based on it. > > > > cpufreq_verify_current_freq() will at least modify the internal state of > > the policy and send PRE and POST notifications, if not do a full frequency > > update, based on this average frequency, which is likely different from > > the current frequency, even beyond the 1MHz threshold. > > > > While I believe it's okay to return this average frequency in > > cpuinfo_cur_freq, I don't think it should be used as an indication of > > an accurate current frequency, which is what > > cpufreq_verify_current_freq() expects. > > > > Sumit, can you give more details on the issue at [1] and why this change > > fixes it? > > > > [1] https://lore.kernel.org/lkml/6a5710f6-bfbb-5dfd-11cd-0cd02220cee7@nvidia.com/ > > > > Thank you, > > Ionela. > > > cpufreq_verify_current_freq() also updates 'policy->cur' in POST > notification if the frequency from hardware has more delta (out of sync). > > As the value from 'cpufreq_driver->get()' is not reliable due to [1], > calling the 'get' hook can update the 'policy->cur' with a wrong value when > governor starts in cpufreq_start_governor(). > And if the frequency is never changed after the governor starts during > boot e.g. when performance governor is set as default, then > 'scaling_cur_freq' always returns wrong value. > > Instead, the arch_freq_get_on_cpu() API updates 'policy->cur' with a more > stable freq value. > > [1] https://lore.kernel.org/lkml/20230418113459.12860-7-sumitg@nvidia.com/ Got it, many thanks! As the code is right now in v2, arch_freq_get_on_cpu() is called on show_scaling_cur_freq(), so the problem you describe would not show up. policy->cur would still be incorrect, but 'scaling_cur_freq' would return the value from arch_freq_get_on_cpu(). Would it be enough if arch_freq_get_on_cpu() gets also called from show_cpuinfo_cur_freq() instead of cpufreq_verify_current_freq()? Thanks, Ionela. > > Best regards, > Sumit Gupta > > > > if (!new_freq) > > > return 0; > > > > > > -- > > > 2.25.1 > > >