From patchwork Thu Jan 4 17:15:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185089 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5747193dyb; Thu, 4 Jan 2024 09:17:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGf9ZG1KdeH/0Ab39EyLQLhMtLSw17F0VsljXnRMZXU/Oeo84JVX7KVLyNqxFLKNNKa9Tiq X-Received: by 2002:a05:6808:1147:b0:3bb:6dfc:c0b0 with SMTP id u7-20020a056808114700b003bb6dfcc0b0mr1086296oiu.37.1704388630203; Thu, 04 Jan 2024 09:17:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388630; cv=none; d=google.com; s=arc-20160816; b=D8iUOpYstHT302MhmCMk99Jqc/ihb7QtNJjq8+ciXN3xaERmGnn0L3JfyGonukWtNn s147dNRz4thT65h+UFrLx58D53C/E6QnMraEDalC8Q7Os2BJi+W/eqlkIyzI1D6qaUZC 4cUK63iqQBcCYR+8dr8/s+fu+qzbsmOLg8obljStDOtSf9OLYsg43lpGel3BR85pyIMB n0T69EFZ9kDpqOTewU6O5hCpjiIYDP+L5r0i/CY6yBYpeGlI35Ps8MWjXCjYoT/6K2JQ KYsISGq4yHWOZfTh6qVjBWgPre9RFIOpH753EMHuMFrira6f/ov7/yMTHP5xUoPs/M4j IaUw== ARC-Message-Signature: i=1; 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=sO+xFRNTgipgQOKTe/WxvJg41iGrKe4y02ki9gngRd8=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=xWtcE0gs6x+JwTf9J/3ZDAd0e40aFyGrfMNmaZHJlTY80GR1PYtEyJyH9rRnmVgfEn d4lgQVSDdZNVDBRXUOWB4g+ttprSWS9WSAbzzGBB2yOmo5nPh3roGjvJKh0z/47LdshQ 1VcyeaSxgDTfa/nc4Fvaij06t1qJOF0IQVFkU1US8MJNABVmIZmqi+2GC4DXsOgQ70ID Af6lxs066MhcPrkq6cp3dCSyFiOrc/P4gkA413Ja+0onl4MWlBf8M2lhcFkbmFUEnxjV CeZNKdLUcRTvgmIttbcguyO4JS3CxTFpPqmSWFjH7oqoBJhKTjK8Efqyi4bBXy97wVP5 MEkA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17005-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17005-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x12-20020a056102090c00b0046749f21a00si1558185vsh.99.2024.01.04.09.17.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:17:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17005-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17005-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17005-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 F14511C24164 for ; Thu, 4 Jan 2024 17:17:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 780FB28E25; Thu, 4 Jan 2024 17:14:58 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BDE5928DD7; Thu, 4 Jan 2024 17:14:55 +0000 (UTC) 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 0B62E153B; Thu, 4 Jan 2024 09:15:41 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 94A6E3F64C; Thu, 4 Jan 2024 09:14:52 -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 Subject: [PATCH v6 02/23] PM: EM: Refactor em_cpufreq_update_efficiencies() arguments Date: Thu, 4 Jan 2024 17:15:32 +0000 Message-Id: <20240104171553.2080674-3-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181012268033085 X-GMAIL-MSGID: 1787181012268033085 In order to prepare the code for the modifiable EM perf_state table, refactor existing function em_cpufreq_update_efficiencies(). The function now takes the ptr to the EM table as its argument. No functional impact. Signed-off-by: Lukasz Luba --- 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 Thu Jan 4 17:15:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185090 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5747406dyb; Thu, 4 Jan 2024 09:17:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZ9uDTHbi7mz44mxCqEySg79X4s9+bcZU2MgkV0cpQeVPxm9iM11c2GCL/fkUtavjjm9Ba X-Received: by 2002:a05:6a20:3945:b0:196:1b73:39dc with SMTP id r5-20020a056a20394500b001961b7339dcmr977397pzg.65.1704388650475; Thu, 04 Jan 2024 09:17:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388650; cv=none; d=google.com; s=arc-20160816; b=iI0741vYWFqL+P3c77emcOPdHKw/XMFDKeYwgAbbUrKJs3cO/3pkaVKu6/Ai0EdYTv sIU3F7iJWTKj96KGQ3xpliE2yz5LM+BKuvDSEZoLtVJ0ELUKD+9Cy70hsr7y/rcFtW5E ZuKn8g2uQoOlIez6BHMOhYFSmprZItGgZVicUqMalUA6+3YgtEe5cSLaPcB2wKLWxdIs 8GSaHBrUAi6sD2/IPplFQz4IpnE7Z6+QZ5+a21IPqdnE59TaRA31UK/D3rabqN/X2/mb fJtnvjzD5K17aOIQEdsU/YacHXveFot2z0N7BvaBlyt84TWB9abwdJir41zLOa87sci2 jTRw== ARC-Message-Signature: i=1; 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=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=ceQecyYECx5PgUV0MsJ7mVrynA3LI+2gMiYN+VRn6sInGDEeFDQHfzm0i2zyYDCB5G wEAoBrdtv5m3YFGRO5hydxkZtjEYJzfV1OwM8dWsLSJ0W+yZfqLP3IgxSsrwF6N9Ew6Z NDwOxIVAcWUoGL+LmtbLkRef4Qe9vkJNap+ywjBx1sGwDX1Kj0STG9ThAnCy0ODD0n/b e6gBmEtknx3WxPqRpDVI8ciouqhwFXWiL3o1M6ETTNrJ37KOL8K7Ab2/d6byOk4qKa4u k8p0Wb7EuHP5xBL5nFItOhL8CCUIUYav0EhDwROtUDkpq07Ni8fTlnLZgVvMVLXm2zIA CoFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17006-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17006-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 d12-20020a63fd0c000000b005cdfa5be05bsi21095000pgh.445.2024.01.04.09.17.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:17:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17006-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; spf=pass (google.com: domain of linux-kernel+bounces-17006-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17006-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 11106285D14 for ; Thu, 4 Jan 2024 17:17:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1365E2C193; Thu, 4 Jan 2024 17:15:01 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6033428E23; Thu, 4 Jan 2024 17:14:58 +0000 (UTC) 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 D26CF153B; Thu, 4 Jan 2024 09:15:43 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 677083F64C; Thu, 4 Jan 2024 09:14:55 -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 Subject: [PATCH v6 03/23] PM: EM: Find first CPU active while updating OPP efficiency Date: Thu, 4 Jan 2024 17:15:33 +0000 Message-Id: <20240104171553.2080674-4-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181033543435542 X-GMAIL-MSGID: 1787181033543435542 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 Thu Jan 4 17:15:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185091 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5747488dyb; Thu, 4 Jan 2024 09:17:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzcgCUkIzclX2YRLQ4sZBMmxX2IqyCbP5fp/6R92sDdxO9I/gPwkmlzxD9zsPVjRKJt51k X-Received: by 2002:a05:620a:2550:b0:781:54d6:912c with SMTP id s16-20020a05620a255000b0078154d6912cmr1142781qko.63.1704388658802; Thu, 04 Jan 2024 09:17:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388658; cv=none; d=google.com; s=arc-20160816; b=UfmUrW1VGRC9T7WjcnnAjdueKpy84WSdmQsCuuZFhlYC5AY2esVxgPHlzOAWp3w1Je vEK99aZxXsjHzItRuvcesp9y8QPk8r7Us0nCPfH+u7RaFGw6ugQAw11OV5IDoMQmIofh gmCsUeptUwHvGEFK62Y4gMxTgmTFhmh2vyVITXRSuWSLukQN5eOyVhSNAD14op+uWIXq ea/AMjWW3CTA5nE8iJ378UshqoHfQCBnbzC9I20hw5wS2uKS7jPBNOHADh6DFF0ZG2FI E9/syBx35dMxC+4ySGqzp4UrECRicla8vDOEIXQhLl+0faIaEX/8FPswcQJI+3h9xGZQ aGZA== ARC-Message-Signature: i=1; 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=3AECYDb6uWJZEUGtaSUJGyTJdveA9vIUqSRzyHgYBEU=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=PUTHuaCU1KHYUlR/OZNpHbcdEUFbktks80uU1dESwO1luqWskL+W9AUNghgqaSxnsV Z6ESqjLD0IxQzakrYP6bm/vlfRdrkV/3akxOyq2UcIT/U6MntyYEoGdlQ8+8UQgs4uBU OPwogGx0L3f4OTntxUtwTUypmjnOse61QPvY2KNpBwJQxoA/6sAyqto9UTyzZ2CrAGco tywOc9eAhAtRVD+LC7/400TyPBdn7SmghIM6RkliQqPqzFLKCd1kGtZSJrtg944TAbnY eqSIyUc4u74ntBqsSGqtTm0zjDxStXykzoVzMxG4pdj3qass6xRIazvkLrY9lU47mzz8 jG2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17007-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17007-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i20-20020a05620a249400b00781eb9c1c7dsi3215744qkn.77.2024.01.04.09.17.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:17:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17007-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17007-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17007-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 977D21C24164 for ; Thu, 4 Jan 2024 17:17:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 395742C1B1; Thu, 4 Jan 2024 17:15:04 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 521832C198; Thu, 4 Jan 2024 17:15:01 +0000 (UTC) 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 A49111570; Thu, 4 Jan 2024 09:15:46 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 393133F64C; Thu, 4 Jan 2024 09:14:58 -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 Subject: [PATCH v6 04/23] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Date: Thu, 4 Jan 2024 17:15:34 +0000 Message-Id: <20240104171553.2080674-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181042530018207 X-GMAIL-MSGID: 1787181042530018207 The Energy Model (EM) is going to support runtime modification. There are going to be 2 EM tables which store information. This patch aims to prepare the code to be generic and use one of the tables. The function will no longer get a pointer to 'struct em_perf_domain' (the EM) but instead a pointer to 'struct em_perf_state' (which is one of the EM's tables). Prepare em_pd_get_efficient_state() for the upcoming changes and make it possible to be re-used. Return an index for the best performance state for a given EM table. The function arguments that are introduced should allow to work on different performance state arrays. The caller of em_pd_get_efficient_state() should be able to use the index either on the default or the modifiable EM table. Reviewed-by: Daniel Lezcano Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 88d91e087471..1dcd1645dde7 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -175,33 +175,35 @@ void em_dev_unregister_perf_domain(struct device *dev); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM - * @pd : Performance domain for which we want an efficient frequency - * @freq : Frequency to map with the EM + * @table: List of performance states, in ascending order + * @nr_perf_states: Number of performance states + * @freq: Frequency to map with the EM + * @pd_flags: Performance Domain flags * * It is called from the scheduler code quite frequently and as a consequence * doesn't implement any check. * - * Return: An efficient performance state, high enough to meet @freq + * Return: An efficient performance state id, high enough to meet @freq * requirement. */ -static inline -struct em_perf_state *em_pd_get_efficient_state(struct em_perf_domain *pd, - unsigned long freq) +static inline int +em_pd_get_efficient_state(struct em_perf_state *table, int nr_perf_states, + unsigned long freq, unsigned long pd_flags) { struct em_perf_state *ps; int i; - for (i = 0; i < pd->nr_perf_states; i++) { - ps = &pd->table[i]; + for (i = 0; i < nr_perf_states; i++) { + ps = &table[i]; if (ps->frequency >= freq) { - if (pd->flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && + if (pd_flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && ps->flags & EM_PERF_STATE_INEFFICIENT) continue; - break; + return i; } } - return ps; + return nr_perf_states - 1; } /** @@ -226,7 +228,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, { unsigned long freq, ref_freq, scale_cpu; struct em_perf_state *ps; - int cpu; + int cpu, i; if (!sum_util) return 0; @@ -250,7 +252,9 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * Find the lowest performance state of the Energy Model above the * requested frequency. */ - ps = em_pd_get_efficient_state(pd, freq); + i = em_pd_get_efficient_state(pd->table, pd->nr_perf_states, freq, + pd->flags); + ps = &pd->table[i]; /* * The capacity of a CPU in the domain at the performance state (ps) From patchwork Thu Jan 4 17:15:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185092 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5747587dyb; Thu, 4 Jan 2024 09:17:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlgC1IC8ns8BDrFNM/wWAEwNEN8wKsn3h/wkNqjSAQWYb4HqzNl0UL87/yGVsbKfFlA+m0 X-Received: by 2002:a05:6122:30a0:b0:4b6:c109:5b46 with SMTP id cd32-20020a05612230a000b004b6c1095b46mr925677vkb.7.1704388673185; Thu, 04 Jan 2024 09:17:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388673; cv=none; d=google.com; s=arc-20160816; b=nj3c1e2yhyMaFXFjbT56B/20D7hi+zDJQmqEO8bjXQBaNdremF0Mm2JCuQlNZQUEax G5tWC5kvhgKpcCC0E7t9VGs96FsYlyoVGgdyefHJ3AOHiuN2p6xFcIdL8FNCo9s4Lhzq lTPooE9Lg9J1D1nYQFauA2PC0egYn4sJk48TmBeb0+STFJ1mW4hAcnCSHOb984dShOqG 2UIrGKBDnSEpiBw2n/OtN2ibRGr2TZf64idHmrn43x5SpTX7sURYqFjotraVp1NXA+79 Rec0gLRmMqG4LPXNkmBlYYS5iekp0weelT533XxB6UfGAf99jknm8GY9xccxt1jtel55 g8Zg== ARC-Message-Signature: i=1; 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=+vNdGSrJXMSHlpsEzY6qXG3SFCKPDLNddytqE2e+UDk=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=c1XMFb8LUNtX0EFw4wAB4LeGwlthAEveQNCetPbOG+NhQFM5KZ4iCegFq8JeWpNKOt ByEamygmFRCA9uY5qhsba4wgsRScvbJBdtVvy9kZxJ+fs1dIWIkqt1NjmsuDoGoNTBt7 Iw+N1JJMGwE5jn7cn583vdLW7WuoewlTKh0WQP4W4pALBI1lBppVu7jc10co97YuVs2K BtTkhaiME+gZibF1gikAQetcZ9mbyPGdYjHRLTO84Nh2ieM4gqyf1qX67AXCn1dIPnD3 kM54P3CapXFfyCzBKHbbbZu/PfyXFwXINX6EIr3Cmc6Liup1SBT87ub5Kvttpa2nD7ca oy6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17008-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17008-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v63-20020a1f4842000000b004b7642e775csi2349178vka.256.2024.01.04.09.17.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:17:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17008-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17008-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17008-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 F164E1C241BE for ; Thu, 4 Jan 2024 17:17:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39CCA2C699; Thu, 4 Jan 2024 17:15:07 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5ADB92C1B6; Thu, 4 Jan 2024 17:15:04 +0000 (UTC) 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 80BD11007; Thu, 4 Jan 2024 09:15:49 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0B2C83F64C; Thu, 4 Jan 2024 09:15: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 Subject: [PATCH v6 05/23] PM: EM: Refactor a new function em_compute_costs() Date: Thu, 4 Jan 2024 17:15:35 +0000 Message-Id: <20240104171553.2080674-6-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181057224010638 X-GMAIL-MSGID: 1787181057224010638 Refactor a dedicated function which will be easier to maintain and re-use in future. The upcoming changes for the modifiable EM perf_state table will use it (instead of duplicating the code). 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 Thu Jan 4 17:15:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185095 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5748279dyb; Thu, 4 Jan 2024 09:19:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSITuri+mKxSulBRZmUw5pWxoCgA/ne89NdPvU09F8N7g3asdXYj6GJ2k2QjfHrT/LXP87 X-Received: by 2002:a05:6a00:38ca:b0:6d9:9984:66d9 with SMTP id ey10-20020a056a0038ca00b006d9998466d9mr668747pfb.37.1704388748247; Thu, 04 Jan 2024 09:19:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388748; cv=none; d=google.com; s=arc-20160816; b=NKFCXCP/f3uOe/8CwilIeY4QjxFR7YxDGeYtThL0MgJhPYbuLeOlLFH6/DWFE0ac8P eUqkSVk1xiXOi1qRE+ajIsy0SZXakfOzWiU8EunEelm8JHhqX86Vmr/VLADLx/RigOBY rxCS5WgJuIxJfR/zMHfvEzM6+kJHf5rGDlZz/bIw81v4P85afevV+eCKKU4QpL76z5Gd cjOVQpmPc5JKIhB7o5JxunCqDocy6lchro2kWpHPso6I9IZsEihCr4et90OlA0O9vjb5 MlEypaGFW/oNCHdoHlsY8/NgUuvA2s10XNRS6GcunM6aH/71juGBHPV3bF9VsD1uMB3y VNkA== ARC-Message-Signature: i=1; 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=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=sNWq/IpUmt5aKiJlVhxdrOcBb+i3ZslB5hCiqL5pGwQ2TGYoauuzZO+OEW2wVKyVP0 0JbcddqXgwCt0VwJKVvcQguZJ+FUhI/9UdZ9xXFiGoTzmWVeGIfA/7iJ3OWbtCK+jIu+ PjwYNj9xF5uqORL+KSZEuJ4pLJv0hYlNrKAWHX9eVmXe7zaXOngkHk0lO5jpuTYREBFj 1TQ+yMtmjRzP7tCCzWqjqPrboiSjeaVdbZIcxm2f2BSCHYPZSvIg+IeIhQrA2tgfNunJ HoZFnpApiV59rQO7cvRsJo33FuGajH72vakpwStocNeLI/VkAQhYDPm45aUNQmI2js0w PiZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17010-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17010-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 h33-20020a63f921000000b005b93bfe91f3si24190394pgi.577.2024.01.04.09.19.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:19:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17010-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; spf=pass (google.com: domain of linux-kernel+bounces-17010-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17010-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 DE805B24A02 for ; Thu, 4 Jan 2024 17:18:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2AE52C861; Thu, 4 Jan 2024 17:15:13 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1CE92C845; Thu, 4 Jan 2024 17:15:09 +0000 (UTC) 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 2FA671576; Thu, 4 Jan 2024 09:15:55 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B4D483F64C; Thu, 4 Jan 2024 09:15:06 -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 Subject: [PATCH v6 07/23] PM: EM: Refactor how the EM table is allocated and populated Date: Thu, 4 Jan 2024 17:15:37 +0000 Message-Id: <20240104171553.2080674-8-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181135942514662 X-GMAIL-MSGID: 1787181135942514662 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 Thu Jan 4 17:15:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185093 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5748023dyb; Thu, 4 Jan 2024 09:18:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkNv+l96yiVDWcdlwoelfxq/l7Ci8BRy0C9podGTFTk2WUBonxW+iXLohFaH4AJDM/Zx3l X-Received: by 2002:a05:6808:e8a:b0:3bb:ebb4:76f2 with SMTP id k10-20020a0568080e8a00b003bbebb476f2mr842359oil.82.1704388716532; Thu, 04 Jan 2024 09:18:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388716; cv=none; d=google.com; s=arc-20160816; b=VoZ9JdN2DoqaZ8rcEGJSCrl3ZGcaSYHuyHbkjOiZSATF+sVUtIEQcJRPcf49Ix0XBO Nh3oyfn6a81bZg4jwdgb4zNZOOyBUoY07xsDERwAeZ2LHV2jaIai152Rbs9YIRskVde8 0Bp6B95O8nQLiBPNPAjEgFORdmvWDhcxbOXY98MqVFGxYhviggBbr1mn6yA8sWxHpxQs ruaPP5tRvnvHgHsmWtuqRip8lnZ36QKLcSo9khcNAI8p6NJkb0n++JUsMqDzs6n8laUU Eo2Z10ZsoHAdXBLB9mL2X7iIYfbWj4uG/VrWg+bKzuqwbPmgzKSMXpltCLes0g3cwuUj qhBQ== ARC-Message-Signature: i=1; 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=NXKRBbbvCN0JzEavSY61+S6KivMFZURvxPMRohANe14=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=s3+lC2EMurZ8c/HxhjMxNKpjx3mtZTGa6+jsZDD1LvPwxEJ5egYtpIlyHgEfb9MiYG fabn2AK3zpzoRRc16JfIgLhwb56FdDYGnVi0Kr5R/89wC/c3c8EH3/12WWIMjIUNKrOv u/QnYiBnwNRQhHOv0K8bB5oZAmw/ldkNj37puHpk+vIY1c/Jkrr5KGVnvX55y5HdLrOi gQNRLtoGhSGSOOY+LXMW53B/IoTkKSp6/8MQw1RfhTCBr7cq5/8Dzgz1uLUrMtRWsLj/ IAIujsuzpi0jfsb5xggSiaqVa6TSp8xFZ3OtgVG3Rxq/ptaZfmT8kmY8S2OzSkuDAuKV Gl2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17011-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17011-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g16-20020ac85d50000000b00423b3c0a8c2si32875793qtx.581.2024.01.04.09.18.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:18:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17011-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17011-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17011-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 51E241C223A5 for ; Thu, 4 Jan 2024 17:18:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B3B82D04D; Thu, 4 Jan 2024 17:15:15 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68A782C843; Thu, 4 Jan 2024 17:15:12 +0000 (UTC) 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 0024D1595; Thu, 4 Jan 2024 09:15:58 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8A9773F64C; Thu, 4 Jan 2024 09:15:09 -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 Subject: [PATCH v6 08/23] PM: EM: Introduce runtime modifiable table Date: Thu, 4 Jan 2024 17:15:38 +0000 Message-Id: <20240104171553.2080674-9-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181102612963491 X-GMAIL-MSGID: 1787181102612963491 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 1dcd1645dde7..8ddf1d8a9581 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 Thu Jan 4 17:15:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185094 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5748133dyb; Thu, 4 Jan 2024 09:18:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHuonaomhJ0m6No7OuFRLTvErLnTOoPd0IXcoumODyRUFDayRYPpCJ3tHswBa9T3lftUPDU X-Received: by 2002:a05:6870:7883:b0:203:c580:c51d with SMTP id hc3-20020a056870788300b00203c580c51dmr1038096oab.84.1704388730932; Thu, 04 Jan 2024 09:18:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388730; cv=none; d=google.com; s=arc-20160816; b=nZBZgAOr1RQ0BJq0F8rv8A9smEtpQmw15u+y/vX4dk4R0MjQ/nHEdHfsRlWEVrM6qS jLltYY4AK/L/j11m3iIBPmpxCRCAamK5qBQHJBp1GPTvxLz8qiyr5qH+IWS395FzRFGG WlXlg5yCVhENbRhNKshy7UHZGxI17zHuqv4/+1HCiphRobjejyLKxCioKGdJ/n4DY761 C29Tak7r55CZy/eShdec1udZO4VCWj184MZQ79Y+iGBscZOc2VmwA3n7UFtxZdKbiCkv 2VgXaoesGyJd2nNbuUHPleYxyY30D6tLOM0FQEDe6OieG5/2nWgnsltRgj5gJx4Ag+ON QvuA== ARC-Message-Signature: i=1; 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=z9JKC41T07MJsYasfrWLWMGJ7gBKZ1zK3m32VMt9k9c=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=i+kOQpzIFsdJdHywBtlrjyz3TIDVRjtIS3zM8mWGKBx3Wl0wwljWQF45b01vSrAZ++ FTy595tlk3j2ISq82n2imirPGJdlTzSKsoWbMuzd1llJWrUiGoG4Vf9KRo3XwpfCQkqQ idzMsF4N5uQoueKYCUJGAhkQF0SkK29zyDWO6s7+HkK8JOaQEL7h0URRv7zj/uL/Yo3m TAHCxAZBsrmo0yecyqGbicGx4AsKUFApYN1eC/zwr0yNWee4YXZOReQq11nzWDKaJrmn 9gGzxRqlaWRKcxYyE4wI5V30r3BzQqySmTkwPp7tCcE1ef+2Tu0sRtUiEQ7U76E2uvnS lcmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17012-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17012-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i20-20020a05620a249400b00781eb9c1c7dsi3215744qkn.77.2024.01.04.09.18.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:18:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17012-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17012-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17012-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 B56BC1C2411D for ; Thu, 4 Jan 2024 17:18:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA26B2DF98; Thu, 4 Jan 2024 17:15:17 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D5FE2CCC4; Thu, 4 Jan 2024 17:15:15 +0000 (UTC) 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 C414E1570; Thu, 4 Jan 2024 09:16:00 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5BF843F64C; Thu, 4 Jan 2024 09:15:12 -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 Subject: [PATCH v6 09/23] PM: EM: Use runtime modified EM for CPUs energy estimation in EAS Date: Thu, 4 Jan 2024 17:15:39 +0000 Message-Id: <20240104171553.2080674-10-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181118186030775 X-GMAIL-MSGID: 1787181118186030775 The new Energy Model (EM) supports runtime modification of the performance state table to better model the power used by the SoC. Use this new feature to improve energy estimation and therefore task placement in Energy Aware Scheduler (EAS). Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 8ddf1d8a9581..5f842da3bb0c 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -239,9 +239,14 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, unsigned long allowed_cpu_cap) { unsigned long freq, ref_freq, scale_cpu; + struct em_perf_table *em_table; struct em_perf_state *ps; int cpu, i; +#ifdef CONFIG_SCHED_DEBUG + WARN_ONCE(!rcu_read_lock_held(), "EM: rcu read lock needed\n"); +#endif + if (!sum_util) return 0; @@ -264,9 +269,10 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * Find the lowest performance state of the Energy Model above the * requested frequency. */ - i = em_pd_get_efficient_state(pd->table, pd->nr_perf_states, freq, - pd->flags); - ps = &pd->table[i]; + em_table = rcu_dereference(pd->em_table); + i = em_pd_get_efficient_state(em_table->state, pd->nr_perf_states, + freq, pd->flags); + ps = &em_table->state[i]; /* * The capacity of a CPU in the domain at the performance state (ps) From patchwork Thu Jan 4 17:15:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185096 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5748668dyb; Thu, 4 Jan 2024 09:19:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjgP5TWONGGjKysKEySE4QvTmNDmSAb93GUafLPagQyDpnr/SBxhVzZAsY03w/vIEf8430 X-Received: by 2002:a05:6830:ec4:b0:6dc:2549:3e6c with SMTP id dq4-20020a0568300ec400b006dc25493e6cmr958734otb.15.1704388788874; Thu, 04 Jan 2024 09:19:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388788; cv=none; d=google.com; s=arc-20160816; b=aDgOVpnRecR2z/0/bGMqayHATDgwdgvCvzBe2OLpqhtSZYNWLbxLqMJGLVdGrN2P0/ 3VVD2XbFkqNRe+FZW3nlMJb/1GsbQIBRYhvFxgxNapTNCmqqJHvyESrhSNaOgABzIBou tZrN3VaYP5PoVTBy1YeWYJy8CvnKBJUuuO/O/o/MHXrT66c4uVW5QOFAhBGrL7KK2cdm d9OXNpAc5iPQgA7E2S8lBqBrWqmqXC/O9ofmoCsJRpVpx9Bzf/y5J1eE7mV7cS4G5l7H GmrFfUeBjHXHqjxyzj7K3vp8oVfRYje2LQyBfUq2EvOAZHAuV061al9fZAUvTiI7Yeaa ypZg== ARC-Message-Signature: i=1; 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=AwIdrfrsN6FU1d3SnWby5u6EgblUdTBHu8gsXIjugcc=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=i8kODrOhjkgtADLimT6aHFYDf+xv4Jg190wbLTQ85sVMbVZqUg8ar6jDwHvCsyLGOI iNfXzx2I4loadXEl4+VtPUOTt8ZGEYzXqbioFic9/62u29JfDNEVu7B3CFZqmK/IJGw+ 5A7fWsRFAlQ/U7aK/BE132aWVgped3zN4AzEi4GpCKWaS/z94N7Z94dowrn9tW4vPbPk nzFqrNGkmbI9kk0nNJvGKSrfnePtpt/ukjzuVTXq7hdvaTqgU0zaYe2b/JSf1Zlr4WdU PXqBKeMpMYs8AXDh06d0S/bHi8/ZcRdo5bcTCo1HjmQByQRNL6KuONDEBoK363vs2qZ+ c9pg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17016-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17016-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m4-20020a05620a24c400b00783040f4afcsi1162312qkn.551.2024.01.04.09.19.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:19:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17016-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17016-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17016-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 A73FF1C2426A for ; Thu, 4 Jan 2024 17:19:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF6412E829; Thu, 4 Jan 2024 17:15:26 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A41DE2E629; Thu, 4 Jan 2024 17:15:23 +0000 (UTC) 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 3D0271007; Thu, 4 Jan 2024 09:16:09 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BDE523F64C; Thu, 4 Jan 2024 09:15:20 -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 Subject: [PATCH v6 12/23] PM: EM: Add helpers to read under RCU lock the EM table Date: Thu, 4 Jan 2024 17:15:42 +0000 Message-Id: <20240104171553.2080674-13-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181178927878622 X-GMAIL-MSGID: 1787181178927878622 To use the runtime modifiable EM table there is a need to use RCU read locking properly. Add helper functions for the device drivers and frameworks to make sure it's done properly. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index f33257ed83fd..cfaf5d8b1aad 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -338,6 +338,20 @@ static inline int em_pd_nr_perf_states(struct em_perf_domain *pd) return pd->nr_perf_states; } +static inline struct em_perf_state *em_get_table(struct em_perf_domain *pd) +{ + struct em_perf_table __rcu *table; + + rcu_read_lock(); + table = rcu_dereference(pd->em_table); + return table->state; +} + +static inline void em_put_table(void) +{ + rcu_read_unlock(); +} + #else struct em_data_callback {}; #define EM_ADV_DATA_CB(_active_power_cb, _cost_cb) { } @@ -384,6 +398,11 @@ int em_dev_update_perf_domain(struct device *dev, { return -EINVAL; } +static inline struct em_perf_state *em_get_table(struct em_perf_domain *pd) +{ + return NULL; +} +static inline void em_put_table(void) {} #endif #endif From patchwork Thu Jan 4 17:15:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185101 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5750213dyb; Thu, 4 Jan 2024 09:22:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFuJPAu3Gv+ntL8BcDu40pjLzL2qeiVhUAMfipU8bBlwOOqa+qIS2NjtAM8R7fv8ZGianS5 X-Received: by 2002:a05:6a20:840a:b0:196:d045:9d9c with SMTP id c10-20020a056a20840a00b00196d0459d9cmr892256pzd.50.1704388940502; Thu, 04 Jan 2024 09:22:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388940; cv=none; d=google.com; s=arc-20160816; b=KDlAbARSrRbFQZpPceuP2DAG7Kpu8TCS5+KGS+u1HHRFp16t4oXCls0pjU8SMYpfm1 WnHURjZstw5mUZ3n1kHo9LiurLRBW74Vywnl8NYttmFiwq2yjB8tIR88bZyIYihQb7k2 gQw3+YJHiitACGyFeB2Hi5TZEWmvu3r692hvQ+1HhVd1dcrp7h+wdUnxut0gOgz7Sotu Z5+YKE1XdZ0llnbxWaEDQi2zs86v5WLbgsq6mN8Om4f7u+NlGAAMIHXyJY+ZKsORKNlF NKHVeVj2gq3t9N5W1bmFoOZBt99n35+88un1ForU7Ws/7gg0vCVBQd9RRVEC5c1q65W9 OxUQ== ARC-Message-Signature: i=1; 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=EhnGOGYkVhSSPNIl6LEicPViZMXWoU0H+gmtlKTuNeg=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=wGwyF18X1cMI2AQO0eoUoRn1ISEedsqA/jRTHp199ow13fgSmbUpjAqlbqieA3GEDn dGex4P+hpOj9Az95EPgK1iVaAxwnf7HcXQU5kLUu54R/Qng0mE2xO1TWDPKATiPCAgGB YOg/Z/9x+r0UkpNYFQaU3VZ6wZlYKHZebFhAFrOHp5OgbBTNQoICfVV9lOG8QKJ4eSSM Xk+ZLN0sDnM8ZVb1ajPgNrHVnp5E0djUrBO2dVF/jj8SvXEvqTnXZKVJg01tkQv7Mf8Q QBaFRkCgUIueHWT/kfomJNjDDQqGp+RNtV6yqeh2SYzL41JMus259I52PYTSC2a/ugOf Ag3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17017-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17017-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 s11-20020a056a00178b00b006d9b9603bd8si17952173pfg.334.2024.01.04.09.22.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:22:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17017-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; spf=pass (google.com: domain of linux-kernel+bounces-17017-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17017-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 799F8B250A6 for ; Thu, 4 Jan 2024 17:20:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54DB62E851; Thu, 4 Jan 2024 17:15:29 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DCE02E657; Thu, 4 Jan 2024 17:15:26 +0000 (UTC) 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 0FC741007; Thu, 4 Jan 2024 09:16:12 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9B3403F64C; Thu, 4 Jan 2024 09:15: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 Subject: [PATCH v6 13/23] PM: EM: Add performance field to struct em_perf_state and optimize Date: Thu, 4 Jan 2024 17:15:43 +0000 Message-Id: <20240104171553.2080674-14-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181337753028042 X-GMAIL-MSGID: 1787181337753028042 The performance doesn't scale linearly with the frequency. Also, it may be different in different workloads. Some CPUs are designed to be particularly good at some applications e.g. images or video processing and other CPUs in different. When those different types of CPUs are combined in one SoC they should be properly modeled to get max of the HW in Energy Aware Scheduler (EAS). The Energy Model (EM) provides the power vs. performance curves to the EAS, but assumes the CPUs capacity is fixed and scales linearly with the frequency. This patch allows to adjust the curve on the 'performance' axis as well. Code speed optimization: Removing map_util_freq() allows to avoid one division and one multiplication operations from the EAS hot code path. Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 20 ++++++++++---------- kernel/power/energy_model.c | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index cfaf5d8b1aad..8abdf3119afd 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -13,6 +13,7 @@ /** * struct em_perf_state - Performance state of a performance domain + * @performance: CPU performance (capacity) at a given frequency * @frequency: The frequency in KHz, for consistency with CPUFreq * @power: The power consumed at this level (by 1 CPU or by a registered * device). It can be a total power: static and dynamic. @@ -21,6 +22,7 @@ * @flags: see "em_perf_state flags" description below. */ struct em_perf_state { + unsigned long performance; unsigned long frequency; unsigned long power; unsigned long cost; @@ -207,14 +209,14 @@ void em_free_table(struct em_perf_table __rcu *table); */ static inline int em_pd_get_efficient_state(struct em_perf_state *table, int nr_perf_states, - unsigned long freq, unsigned long pd_flags) + unsigned long max_util, unsigned long pd_flags) { struct em_perf_state *ps; int i; for (i = 0; i < nr_perf_states; i++) { ps = &table[i]; - if (ps->frequency >= freq) { + if (ps->performance >= max_util) { if (pd_flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && ps->flags & EM_PERF_STATE_INEFFICIENT) continue; @@ -245,9 +247,9 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, unsigned long max_util, unsigned long sum_util, unsigned long allowed_cpu_cap) { - unsigned long freq, ref_freq, scale_cpu; struct em_perf_table *em_table; struct em_perf_state *ps; + unsigned long scale_cpu; int cpu, i; #ifdef CONFIG_SCHED_DEBUG @@ -260,25 +262,23 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, /* * In order to predict the performance state, map the utilization of * the most utilized CPU of the performance domain to a requested - * frequency, like schedutil. Take also into account that the real - * frequency might be set lower (due to thermal capping). Thus, clamp + * performance, like schedutil. Take also into account that the real + * performance might be set lower (due to thermal capping). Thus, clamp * max utilization to the allowed CPU capacity before calculating - * effective frequency. + * effective performance. */ cpu = cpumask_first(to_cpumask(pd->cpus)); scale_cpu = arch_scale_cpu_capacity(cpu); - ref_freq = arch_scale_freq_ref(cpu); max_util = min(max_util, allowed_cpu_cap); - freq = map_util_freq(max_util, ref_freq, scale_cpu); /* * Find the lowest performance state of the Energy Model above the - * requested frequency. + * requested performance. */ em_table = rcu_dereference(pd->em_table); i = em_pd_get_efficient_state(em_table->state, pd->nr_perf_states, - freq, pd->flags); + max_util, pd->flags); ps = &em_table->state[i]; /* diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 496dc00835c6..fac1c82937eb 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -46,6 +46,7 @@ static void em_debug_create_ps(struct em_perf_state *ps, struct dentry *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); } @@ -170,6 +171,30 @@ em_allocate_table(struct em_perf_domain *pd) return table; } +static void em_init_performance(struct device *dev, struct em_perf_domain *pd, + struct em_perf_state *table, int nr_states) +{ + u64 fmax, max_cap; + int i, cpu; + + /* This is needed only for CPUs and EAS skip other devices */ + if (!_is_cpu_device(dev)) + return; + + cpu = cpumask_first(em_span_cpus(pd)); + + /* + * Calculate the performance value for each frequency with + * linear relationship. The final CPU capacity might not be ready at + * boot time, but the EM will be updated a bit later with correct one. + */ + fmax = (u64) table[nr_states - 1].frequency; + max_cap = (u64) arch_scale_cpu_capacity(cpu); + for (i = 0; i < nr_states; i++) + table[i].performance = div64_u64(max_cap * table[i].frequency, + fmax); +} + static int em_compute_costs(struct device *dev, struct em_perf_state *table, struct em_data_callback *cb, int nr_states, unsigned long flags) @@ -326,6 +351,8 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, table[i].frequency = prev_freq = freq; } + em_init_performance(dev, pd, table, nr_states); + ret = em_compute_costs(dev, table, cb, nr_states, flags); if (ret) return -EINVAL; From patchwork Thu Jan 4 17:15:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185097 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5749127dyb; Thu, 4 Jan 2024 09:20:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8qk10Yh1F2d8SIeAkczMGuyjkQdDsJ9FFue++NHudtPecv0x4B/VT/VbfozFHSj5mz6K9 X-Received: by 2002:a05:6359:4c19:b0:174:d950:529 with SMTP id kj25-20020a0563594c1900b00174d9500529mr869810rwc.50.1704388836294; Thu, 04 Jan 2024 09:20:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388836; cv=none; d=google.com; s=arc-20160816; b=c1JidMiVdK8lzJSA/M4qmf8hkbqCL6OfxYJ9l5dq5YHhiNoYDgjM9KsTDNG+6lrkhZ tcR5BrHWDrJsQ/LeYwNa5Ixi4LLi6sS9Avdn+fwPRdtMaTHox7cI0/jzTUA8AiT82Oro u52im2O1CPPQXgA1lAGQG5cv/STjbx8LT8PgCgVwtn5mH/UHuJ1aj5ZzzLhvRyY+hmdQ RRJpVFbYU/8dreaZGQWnAe31Dn7Ca+ZZQEeRaNvnV+B9gG/PKO+rCV60g+qkerqheUcq zFCrh4N3ExU4r6klWJSUoVHLZjNCguz1emg4ri49SIYgLdMUYHTT/pEKKmyuA2gj5608 /hsg== ARC-Message-Signature: i=1; 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=2M9sqruo9+1Rk5RWLPYyfN0VSqGccJr7l6tCOE4PZ0Q=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=J3doOTo491Zxg3wz8gI9wNIq69HR365fNIWrF/590wCIpw35lpbdTaerxbcPDK8MMC yHRqLunZZnCqOq3a5m3Vl3w1/BB1SY/9JRdnVbFgKISyyWH+espMajXao3Nf0p+QNcrm h/fKE91PjNW7vyt09bzt2d57z6sqaQ1XhbfcAx7Awu5LByaaUBT5LOccj6RjaUnqRnvu bDex7hb++R/uJub11FoHHZsB6oeXGu2GkETqZ7/rEorBtHyT13XQ8X/zPc8Mnd+z4DF9 ZzWY0QLWjuG4zGaZLUxLm2VG8+lFs7hnGio3DcnXKfv+GhVMmV7IAnsltNejhW4cmvdx D5yA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17018-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17018-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v6-20020a05622a014600b004283b980396si3279377qtw.431.2024.01.04.09.20.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:20:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17018-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17018-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17018-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 722E51C245EA for ; Thu, 4 Jan 2024 17:20:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5593831728; Thu, 4 Jan 2024 17:15:32 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 77AFC2E857; Thu, 4 Jan 2024 17:15:29 +0000 (UTC) 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 D58E51007; Thu, 4 Jan 2024 09:16:14 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6B5D33F64C; Thu, 4 Jan 2024 09:15: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 Subject: [PATCH v6 14/23] PM: EM: Support late CPUs booting and capacity adjustment Date: Thu, 4 Jan 2024 17:15:44 +0000 Message-Id: <20240104171553.2080674-15-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181228002711519 X-GMAIL-MSGID: 1787181228002711519 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 | 122 ++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index fac1c82937eb..70c41a81286c 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) { @@ -591,6 +594,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); @@ -626,3 +633,118 @@ 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_allocate_table(pd); + if (!em_table) { + dev_warn(dev, "EM: allocation failed\n"); + return; + } + + new_table = em_table->state; + + table = em_get_table(pd); + /* Initialize data based on old table */ + table_size = sizeof(struct em_perf_state) * pd->nr_perf_states; + memcpy(new_table, table, table_size); + + em_put_table(); + + 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_free_table(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); + + table = em_get_table(pd); + em_max_perf = table[pd->nr_perf_states - 1].performance; + em_put_table(); + + /* + * 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 Thu Jan 4 17:15:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5749252dyb; Thu, 4 Jan 2024 09:20:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGksVe39TX82T3+0jlARwa5u0C3+CgUR7ck+KETrrMkXwUoFafE5eSeBBUtOFbBl8wH2Dn X-Received: by 2002:a05:620a:1499:b0:781:ae70:a75c with SMTP id w25-20020a05620a149900b00781ae70a75cmr793270qkj.119.1704388848324; Thu, 04 Jan 2024 09:20:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388848; cv=none; d=google.com; s=arc-20160816; b=0MaodoTnZ/5eBWlulkpgUTE87SWt7pa7xqmS4GWA6Viaw0OHRRfJfqE5Q3mTMWLHQd 1XaMuKQHvmQmVO/0IsP7+5db1BG+zjCBqpAM3gPGPqbXD4izjNoSa1fsAItoD1AkTrRj zSye9sWTp3k/DLUz1OMl47lTyfQDpDNtl6cBGtwdB6BOcc1+vi/3LGgEiqkk8NODoW4I cZvWmw+C8ceOvChPS7Tnul4Gu0k4rqnEJ5TVByLEHi8x0+PnJt6b8YHtKonJ3T33cd4K um7wGpleyzn1jml1vco8GgVuh0XnkStZHe+s9XpyLKdt5tf2Xa+k/nUwX5EeUF4i8Eq6 M+3Q== ARC-Message-Signature: i=1; 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=yhqG3M0Lu7d6Ch0z8FzEOWg8INy6fc6RiTJKJktvoSs=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=hscNkJhfB8s5WEdRCzG7kcCK5W0GMthFXl3aQTG0lDBh59uVcQpetCUbOnseWnXYVi UJ/Ezpiqp3nW4KHGvBngu8bmcq7QMxMuU3sjiXvJnTDnm6Z7y17PjXhr4WmPC4diZf6E uQIinOleer9jNpsfh7/Ci6o77f/Zm9z5mKKxxBScEuLghwl24+KfFQSs95iLWCvfgp+I oOeQjk4oYKbQuCP724sgbd3F71uuV1JbnTC2d7ihydpnYJgitHuyUdcsrWsLssmsEhKy lJAwV8Gky4s0ZDIqCp3wY/GFeJo1PT+sMdYgF0wEdlr1DwcwT0B6ESqcQfyLf2G1rkZC rN3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17019-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id br10-20020a05620a460a00b0077fa5437f7fsi33389666qkb.354.2024.01.04.09.20.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:20:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17019-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 4CD631C2104D for ; Thu, 4 Jan 2024 17:20:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 26C2731753; Thu, 4 Jan 2024 17:15:36 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E2C731735; Thu, 4 Jan 2024 17:15:31 +0000 (UTC) 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 84A1E153B; Thu, 4 Jan 2024 09:16:17 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3EAD93F64C; Thu, 4 Jan 2024 09:15: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 Subject: [PATCH v6 15/23] PM: EM: Optimize em_cpu_energy() and remove division Date: Thu, 4 Jan 2024 17:15:45 +0000 Message-Id: <20240104171553.2080674-16-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181241132093493 X-GMAIL-MSGID: 1787181241132093493 The Energy Model (EM) can be modified at runtime which brings new possibilities. The em_cpu_energy() is called by the Energy Aware Scheduler (EAS) in its hot path. The energy calculation uses power value for a given performance state (ps) and the CPU busy time as percentage for that given frequency. It is possible to avoid the division by 'scale_cpu' at runtime, because EM is updated whenever new max capacity CPU is set in the system. Use that feature and do the needed division during the calculation of the coefficient 'ps->cost'. That enhanced 'ps->cost' value can be then just multiplied simply by utilization: pd_nrg = ps->cost * \Sum cpu_util to get the needed energy for whole Performance Domain (PD). With this optimization and earlier removal of map_util_freq(), the em_cpu_energy() should run faster on the Big CPU by 1.43x and on the Little CPU by 1.69x (RockPi 4B board). Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 54 ++++++++++-------------------------- kernel/power/energy_model.c | 7 ++--- 2 files changed, 17 insertions(+), 44 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 8abdf3119afd..4a39825d3479 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 = min(max_util, allowed_cpu_cap); /* @@ -282,12 +257,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 @@ -295,9 +270,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 @@ -307,9 +283,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'. @@ -319,11 +295,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 70c41a81286c..0fa98fa7dbec 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -203,11 +203,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; @@ -219,8 +217,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 Thu Jan 4 17:15:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185099 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5749486dyb; Thu, 4 Jan 2024 09:21:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCtu9bjxyxasId9i5mTLRcKUb2TuKvYd39RTjmDRsin+q/qkfBhwLVFFGAf11wp/GPMA1C X-Received: by 2002:a17:906:1c9:b0:a26:8c3a:5133 with SMTP id 9-20020a17090601c900b00a268c3a5133mr535210ejj.99.1704388870216; Thu, 04 Jan 2024 09:21:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388870; cv=none; d=google.com; s=arc-20160816; b=oHQE/486EC1A0GJZtBc2EFh2b9ZVAhfJvUSpKa7zUbpHRS02HVTk3UyXdgSsJkz2cy L4T2aiL6n1c4euP3pTC6BBzpwPKLG9gl2ZVKaJduPsNXuQHDpkHr+7Itftrs+QYG2HNA zMBP2GwxPvMyWKEprBDf5y8NqMV2YWyApfKHkITvIJcG2sb3stHX6Mft0/6D3EMX8zKz Sn72oaeRba1k/dUp5cSkVGZWk8RHn7VTXJ9rZWNf4omKfNDu7F23cjTCjeEInBYKVm9N E4F2JKpH4iGsGXo1f2FW/hCq3HktOLJQV7yhdKiF5ZwMBTHXn4dXo0ZlzlOj23GuZbPQ XZXQ== ARC-Message-Signature: i=1; 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=aQtCQn3+yeI8RbgkrYpX1oP2V2ok3pdrsZ5adnU+zr4=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=kppz5qJx/SM7xzRWQKKpfp/730kjLONcH/yeh2HKcubHUM/o5VsJ4zlPf27xt/nFIK X8Uyk4J44Ob7yP5dysWjZke0X269QgYzhmIZ2rFmjwhyQYhR5PzviG0MMdBtFVNGgLps HpG4olT8OiplPjFE0xBAtAsZD2dQRaoHGpMvth8+e4eZe3xnXSyIohtUlSeJ9ZilE1Jg 4KgoLJs5ioIw0WTeL1VQ3CzxPQ9p8xVUWuzImVIpAxQ6pylETz3E9mMuIcaTJ/kriA3b 1EMhwzNR9JTkEpYyRAld7N1wC1LRKr45RSbAK2ziBjUq97plwDs6lawmUWBGegKoUCbo ne/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17020-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17020-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 c18-20020a1709060fd200b00a2318cb9d9bsi12307975ejk.750.2024.01.04.09.21.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:21:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17020-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; spf=pass (google.com: domain of linux-kernel+bounces-17020-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17020-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 894911F257D5 for ; Thu, 4 Jan 2024 17:21:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96BEC32186; Thu, 4 Jan 2024 17:15:37 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B957025577; Thu, 4 Jan 2024 17:15:34 +0000 (UTC) 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 542341570; Thu, 4 Jan 2024 09:16:20 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E088B3F64C; Thu, 4 Jan 2024 09:15:31 -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 Subject: [PATCH v6 16/23] powercap/dtpm_cpu: Use new Energy Model interface to get table Date: Thu, 4 Jan 2024 17:15:46 +0000 Message-Id: <20240104171553.2080674-17-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181264128558409 X-GMAIL-MSGID: 1787181264128558409 Energy Model framework support modifications at runtime of the power values. Use the new EM table API which is protected with RCU. Align the code so that this RCU read section is short. This change is not expected to alter the general functionality. Signed-off-by: Lukasz Luba --- drivers/powercap/dtpm_cpu.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c index 9193c3b8edeb..aac278e162d9 100644 --- a/drivers/powercap/dtpm_cpu.c +++ b/drivers/powercap/dtpm_cpu.c @@ -42,6 +42,7 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit) { struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm); struct em_perf_domain *pd = em_cpu_get(dtpm_cpu->cpu); + struct em_perf_state *table; struct cpumask cpus; unsigned long freq; u64 power; @@ -50,20 +51,21 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit) cpumask_and(&cpus, cpu_online_mask, to_cpumask(pd->cpus)); nr_cpus = cpumask_weight(&cpus); + table = em_get_table(pd); for (i = 0; i < pd->nr_perf_states; i++) { - power = pd->table[i].power * nr_cpus; + power = table[i].power * nr_cpus; if (power > power_limit) break; } - freq = pd->table[i - 1].frequency; + freq = table[i - 1].frequency; + power_limit = table[i - 1].power * nr_cpus; + em_put_table(); freq_qos_update_request(&dtpm_cpu->qos_req, freq); - power_limit = pd->table[i - 1].power * nr_cpus; - return power_limit; } @@ -87,9 +89,11 @@ static u64 scale_pd_power_uw(struct cpumask *pd_mask, u64 power) static u64 get_pd_power_uw(struct dtpm *dtpm) { struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm); + struct em_perf_state *table; struct em_perf_domain *pd; struct cpumask *pd_mask; unsigned long freq; + u64 power = 0; int i; pd = em_cpu_get(dtpm_cpu->cpu); @@ -98,33 +102,41 @@ static u64 get_pd_power_uw(struct dtpm *dtpm) freq = cpufreq_quick_get(dtpm_cpu->cpu); + table = em_get_table(pd); for (i = 0; i < pd->nr_perf_states; i++) { - if (pd->table[i].frequency < freq) + if (table[i].frequency < freq) continue; - return scale_pd_power_uw(pd_mask, pd->table[i].power); + power = scale_pd_power_uw(pd_mask, table[i].power); + break; } + em_put_table(); - return 0; + return power; } static int update_pd_power_uw(struct dtpm *dtpm) { struct dtpm_cpu *dtpm_cpu = to_dtpm_cpu(dtpm); struct em_perf_domain *em = em_cpu_get(dtpm_cpu->cpu); + struct em_perf_state *table; struct cpumask cpus; int nr_cpus; cpumask_and(&cpus, cpu_online_mask, to_cpumask(em->cpus)); nr_cpus = cpumask_weight(&cpus); - dtpm->power_min = em->table[0].power; + table = em_get_table(em); + + dtpm->power_min = table[0].power; dtpm->power_min *= nr_cpus; - dtpm->power_max = em->table[em->nr_perf_states - 1].power; + dtpm->power_max = table[em->nr_perf_states - 1].power; dtpm->power_max *= nr_cpus; + em_put_table(); + return 0; } @@ -180,6 +192,7 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent) { struct dtpm_cpu *dtpm_cpu; struct cpufreq_policy *policy; + struct em_perf_state *table; struct em_perf_domain *pd; char name[CPUFREQ_NAME_LEN]; int ret = -ENOMEM; @@ -216,9 +229,11 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent) if (ret) goto out_kfree_dtpm_cpu; + table = em_get_table(pd); ret = freq_qos_add_request(&policy->constraints, &dtpm_cpu->qos_req, FREQ_QOS_MAX, - pd->table[pd->nr_perf_states - 1].frequency); + table[pd->nr_perf_states - 1].frequency); + em_put_table(); if (ret) goto out_dtpm_unregister; From patchwork Thu Jan 4 17:15:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185100 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5750111dyb; Thu, 4 Jan 2024 09:22:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9btNI+eXCwJ3AXGN7XhhitKHEly8MNe64N2cYWuB/O7wLXpkW7nkFsetfYQA8J/dsZHPU X-Received: by 2002:a62:b40e:0:b0:6d9:c70e:acd3 with SMTP id h14-20020a62b40e000000b006d9c70eacd3mr755142pfn.39.1704388930334; Thu, 04 Jan 2024 09:22:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388930; cv=none; d=google.com; s=arc-20160816; b=Jq0wLyfr5x03+OQi5Qx2XvLzroCkQGLOZiPENXDbX8bMmru6sjiLqfne6xqkFPZA7g fo8YRbUP6oWhXBhkbO5wvWZb3YKSFbhbv7948BePsIXKPgMkjQHWR/cWFKMoeOaTFqdH XJzZFVsutvepKCa/4azXZevqjd7fwJ1zRZBI5Pf8iwo/ZXCtRnBmeU/0BbmnE5E0JrKm 4OX3kxVJ2JUXOa9PFG/+GDBJ3GEvB89+yFdvI4kw+7DK1wjIlSetcasaYwQLNOGMhUT9 dh2ryhqT4uYHNSXlwRiEt4lRNELFVdnGCvWkyWfO4Owuf048awni79S2ns0Mpsb48oH8 5buw== ARC-Message-Signature: i=1; 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=LpZWfHg6TdrAV5vW1mDNzjuI9CX3yzMjilOisha+2ro=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=pSot8qZGwwVzYjmiyGwgc6GxH4T3ntamy8HBuaaonkU4FCAWhORj87Rg+QLdEIXXde 4WObi36v7t7Vsm1I9LYled2DKo3dg5k4mGgm8iuFb+tjoWln/0dgTKzkW9hxQCEW/8dM 2iQqX81bMmDhBEj+VYzlllh0Kn68s57kCMXKrcqbu6sbs8EdblGVMxIN4ea9Y9cWKKUQ w74SHprLLMjq0MVpIn5QJurRjWdudp1fJFzjZRlhVQg+oFArKputUT4YsIm4mMsYyjWM hCrmOiQFgsbB8+dDCiIqSezbL0NM2BgDkmyB0EnWvUR1u6+2AaFyLMzcri8HywnMYc59 SRwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17024-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17024-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 s10-20020a632c0a000000b005cdfa6ec016si20705838pgs.535.2024.01.04.09.22.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:22:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17024-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; spf=pass (google.com: domain of linux-kernel+bounces-17024-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17024-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 214F5281581 for ; Thu, 4 Jan 2024 17:22:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06AF435288; Thu, 4 Jan 2024 17:15:49 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3AE8034CEA; Thu, 4 Jan 2024 17:15:45 +0000 (UTC) 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 8886B1007; Thu, 4 Jan 2024 09:16:31 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1F6A63F64C; Thu, 4 Jan 2024 09:15:42 -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 Subject: [PATCH v6 20/23] PM: EM: Change debugfs configuration to use runtime EM table data Date: Thu, 4 Jan 2024 17:15:50 +0000 Message-Id: <20240104171553.2080674-21-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181327158417099 X-GMAIL-MSGID: 1787181327158417099 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 | 65 ++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 0fa98fa7dbec..1257b8fea9fc 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -37,20 +37,63 @@ 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; \ + \ + table = em_get_table(em_dbg->pd); \ + val = table[em_dbg->ps_id].name; \ + em_put_table(); \ + \ + 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; + + table = em_get_table(em_pd); + freq = table[i].frequency; + em_put_table(); + + 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 +116,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 +130,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 Thu Jan 4 17:15:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185102 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5750270dyb; Thu, 4 Jan 2024 09:22:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5NomZdu8uN4gEuwYhCgsCC5LccuL9x++ABm9l8dTqshiwJs4TgTM/Omvh5PWmi22HwdUn X-Received: by 2002:a05:622a:1808:b0:427:88c0:14f7 with SMTP id t8-20020a05622a180800b0042788c014f7mr969244qtc.77.1704388948245; Thu, 04 Jan 2024 09:22:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388948; cv=none; d=google.com; s=arc-20160816; b=ZDfLioHS2uph+Uerb0h+VmBavEFoMTd3VucaEgYxZcNl23i136Uq2Ycvqz/ipY7a3h Qmvo6cyK9pRFz2igBjyBNCShAraVeuc5FYY624/IQWi/Z+XmBTyvCDLDG3+Dync6pcxz gX70q6LMUImX/CjEbKQgToVQ4C10gSVDlnloj+XE8RM89qRQ51cVaevhnhsVVmu+n6R9 mZLuG7PsDvvqA/fBQjsyOUXiUDs14lczikpZxgalYB0/YGsCeUKWDGxxcApX3gDx1ySL TM2ars2jKsUp4puxUIkIMq3bpqKzexkxEQA70gODDap78u3kBwUOINOQGRxU4cil5eVl AcyQ== ARC-Message-Signature: i=1; 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=k0hSUuzN4uWNFFmvuMt/zadkXlXdjD4z2VM0n86RB6g=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=amq4EHAwEvaDzbjbVE5eYDH7jOc6zJBEWRpoA6w8iofQWv7WKMQe8Tc3oP04CMe3jw gpIh+/ABfaPLVY719BIOdSnmo5oSsLgujTGYb9vs+jhicnLnLlSG6/hyl1U5PVxlpV7T ehp77ganDlkf8mmWsvccwFBmfGMpAPSui/oRqZKYCBuJFt3VCWhTpU2kPPnhgx+TrL48 d5cWJR0inPJQor+5QSsajKOefAK8iVSTx3mNmeCkhPa37Nlu6CjNkrPlE2aJvCR9ENUM biAP2vH6AxiDuTcsiCjt6dqV/2xGMegau+i2ztM/74ghAyXmUTEMOcSkgaROJ54NFXjv 7RgA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17025-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17025-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g16-20020ac85d50000000b00423b3c0a8c2si32875793qtx.581.2024.01.04.09.22.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:22:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17025-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17025-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17025-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 115E51C20C23 for ; Thu, 4 Jan 2024 17:22:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9CCA035890; Thu, 4 Jan 2024 17:15:51 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BEF4935283; Thu, 4 Jan 2024 17:15:48 +0000 (UTC) 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 579921007; Thu, 4 Jan 2024 09:16:34 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E43673F64C; Thu, 4 Jan 2024 09:15:45 -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 Subject: [PATCH v6 21/23] PM: EM: Remove old table Date: Thu, 4 Jan 2024 17:15:51 +0000 Message-Id: <20240104171553.2080674-22-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181345924057467 X-GMAIL-MSGID: 1787181345924057467 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 4a39825d3479..dd8a69bdf0d0 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 1257b8fea9fc..79877d8975d5 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -285,17 +285,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 @@ -337,24 +326,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_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, @@ -415,6 +386,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; @@ -441,17 +413,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_allocate_table(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) { @@ -464,7 +434,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; @@ -635,7 +605,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"); @@ -672,8 +642,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_free_table(dev->em_pd->em_table); kfree(dev->em_pd); From patchwork Thu Jan 4 17:15:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 185103 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5750426dyb; Thu, 4 Jan 2024 09:22:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFC9cEO7krpdVd+9FpimStyf3Ug4x0tuqF0v4+tGhQDbM7IvnenCZPLczxTziUj26JIn8H4 X-Received: by 2002:a05:6512:3a8d:b0:50e:3e65:5f30 with SMTP id q13-20020a0565123a8d00b0050e3e655f30mr560597lfu.125.1704388966396; Thu, 04 Jan 2024 09:22:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388966; cv=none; d=google.com; s=arc-20160816; b=gxC1YeJmjr2v79AUd1c34JVgJ0HADYx/zrCca+Mwa45FepaAf1a2fBEYpdy25QdOdD mEzDz+PQFVgdfrwE32TpejB9IYFnEmM4VGU2bUGAu8DZP+sOj8/09ISs7toa33r6zPY/ n9Wc7l/9qK+xC9x9PieeYCrFtHJAz23b3XXx43ckSXmwkq2SGZlygCXGMAJ2o4srzQOZ zsLW8Wp12lAtqNj3fxmP4M3ZZNlqnLW6N7iBvXmdSgEf1yLy6NN7OTs8ZNVr+oLeDARw NR82Wx+KBbAYiopUyWCz2ITSyqsxrzT3PTPctruAmythWvRhQJyJNn4yHVPinhyfvySP b7xg== ARC-Message-Signature: i=1; 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=3LcV1qOCqS+SSHawywK0UaPbeyJC+/Uu/xXMyt/SwEg=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=RbtqxMUu+goJP1xJPKvoF7WN2YFDJlU8QR3bQudZVvpnkg2WkavwIdmRafY5LmrT/3 NcGR8QnBoGFA+FO4KUAOvT7TmLkyql7Z1e1c4VVlkq0nSEy2jsEUJSXh0TKqDoL3Ki3E /I8hFRt6MZLkA04aQd+BAWPGg1R+U+JebzYSUQtr8lywQnKqcOGmYNuZOf90/bho/Ulh gLY5gLF3Rdi+0mLnkdUrjCilBE0VjYr39pwamHThvwZ57GKs74xYMZzrR+NtEmlE5JQV B5WiMDzyZ0ALhQbsHSTIpLBXau9B1KdQI7Z8kkFykSUHs0xRuxVS7nyZazKyeDToSjDs u/Vw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17026-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17026-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 wg14-20020a1709078f0e00b00a27a3bcd9d1si4652625ejc.780.2024.01.04.09.22.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:22:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17026-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; spf=pass (google.com: domain of linux-kernel+bounces-17026-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17026-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 016A21F21422 for ; Thu, 4 Jan 2024 17:22:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F90C358B4; Thu, 4 Jan 2024 17:15:54 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85BE13588E; Thu, 4 Jan 2024 17:15:51 +0000 (UTC) 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 282A2153B; Thu, 4 Jan 2024 09:16:37 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B2E583F64C; Thu, 4 Jan 2024 09:15:48 -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 Subject: [PATCH v6 22/23] PM: EM: Add em_dev_compute_costs() as API for device drivers Date: Thu, 4 Jan 2024 17:15:52 +0000 Message-Id: <20240104171553.2080674-23-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181364816477650 X-GMAIL-MSGID: 1787181364816477650 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 dd8a69bdf0d0..f50f3c6ab2e5 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_allocate_table(struct em_perf_domain *pd); void em_free_table(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 @@ -375,6 +377,12 @@ static inline struct em_perf_state *em_get_table(struct em_perf_domain *pd) return NULL; } static inline void em_put_table(void) {} +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 79877d8975d5..7f9337f4ae30 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -285,6 +285,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 Thu Jan 4 17:15: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: 185104 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5750571dyb; Thu, 4 Jan 2024 09:23:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzJjo8/ZIO6X/dRrNu1CzB5N/M9d+JUuVwHQUSNygsDbPbWxRQc2g4wXBFjGJ8d//hRi6n X-Received: by 2002:a05:6a00:8616:b0:6da:c9e8:486f with SMTP id hg22-20020a056a00861600b006dac9e8486fmr651264pfb.3.1704388982800; Thu, 04 Jan 2024 09:23:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704388982; cv=none; d=google.com; s=arc-20160816; b=YFZmi1Y+Ge0h5cLBkm9KdU/JPWM2NOWb0qb/vaILqsrxuymUbxIYi8IopKX9oLSZmn xvCArUa1b8S/87C/bMpzQ22eLA9RkWu6YTPMPM29N4WekZLj6ZpeOdtt8TXBiCmKlY9w LJrbBnOMfIezaxFLR4Y9N8hxv/6jczF9yJ0i2fKXnf/N+Cj3wEQJ/yuYUYTJ0M2Meftk +IlaX6vHl0S0+6OkGkNAsG1upbkleoQzFclpJXOgfb9eWT4QW6ikojd1lV+YrcfaUZ0D 9lo6ATdBGJf/bG5vtmICi9sfld9YKACjkLLDGLUvUSiiOv7jSTlFW52qYqyWKrd8fSCa 93GQ== ARC-Message-Signature: i=1; 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=rmpoh1wnQGSPn/Kilz57uquueuBb+3SIbS4cMEz5PxY=; fh=jF+j1UEDAwnYbShW3HmO1TshMsWh36Jt7pSLTP62NeE=; b=aTjJi7KEY9xINsADgWzb3JEao+2xbp5vbW21z8b0jBn/Gk1NIPvlgzFkUQxDsAa+0A mcHjWU0/cPtaCUDCRwtejeDotYda6AV6GuGkuSBwmcil+ENWXZkLceKmfaHzaI8XTg7c WINFgFi/4ggU+gL080bW0RZMSHcvTxhkteV0izWVJNLuVSM2tMvJ8kgZdNKE+ghB/MhU fPmUuonuWVwu9xShc67fRV+BCrq7UjiMu0jzb9scDtEFZxfX1C4FUFw4oipgdyuCXTbv avS7YBzaeEvdAdo/Rg8b5lCAVMvafu11Wczm9VCzzIYEt06J1sPr56z+dceEfBGXf9dJ 6Zfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17027-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17027-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 a25-20020a62d419000000b006d9aa70878bsi19539100pfh.181.2024.01.04.09.23.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 09:23:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17027-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; spf=pass (google.com: domain of linux-kernel+bounces-17027-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17027-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 8F538283A58 for ; Thu, 4 Jan 2024 17:23:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5AE3835EF3; Thu, 4 Jan 2024 17:15:57 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 575E4358B3; Thu, 4 Jan 2024 17:15:54 +0000 (UTC) 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 EFBFA1007; Thu, 4 Jan 2024 09:16:39 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.88.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 844023F64C; Thu, 4 Jan 2024 09:15:51 -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 Subject: [PATCH v6 23/23] Documentation: EM: Update with runtime modification design Date: Thu, 4 Jan 2024 17:15:53 +0000 Message-Id: <20240104171553.2080674-24-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104171553.2080674-1-lukasz.luba@arm.com> References: <20240104171553.2080674-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: 1787181382327205002 X-GMAIL-MSGID: 1787181382327205002 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..5691d53f9a78 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,83 @@ 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_allocate_table(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_free_table(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_get_table(struct em_perf_domain *pd); + +It returns the 'struct em_perf_state' pointer which is an array of performance +states in ascending order. + +When the EM table is not needed anymore there is a need to call dedicated API:: + void em_put_table(void); -2.4 Description details of this API +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. + +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 4.2 with an example code showing simple implementation of the +updating mechanism in a device driver. + + +2.5 Description details of this API ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. kernel-doc:: include/linux/energy_model.h :internal: @@ -187,8 +285,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 +343,77 @@ 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_allocate_table(pd); + 15 if (!em_table) + 16 return; + 17 + 18 new_table = em_table->state; + 19 + 20 table = em_get_table(pd); + 21 for (i = 0; i < pd->nr_perf_states; i++) { + 22 freq = table[i].frequency; + 23 foo_get_power_perf_values(dev, freq, &new_table[i]); + 24 } + 25 em_put_table(); + 26 + 27 /* Calculate 'cost' values for EAS */ + 28 ret = em_dev_compute_costs(dev, table, pd->nr_perf_states); + 29 if (ret) { + 30 dev_warn(dev, "EM: compute costs failed %d\n", ret); + 31 em_free_table(em_table); + 32 return; + 33 } + 34 + 35 ret = em_dev_update_perf_domain(dev, em_table); + 36 if (ret) { + 37 dev_warn(dev, "EM: update failed %d\n", ret); + 38 em_free_table(em_table); + 39 return; + 40 } + 41 + 42 /* + 43 * Since it's one-time-update drop the usage counter. + 44 * The EM framework will later free the table when needed. + 45 */ + 46 em_free_table(em_table); + 47 } + 48 + 49 /* + 50 * Function called periodically to check the temperature and + 51 * update the EM if needed + 52 */ + 53 static void foo_thermal_em_update(struct foo_context *ctx) + 54 { + 55 struct device *dev = ctx->dev; + 56 int cpu; + 57 + 58 ctx->temperature = foo_get_temp(dev, ctx); + 59 if (ctx->temperature < FOO_EM_UPDATE_TEMP_THRESHOLD) + 60 return; + 61 + 62 foo_get_new_em(ctx); + 63 }