Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp244087rdh; Wed, 7 Feb 2024 03:40:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWcstARktZHEa2WMBiUVTp0m4ua4z86fufBKiG01jk7N/1Np2YZWp3YlbqZ5V/7dnynDxlQJozKCKRz0uMfTTNLddR7qxkzcp3gSQoY9A== X-Google-Smtp-Source: AGHT+IFvI6eASVC2bQltA2L52y/UQnu7PE13obKtngw2IxigN6hQf3+HGttBGVfk0upRZOdLUvcF X-Received: by 2002:a17:906:3005:b0:a38:3a78:1d0c with SMTP id 5-20020a170906300500b00a383a781d0cmr2937321ejz.55.1707306027005; Wed, 07 Feb 2024 03:40:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707306026; cv=pass; d=google.com; s=arc-20160816; b=bnjjOXRvozWvFARuZ/TWgly08Ali7cQPPw6w0JqN7qWBwSzI3Z8nR1erOuodhbIeNZ Cq0pH03VaP8MhlIYpa7uUM/Iz4niJAslolUGjvwHk0TqWrvNAS6VeD+5cPEgtu04D7PV EWQTCCLjELf/JJH1z7XaEhRkgOokoL0goXeZIEOn5kyO3gxq5ynQ470oGVMkEQyJDzA2 oerNpmbMd76oXVUC5/vHwdy3p+WUTJJ7KlqWVeOTsyfsTz07Ka62v/HoXGhnDel+cb1n sOor5jyBu+REACXZgYjQZjyJEYUPa11t5un2tRzHBOmSrTbAQoVkfvvq8BNcVxbXRRyu 7eNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=2wyfxg79Cf6sWnOVBatEVOykolJoy49LxuAb6udBATU=; fh=NVe3yFyI3al0ldl9UdYv4AZBrUoK+gSWCJj1EwNKXsU=; b=riJaRF2J8tn9t1ahf+5ixBALTc+VtBnLzPIfbW5RZrE2jbU4YM7wCzL3ItlhQhJGhb M2epuIXgtDgKkGMGAprjtLLp5qqjddeIhWZyymbF55+ODRfs/lnoQYU6jLmcqllfIeX8 LD8No3fpM2sLHF99ppXVdFZBjNdYKhcz6N8F/mam70ugGpeyOwNi1GXtV5nD9aQ3VAJ5 npzQjaGGhrbmE9aeYVXeEx0VndltCqHx1FlO9q1GPIFSIo0uGECtcUvF+BvQxuB+rKGo H1VPzZDW0fYkw4LKT2jFjh+y430EFiUo9yk2Pv8DamfuGEaLbR4wRB0O35AKX/z9dp9d wk7w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-56401-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56401-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVCkh9vg9SDAmzQuH1JfcJBW2Mjr2K2TKdoPDr6cAfmMQEyX8eK7wKjtgS+9cUMjV7G7ZgeGTI0Zv7SZNDOu++BPtItH+E376z6l26dAw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n1-20020a1709061d0100b00a381da7b31fsi804184ejh.226.2024.02.07.03.40.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 03:40:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56401-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-56401-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56401-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 BC94F1F23FA0 for ; Wed, 7 Feb 2024 11:40:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 62D9A1B582; Wed, 7 Feb 2024 11:40:16 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A67F719BBA; Wed, 7 Feb 2024 11:40:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707306015; cv=none; b=CKV/gds3KbB1VeZAnd5goStomhwAs4jdqdiJcMMffMNlK9Ih7HJYxwwv8+meRFaowyG57Jy9a1FvEVJJupG7yDP4FY7tq+L6v0r24Xdm0xhWDbwJLym3lDXmjTLokq2Z7Aiq0MNiicFnDCL69tokAI0M+e1gkhOc26khoiwQie0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707306015; c=relaxed/simple; bh=3RxULCQqTCej+mKyEk8otgcgo4i+w98owSqN13Hn9aQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kwfvRJqkzbWwuy6WLxLxIP/6t75Rj0kdrRbx4lLumYeV4DjDcs3di2Hww3fD+QIJIO3KV6K1BQJmnfEA12phl/Qu2agRf9nPuHQyROOooolMpE3t4jTn7sDPUwAleY2fxuxnt/9L6Xp+aAziOQFt4JWjrtaTAd+69QHMOlo102Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 8802A1FB; Wed, 7 Feb 2024 03:40:48 -0800 (PST) Received: from [10.1.30.29] (e133649.arm.com [10.1.30.29]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4F5803F762; Wed, 7 Feb 2024 03:40:04 -0800 (PST) Message-ID: <8e969ccb-888d-43c8-a9a2-d46bad4bf5e8@arm.com> Date: Wed, 7 Feb 2024 11:40:03 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7 15/23] PM: EM: Optimize em_cpu_energy() and remove division To: Lukasz Luba , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com References: <20240117095714.1524808-1-lukasz.luba@arm.com> <20240117095714.1524808-16-lukasz.luba@arm.com> Content-Language: en-US From: Hongyan Xia In-Reply-To: <20240117095714.1524808-16-lukasz.luba@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 17/01/2024 09:57, Lukasz Luba wrote: > The Energy Model (EM) can be modified at runtime which brings new > possibilities. The em_cpu_energy() is called by the Energy Aware Scheduler > (EAS) in its hot path. The energy calculation uses power value for > a given performance state (ps) and the CPU busy time as percentage for that > given frequency. > > It is possible to avoid the division by 'scale_cpu' at runtime, because > EM is updated whenever new max capacity CPU is set in the system. > > Use that feature and do the needed division during the calculation of the > coefficient 'ps->cost'. That enhanced 'ps->cost' value can be then just > multiplied simply by utilization: > > pd_nrg = ps->cost * \Sum cpu_util > > to get the needed energy for whole Performance Domain (PD). > > With this optimization and earlier removal of map_util_freq(), the > em_cpu_energy() should run faster on the Big CPU by 1.43x and on the Little > CPU by 1.69x (RockPi 4B board). > > Signed-off-by: Lukasz Luba > --- > include/linux/energy_model.h | 54 ++++++++++-------------------------- > kernel/power/energy_model.c | 7 ++--- > 2 files changed, 17 insertions(+), 44 deletions(-) > > diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h > index 689d71f6b56f..aabfc26fcd31 100644 > --- a/include/linux/energy_model.h > +++ b/include/linux/energy_model.h > [...] > @@ -208,8 +206,9 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, > return -EINVAL; > } > } else { > - power_res = table[i].power; > - cost = div64_u64(fmax * power_res, table[i].frequency); > + /* increase resolution of 'cost' precision */ > + power_res = table[i].power * 10; NIT: Does this have to be 10, or something simple like << 3 (* 8) also does the job? Although compiler these days often are clever enough to convert x * 10 into (x << 3) + (x << 1), and this is not on the hot path anyway, so just a NIT. > + cost = power_res / table[i].performance; > } > > table[i].cost = cost; Reviewed-by: Hongyan Xia