From patchwork Wed Jan 17 09:56:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188752 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp800776dye; Wed, 17 Jan 2024 01:56:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IENzoR67Hox74h8QUu4glcQAweEmchaGFYuF18jDLWubMghktgRNc/KWGC3DLYTR36HN1Ub X-Received: by 2002:a17:906:b797:b0:a26:c9e6:d5e0 with SMTP id dt23-20020a170906b79700b00a26c9e6d5e0mr2629427ejb.74.1705485408650; Wed, 17 Jan 2024 01:56:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485408; cv=pass; d=google.com; s=arc-20160816; b=rEW26nZPX1mSKZarsp0Wp3rnWVIAcq9eBRv3EsTCEGdsZkainUz6nBLcfeQoLeHeY0 TnZ4+t/B9VWDH5LjfqNqcNAbMZzne4dgPExbLDrSBaJPbN4yL7CR6gVOb54NILovRDWE 8TMj5nz8ZyWnK2eRpDpqy8yY0pWRTTGkKBk1/8GhS9zEZ4XTQQj6gsga60VJbWXPsqUg v1F9gKo+HeWDozjm0KFAzM7soSVEn5RQBC0WI9R4Nroe9BfwdRWg4u0WOXKDwbl921n/ JsnrQY4bT8OpNC/QMlMnLULQ53dYL4gDPSgHZuMkfqKB0UEhyC5GTjVypxqoOUtMvOIw +VXw== 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=uGhco7J5TgdBe4HVHErzn104yzI0XoRDssU6JxBLmLw=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=pnOxLGopAD8RdE4anXuuUtiQPRk1RG2StE/rfS8M0Fd36cBDw5xwQ25yLkUhobw5ss kaydVdulvzYZZEJHpipCu6ZVJZKC4UZnIfqlevuFwpgSgmS7WlUlP4ius2a5JE1s6Umy v8lLculdODayoy9nGJ8s9098ycZuWhCpXngnEpLo6F2IdjQx81I3XAj6fsz+pIfOlbxU Dj1NLxc9sGjQv4BZJpkY56YzCXMVpHhIGvC3UudLKCa1D0yBoRN2v54Yt8IQQF1wAkgK YtYuZTrvd/yVm5b2y7izNQ3DiFuila4wIHkKvPwaJzuePYTcKaudh0KcsGSwNT08w4vC tvow== 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-28772-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28772-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e23-20020a170906c01700b00a2cd616e28fsi4478011ejz.284.2024.01.17.01.56.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:56:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28772-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-28772-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28772-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 449721F2320C for ; Wed, 17 Jan 2024 09:56:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ECD541CAB6; Wed, 17 Jan 2024 09:56:06 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E19515EA2; Wed, 17 Jan 2024 09:56:03 +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=1705485365; cv=none; b=gpCkuS5KTbmn3UYZKmuQ5mzxOH94xAbMwcnPopHTGu4OlXlEvSbgI+7+YoVaPSre+Ex0wtZcpKkrNU9K7B1ItECClFtN4zy7UDRXJGrvhk+pRhUmfKfGxYXYxS0occaYsO8UPkWDOuhC44pxZZQwm8ILQ3FjwVvxODB1fFiNxVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485365; c=relaxed/simple; bh=6Wi5CZcTdePdWR3CmLK/lfq50M9LGiUfZZMfj9IusOE=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=J9p9oGQezd1cWKTWcdgr2KrlVu55cLqHpp9REG38CcxarpYtjqw6BsK1HIg3AqmR8WD2l4nYUhe93R/4BJarNfvDRNj7MfC6tHSpmpHTxXtjF8RPSp+nzk4v2D51UUgtw55ljZbNJL0KCe7nUV1yVQmHGkEBXvEn6QgCBEHfp6M= 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 1C211DA7; Wed, 17 Jan 2024 01:56:49 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 372AE3F5A1; Wed, 17 Jan 2024 01:56:00 -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 v7 02/23] PM: EM: Extend em_cpufreq_update_efficiencies() argument list Date: Wed, 17 Jan 2024 09:56:53 +0000 Message-Id: <20240117095714.1524808-3-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331067550251008 X-GMAIL-MSGID: 1788331067550251008 In order to prepare the code for the modifiable EM perf_state table, make em_cpufreq_update_efficiencies() take a pointer to the EM table as its second argument and modify it to use that new argument instead of the 'table' member of dev->em_pd. No functional impact. Signed-off-by: Lukasz Luba Reviewed-by: Hongyan Xia --- kernel/power/energy_model.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 8b9dd4a39f63..42486674b834 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -237,10 +237,10 @@ static int em_create_pd(struct device *dev, int nr_states, return 0; } -static void em_cpufreq_update_efficiencies(struct device *dev) +static void +em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table) { struct em_perf_domain *pd = dev->em_pd; - struct em_perf_state *table; struct cpufreq_policy *policy; int found = 0; int i; @@ -254,8 +254,6 @@ static void em_cpufreq_update_efficiencies(struct device *dev) return; } - table = pd->table; - for (i = 0; i < pd->nr_perf_states; i++) { if (!(table[i].flags & EM_PERF_STATE_INEFFICIENT)) continue; @@ -397,7 +395,7 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, dev->em_pd->flags |= flags; - em_cpufreq_update_efficiencies(dev); + em_cpufreq_update_efficiencies(dev, dev->em_pd->table); em_debug_create_pd(dev); dev_info(dev, "EM: created perf domain\n"); From patchwork Wed Jan 17 09:56:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188753 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp800848dye; Wed, 17 Jan 2024 01:57:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEDhr+mqwFXEBC1DWun07llBMSox/jbfa04lvxITz/R7rLuI9itEKDPsfEElOmri80dQd7 X-Received: by 2002:a05:6102:1888:b0:468:12a:6773 with SMTP id ji8-20020a056102188800b00468012a6773mr4851535vsb.3.1705485422354; Wed, 17 Jan 2024 01:57:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485422; cv=pass; d=google.com; s=arc-20160816; b=Kn/sPvZJ5YFN+dmrV3wMwSSxD/JKi9o9RpSa7N78aM3gGenVKMEGPuvj8urSOArEmy I7+j4mCHbrsNy6f5cyvyddRexas9ZFKN4WvnM2ipvQNZUnbu5v6+8BT2tSM5JnXhnwbM aM7spucfyqGfKBl/+4LH+Acf/UnKPaarAZik8WN6CHIkU8BclO1xeODiRv+0I/ks8Fl+ vELiTKLzRfmR6htLpXwli0in5iRSasEeyHUir+F+4neLZXo559EF7Xa8xp51GXE/iNAG aNIuW/PyPSnejZCWJ5BXOJ8hVAtFE2/1RPpRtnx6s0oIDY2xyU57Q2tJpgfgzhp9ndmh Iwog== 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=Dn3T/Q0d9aQheDGMy+OaTURuhfWKkx83TyCMS1BTVoQ=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=MSr0HIhBkxoVAnnWkH7C/Cqa8ZK1qqUyGgSYJEqfeybbiXKlTwWdzd56UIsV9zWFpk anXVVMLcNOd4EkDoRyRWSGkhNvVq+rb8W4AY+Qkrck3DYsm8XMbDkuYedrwQjKXk1Y64 K1aGQwmQ4yqBn+Y14VjajU3Mq31aq8r7JeAJDTAkta4fn7X2H8uKp+aC4FZnMczhBvTh 5OMYyBH/k7LaKr6f91nruRW5pQyUTAhejbwfwaJo3X00gFWQ3deQUxragSXMhpkUDPKr IJAMO/CsUwWSrGCszbIAUCD+m8ttPNmhHVDVa6ohFVVyI0/Zt4SA9obf/hZWwR9FQEpT A6xw== 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-28773-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28773-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b22-20020a0cb3d6000000b0068063f0d760si3167755qvf.404.2024.01.17.01.57.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:57:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28773-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-28773-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28773-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2720C1C2450A for ; Wed, 17 Jan 2024 09:57:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 50AB41D687; Wed, 17 Jan 2024 09:56:09 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33A7D1BF31; Wed, 17 Jan 2024 09:56:06 +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=1705485367; cv=none; b=aghV5UU97222RDWACjsXtyYNGJa9sxg8ooVRToODNVFSe89IPtTn1dgQVrLD7gTAcTBe5H91uKQxjD3iXLBWo54b2uO+N+dCWdj0n1jVO5oCQcH0YOOZ1YXE49R1svOBuRuA7F0zSCVX4hZOcUz+bW1bRT1yCzFm7tX/o87KvTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485367; c=relaxed/simple; bh=F95ZfpYEK24miPqt4g6SQTKtaEf9bFaTmeWUelc2lTo=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=KyevuwI5bZMk1or8LpeqNJJGOVLHyz631RzkFlzb0GiiLzQe56VOATW82QKaCX9+XqBbXqaK+mpIqEFDDp8JOEgca6orbLnRU0CKSHZxY7Eb/dLapq5gnCPnq8T2soU4wS4RaYbYp4E5aTfXVehchgCEMZ18/ZXq7cPnUpKEim4= 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 114E3DA7; Wed, 17 Jan 2024 01:56:52 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3AC273F5A1; Wed, 17 Jan 2024 01:56:03 -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 v7 03/23] PM: EM: Find first CPU active while updating OPP efficiency Date: Wed, 17 Jan 2024 09:56:54 +0000 Message-Id: <20240117095714.1524808-4-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331082280367696 X-GMAIL-MSGID: 1788331082280367696 The Energy Model might be updated at runtime and the energy efficiency for each OPP may change. Thus, there is a need to update also the cpufreq framework and make it aligned to the new values. In order to do that, use a first active CPU from the Performance Domain. This is needed since the first CPU in the cpumask might be offline when we run this code path. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 42486674b834..aa7c89f9e115 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -243,12 +243,19 @@ em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table) struct em_perf_domain *pd = dev->em_pd; struct cpufreq_policy *policy; int found = 0; - int i; + int i, cpu; if (!_is_cpu_device(dev) || !pd) return; - policy = cpufreq_cpu_get(cpumask_first(em_span_cpus(pd))); + /* Try to get a CPU which is active and in this PD */ + cpu = cpumask_first_and(em_span_cpus(pd), cpu_active_mask); + if (cpu >= nr_cpu_ids) { + dev_warn(dev, "EM: No online CPU for CPUFreq policy\n"); + return; + } + + policy = cpufreq_cpu_get(cpu); if (!policy) { dev_warn(dev, "EM: Access to CPUFreq policy failed\n"); return; From patchwork Wed Jan 17 09:56:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188754 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp801029dye; Wed, 17 Jan 2024 01:57:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnVU1NLVfD+UPcdM3V/qvLf7ErDj91MhNJyspG8H+6gpR2IBVJPDbysoMztg42n8VryUga X-Received: by 2002:a17:906:c1d6:b0:a23:55c5:a657 with SMTP id bw22-20020a170906c1d600b00a2355c5a657mr4400330ejb.44.1705485454488; Wed, 17 Jan 2024 01:57:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485454; cv=pass; d=google.com; s=arc-20160816; b=DxOVwIqFgREbMfICyfinnJpga4+jCknCgjZCwvUzmUazJn1GSLUyb+T1yYrXcyh7oS AdAJrxp/RZF7TXIHzMvHOOyvLCdmzFdGzlpiNEfVliEloM/XK9sZGHV40QOXT9hKivrn SuWI8SEI6cqUBgeCjyGeG2jkCz0PP0UEMzLFGC8SyT7uY9z6z18aP0Qc9UswiwPRAtVQ CeddayabBqbIVu25U+s6UkEfL0GPnHwyZPwywg1O1nDZlay7IF+5X9vix43pJlctiX5b sVHicyYFY/qrLwz7tT12zP8no5F6aR2hq6NRTv1jhKgiL4jUqaVRroGmDOmKUPoNSxJS 1ldA== 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=0yzt2AJl7YEH1/EmWhETGQIwcKED0yq1SVLcZlQI1mM=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=d0gVlsSHj0zqrF2l7tHskxq2n6TCPFC7XDQjeIV1kq/ixwgx4SQrrs6QbcRP7dDJCK s8Wrrh3wjPF82idUvBcc7y7pREXPZMtCyxjMFtkHmpZEH0a/F4N/EHfeK0b+mlZsTkfq 9yreCJSx47dB6+j9Qq9Atso7tu6MOikYwnNh6LsO9Lwh429Xkp6IL0p9x/MxXWH4TH6a 14/fIpI1ASNQIBk3PZYbURz2EcyC7LKDi8xgRAniMFw/BkLUqNnKbsG6/QsO1WryEsnC xyTShq2g4PswrsJYGvzYxlmhReYJPzLDEikV471LaQYZ8pjItXo2KRgxQmmXtIhXX1BL ReGA== 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-28775-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28775-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z17-20020a170906241100b00a2d1c3c7506si3966836eja.442.2024.01.17.01.57.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:57:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28775-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-28775-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28775-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 am.mirrors.kernel.org (Postfix) with ESMTPS id F01531F249F1 for ; Wed, 17 Jan 2024 09:57:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 99D241DDD2; Wed, 17 Jan 2024 09:56:15 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 546441DA33; Wed, 17 Jan 2024 09:56: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=1705485374; cv=none; b=kKi0t5q3hef3A7gelYp3sL6FNf6ZoFevcy0ZOAyUII8mZCPb0nvHXjpDnmj+0nQUo194AfMf/pa7JjfguQ1wyD59U8bl9dv0EWuKFW4R8Z2A9Ln7tRnR0zkls0+TXP/HJP05K383bhzsciYzOfFLFpcu5FGJ/mo7TWUDEXmVI1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485374; c=relaxed/simple; bh=Rzy1bpw1hjeIG4FREVAS7YWhCelPT+QhR3d1SJuCUO0=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=lLbjJPt4EFAiP7fq1FRzEqBM+zwQF9V1j53DHZ/3MWdboQ5uUfRlY32lmyVkfc6hNzjUu/g4pTWtZQx/YTjshF2Nl0gj0D9mGWGDHonv439Kz/Fimr7H3rLRWN+2muoou12XI8PYbKc/aPMim7m+4LZ17Rx/6+W3C4d7C+AHTH8= 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 EB594DA7; Wed, 17 Jan 2024 01:56:57 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2267E3F5A1; Wed, 17 Jan 2024 01:56:08 -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 v7 05/23] PM: EM: Introduce em_compute_costs() Date: Wed, 17 Jan 2024 09:56:56 +0000 Message-Id: <20240117095714.1524808-6-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331116040642535 X-GMAIL-MSGID: 1788331116040642535 Move the EM costs computation code into a new dedicated function, em_compute_costs(), that can be reused in other places in the future. This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 72 ++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index aa7c89f9e115..3bea930410c6 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -103,14 +103,52 @@ static void em_debug_create_pd(struct device *dev) {} static void em_debug_remove_pd(struct device *dev) {} #endif +static int em_compute_costs(struct device *dev, struct em_perf_state *table, + struct em_data_callback *cb, int nr_states, + unsigned long flags) +{ + unsigned long prev_cost = ULONG_MAX; + u64 fmax; + int i, ret; + + /* Compute the cost of each performance state. */ + fmax = (u64) table[nr_states - 1].frequency; + for (i = nr_states - 1; i >= 0; i--) { + unsigned long power_res, cost; + + if (flags & EM_PERF_DOMAIN_ARTIFICIAL) { + ret = cb->get_cost(dev, table[i].frequency, &cost); + if (ret || !cost || cost > EM_MAX_POWER) { + dev_err(dev, "EM: invalid cost %lu %d\n", + cost, ret); + return -EINVAL; + } + } else { + power_res = table[i].power; + cost = div64_u64(fmax * power_res, table[i].frequency); + } + + table[i].cost = cost; + + if (table[i].cost >= prev_cost) { + table[i].flags = EM_PERF_STATE_INEFFICIENT; + dev_dbg(dev, "EM: OPP:%lu is inefficient\n", + table[i].frequency); + } else { + prev_cost = table[i].cost; + } + } + + return 0; +} + static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, int nr_states, struct em_data_callback *cb, unsigned long flags) { - unsigned long power, freq, prev_freq = 0, prev_cost = ULONG_MAX; + unsigned long power, freq, prev_freq = 0; struct em_perf_state *table; int i, ret; - u64 fmax; table = kcalloc(nr_states, sizeof(*table), GFP_KERNEL); if (!table) @@ -154,33 +192,9 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, table[i].frequency = prev_freq = freq; } - /* Compute the cost of each performance state. */ - fmax = (u64) table[nr_states - 1].frequency; - for (i = nr_states - 1; i >= 0; i--) { - unsigned long power_res, cost; - - if (flags & EM_PERF_DOMAIN_ARTIFICIAL) { - ret = cb->get_cost(dev, table[i].frequency, &cost); - if (ret || !cost || cost > EM_MAX_POWER) { - dev_err(dev, "EM: invalid cost %lu %d\n", - cost, ret); - goto free_ps_table; - } - } else { - power_res = table[i].power; - cost = div64_u64(fmax * power_res, table[i].frequency); - } - - table[i].cost = cost; - - if (table[i].cost >= prev_cost) { - table[i].flags = EM_PERF_STATE_INEFFICIENT; - dev_dbg(dev, "EM: OPP:%lu is inefficient\n", - table[i].frequency); - } else { - prev_cost = table[i].cost; - } - } + 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; From patchwork Wed Jan 17 09:56:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188755 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp801159dye; Wed, 17 Jan 2024 01:58:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGr00aEMXuu4uWzcLhwSpTwEdqjK/WxSxGXNAlyDa5fux+Qrz344iE3+DQdniyooN2DLBzm X-Received: by 2002:a05:6830:4b4:b0:6dd:e17e:f714 with SMTP id l20-20020a05683004b400b006dde17ef714mr8897054otd.27.1705485482642; Wed, 17 Jan 2024 01:58:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485482; cv=pass; d=google.com; s=arc-20160816; b=RKHnoBcNruWO6zgmFPt5VLtnRrLXI8mC69PP/T9bwuNvoiIoBOkP0y8jD6H13PE+NC 1OtKI870OsvIYV22kICCJdpT3qYkWLFNtbFtG4Efyy034Z7dnfmLy3jP7l6LaCAhVXc8 qrzGXRMEKUnXXudjaIsKleJJDYL9hq4AN2ydz9JQnRpNCCelqX2r05ABLGhh9FHEkk0n Ccy2aJLlaWcYmtxcNIUAyNHhMM371GpDltjybR18a67YmpdhlwbGFnSPoIDsTlP0PONM pePVGIhbQAYejEoPqIaadQUDtDQJQ6mC6dm4NPDbpfFR1f4THrvttdc4v8B4ZqMSLeWF Zhtg== 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=32l98r/0GeRNxr/eo6WVDZUmrNd9NDFBRTZoy9jXTjQ=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=MNrvixohp3snjjC87EyKx5HgHtYlMT95rXcCcGPGQaKKcGssLAJcg5ax0VZyM/9rQp GTmobMPE2YFezGAx3kJ4X+AC4ju5bPwZ1aK01kQwb9ibdiXMYrclewM2ObCzz56xBlrL Juxi7NAAKGog3blgiDFVi+Cho5NXI/z+l96BhVzGGDYjOlcFY2ayTUh2Bh0D8aMdL294 C5qU2q0IWPuRn2e9P1XxXnjbvkIT7JJ1KE2qnVrSR3iNHnWPeBvtVX7IW1zI+xkw/iB1 yoRJck4NXe2b1ZzApaT3iEKeOjkVZa1bnKTMK4Uz0e0Vn2GEmzdZiJnKL8KCE9cZ2RFS fB8w== 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-28777-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28777-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y185-20020a638ac2000000b005c65eb2bc63si12456161pgd.608.2024.01.17.01.58.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:58:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28777-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-28777-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28777-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 6742828754F for ; Wed, 17 Jan 2024 09:58:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3378C1DFD6; Wed, 17 Jan 2024 09: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 0E2491DDE2; Wed, 17 Jan 2024 09: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=1705485379; cv=none; b=H32X+GnsuECcoc7YlSw7cxkn9FrKwErxCTZ3nPcbrMbSOoteykmAObURuHc1bX1wJIqL7yQxISVJb85BIiCYbZ4RdQhTsLgqNohXEzDSwa/DlL2B59zxoZ4XWPmdP/TuThGhA/qaA+8PE7jH5GjES3+wDabv68+JgGraYNgpNEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485379; c=relaxed/simple; bh=yfzOEMe3mWbA4431rxC4ttbOEOYJYd0y8wHDaL3uud4=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=YNr1bT9bO10XCq5OVPPGVwUsTyVIhwU7X6QnhkX/tQK2BiT5RClSS5ZScT3OzyMgoikQ4xF0qOEkv0pXbHEk6ZavEoEQitGdhwFN93MRpjQD/n6FQgevl3BlFJUfbV5lD32BGQ4NlEtbRRjeg0wBh4sGvFSRmiXYDB0HVrrOnRY= 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 D846ADA7; Wed, 17 Jan 2024 01:57:03 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0F11D3F5A1; Wed, 17 Jan 2024 01: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 Subject: [PATCH v7 07/23] PM: EM: Split the allocation and initialization of the EM table Date: Wed, 17 Jan 2024 09:56:58 +0000 Message-Id: <20240117095714.1524808-8-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331145309325109 X-GMAIL-MSGID: 1788331145309325109 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. 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 3c8542443dd4..e7826403ae1d 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 From patchwork Wed Jan 17 09:56:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp801249dye; Wed, 17 Jan 2024 01:58:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjzIywPR5kpkn7aQ/wBTlb2op4F7gEjs/txsEYMK40VGJ0FkMVJcJQ+mu/SgRvF5u5zfOB X-Received: by 2002:a05:6808:220f:b0:3b9:e626:d714 with SMTP id bd15-20020a056808220f00b003b9e626d714mr10054296oib.37.1705485499503; Wed, 17 Jan 2024 01:58:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485499; cv=pass; d=google.com; s=arc-20160816; b=P9VxwpSb/0ni/MNhqjCNymiq4lOvGMoOEmlt25Qq/NP+hMy9QRWSFPyAABMXjK0upQ L+8SMX/IwpFl3/cXBS8yXxqA+lJXgTo9Za1kdFmCURzRwYDsBLMxQMRrz2ZebBIDbdH9 yP9JWJPBxvhuVy+4OiWe2WzUilqnDvnhkPjPSLJP4BgxFlkcgOavlgjXV3Awwszx0mAW xXNqO6QdaHfVLGgRXOpoaiEby5rOEk8HlHeNURlySLxkq2ZZrGOvE9bNhxYX6Zyp1fPw TcjVADitperiD4AZPP8uG3TJOagCQX52oj2hgco2PsbzGDZX23DhKMGM4LmFt99T/OOD nEjQ== 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=tUF8g2jfsm9l3df8PPsICBLw0iQ0wtLKVNNzNjEJMD4=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=J4l213FJ/ok/d3Wrmdd0WRBrbiEdzvPXRyqACET9o8gUMevwe1RCeH7Hy2PGZqGKis 5ya6258BwvBQC4MpdLMw3MZx9JxECR0IuqTKksdi3wtrODhXgEO3fcd3WEwflCDv3g8J Mphkf9+w3ms7FlLa1yBBHbNiMgAmuaYZ3N+elZDMOO8tnFY+hs6EyxM/kX2QDsn21TCd PBFyFCnmvZ/yFPkC+3TirlD2m59V37fJSJ1rFdQ51ozR0lgnI+X9tJNHskmVIc60uMaM mGhmDx576Yb7BZLa8SddYKZtYC+jwyhMjMnUnvSdFp2dgkSMlBUyc4x4ZqnwF6V/XNT2 yxSg== 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-28778-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28778-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x7-20020a056a00188700b006d9a5c9d9b1si1334990pfh.153.2024.01.17.01.58.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:58:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28778-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::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-28778-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28778-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 86660B2381B for ; Wed, 17 Jan 2024 09:58:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4E171DFEA; Wed, 17 Jan 2024 09:56:24 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40FB71DFD7; Wed, 17 Jan 2024 09:56:21 +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=1705485383; cv=none; b=CsBrnvcZ5onFGgGBg1spvL5inTcic8wnHNS/Mj1KdKPmwHc9q6piFuiDWyHUtcnbdXcnzpigajGLi32imj6IQTSWrnfK7hu8O2KTUdYnDgHTf1mKHM7yg/P9qwVKfobMUJdDgkpIbZIecS05pIn9E8wOGha/PAVP44vcuqwQF+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485383; c=relaxed/simple; bh=DJG0Pc8+NVQr0FyzRFhON4R08jZ/JxEARBwVvnw6hR4=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=slv1A5DFcsJw8MDx6sYsjWupGEW5UCYKVH0Oefd1BlirPnX4i14umV1aeDvwr8twJJN+cctoGD537bmdYWSuHrZaaMpHgvXKflcLulEvB49kWHSvXDnEChSGbb2a317Nf9rrz5z6/cyY9fLP52oVeYuzsEyOYNBR8USLjlWM47Y= 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 CB9DADA7; Wed, 17 Jan 2024 01:57:06 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 03D843F5A1; Wed, 17 Jan 2024 01:56:17 -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 v7 08/23] PM: EM: Introduce runtime modifiable table Date: Wed, 17 Jan 2024 09:56:59 +0000 Message-Id: <20240117095714.1524808-9-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331163495147060 X-GMAIL-MSGID: 1788331163495147060 The new runtime table can be populated with a new power data to better reflect the actual efficiency of the device e.g. CPU. The power can vary over time e.g. due to the SoC temperature change. Higher temperature can increase power values. For longer running scenarios, such as game or camera, when also other devices are used (e.g. GPU, ISP) the CPU power can change. The new EM framework is able to addresses this issue and change the EM data at runtime safely. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 12 ++++++++ kernel/power/energy_model.c | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index b01277b17946..585c5ffc898b 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -36,9 +36,20 @@ struct em_perf_state { */ #define EM_PERF_STATE_INEFFICIENT BIT(0) +/** + * struct em_perf_table - Performance states table + * @rcu: RCU used for safe access and destruction + * @state: List of performance states, in ascending order + */ +struct em_perf_table { + struct rcu_head rcu; + struct em_perf_state state[]; +}; + /** * struct em_perf_domain - Performance domain * @table: List of performance states, in ascending order + * @em_table: Pointer to the runtime modifiable em_perf_table * @nr_perf_states: Number of performance states * @flags: See "em_perf_domain flags" * @cpus: Cpumask covering the CPUs of the domain. It's here @@ -54,6 +65,7 @@ struct em_perf_state { */ struct em_perf_domain { struct em_perf_state *table; + struct em_perf_table __rcu *em_table; int nr_perf_states; unsigned long flags; unsigned long cpus[]; diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index e7826403ae1d..c03010084208 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -23,6 +23,9 @@ */ static DEFINE_MUTEX(em_pd_mutex); +static void em_cpufreq_update_efficiencies(struct device *dev, + struct em_perf_state *table); + static bool _is_cpu_device(struct device *dev) { return (dev->bus == &cpu_subsys); @@ -103,6 +106,31 @@ static void em_debug_create_pd(struct device *dev) {} static void em_debug_remove_pd(struct device *dev) {} #endif +static void em_destroy_table_rcu(struct rcu_head *rp) +{ + struct em_perf_table __rcu *table; + + table = container_of(rp, struct em_perf_table, rcu); + kfree(table); +} + +static void em_free_table(struct em_perf_table __rcu *table) +{ + call_rcu(&table->rcu, em_destroy_table_rcu); +} + +static struct em_perf_table __rcu * +em_allocate_table(struct em_perf_domain *pd) +{ + struct em_perf_table __rcu *table; + int table_size; + + table_size = sizeof(struct em_perf_state) * pd->nr_perf_states; + + table = kzalloc(sizeof(*table) + table_size, GFP_KERNEL); + return table; +} + static int em_compute_costs(struct device *dev, struct em_perf_state *table, struct em_data_callback *cb, int nr_states, unsigned long flags) @@ -153,6 +181,24 @@ static int em_allocate_perf_table(struct em_perf_domain *pd, return 0; } +static int em_create_runtime_table(struct em_perf_domain *pd) +{ + struct em_perf_table __rcu *table; + int table_size; + + table = em_allocate_table(pd); + if (!table) + return -ENOMEM; + + /* Initialize runtime table with existing data */ + table_size = sizeof(struct em_perf_state) * pd->nr_perf_states; + memcpy(table->state, pd->table, table_size); + + rcu_assign_pointer(pd->em_table, table); + + return 0; +} + static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, struct em_perf_state *table, struct em_data_callback *cb, @@ -245,6 +291,10 @@ static int em_create_pd(struct device *dev, int nr_states, if (ret) goto free_pd_table; + ret = em_create_runtime_table(pd); + if (ret) + goto free_pd_table; + if (_is_cpu_device(dev)) for_each_cpu(cpu, cpus) { cpu_dev = get_cpu_device(cpu); @@ -461,6 +511,9 @@ void em_dev_unregister_perf_domain(struct device *dev) em_debug_remove_pd(dev); kfree(dev->em_pd->table); + + em_free_table(dev->em_pd->em_table); + kfree(dev->em_pd); dev->em_pd = NULL; mutex_unlock(&em_pd_mutex); From patchwork Wed Jan 17 09:57:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188757 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp801368dye; Wed, 17 Jan 2024 01:58:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHX5qpLD86tP8bNVXarDY4IuRj8fevuoN6b8q+TKsFp4A22TuUAfmAZl+aMwnSTPFdoBwo X-Received: by 2002:a05:620a:4f:b0:783:770a:f13a with SMTP id t15-20020a05620a004f00b00783770af13amr135230qkt.53.1705485527718; Wed, 17 Jan 2024 01:58:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485527; cv=pass; d=google.com; s=arc-20160816; b=qGsVYnizWa7UBJoQJXY47t8ObMkrsxcjPHH2qmPia9oH5PhPd5Tj9WWrjq/AtXIJP1 MdajzN/oocXF6OkntWnr0jhZjwIVx73v36E1nUdf7Q4ZWavRGSrSz69ukExYd/L0ocUU WE4LFrU0P0W47vBi+xuGTl04MaBqqNaRsI6dOC4l+FQJCVeMpk20fzteiUAPvxnKqN3M FERLDnZLioxEiTmWMVxeIfagHVs27DJdgn1UVRdeDFIlaqcm0xSEwfXP4WfMoui9yS1E I2ncJXNSKznCYIOW6Mk/AOtAcDVMRhm+d9S0IAOr2bLq45DrHt3lZBOHW06/rsQi3hpc LzdQ== 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=aiwgqlFIY0rUpWmH3iJ+FQs0op51tcYPdmaPgM9bQw8=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=RB0b4J2MnSpcSbn/A2GrGK1KeEQSLXaZO29wymN8lY9Qgs6nPmsbBhlxhdK3+hc9sL lZPoFv1sAqwm2qBbp8RSNO6+0rR+o3aTq9DFfWEDIYnmXqD54bIxf3VDtz7QMDaeJpyT u+CptMT3FSKDTGP1JveoFo9BeojY0ZNOjsGexvpC2UqEgxQijvMfnPFhxtd3vF4YBFu6 qeRRNXkvmnMvPnjRF5d97uAZZxcS8hoxuIdeMwx6DRoRCWXJD5nQ4K1rZseq2y7QJAAG g0UU2/IMs+Q32bWN1iN92J8OCDoiDwRL49chjzlDxmwYm/6s+k9jw/0M8RMybyEMtsw2 8kVQ== 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-28780-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28780-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b4-20020a05620a126400b007833622f15esi11142474qkl.725.2024.01.17.01.58.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:58:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28780-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-28780-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28780-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 81EED1C2450A for ; Wed, 17 Jan 2024 09:58:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 77CD51EB20; Wed, 17 Jan 2024 09: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 DD45C1E89D; Wed, 17 Jan 2024 09:56:26 +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=1705485388; cv=none; b=GSrgTGDB/Zc6jCtAKX3X0rtcM6FEhYpL98W6lmj9s74cO8pT3cWLP2IFkPctJk9V7M8dkMxk+GWqT6p76SmVq+nF80wKl3l7NBcdEynrZxi8Pf7DP5babMi/x2wPedw+jG0NJlweD1mFNnfvU82FCA3d2esVsB0j8LNraL+WvKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485388; c=relaxed/simple; bh=AvyOd1GUNmnUqP/7z2XWIjzHwU151boQ1Y08G9WFx/Y=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=j47jqXcWgC+PTfVlHhyyyZ3l/Maa0IkuRFSPZPAErx2Ac9/X2/R1xPjDcwGQaGPCAAtaYW6xviwxjWdQiKcOjeCMgZSnuZNStsOIL+pySvaJQUoST4l1B9xv1BbG4D1q3ZCwWppDfkeEZrI5OAL2yB55yPdOOzIDRxeHltx5+8A= 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 B11D8DA7; Wed, 17 Jan 2024 01:57:12 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DAAFA3F5A1; Wed, 17 Jan 2024 01:56:23 -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 v7 10/23] PM: EM: Add functions for memory allocations for new EM tables Date: Wed, 17 Jan 2024 09:57:01 +0000 Message-Id: <20240117095714.1524808-11-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331192824979943 X-GMAIL-MSGID: 1788331192824979943 The runtime modified EM table can be provided from drivers. Create mechanism which allows safely allocate and free the table for device drivers. The same table can be used by the EAS in task scheduler code paths, so make sure the memory is not freed when the device driver module is unloaded. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 11 +++++++++++ kernel/power/energy_model.c | 38 +++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index fcd8de1a2dbd..e44c5080407f 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -39,10 +40,12 @@ struct em_perf_state { /** * struct em_perf_table - Performance states table * @rcu: RCU used for safe access and destruction + * @kref: Reference counter to track the users * @state: List of performance states, in ascending order */ struct em_perf_table { struct rcu_head rcu; + struct kref kref; struct em_perf_state state[]; }; @@ -184,6 +187,8 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, struct em_data_callback *cb, cpumask_t *span, bool microwatts); void em_dev_unregister_perf_domain(struct device *dev); +struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd); +void em_table_free(struct em_perf_table __rcu *table); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM @@ -366,6 +371,12 @@ static inline int em_pd_nr_perf_states(struct em_perf_domain *pd) { return 0; } +static inline +struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd) +{ + return NULL; +} +static inline void em_table_free(struct em_perf_table __rcu *table) {} #endif #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index c03010084208..ffe94614f004 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -114,13 +114,36 @@ static void em_destroy_table_rcu(struct rcu_head *rp) kfree(table); } -static void em_free_table(struct em_perf_table __rcu *table) +static void em_release_table_kref(struct kref *kref) { + struct em_perf_table __rcu *table; + + /* It was the last owner of this table so we can free */ + table = container_of(kref, struct em_perf_table, kref); + call_rcu(&table->rcu, em_destroy_table_rcu); } -static struct em_perf_table __rcu * -em_allocate_table(struct em_perf_domain *pd) +/** + * em_table_free() - Handles safe free of the EM table when needed + * @table : EM table which is going to be freed + * + * No return values. + */ +void em_table_free(struct em_perf_table __rcu *table) +{ + kref_put(&table->kref, em_release_table_kref); +} + +/** + * em_table_alloc() - Allocate a new EM table + * @pd : EM performance domain for which this must be done + * + * Allocate a new EM table and initialize its kref to indicate that it + * has a user. + * Returns allocated table or NULL. + */ +struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd) { struct em_perf_table __rcu *table; int table_size; @@ -128,6 +151,11 @@ em_allocate_table(struct em_perf_domain *pd) table_size = sizeof(struct em_perf_state) * pd->nr_perf_states; table = kzalloc(sizeof(*table) + table_size, GFP_KERNEL); + if (!table) + return NULL; + + kref_init(&table->kref); + return table; } @@ -186,7 +214,7 @@ static int em_create_runtime_table(struct em_perf_domain *pd) struct em_perf_table __rcu *table; int table_size; - table = em_allocate_table(pd); + table = em_table_alloc(pd); if (!table) return -ENOMEM; @@ -512,7 +540,7 @@ void em_dev_unregister_perf_domain(struct device *dev) kfree(dev->em_pd->table); - em_free_table(dev->em_pd->em_table); + em_table_free(dev->em_pd->em_table); kfree(dev->em_pd); dev->em_pd = NULL; From patchwork Wed Jan 17 09:57:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188758 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp801446dye; Wed, 17 Jan 2024 01:59:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFoGyRVRTcsiqSTu6O6DTaNIgjbklp3kQ1Y5d5jtr08ZTtWwJw+3SaIlwJaq4ZHVgURJH5S X-Received: by 2002:a17:90a:db8c:b0:290:9b5:124f with SMTP id h12-20020a17090adb8c00b0029009b5124fmr53857pjv.77.1705485542321; Wed, 17 Jan 2024 01:59:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485542; cv=pass; d=google.com; s=arc-20160816; b=jj8Gbhy0Yyl59K5Sqv8a9fJAP3Ryzg1WrSOnYGuEizjr5eVbCn4AZ0o5syPZuu4naO 6BMg+liztSkuv5mNSoJoEqyhqYtzw40adGMXj7rQAltEncJSrkf3H8fNTlTwZGfE6lnS 4cKUIGR/AQ2gCdjvtLy2yZtgzUrqviwsg1rG45eVcxlqFO9EOeX7scNLDR7JNscUXdTs 1obNPJeXDC1I5v0zMiOIg31QdsIxCwztGHZsyy/xz/mZrhLaxdROCFz/SyKt8F6qP1SE EOeFwcfX2W+0QeCBbbuAX1+mhLAddEeYXIltH2Vfcc7D8arvKUF2yugAVMJrWMKUzNMB 7QNw== 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=dVszTN7kB0bMl4ij78cpGrt+NI0U7anAbUl3WoMCJxU=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=yVB0/aUNvX4+0KM7mcuvL7/uv/d+qILkb+oaNNh/TuQSNxdvxvvHQfWX5rGDH8bcVM yUIWOG7u+izwhxWl79E4fzbrjJvgwzTS11qgv0rYRKfSxOEpwcteEn7tK3X1obcGqb29 DdoxMU2bN1pAN8/Io+dPcWBPEw+jeVARYtn/0fHSSMvRKbbP+am/7DybdC/zufNvvAR6 OjgfeSjDl6ZUwWThgyVraPEmssIFG2yaIzcJfSjdUenAwxCVOV45HtKBtXCkLVzIp/8e Ps2WFmbh30TwHDraLGOq6xl3NdN67sfc86r1hcogeKer9FZLgIXORcuAgh6eXoRecxOk ejQA== 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-28781-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28781-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p8-20020a17090a2c4800b0028ba37adbfasi15525660pjm.55.2024.01.17.01.59.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:59:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28781-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-28781-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28781-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 1CB7228738F for ; Wed, 17 Jan 2024 09:59:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 375531EB40; Wed, 17 Jan 2024 09:56:33 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06E5A1EA7F; Wed, 17 Jan 2024 09:56:29 +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=1705485391; cv=none; b=kt4+ATn/uSH+WavzrIcCvzd+utVUcg865nrLinCZoEGiSQebyU1D0vY0FmQwXHKlWZIuOTr15NNgYzLyQbryMGrqg5ZVQw7UEwRT+FOx27bjM26gL6aNkV/KKYhnlra2iphy46hG1xP038vr7COyhAS4l2TVRRvm9AxrKT9mirM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485391; c=relaxed/simple; bh=Yfz93Uu8Wq2FtpkolTFGNCbrQitOf6xGhZBeU+qcJ9s=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=Ak3XNBcleUAR+9JOTYvgjMLqzsQouOoshYW5s+LsouC9H9068YW/BiWWVIJ0vcTU9FQGpJijSZZ/muGUgIllrIdB3J7JhUEAY5RL31E3MstHR0OUa93fhmSvEpvQ4YPpJs3QBazUPaS8117yCnSa+IqxAPn+d1L+QsfAK0Trg/Q= 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 A3EE7DA7; Wed, 17 Jan 2024 01:57:15 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CED123F5A1; Wed, 17 Jan 2024 01:56:26 -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 v7 11/23] PM: EM: Introduce em_dev_update_perf_domain() for EM updates Date: Wed, 17 Jan 2024 09:57:02 +0000 Message-Id: <20240117095714.1524808-12-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331207601036268 X-GMAIL-MSGID: 1788331207601036268 Add API function em_dev_update_perf_domain() which allows the EM to be changed safely. Concurrent updaters are serialized with a mutex and the removal of memory that will not be used any more is carried out with the help of RCU. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 8 +++++++ kernel/power/energy_model.c | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index e44c5080407f..494df6942cf7 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -183,6 +183,8 @@ struct em_data_callback { struct em_perf_domain *em_cpu_get(int cpu); struct em_perf_domain *em_pd_get(struct device *dev); +int em_dev_update_perf_domain(struct device *dev, + struct em_perf_table __rcu *new_table); int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, struct em_data_callback *cb, cpumask_t *span, bool microwatts); @@ -377,6 +379,12 @@ struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd) return NULL; } static inline void em_table_free(struct em_perf_table __rcu *table) {} +static inline +int em_dev_update_perf_domain(struct device *dev, + struct em_perf_table __rcu *new_table) +{ + return -EINVAL; +} #endif #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index ffe94614f004..190042640935 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -209,6 +209,50 @@ static int em_allocate_perf_table(struct em_perf_domain *pd, return 0; } +/** + * em_dev_update_perf_domain() - Update runtime EM table for a device + * @dev : Device for which the EM is to be updated + * @new_table : The new EM table that is going to be used from now + * + * Update EM runtime modifiable table for the @dev using the provided @table. + * + * This function uses a mutex to serialize writers, so it must not be called + * from a non-sleeping context. + * + * Return 0 on success or an error code on failure. + */ +int em_dev_update_perf_domain(struct device *dev, + struct em_perf_table __rcu *new_table) +{ + struct em_perf_table __rcu *old_table; + struct em_perf_domain *pd; + + if (!dev) + return -EINVAL; + + /* Serialize update/unregister or concurrent updates */ + mutex_lock(&em_pd_mutex); + + if (!dev->em_pd) { + mutex_unlock(&em_pd_mutex); + return -EINVAL; + } + pd = dev->em_pd; + + kref_get(&new_table->kref); + + old_table = pd->em_table; + rcu_assign_pointer(pd->em_table, new_table); + + em_cpufreq_update_efficiencies(dev, new_table->state); + + em_table_free(old_table); + + mutex_unlock(&em_pd_mutex); + return 0; +} +EXPORT_SYMBOL_GPL(em_dev_update_perf_domain); + static int em_create_runtime_table(struct em_perf_domain *pd) { struct em_perf_table __rcu *table; From patchwork Wed Jan 17 09:57:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188759 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp801527dye; Wed, 17 Jan 2024 01:59:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IHi/oa6tKDG3FVJUwG/xxuWSOFuiNbhPDLq/rY7HLAag0cpsrMfLU1wGLfPuQqaS/O8PB+w X-Received: by 2002:a05:6808:bd2:b0:3bd:940b:16a with SMTP id o18-20020a0568080bd200b003bd940b016amr728152oik.41.1705485557670; Wed, 17 Jan 2024 01:59:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485557; cv=pass; d=google.com; s=arc-20160816; b=PpgwpwNdraXVUXXyHAc1wy19hZ6CipBzRi0kJtl75oAv6D44P8HjqyU9M/9wr5IWKq fAO0HkE6yGgR9G0VMAqG06V/C/2WkgYM3USForMQbJ+OggP1d4RiQz27GEaVEGMHwqCc R6mTpSDFt9FBttZxm8PmXESw5tDWMhgVbI1NlvjA1EjjQ3UQpbQRQhXgYm9RkHFLAZHO rA+VFyrn7nRb9m9NGF/qh0dA7Q9jrNbEsgIOs3+oTmbghiL7+1hKKk7v4pPejseOaLsN kDnDujQ70m8vGfA7r4kocOgCJPZX3xw8M2pzXcTZgiPZYJbAFiHMNs6ETV0oWufx+C6v 97uA== 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=TFFw4fukJL80nbh9BXIvLcUsEWinm5wrpy+lkFqC7EQ=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=eZU0az/r3GVVBPG6U9cbfDihUdngyYJP+D3Z+XRJUvAoQ+kCAUwttGJ00rQcQIySRu Y2sKjb8/89Sa0J2EZBaB1je1t/u/15zGoKI9bLPE1cDQVe9c7pZyYv52R6ILBeUYk7RZ EUuzTtqj/M/+rcNURPxvhjjSHIpx9iZ/V0FVFnj/geXGNBvOd4CERO1HiL/+cAs78yKo 0Fuk080Sn6p1cwHJ/82zOhwj3GTxEuGOxtSTSkfVRtxPaYAJG52QLBugZjxS1m8RRbPN hbgx5I6uMbackMvpC4GkDKhPOZAkswPrF7kRZY0ym7CRccj1HAPu3u/20110bTemxVQm W0lg== 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-28782-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28782-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h30-20020aa79f5e000000b006d6faec9bf6si1270490pfr.13.2024.01.17.01.59.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:59:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28782-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-28782-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28782-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 6B4E8287965 for ; Wed, 17 Jan 2024 09:59:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB5301F608; Wed, 17 Jan 2024 09:56:35 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B60381EB2F; Wed, 17 Jan 2024 09:56:32 +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=1705485394; cv=none; b=eIvRiQii+uYZzTSr1hJ0Tm5Ep7zIt4I6EQCbN7AWb1BkIYryE10YqJ4UR6lHV4gwadAJ691QnHth4wdXYeNwNy6bG5pw7NZSgLLiWCC3WI9uYXQGgU987Y/wPNHMEDyYeG5TmUwSMSI1eSOYfcMGgHFVlBYjK+PiOl/FUM3hrjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485394; c=relaxed/simple; bh=gHen9X6HPGwhxQEt4lAep0V5ayco+8boFV7pC+UpjsY=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=Vv4VT9GvTTeKHiqWidhgP90lWhxU27P7qu4NfJALoLNTc4x0fbSpOnkQJSqQxOw2hBNjJG/hgEoLOk6dpBCfniD/tN0zuBOmUZ/DW97TNEU2WXbluGYFO8Xo1RbSk1SmNl7+8rPX1cBdk3WJnGZs5SBlgjC5vdLt9rs3+tVQyms= 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 97303DA7; Wed, 17 Jan 2024 01:57:18 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C2BF13F5A1; Wed, 17 Jan 2024 01:56:29 -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 v7 12/23] PM: EM: Add em_perf_state_from_pd() to get performance states table Date: Wed, 17 Jan 2024 09:57:03 +0000 Message-Id: <20240117095714.1524808-13-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331223698979632 X-GMAIL-MSGID: 1788331223698979632 Introduce a wrapper to get the performance states table of the performance domain. The function should be called within the RCU read critical section. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 494df6942cf7..5ebe9dbec8e1 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -339,6 +339,23 @@ static inline int em_pd_nr_perf_states(struct em_perf_domain *pd) return pd->nr_perf_states; } +/** + * em_perf_state_from_pd() - Get the performance states table of perf. + * domain + * @pd : performance domain for which this must be done + * + * To use this function the rcu_read_lock() should be hold. After the usage + * of the performance states table is finished, the rcu_read_unlock() should + * be called. + * + * Return: the pointer to performance states table of the performance domain + */ +static inline +struct em_perf_state *em_perf_state_from_pd(struct em_perf_domain *pd) +{ + return rcu_dereference(pd->em_table)->state; +} + #else struct em_data_callback {}; #define EM_ADV_DATA_CB(_active_power_cb, _cost_cb) { } @@ -385,6 +402,11 @@ int em_dev_update_perf_domain(struct device *dev, { return -EINVAL; } +static inline +struct em_perf_state *em_perf_state_from_pd(struct em_perf_domain *pd) +{ + return NULL; +} #endif #endif From patchwork Wed Jan 17 09:57:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp801710dye; Wed, 17 Jan 2024 01:59:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFyUid3/3h4+BuphXDW3i89M4HSjJZ4Q12IBGQiHJMVmqlbup03SZ1ve92Ssq4LW7p/qDUK X-Received: by 2002:a05:6830:1d7b:b0:6dd:e656:5ddb with SMTP id l27-20020a0568301d7b00b006dde6565ddbmr8906348oti.76.1705485589630; Wed, 17 Jan 2024 01:59:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485589; cv=pass; d=google.com; s=arc-20160816; b=tuVlyTPNmu2cZFudgSDvcKVe95H1cc4QQHWUeO4RkRbq/UHZdcELjK9KxT2VzJSfJ/ 3Y9SGRgyN/J6Ktq19rXJ9u8WNG1E7V4DqamM2C77GId/7v/JG/H6mA7JmFIPxPe550ap Zwa5lEHBEHWyGjDQVhCfr7ib6HjmumSkzPNtexEaYPrXkC+p0h6VgUfiew+ci4p1Cxqq nsfBFw3jgVgdovUxA6HnLPb3wwqplMhTfkvulWhQIi/kZ43+qPVRqpSIQhx/+DFac3mp sZ2LJbNZJxJm9Zc5fAN4t5OKm5R2rBBCdR2a195LHzwGbv34rznIZ+Tid7fg7GQIoc9+ b1MQ== 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=S1p2Ryd/FgxlhWcQ8m46zZdmu15VEOJBg1EqudeXhl4=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=QH9qShBG1zfTQA2RxDpDHliLXFgZOk97vCrjN2cZxbzqh0QZ9h0hvXt4HY7kBLA7Qx 3pYm7mXBiEM6TjNpDvUUgS6lcufU+LqcDxfyZFwGXEpLfYAxqvXIWTLoEO5XSykknXAt YAgnLwx5RUlxCnmirwPBBZpxu2J9LtArUjNw5S+Tj41pGOHZU1U4rnWn1F0husbjOOnr LpGx9tqo/AP6Zb35vHAG+zV/AWESEV/3gTAlUCk9FC5pj3r80vvkAxz2OO8yixwxAxFO 75Sq74A1NvsTqLylqswq60GcQSIoGky4Er4JoK1spfRVqGk5DlpBNF3utsfeqIJCexMn xIQw== 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-28784-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28784-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x24-20020a056a00189800b006d983f185bfsi1344854pfh.88.2024.01.17.01.59.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:59:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28784-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-28784-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28784-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 6278D2878E4 for ; Wed, 17 Jan 2024 09:59:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 730C1200BD; Wed, 17 Jan 2024 09:56:43 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2ADC91F94C; Wed, 17 Jan 2024 09:56:40 +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=1705485401; cv=none; b=aMUhG4nn/p3H53I1zk8/HXVtrg30StR4Ejgenure32PNxHmoSe1ACZOD94IAz3qiAmiiK3tS4FTesLjZAr2VfgBhhTvKVcXD2rLKpftAYI6A0Y5OM03sxQnEcM2lyvGLwi2/th1f/eXdd3Hh/OYoWXXOAJLB55P3wHrlXmRnHnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485401; c=relaxed/simple; bh=Bubw8+V2pl1hptgkrOBgFTgvvXlgzQtg2eJRxhpNddk=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=DdAizTtWezim3ybIwp/tLkNPAhlkmXrxvnyE1kwZ4HkgoXkZdpREOrd2Xe44u1kOdcA5kg9zTwfJbVkKbg873iC6RmjFtVikv5aYqWRDnEtH8cnnp/pMg2H5RyTRIPGyyZlLAV1i9yY9hLjzJxJoJ1IhOvzl4YXTDDnTpgVR1YA= 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 0B6E0DA7; Wed, 17 Jan 2024 01:57:26 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A30943F5A1; Wed, 17 Jan 2024 01:56:35 -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 v7 14/23] PM: EM: Support late CPUs booting and capacity adjustment Date: Wed, 17 Jan 2024 09:57:05 +0000 Message-Id: <20240117095714.1524808-15-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331257808251035 X-GMAIL-MSGID: 1788331257808251035 The patch adds needed infrastructure to handle the late CPUs boot, which might change the previous CPUs capacity values. With this changes the new CPUs which try to register EM will trigger the needed re-calculations for other CPUs EMs. Thanks to that the em_per_state::performance values will be aligned with the CPU capacity information after all CPUs finish the boot and EM registrations. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 124 ++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 2a817b92804b..548d54e55b08 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -25,6 +25,9 @@ static DEFINE_MUTEX(em_pd_mutex); static void em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table); +static void em_check_capacity_update(void); +static void em_update_workfn(struct work_struct *work); +static DECLARE_DELAYED_WORK(em_update_work, em_update_workfn); static bool _is_cpu_device(struct device *dev) { @@ -583,6 +586,10 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, unlock: mutex_unlock(&em_pd_mutex); + + if (_is_cpu_device(dev)) + em_check_capacity_update(); + return ret; } EXPORT_SYMBOL_GPL(em_dev_register_perf_domain); @@ -618,3 +625,120 @@ void em_dev_unregister_perf_domain(struct device *dev) mutex_unlock(&em_pd_mutex); } EXPORT_SYMBOL_GPL(em_dev_unregister_perf_domain); + +/* + * Adjustment of CPU performance values after boot, when all CPUs capacites + * are correctly calculated. + */ +static void em_adjust_new_capacity(struct device *dev, + struct em_perf_domain *pd, + u64 max_cap) +{ + struct em_perf_state *table, *new_table; + struct em_perf_table __rcu *em_table; + int ret, table_size; + + em_table = em_table_alloc(pd); + if (!em_table) { + dev_warn(dev, "EM: allocation failed\n"); + return; + } + + new_table = em_table->state; + + rcu_read_lock(); + table = em_perf_state_from_pd(pd); + /* Initialize data based on old table */ + table_size = sizeof(struct em_perf_state) * pd->nr_perf_states; + memcpy(new_table, table, table_size); + + rcu_read_unlock(); + + em_init_performance(dev, pd, new_table, pd->nr_perf_states); + ret = em_compute_costs(dev, new_table, NULL, pd->nr_perf_states, + pd->flags); + if (ret) { + dev_warn(dev, "EM: compute costs failed\n"); + return; + } + + ret = em_dev_update_perf_domain(dev, em_table); + if (ret) + dev_warn(dev, "EM: update failed %d\n", ret); + + /* + * This is one-time-update, so give up the ownership in this updater. + * The EM framework has incremented the usage counter and from now + * will keep the reference (then free the memory when needed). + */ + em_table_free(em_table); +} + +static void em_check_capacity_update(void) +{ + cpumask_var_t cpu_done_mask; + struct em_perf_state *table; + struct em_perf_domain *pd; + unsigned long cpu_capacity; + int cpu; + + if (!zalloc_cpumask_var(&cpu_done_mask, GFP_KERNEL)) { + pr_warn("no free memory\n"); + return; + } + + /* Check if CPUs capacity has changed than update EM */ + for_each_possible_cpu(cpu) { + struct cpufreq_policy *policy; + unsigned long em_max_perf; + struct device *dev; + int nr_states; + + if (cpumask_test_cpu(cpu, cpu_done_mask)) + continue; + + policy = cpufreq_cpu_get(cpu); + if (!policy) { + pr_debug("Accessing cpu%d policy failed\n", cpu); + schedule_delayed_work(&em_update_work, + msecs_to_jiffies(1000)); + break; + } + cpufreq_cpu_put(policy); + + pd = em_cpu_get(cpu); + if (!pd || em_is_artificial(pd)) + continue; + + cpumask_or(cpu_done_mask, cpu_done_mask, + em_span_cpus(pd)); + + nr_states = pd->nr_perf_states; + cpu_capacity = arch_scale_cpu_capacity(cpu); + + rcu_read_lock(); + table = em_perf_state_from_pd(pd); + em_max_perf = table[pd->nr_perf_states - 1].performance; + rcu_read_unlock(); + + /* + * Check if the CPU capacity has been adjusted during boot + * and trigger the update for new performance values. + */ + if (em_max_perf == cpu_capacity) + continue; + + pr_debug("updating cpu%d cpu_cap=%lu old capacity=%lu\n", + cpu, cpu_capacity, em_max_perf); + + dev = get_cpu_device(cpu); + em_adjust_new_capacity(dev, pd, cpu_capacity); + } + + free_cpumask_var(cpu_done_mask); +} + +static void em_update_workfn(struct work_struct *work) +{ + em_check_capacity_update(); +} From patchwork Wed Jan 17 09:57:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188762 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp802481dye; Wed, 17 Jan 2024 02:01:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGTHdj7ZZdAD7yi88GnKL1ogoMo04AxvevCa2F5/LJKmvLNSAj2fL+B7WNMPW3oMaB2uT2A X-Received: by 2002:a17:902:e889:b0:1d5:aee7:20d0 with SMTP id w9-20020a170902e88900b001d5aee720d0mr11326058plg.17.1705485673488; Wed, 17 Jan 2024 02:01:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485673; cv=pass; d=google.com; s=arc-20160816; b=zhsDhhhpboVgjAncA1R+rqG4WEQ9X7O8kPyd1KMy5vAtrg6dqLQbvAhIAcvR6A33S+ BqTo2uORqPq0cwufpH3UzqJIgqweDnt7nRQjl+8oVcJittQq6k6s473pFxfpZIkVsFK2 nqVOQJ3LW04LiyMSGoxMfqSoOwNhgvgGJugHVLmRMSSsdmn/lxCOhSUTU4LXwc+Jk4w7 t7l4UaebLpgfyKtgkIioXU9mSQcTLUJW9dK0wTOgEXurmM2CMcdixELPMtnntoTlT8dD 3X56ymM4NMw+0fv2+okdj4qMovxZ25ibJ4+Y7/9LdWw2lq/KXrigSv7bqk37oB3GJ529 MVQA== 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=W8ZzgkvOLUd5/3efy3XySwW9AwE5JvXHaF1sEFEwZsI=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=WZyVqp5bsHNhG7/YB1rkEr6qMZ4ZNTTohf8LVZfg8Eieym2QKOlCdvnjMzcFtUHmSL 7RifDtha7qgVLbY9LyGkvi8PHZio6HNq2oxF3oCh2/Bus7RV18L3/KF9FlCQ3Sh/eI2X dD3LjzXmcrdBFFLl5FROnlDKI+Xb+54gOrUDJ9tjtkjsGU0zVOAqiFGIEnyilvKTWoFI fSgN54xUVRdM5+xQftTK+Vr972Ml4ymBvFQmJwkipVyLOhWJvZX/fCPWCYtjDSEMdqeO IVOuSH92H5Nl+PRDjiP4SXoM9rF5OSVIoLU8UIEJIj1v+lbNJuy4umZO7+8VD0GVFJeV sAtQ== 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-28785-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28785-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m1-20020a1709026bc100b001d6ed08880csi1396785plt.532.2024.01.17.02.01.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 02:01:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28785-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::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-28785-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28785-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 20CC9B24512 for ; Wed, 17 Jan 2024 10:00:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E70A120315; Wed, 17 Jan 2024 09:56:46 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FD10200AC; Wed, 17 Jan 2024 09:56:43 +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=1705485404; cv=none; b=dxCd0L+lVngMa5ztXqHrsecHBFqJtoWyppEZZUNj4ncTPTaZGKKliZII8eCHdHfQE6O3URPmzsc+v1ZOy/YZbRGwyfD3RCFf1JDPNI9A9UaLrRU4SV6eF0ndxYjLxEOq8CUuNJtZf7vSMh2gs09ItU7DLZzXuVW0EafFesWjn4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485404; c=relaxed/simple; bh=paUBCe3QpfBdgoRCUfyNO5pc9dm9xvZhUVpr9HAgl8Y=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=gKvChqsZCmg81fCgeR48ZTV66mO+wzuXV00gJcmQlL6WSvULWTeOWXCInHfTXDll1mvJdPEYtWCy95l2SxFoCHhd+BdfGHm32WZVPJOeXRp2DqT0DR0fvw9ueFFdj2yIPoAMJ6unrZE4v5dcudfrUexmZWq59VSHJ2yoWBSoehY= 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 F1D7FDA7; Wed, 17 Jan 2024 01:57:28 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 295073F5A1; Wed, 17 Jan 2024 01:56:40 -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 v7 15/23] PM: EM: Optimize em_cpu_energy() and remove division Date: Wed, 17 Jan 2024 09:57:06 +0000 Message-Id: <20240117095714.1524808-16-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331345475798125 X-GMAIL-MSGID: 1788331345475798125 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 Reviewed-by: Hongyan Xia --- 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 @@ -115,27 +115,6 @@ struct em_perf_domain { #define EM_MAX_NUM_CPUS 16 #endif -/* - * To avoid an overflow on 32bit machines while calculating the energy - * use a different order in the operation. First divide by the 'cpu_scale' - * which would reduce big value stored in the 'cost' field, then multiply by - * the 'sum_util'. This would allow to handle existing platforms, which have - * e.g. power ~1.3 Watt at max freq, so the 'cost' value > 1mln micro-Watts. - * In such scenario, where there are 4 CPUs in the Perf. Domain the 'sum_util' - * could be 4096, then multiplication: 'cost' * 'sum_util' would overflow. - * This reordering of operations has some limitations, we lose small - * precision in the estimation (comparing to 64bit platform w/o reordering). - * - * We are safe on 64bit machine. - */ -#ifdef CONFIG_64BIT -#define em_estimate_energy(cost, sum_util, scale_cpu) \ - (((cost) * (sum_util)) / (scale_cpu)) -#else -#define em_estimate_energy(cost, sum_util, scale_cpu) \ - (((cost) / (scale_cpu)) * (sum_util)) -#endif - struct em_data_callback { /** * active_power() - Provide power at the next performance state of @@ -249,8 +228,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, { struct em_perf_table *em_table; struct em_perf_state *ps; - unsigned long scale_cpu; - int cpu, i; + int i; #ifdef CONFIG_SCHED_DEBUG WARN_ONCE(!rcu_read_lock_held(), "EM: rcu read lock needed\n"); @@ -267,9 +245,6 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * max utilization to the allowed CPU capacity before calculating * effective performance. */ - cpu = cpumask_first(to_cpumask(pd->cpus)); - scale_cpu = arch_scale_cpu_capacity(cpu); - max_util = map_util_perf(max_util); max_util = min(max_util, allowed_cpu_cap); @@ -283,12 +258,12 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, ps = &em_table->state[i]; /* - * The capacity of a CPU in the domain at the performance state (ps) - * can be computed as: + * The performance (capacity) of a CPU in the domain at the performance + * state (ps) can be computed as: * - * ps->freq * scale_cpu - * ps->cap = -------------------- (1) - * cpu_max_freq + * ps->freq * scale_cpu + * ps->performance = -------------------- (1) + * cpu_max_freq * * So, ignoring the costs of idle states (which are not available in * the EM), the energy consumed by this CPU at that performance state @@ -296,9 +271,10 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * * ps->power * cpu_util * cpu_nrg = -------------------- (2) - * ps->cap + * ps->performance * - * since 'cpu_util / ps->cap' represents its percentage of busy time. + * since 'cpu_util / ps->performance' represents its percentage of busy + * time. * * NOTE: Although the result of this computation actually is in * units of power, it can be manipulated as an energy value @@ -308,9 +284,9 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * By injecting (1) in (2), 'cpu_nrg' can be re-expressed as a product * of two terms: * - * ps->power * cpu_max_freq cpu_util - * cpu_nrg = ------------------------ * --------- (3) - * ps->freq scale_cpu + * ps->power * cpu_max_freq + * cpu_nrg = ------------------------ * cpu_util (3) + * ps->freq * scale_cpu * * The first term is static, and is stored in the em_perf_state struct * as 'ps->cost'. @@ -320,11 +296,9 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * total energy of the domain (which is the simple sum of the energy of * all of its CPUs) can be factorized as: * - * ps->cost * \Sum cpu_util - * pd_nrg = ------------------------ (4) - * scale_cpu + * pd_nrg = ps->cost * \Sum cpu_util (4) */ - return em_estimate_energy(ps->cost, sum_util, scale_cpu); + return ps->cost * sum_util; } /** diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 548d54e55b08..4529a0469353 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -192,11 +192,9 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, unsigned long flags) { unsigned long prev_cost = ULONG_MAX; - u64 fmax; int i, ret; /* Compute the cost of each performance state. */ - fmax = (u64) table[nr_states - 1].frequency; for (i = nr_states - 1; i >= 0; i--) { unsigned long power_res, cost; @@ -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; + cost = power_res / table[i].performance; } table[i].cost = cost; From patchwork Wed Jan 17 09:57:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp802868dye; Wed, 17 Jan 2024 02:01:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGiDBT4dTozmTN/nRGkjkoK64ascfdVrOCSBwYiCkPypSaKFaAd6JzPFM+HtBFl1UyeHwd6 X-Received: by 2002:ae9:f44d:0:b0:783:49ec:1710 with SMTP id z13-20020ae9f44d000000b0078349ec1710mr8285265qkl.37.1705485708114; Wed, 17 Jan 2024 02:01:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485708; cv=pass; d=google.com; s=arc-20160816; b=rlWqjw+mnQ6n6NjHQZkXcC0YhudAtJoADSuES0h9Wfp9uMnILbqmO0MsSEgrVBO44u 0BfirH18L8VT1t18ecj0P1QFS447anRdx7wASsjJmvjdplG4NRte0BQuhPr/bvlyphTr Vmj3UxzResuPSQ/f62y//htolnjueW5JQCqoLVryp3fZUZcM+fVYc8q5M/uysUpub2xC 5NJPzQzCSUvwHQI9hCMo3v/hvD9okaO9b4nOGkA6sAwehqAF//AjrvZu69vdwmpP3j4T /JJ0bK4lxInddCI/PRzMhP+POf2BNsBJnO2SuXOuceygNbz1FGgpDAbUtkex3i99nSCl MtIg== 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=GPLde4qC7PLqD7UiZlgRcTLjNHHUFzDI3H4U4JIRuD8=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=mwPfvUIHqAqpXjkO95Ky6BlycHNBb7ng0eMHFIjgugOjvL32fFsauwnvfSH8wkBKQg XmAMovMusVOiUkkoygD0CjL/aDVLl29yRvvYbLFwE9BY09RUAeqTA0YeRqsrltC6ylz4 On/5oawdOnPfrzSuLQ3444JgtnjgmgGmZjOa9n0wWRF2Xi01IfgVyZiT6VTRLY9d1B0u P4g7wk3vXMFtqAtwkAlU+QLKkpnrMELf1iAKO/WJlchCbdijT3wRRyHg2dCHW1FzEUvg X/G/pykmarQwNcabTwOcQ5WJqX5dUKM8kknbjVtXH1KGLwsV991PhxfLRwK//a2BqUzx +HQg== 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-28791-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28791-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b10-20020a05620a088a00b00781187ac362si11476591qka.211.2024.01.17.02.01.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 02:01:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28791-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-28791-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28791-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id DE7381C24333 for ; Wed, 17 Jan 2024 10:01:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C1A521366; Wed, 17 Jan 2024 09:57:02 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4023C20DC7; Wed, 17 Jan 2024 09:56:59 +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=1705485421; cv=none; b=p6tI8GxigH1iaiOJfoktxArUtWLa4qZZEhzWgORl4/xg3cIlk3zyXM18NlN42MsOLpfP8jLn2ft1oh2C1ak30oFx76DPsc5V35604JufyX/ULfeY3lYVmeB390AhWik3ayB00MANSapCvYrTrE9tDTdlZWzdNUo6KAuec6awjyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485421; c=relaxed/simple; bh=bN8zkaUcMQSZ+WexLEFmE8LFAd5QK0bzmz+ebf2xcUk=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=oPjZAyVCNqZNiROJKBYbEyYtPYBDwWx/yWHcUVHhJJG0doLJmxJgqvCpDJixLE81vMmvlQsebwTiBOaokraLX21dQfrPZKtcV6Xx9g63LmJc5v5PZdLDZpA/QtHEMAWVa/M67iaPl8zi+P0BJ0oBAiMaC9rANpGUpzQsnqgYINw= 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 1599ADA7; Wed, 17 Jan 2024 01:57:45 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 412023F5A1; Wed, 17 Jan 2024 01:56:56 -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 v7 20/23] PM: EM: Change debugfs configuration to use runtime EM table data Date: Wed, 17 Jan 2024 09:57:11 +0000 Message-Id: <20240117095714.1524808-21-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331381686572261 X-GMAIL-MSGID: 1788331381686572261 Dump the runtime EM table values which can be modified in time. In order to do that allocate chunk of debug memory which can be later freed automatically thanks to devm_kcalloc(). This design can handle the fact that the EM table memory can change after EM update, so debug code cannot use the pointer from initialization phase. Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 67 ++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 4529a0469353..76aab2801bf0 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -37,20 +37,65 @@ static bool _is_cpu_device(struct device *dev) #ifdef CONFIG_DEBUG_FS static struct dentry *rootdir; -static void em_debug_create_ps(struct em_perf_state *ps, struct dentry *pd) +struct em_dbg_info { + struct em_perf_domain *pd; + int ps_id; +}; + +#define DEFINE_EM_DBG_SHOW(name, fname) \ +static int em_debug_##fname##_show(struct seq_file *s, void *unused) \ +{ \ + struct em_dbg_info *em_dbg = s->private; \ + struct em_perf_state *table; \ + unsigned long val; \ + \ + rcu_read_lock(); \ + table = em_perf_state_from_pd(em_dbg->pd); \ + val = table[em_dbg->ps_id].name; \ + rcu_read_unlock(); \ + \ + seq_printf(s, "%lu\n", val); \ + return 0; \ +} \ +DEFINE_SHOW_ATTRIBUTE(em_debug_##fname) + +DEFINE_EM_DBG_SHOW(frequency, frequency); +DEFINE_EM_DBG_SHOW(power, power); +DEFINE_EM_DBG_SHOW(cost, cost); +DEFINE_EM_DBG_SHOW(performance, performance); +DEFINE_EM_DBG_SHOW(flags, inefficiency); + +static void em_debug_create_ps(struct em_perf_domain *em_pd, + struct em_dbg_info *em_dbg, int i, + struct dentry *pd) { + struct em_perf_state *table; + unsigned long freq; struct dentry *d; char name[24]; - snprintf(name, sizeof(name), "ps:%lu", ps->frequency); + em_dbg[i].pd = em_pd; + em_dbg[i].ps_id = i; + + rcu_read_lock(); + table = em_perf_state_from_pd(em_pd); + freq = table[i].frequency; + rcu_read_unlock(); + + snprintf(name, sizeof(name), "ps:%lu", freq); /* Create per-ps directory */ d = debugfs_create_dir(name, pd); - debugfs_create_ulong("frequency", 0444, d, &ps->frequency); - debugfs_create_ulong("power", 0444, d, &ps->power); - debugfs_create_ulong("cost", 0444, d, &ps->cost); - debugfs_create_ulong("performance", 0444, d, &ps->performance); - debugfs_create_ulong("inefficient", 0444, d, &ps->flags); + debugfs_create_file("frequency", 0444, d, &em_dbg[i], + &em_debug_frequency_fops); + debugfs_create_file("power", 0444, d, &em_dbg[i], + &em_debug_power_fops); + debugfs_create_file("cost", 0444, d, &em_dbg[i], + &em_debug_cost_fops); + debugfs_create_file("performance", 0444, d, &em_dbg[i], + &em_debug_performance_fops); + debugfs_create_file("inefficient", 0444, d, &em_dbg[i], + &em_debug_inefficiency_fops); } static int em_debug_cpus_show(struct seq_file *s, void *unused) @@ -73,6 +118,7 @@ DEFINE_SHOW_ATTRIBUTE(em_debug_flags); static void em_debug_create_pd(struct device *dev) { + struct em_dbg_info *em_dbg; struct dentry *d; int i; @@ -86,9 +132,14 @@ static void em_debug_create_pd(struct device *dev) debugfs_create_file("flags", 0444, d, dev->em_pd, &em_debug_flags_fops); + em_dbg = devm_kcalloc(dev, dev->em_pd->nr_perf_states, + sizeof(*em_dbg), GFP_KERNEL); + if (!em_dbg) + return; + /* Create a sub-directory for each performance state */ for (i = 0; i < dev->em_pd->nr_perf_states; i++) - em_debug_create_ps(&dev->em_pd->table[i], d); + em_debug_create_ps(dev->em_pd, em_dbg, i, d); } From patchwork Wed Jan 17 09:57:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188764 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp803037dye; Wed, 17 Jan 2024 02:02:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJ/XzmgxuwxO//EbuzDvhGI5QKH+W8wXPW3iyYOc6ndMX210pCsSVa6FiiuWm13NSqu7Xw X-Received: by 2002:ad4:5bcd:0:b0:681:7837:ccda with SMTP id t13-20020ad45bcd000000b006817837ccdamr1596175qvt.4.1705485724232; Wed, 17 Jan 2024 02:02:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485724; cv=pass; d=google.com; s=arc-20160816; b=WIs98lh2TwM/57g35DrRCu2XNnExj42l/HO/AyY7cOVWnaDu8Cr3ac6dJ9aHwpsh9F YK2Sht0ZB/PDEGWsJp5OyPeehKreIjpnOIDYarfE90m1WX6JPik4O5r4lRx5Bh5kbowO zBeHumlueLg1x3FJdO/qEgE2ha2u8POBSvSAecPXJdtqBHHmUBTnPbFUe1i81nSTi4+m xmU6VhgN3TZOVRr6b4ekYnUJFev6wsZiygSalpf9jKgbzqpXbKt5Cfd9G3NPSM/SXqRt GNRGToHtJ7WHTZTIxa8op1ZsukfS80MwBZG14aFJ46zu4s9Hu+njmpe8VPvP1w3TtvN0 f7Mg== 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=0v0iCUl/fcOx3hG1Zs3JSjI7UI7A7G3LoayVKDmTLbY=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=kYGJW6o6S5QWvvpHHQkb8xvMvAe8GxJsxT1SonmO3HnVKF/c4cFAWkz/gQi9RvEtty G2DNc9hstw5pGHTjsXCakxnYdPtqrxnP5DmUrFYhzX9aGtUChbBlAGu9BqvC0XZz6ahK Ys/vjQztXkDVFQlWxaxB07LVy2yF8/dULqilOpEX2X/14e/RpIqWTvfq+N7Lyg6CvYGF eDs0KIMmtWK+8tGYgPCctps9AmWSjMInqL0ivundRT2Ntfpp7r5wZ6GFQBw7dhDcFoJp b8mgxJ6WTMkGEgpYlGZeuoKUupuIxnJbB+oQZlMh148nl9PejWbMCo3jzBDHop+5Rkkg fybA== 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-28792-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28792-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c14-20020a0cca0e000000b006817785de23si1851802qvk.316.2024.01.17.02.02.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 02:02:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28792-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-28792-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28792-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0A5FC1C24346 for ; Wed, 17 Jan 2024 10:02:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E48F0219EE; Wed, 17 Jan 2024 09:57:05 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 706E721364; Wed, 17 Jan 2024 09:57:02 +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=1705485424; cv=none; b=c1Mr8U2xrEcwvtzbdCG/ywb+jT7Rccv1MnkQC02zp6X0fpaZ3x1FWNiKtaMMWeMBLTncQeiG07TTmqmJp59qbN+6/QMgDQLIE2F496JKtu+kBnaLm9Pz6b6qe1EqUeVSFytyxJnq+NLXkAJosayynO+7tVZsWpViyyH8NDQikgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485424; c=relaxed/simple; bh=a+ihGKmCAGS+/wyl5s2j46tqfPjSLpmEBphz3uVw6lQ=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=RAuL3TYpXGwxqtTSlFLxXpUMfwM2GntiHnl5Zo8MLaVFJySG5aEwUz6plzsDivJj7CE9DODM+qNYu+myni0QTTdu/V9CWq3R5FfhVPGDAWmvihKOHYrnp0v7L8u6EEZIXlEA0N5npC84wVKu0kTo9TvFVkUgBW0q2AU/HkTSKOk= 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 07001DA7; Wed, 17 Jan 2024 01:57:48 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3432F3F5A1; Wed, 17 Jan 2024 01:56:59 -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 v7 21/23] PM: EM: Remove old table Date: Wed, 17 Jan 2024 09:57:12 +0000 Message-Id: <20240117095714.1524808-22-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331399076527000 X-GMAIL-MSGID: 1788331399076527000 Remove the old EM table which wasn't able to modify the data. Clean the unneeded function and refactor the code a bit. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 2 -- kernel/power/energy_model.c | 46 ++++++------------------------------ 2 files changed, 7 insertions(+), 41 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index aabfc26fcd31..92866a81abe4 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -53,7 +53,6 @@ struct em_perf_table { /** * struct em_perf_domain - Performance domain - * @table: List of performance states, in ascending order * @em_table: Pointer to the runtime modifiable em_perf_table * @nr_perf_states: Number of performance states * @flags: See "em_perf_domain flags" @@ -69,7 +68,6 @@ struct em_perf_table { * field is unused. */ struct em_perf_domain { - struct em_perf_state *table; struct em_perf_table __rcu *em_table; int nr_perf_states; unsigned long flags; diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 76aab2801bf0..e91c8efb5361 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -276,17 +276,6 @@ 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; -} - /** * em_dev_update_perf_domain() - Update runtime EM table for a device * @dev : Device for which the EM is to be updated @@ -331,24 +320,6 @@ int em_dev_update_perf_domain(struct device *dev, } EXPORT_SYMBOL_GPL(em_dev_update_perf_domain); -static int em_create_runtime_table(struct em_perf_domain *pd) -{ - struct em_perf_table __rcu *table; - int table_size; - - table = em_table_alloc(pd); - if (!table) - return -ENOMEM; - - /* Initialize runtime table with existing data */ - table_size = sizeof(struct em_perf_state) * pd->nr_perf_states; - memcpy(table->state, pd->table, table_size); - - rcu_assign_pointer(pd->em_table, table); - - return 0; -} - static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, struct em_perf_state *table, struct em_data_callback *cb, @@ -409,6 +380,7 @@ static int em_create_pd(struct device *dev, int nr_states, struct em_data_callback *cb, cpumask_t *cpus, unsigned long flags) { + struct em_perf_table __rcu *em_table; struct em_perf_domain *pd; struct device *cpu_dev; int cpu, ret, num_cpus; @@ -435,17 +407,15 @@ static int em_create_pd(struct device *dev, int nr_states, pd->nr_perf_states = nr_states; - ret = em_allocate_perf_table(pd, nr_states); - if (ret) + em_table = em_table_alloc(pd); + if (!em_table) goto free_pd; - ret = em_create_perf_table(dev, pd, pd->table, cb, flags); + ret = em_create_perf_table(dev, pd, em_table->state, cb, flags); if (ret) goto free_pd_table; - ret = em_create_runtime_table(pd); - if (ret) - goto free_pd_table; + rcu_assign_pointer(pd->em_table, em_table); if (_is_cpu_device(dev)) for_each_cpu(cpu, cpus) { @@ -458,7 +428,7 @@ static int em_create_pd(struct device *dev, int nr_states, return 0; free_pd_table: - kfree(pd->table); + kfree(em_table); free_pd: kfree(pd); return -EINVAL; @@ -629,7 +599,7 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, dev->em_pd->flags |= flags; - em_cpufreq_update_efficiencies(dev, dev->em_pd->table); + em_cpufreq_update_efficiencies(dev, dev->em_pd->em_table->state); em_debug_create_pd(dev); dev_info(dev, "EM: created perf domain\n"); @@ -666,8 +636,6 @@ void em_dev_unregister_perf_domain(struct device *dev) mutex_lock(&em_pd_mutex); em_debug_remove_pd(dev); - kfree(dev->em_pd->table); - em_table_free(dev->em_pd->em_table); kfree(dev->em_pd); From patchwork Wed Jan 17 09:57:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188765 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp803208dye; Wed, 17 Jan 2024 02:02:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhgxY+RzG0qn4EHtHPOyp24+ZVVipeRDDK/QlE3Ae0Bo8Ho7XK+6FH5rt7Ete2T85sR2lk X-Received: by 2002:a19:6519:0:b0:50e:b8d3:143e with SMTP id z25-20020a196519000000b0050eb8d3143emr3833016lfb.51.1705485741793; Wed, 17 Jan 2024 02:02:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485741; cv=pass; d=google.com; s=arc-20160816; b=KJGJwHTbcJibir5/M2s2T1cxUxNw6K3t09p17VFTWUPbeFMdd5hZnjGyqNzqBGOghL gSf6YTLjjeKib0uX+NshRWJJUkJhcwTVR5VflMldK6FW8eps150/Qmmj2hWHUfCLpZpe BiRvmFByXCISiH7EBGs1EQakC+GyO38pn2h5XLzf5SCtkODoFXyq8W+Gfnk5JR50XC9z HjM00f8LlYJH6GG9d8eda4kfx5mhRs+yRqD+cF4LRaNmekTd9CqJOJSJ8h+hgLgYBq7K y3B4nHDGjfk9Nws20HULoxSvBPrLqx7W/EjKxOhGIbYnsodtfRt4TAox8GC96OU69y00 hflg== 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=vJMdtZdOtrb9QcW4CMQsyoF/cY5IZdrvK7Nb1VQTSGk=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=R+WGE327z5zm25rW+6EVkloRPWolx0xrNjdT0yeqd3AzIyRIptR5hHAwXa7ob20tk0 J1Uk4/Z7gTuyrQUr1B8ZpeWZl5B7wtlwnzb/3V3sIo9PU7XMLNWIGQ+8AKisOBkJUIw2 bVydT1sMiAA8MXQAwsSe4FME87yJooVbZSH+vKIq2/UvrOxfu4utTchfKxB82T4l+5QI FYte/RnDoTzGJ9HQj6ZvG6NNTZvks5/28ValzY3Pd444GsZFi/f59Oau/SH1lRzcv4B3 oKN5cztae5GAA+Zy2v/OQgUIBdHNSS34dkyDiQcMOCIqthfzBXHQWkJKIBcRYSzsswFN 8Usg== 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-28793-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28793-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id es14-20020a056402380e00b00556a77ae452si5758074edb.215.2024.01.17.02.02.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 02:02:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28793-ouuuleilei=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-28793-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28793-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 663901F212D0 for ; Wed, 17 Jan 2024 10:02:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4483721A03; Wed, 17 Jan 2024 09:57:08 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A8B021376; Wed, 17 Jan 2024 09:57:05 +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=1705485426; cv=none; b=VuZqFmUEN/k2aqF6CuHSy+Lnyys126Hxc/h/Q+X61OaRH8oqnVUgUvCyVvo2veXVu4v2JHYMwpo5qU2kv8IbJpwaAaKsvd32ygjaGSq3OKmwaN7tbESw7Vgg5CPQI18DuiPvMuvTJzkJix8J59AVr7UnQQTo2bPgVyKzQ9gifpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485426; c=relaxed/simple; bh=A2pgHBmRnmRSJFL5C5XWdn1pDAImwUbEwNRZLTh2wQw=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=Wg34bI7b7rJ1ttMiuxqiMm4DGvces214OczX/jR5ZgQ31dKFSzRe7JyR+ycyNb0stcfz8MrFrAbWRBp5VP/8ijt9Vtaht3ZYECBsp0SJ6tztpQbPy9fyoTBF/mNJ/S3aDMM26RIynNnhtAMNb8AhZrEVGB2j04PLZfIrmei8Jmc= 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 EF09711FB; Wed, 17 Jan 2024 01:57:50 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2609B3F5A1; Wed, 17 Jan 2024 01:57:02 -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 v7 22/23] PM: EM: Add em_dev_compute_costs() Date: Wed, 17 Jan 2024 09:57:13 +0000 Message-Id: <20240117095714.1524808-23-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331417338852718 X-GMAIL-MSGID: 1788331417338852718 The device drivers can modify EM at runtime by providing a new EM table. The EM is used by the EAS and the em_perf_state::cost stores pre-calculated value to avoid overhead. This patch provides the API for device drivers to calculate the cost values properly (and not duplicate the same code). Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 8 ++++++++ kernel/power/energy_model.c | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 92866a81abe4..770755df852f 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -170,6 +170,8 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, void em_dev_unregister_perf_domain(struct device *dev); struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd); void em_table_free(struct em_perf_table __rcu *table); +int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM @@ -379,6 +381,12 @@ struct em_perf_state *em_perf_state_from_pd(struct em_perf_domain *pd) { return NULL; } +static inline +int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states) +{ + return -EINVAL; +} #endif #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index e91c8efb5361..104cc2e2aa84 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -276,6 +276,24 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, return 0; } +/** + * em_dev_compute_costs() - Calculate cost values for new runtime EM table + * @dev : Device for which the EM table is to be updated + * @table : The new EM table that is going to get the costs calculated + * + * Calculate the em_perf_state::cost values for new runtime EM table. The + * values are used for EAS during task placement. It also calculates and sets + * the efficiency flag for each performance state. When the function finish + * successfully the EM table is ready to be updated and used by EAS. + * + * Return 0 on success or a proper error in case of failure. + */ +int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states) +{ + return em_compute_costs(dev, table, NULL, nr_states, 0); +} + /** * em_dev_update_perf_domain() - Update runtime EM table for a device * @dev : Device for which the EM is to be updated From patchwork Wed Jan 17 09:57:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 188766 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp803396dye; Wed, 17 Jan 2024 02:02:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEcHrE/nNE3OVZL9zMMXvHRZrAs6e/jMsc0RBhU7/8KvezDQWDSlndHlO0p8BiHjUlKXrIa X-Received: by 2002:aa7:d9d6:0:b0:557:1a63:812d with SMTP id v22-20020aa7d9d6000000b005571a63812dmr3091517eds.6.1705485760798; Wed, 17 Jan 2024 02:02:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485760; cv=pass; d=google.com; s=arc-20160816; b=qteUV2D/qMi3FPNyO2+kw0ujAmwqmZ3YjPIRmfDB1BB1rcuGxSzC7VFcP249JfXr71 VFDlxR1V4TCSbUkqD6u3BNXVF6pRx5F1YTrlp3R2gyeDkds5jo2dm8BbjiQC4WVCN383 WCzt898cjTOVY8sDKf7KbeD4xk90+8ppZwKK4OsY+nUFvTelEcEaIGpfAfJC1GwFYrE7 XAooS5Wh4OSMfTs0gd8Nk5vfk8Q74LxF3ZW59hayTpalCuMbyhwZMuIGMdW+L3ttbHeI LsFmVbRRYowfybpuWkTdHDUSfOYYmSKBOPY/pRIM7n2TUSOXSMU61NxATXHGS7GzPmBp 86PQ== 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=kcLJrg/l5MPGA7CI3BMSpEWcCPuU9VYWzLKr22o1L0U=; fh=dnwF3PGywHXrL+zB51aLYhCKaTICdBffwESxtAIta2U=; b=ajwpF0RgwgICt+ksc9lLnzGZS0r+MY3sTC3nN2VEK7HWaZCo34dcrr0uU37CuANA6s idTw1ioGLSuHWaMBpfIqLnAmHKFYhySngaNIgHfLmGU7bvQsVn70wJAt1j+6O9VmtFEB i+18hemlrsb6IPTqQQ0Xjw8eMFdNG120px1t09t4T44WaRxBjcep7SlfDmcLGd2ZdJj4 Ey70yCw6uoxeDHEwzA415669F0A5RFU1pmR1XzwHYugrsWFuQfCNiebqzjrgMLrDp52N XXBAggFoBJWnWeN7rCBF8Je7IYpaFiwjSb21hHS/xCRS9/kkmUNZYtD97PF6JTYGP6/v UKXg== 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-28794-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28794-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ds5-20020a0564021cc500b0054c392acb7asi5925752edb.281.2024.01.17.02.02.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 02:02:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28794-ouuuleilei=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-28794-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28794-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 am.mirrors.kernel.org (Postfix) with ESMTPS id C3B3C1F2175D for ; Wed, 17 Jan 2024 10:02:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC8E922301; Wed, 17 Jan 2024 09:57:12 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 473A021A04; Wed, 17 Jan 2024 09:57:08 +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=1705485430; cv=none; b=HDJsW1J1z2hKXHVcBF2MHU2vBKB/7uQaeXY/itAc/VgQ8YJfmf81RHnzq+JLL0xVky1H2s9prSBekLKIHXGLEROdyXcIeFuIYCIElv/XfCXIeFbyZDRK0BjfcSCaCyH9HmTFZQRs1tUGHR3+FeT/OW3snI6rlF8HtjlBdkrPH38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705485430; c=relaxed/simple; bh=A2H4bLvuCGFSPvwL6isvOpohvRIF8XsUro/bO9ezbw0=; h=Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; b=jBxhoyt61ZhT3V4+dvu+aWrb9Ak7rgsHUsUWKA5dSTERlXNQEZfoPUqQ0EcXERPfANzT1HOw/svBBYg2JK/c3mGbiL1QRlls3OOvq/mFdVypABKkPMbbi2mG909RXnT0kR6ct9iua10kmnBj5du69spuCl5+bPPL8GyRpibkmkw= 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 DF672DA7; Wed, 17 Jan 2024 01:57:53 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.90.139]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 190F13F5A1; Wed, 17 Jan 2024 01:57:04 -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 v7 23/23] Documentation: EM: Update with runtime modification design Date: Wed, 17 Jan 2024 09:57:14 +0000 Message-Id: <20240117095714.1524808-24-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240117095714.1524808-1-lukasz.luba@arm.com> References: <20240117095714.1524808-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: 1788331436999600442 X-GMAIL-MSGID: 1788331436999600442 Add a new description which covers the information about runtime EM. It contains the design decisions, describes models and how they reflect the reality. Remove description of the default EM. Add example driver code which modifies EM. Add API documentation for the new feature which allows to modify the EM in runtime. Signed-off-by: Lukasz Luba --- Documentation/power/energy-model.rst | 183 ++++++++++++++++++++++++++- 1 file changed, 179 insertions(+), 4 deletions(-) diff --git a/Documentation/power/energy-model.rst b/Documentation/power/energy-model.rst index 13225965c9a4..ada4938c37e5 100644 --- a/Documentation/power/energy-model.rst +++ b/Documentation/power/energy-model.rst @@ -71,6 +71,31 @@ whose performance is scaled together. Performance domains generally have a required to have the same micro-architecture. CPUs in different performance domains can have different micro-architectures. +To better reflect power variation due to static power (leakage) the EM +supports runtime modifications of the power values. The mechanism relies on +RCU to free the modifiable EM perf_state table memory. Its user, the task +scheduler, also uses RCU to access this memory. The EM framework provides +API for allocating/freeing the new memory for the modifiable EM table. +The old memory is freed automatically using RCU callback mechanism when there +are no owners anymore for the given EM runtime table instance. This is tracked +using kref mechanism. The device driver which provided the new EM at runtime, +should call EM API to free it safely when it's no longer needed. The EM +framework will handle the clean-up when it's possible. + +The kernel code which want to modify the EM values is protected from concurrent +access using a mutex. Therefore, the device driver code must run in sleeping +context when it tries to modify the EM. + +With the runtime modifiable EM we switch from a 'single and during the entire +runtime static EM' (system property) design to a 'single EM which can be +changed during runtime according e.g. to the workload' (system and workload +property) design. + +It is possible also to modify the CPU performance values for each EM's +performance state. Thus, the full power and performance profile (which +is an exponential curve) can be changed according e.g. to the workload +or system property. + 2. Core APIs ------------ @@ -175,10 +200,82 @@ CPUfreq governor is in use in case of CPU device. Currently this calculation is not provided for other type of devices. More details about the above APIs can be found in ```` -or in Section 2.4 +or in Section 2.5 + + +2.4 Runtime modifications +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Drivers willing to update the EM at runtime should use the following dedicated +function to allocate a new instance of the modified EM. The API is listed +below:: + + struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd); + +This allows to allocate a structure which contains the new EM table with +also RCU and kref needed by the EM framework. The 'struct em_perf_table' +contains array 'struct em_perf_state state[]' which is a list of performance +states in ascending order. That list must be populated by the device driver +which wants to update the EM. The list of frequencies can be taken from +existing EM (created during boot). The content in the 'struct em_perf_state' +must be populated by the driver as well. + +This is the API which does the EM update, using RCU pointers swap:: + + int em_dev_update_perf_domain(struct device *dev, + struct em_perf_table __rcu *new_table); + +Drivers must provide a pointer to the allocated and initialized new EM +'struct em_perf_table'. That new EM will be safely used inside the EM framework +and will be visible to other sub-systems in the kernel (thermal, powercap). +The main design goal for this API is to be fast and avoid extra calculations +or memory allocations at runtime. When pre-computed EMs are available in the +device driver, than it should be possible to simply re-use them with low +performance overhead. + +In order to free the EM, provided earlier by the driver (e.g. when the module +is unloaded), there is a need to call the API:: + + void em_table_free(struct em_perf_table __rcu *table); + +It will allow the EM framework to safely remove the memory, when there is +no other sub-system using it, e.g. EAS. + +To use the power values in other sub-systems (like thermal, powercap) there is +a need to call API which protects the reader and provide consistency of the EM +table data:: + + struct em_perf_state *em_perf_state_from_pd(struct em_perf_domain *pd); + +It returns the 'struct em_perf_state' pointer which is an array of performance +states in ascending order. +This function must be called in the RCU read lock section (after the +rcu_read_lock()). When the EM table is not needed anymore there is a need to +call rcu_real_unlock(). In this way the EM safely uses the RCU read section +and protects the users. It also allows the EM framework to manage the memory +and free it. More details how to use it can be found in Section 3.2 in the +example driver. + +There is dedicated API for device drivers to calculate em_perf_state::cost +values:: + + int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states); + +These 'cost' values from EM are used in EAS. The new EM table should be passed +together with the number of entries and device pointer. When the computation +of the cost values is done properly the return value from the function is 0. +The function takes care for right setting of inefficiency for each performance +state as well. It updates em_perf_state::flags accordingly. +Then such prepared new EM can be passed to the em_dev_update_perf_domain() +function, which will allow to use it. + +More details about the above APIs can be found in ```` +or in Section 3.2 with an example code showing simple implementation of the +updating mechanism in a device driver. -2.4 Description details of this API +2.5 Description details of this API ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. kernel-doc:: include/linux/energy_model.h :internal: @@ -187,8 +284,11 @@ or in Section 2.4 :export: -3. Example driver ------------------ +3. Examples +----------- + +3.1 Example driver with EM registration +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The CPUFreq framework supports dedicated callback for registering the EM for a given CPU(s) 'policy' object: cpufreq_driver::register_em(). @@ -242,3 +342,78 @@ EM framework:: 39 static struct cpufreq_driver foo_cpufreq_driver = { 40 .register_em = foo_cpufreq_register_em, 41 }; + + +3.2 Example driver with EM modification +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This section provides a simple example of a thermal driver modifying the EM. +The driver implements a foo_thermal_em_update() function. The driver is woken +up periodically to check the temperature and modify the EM data:: + + -> drivers/soc/example/example_em_mod.c + + 01 static void foo_get_new_em(struct foo_context *ctx) + 02 { + 03 struct em_perf_table __rcu *em_table; + 04 struct em_perf_state *table, *new_table; + 05 struct device *dev = ctx->dev; + 06 struct em_perf_domain *pd; + 07 unsigned long freq; + 08 int i, ret; + 09 + 10 pd = em_pd_get(dev); + 11 if (!pd) + 12 return; + 13 + 14 em_table = em_table_alloc(pd); + 15 if (!em_table) + 16 return; + 17 + 18 new_table = em_table->state; + 19 + 20 rcu_read_lock(); + 21 table = em_perf_state_from_pd(pd); + 22 for (i = 0; i < pd->nr_perf_states; i++) { + 23 freq = table[i].frequency; + 24 foo_get_power_perf_values(dev, freq, &new_table[i]); + 25 } + 26 rcu_read_unlock(); + 27 + 28 /* Calculate 'cost' values for EAS */ + 29 ret = em_dev_compute_costs(dev, table, pd->nr_perf_states); + 30 if (ret) { + 31 dev_warn(dev, "EM: compute costs failed %d\n", ret); + 32 em_free_table(em_table); + 33 return; + 34 } + 35 + 36 ret = em_dev_update_perf_domain(dev, em_table); + 37 if (ret) { + 38 dev_warn(dev, "EM: update failed %d\n", ret); + 39 em_free_table(em_table); + 40 return; + 41 } + 42 + 43 /* + 44 * Since it's one-time-update drop the usage counter. + 45 * The EM framework will later free the table when needed. + 46 */ + 47 em_table_free(em_table); + 48 } + 49 + 50 /* + 51 * Function called periodically to check the temperature and + 52 * update the EM if needed + 53 */ + 54 static void foo_thermal_em_update(struct foo_context *ctx) + 55 { + 56 struct device *dev = ctx->dev; + 57 int cpu; + 58 + 59 ctx->temperature = foo_get_temp(dev, ctx); + 60 if (ctx->temperature < FOO_EM_UPDATE_TEMP_THRESHOLD) + 61 return; + 62 + 63 foo_get_new_em(ctx); + 64 }