Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1402211pxj; Fri, 21 May 2021 13:22:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwy9DyVFy+jbb14zB5V+R6IF9HAJnE4jDAZw3C9dW9vJHHgJ/D8aSxpKM5s+uh2pchxwWcG X-Received: by 2002:a92:ca0e:: with SMTP id j14mr552434ils.271.1621628558779; Fri, 21 May 2021 13:22:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621628558; cv=none; d=google.com; s=arc-20160816; b=FrxTqq6uw3QHC/pxWMphKYrVNVTC9clorK3ElijKtLPjROgjbJoYScwxHu13Kn06+L +tf93I1t0bxu0Z8egyd+AN7ibwVAvPzd6iKc7zzkONK59wGyszor6umL5NdgNhGJCwzL I4wINPN86qkgqsrhR5FjoiSwoDjXUuepHv7zzZAMjXOdSwWHT3rkGu5r1nAo+OiQLNZ5 B7twCdP8onAVYBNUm1DdNJGy7xtsdTt/MiHbpvIZ0fpDbA7Iqqbj0nV3GMaQJk80u/yx B1uKumbi99BPRpd8Dled1p6gQGlFavUnuhVWQsmTCChXo8x+radEzNLITWHerKuoiPNL SqPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=9IeA6EHeFVGoZHZ0tBCV5ZvCnuDFnPqY3eGCT1/Os7Y=; b=sKPz9LKg2jSYBCYtF0AVApNvaMkJauXrLFoGmBgRPmMrD1joc7FFbV3KClfJf2H+1U +pV0SKWw3cjJZ++de2SevCZqEPM8ZO6IyOxwUTavWxr/4CD4pfV/CYtGl1rz6q8WDVTV u+h6A8MmT0l+3rMtahHzhbRnb0yuK4lbbelf2bqn4+m/ZLiZRCy23ywmPtWTxvlDa6Fu 7wXoMmas5PkzQzIUPtU0t5uU7/H++bCa8/TFbef5HGICuZ9TRsPbW61IJmGAlt90w01g IyyjnR4SyUFlaF48MYOP2botrBeeKs+GL9WicHDyFZCigW1byktDVL7JaNLC+dkk7T9l rdVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u9si7381904jat.83.2021.05.21.13.22.26; Fri, 21 May 2021 13:22:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237819AbhEUQ4R (ORCPT + 99 others); Fri, 21 May 2021 12:56:17 -0400 Received: from foss.arm.com ([217.140.110.172]:51560 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237802AbhEUQ4Q (ORCPT ); Fri, 21 May 2021 12:56:16 -0400 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 B4A5E1480; Fri, 21 May 2021 09:54:52 -0700 (PDT) Received: from e120877-lin.cambridge.arm.com (e120877-lin.cambridge.arm.com [10.1.194.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5FD103F73D; Fri, 21 May 2021 09:54:51 -0700 (PDT) From: Vincent Donnefort To: peterz@infradead.org, rjw@rjwysocki.net, viresh.kumar@linaro.org, vincent.guittot@linaro.org, qperret@google.com Cc: linux-kernel@vger.kernel.org, ionela.voinescu@arm.com, lukasz.luba@arm.com, dietmar.eggemann@arm.com, Vincent Donnefort Subject: [PATCH v2 1/3] PM / EM: Fix inefficient state detection Date: Fri, 21 May 2021 17:54:22 +0100 Message-Id: <1621616064-340235-2-git-send-email-vincent.donnefort@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1621616064-340235-1-git-send-email-vincent.donnefort@arm.com> References: <1621616064-340235-1-git-send-email-vincent.donnefort@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, a debug message is printed if an inefficient state is detected in the Energy Model. Unfortunately, it won't detect if the first state is inefficient or if two successive states are. Fix this behavior. Signed-off-by: Vincent Donnefort diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 0c620eb..c4871a8 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -107,8 +107,7 @@ static void em_debug_remove_pd(struct device *dev) {} static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, int nr_states, struct em_data_callback *cb) { - unsigned long opp_eff, prev_opp_eff = ULONG_MAX; - unsigned long power, freq, prev_freq = 0; + unsigned long power, freq, prev_freq = 0, prev_cost = ULONG_MAX; struct em_perf_state *table; int i, ret; u64 fmax; @@ -153,25 +152,19 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, table[i].power = power; table[i].frequency = prev_freq = freq; - - /* - * The hertz/watts efficiency ratio should decrease as the - * frequency grows on sane platforms. But this isn't always - * true in practice so warn the user if a higher OPP is more - * power efficient than a lower one. - */ - opp_eff = freq / power; - if (opp_eff >= prev_opp_eff) - dev_dbg(dev, "EM: hertz/watts ratio non-monotonically decreasing: em_perf_state %d >= em_perf_state%d\n", - i, i - 1); - prev_opp_eff = opp_eff; } /* Compute the cost of each performance state. */ fmax = (u64) table[nr_states - 1].frequency; - for (i = 0; i < nr_states; i++) { + for (i = nr_states - 1; i >= 0; i--) { table[i].cost = div64_u64(fmax * table[i].power, table[i].frequency); + if (table[i].cost >= prev_cost) { + dev_dbg(dev, "EM: OPP:%lu is inefficient\n", + table[i].frequency); + } else { + prev_cost = table[i].cost; + } } pd->table = table; -- 2.7.4