Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp209701rdb; Thu, 8 Feb 2024 03:57:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVEMUYXJbIhaPhy+Zn+/toW8k1r4bMQhesDuU878Uq/Wwzh6qabjqSqkKLirrJ4oaT+hujPZxzjoazlfi3r0X/Gr2WaXUHIuDFJwu3q4A== X-Google-Smtp-Source: AGHT+IEcnbWZ+i06bBJuyh+nOkOvsWyE01bXk+aBDu+5Zf268EK1Ttyw9A2g5B8GB5kLPJg8XoW4 X-Received: by 2002:a05:620a:2191:b0:785:a0fd:26c with SMTP id g17-20020a05620a219100b00785a0fd026cmr3243823qka.36.1707393443770; Thu, 08 Feb 2024 03:57:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393443; cv=pass; d=google.com; s=arc-20160816; b=gOrljww2T3Sh3klb99Dtp51vqXrDIpXE7ItuRS6e+Dfa868AiJoiho56MLC6Q5r9ko 6N1tmFwVM/fJLDNDARbb+yl4/Xtw80F5+fTSQj3TTbs2wrzIHNuoNHquOaVwpHUFzZw9 NRdT51p+AI/BrPhRt5Mk6DAUzEk96mKwZgNRUrHIILia9aA8ZL80evpp4Y10MJUdkAp9 NGmwcFVaAEBXihNFglL7+9aa4GjT/mOyiQSvFRe8u7/+YN/OCN6yQeRpINL8cZHoaOGV PoO7gIpABo+oUVEHiZzxvzu45JBmGezy7CmLsZCfB5Xd/2z0RG/eco1D8k6a4HU5+D38 CBDQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from; bh=/r4N6VsZ8/qe/wqCW0BqzD+PyOsJELYWwW7UyTyMS6I=; fh=v3hIuf4BuYxdHkY9cmMTHKNWWpnQQ7R5ZNwY8s8UHpA=; b=t/7/njHJx+kywPI0DY//vy24jlSXpsoH2tEyqnY5s/cxjNToojbdpzChtEzJrnwWqw Rs8JdVBzSWoJi1rc7Gm/sX+3LjzQdLzQGjgqCce7z589IgfB1xFqAo2PToWPpcToK0OI GjN/BkWMgQ6ty/5nNqODBacz/kEwRi18zitTBTw7vqMoCAWXSzSjmduzM8Wn3FKA83+x In7svWIds26VLgt60A0dVVce7Z45/udvKpPHNsmVottb/l5GG1LEq50P3j+lEvLWY2/V G5AzqJ++rfCMi4YjYj2W0AVajBypXh3szs11sWxc6mHkORNy8lo8lASkwzPMF8GOrAP+ va6g==; 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-57997-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57997-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; AJvYcCVO8HCg98H7h0X0bJy679hVl7Q3+M+lcQtm8pTsKWF2/AMMo3ubV/oaZLKUv+E79sJAkapbW+yVSVoCNKi3dzrdmzlplLYZU3R8Tm6rNw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a23-20020a05620a125700b0078401633e31si2998539qkl.509.2024.02.08.03.57.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 03:57:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57997-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; 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-57997-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57997-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 77C6B1C2488D for ; Thu, 8 Feb 2024 11:57:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 23F7B762E3; Thu, 8 Feb 2024 11:56:21 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6C241762C5; Thu, 8 Feb 2024 11:56:18 +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=1707393380; cv=none; b=Snd0jMfugaC2abcw3tNSrXJ5UNHbbR0yo0MC0JlIrl5ZYcDGqw45OSHfT26o4LUU54R4Iln6lgPP+MeeumMM0oc7poa/o0+QSRcRNuyNJ4n9jMaXWnqd5nkK/mNCUVsbu1kIO7QfmMKBJOxGSlHwi/SFApWFf3uh6hSfY965QSA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393380; c=relaxed/simple; bh=EgS98AzIrfTEkTeSSi8iSkdXy/W4/EMIsMiXga11j8A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UozrOH42QHl4DlAHS5VCh+1GmR6JU+QP6YU40jHjviRTbkxxgIZHT6ksRoIfuiXAYo/ZwYWeDgrYAhFNcttYhb54ZF/pAkwHlQy0s6cMyAyPWKMZilpkhB2pEzRyJuGHFd+sjPkSPf30KkNeBlDxNRgoeR55/CQdqLdlhtGRWIQ= 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 F30501FB; Thu, 8 Feb 2024 03:56:59 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EE4093F5A1; Thu, 8 Feb 2024 03:56:14 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, 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, Hongyan Xia Subject: [PATCH v8 04/23] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Date: Thu, 8 Feb 2024 11:55:38 +0000 Message-Id: <20240208115557.1273962-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The Energy Model (EM) is going to support runtime modification. There are going to be 2 EM tables which store information. This patch aims to prepare the code to be generic and use one of the tables. The function will no longer get a pointer to 'struct em_perf_domain' (the EM) but instead a pointer to 'struct em_perf_state' (which is one of the EM's tables). Prepare em_pd_get_efficient_state() for the upcoming changes and make it possible to be re-used. Return an index for the best performance state for a given EM table. The function arguments that are introduced should allow to work on different performance state arrays. The caller of em_pd_get_efficient_state() should be able to use the index either on the default or the modifiable EM table. Reviewed-by: Daniel Lezcano Reviewed-by: Hongyan Xia Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 88d91e087471..1dcd1645dde7 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -175,33 +175,35 @@ void em_dev_unregister_perf_domain(struct device *dev); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM - * @pd : Performance domain for which we want an efficient frequency - * @freq : Frequency to map with the EM + * @table: List of performance states, in ascending order + * @nr_perf_states: Number of performance states + * @freq: Frequency to map with the EM + * @pd_flags: Performance Domain flags * * It is called from the scheduler code quite frequently and as a consequence * doesn't implement any check. * - * Return: An efficient performance state, high enough to meet @freq + * Return: An efficient performance state id, high enough to meet @freq * requirement. */ -static inline -struct em_perf_state *em_pd_get_efficient_state(struct em_perf_domain *pd, - unsigned long freq) +static inline int +em_pd_get_efficient_state(struct em_perf_state *table, int nr_perf_states, + unsigned long freq, unsigned long pd_flags) { struct em_perf_state *ps; int i; - for (i = 0; i < pd->nr_perf_states; i++) { - ps = &pd->table[i]; + for (i = 0; i < nr_perf_states; i++) { + ps = &table[i]; if (ps->frequency >= freq) { - if (pd->flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && + if (pd_flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && ps->flags & EM_PERF_STATE_INEFFICIENT) continue; - break; + return i; } } - return ps; + return nr_perf_states - 1; } /** @@ -226,7 +228,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, { unsigned long freq, ref_freq, scale_cpu; struct em_perf_state *ps; - int cpu; + int cpu, i; if (!sum_util) return 0; @@ -250,7 +252,9 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * Find the lowest performance state of the Energy Model above the * requested frequency. */ - ps = em_pd_get_efficient_state(pd, freq); + i = em_pd_get_efficient_state(pd->table, pd->nr_perf_states, freq, + pd->flags); + ps = &pd->table[i]; /* * The capacity of a CPU in the domain at the performance state (ps) -- 2.25.1