From patchwork Thu Feb 8 11:55: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: 198337 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp109595dyd; Thu, 8 Feb 2024 03:56:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVd2kFV0AGa/4aCqwZ6+NDaQDmiwk/QaJzE4jryoeEsIcwDeYatgM/yamKpLrG+M67olqLm8jVHNouPM00NFJ2xBwLmJA== X-Google-Smtp-Source: AGHT+IF2F+vaS8UjFT37kT0irUuIj5aRUkorp55Pp1wHg+BqM7xm/OBAUPI8He19FyVjrBN7+XiN X-Received: by 2002:ac8:7ca9:0:b0:42b:f020:f36e with SMTP id z9-20020ac87ca9000000b0042bf020f36emr8124285qtv.59.1707393393277; Thu, 08 Feb 2024 03:56:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393393; cv=pass; d=google.com; s=arc-20160816; b=1BvyvdzaudUswA0/9A0pMqVhIhowqgeNYOF89GobGPI3QLMLePDFZL8hZltUgDOCIH bUCRHgvO5JULhvHryQq7xAlwnZog4yi6rQTQL9OmC7+c0xZ6SvIb/ZmkimpLHUqjKPEI Sh1HV794TkOhxuNaLekzwIvhOi1G7+5AjOyfohuOSV98ZFFo262e4d72t7bkaJ27Jq8R 1/TEXTfT9zxBQqTGkIs9N5Sv8QEcYh0QqM4drx3H7IMlP5S8tYJ4DWUgXxEcxZI2Ny3r Y4BXYtETn42w9SCEoe8WX3NCzS1yzOXWDI1yRaWgL+poP6DMReWHnnS3F9ElXnw2cLiq v30Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=44OHuqKdz/CdV+/I/LUbqJR6OYiOPrT/fH9OaPNr/SI=; fh=EsEjojEL6OPDF8f/FebfE9JM6O+YVxT9ZgdEGGZQ7Jk=; b=GUGspaAcc5FPHJ3Uug8Yh/Iwu1PReFBY83KiPcdO4wCORU+thgc0U/DFsveqqLcLtm 4KjvROrc760LmNsqWtibIssRb2nl+cKamVDnTIOQWeIqgH3fHiX8O6ZXSGSq6r406j+5 ik9SWTckJsXRG75nEFc0Lrh0+hpA0efbn8S4/UEDeWrWlrh/IrJT9+XFZamny7de+wpu E4z5Wv8j2Q4VK1D0mU7TbNbZWqMc2HjDM+GuytpwSf9HEcjjVUx7BeOxTTBKr9lH/BtX 104getV6exntPwMog8l6MUx5idF4GoS2vli0+J0E/phgZVSWqlrEg0bS8/IF/hzewhbi NsOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57993-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57993-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUV+p7tGcnBSvs4+mIKIVHiabBqY3P3C3CUfmqYKe4qlLOwUgq/UMUAKbp75YkmpmQnihnipYFTKQLL7E4+vBsXn2ysHw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a7-20020a05622a064700b0042c0d77ad95si3114878qtb.214.2024.02.08.03.56.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 03:56:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57993-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57993-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57993-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 144B71C24D2B for ; Thu, 8 Feb 2024 11:56:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4EBAC71B5E; Thu, 8 Feb 2024 11:56:13 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 301F66EB51; Thu, 8 Feb 2024 11:56:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393371; cv=none; b=HYemXiI0La8kkNixRt+Z74q1hwZeRj/QsvQ7AK8Mv9SHbdHVxpULwzLjMss5YuoaQsE3t9K++fONQkG/iUEH5Csj17PvMGDrB7MOsEJmJXCwSR/4wuic8Sr1/+1q2ruNYb4ZpdAHMGThvFndl/we2kSgP5agqZ55wxW55O2KSJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393371; c=relaxed/simple; bh=8DMwt8yyB/AH6UsoAjLC//3tT+olnUYsZlQ9JSoRWMQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WKnfBiCmA1HgEiLNVQe4qcRWX6talPygQWMp4cPoLcazqKZ8gnHnl8Z072WW5qrt4Eg6YiGA7gBK3uasREEtjMW6w65fsvltGuXWd41Cs7yIaEW8xs8Z8VpQh03EH8Syxj+IojgmWCL80OQoI1uPhu13I2b3RrwPPvvARjtPVPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A6494DA7; Thu, 8 Feb 2024 03:56:50 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 994823F5A1; Thu, 8 Feb 2024 03:56:05 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com, Hongyan Xia Subject: [PATCH v8 01/23] PM: EM: Add missing newline for the message log Date: Thu, 8 Feb 2024 11:55:35 +0000 Message-Id: <20240208115557.1273962-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790331734687145603 X-GMAIL-MSGID: 1790331734687145603 Fix missing newline for the string long in the error code path. Reviewed-by: Hongyan Xia Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 7b44f5b89fa1..8b9dd4a39f63 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -250,7 +250,7 @@ static void em_cpufreq_update_efficiencies(struct device *dev) policy = cpufreq_cpu_get(cpumask_first(em_span_cpus(pd))); if (!policy) { - dev_warn(dev, "EM: Access to CPUFreq policy failed"); + dev_warn(dev, "EM: Access to CPUFreq policy failed\n"); return; } From patchwork Thu Feb 8 11:55:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 198338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp109774dyd; Thu, 8 Feb 2024 03:57:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWoZ39323GR8DL3eWd+UKTZYJBRZWndfUAqEj8kwjNmsP8ZVtFXvcCCYFEoFg/cYPoYKCo8CHaF7zC5z80b+q3uZzvZMA== X-Google-Smtp-Source: AGHT+IECQkd3Y3MZmIVM8vqDm0edC6ezXWjgWofRvVnLDzhzjJC7eJ1zHtmbUzsIyJq+7BwCvQqG X-Received: by 2002:a17:90b:903:b0:296:833a:b47f with SMTP id bo3-20020a17090b090300b00296833ab47fmr5799516pjb.21.1707393420783; Thu, 08 Feb 2024 03:57:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393420; cv=pass; d=google.com; s=arc-20160816; b=knfisk9gunP48c4cKR5JOy6pL0vqigz/g0f1VjxLTONY1ZWPPNQpOQdTJj8hijk5Gh 1Ca01NqiPw/bzX4aV5vqmH5Ofwdacr6jD4hJYJfTgha9bl/wYv35ECqlj+Qg5818dyPK qvlmtNphlvF1VM/ju/lCrqp59H0p4QBHDYMvLNeTyPuCSk16P2PxAoM8fMyDsDxHK8ZJ zxjeL22IsT0r7KhUMsgRvx3BpxFQdTEjBfsOFJJjMuwiAy2xPS36cIGwr1OGiRRhzMQd jJoocflnN8O76oLCqXz5jJPZHOXteTREaMObg6AUEoYJE2PityqsttPVwpCbbNadU2v5 64dQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=j4+bu/ALg14Uvo5pcLwX6E+FH3oM5QGapbjXo8US690=; fh=9FhwDQCBj3oh8KoL6uKp5NAvlIb8dXFVHsz3b0e2ym0=; b=VRrAX67DAW0UKzCeT96JGSoIOq6GJiNGiVlJq9uVnAINm/3s555nJyCwWqQqN9tXkr tRMZewM437eb1utHzkuaiCv4mVsxAGgs2D3X5MB/CwBQLBRSWkl4h06JR6Zv7MemalVr MWcH96NJx7Lojgdj0WlRPLI8QYSqUbIkeKCQoD3Unxg+DBwfSAZPUj4nNd3He5gWAC89 +NxE0MW4plr0r3UuDz3HgzmOpA/b1/126bttQiOm1wbdhcJ0CpCdnaYHiu7MMteR5NjK Np+9b1+RLIPfZquLWQYOANA6AWPBmdPFJ4BNkp9Wopb0+60ZIaB++i2ygnKikaXLX/H3 Jy6w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57995-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57995-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWPyZChmzjQW2+NURrYrifheg8eygvR44yJTB95FliBhJe6D2xwgGqUli5+uQALgzmqN+ugNUVeefvu9e7cGNXe+wH9/A== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h3-20020a17090aa88300b00296454b0b6fsi1156907pjq.103.2024.02.08.03.57.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 03:57:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57995-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57995-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57995-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 7603328BFD2 for ; Thu, 8 Feb 2024 11:57:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9033E73186; Thu, 8 Feb 2024 11:56:15 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 097146F539; Thu, 8 Feb 2024 11:56:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393374; cv=none; b=buPSAkS4IWGv/Va7gUoj5EVww2HuYSoD740uREPxqCDeSMENlHYTranK+7jeu2hZvI0BfiHuo2tYm1Lj/FGKygi1vRSN1blRGE0tdjesY+AltgfwENNUxfZ3Z5tAp61QuCmbn5eYM6ieVDeP518L5hkIxhs4R4yQxkcBdV6hRWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393374; c=relaxed/simple; bh=3JyBDbzGvfBhPotIs1tob8kBWsx0vCf+QiqaU2yqhXI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QCDOTfLlwkCoo7z7JqreCrMP5TaHHlIOsESR85/btC5G1LnJhaVw8eLY2DXHVCCYRqLJHaG1y5/VptsocjbTub/mD7gnr2/LOuIDIeQ8fXn22Zq3CDZhdXoV4cmg7MTTBN8R2sRfQ8uF0RqXzY+RyD90F8bK+GMYlGk1QfE3aNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BEA411515; Thu, 8 Feb 2024 03:56:53 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BA42B3F5A1; Thu, 8 Feb 2024 03:56:08 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com, Hongyan Xia Subject: [PATCH v8 02/23] PM: EM: Extend em_cpufreq_update_efficiencies() argument list Date: Thu, 8 Feb 2024 11:55:36 +0000 Message-Id: <20240208115557.1273962-3-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790331763074537611 X-GMAIL-MSGID: 1790331763074537611 In order to prepare the code for the modifiable EM perf_state table, make em_cpufreq_update_efficiencies() take a pointer to the EM table as its second argument and modify it to use that new argument instead of the 'table' member of dev->em_pd. No functional impact. Reviewed-by: Hongyan Xia Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 8b9dd4a39f63..8c373b151875 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -237,15 +237,15 @@ 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; - if (!_is_cpu_device(dev) || !pd) + if (!_is_cpu_device(dev)) return; policy = cpufreq_cpu_get(cpumask_first(em_span_cpus(pd))); @@ -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 Feb 8 11:55: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: 198339 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp109894dyd; Thu, 8 Feb 2024 03:57:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIP/AXnxvvyfj5sJoOO4/91rKj9iBghhI9MapsMvDm4rF9Jomnf9eTX8GUqylGH+rV1PPR X-Received: by 2002:a05:6a21:6315:b0:19e:a658:3d78 with SMTP id wu21-20020a056a21631500b0019ea6583d78mr4859677pzb.22.1707393436320; Thu, 08 Feb 2024 03:57:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393436; cv=pass; d=google.com; s=arc-20160816; b=Vl78+x97IK+rHCOwfQcyl/VkUniTSlzW4LzEUFUwTAJxwMnd+HIPKNdBEudIKSCDWw Ye4hIaQzxpbtOETYFKzxxdZhGV+aop1Z5vVJ5L37zmoj5nFD1hi3XWuEiTbgEwYpyqdY w1S0IL71nFgLqeP/iT1IiEf189+SRviXTE/9rs0SJn6UOgCAe/t4vUlo6030MQ309GxV 70lzCs2Max3HGBPL4WjUWJ9xBf/TChbifGvvlullWEMcbk3P7yaZXVmSRS+KtPcUTfbz aU9ml70h5HLH1kNPMZkhnVDSUhH0nVmvNEjb4M+V4mxsoQixrg1Ma9K4uxXWnWpf8FJ3 GESA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=BClLa1cGaKPpdCiU5OhSccGOFmQHmqZiM4CmxfNWV2Y=; fh=Mt3GYvqK+OH3xC6EopCtOomxTn8/w9Pn4XoAMt2G8bI=; b=B42VlIWcx4Jw06DFBCWrKabu1SD6PvddCwdeMeGqRGPynFmVO3jjnL9D9YwX1nXVUW igilHBbfKtuGPJvmR5M/4DmyE46x5AlJf4aywAuUsnEZeyooQR+LyUJnB2denRyUVeg4 Uvnjcy40sqvdWSuLc41Dexj6L2QKZ9qHVQUMw9rUmj8Ii3Ag5+5IyfI9jgA8RUT41zqd DQsgzcxbvrVuxEcZk5lVGON5Xvyx/X1vOj5+432sgCeaWZbMe3MJ6ZWMqzAErbYYM109 OH8xoocWqktNmHGnxiPNc/1VezIzxpAILDaNfWWz+trMODe2wCfTDxdy5zwMg8nl8ngS afSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57996-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57996-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUBosDvI8wEyXAnMr5BSu1/1nTMd3pxJ1Y0CVXGGbBNyKbmbNaOdk9Gafei+QVZAucuA/04yMflZaTl7DGTWSKYVvm1rQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id le19-20020a056a004fd300b006ddd2c0b76bsi4156676pfb.87.2024.02.08.03.57.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 03:57:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57996-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57996-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57996-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 153C028C000 for ; Thu, 8 Feb 2024 11:57:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 77521762C6; Thu, 8 Feb 2024 11:56:18 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5115A5427E; Thu, 8 Feb 2024 11:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393377; cv=none; b=K93qfj+r6H7SBJgXTxc0j32FTr2wXNqZAvD6G3gan2x7arVMo4+ois6nixR61/nOvorDR651qaZ1C+utbkwPE53uAIEH+NNoA4c9MRTNOUsug3SAL1dzke3fGK+t1L1GopiU/c+AOkc1cubfMoQ8Cp2nkE+siz9n5wXAIqAbBG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393377; c=relaxed/simple; bh=vFMblhCLavHFIcqb3d9HPoVvxX4CxDbS2BZT1wAG2Rs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rJz5/EC2Os2br+fyerKhK26+1d5H93XJSwyt6lGOCj2UToxN2WHFa6dgtY2fZ0SjFC0kLXnhu3Cz2cKO7lTxFWWeMhkZlprgQkcsVxjy7JwOYEwFe/2YSPBVdNZD7Kg8yGSrkWfh7WlMhHTT6VCC5QPi0WbXcA1RBCwIIb2FOho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D9E641FB; Thu, 8 Feb 2024 03:56:56 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D51B93F5A1; Thu, 8 Feb 2024 03:56:11 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com, Hongyan Xia Subject: [PATCH v8 03/23] PM: EM: Find first CPU active while updating OPP efficiency Date: Thu, 8 Feb 2024 11:55:37 +0000 Message-Id: <20240208115557.1273962-4-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790331780185673292 X-GMAIL-MSGID: 1790331780185673292 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. Reviewed-by: Hongyan Xia Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann 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 8c373b151875..0c3220ff54f7 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)) 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 Feb 8 11:55: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: 198340 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp109995dyd; Thu, 8 Feb 2024 03:57:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCURECgJIPzYmqThvQjGBiuHeItteIsk1g7b1VAk9+9OKkXzZg6SGCetZwl/4CognT/I9LepNXE0Xww7ZKrj8TR0HZwOjg== X-Google-Smtp-Source: AGHT+IEiSkeT1JIJbWA+SYn+62FMCTHrgFAe7D01NZX+djGcZYeoYbheSW27FLzvYcrNNM8qldP6 X-Received: by 2002:a05:6a00:27a1:b0:6e0:5cb7:168c with SMTP id bd33-20020a056a0027a100b006e05cb7168cmr4148136pfb.17.1707393451202; Thu, 08 Feb 2024 03:57:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393451; cv=pass; d=google.com; s=arc-20160816; b=j4/vDMJP3CNJ9FGcPPYQidhQAbTLqVb96tAddbXIEaS8Iwz9tE7vwCX2JkEJ9YkMwp Rp8X7J5oSBGvoUogjP0sLAx6+jwQid7F+hqNw4dwvO8+y27s1iH0G3tHG+ucKf6kmWGQ D3J+RKSda3bJ0DFYs0YSOCttEeXZEYl8NitqQPVfiyroQI7Y/ETXe0fhArQNlTy2wqiY 66Xt8cTn4NT5axgVQSW+VEvIVatddJKOA/hU9yPfjIvkMZEc/gqfWQS7uMGW/29swIbb 8hgv8b8VgotDliTlTfSCmu3eXghGC8TPTOdakgH309gJNJ+o14VXi9uzHKuPlaIsCOJS 2Yqg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=/r4N6VsZ8/qe/wqCW0BqzD+PyOsJELYWwW7UyTyMS6I=; fh=+aD0/yY+QNUmHoBkna2rTxcoXXcGTQ4tyos9RQGbDqo=; b=zz2ALSiq1sOUKmc6vjgphTXUdP0MPJkee5ycqsh6DOzJbrmjp/gsmuC7NK9/UTxWSK RZGxUi6eyBg2VQGRAySmNzZCX+qk74cAiSbtnZvNfxabo5ZmM92q3yzIEWBzEkxGBqrO 7f0r//Qpo+vCq1e11JlFI8hXNZd2v8BoKybCcHsDogJie7FFP8/+XEbYpR3PtF0b9J5j DbS2dqbR230LYqALeiyE0wW7CxVFHmru/VpY60RNj/el+d/jmRwKWzLXNa0ngJ20kACW tUzssi76kIPjtogSmArIDuMT6LVvDGi6CuKTn3tKWXLuWvQgbfSlKE8zcsoh9/WAc5DC 8C+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57997-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57997-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWIg48czVsVisMAl4qEbAqfh2Lam1TO/11uoC4CLRh3OvL5c9kr6J/B0SBC1kysCsDmCv4Jz5sV834kL6qzwN2M48KJVw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jw16-20020a056a00929000b006e06f330bdasi2919828pfb.55.2024.02.08.03.57.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 03:57:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57997-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57997-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57997-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 0167828C02C for ; Thu, 8 Feb 2024 11:57:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D463762F4; Thu, 8 Feb 2024 11:56:22 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6C241762C5; Thu, 8 Feb 2024 11:56:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393380; cv=none; b=Snd0jMfugaC2abcw3tNSrXJ5UNHbbR0yo0MC0JlIrl5ZYcDGqw45OSHfT26o4LUU54R4Iln6lgPP+MeeumMM0oc7poa/o0+QSRcRNuyNJ4n9jMaXWnqd5nkK/mNCUVsbu1kIO7QfmMKBJOxGSlHwi/SFApWFf3uh6hSfY965QSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393380; c=relaxed/simple; bh=EgS98AzIrfTEkTeSSi8iSkdXy/W4/EMIsMiXga11j8A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UozrOH42QHl4DlAHS5VCh+1GmR6JU+QP6YU40jHjviRTbkxxgIZHT6ksRoIfuiXAYo/ZwYWeDgrYAhFNcttYhb54ZF/pAkwHlQy0s6cMyAyPWKMZilpkhB2pEzRyJuGHFd+sjPkSPf30KkNeBlDxNRgoeR55/CQdqLdlhtGRWIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F30501FB; Thu, 8 Feb 2024 03:56:59 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EE4093F5A1; Thu, 8 Feb 2024 03:56:14 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com, Hongyan Xia Subject: [PATCH v8 04/23] PM: EM: Refactor em_pd_get_efficient_state() to be more flexible Date: Thu, 8 Feb 2024 11:55:38 +0000 Message-Id: <20240208115557.1273962-5-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790331795314127603 X-GMAIL-MSGID: 1790331795314127603 The Energy Model (EM) is going to support runtime modification. There are going to be 2 EM tables which store information. This patch aims to prepare the code to be generic and use one of the tables. The function will no longer get a pointer to 'struct em_perf_domain' (the EM) but instead a pointer to 'struct em_perf_state' (which is one of the EM's tables). Prepare em_pd_get_efficient_state() for the upcoming changes and make it possible to be re-used. Return an index for the best performance state for a given EM table. The function arguments that are introduced should allow to work on different performance state arrays. The caller of em_pd_get_efficient_state() should be able to use the index either on the default or the modifiable EM table. Reviewed-by: Daniel Lezcano Reviewed-by: Hongyan Xia Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 88d91e087471..1dcd1645dde7 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -175,33 +175,35 @@ void em_dev_unregister_perf_domain(struct device *dev); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM - * @pd : Performance domain for which we want an efficient frequency - * @freq : Frequency to map with the EM + * @table: List of performance states, in ascending order + * @nr_perf_states: Number of performance states + * @freq: Frequency to map with the EM + * @pd_flags: Performance Domain flags * * It is called from the scheduler code quite frequently and as a consequence * doesn't implement any check. * - * Return: An efficient performance state, high enough to meet @freq + * Return: An efficient performance state id, high enough to meet @freq * requirement. */ -static inline -struct em_perf_state *em_pd_get_efficient_state(struct em_perf_domain *pd, - unsigned long freq) +static inline int +em_pd_get_efficient_state(struct em_perf_state *table, int nr_perf_states, + unsigned long freq, unsigned long pd_flags) { struct em_perf_state *ps; int i; - for (i = 0; i < pd->nr_perf_states; i++) { - ps = &pd->table[i]; + for (i = 0; i < nr_perf_states; i++) { + ps = &table[i]; if (ps->frequency >= freq) { - if (pd->flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && + if (pd_flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && ps->flags & EM_PERF_STATE_INEFFICIENT) continue; - break; + return i; } } - return ps; + return nr_perf_states - 1; } /** @@ -226,7 +228,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, { unsigned long freq, ref_freq, scale_cpu; struct em_perf_state *ps; - int cpu; + int cpu, i; if (!sum_util) return 0; @@ -250,7 +252,9 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, * Find the lowest performance state of the Energy Model above the * requested frequency. */ - ps = em_pd_get_efficient_state(pd, freq); + i = em_pd_get_efficient_state(pd->table, pd->nr_perf_states, freq, + pd->flags); + ps = &pd->table[i]; /* * The capacity of a CPU in the domain at the performance state (ps) From patchwork Thu Feb 8 11:55: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: 198341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp110112dyd; Thu, 8 Feb 2024 03:57:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUa/oH3o45ry2nDnj1xj+QHUfw6+ZEVRfIcWwFppqbxkPBmKMLMhalZmd9Pp1BFKCPMQh5 X-Received: by 2002:a05:620a:4141:b0:785:8da7:5e6f with SMTP id k1-20020a05620a414100b007858da75e6fmr4770164qko.0.1707393466800; Thu, 08 Feb 2024 03:57:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393466; cv=pass; d=google.com; s=arc-20160816; b=hJOZ3ZYwlw3VL9nwUg77zbsFOKtZ1S5YEiqpcysnndgp3+z3zxr8AXUN8tC4YIUfcc edc7cTLjztATNRMaifDsQeBRukQrXztuc/DJtTDEKgf9QM81ZmTHdA7tMOfNL3PQTBea TwXwnGIOQKDgTgIN+T4rj3o7mbGLD6nZ9I6/eK/7VJrxL1hT68XRWROHaP0kVCyh4lX8 mYQTHP+gxxduOWGS3o9+jk26domL1josFXV44kC7CMjd81/FBhx6kisiwqi9UUaidA2w Lee9SMReaMMLw8E+bfMvDPyvHwWf4T8MReQc9rQpDJTGl9w4kR7HFLxF0S+xqz/TlnNU LgDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Qmka6xEkm9gzK2orODS09CEOeqNSzzXmj8im47sePwI=; fh=KUeXzRwv91r22iP8xHlbwll1F+H6disgs8M1YhXOxTg=; b=dQOe4HGrnZiFE+IpTP/J2pv/14L37AlSkr0qHZXbMpvejeeC7rd/sKgcnKYZDBAQ8k lj42Zg2LRCVTveED69WNV5XPwQ6vo/wFgTFT9gDV8wDf99jSVyJlhbaUOylje/KObufP /l7Axdd2dOxqiDnc29YJtGHOd4/TwQwPUbR/2J4KDTZygeosToZlZkUI6aSoUWJkC98m x6XVW2xsWVss9IPcB4Tlbp5gTJo4+/8F8F3UTqJ8qxmvB9iwWqNh9nB96dy6ni9DN0D4 rMY40bb2+INyTdHT8BnDG0yEqszt8cyjL84gAiP6fxouUVuLpLpS2b5vBHqh1k2YwdNF VGww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57998-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57998-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCXLzSJaN8GxrzkKOBXqj8yVHJNr/fQQyPqzlaXNUHiCqmb2OS19zXpunB50RAQ4CPVcT7pzAxOp38nDJyZ1SiHrplTmKw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u16-20020a05620a455000b0078403334a6fsi2069636qkp.733.2024.02.08.03.57.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 03:57:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57998-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57998-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57998-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 959A81C25CB7 for ; Thu, 8 Feb 2024 11:57:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCA96763F4; Thu, 8 Feb 2024 11:56:24 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5388A6F51E; Thu, 8 Feb 2024 11:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393383; cv=none; b=m/gV6ZvxTClVTM5pY260QR0RyQImfyDZjnqAhAoHDQC3DMKjAhsHuB+GPqcHeOD3kkOQMb74q8tCTlKva5S9/wULcvcsrDx9ShSO+ohBpW1B1rn4O0ZT+KcyyJBic7RsYbbCEgS+M0rtrICaV5kpboE0GRYEv5bT+DYIb/ZuIKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393383; c=relaxed/simple; bh=bJjuu1EuWo74cFfQaOzHPNk7ZlfyPGiQ3J7BsnvcTcQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eZ86kaXJxcZX402AsiOH0enAawl/CQhPSrgFJid671aHSFLFa9XR1tc+MJ0UQ1GZusso8MroHUguWWUVO+aKoKz+maAqZ10yC+2d/V/Ey4ZDOKPN/yMhl5DTcuwPLBlQ0nyj3OE7VqAjzlS1O++23Lb2r4lHt+sdS7PLflRTN1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E9504DA7; Thu, 8 Feb 2024 03:57:02 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 143B13F5A1; Thu, 8 Feb 2024 03:56:17 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 05/23] PM: EM: Introduce em_compute_costs() Date: Thu, 8 Feb 2024 11:55:39 +0000 Message-Id: <20240208115557.1273962-6-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790331811794209794 X-GMAIL-MSGID: 1790331811794209794 Move the EM costs computation code into a new dedicated function, em_compute_costs(), that can be reused in other places in the future. This change is not expected to alter the general functionality. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann 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 0c3220ff54f7..5c47caaf270e 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 Feb 8 11:55:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 198360 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp126085dyd; Thu, 8 Feb 2024 04:24:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGf1+14Hdw0aHJaldDBF0d5r/dCJcL+YnYbIkUQZENm7tOOvJFsVyMZRYsKSINQQ62VF6VR X-Received: by 2002:a05:6a00:2d81:b0:6e0:25d7:debc with SMTP id fb1-20020a056a002d8100b006e025d7debcmr6610875pfb.24.1707395093000; Thu, 08 Feb 2024 04:24:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707395092; cv=pass; d=google.com; s=arc-20160816; b=IiJy5fx5y06bzEPCV08Wg8ov8HmU2bNtq5e4vOm6JLbQ73zGmceV7Ati8XxJKpYbqV N5IWS3M7VPoV9CpvTchE70RMMkJhYGp3zhyx4KuhhQav9rW1r1yRxAk8JNWbX2UWHz5i 7yDxCpFmbs7L1CD8UpdejVxf8N1q8uplA4aU+LlFSidR0HTYGs23xTKqvckAiaOFMUAw JjDtYPH1cGQGBTFQsm0UrsKkOOzRCqar1H/z06gWcQChXLjgBOqvcFbzG4BZy7+zsG3y 84UCMajXhxj46+BUV8JMtD5wRqPgbTWlLZg1FA3bQLLtoIzQ0souo3ODjXo/OVCWEcMb TKdQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=pNudkuW67175AYZXExAU7FwVK78v0+Vc4RQALB3xfw8=; fh=YdKtU6dg5End+ya/IRdW0AfHlvtLVwNcv0KS0TdAPrQ=; b=kNgApK699zmW9NpcTg0fPC8Fwgd2ttvPblppGPlAq03FEHpIDHQSGCih4pGhWCzsEn GRkIxZ+YQOP7iu4joGn5cv048Cg0z9hrhpFFisMXm0qI7TQj0Ozzo1tsEw5Oex0DT7Xd WpT/jvSh23p8h+cvpYWABak0Wb4J8JoitQk5+O/pAGgi1ZJgToTXJo77iKYe+569BIBF ELdUVeJMMP9dweK4vgXu4dlDGW0clN9+LD5HqGZNjRGxX548EOM3BR1YyPvwmR9IYpTA 4RNJa7FqsHpU2QMhqy0AZgVKznc9I/7Ca1qNtl5NtJPuhkY88y9tlbKWTtTT/HgLWKxF ZfKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57999-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57999-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVPjKUW2ttnvCtiqaJXa9Qp0NLttsPdfkqupnCeND4GjIai2N0n89ecppniGm/mjOJLBO583IpgCL5P/qY0ssOSoAsZ6Q== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id by23-20020a056a02059700b005dbf27229f0si4348185pgb.303.2024.02.08.04.24.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:24:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57999-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-57999-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57999-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 A84AFB2B976 for ; Thu, 8 Feb 2024 11:58:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F423D76415; Thu, 8 Feb 2024 11:56:27 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7854B763EF; Thu, 8 Feb 2024 11:56:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393386; cv=none; b=phkc+KWI+3moz0NlZYszUOi3dfKU6NCR/11pAXqVZOBGdFCoop8jw9JVoNdZZBtu/tq6up2s9lnmu2+n+mNk6D/fWMGUhtOv/vEXfhuX6wao1ajA5eBmWKpXZHWYwZq0mNwN8Bdvii3aLc3Uk5++No2nrhmP5WTwr22dh9Ay0CY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393386; c=relaxed/simple; bh=Da4Wg14h1CcjXL0JhFy9dAEG/iSfGR93L/E4kBh6W60=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mwR4z9TQIJ3uYydZtMgCfMK2m2L6W/NoJ1I86THIWWBQ4j6Esf/UgqMqQPFzrFDT6RFjRDPlFvt25FkCISpLnfQWxUdpNn9tYxT/56aiEfhtvoDivpY2uyyBylIKF65sBQIoCcfkDZn7ABVb/8WJCaDvFj1HdEtkKbAUu5rwS4E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2D2741FB; Thu, 8 Feb 2024 03:57:06 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 08FFE3F5A1; Thu, 8 Feb 2024 03:56: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, xuewen.yan94@gmail.com Subject: [PATCH v8 06/23] PM: EM: Check if the get_cost() callback is present in em_compute_costs() Date: Thu, 8 Feb 2024 11:55:40 +0000 Message-Id: <20240208115557.1273962-7-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790333516937367439 X-GMAIL-MSGID: 1790333516937367439 Subsequent changes will introduce a case in which 'cb->get_cost' may not be set in em_compute_costs(), so add a check to ensure that it is not NULL before attempting to dereference it. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 5c47caaf270e..21d761223255 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -116,7 +116,7 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, for (i = nr_states - 1; i >= 0; i--) { unsigned long power_res, cost; - if (flags & EM_PERF_DOMAIN_ARTIFICIAL) { + if ((flags & EM_PERF_DOMAIN_ARTIFICIAL) && cb->get_cost) { 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", From patchwork Thu Feb 8 11:55:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 198342 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp110319dyd; Thu, 8 Feb 2024 03:58:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW79OtLWpQecvLr5qeIn0tHC8gRjaM5YysJD5TiFNaY21HaNJUCvEYsOlm5i5DPPcnuCioRPSpMPOKbaARxYyhUI0cWjg== X-Google-Smtp-Source: AGHT+IFTnzSD2k4Bjib++mafPUbe9D4d/6UJeMu9Bl5V/gIarHqKTEWhHOuKwhcqPvBlBgj99m9Y X-Received: by 2002:a17:90b:2e0d:b0:296:2ce2:5b3c with SMTP id sl13-20020a17090b2e0d00b002962ce25b3cmr5231487pjb.20.1707393497628; Thu, 08 Feb 2024 03:58:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393497; cv=pass; d=google.com; s=arc-20160816; b=GFHxPdJD7VVSB+S65kNfwqN/5oTTaH2OOd/48mgAt+7dg3dx3gS/5lPlqGmrZkDRgI uUO+6yibc/ZOeA9ttgqh4P72bm3nZklO5J1L0omaKDrfGciAkVOa8ltk3nvLm6SaULBU m+2CCLcEgNHxLavkfNwda3jTWPtOvIFq6ND0uxEQ6UW88Ey7YxxnqqkII2xEWQ2qHKpB 6l7kn58QqkcppjhPHnySKPWkHMjbrN5stOuRxOFHgMJWSrHmyA8BKR464YrkdeKuFKVe 0YS/inipq5qa8kebKe5X74vD+R5+lSXicRkoiFrbvgiwmKZ8cipIs6NsVmcNGh3x0BsU S4lA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=r75b9yAGSdpOyl9uKgAKk0nWf04cFAgLBVceqMPZ2DI=; fh=OfBcl6ftAea+zKVRru6JEhFxNd3RNS6MkVAJxaBvVtc=; b=K13LcOGHNK+6CdRFlKJi01wPu9YIS/XqZ9XyHbTJULkwzKCv2c9zp6oNCmYJpbgdfD A4GPqu1oPY5Y/EpHJooYiL5MCp6meX3T5G9vQpeGdYNagklcIFJjoMaKlbs85nErOj8i XgmrgNWeavVkglY0baLuawEyQ9yJYL/jTx4dn8OM/waeOzxMbJOzRQSprxzp4ryd0r3y A7+OuCl0TEW/0iX4oodxdJBq5fWmZ3dM/1SPONnwLXbvEuZKy/dnBAVRaU2mXwWjow3l awj/E06acydsWsPKZoRgpFIXdBeD4PXLkVin2kJArxlmChfJevJIZ22rqT/E3gwBM+FV EK5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58000-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58000-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCU10cr6hN2h7p5Z5T1OWnILYV3J+Tz/M5jyBmpAIBvhFf54eul2OZcvHBWoMlAN7OsO+pKfE6dmHAdwb+ENDlLfz+QMTQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h3-20020a17090aa88300b00296454b0b6fsi1156907pjq.103.2024.02.08.03.58.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 03:58:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58000-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58000-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58000-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 68C7A28C006 for ; Thu, 8 Feb 2024 11:58:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F19CD7691B; Thu, 8 Feb 2024 11:56:30 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73DCE7640C; Thu, 8 Feb 2024 11:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393389; cv=none; b=OumosfupNZKX472XKvzGp96Iodm/aMk+ZfqLwWBAoNx8YW/6uhnAeAgmoURp5mbftcs3R1RnYZkGEeMHjWQgiKOUt54UmHyQSfdVQz3nFBs+1vCehezs41ybjcQCMAWgwUvNRipj54oRUf6l+KD1nGTGBByy+RuU5cYmNkc9mlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393389; c=relaxed/simple; bh=uOfszU8onKghXMWUp5uW3OMPxsyNzrUd6JfObHueJo0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iE+BK5K2pVSUbOBhLD21F2BYaRLmg+5ayMrhV6z14K80pPyp9FsabPDVIjRpChLIlTgC9zUf4bKSXU8B2sYlui+as+KDBtNNRgyYi/drjl/AccGLTCpQdfhvjLrRnumTdTtESH4DaZXI8RNN3Zj4CVkdxWu8qldiNT47FdDjixA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 21E031FB; Thu, 8 Feb 2024 03:57:09 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 403393F5A1; Thu, 8 Feb 2024 03:56:24 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 07/23] PM: EM: Split the allocation and initialization of the EM table Date: Thu, 8 Feb 2024 11:55:41 +0000 Message-Id: <20240208115557.1273962-8-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790331844616086968 X-GMAIL-MSGID: 1790331844616086968 Split the process of allocation and data initialization for the EM table. The upcoming changes for modifiable EM will use it. This change is not expected to alter the general functionality. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 55 ++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 21d761223255..7468fa92134b 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -142,18 +142,26 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, return 0; } +static int em_allocate_perf_table(struct em_perf_domain *pd, + int nr_states) +{ + pd->table = kcalloc(nr_states, sizeof(struct em_perf_state), + GFP_KERNEL); + if (!pd->table) + return -ENOMEM; + + return 0; +} + static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, - int nr_states, struct em_data_callback *cb, + struct em_perf_state *table, + struct em_data_callback *cb, unsigned long flags) { unsigned long power, freq, prev_freq = 0; - struct em_perf_state *table; + int nr_states = pd->nr_perf_states; int i, ret; - table = kcalloc(nr_states, sizeof(*table), GFP_KERNEL); - if (!table) - return -ENOMEM; - /* Build the list of performance states for this performance domain */ for (i = 0, freq = 0; i < nr_states; i++, freq++) { /* @@ -165,7 +173,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (ret) { dev_err(dev, "EM: invalid perf. state: %d\n", ret); - goto free_ps_table; + return -EINVAL; } /* @@ -175,7 +183,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (freq <= prev_freq) { dev_err(dev, "EM: non-increasing freq: %lu\n", freq); - goto free_ps_table; + return -EINVAL; } /* @@ -185,7 +193,7 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, if (!power || power > EM_MAX_POWER) { dev_err(dev, "EM: invalid power: %lu\n", power); - goto free_ps_table; + return -EINVAL; } table[i].power = power; @@ -194,16 +202,9 @@ static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, ret = em_compute_costs(dev, table, cb, nr_states, flags); if (ret) - goto free_ps_table; - - pd->table = table; - pd->nr_perf_states = nr_states; + return -EINVAL; return 0; - -free_ps_table: - kfree(table); - return -EINVAL; } static int em_create_pd(struct device *dev, int nr_states, @@ -234,11 +235,15 @@ static int em_create_pd(struct device *dev, int nr_states, return -ENOMEM; } - ret = em_create_perf_table(dev, pd, nr_states, cb, flags); - if (ret) { - kfree(pd); - return ret; - } + pd->nr_perf_states = nr_states; + + ret = em_allocate_perf_table(pd, nr_states); + if (ret) + goto free_pd; + + ret = em_create_perf_table(dev, pd, pd->table, cb, flags); + if (ret) + goto free_pd_table; if (_is_cpu_device(dev)) for_each_cpu(cpu, cpus) { @@ -249,6 +254,12 @@ static int em_create_pd(struct device *dev, int nr_states, dev->em_pd = pd; return 0; + +free_pd_table: + kfree(pd->table); +free_pd: + kfree(pd); + return -EINVAL; } static void From patchwork Thu Feb 8 11:55: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: 198343 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp110421dyd; Thu, 8 Feb 2024 03:58:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IEWMn72WLeC6nQxr1qMn6kzkqF0DCVs/eYQtoYf4GiVUUPRKdX2WafFHq4jNyx155LrmYb+ X-Received: by 2002:a05:620a:17a8:b0:785:9323:e60a with SMTP id ay40-20020a05620a17a800b007859323e60amr4335860qkb.8.1707393515863; Thu, 08 Feb 2024 03:58:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393515; cv=pass; d=google.com; s=arc-20160816; b=GlPEYBWmMVgKXgmSprqDvaeWHqvtro1gEC0L6o4ZgKApfB03O/Sz3arPMGW5yrfzdd fASoZB2mBo3qEyXEj7BLTOjdtIjNB0Nixn7d8qBt1bsXHYvENyfdfyB7hA4/knPYTX23 arKFnWi0lycxtVf3Ir+vuNpfN/avWiZVnq6qpaYtvX0tuOuIOwUP+5zjTgVA6G5lQCeM MUrc8tcMHmqZ3vTM0OSN0d+k7efD2arY21O/DuvDqtpYtDTFph3djH3PukHdDMLvTo4E 8pAfU452nmJVX1G+4fK6q+v8wPwvGZBQTO8v04YD+LqsJh0TRjB/4xwacA4OgN6ZZZaz 9jJg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=j2NcVgRqfY0zeOECalgt0wYrBdRrNl5Z7pjZxgCS3Lg=; fh=RZqU1uM4y4O5KnzNFszTTgiDnAHiRZZ1asCX6/ovJ9s=; b=NFVN5oSWrslzxrI6Cdcqygtrjw8O4OmgiRjpehFbfQL/7CcSwp7W/b3PNXxeGONnFG Rj8hsqkSseyIqTXBwXmuf1L1J2oMbA9AdT55d/dd068xdFWDLpYX4wYbbrYQh8zSmhiX lCnszAOIUbOHcw0Y/ynjCdooexJ8GBbZVgy0Mnb9vqtTDDJrrbyb7q2bYSQSSNuUDRlH vonqs9KG1FjwCC8TvCuhhZ6V0gTPBZtMw5UWE38scaqLyrqBCKXQqbZThGOui9rKSHKW iwZ9e6Ufc3/w/zzv2JgUDG5VMWdiKkekJgrZ6C8TN82l0cs6EVbhfqI9ElW7WNAM63cl V4aw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58001-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58001-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUEKTdmmVhnc/a1oJHOQDT40DfW4fxl4WuzhVbznDEEaPiKVjzh9/Jz4NS9xj6FhjoE23UscNKXTR+kQlexd8CB9vtg6Q== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u16-20020a05620a455000b0078403334a6fsi2069636qkp.733.2024.02.08.03.58.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 03:58:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58001-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58001-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58001-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 A3BF41C26010 for ; Thu, 8 Feb 2024 11:58:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2304E77653; Thu, 8 Feb 2024 11:56:34 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5AF25763F8; Thu, 8 Feb 2024 11:56:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393392; cv=none; b=Kk79A5lqqBxck/xsm5mkZ8j8mKofppdxVESfUf+/g6Tp206FLWWhepK4EQjELyfO2Uls24MXU+MlkVHUuNfa2cYg4bLxN/yPnvj8qh0WE+UhFGJW4pvCF/OJ1srq8TlEVte6aglNCDjkY6DGHPldXZcf8+En2UGXgsT0iMAH0EE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393392; c=relaxed/simple; bh=QZpub5tc2Ol3rvjorYPhlX7VrudK5oDI3YjjuCvccKU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Kg5MuaSUxDyY36hyRN1nro+EkE33ibO0bru4CjZ7SYawNIjeO1Pttanq2WYt3jcGsm4TY9l2QWncMrISCjq/Gw9OWFGYx3AFrKurWMk62nt7K1SkNhsddwuIIRqZ936+OZ+ypTrRPKm6vQm+JTtVLKUOKT9le9sUs5dnVbkSNhw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1389D1FB; Thu, 8 Feb 2024 03:57:12 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3575A3F5A1; Thu, 8 Feb 2024 03:56:27 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 08/23] PM: EM: Introduce runtime modifiable table Date: Thu, 8 Feb 2024 11:55:42 +0000 Message-Id: <20240208115557.1273962-9-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790331863091345622 X-GMAIL-MSGID: 1790331863091345622 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. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann 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 7468fa92134b..131ff1d0dc5b 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 Feb 8 11:55: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: 198345 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp111101dyd; Thu, 8 Feb 2024 04:00:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVx9WdWImy/Ob8xj4DpFUmEZ9ycFm2NPzddf81860I0ERr3zN7rEiL2rfAX/FkKHPE46UR1bjG+5Vs4RhBxUJBQcEnHXA== X-Google-Smtp-Source: AGHT+IF+oP9om4Ji6TKCHcO469kpdp4nGvhviuqS2gnD3O151G7b4+NvGed/DbYDuqhygoOo4mEP X-Received: by 2002:a05:6808:1289:b0:3bf:cc6a:d00 with SMTP id a9-20020a056808128900b003bfcc6a0d00mr11045668oiw.8.1707393605679; Thu, 08 Feb 2024 04:00:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393605; cv=pass; d=google.com; s=arc-20160816; b=jq3toOciojP/OTaoR1zE4z9y3NQA98cSCyLAWwfx5ENpYzdXcgYmWToUH4EqSxPMip AF/wAE7Ud1cn1Dj9gqlFLwA9xk4ySzbg6JoGRsr9zT0hKE982kABTj9Fixt94mOUBtph kaMrzLNora78qPxud2lLn+ZkHo8KoD+uzL5rwpTebf2MQ7bt8slJ5Hn85MBrgkgCjewO OtKhn1MEz+F/xHFQcK78Vlokzpuhz/ys0Sr1o4N5D/QfmblLwtPaLSBV+SKPEVHq4K+J wg0r61Q9GzvPFkQG3vObaCNYLzh3UlCcY9eg+4STRGGbEt+1SaYm2cP4+5lbH7BIvVEP SUnw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=BBCshDgzvyYzGZn9xmC/6TISc2fmUCjGJYfyXQLT3Mw=; fh=Vth8BRR97Xrto30raIrfS43QQoi/yAu3QIXJGlyycCI=; b=KQVfMCVgpGZUYdG53ZV5D7iZ8yTIfD1672eglMrIzTFnKqo43ey+nGI5xyVcfEWoyg 4ZndRosVbgbxhPNbCQYQYnRhSh1FTVEojU027ERBP2RdoNT8N4tRMDvK6Byp21dFoKVo 6urjb1h6r+2rDy05pbiuoo0Gem6WkUsktMKNTMukUFGLXFRupWCVZVVrrNKQRVwqdhQ6 9gUbCxZXVimQkcscz5U4R7aYRpSJe3VUuWKzEbak8occ5THjphzCI+FCxIHysAsZqfI0 B6rN4p2miL1+4UWYO2f2BXS4pgUw/ZCybnsQrXxUgO6640Q4G+RHRKFJCyQ/r+omaoLY vwMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58002-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58002-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVHSm2OsBwpjUqWkzL9zAwISKv2wIy/Q4vbvqMjAz2W+Sb9fKDSOSNlS3UH+yX54dm8+zjBytKuKBWLtkR8Za8a9QIN7A== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r7-20020aa78447000000b006e03ac13dbcsi3629481pfn.31.2024.02.08.04.00.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:00:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58002-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58002-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58002-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 EB441282536 for ; Thu, 8 Feb 2024 11:59:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A720079920; Thu, 8 Feb 2024 11:56:36 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 502D276C8C; Thu, 8 Feb 2024 11:56:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393395; cv=none; b=EHPF3sn6H6Tm5Oj+djv0oSMzvK3o5G/YbsRd8xIQgRracFad4RShO/PwpoW0h8q0dbW8xtqx70716cl9ztLaha07auqhbdiaFvPyqTHzaCiq3E2xLq4iJaTAx2Ye3WVAFw2/g+DeZrm8adeymspOMOZ5XLxTOj/FfDZsZ+xVkBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393395; c=relaxed/simple; bh=jSDNw/gdJcgEyLMwynWhjBDaJb3Vfg+ndN6jLvTWrnk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jsDiU52HOnBD2TH1ARYvj99ykGkU3sxuCKb3mdeZZjdW9DAe+lLnUFcObwUNvL0tj/REtwVfPsK9SL9rzaN/khhr6fimeGgxYcmkEdYdWL11FPoPAiqI62WZOea23at/scH5J3ANugeJ04znIWqHL4p+Bw56+Gmt5t8CvRFad3o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 06C7B1FB; Thu, 8 Feb 2024 03:57:15 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 274A53F5A1; Thu, 8 Feb 2024 03:56:30 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 09/23] PM: EM: Use runtime modified EM for CPUs energy estimation in EAS Date: Thu, 8 Feb 2024 11:55:43 +0000 Message-Id: <20240208115557.1273962-10-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790331957455185565 X-GMAIL-MSGID: 1790331957455185565 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). Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann 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 Feb 8 11:55: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: 198351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp115874dyd; Thu, 8 Feb 2024 04:06:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUHwVC19DWfp+jpiDu3q//HTNYuL41Q6kyYpr1cE/raqpU4UoXaqQsHMy1hHSkpmbA7qYQCB2udmrc9Z0ZVERxTbVF9tg== X-Google-Smtp-Source: AGHT+IE2dnKr6AJR9svuDMkU5LsBdv6k+6JnWA4DFpyOIoB+RIgaIpedUMy6aHT4jdG30PhwNYze X-Received: by 2002:a17:906:578b:b0:a39:34ff:d6ad with SMTP id k11-20020a170906578b00b00a3934ffd6admr1744218ejq.7.1707393997524; Thu, 08 Feb 2024 04:06:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393997; cv=pass; d=google.com; s=arc-20160816; b=VTmOH7C1cqx2JufYuwwQbK5gGr9ri+0EXOvrujFBRjDp/uwc48IuD3PG4p5itr+kRR UNPb6EQwiez0zEb371JqaLYAGKx5sjsP9ZD/lOLG2MhV6PKzloPnvKJMpJo7djyahTRJ a/iqmvixHAeCwCxm/UtSrajxVo1fSV2Msd/5nvFqrq75taNY8cGZgYr/8QzZa6mumogD jM2Tt8rhIFaUtpm13glQ9q7RQYR6i/JKI5+oP9FSox+cO3Mlwm1Rcmu526xkevh8Jl0r APgx0jTYou2HP+N1ewSnIxx1dG+2sssW04AVNyuq4Cw2Srwp2dZ6l+u6RhvXWqqWQLO3 FOhw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=y0FTRhgGoeghg3P4DAY4Fd0aymLCTWCadF5o//dluwA=; fh=D/4y9ZrSa+JjcXRscAmxuSQ+HMX6BK/Z3rYUbyZUFf0=; b=ZaH0aM2OdL8d7RNZPQhaMR9+NdfY3XOI0p9nSoVGF0k7N1EerE8c9h7jccNdlONWRk pZcwMRO/OjivEXM4YxbZDYwVsDjlq7u0BvkW7MyCzQbdHQZR7HSDVq5u6z3E/AZj2FDN 2fbdNthaFF6xGacXmFYvF1zFclDdOxxo0icqEMOvf31rZ9tM/TmYyimJk0k1VTlKSf8t S0v/bA+ghO8O0HqV18rhm+ahSSjZzNyaTbbZrrHiLnfJdiGBdcHbQGCSbPoY9Sf4q1yN mWzTqnW7nsT11XOZy8cIZPfo73k4PmoRPeup0cSfX4crL2h/SkRgyWoVKnwY+t60S2Dm vLwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58004-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58004-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUUMPQAkXq4XSPB2VSbIKjyL0ewSzQvCST36xqfEtgKvADuErXBFiXLbC4PS2YJ8mgXcXuNZgj3ubrIkY8wMvbekow+6g== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gq8-20020a170906e24800b00a38460f89absi2174043ejb.476.2024.02.08.04.06.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:06:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58004-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58004-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58004-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 9909B1F2BFED for ; Thu, 8 Feb 2024 11:59:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E43AF7A70E; Thu, 8 Feb 2024 11:56:39 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2480D76C79; Thu, 8 Feb 2024 11:56:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393398; cv=none; b=SGduYDeHBDz8APkeAMP5xmFnLU5x2R+FF9uaW6cO0hE8V6nwDLLUKwLxNplxPlwvWIVC2U7jrjctp9R7CdX06qCHHqGSJdKTQ6HtC3MhEUFZr7SmUtNnzD2DIVejmXIinUjpC4Gk7eRpmYsMh6ijNP59fLaOX1Q0CIdhoxXPQ9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393398; c=relaxed/simple; bh=DiNv7mQncPSnB+eywfhrvz0BEnMEKg6b9IKEAkOD/Bg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kJpiAt10YG5b78qJHHT5ewi0/IajsXgRaId9+MLyEu3Cm7mK9v6YeTsxBPWwGhWbgbZEj2OoPIHiIbf+oHkjvVIp4BTIi73rLXeFcjGiBFwQnFSrRB6k8n65DrB3CRcstmxHNWKXvkaaDTn/vwycJLBPRLTi3hOwyKkLQsv7uh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F051B1FB; Thu, 8 Feb 2024 03:57:17 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1B12A3F5A1; Thu, 8 Feb 2024 03:56:32 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 10/23] PM: EM: Add functions for memory allocations for new EM tables Date: Thu, 8 Feb 2024 11:55:44 +0000 Message-Id: <20240208115557.1273962-11-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790332368358895460 X-GMAIL-MSGID: 1790332368358895460 The runtime modified EM table can be provided from drivers. Create mechanism which allows safely allocate and free the table for device drivers. The same table can be used by the EAS in task scheduler code paths, so make sure the memory is not freed when the device driver module is unloaded. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 11 +++++++++++ kernel/power/energy_model.c | 38 +++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 5f842da3bb0c..27911dc1887e 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -39,10 +40,12 @@ struct em_perf_state { /** * struct em_perf_table - Performance states table * @rcu: RCU used for safe access and destruction + * @kref: Reference counter to track the users * @state: List of performance states, in ascending order */ struct em_perf_table { struct rcu_head rcu; + struct kref kref; struct em_perf_state state[]; }; @@ -184,6 +187,8 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, struct em_data_callback *cb, cpumask_t *span, bool microwatts); void em_dev_unregister_perf_domain(struct device *dev); +struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd); +void em_table_free(struct em_perf_table __rcu *table); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM @@ -365,6 +370,12 @@ static inline int em_pd_nr_perf_states(struct em_perf_domain *pd) { return 0; } +static inline +struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd) +{ + return NULL; +} +static inline void em_table_free(struct em_perf_table __rcu *table) {} #endif #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 131ff1d0dc5b..16795743f969 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -114,13 +114,36 @@ static void em_destroy_table_rcu(struct rcu_head *rp) kfree(table); } -static void em_free_table(struct em_perf_table __rcu *table) +static void em_release_table_kref(struct kref *kref) { + struct em_perf_table __rcu *table; + + /* It was the last owner of this table so we can free */ + table = container_of(kref, struct em_perf_table, kref); + call_rcu(&table->rcu, em_destroy_table_rcu); } -static struct em_perf_table __rcu * -em_allocate_table(struct em_perf_domain *pd) +/** + * em_table_free() - Handles safe free of the EM table when needed + * @table : EM table which is going to be freed + * + * No return values. + */ +void em_table_free(struct em_perf_table __rcu *table) +{ + kref_put(&table->kref, em_release_table_kref); +} + +/** + * em_table_alloc() - Allocate a new EM table + * @pd : EM performance domain for which this must be done + * + * Allocate a new EM table and initialize its kref to indicate that it + * has a user. + * Returns allocated table or NULL. + */ +struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd) { struct em_perf_table __rcu *table; int table_size; @@ -128,6 +151,11 @@ em_allocate_table(struct em_perf_domain *pd) table_size = sizeof(struct em_perf_state) * pd->nr_perf_states; table = kzalloc(sizeof(*table) + table_size, GFP_KERNEL); + if (!table) + return NULL; + + kref_init(&table->kref); + return table; } @@ -186,7 +214,7 @@ static int em_create_runtime_table(struct em_perf_domain *pd) struct em_perf_table __rcu *table; int table_size; - table = em_allocate_table(pd); + table = em_table_alloc(pd); if (!table) return -ENOMEM; @@ -512,7 +540,7 @@ void em_dev_unregister_perf_domain(struct device *dev) kfree(dev->em_pd->table); - em_free_table(dev->em_pd->em_table); + em_table_free(dev->em_pd->em_table); kfree(dev->em_pd); dev->em_pd = NULL; From patchwork Thu Feb 8 11:55: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: 198344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp110972dyd; Thu, 8 Feb 2024 03:59:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVpCPrq07mrReIG9LTyW708UQcPjk1umeOq60ux1DoEjwMxVj3zaXR+lEp03vEVUa4TpGSm0kNK1eMnLQdt1V87eZHW/g== X-Google-Smtp-Source: AGHT+IF+Kd9zWQi3H0w+kD7puIYlccr41jQurPrD3azJnvwef10wr9b9RtuNPNJi8IvJZXphK6/B X-Received: by 2002:a05:620a:3890:b0:785:9fb8:a46b with SMTP id qp16-20020a05620a389000b007859fb8a46bmr3544902qkn.60.1707393594738; Thu, 08 Feb 2024 03:59:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393594; cv=pass; d=google.com; s=arc-20160816; b=K9+7U16T4tnltvibONDDpydpVH0l5mXRj5WZRlWhNf1w320+CFwYfcrUqsFlxSis6T rcR8rJtg1+RZlJHrtp8jYw0w5wLezwvlGlDUM4iq0OJnN3ck0cSpW/Ek91XJS3pdkzAR rzTCZ6z4hVUdTAUt0t+JjJ/gB1FkIYjWOkfkWlYEexaPAStIjWY3zD1aa/KkTt5iGUzS zfs+dKf+XehmBa4OmvowqNCrLUhZKQXtgsP1O6bocQX/UwGz07SXStk08vlezUNuQ3CG K5WVGpniCvDVaS2j1j1uinl21RHpSxAY5sMv/ao5YYeH9orpZgpe4f65Jk0TKKbxhpPn QYsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=ehl74s8H6KBWPH1gNbRcisSNCymH4a0OFm6UiRHHYBE=; fh=tUw5tHTPu9WfuyPta6y3NF5E8yjz0hqlZcwMpYCDJrE=; b=bejfmkoK5/ISxQJuefIXawULLXJuyTBZi5xDzpO31NbwrLByJFeBsPhgUw01pooLWh Z86BRpRgApplRane3zCTtdkQC1f6uKViF9xqYZoaP6J0Kkot14UsoVUD7vEOWoL+JCH1 mGZQ2HbPII8/rptVrfv5TcmMd6btc6OxOIxwDsxcopEZXSR8ihOvPZBdkE8SWdDny9aX DSdMFGDq5zPFfY7y8YxCQK2Yy/4he04v4r27+prTE36S2fEVltdWVGPKI+/4wTtJtlzV 1vWKFn1V3+/t5XXaQbNiQzWRDVMMAL5fkcGdApXXxWZllAQ/e+/gywvIBU82B4XGF4Y0 y8Nw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58005-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58005-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCXztm1wYnuB+5wL6ZozGx8OpX/ThWBtYC7ZKJjnNRunbKCr7ZXNBHwT8E+7oz2pkPI8owEiUZjC2fvXoqxyKgJMuSsddw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ay39-20020a05622a22a700b0042c4118fcfdsi3062020qtb.157.2024.02.08.03.59.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 03:59:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58005-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58005-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58005-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 8405B1C25D33 for ; Thu, 8 Feb 2024 11:59:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A60987AE79; Thu, 8 Feb 2024 11:56:42 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F5FD79DA1; Thu, 8 Feb 2024 11:56:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393400; cv=none; b=Dv1sxkBgJEmfImUZ0dDGCEsse6OlgCbyb1BhwiB6TFH2WrklUoZYLz+WHjFF7rF1FfXWHcqc9a9oDx/YfNxUd69wyHV+8ntrwo5mfoRZDbibP7ZBh5OdB92m+L+nftu1Umeu9qNi7FuB4BIQElXCBrq0R3t2dxZJPUkEkj291ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393400; c=relaxed/simple; bh=OoFrzVwdfR8MuA4B3/NSqIrR20qh/M0U8am5P3jts3o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gZ89Zw/TrzrjqAYHntSSVxAUjpQzvOEVvsK0iTIznzBhVqdoNOwdKbFSi0lgoX8h/Wede2GwYSOlIowuZ2ra2tg5AH0T+PCYso5o3sxBrT/Yfvg1fvroVSF5sdbesD/K2PBDUP4hjcytCBjCqhMTgsTvXf9wZ8dptuVvAUjCwp8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E565A1FB; Thu, 8 Feb 2024 03:57:20 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1013B3F5A1; Thu, 8 Feb 2024 03:56:35 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 11/23] PM: EM: Introduce em_dev_update_perf_domain() for EM updates Date: Thu, 8 Feb 2024 11:55:45 +0000 Message-Id: <20240208115557.1273962-12-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790331945911961435 X-GMAIL-MSGID: 1790331945911961435 Add API function em_dev_update_perf_domain() which allows the EM to be changed safely. Concurrent updaters are serialized with a mutex and the removal of memory that will not be used any more is carried out with the help of RCU. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 8 +++++++ kernel/power/energy_model.c | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 27911dc1887e..324a3a8e0a2d 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -183,6 +183,8 @@ struct em_data_callback { struct em_perf_domain *em_cpu_get(int cpu); struct em_perf_domain *em_pd_get(struct device *dev); +int em_dev_update_perf_domain(struct device *dev, + struct em_perf_table __rcu *new_table); int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, struct em_data_callback *cb, cpumask_t *span, bool microwatts); @@ -376,6 +378,12 @@ struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd) return NULL; } static inline void em_table_free(struct em_perf_table __rcu *table) {} +static inline +int em_dev_update_perf_domain(struct device *dev, + struct em_perf_table __rcu *new_table) +{ + return -EINVAL; +} #endif #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 16795743f969..667619b70be7 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -209,6 +209,50 @@ static int em_allocate_perf_table(struct em_perf_domain *pd, return 0; } +/** + * em_dev_update_perf_domain() - Update runtime EM table for a device + * @dev : Device for which the EM is to be updated + * @new_table : The new EM table that is going to be used from now + * + * Update EM runtime modifiable table for the @dev using the provided @table. + * + * This function uses a mutex to serialize writers, so it must not be called + * from a non-sleeping context. + * + * Return 0 on success or an error code on failure. + */ +int em_dev_update_perf_domain(struct device *dev, + struct em_perf_table __rcu *new_table) +{ + struct em_perf_table __rcu *old_table; + struct em_perf_domain *pd; + + if (!dev) + return -EINVAL; + + /* Serialize update/unregister or concurrent updates */ + mutex_lock(&em_pd_mutex); + + if (!dev->em_pd) { + mutex_unlock(&em_pd_mutex); + return -EINVAL; + } + pd = dev->em_pd; + + kref_get(&new_table->kref); + + old_table = pd->em_table; + rcu_assign_pointer(pd->em_table, new_table); + + em_cpufreq_update_efficiencies(dev, new_table->state); + + em_table_free(old_table); + + mutex_unlock(&em_pd_mutex); + return 0; +} +EXPORT_SYMBOL_GPL(em_dev_update_perf_domain); + static int em_create_runtime_table(struct em_perf_domain *pd) { struct em_perf_table __rcu *table; From patchwork Thu Feb 8 11:55: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: 198352 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp116000dyd; Thu, 8 Feb 2024 04:06:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFY9Kd6IzK80XT7hxz4pKOZnek28vP0+QnzcihvKIH8rPse5amE3hsdHjdDb2i7AOWwRrj0 X-Received: by 2002:aa7:d902:0:b0:560:9277:80e5 with SMTP id a2-20020aa7d902000000b00560927780e5mr6064084edr.21.1707394012649; Thu, 08 Feb 2024 04:06:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707394012; cv=pass; d=google.com; s=arc-20160816; b=B6v70fK6DNwXLKAHoS1+0LRsjEX8ls9G+Db920CiB+2y4HlMWpqP0AUlpPQpp/AZgu LATRObw5Tu5ZLE7M+D1iaUx7TLB7TA86sVdCM6vmDkbEC9dLdeqtuIVWu33Yr0mmpO5n xZfXZ7QKhwtNqiqGo+c4mizVUlA3zx3hwLy298NAWoIg8xMytlApcOdAbbJltoi/F6L6 AJHUTO5OtF1le9LHbFvUtS+itD8xnTgF/MmNiuFeUgDpj3iUQQnrUvyJVn1nuZxKOc6e gKBFY9YjTE2Fh2Z2BI+gkGx3PKRoSXGNY0zjPbi3G+Wh/p8aGuU+e8zQJjOolJTPa48r DOTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=SYWM+MbdENBgwwJMugawdJXQ8ceIiSWsGOLhNLQcIvU=; fh=UhFVAADUnwsQZOf4MtexnUD976ccA9p7xlp4kXvQPn8=; b=ZAW7sTmciC9YfvcQ6/Bhr0J/WkHPpto4IWyOyqOZgGVpVfcgzgN2qTI6hSUXIgM+jG wLYpzM+e2eWRCj3DMLOSZMj1g4aqzOBo0u+tGxHtb+H+dN7OiozFU8PnDsnweGtAuw0t fXXfcasRXyv1eA+O/ZomD42fLv3NVflgUzsC4UwnTyoMLvb4mzGwOXHqnoZH2CT6USG5 B8gEYCtbQ+7n+ddvoHaWJMzxVwbeWq5RNbahsuV1HAghoBTpSiAt4m8Hvs2klvUnwDmI MDtul4GqROUZtIC6BTRX26wOPsPLgFMOPu1QAM0e9XCn2u3TwVRjf0VIGEbIKyF2BCsm NLpg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58006-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58006-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVJdGPzE/tVfBjGj6Uwke2YoDLrGLNTcwNSoFKpFE+BOrPePHc5+MdcGZeTZKMlaTKU04iV/e0hx7YkL1I5FoHVL5KDEA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dn9-20020a05640222e900b0055deaaf8b06si820164edb.346.2024.02.08.04.06.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:06:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58006-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58006-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58006-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 63E6E1F2C52A for ; Thu, 8 Feb 2024 12:00:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BDBD7318C; Thu, 8 Feb 2024 11:56:45 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F64D7AE62; Thu, 8 Feb 2024 11:56:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393403; cv=none; b=Vq68Qmn7ROtnT37JJ9bUsp3bAU1RuHEv2f0nuHNNxVazEKrbEt77yZeDZe12l0emB18LsTBNxykzRQdnJNt2nTa7OrsgS66Kuh6zW5SYI7A2kzeEr+x3eRGB0BaL+OveS+W3xHJm7bcnnIMyZOVYJKk1kQGdR78rD5hlkoug6D8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393403; c=relaxed/simple; bh=t1KyvAYlPGYt5k4QNfvPcCk4liGk3G3znjAuCwRkKtk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IlMawcnW0V2rpm9OHZbIXaSMDI5BXsm9YBynNnD1geIcME4RrafRyGimkB0lga63BI7jOq4bQwsorGFuvqOC/PNof1VLHNAScUPL3M2fznWYXOK4o5Xgt+c4ycWNrq5chVmV1IpHjReWUY8yFIz7d9vbRG+ghDXov3QZllc1OU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D937F1FB; Thu, 8 Feb 2024 03:57:23 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 055293F5A1; Thu, 8 Feb 2024 03:56:38 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 12/23] PM: EM: Add em_perf_state_from_pd() to get performance states table Date: Thu, 8 Feb 2024 11:55:46 +0000 Message-Id: <20240208115557.1273962-13-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790332384101841782 X-GMAIL-MSGID: 1790332384101841782 Introduce a wrapper to get the performance states table of the performance domain. The function should be called within the RCU read critical section. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 324a3a8e0a2d..158dad6ea313 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -338,6 +338,23 @@ static inline int em_pd_nr_perf_states(struct em_perf_domain *pd) return pd->nr_perf_states; } +/** + * em_perf_state_from_pd() - Get the performance states table of perf. + * domain + * @pd : performance domain for which this must be done + * + * To use this function the rcu_read_lock() should be hold. After the usage + * of the performance states table is finished, the rcu_read_unlock() should + * be called. + * + * Return: the pointer to performance states table of the performance domain + */ +static inline +struct em_perf_state *em_perf_state_from_pd(struct em_perf_domain *pd) +{ + return rcu_dereference(pd->em_table)->state; +} + #else struct em_data_callback {}; #define EM_ADV_DATA_CB(_active_power_cb, _cost_cb) { } @@ -384,6 +401,11 @@ int em_dev_update_perf_domain(struct device *dev, { return -EINVAL; } +static inline +struct em_perf_state *em_perf_state_from_pd(struct em_perf_domain *pd) +{ + return NULL; +} #endif #endif From patchwork Thu Feb 8 11:55:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 198362 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp127524dyd; Thu, 8 Feb 2024 04:27:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOBxVKC8rT1TinIcS6bbypH2MGj5Fi5HusdEzROLPvwWv/5Khd62eLKiqDNTsRzVHW1IVc X-Received: by 2002:a17:90b:4388:b0:296:65ec:3172 with SMTP id in8-20020a17090b438800b0029665ec3172mr5314857pjb.10.1707395269545; Thu, 08 Feb 2024 04:27:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707395269; cv=pass; d=google.com; s=arc-20160816; b=DjObzLn9o3tNL5/r7Gp6UU8Z6/n1Xbb/krAdx1svg2oFMS/sUjY0LxLAUqzGzs2UwQ RoJuNP5iRnLX4kzOF7bqk4gFXjCDTUV45vt0YzrXuVGdljufVzsSd/y+hFaIBv+8aVxk oVNhqQd0zsvVsmkndazNcDAJJ8hKLWaoCkptdcmGYIH8sF1SbO4CEhnarioVjBIsrQRT LV1OyYUiitTgttP2koaqhce2pcxFA9HTjQ5WoazVbL5aY6tyuo0jGvcRkw7Q6LOJIyVC lGASzx5L5HdYA6HB3S1h+kf9RY2IqUwZMFYi0QNBbgQ69rvyVAcUZW+Pdkhn3muxc3QX deZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=t/nVmVAvV3KonidjqGEDM5ZBwwWD64ysvfPAtp1spJk=; fh=akHVmLvl0lkzFu7+9oYTwrXbV7p8vLTB2wkGpa1Yb+E=; b=irGC4on24bSKCSfZZG+pH7d2xQRAjepIX+b6xFs2IB2Q0bk8sD2M4xQK5FnQGYdzaC d/xM8xm7OWY/8ViBzedP5PMTbjJ+GGUtBrvD0mdxeGifHgcPRhBG/EUlzxG8Bt5/EfHW spAvGBO3NtI9yjky5V1eWFTXT/gtTzeYzQvxSziJrarpxfr02ESc2/+hwxAVu/PSURmV ADqzW/5YJHLDfsbRKfpka4Xz0KucNEqHASiKUmOD3iH0SMcqLUDs2sKCOKXLTMIr8QLT nvrbEkONNYOlK9wH3+rU3GeVVu9NqzM8REbERW+gbNPvSK8WP39rgnuXL2u5Q4iJW9AP r6bA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58008-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58008-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUNx3MbO26xq78lvAPBsWM78OzHFaEKX/IC1MnZH+1GTlAYgbDfuVcSNg85W7exH7ZQt1kMwTSY+PUVpkHku4urrI2L5Q== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id dj16-20020a17090ad2d000b00296426bc1a3si1299788pjb.168.2024.02.08.04.27.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:27:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58008-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58008-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58008-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 4C392B2447F for ; Thu, 8 Feb 2024 12:00:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC69971B38; Thu, 8 Feb 2024 11:56:51 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 195817B3F2; Thu, 8 Feb 2024 11:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393409; cv=none; b=fyBf7mwY1+kVneeoVFAA1nCNMI86fVLaZp91uFJDmlTBL3noZbDIAkls5cAHC5hjsOxZOGB7KTF6qEpRhuFB9frfXqIE3foWRvHmX2QYFNclwGLMzV8+k/UrNq7vAYZr12bfgq17ir5m17yO8ZwkMJO9rbKYyRtqzVY5nGhla5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393409; c=relaxed/simple; bh=ZR61DaeFcB991ir0orXLWZ0iQoLKSU51+OwfZAOti0Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VK6bjMl8USVlC87Y8c2kKGqIeMmzYjIWqJXzC69LPoTwup5bxEzsmCyMC25Z2u8UVtCz8p0ZbezlNMIrZ3v9w0GmPpUgWI62jKnKMSJVBSqEEkVKQd0652BHVliZno3oxd5ewjiZ5Cl3ps3ydQT8yi4kiY4J0e7IviGNf9G1J7M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 03AB51FB; Thu, 8 Feb 2024 03:57:30 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 24D8F3F5A1; Thu, 8 Feb 2024 03:56: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, xuewen.yan94@gmail.com Subject: [PATCH v8 14/23] PM: EM: Support late CPUs booting and capacity adjustment Date: Thu, 8 Feb 2024 11:55:48 +0000 Message-Id: <20240208115557.1273962-15-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790333701912755141 X-GMAIL-MSGID: 1790333701912755141 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. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 124 ++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 41418aa6daa6..b192b0ac8c6e 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -25,6 +25,9 @@ static DEFINE_MUTEX(em_pd_mutex); static void em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table); +static void em_check_capacity_update(void); +static void em_update_workfn(struct work_struct *work); +static DECLARE_DELAYED_WORK(em_update_work, em_update_workfn); static bool _is_cpu_device(struct device *dev) { @@ -583,6 +586,10 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, unlock: mutex_unlock(&em_pd_mutex); + + if (_is_cpu_device(dev)) + em_check_capacity_update(); + return ret; } EXPORT_SYMBOL_GPL(em_dev_register_perf_domain); @@ -618,3 +625,120 @@ void em_dev_unregister_perf_domain(struct device *dev) mutex_unlock(&em_pd_mutex); } EXPORT_SYMBOL_GPL(em_dev_unregister_perf_domain); + +/* + * Adjustment of CPU performance values after boot, when all CPUs capacites + * are correctly calculated. + */ +static void em_adjust_new_capacity(struct device *dev, + struct em_perf_domain *pd, + u64 max_cap) +{ + struct em_perf_table __rcu *em_table; + struct em_perf_state *ps, *new_ps; + int ret, ps_size; + + em_table = em_table_alloc(pd); + if (!em_table) { + dev_warn(dev, "EM: allocation failed\n"); + return; + } + + new_ps = em_table->state; + + rcu_read_lock(); + ps = em_perf_state_from_pd(pd); + /* Initialize data based on old table */ + ps_size = sizeof(struct em_perf_state) * pd->nr_perf_states; + memcpy(new_ps, ps, ps_size); + + rcu_read_unlock(); + + em_init_performance(dev, pd, new_ps, pd->nr_perf_states); + ret = em_compute_costs(dev, new_ps, NULL, pd->nr_perf_states, + pd->flags); + if (ret) { + dev_warn(dev, "EM: compute costs failed\n"); + return; + } + + ret = em_dev_update_perf_domain(dev, em_table); + if (ret) + dev_warn(dev, "EM: update failed %d\n", ret); + + /* + * This is one-time-update, so give up the ownership in this updater. + * The EM framework has incremented the usage counter and from now + * will keep the reference (then free the memory when needed). + */ + em_table_free(em_table); +} + +static void em_check_capacity_update(void) +{ + cpumask_var_t cpu_done_mask; + struct em_perf_state *table; + struct em_perf_domain *pd; + unsigned long cpu_capacity; + int cpu; + + if (!zalloc_cpumask_var(&cpu_done_mask, GFP_KERNEL)) { + pr_warn("no free memory\n"); + return; + } + + /* Check if CPUs capacity has changed than update EM */ + for_each_possible_cpu(cpu) { + struct cpufreq_policy *policy; + unsigned long em_max_perf; + struct device *dev; + int nr_states; + + if (cpumask_test_cpu(cpu, cpu_done_mask)) + continue; + + policy = cpufreq_cpu_get(cpu); + if (!policy) { + pr_debug("Accessing cpu%d policy failed\n", cpu); + schedule_delayed_work(&em_update_work, + msecs_to_jiffies(1000)); + break; + } + cpufreq_cpu_put(policy); + + pd = em_cpu_get(cpu); + if (!pd || em_is_artificial(pd)) + continue; + + cpumask_or(cpu_done_mask, cpu_done_mask, + em_span_cpus(pd)); + + nr_states = pd->nr_perf_states; + cpu_capacity = arch_scale_cpu_capacity(cpu); + + rcu_read_lock(); + table = em_perf_state_from_pd(pd); + em_max_perf = table[pd->nr_perf_states - 1].performance; + rcu_read_unlock(); + + /* + * Check if the CPU capacity has been adjusted during boot + * and trigger the update for new performance values. + */ + if (em_max_perf == cpu_capacity) + continue; + + pr_debug("updating cpu%d cpu_cap=%lu old capacity=%lu\n", + cpu, cpu_capacity, em_max_perf); + + dev = get_cpu_device(cpu); + em_adjust_new_capacity(dev, pd, cpu_capacity); + } + + free_cpumask_var(cpu_done_mask); +} + +static void em_update_workfn(struct work_struct *work) +{ + em_check_capacity_update(); +} From patchwork Thu Feb 8 11:55: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: 198347 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp113221dyd; Thu, 8 Feb 2024 04:02:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVXm96VFsZrOzI6sUzfW4LNndfIoLPo/QUk24L6vJOvgdSF8VB1kZGH0FOvXOgjuoDNCaegnEYHt9LNTBbA7Xq0inw/YA== X-Google-Smtp-Source: AGHT+IHJqV3MpAr8bgP1EPqP4uckzNieRqNPR1VWo+dsgGWHBlELeuEhCxTUiKfJfXgs3pqxHXg/ X-Received: by 2002:a05:620a:4d19:b0:783:e9ba:7d4c with SMTP id wa25-20020a05620a4d1900b00783e9ba7d4cmr9616412qkn.23.1707393760087; Thu, 08 Feb 2024 04:02:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393760; cv=pass; d=google.com; s=arc-20160816; b=v8H+umDWn6n0rTpy6SaEXBRVEIxNmoR5b8jhavxnobd+gjefH5CfeBeaWFQlz7hLSi QE5KrFAQ+yUe6HWbjGhWHFxFhBkoDldOKfi9+/kFcMmGaVBJI8+K0WH0VamsUvTYWS2n gWbQ98PeYU+reQbX2ipxBDGFkDcPkTNXy7Q0AIOESy9yHy4K2v4NLmegWpZJ/VDBcBDs IpK0n+XB9ndbyseGLZZpKjA7v0ROfDFSScJROm1Sljnnxx1PDOoNLQPs9Ps75WE0fjHA kEAK85uKS6uys+o40HKU5Y1xV96thwo5kj+d6NvBHs67VOH4Z5dwc3qFpZHYv4EyyUrk P0ig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=M9xV9Fr+e7f6l0YF9FW+xsj3vZaJfVBxIMtTVYzVO/g=; fh=dg/VQKi2UieVX7/IQuZltGlGxhWXcV1zv/4NyBOTJO8=; b=U2ObeWpHaWdXNGyLFgJeRjkaaPNvL8BkI74/qqKcZgjQ99FkaTUYtxcQ98qTUmtiv5 8BuxlqA2ngP6krhGYC0EtS0cNpaFrTCvCm8fyBRVlK2NsvvzO2Awt0OvZBa/dHkkyBGL xdNc/NL9fDNF7d8iJ1wlnSbWVgz++l2fwyNC1E//jrmVkFCZ58ZNwp0785r92tN56Evn eYPqDLYFN+pF0eAnLgB11wpE1aI2MMkKYSjXHm73TjwugnezXe085nRAtXWj+HBAUyDa hXGIzqU0zSiBlzwzwaPf0iPfb/0fLkxbTpOrmLeZ65LxglPuGvBHoEWIqgWz+FFfI3IE ggIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58010-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58010-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWCrHW9xkkIr40NQOVPaEysBK2kg4XCiOAXSKNqqKE58ypNL7HuEVwKIi5kH05NQOEVZ+eo/UExx1WkD6oqLQ2xEvRc5A== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id wg10-20020a05620a568a00b007857d38b181si386156qkn.708.2024.02.08.04.02.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:02:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58010-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58010-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58010-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 515FD1C285FC for ; Thu, 8 Feb 2024 12:01:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1EA87D406; Thu, 8 Feb 2024 11:56:57 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47A547CF1E; Thu, 8 Feb 2024 11:56:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393416; cv=none; b=fW0B7D8iMNiJYHiiFa9Z9Laq8QiKLYS2pDtC2pl2PQyxkObnJuUVzbzJDIVfOpeQAYzAmCjWDqrMw5+yfjI8NDupqIIKYw+yeCHpT3x8TK7Jg5sAjy+feGgaWFDLCdXZbAQvj72FOkJyAQZ5S85hH3MKel9OCTeF96cEcy4jEsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393416; c=relaxed/simple; bh=8Gb0YkEvYUITCwedTOxqRk/oFDUD0wCdBVpfWbXqFYQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pJy991IgPinO0F3sObMBuHJ2xuSNmlvN5wTILxGFyOqfaAkaHcTD20/lHsDxFw+VLSOYd5KYRE1qLx9VlmAKxxEL0y3TCpXeeDpnD5k4es+ZpG+WzImbx42y0wf7t0DirNKm+WQoM3yXcBsUxtltg2INYufEKOW4lllMhRb5hhI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DE7231FB; Thu, 8 Feb 2024 03:57:35 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0D1F73F5A1; Thu, 8 Feb 2024 03:56:50 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 16/23] powercap/dtpm_cpu: Use new Energy Model interface to get table Date: Thu, 8 Feb 2024 11:55:50 +0000 Message-Id: <20240208115557.1273962-17-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790332119148149709 X-GMAIL-MSGID: 1790332119148149709 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. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- drivers/powercap/dtpm_cpu.c | 39 +++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c index 9193c3b8edeb..ee0d1aa3e023 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,22 @@ 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); + rcu_read_lock(); + table = em_perf_state_from_pd(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; + rcu_read_unlock(); freq_qos_update_request(&dtpm_cpu->qos_req, freq); - power_limit = pd->table[i - 1].power * nr_cpus; - return power_limit; } @@ -87,9 +90,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 +103,43 @@ static u64 get_pd_power_uw(struct dtpm *dtpm) freq = cpufreq_quick_get(dtpm_cpu->cpu); + rcu_read_lock(); + table = em_perf_state_from_pd(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; } + rcu_read_unlock(); - 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; + rcu_read_lock(); + table = em_perf_state_from_pd(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; + rcu_read_unlock(); + return 0; } @@ -180,6 +195,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 +232,12 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent) if (ret) goto out_kfree_dtpm_cpu; + rcu_read_lock(); + table = em_perf_state_from_pd(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); + rcu_read_unlock(); if (ret) goto out_dtpm_unregister; From patchwork Thu Feb 8 11:55:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 198346 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp113076dyd; Thu, 8 Feb 2024 04:02:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWaNeerAjEpmhgzf4OtIBOAaTkhlliuUC/1UrH0G5mJU69/a/xpA4+OZOxMPDITpL9imvclEazgrteYSxaJfr+LsspKxQ== X-Google-Smtp-Source: AGHT+IFsTU5nS9WyxD0JGwQceQ6zhMsdsP8TeGlfrkfzUYcTBPFYdzBVWKrAcWBq8hgKhujqNkzD X-Received: by 2002:a05:6358:441d:b0:178:7556:11e6 with SMTP id z29-20020a056358441d00b00178755611e6mr6282282rwc.27.1707393750380; Thu, 08 Feb 2024 04:02:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393750; cv=pass; d=google.com; s=arc-20160816; b=sOs1hgdixYPFzS2fPM9aWpwstJgQzHySibpU6/rNfIsIfXEuGx4qdDa0Mj12Xtp11w vlnGIkyzZisxrIKA0lyExfw6CtEOukgHwa6Z8YiVAoigfuxeypmlyQlSdPC3YXSScJ8K uWOryjqXgZ+4MP54NMEkk1/ncGQo4/uGsi7F5Zeirz+hh2hm4NbNJsKEf0hqZWnm2fH2 TUR34xBxQvENbwHo7lTZGyCI9cbYaPbeaCfoEwZzn4lsmktTcbHKAxNc+IzJ44bfgzQA QdR3qXuO6YfrCFGFCX5a6MUsUrDyFJCnMnuTXWvjY7UgkphtUx+ih2v3kJwpmN4P1PFa QGzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=vMCAbN6FWrAVVTpWWUeQRCqOvp55YwzptftZbKiA1Ck=; fh=sTbhvl6h9CpQn4tDXCrv6h2WoKLr7mnOuPnka94/LTc=; b=06j7Hr822Hb86NRwMaHlhXm4y1z9yVTIcu3I7W643bmwfLzcpY781u3VegwkWXmS2a mUoyL6LheQGRtrJzpzh3GC8d6vJb0m8li38NFvJGSx1H6Q/HbpV3L6IXznJQKnTkkaDN aczCFjAkhQz2P5FJfoVmiUUPTfsO/EgQULcGZTTP4QG5Qobp9ZJVlJZOhgd6IUHvvWOC TJgl/hj4n4WQ3KBIFIbRArnKMplxZvGCkw8HWLFqJED05Z/X00lhaz/utPVuvhLbZ+co qZjm876bjn+hj/JRFhSAXc8OZeVQM2obHnkXoB8b5JmuwKHFCA73leCc7KLuYcJGbFX3 LN7g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58014-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58014-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVkzHtjgcvHXdqXFeiUqzRY9Sw7XZhjd0iWK0wRP9xkg/uU84Vaivl+GMQb6hIH7v8l4R70rp3TTLzpkKuKj4/SbeOUuQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id dq9-20020a056a020f8900b005dc4202b412si1627824pgb.196.2024.02.08.04.02.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:02:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58014-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58014-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58014-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 20FF0282227 for ; Thu, 8 Feb 2024 12:02:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B6B07EEF5; Thu, 8 Feb 2024 11:57:09 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE4047EF01; Thu, 8 Feb 2024 11:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393427; cv=none; b=TTDZW8PF7g11GqM9Ykj5u54QSBqcA/8fXFgQHoeE6eH56xG6LxXrFMLh31YQDX/146qUQBCiWLQ4GZAS6GOWOHY6tFsXM5/difGyfxh2riksJYP1CxHIxqvyzZE/Qlr2pL1Z5w+ZcFgWHADuDTraD7sNKRMCducEwRrz1NchOWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393427; c=relaxed/simple; bh=jF9xvV+ffyDXEcEQmXtChRdRJUYNKBG4fWdMvZO8qKc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YKM4RXpawkxUU+qbfbrJnQfClnXoG0MO36xgrwmYzWvvpsve4lmO4xR6A0ilxoQQIrqnVL3Liu8yqcosCPCwCflYHw1MLmsQUPShRSkWjEXOmlanyW8EHzvJ/ag+fBvRu1TJKmtYb6pQGm6FvSdVU4OJg1O9Cand+gSN45oiWxU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A88E3DA7; Thu, 8 Feb 2024 03:57:47 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C8A8B3F5A1; Thu, 8 Feb 2024 03:57:02 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 20/23] PM: EM: Change debugfs configuration to use runtime EM table data Date: Thu, 8 Feb 2024 11:55:54 +0000 Message-Id: <20240208115557.1273962-21-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790332109158567349 X-GMAIL-MSGID: 1790332109158567349 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. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- kernel/power/energy_model.c | 67 ++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 8 deletions(-) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index a631d7d52c40..548908e686ed 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -37,20 +37,65 @@ static bool _is_cpu_device(struct device *dev) #ifdef CONFIG_DEBUG_FS static struct dentry *rootdir; -static void em_debug_create_ps(struct em_perf_state *ps, struct dentry *pd) +struct em_dbg_info { + struct em_perf_domain *pd; + int ps_id; +}; + +#define DEFINE_EM_DBG_SHOW(name, fname) \ +static int em_debug_##fname##_show(struct seq_file *s, void *unused) \ +{ \ + struct em_dbg_info *em_dbg = s->private; \ + struct em_perf_state *table; \ + unsigned long val; \ + \ + rcu_read_lock(); \ + table = em_perf_state_from_pd(em_dbg->pd); \ + val = table[em_dbg->ps_id].name; \ + rcu_read_unlock(); \ + \ + seq_printf(s, "%lu\n", val); \ + return 0; \ +} \ +DEFINE_SHOW_ATTRIBUTE(em_debug_##fname) + +DEFINE_EM_DBG_SHOW(frequency, frequency); +DEFINE_EM_DBG_SHOW(power, power); +DEFINE_EM_DBG_SHOW(cost, cost); +DEFINE_EM_DBG_SHOW(performance, performance); +DEFINE_EM_DBG_SHOW(flags, inefficiency); + +static void em_debug_create_ps(struct em_perf_domain *em_pd, + struct em_dbg_info *em_dbg, int i, + struct dentry *pd) { + struct em_perf_state *table; + unsigned long freq; struct dentry *d; char name[24]; - snprintf(name, sizeof(name), "ps:%lu", ps->frequency); + em_dbg[i].pd = em_pd; + em_dbg[i].ps_id = i; + + rcu_read_lock(); + table = em_perf_state_from_pd(em_pd); + freq = table[i].frequency; + rcu_read_unlock(); + + snprintf(name, sizeof(name), "ps:%lu", freq); /* Create per-ps directory */ d = debugfs_create_dir(name, pd); - debugfs_create_ulong("frequency", 0444, d, &ps->frequency); - debugfs_create_ulong("power", 0444, d, &ps->power); - debugfs_create_ulong("cost", 0444, d, &ps->cost); - debugfs_create_ulong("performance", 0444, d, &ps->performance); - debugfs_create_ulong("inefficient", 0444, d, &ps->flags); + debugfs_create_file("frequency", 0444, d, &em_dbg[i], + &em_debug_frequency_fops); + debugfs_create_file("power", 0444, d, &em_dbg[i], + &em_debug_power_fops); + debugfs_create_file("cost", 0444, d, &em_dbg[i], + &em_debug_cost_fops); + debugfs_create_file("performance", 0444, d, &em_dbg[i], + &em_debug_performance_fops); + debugfs_create_file("inefficient", 0444, d, &em_dbg[i], + &em_debug_inefficiency_fops); } static int em_debug_cpus_show(struct seq_file *s, void *unused) @@ -73,6 +118,7 @@ DEFINE_SHOW_ATTRIBUTE(em_debug_flags); static void em_debug_create_pd(struct device *dev) { + struct em_dbg_info *em_dbg; struct dentry *d; int i; @@ -86,9 +132,14 @@ static void em_debug_create_pd(struct device *dev) debugfs_create_file("flags", 0444, d, dev->em_pd, &em_debug_flags_fops); + em_dbg = devm_kcalloc(dev, dev->em_pd->nr_perf_states, + sizeof(*em_dbg), GFP_KERNEL); + if (!em_dbg) + return; + /* Create a sub-directory for each performance state */ for (i = 0; i < dev->em_pd->nr_perf_states; i++) - em_debug_create_ps(&dev->em_pd->table[i], d); + em_debug_create_ps(dev->em_pd, em_dbg, i, d); } From patchwork Thu Feb 8 11:55:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 198348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp113316dyd; Thu, 8 Feb 2024 04:02:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMctXXwX7kEJLTU4e6NkVF8iY2hRkhzcH9K5Ayde8+Hq5MRA+wDwAD7oczojbc0JRr2m/q X-Received: by 2002:a92:c5a3:0:b0:363:b8fb:fcb7 with SMTP id r3-20020a92c5a3000000b00363b8fbfcb7mr9288179ilt.16.1707393767753; Thu, 08 Feb 2024 04:02:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393767; cv=pass; d=google.com; s=arc-20160816; b=ywXXp7LrP0Nxvs2YfyyNLo2PGPvvVU3upY+ESkk4bWchXL6be7JCBR1WnZDic2rfyS a7RA/TzoXs8WiTATi4pjrkC3ZcSTfSLvvQZ3oVYFfIG97FKqxtWbQW/f1oxe3iwykKGB vEFIT094y5Gq79ucVb8nOrMUYptGOI2EGYc82dFu1o49SpjITqTcCljGgby7/hpwlJdo xUyORMwe6nMN8jdvyZVDBj1JNTDoILiyBNTRXRygGg2mn+jeCYcZFcPkyR8HSTYCGK42 tZtmNJqPnK0WZ5AF8M3wrMJPDsrbZrC4klBmvBxzn/Y6+5JaLW2EMJOUD/lwzXAAKBOZ 7OCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=//BvnQ3lDHfbjL6yCZF7n7+BLmbP89NZh/OS+Rx56VM=; fh=L0224qvgACCloMS/v7LoBVHwIwBMNwkTZzGo+uCKPZA=; b=vMjt5d2gAYqQ/sHDtcJwK5gqEzr3wtqHNl3Mr8UnqwY2J/dtYojPnqOb+lARoDBKwM 0NgXftyiiXu6VzBGsYK2fufjcrr7N0csCiMLW3CRm8O9wS3+rcLXI7BzmtqwT0emzyNK WwhYnKrFBV0Ft9PhGC/zWWVCuK+jkvko7W6wQHNO41JaW9WoVrRbf5bliYog0496fnQs lNDCQpt8/Nb2ur2XN/s8J/iKSm8kbLMF1cOtfZZP62nEpSrqMDs1Z83epogkIgn5etys eg3iBuiZbDk/if1w84M9T1cIn1HFWats0EHLnk9B+CWR5+JlNSXTH8oFnu/coSR0ORtN vgJw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58015-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58015-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCXATlqPfETxbssYpZ8psSe4w+CuG+IzuUCYD3xRtzMzl4n3HMpqQS5i8eP3Im8ZSS+s7DdMwgQGl/lEL7YIPNvop2XRAw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j37-20020a634a65000000b005d7a78810acsi3686834pgl.278.2024.02.08.04.02.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:02:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58015-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58015-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58015-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 77179281E92 for ; Thu, 8 Feb 2024 12:02:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61ED080056; Thu, 8 Feb 2024 11:57:13 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B1AA7F48B; Thu, 8 Feb 2024 11:57:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393430; cv=none; b=HXVKF0RVldHK28FWfYJVPga+SotaGaEP+byAmnGQNM9A1KpmxAQ3YjdnBinbo5P1FkaH9xNG+liOwTvmRSTI96PDyKkRnAZy4yz9nJR5MWqvBU4SP2PRg1SnttTLzyj22tIiGW5uEZTYgpXpf/1pTmezShkz7BZTdp9AgrXecIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393430; c=relaxed/simple; bh=lzHdLn3RnU4KvLq9L4yLPglARNGzesbjMWjFLLMt1MQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fA0unZ3SnH+1hM/ZCfv25flhFrNcmIm0qKc50LpXBDNrMHphJ3qZC709MUkJ/Lhs+K6Y1DjgWdHavKAA5vH7hNeAa81NtufH3qljQNsoQWXiufDp14UyqivdXH8ZjPjOVrMsx8Qi2wC/Gl1aOUfTOjBl7aPLxgSS/gPTN2FRVOI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9B0C31FB; Thu, 8 Feb 2024 03:57:50 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BCACA3F5A1; Thu, 8 Feb 2024 03:57:05 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 21/23] PM: EM: Remove old table Date: Thu, 8 Feb 2024 11:55:55 +0000 Message-Id: <20240208115557.1273962-22-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790332127400467913 X-GMAIL-MSGID: 1790332127400467913 Remove the old EM table which wasn't able to modify the data. Clean the unneeded function and refactor the code a bit. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 2 -- kernel/power/energy_model.c | 46 ++++++------------------------------ 2 files changed, 7 insertions(+), 41 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index aabfc26fcd31..92866a81abe4 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -53,7 +53,6 @@ struct em_perf_table { /** * struct em_perf_domain - Performance domain - * @table: List of performance states, in ascending order * @em_table: Pointer to the runtime modifiable em_perf_table * @nr_perf_states: Number of performance states * @flags: See "em_perf_domain flags" @@ -69,7 +68,6 @@ struct em_perf_table { * field is unused. */ struct em_perf_domain { - struct em_perf_state *table; struct em_perf_table __rcu *em_table; int nr_perf_states; unsigned long flags; diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 548908e686ed..57838d28af85 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -276,17 +276,6 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, return 0; } -static int em_allocate_perf_table(struct em_perf_domain *pd, - int nr_states) -{ - pd->table = kcalloc(nr_states, sizeof(struct em_perf_state), - GFP_KERNEL); - if (!pd->table) - return -ENOMEM; - - return 0; -} - /** * em_dev_update_perf_domain() - Update runtime EM table for a device * @dev : Device for which the EM is to be updated @@ -331,24 +320,6 @@ int em_dev_update_perf_domain(struct device *dev, } EXPORT_SYMBOL_GPL(em_dev_update_perf_domain); -static int em_create_runtime_table(struct em_perf_domain *pd) -{ - struct em_perf_table __rcu *table; - int table_size; - - table = em_table_alloc(pd); - if (!table) - return -ENOMEM; - - /* Initialize runtime table with existing data */ - table_size = sizeof(struct em_perf_state) * pd->nr_perf_states; - memcpy(table->state, pd->table, table_size); - - rcu_assign_pointer(pd->em_table, table); - - return 0; -} - static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd, struct em_perf_state *table, struct em_data_callback *cb, @@ -409,6 +380,7 @@ static int em_create_pd(struct device *dev, int nr_states, struct em_data_callback *cb, cpumask_t *cpus, unsigned long flags) { + struct em_perf_table __rcu *em_table; struct em_perf_domain *pd; struct device *cpu_dev; int cpu, ret, num_cpus; @@ -435,17 +407,15 @@ static int em_create_pd(struct device *dev, int nr_states, pd->nr_perf_states = nr_states; - ret = em_allocate_perf_table(pd, nr_states); - if (ret) + em_table = em_table_alloc(pd); + if (!em_table) goto free_pd; - ret = em_create_perf_table(dev, pd, pd->table, cb, flags); + ret = em_create_perf_table(dev, pd, em_table->state, cb, flags); if (ret) goto free_pd_table; - ret = em_create_runtime_table(pd); - if (ret) - goto free_pd_table; + rcu_assign_pointer(pd->em_table, em_table); if (_is_cpu_device(dev)) for_each_cpu(cpu, cpus) { @@ -458,7 +428,7 @@ static int em_create_pd(struct device *dev, int nr_states, return 0; free_pd_table: - kfree(pd->table); + kfree(em_table); free_pd: kfree(pd); return -EINVAL; @@ -629,7 +599,7 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, dev->em_pd->flags |= flags; - em_cpufreq_update_efficiencies(dev, dev->em_pd->table); + em_cpufreq_update_efficiencies(dev, dev->em_pd->em_table->state); em_debug_create_pd(dev); dev_info(dev, "EM: created perf domain\n"); @@ -666,8 +636,6 @@ void em_dev_unregister_perf_domain(struct device *dev) mutex_lock(&em_pd_mutex); em_debug_remove_pd(dev); - kfree(dev->em_pd->table); - em_table_free(dev->em_pd->em_table); kfree(dev->em_pd); From patchwork Thu Feb 8 11:55:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 198349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp113891dyd; Thu, 8 Feb 2024 04:03:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV1L8yYeM9DtLnS5YMLfjD7pMMdED7wOi/5rLx//OWnUIiOTdsLA2EQPv2Gff0rGmrlWCBOrvi7/LZ2hQd0R+S18BSqCQ== X-Google-Smtp-Source: AGHT+IGhEkFSi+y9nwLpZj/e9F3fu0I68WoWELvGOfMdq88PE8qplkCEJFT4hjQejTcYoDuvuxBU X-Received: by 2002:a05:6214:1c0e:b0:686:8ffe:1278 with SMTP id u14-20020a0562141c0e00b006868ffe1278mr9489609qvc.4.1707393815943; Thu, 08 Feb 2024 04:03:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707393815; cv=pass; d=google.com; s=arc-20160816; b=c42hPUi9IFuqG0pAt5QLEB5nHxiqlwmQ5eNd5RS0WstZoS4FEEDvaIqB5SEqwCWADg AhMUSqxHXMdUICJIivZecvNAoIvvdYHWXP9T7qH4qXnE4xQqEjymbXicYD7AwOLnypW3 A95xiSZrwVwMTd9sOKRIQoA/T9Tm4NLNagf1ZxFUAMR/XHxTBCy80cLEIPInL/uL3PAo KVIjO7AiHJntZogjyI6Tyisot4EPavk6DMJKf0SPSbti4sveq618OZ0PaJLdAS6LUO/p BZ7WxFvSE9VRsYkR3LG7tRM1RfbseJ/fgDHq4iO6YpbibruaO7Epym5lhjz8e6FmS2Nq adwQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=MfKVP4hOIZVwFQsZHHBqK1R4iwjUJsWN9z0HxpPHRiM=; fh=nggrAJYqx7Z/Vnlf2hI3iPBYdgyZolz2td3nnMQYo60=; b=pRPqv0IkHAfHFQLkAnrSu4EEHqY+vV4q+2bFBqLaYbz/+Z39+DVL7RJuyHbQeCgKyU FZ2tgXmgfF45GsTp7EnDq5ShDHs4Xx6mDByVS/jwjf8efkU1XTXJGeL2Mpft3y6F9Vcd JUXmdqvZCYJHzhpXyiCEyyLcuhN1hnQRs/aI1vjOnZwrDwgmwzEozCXlOI3rtotC4AbO 8yOjHmLZDvum0Ks0MXfb4z3a6u755UsX0qdlNLWlzTrvyjOInnSgpZmYNpBvowKihvvR 6oly6e91UWYcp6YX7lpLyCLg214aJ3g8w9Vc8BrSOFz9yhKy7SlH27mClhCflOl2ggIT 4OMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58016-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58016-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCV6TFYulq2oXkXa3KwadSHz+HaXnyqbqu3chqWW+8NU0ppUTBFQq8TZrnVA46UgaCC6H45ZCGJ64uD7WLECHNyp8ey4mA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id gw12-20020a0562140f0c00b0068ccc9a0ef4si289605qvb.494.2024.02.08.04.03.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:03:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58016-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58016-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58016-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 721F61C28267 for ; Thu, 8 Feb 2024 12:03:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A5ED81AAA; Thu, 8 Feb 2024 11:57:16 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A84C8002E; Thu, 8 Feb 2024 11:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393434; cv=none; b=ntycIZgKHXyjixu4juEyF3osKVcJUdHohKrjwiguNCYxZNs/JmvrI6PCElVmMpYtd/WbPunfsIX8p3T0YiR2RrK9kAq80vPqojo4QeQRV6EPXIcqUMt0FqIMV+oP35ApNANKECrDTqT+7k4P1Qq03U8pE72rj+qJKHDcF8DBUOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393434; c=relaxed/simple; bh=ObVLAB8KuRCDvRT3WPT0Lj1kkK4Fwrkdi2IV35YawEs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oSdpLl+KRREvPSYZALkQZf8odmTOIghtZrEKSsmUkwL1lPKTcmcoD9LHcG5SsGy/atAuR33888qanNOnQW8bBrVLltnMW/Oo/O0Oa4Zob6X32Rt1b/XT3rFoS6RjIBG+oFEYHU9gjF99gLkRy6oG1x2I4VEyxKYeQXqjPlBpts0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 98F801FB; Thu, 8 Feb 2024 03:57:53 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B03DD3F5A1; Thu, 8 Feb 2024 03:57:08 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 22/23] PM: EM: Add em_dev_compute_costs() Date: Thu, 8 Feb 2024 11:55:56 +0000 Message-Id: <20240208115557.1273962-23-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790332177638859432 X-GMAIL-MSGID: 1790332177638859432 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). Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- include/linux/energy_model.h | 8 ++++++++ kernel/power/energy_model.c | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 92866a81abe4..770755df852f 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -170,6 +170,8 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states, void em_dev_unregister_perf_domain(struct device *dev); struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd); void em_table_free(struct em_perf_table __rcu *table); +int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM @@ -379,6 +381,12 @@ struct em_perf_state *em_perf_state_from_pd(struct em_perf_domain *pd) { return NULL; } +static inline +int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states) +{ + return -EINVAL; +} #endif #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 57838d28af85..7101fa3fa0c0 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -276,6 +276,24 @@ static int em_compute_costs(struct device *dev, struct em_perf_state *table, return 0; } +/** + * em_dev_compute_costs() - Calculate cost values for new runtime EM table + * @dev : Device for which the EM table is to be updated + * @table : The new EM table that is going to get the costs calculated + * + * Calculate the em_perf_state::cost values for new runtime EM table. The + * values are used for EAS during task placement. It also calculates and sets + * the efficiency flag for each performance state. When the function finish + * successfully the EM table is ready to be updated and used by EAS. + * + * Return 0 on success or a proper error in case of failure. + */ +int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states) +{ + return em_compute_costs(dev, table, NULL, nr_states, 0); +} + /** * em_dev_update_perf_domain() - Update runtime EM table for a device * @dev : Device for which the EM is to be updated From patchwork Thu Feb 8 11:55:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Luba X-Patchwork-Id: 198364 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp129753dyd; Thu, 8 Feb 2024 04:31:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVqnACIBYdbaDxqrfQlhFj9wzf06NDMWK4ogrrIEo2CgvOHa3ZbHKp1ASmIfgomynFPzpuuOUeVOrsOEI5Jr/jdv4NK1w== X-Google-Smtp-Source: AGHT+IFeswt7poDMdQ8A/GGkBhO/7VPWqKZm2VHAAcGtrXfD09Ol4vrSpWYNk1iHnnAOBoSsRFpM X-Received: by 2002:a92:d20b:0:b0:363:c386:194a with SMTP id y11-20020a92d20b000000b00363c386194amr7863340ily.25.1707395502132; Thu, 08 Feb 2024 04:31:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707395502; cv=pass; d=google.com; s=arc-20160816; b=JzDN6L2ztEj/9oiQxNmmk8GquzEbkXkHXvgFdjnjGhUh4guzKD52siTiCaWySGs59K ZlTViLQQQlKpouEn6KbtfRaW77ymsmJvo2zfSj0+jBaKinXtvPpBoJKsRvsGGW+scvaB PUpq6h7W1F5GMW/WHrPjZBW8oWw7vcEFO7c2R9aLZg9CbPn7IPUdHaUzDqdRhy92pkWf dGosbuPMyU+kImJ984q6KFbiLJ9wtnOWwJoRpl2Z0LJf3V8+KF+bf412NayhiAJ3BhXn fxmYrJqQ8CGsbq0R5HIfZOwxXn0jpZsnGiwX2T2gNNGLfx7KAI5lb2FtZ1RAe18uCqh/ k2+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=7VNn0mXQAieoIKAnLx28Uwm/UYJepunmgt3GNK/z4BU=; fh=ofa2bUuQV+GBNSE8PpUMmoUFdETFjuTJAEpMnumlNDc=; b=AT3yS/6TitECNRiV7Ugh5GSBkR3CLI3HUIZWxqslRGZuJPwexrC2+id++KHBXlClqs OzCJJOUZGWoMH6Uua8amb3mbwqTs4ZgbRW1XisXzoaxv2a4xg9VOs+hfAy6w7pyWZK3T A2eF3v9Xe+UfW1JiKlZbbmuHTsxKNn6KU405RwhdeIkkRFWB2gS6Oqmpg7rVy7owDObw ZZLdlhKwdo4czONa5r7CFY1Uxzla/t9sEbGNdHZ1yJp99oXOKesDloJqMvJhizJVwFh/ H2jfoZsvplkIgk4FdH07H7KbS7FRogSmsFV5xd0n3SS4r42RXu5teFP2d4VozVBNnvVU POQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58017-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58017-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUoJzvAYdrM0wAIw/1dvdiiW62YxQxv2nu/XdIgjf8p85yjZb0Gr0xvCTpCXIYGuS0j9KuCtKE3YWs5UEPInLgiy74zxg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p28-20020a63741c000000b005d8b49c9b43si4084085pgc.693.2024.02.08.04.31.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 04:31:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58017-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-58017-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58017-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 6EE89B23D24 for ; Thu, 8 Feb 2024 12:03:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBE1D823B4; Thu, 8 Feb 2024 11:57:19 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07AD280C05; Thu, 8 Feb 2024 11:57:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393437; cv=none; b=kQw+dbNy81eAz+//O9CWXiwMTu9zb6X8nr5euZgOPCBDI4nLNZUtGWO7IeLey/zQFVWi07HEZs9yv7Xvgu5ib9Z/EhQLDSkDFwyuhbtv3KIHtSFxga+bMv/uUtHArS/SYe1zp8zMUNWO0coctLpMss2Yo4qzKZTDMMdyZFBLkUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707393437; c=relaxed/simple; bh=mOT08XEByO+LeskfYMHlZjEPu2b3L6qYci807q41tVw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C9sEMfRqKqAQJgjEbFTc2YnfWq1ZRsl4Vqz3XddNyIE1JUX5UUpOjLjKxxlrxOg6tUS6C+DkN1RDpzYarSNKopC5lgtca+xAnNzRENH8KlUKmr6iLDBUGF5Ml9GtfvM+QmjBeRVrlWJ17jBhHfoIOch1WUnuf/7J5HT7d8C5iOA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8C8BBDA7; Thu, 8 Feb 2024 03:57:56 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.8.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id AD0A93F5A1; Thu, 8 Feb 2024 03:57:11 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org Cc: lukasz.luba@arm.com, dietmar.eggemann@arm.com, rui.zhang@intel.com, amit.kucheria@verdurent.com, amit.kachhap@gmail.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, len.brown@intel.com, pavel@ucw.cz, mhiramat@kernel.org, qyousef@layalina.io, wvw@google.com, xuewen.yan94@gmail.com Subject: [PATCH v8 23/23] Documentation: EM: Update with runtime modification design Date: Thu, 8 Feb 2024 11:55:57 +0000 Message-Id: <20240208115557.1273962-24-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208115557.1273962-1-lukasz.luba@arm.com> References: <20240208115557.1273962-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790333946026945889 X-GMAIL-MSGID: 1790333946026945889 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. Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Signed-off-by: Lukasz Luba --- Documentation/power/energy-model.rst | 183 ++++++++++++++++++++++++++- 1 file changed, 179 insertions(+), 4 deletions(-) diff --git a/Documentation/power/energy-model.rst b/Documentation/power/energy-model.rst index 13225965c9a4..ada4938c37e5 100644 --- a/Documentation/power/energy-model.rst +++ b/Documentation/power/energy-model.rst @@ -71,6 +71,31 @@ whose performance is scaled together. Performance domains generally have a required to have the same micro-architecture. CPUs in different performance domains can have different micro-architectures. +To better reflect power variation due to static power (leakage) the EM +supports runtime modifications of the power values. The mechanism relies on +RCU to free the modifiable EM perf_state table memory. Its user, the task +scheduler, also uses RCU to access this memory. The EM framework provides +API for allocating/freeing the new memory for the modifiable EM table. +The old memory is freed automatically using RCU callback mechanism when there +are no owners anymore for the given EM runtime table instance. This is tracked +using kref mechanism. The device driver which provided the new EM at runtime, +should call EM API to free it safely when it's no longer needed. The EM +framework will handle the clean-up when it's possible. + +The kernel code which want to modify the EM values is protected from concurrent +access using a mutex. Therefore, the device driver code must run in sleeping +context when it tries to modify the EM. + +With the runtime modifiable EM we switch from a 'single and during the entire +runtime static EM' (system property) design to a 'single EM which can be +changed during runtime according e.g. to the workload' (system and workload +property) design. + +It is possible also to modify the CPU performance values for each EM's +performance state. Thus, the full power and performance profile (which +is an exponential curve) can be changed according e.g. to the workload +or system property. + 2. Core APIs ------------ @@ -175,10 +200,82 @@ CPUfreq governor is in use in case of CPU device. Currently this calculation is not provided for other type of devices. More details about the above APIs can be found in ```` -or in Section 2.4 +or in Section 2.5 + + +2.4 Runtime modifications +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Drivers willing to update the EM at runtime should use the following dedicated +function to allocate a new instance of the modified EM. The API is listed +below:: + + struct em_perf_table __rcu *em_table_alloc(struct em_perf_domain *pd); + +This allows to allocate a structure which contains the new EM table with +also RCU and kref needed by the EM framework. The 'struct em_perf_table' +contains array 'struct em_perf_state state[]' which is a list of performance +states in ascending order. That list must be populated by the device driver +which wants to update the EM. The list of frequencies can be taken from +existing EM (created during boot). The content in the 'struct em_perf_state' +must be populated by the driver as well. + +This is the API which does the EM update, using RCU pointers swap:: + + int em_dev_update_perf_domain(struct device *dev, + struct em_perf_table __rcu *new_table); + +Drivers must provide a pointer to the allocated and initialized new EM +'struct em_perf_table'. That new EM will be safely used inside the EM framework +and will be visible to other sub-systems in the kernel (thermal, powercap). +The main design goal for this API is to be fast and avoid extra calculations +or memory allocations at runtime. When pre-computed EMs are available in the +device driver, than it should be possible to simply re-use them with low +performance overhead. + +In order to free the EM, provided earlier by the driver (e.g. when the module +is unloaded), there is a need to call the API:: + + void em_table_free(struct em_perf_table __rcu *table); + +It will allow the EM framework to safely remove the memory, when there is +no other sub-system using it, e.g. EAS. + +To use the power values in other sub-systems (like thermal, powercap) there is +a need to call API which protects the reader and provide consistency of the EM +table data:: + + struct em_perf_state *em_perf_state_from_pd(struct em_perf_domain *pd); + +It returns the 'struct em_perf_state' pointer which is an array of performance +states in ascending order. +This function must be called in the RCU read lock section (after the +rcu_read_lock()). When the EM table is not needed anymore there is a need to +call rcu_real_unlock(). In this way the EM safely uses the RCU read section +and protects the users. It also allows the EM framework to manage the memory +and free it. More details how to use it can be found in Section 3.2 in the +example driver. + +There is dedicated API for device drivers to calculate em_perf_state::cost +values:: + + int em_dev_compute_costs(struct device *dev, struct em_perf_state *table, + int nr_states); + +These 'cost' values from EM are used in EAS. The new EM table should be passed +together with the number of entries and device pointer. When the computation +of the cost values is done properly the return value from the function is 0. +The function takes care for right setting of inefficiency for each performance +state as well. It updates em_perf_state::flags accordingly. +Then such prepared new EM can be passed to the em_dev_update_perf_domain() +function, which will allow to use it. + +More details about the above APIs can be found in ```` +or in Section 3.2 with an example code showing simple implementation of the +updating mechanism in a device driver. -2.4 Description details of this API +2.5 Description details of this API ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. kernel-doc:: include/linux/energy_model.h :internal: @@ -187,8 +284,11 @@ or in Section 2.4 :export: -3. Example driver ------------------ +3. Examples +----------- + +3.1 Example driver with EM registration +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The CPUFreq framework supports dedicated callback for registering the EM for a given CPU(s) 'policy' object: cpufreq_driver::register_em(). @@ -242,3 +342,78 @@ EM framework:: 39 static struct cpufreq_driver foo_cpufreq_driver = { 40 .register_em = foo_cpufreq_register_em, 41 }; + + +3.2 Example driver with EM modification +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This section provides a simple example of a thermal driver modifying the EM. +The driver implements a foo_thermal_em_update() function. The driver is woken +up periodically to check the temperature and modify the EM data:: + + -> drivers/soc/example/example_em_mod.c + + 01 static void foo_get_new_em(struct foo_context *ctx) + 02 { + 03 struct em_perf_table __rcu *em_table; + 04 struct em_perf_state *table, *new_table; + 05 struct device *dev = ctx->dev; + 06 struct em_perf_domain *pd; + 07 unsigned long freq; + 08 int i, ret; + 09 + 10 pd = em_pd_get(dev); + 11 if (!pd) + 12 return; + 13 + 14 em_table = em_table_alloc(pd); + 15 if (!em_table) + 16 return; + 17 + 18 new_table = em_table->state; + 19 + 20 rcu_read_lock(); + 21 table = em_perf_state_from_pd(pd); + 22 for (i = 0; i < pd->nr_perf_states; i++) { + 23 freq = table[i].frequency; + 24 foo_get_power_perf_values(dev, freq, &new_table[i]); + 25 } + 26 rcu_read_unlock(); + 27 + 28 /* Calculate 'cost' values for EAS */ + 29 ret = em_dev_compute_costs(dev, table, pd->nr_perf_states); + 30 if (ret) { + 31 dev_warn(dev, "EM: compute costs failed %d\n", ret); + 32 em_free_table(em_table); + 33 return; + 34 } + 35 + 36 ret = em_dev_update_perf_domain(dev, em_table); + 37 if (ret) { + 38 dev_warn(dev, "EM: update failed %d\n", ret); + 39 em_free_table(em_table); + 40 return; + 41 } + 42 + 43 /* + 44 * Since it's one-time-update drop the usage counter. + 45 * The EM framework will later free the table when needed. + 46 */ + 47 em_table_free(em_table); + 48 } + 49 + 50 /* + 51 * Function called periodically to check the temperature and + 52 * update the EM if needed + 53 */ + 54 static void foo_thermal_em_update(struct foo_context *ctx) + 55 { + 56 struct device *dev = ctx->dev; + 57 int cpu; + 58 + 59 ctx->temperature = foo_get_temp(dev, ctx); + 60 if (ctx->temperature < FOO_EM_UPDATE_TEMP_THRESHOLD) + 61 return; + 62 + 63 foo_get_new_em(ctx); + 64 }