Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1310344lqt; Tue, 19 Mar 2024 22:24:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX9d0tu5nhhE3SgOavCEJk5zCxCyJIIVjdCuT+G+r2EHr25yTxCXRSf0ghl/UuLlw2HVG8U2SuEnhhDtHHA2o6TdBcW8lttqyK5Ep7TWg== X-Google-Smtp-Source: AGHT+IHkuusoy1/XCjWTxWhTGcX1MlCrpaI20BBmXiEzW8JDPrkSgCchk9L4UEcMqgO/+o5zeoZy X-Received: by 2002:a05:6402:249e:b0:568:d7fe:a768 with SMTP id q30-20020a056402249e00b00568d7fea768mr7859501eda.25.1710912259665; Tue, 19 Mar 2024 22:24:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710912259; cv=pass; d=google.com; s=arc-20160816; b=FDvokqp1jLtHErP4Zkv7m2ehMlxd3WcU5SYZO4kAsn9O0BAFnY8U54blRJjXrC5PaA TGgCCR4eYF00n6Y8uzZfdq12AeTnHH/52dKJkjK3kMna+1MEbhhmz0AbLpkd/BA1AFTk GOKAIhNysMyx2FCIVtpkYKgMBFXi75yOzXCwvBB9JwFI6giVfvFWQPxYHHwPmZ8cEYQR PhcpQ/xzicIMCSOHeYcoVLzaqGBcvHU0Qb8lnHr2nhNRZlFIet1VHp3kUEivC9rrMM96 8NgZzOWEZ/f6DgF34bZ3E2a4gx64f9v1SVeLivDdCeWuVkArIdALpqd6RDV2bpmS7QlE C12Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hclMrfbJMmUXigAObWf3+YqP1MxsUJQZjymXgjSMcuw=; fh=0XnG4t1bH8OroaGEkLMYedxvlm00ypBo1b9nLCYk0jY=; b=szuwVFnHNj+FGpTEZ9Gb2/FqGxJP5wKHZQqUb9pIKNJWsVV3p6RY6OFyqNPtKXkWfH LZeg+I9HtJUDfJH+SrD/N0eynA+X93z4vju8oR3H59/QYI1RcsnkDO+1wAxO4ec/8IVm cq1PPKh52qCC5QETsPuyqDVxD4zTCH1x92S8yqFB+/6GuMoBOVz87gn9vUYNOYFdz4QN VpbkZz1uLOwF/wEJ/cjSlqKWPX9f8g3iI/jENVXoJi2HpM5xSXVJKKnWwFHHMOMwg6Sf zUwH0d3UITI3Hs/mjm4YvhQfrpo7TYnPNlUsf5odV7/AzPRxRZXbqzUgGGALzfg3Akw0 tcZw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=hKGkHQKQ; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-108442-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108442-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id fd18-20020a056402389200b0056b9ec20570si1003657edb.673.2024.03.19.22.24.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 22:24:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108442-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=hKGkHQKQ; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-108442-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108442-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 55C9B1F22C50 for ; Wed, 20 Mar 2024 05:24:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC14D14F75; Wed, 20 Mar 2024 05:24:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="hKGkHQKQ" Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F031134AB; Wed, 20 Mar 2024 05:24:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710912249; cv=none; b=ej7GUGkmDdCmHUMha7k5UM3mP3NrdWOiLSHbGjgab5C6KbQYv8J2w2I/mJMlskQasXu/y9QcN2u9N9Uex4gjX02MiblhGYtoo4Ats12lwtT/BbWJtAEt2KmWX/J6GlRcbdPZ5uR078hC+WWg9NTU6qw7AVKECuonxMv1ihKGc7E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710912249; c=relaxed/simple; bh=HJrpAB3s870TF7XDdJL3Y/viUMsCZ5xu7IbozphFcg4=; h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bI7auOrYA+PAD+3b1UPVk4hqoNie4AZEqwLoOFZ8IDWfXxXjKEX0e/X4Sw/ennTm+FywRYIxMgua4N570IKdT7nMWM/0ehkkmI1dwWu9xHw8J9qr9LP/JP90F9Y+fxfCLc6hxzdTSaLer6omnn1n9KpyNgedgVhwnkPO7rS2ebI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=hKGkHQKQ; arc=none smtp.client-ip=198.47.23.248 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 42K5Nwt1063360; Wed, 20 Mar 2024 00:23:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1710912238; bh=hclMrfbJMmUXigAObWf3+YqP1MxsUJQZjymXgjSMcuw=; h=Date:From:To:CC:Subject:References:In-Reply-To; b=hKGkHQKQ+Nov4FIkZwuAlfOLx24b+8miR1OL0uFzwgDZ8/ubErzP5GQRGybA/qmAj J47yy7qUW6UzRA/v1/MYiI2mZexZ9z9/9YlkipG1PGZWul9NgxUJ/x8J43qNAUKvOh r4m0CymaC6T8BruALMZ9+WskQte41eGz2m2TkPVs= Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 42K5NwYJ130209 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 20 Mar 2024 00:23:58 -0500 Received: from DLEE104.ent.ti.com (157.170.170.34) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Wed, 20 Mar 2024 00:23:58 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Wed, 20 Mar 2024 00:23:58 -0500 Received: from localhost (dhruva.dhcp.ti.com [172.24.227.68]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 42K5Nvpv008108; Wed, 20 Mar 2024 00:23:57 -0500 Date: Wed, 20 Mar 2024 10:53:56 +0530 From: Dhruva Gole To: Xuewen Yan CC: , , , , , , Subject: Re: [PATCH] cpufreq: Use a smaller freq for the policy->max when verify Message-ID: <20240320052356.6ogxfa6teocp7br6@dhruva> References: <20240319080153.3263-1-xuewen.yan@unisoc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20240319080153.3263-1-xuewen.yan@unisoc.com> X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Hi, On Mar 19, 2024 at 16:01:53 +0800, Xuewen Yan wrote: > When driver use the cpufreq_frequency_table_verify() as the > cpufreq_driver->verify's callback. It may cause the policy->max > bigger than the freq_qos's max freq. > > Just as follow: > > unisoc:/sys/devices/system/cpu/cpufreq/policy0 # cat scaling_available_frequencies > 614400 768000 988000 1228800 1469000 1586000 1690000 1833000 2002000 2093000 > > unisoc:/sys/devices/system/cpu/cpufreq/policy0 # echo 1900000 > scaling_max_freq > unisoc:/sys/devices/system/cpu/cpufreq/policy0 # echo 1900000 > scaling_min_freq > unisoc:/sys/devices/system/cpu/cpufreq/policy0 # cat scaling_max_freq > 2002000 > unisoc:/sys/devices/system/cpu/cpufreq/policy0 # cat scaling_min_freq > 2002000 > > When user set the qos_min and qos_max as the same value, and the value > is not in the freq-table, the above scenario will occur. > > This is because in cpufreq_frequency_table_verify() func, when it can not > find the freq in table, it will change the policy->max to be a bigger freq, > as above, because there is no 1.9G in the freq-table, the policy->max would > be set to 2.002G. As a result, the cpufreq_policy->max is bigger than the > user's qos_max. This is unreasonable. That's a good catch! Never thought of this. > > So use a smaller freq when can not find the freq in fre-table, to prevent > the policy->max exceed the qos's max freq. > > Signed-off-by: Xuewen Yan > --- > drivers/cpufreq/freq_table.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c > index c4d4643b6ca6..1d98b8cf1688 100644 > --- a/drivers/cpufreq/freq_table.c > +++ b/drivers/cpufreq/freq_table.c > @@ -70,7 +70,7 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy_data *policy, > struct cpufreq_frequency_table *table) > { > struct cpufreq_frequency_table *pos; > - unsigned int freq, next_larger = ~0; > + unsigned int freq, prev_smaller = 0; > bool found = false; > > pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n", > @@ -86,12 +86,12 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy_data *policy, > break; > } > > - if ((next_larger > freq) && (freq > policy->max)) > - next_larger = freq; > + if ((prev_smaller < freq) && (freq <= policy->max)) > + prev_smaller = freq; > } > > if (!found) { > - policy->max = next_larger; > + policy->max = prev_smaller; > cpufreq_verify_within_cpu_limits(policy); LGTM! Reviewed-by: Dhruva Gole -- Best regards, Dhruva