Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1801438rbb; Tue, 27 Feb 2024 01:16:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVqlKCZKabgeJ7nd6ErcJNeRYXK59QtvtYELNctTYRXro+ZrpVV7xss7mcjeCi+lEtrj/JtLCmwjRCJ9J0D2yqOSwzyUil1LkVcTPA+4w== X-Google-Smtp-Source: AGHT+IEvbEzVrdBRh1B9OlhNUa3WoN3ZwP5CAkX9SWqAjpwcvgsj4Bzhj7lpeDQmVgbbempFZARG X-Received: by 2002:a05:622a:28f:b0:42e:8f31:9172 with SMTP id z15-20020a05622a028f00b0042e8f319172mr3609576qtw.45.1709025399507; Tue, 27 Feb 2024 01:16:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709025399; cv=pass; d=google.com; s=arc-20160816; b=qKndGFyZucGALSXrWA/rnJBDnO7iGc/yT3srRbYz69RWVdc9jX80jr0cLczwALTUzR srcv44KiXGSMfqwrFAvZnFktwub//VAkLQzhXnC7QYZX7UHiiv3iA8rzh61I8va5GGE7 G8um44UPVMUT0VKp2NB6k08CQw2It4YArnBrzdK29SI5cd9EWMzQEbHnVFhmnzi9dD3M D1rJNfUQ8xRPzAIfqzU9pBqRhbKS1k84NA0vMpMm36XbHs6ZP13rfplitEoVL3iFxomI m9RqT8kGqFy97JsNc36CpoYeTkwmUz2VTtiAHJBDs5gy6OO30omATYZe4Ej1ZtfjH74o Hbxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=vm43AHfKrpEAmlriQ1rL1f2nqgUvYYMyaY7EE4JlVIo=; fh=TowcKpwk4ms037500iY8JaMlb0u9Bz/9Xwiw0skD4Tg=; b=sdT1Q9SAiRtl+nASlDgGz5XHeDrk/3cG2bMIAxvJIG2zdSEYfOhoFiWafuQtb71Jwh r7kafCFRSUVoLbYBigma+eg0GbiUYxDsWnT2OmwWP1UncXOTt8GxiOyLSU29lANn24/U sVL6Gs/29Drnkoj60kQAP8YB0HH1P4zlRFm3Q0PuQjC2ujetKwYWK3ZdY9fY5jQeIEhG 0wrgW7khO2eR6idl1H7b9V0OrBsQj8ZSNZtiPPhLMAC9j7mI8rA6dVTBl44QhVrNNIIT BPz/QT+LPXyUxvZ7AIbRGQjkFREoXvmHzSwI9OVoj+IN7O4kUV8wRzGKWsQ91sSXdxOx Efaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=DoBgcFgk; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-82935-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82935-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p26-20020ac8461a000000b0042e154b2507si6939130qtn.131.2024.02.27.01.16.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 01:16:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82935-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=DoBgcFgk; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-82935-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82935-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 84DC41C22925 for ; Tue, 27 Feb 2024 09:15:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31705136981; Tue, 27 Feb 2024 09:15:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="DoBgcFgk" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 B536713664E; Tue, 27 Feb 2024 09:15:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709025312; cv=none; b=f6qHAfYnoTz6HJvtDmufbtaAqaHHCvrhMdXsk0wnpWABfNIg5F7jXwun6wtMOUUtfw9Z6ZWK4Dv52yehrbbLQv2nXPjSetgCsq5dWfkwKmge+eZiiXLPTidgHFZtjg9DHzC+BJD+HSaPoM9y+8jKY3EQjIuoxn1u8Rm8jKkhOi8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709025312; c=relaxed/simple; bh=iH0cmn/PzDVCeYjVzbKKlG/flQNqKVr7ns0XcjV4cMA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=JY047KBJ2iE9/rUaR5Zke4azfAETDHXWuZU4XUa9n155p0OGQm6HKIV1gJ/Hwg0HkRyfU2k2K6QtQ1oe25oF/f0Yd3MQAX1z3IrQwFWN8ujv9OE7SDVH6weOM8fIGgFFdo6yXy5DVr9VLTKZshRmbypS583nZ/mRbWjk0AbfC9w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=DoBgcFgk; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41R6Ohis031405; Tue, 27 Feb 2024 09:14:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=qcppdkim1; bh=vm43AHf KrpEAmlriQ1rL1f2nqgUvYYMyaY7EE4JlVIo=; b=DoBgcFgkB/NgO9Y7roAYTZA SZaXAyGc8cIXmAlrwcWstuwxBJ6uCb4ZCS9zUL+cBqGV/5g8+r6+G8Y3iHTYqMQe cPIgbTepYBK1sfKU2UxWTb6kFqmzmo2WdzFZnUPxNgsNflVCyweC2+AMfqjwmIjz RpFAlBqrZ2M6ycYsN6GGXEaTl/PClhXWZhfOS56z0gUoaVg8OCWSvtp29p/v5KpU IDtpvE7hP09LiL4C0qfgcSpYZBxmmMupmHu5IDOR3Pn8wQYuuFNryyNaQlbkpJdt lmvZQr1lQQoLVBCUycUPSEcxZxWX1qs/x0+DB706UrrM3OuWnUz3TqpXLnlOM5Q= = Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wh6ws8rdq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Feb 2024 09:14:58 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41R9EvIS026172 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Feb 2024 09:14:57 GMT Received: from hu-kshivnan-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 27 Feb 2024 01:14:51 -0800 From: Shivnandan Kumar To: , Viresh Kumar , "Vincent Donnefort" CC: , , , , , kernel , Shivnandan Kumar , Subject: [PATCH v2] cpufreq: Limit resolving a frequency to policy min/max Date: Tue, 27 Feb 2024 14:43:51 +0530 Message-ID: <20240227091351.1144757-1-quic_kshivnan@quicinc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: ePEAwZl82dk9kvHeNAIxGCDV8ak971nS X-Proofpoint-GUID: ePEAwZl82dk9kvHeNAIxGCDV8ak971nS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 adultscore=0 priorityscore=1501 bulkscore=0 clxscore=1011 suspectscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402270072 Resolving a frequency to an efficient one should not transgress policy->max (which can be set for thermal reason) and policy->min. Currently there is possibility where scaling_cur_freq can exceed scaling_max_freq when scaling_max_freq is inefficient frequency. Add additional check to ensure that resolving a frequency will respect policy->min/max. Cc: Fixes: 1f39fa0dccff ("cpufreq: Introducing CPUFREQ_RELATION_E") Signed-off-by: Shivnandan Kumar -- Changes in v2: -rename function name from cpufreq_table_index_is_in_limits to cpufreq_is_in_limits -remove redundant outer parenthesis in return statement -Make comment single line -- --- include/linux/cpufreq.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index afda5f24d3dd..7741244dee6e 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -1021,6 +1021,19 @@ static inline int cpufreq_table_find_index_c(struct cpufreq_policy *policy, efficiencies); } +static inline bool cpufreq_is_in_limits(struct cpufreq_policy *policy, + int idx) +{ + unsigned int freq; + + if (idx < 0) + return false; + + freq = policy->freq_table[idx].frequency; + + return freq == clamp_val(freq, policy->min, policy->max); +} + static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation) @@ -1054,7 +1067,8 @@ static inline int cpufreq_frequency_table_target(struct cpufreq_policy *policy, return 0; } - if (idx < 0 && efficiencies) { + /* Limit frequency index to honor policy->min/max */ + if (!cpufreq_is_in_limits(policy, idx) && efficiencies) { efficiencies = false; goto retry; } -- 2.25.1