From patchwork Thu Feb 8 11:55:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 198342 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp110319dyd; Thu, 8 Feb 2024 03:58:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW79OtLWpQecvLr5qeIn0tHC8gRjaM5YysJD5TiFNaY21HaNJUCvEYsOlm5i5DPPcnuCioRPSpMPOKbaARxYyhUI0cWjg== X-Google-Smtp-Source: AGHT+IFTnzSD2k4Bjib++mafPUbe9D4d/6UJeMu9Bl5V/gIarHqKTEWhHOuKwhcqPvBlBgj99m9Y X-Received: by 2002:a17:90b:2e0d:b0:296:2ce2:5b3c with SMTP id sl13-20020a17090b2e0d00b002962ce25b3cmr5231487pjb.20.1707393497628; Thu, 08 Feb 2024 03:58:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393497; cv=pass; d=google.com; s=arc-20160816; b=GFHxPdJD7VVSB+S65kNfwqN/5oTTaH2OOd/48mgAt+7dg3dx3gS/5lPlqGmrZkDRgI uUO+6yibc/ZOeA9ttgqh4P72bm3nZklO5J1L0omaKDrfGciAkVOa8ltk3nvLm6SaULBU m+2CCLcEgNHxLavkfNwda3jTWPtOvIFq6ND0uxEQ6UW88Ey7YxxnqqkII2xEWQ2qHKpB 6l7kn58QqkcppjhPHnySKPWkHMjbrN5stOuRxOFHgMJWSrHmyA8BKR464YrkdeKuFKVe 0YS/inipq5qa8kebKe5X74vD+R5+lSXicRkoiFrbvgiwmKZ8cipIs6NsVmcNGh3x0BsU S4lA== 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=r75b9yAGSdpOyl9uKgAKk0nWf04cFAgLBVceqMPZ2DI=; fh=OfBcl6ftAea+zKVRru6JEhFxNd3RNS6MkVAJxaBvVtc=; b=K13LcOGHNK+6CdRFlKJi01wPu9YIS/XqZ9XyHbTJULkwzKCv2c9zp6oNCmYJpbgdfD A4GPqu1oPY5Y/EpHJooYiL5MCp6meX3T5G9vQpeGdYNagklcIFJjoMaKlbs85nErOj8i XgmrgNWeavVkglY0baLuawEyQ9yJYL/jTx4dn8OM/waeOzxMbJOzRQSprxzp4ryd0r3y A7+OuCl0TEW/0iX4oodxdJBq5fWmZ3dM/1SPONnwLXbvEuZKy/dnBAVRaU2mXwWjow3l awj/E06acydsWsPKZoRgpFIXdBeD4PXLkVin2kJArxlmChfJevJIZ22rqT/E3gwBM+FV EK5Q==; 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-58000-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58000-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCU10cr6hN2h7p5Z5T1OWnILYV3J+Tz/M5jyBmpAIBvhFf54eul2OZcvHBWoMlAN7OsO+pKfE6dmHAdwb+ENDlLfz+QMTQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h3-20020a17090aa88300b00296454b0b6fsi1156907pjq.103.2024.02.08.03.58.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 03:58:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58000-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-58000-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58000-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 68C7A28C006 for ; Thu, 8 Feb 2024 11:58:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F19CD7691B; Thu, 8 Feb 2024 11:56:30 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73DCE7640C; Thu, 8 Feb 2024 11:56:27 +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=1707393389; cv=none; b=OumosfupNZKX472XKvzGp96Iodm/aMk+ZfqLwWBAoNx8YW/6uhnAeAgmoURp5mbftcs3R1RnYZkGEeMHjWQgiKOUt54UmHyQSfdVQz3nFBs+1vCehezs41ybjcQCMAWgwUvNRipj54oRUf6l+KD1nGTGBByy+RuU5cYmNkc9mlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393389; c=relaxed/simple; bh=uOfszU8onKghXMWUp5uW3OMPxsyNzrUd6JfObHueJo0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iE+BK5K2pVSUbOBhLD21F2BYaRLmg+5ayMrhV6z14K80pPyp9FsabPDVIjRpChLIlTgC9zUf4bKSXU8B2sYlui+as+KDBtNNRgyYi/drjl/AccGLTCpQdfhvjLrRnumTdTtESH4DaZXI8RNN3Zj4CVkdxWu8qldiNT47FdDjixA= 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 21E031FB; Thu, 8 Feb 2024 03:57:09 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 403393F5A1; Thu, 8 Feb 2024 03:56:24 -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 Subject: [PATCH v8 07/23] PM: EM: Split the allocation and initialization of the EM table Date: Thu, 8 Feb 2024 11:55:41 +0000 Message-Id: <20240208115557.1273962-8-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790331844616086968 X-GMAIL-MSGID: 1790331844616086968 Split the process of allocation and data initialization for the EM table. The upcoming changes for modifiable EM will use it. This change is not expected to alter the general functionality. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 55 ++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 21d761223255..7468fa92134b 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -142,18 +142,26 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, return 0; } +static int em_allocate_perf_table(struct em_perf_domain *pd, + int nr_states) +{ + pd->table = kcalloc(nr_states, sizeof(struct em_perf_state), + GFP_KERNEL); + if (!pd->table) + return -ENOMEM; + + return 0; +} + static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, - int nr_states, struct em_data_callback *cb, + struct em_perf_state *table, + struct em_data_callback *cb, unsigned long flags) { unsigned long power, freq, prev_freq = 0; - struct em_perf_state *table; + int nr_states = pd->nr_perf_states; int i, ret; - table = kcalloc(nr_states, sizeof(*table), GFP_KERNEL); - if (!table) - return -ENOMEM; - /* Build the list of performance states for this performance domain */ for (i = 0, freq = 0; i < nr_states; i++, freq++) { /* @@ -165,7 +173,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (ret) { dev_err(dev, "EM: invalid perf. state: %d\n", ret); - goto free_ps_table; + return -EINVAL; } /* @@ -175,7 +183,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (freq <= prev_freq) { dev_err(dev, "EM: non-increasing freq: %lu\n", freq); - goto free_ps_table; + return -EINVAL; } /* @@ -185,7 +193,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (!power || power > EM_MAX_POWER) { dev_err(dev, "EM: invalid power: %lu\n", power); - goto free_ps_table; + return -EINVAL; } table[i].power = power; @@ -194,16 +202,9 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, ret = em_compute_costs(dev, table, cb, nr_states, flags); if (ret) - goto free_ps_table; - - pd->table = table; - pd->nr_perf_states = nr_states; + return -EINVAL; return 0; - -free_ps_table: - kfree(table); - return -EINVAL; } static int em_create_pd(struct device *dev, int nr_states, @@ -234,11 +235,15 @@ static int em_create_pd(struct device *dev, int nr_states, return -ENOMEM; } - ret = em_create_perf_table(dev, pd, nr_states, cb, flags); - if (ret) { - kfree(pd); - return ret; - } + pd->nr_perf_states = nr_states; + + ret = em_allocate_perf_table(pd, nr_states); + if (ret) + goto free_pd; + + ret = em_create_perf_table(dev, pd, pd->table, cb, flags); + if (ret) + goto free_pd_table; if (_is_cpu_device(dev)) for_each_cpu(cpu, cpus) { @@ -249,6 +254,12 @@ static int em_create_pd(struct device *dev, int nr_states, dev->em_pd = pd; return 0; + +free_pd_table: + kfree(pd->table); +free_pd: + kfree(pd); + return -EINVAL; } static void