From patchwork Wed Jul 8 07:53:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 235041 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp205408ilg; Wed, 8 Jul 2020 00:53:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGE06kLRBZ4kECV5JvtY/4RM5ubf/FzL+u9aouofTaelyJO4TZc2tHwt/wZCymtaUnkUcq X-Received: by 2002:a17:906:694d:: with SMTP id c13mr48888237ejs.337.1594194839323; Wed, 08 Jul 2020 00:53:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594194839; cv=none; d=google.com; s=arc-20160816; b=GDalZcmuQRYw0snsHJGkZ5oOQbgc4bp5fm8/lkPEY1Z6Fyn4KiTEBoXWkejrbAYZxa I6owzr6UfNoSvesji8ANhw7OJAX6FjT+CLV3vGQePSCItRDsLEflsX7gllvjy80yXgjA wERF45YaFRlzapdb/AvIZG6qvIGLO3qR4PnpNxVZkzro4bXf0fNqvkP/uZODidwAzRLh 1Ny9/R9g4lm7phjwcYPqJTE4H75C23QcopaTmG60NhQ4VgryGjN2CKF/aAWn0UvbZoTK Q7ETSUUyjlcg+guaPLrGigLpvqHrIYJne7tRfx44T7RzCrTDLVxWl4TUaQYRssNcn3hl yFpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Y55nygfLWId4LN/DVfidqEEz07PpT+kE/Of591U6tQ4=; b=nX2IGIJ77TefeXwhOqZjlxDraS2fHfT0uv0xJN+xUSInURDBzvjTxVac4M7XSoxxn9 A5oZykFZfAafswB/e+sHvFjzVz6KDWwJIvejQVYvkxMpszYwDMpEObrEPffyr1maMb6i rQDVK9bnqTZnCyEvGXAnSKMurlhlhYBAXYToX+VMAR9d3EdwGk/wmePJLor/gYSOE0Wa GniKQnYhU8HLwUJ6+n0o/VZHtsb6PjC8I1MjzYvD5phRgFokRN/Z3k9e+FYGltCj4M4g BlIJpp7Mus0SnTOgwaONJ+TluW+lYUKdE/LREmvsXmoP9N17f6VK99e2aLZC/emB4OYC J36A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xg5+rbjB; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l16si16490310edw.377.2020.07.08.00.53.59; Wed, 08 Jul 2020 00:53:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xg5+rbjB; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727963AbgGHHx6 (ORCPT + 10 others); Wed, 8 Jul 2020 03:53:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727953AbgGHHx6 (ORCPT ); Wed, 8 Jul 2020 03:53:58 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DC4DC08E6DC for ; Wed, 8 Jul 2020 00:53:58 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id u185so17575945pfu.1 for ; Wed, 08 Jul 2020 00:53:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Y55nygfLWId4LN/DVfidqEEz07PpT+kE/Of591U6tQ4=; b=Xg5+rbjB4NptqIoHOkzJD8CBC9CdjUtEiqL6VhBe9weMoDUPG2r3x3/raQHvb+DQfw z7VO288nlBCiFbODbJrcXUvNxl2qAwJp4QuldqLdXN6AMj9eMqdOkVyiYG/91TWuIuvC j2L0f69XENjZEe26MlLnqG0lemBcCDxqqFoXWxYq6Vcy5lINlm18YvOPVR8Di4PnIh3w DJQrNXwsbvEfzAHgFVkBFtkpJ6X2qFDCiaI7z4xK1T6JmywW7ZFzl2rjwFOH6RRVBDhl pvQSyELHn9KwzfgDJx0yo6LGJuLYdqg+du4ZiHgZ7nXmznz2YYghQY1oVwn3oMgzzGss IkoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Y55nygfLWId4LN/DVfidqEEz07PpT+kE/Of591U6tQ4=; b=V+hKbBqmNIwfC1ImlSPzJG424pxyKCvwBK9wT2729gj74P6JLNZvIXg1D2EJAcqIbT BSv2qFcP8tXxd9FyXsm7pq8XXoIpnYKksPhjYgjOVh1YutgVBNopgAkgTCyrzNidRovZ q5UqXcW+duazK8j9d/cRsEgSHVFel5NZg1pGVcghwAUvRof6Rtau6wqWSl8phwvtOKI6 yN95ouCQzjR66TZG5Y4bYX17KcLtTkH7wlUkeiwukzxPqFvxmhTtMUSA4evlTLo/skDR NrFGBXFzoGJkguhba4cxwDyhx6LuJrhkk8kDPCnilualP7YQmxIu1NwpNuTv9Hr3VyBo uMIA== X-Gm-Message-State: AOAM532E7FTdCUF0sCvPgShk7qpYfHpwEZZ24e5nCOq0AvE9Hs1/ViBB xt0Q2QGAAW9V0uvyGtsPwR57gA== X-Received: by 2002:a62:178e:: with SMTP id 136mr51909249pfx.180.1594194837422; Wed, 08 Jul 2020 00:53:57 -0700 (PDT) Received: from localhost ([122.172.40.201]) by smtp.gmail.com with ESMTPSA id m68sm4672626pje.24.2020.07.08.00.53.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jul 2020 00:53:56 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org, Amit Daniel Kachhap , Viresh Kumar , Javi Merino , Zhang Rui , Eduardo Valentin Cc: Vincent Guittot , Finley Xiao , Amit Kucheria , Daniel Lezcano , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [For-STABLE] thermal/drivers/cpufreq_cooling: Fix wrong frequency converted from power Date: Wed, 8 Jul 2020 13:23:43 +0530 Message-Id: X-Mailer: git-send-email 2.25.0.rc1.19.g042ed3e048af MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Finley Xiao commit 371a3bc79c11b707d7a1b7a2c938dc3cc042fffb upstream. The function cpu_power_to_freq is used to find a frequency and set the cooling device to consume at most the power to be converted. For example, if the power to be converted is 80mW, and the em table is as follow. struct em_cap_state table[] = { /* KHz mW */ { 1008000, 36, 0 }, { 1200000, 49, 0 }, { 1296000, 59, 0 }, { 1416000, 72, 0 }, { 1512000, 86, 0 }, }; The target frequency should be 1416000KHz, not 1512000KHz. Fixes: 349d39dc5739 ("thermal: cpu_cooling: merge frequency and power tables") Cc: # v4.13+ Signed-off-by: Finley Xiao Acked-by: Viresh Kumar Reviewed-by: Amit Kucheria Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/20200619090825.32747-1-finley.xiao@rock-chips.com Signed-off-by: Viresh Kumar --- Hi Greg, I am resending this as I got your emails of this failing on 4.14, 4.19 and 5.4. This should be applied to all three of them. @Finley: I hope I have done it correctly, please do check it as this required me to rewrite the code to adapt to previous kernels. drivers/thermal/cpu_cooling.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.25.0.rc1.19.g042ed3e048af diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 908a8014cf76..1f4387a5ceae 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -280,11 +280,11 @@ static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev, int i; struct freq_table *freq_table = cpufreq_cdev->freq_table; - for (i = 1; i <= cpufreq_cdev->max_level; i++) - if (power > freq_table[i].power) + for (i = 0; i < cpufreq_cdev->max_level; i++) + if (power >= freq_table[i].power) break; - return freq_table[i - 1].frequency; + return freq_table[i].frequency; } /**