From patchwork Fri Nov 8 16:36:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 13868516 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D65E1974FA; Fri, 8 Nov 2024 16:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731084395; cv=none; b=kgViCzX/CvAys0mentgFMng3e60+2GuTqb9ZS3YZm9ix5STC/UVvhWt1M1FrKTCWJ0+NXrGF1X7eIg6ZbtHW0X8h5wUXkEnsQAl60jb29xUvk7QpDLYmNkqA0nOKnaAuOLDkbJyr2vmW/80bKk7KOBF6gUkyLUe67l0JAq65l7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731084395; c=relaxed/simple; bh=TULGYlML1sIhPReD5NLf2WnpNAK3uqkDVsOXeFWx3Gw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=b1Ih4zFNYiY/NVC+u1ajGeV+Ag+kalY3kp60VPubUQ7vrCm6e5BmHtqE4pWWPjdzNxAsyDUxJKkZ1hbfd/EKnTyAAt1ssT9mFMxz3k044BZ6yqyowK9qkP/bFkcpyMgEeMi3djYD1H7MJ3S1WjUqVKHRihBYfAB+ODE3qViivjE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=L+uvjbMu reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="L+uvjbMu" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.1) id 816be685936a7f17; Fri, 8 Nov 2024 17:46:26 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 03B14834811; Fri, 8 Nov 2024 17:46:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1731084386; bh=TULGYlML1sIhPReD5NLf2WnpNAK3uqkDVsOXeFWx3Gw=; h=From:Subject:Date; b=L+uvjbMuK9pjUTo6SZn+P63DXXYsKpy5vMm98PaeSakg5NcIXCXdV9/Dz7Fapg+7b DdpGN0lubgwWrmn5VIq9sItWsVRHNFvPqE6Neq0wtrA/409/U5D+/cBTrAq40xxhG0 mDCAsfXnLcpaDtiNNjSmLBh6u6ECh14P6sY5RPNmo8DirrNrV1JQl4nLAn0wUc87NJ qzVAayKKryPDRNi8880vXD58UbrE1Dk9zbz9CNn/sWc5Z8tpvSiH1SyZJktw9daz7B sqReUkXvtODBrQ8xz42OzKgMVHg2ySmeDw0gqxbEK9GkXIai2lyVgS5cyU2ucmWpiH +bp1hA6SHxUoA== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Lukasz Luba , Peter Zijlstra , Srinivas Pandruvada , Len Brown , Dietmar Eggemann , Morten Rasmussen , Vincent Guittot , Ricardo Neri Subject: [RFC][PATCH v0.1 1/6] PM: EM: Move perf rebuilding function from schedutil to EM Date: Fri, 08 Nov 2024 17:36:29 +0100 Message-ID: <3263759.5fSG56mABF@rjwysocki.net> In-Reply-To: <3607404.iIbC2pHGDl@rjwysocki.net> References: <3607404.iIbC2pHGDl@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefuddrtdeigdeklecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopedutddprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthg X-DCC--Metrics: v370.home.net.pl 0; Body=10 Fuz1=10 Fuz2=10 From: Rafael J. Wysocki The sugov_eas_rebuild_sd() function defined in the schedutil cpufreq governor implements generic functionality that may be useful in other places. In particular, going forward it will be used in the intel_pstate driver. For this reason, move it from schedutil to the energy model code and rename it to em_rebuild_perf_domains(). This also involves getting rid of some #ifdeffery in schedutil which is a plus. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- include/linux/energy_model.h | 2 ++ kernel/power/energy_model.c | 17 +++++++++++++++++ kernel/sched/cpufreq_schedutil.c | 33 ++++++--------------------------- 3 files changed, 25 insertions(+), 27 deletions(-) Index: linux-pm/kernel/power/energy_model.c =================================================================== --- linux-pm.orig/kernel/power/energy_model.c +++ linux-pm/kernel/power/energy_model.c @@ -908,3 +908,20 @@ int em_update_performance_limits(struct return 0; } EXPORT_SYMBOL_GPL(em_update_performance_limits); + +static void rebuild_sd_workfn(struct work_struct *work) +{ + rebuild_sched_domains_energy(); +} + +static DECLARE_WORK(rebuild_sd_work, rebuild_sd_workfn); + +void em_rebuild_perf_domains(void) +{ + /* + * When called from the cpufreq_register_driver() path, the + * cpu_hotplug_lock is already held, so use a work item to + * avoid nested locking in rebuild_sched_domains(). + */ + schedule_work(&rebuild_sd_work); +} Index: linux-pm/kernel/sched/cpufreq_schedutil.c =================================================================== --- linux-pm.orig/kernel/sched/cpufreq_schedutil.c +++ linux-pm/kernel/sched/cpufreq_schedutil.c @@ -604,31 +604,6 @@ static const struct kobj_type sugov_tuna /********************** cpufreq governor interface *********************/ -#ifdef CONFIG_ENERGY_MODEL -static void rebuild_sd_workfn(struct work_struct *work) -{ - rebuild_sched_domains_energy(); -} - -static DECLARE_WORK(rebuild_sd_work, rebuild_sd_workfn); - -/* - * EAS shouldn't be attempted without sugov, so rebuild the sched_domains - * on governor changes to make sure the scheduler knows about it. - */ -static void sugov_eas_rebuild_sd(void) -{ - /* - * When called from the cpufreq_register_driver() path, the - * cpu_hotplug_lock is already held, so use a work item to - * avoid nested locking in rebuild_sched_domains(). - */ - schedule_work(&rebuild_sd_work); -} -#else -static inline void sugov_eas_rebuild_sd(void) { }; -#endif - struct cpufreq_governor schedutil_gov; static struct sugov_policy *sugov_policy_alloc(struct cpufreq_policy *policy) @@ -783,7 +758,11 @@ static int sugov_init(struct cpufreq_pol if (ret) goto fail; - sugov_eas_rebuild_sd(); + /* + * EAS shouldn't be attempted without sugov, so rebuild the sched_domains + * on governor changes to make sure the scheduler knows about it. + */ + em_rebuild_perf_domains(); out: mutex_unlock(&global_tunables_lock); @@ -827,7 +806,7 @@ static void sugov_exit(struct cpufreq_po sugov_policy_free(sg_policy); cpufreq_disable_fast_switch(policy); - sugov_eas_rebuild_sd(); + em_rebuild_perf_domains(); } static int sugov_start(struct cpufreq_policy *policy) Index: linux-pm/include/linux/energy_model.h =================================================================== --- linux-pm.orig/include/linux/energy_model.h +++ linux-pm/include/linux/energy_model.h @@ -179,6 +179,7 @@ int em_dev_compute_costs(struct device * int em_dev_update_chip_binning(struct device *dev); int em_update_performance_limits(struct em_perf_domain *pd, unsigned long freq_min_khz, unsigned long freq_max_khz); +void em_rebuild_perf_domains(void); /** * em_pd_get_efficient_state() - Get an efficient performance state from the EM @@ -404,6 +405,7 @@ int em_update_performance_limits(struct { return -EINVAL; } +static inline void em_rebuild_perf_domains(void) {} #endif #endif From patchwork Fri Nov 8 16:37:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 13868515 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FF78197A8E; Fri, 8 Nov 2024 16:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731084395; cv=none; b=XO1thm97EA/N9793ggiD0X+AVMuA0OP8tb+uLz19f4Y3LtCe+ifGtyd/fMQNtqkualHbFA1mnZKKHDipDiUgMbhXp3ih/RnBelnD9cjRstcYh8BXPROaBickz1XLoe1nWoioEQE4K2LHjpmdg01GN1ANytObznsumzdm3QAbWP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731084395; c=relaxed/simple; bh=EWHBWVq8c2xPlLQOEUYeio/FxqoJ8rmfYy1j7aExdLU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AS1O+BIEnPCBJGdbrWl7Bf8lF2BvEFsrzG4lkLPtY3HW2AgAKnNJ35GFPz9Rkvql7TsdH1ZrbahnbhrVJ9fhHIvfeHTQCIqK+s+oP9s1HxhS2sK+umcyr1aZqmbRhzY7bJhZesSRcFQVkrj+Ox9SuGI1DB5JhbyI6gjzOWtLNig= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=FEogs6sT reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="FEogs6sT" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.1) id db0b5c1feafc1978; Fri, 8 Nov 2024 17:46:25 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 9B10D834811; Fri, 8 Nov 2024 17:46:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1731084385; bh=EWHBWVq8c2xPlLQOEUYeio/FxqoJ8rmfYy1j7aExdLU=; h=From:Subject:Date; b=FEogs6sT+okuG0ijr0ZDOsqFcaQXyBgl1+9sPqHe8qm9nODAw4KRdWHMJmTI8H3/s ap9aV4B5IQ2D/yVvH9fB36lfoSWu87YFr3RP1FZy4Uuzo7OynUGqGwJ6P62f4ml+WR SemZ35t6qa8fE44TNPOSpcsXss4bUXuY1BS+aYvJBGnAD1XJ83jzfB85iPiROFZ/8a RAN2PgjJpMSPXiaWoIdngtJ3lbRlueX0NrLCVSwzfH3sx27obZjifl3IleIW1+2ret AwC4Krb/xJfQfv9wWQKZziaIKvinx5NhCS3x7Il6izm8RsYco/UnwUGuEiQPa/uMJv YCk0ck++w1zNw== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Lukasz Luba , Peter Zijlstra , Srinivas Pandruvada , Len Brown , Dietmar Eggemann , Morten Rasmussen , Vincent Guittot , Ricardo Neri Subject: [RFC][PATCH v0.1 2/6] PM: EM: Call em_compute_costs() from em_create_perf_table() Date: Fri, 08 Nov 2024 17:37:21 +0100 Message-ID: <1821040.VLH7GnMWUR@rjwysocki.net> In-Reply-To: <3607404.iIbC2pHGDl@rjwysocki.net> References: <3607404.iIbC2pHGDl@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefuddrtdeigdeklecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopedutddprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthg X-DCC--Metrics: v370.home.net.pl 0; Body=10 Fuz1=10 Fuz2=10 From: Rafael J. Wysocki In preparation for subsequent changes, move the em_compute_costs() invocation from em_create_perf_table() to em_create_pd() which is its only caller. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- kernel/power/energy_model.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) Index: linux-pm/kernel/power/energy_model.c =================================================================== --- linux-pm.orig/kernel/power/energy_model.c +++ linux-pm/kernel/power/energy_model.c @@ -388,10 +388,6 @@ static int em_create_perf_table(struct d em_init_performance(dev, pd, table, nr_states); - ret = em_compute_costs(dev, table, cb, nr_states, flags); - if (ret) - return -EINVAL; - return 0; } @@ -434,6 +430,10 @@ static int em_create_pd(struct device *d if (ret) goto free_pd_table; + ret = em_compute_costs(dev, em_table->state, cb, nr_states, flags); + if (ret) + goto free_pd_table; + rcu_assign_pointer(pd->em_table, em_table); if (_is_cpu_device(dev)) From patchwork Fri Nov 8 16:38:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 13868517 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E543D1946C7; Fri, 8 Nov 2024 16:46:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731084396; cv=none; b=VZ4QlpAsUlXsFok+WyFJa1dwvQr/MfSmJmVDVej6d+R6tSnBdhzPpJo7yMP8pYjunzMqZc3IFpmEloMSIcYYUoCEJE6K+c5txSsyinMfVppFO3+ZDN0YLd5WYH0qGzxapI7H3O+7AGRgTpRb8Mu99fQeKGiBXCT6M5/CCU8Snyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731084396; c=relaxed/simple; bh=I/l6yS2A34mcKFYeAnorgxbnF2qkABDnsse+by9CHTU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Zp3XDddMo8GxI3SFz6EhjjnfTnN/g4EEnwYo5vCaG3sqnhsMq6DLK55zgUoFPZJBu5n0Wgt2C0ch0as0Tiz04BLIrdLGQ1fmQfCOR85kE+2O1KwiFtdRQ1Q1t/mENBLDUFkNg5hbp2Kr9A6X2RJUP/4gzqY8TG0N3M9+WMuqC9Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=CziqCWxg reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="CziqCWxg" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.1) id 5734cae46dce7224; Fri, 8 Nov 2024 17:46:25 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 39B41834811; Fri, 8 Nov 2024 17:46:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1731084385; bh=I/l6yS2A34mcKFYeAnorgxbnF2qkABDnsse+by9CHTU=; h=From:Subject:Date; b=CziqCWxg+n7ku4VAECHUivC9CqvzabHHFcHiozFgZyZYFvb+ZXCvFBbz4eVGPUrs/ 8Ro999u4XvOmPOgk0s2nGXHE1L6SVLbNSnhlP1uYXzgArwrZG7bhSZ9B/Xn6mzp0AC MIgpVU9q1pqoezHIQEBBtLb6y22XpDwLHm7hZ23Yfg3avGqo8DxuJu03TxSuUBQikv Ho8bKxQDSEfUiSRzgOKyzLUZt5VhSY1STh7z6O8Hr5jkUgApmORom6PuKSy/f9Vbft vrgzmY8Ln6udaPv142z4qkFun2MNUyY34H2JuLAXQM263Cxo9/cKRYzVC/ecJ9rQ0O hvMSyg+EeUqpw== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Lukasz Luba , Peter Zijlstra , Srinivas Pandruvada , Len Brown , Dietmar Eggemann , Morten Rasmussen , Vincent Guittot , Ricardo Neri Subject: [RFC][PATCH v0.1 3/6] PM: EM: Add special case to em_dev_register_perf_domain() Date: Fri, 08 Nov 2024 17:38:11 +0100 Message-ID: <2017201.usQuhbGJ8B@rjwysocki.net> In-Reply-To: <3607404.iIbC2pHGDl@rjwysocki.net> References: <3607404.iIbC2pHGDl@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefuddrtdeigdeklecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopedutddprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthg X-DCC--Metrics: v370.home.net.pl 0; Body=10 Fuz1=10 Fuz2=10 From: Rafael J. Wysocki Allow em_dev_register_perf_domain() to register a cost-only stub perf domain with one-element states table if the .active_power() callback is not provided. Subsequently, this will be used by the intel_pstate driver to register stub perf domains for CPUs on hybrid systems. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- kernel/power/energy_model.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) Index: linux-pm/kernel/power/energy_model.c =================================================================== --- linux-pm.orig/kernel/power/energy_model.c +++ linux-pm/kernel/power/energy_model.c @@ -426,9 +426,11 @@ static int em_create_pd(struct device *d if (!em_table) goto free_pd; - ret = em_create_perf_table(dev, pd, em_table->state, cb, flags); - if (ret) - goto free_pd_table; + if (cb->active_power) { + ret = em_create_perf_table(dev, pd, em_table->state, cb, flags); + if (ret) + goto free_pd_table; + } ret = em_compute_costs(dev, em_table->state, cb, nr_states, flags); if (ret) @@ -561,11 +563,20 @@ int em_dev_register_perf_domain(struct d { unsigned long cap, prev_cap = 0; unsigned long flags = 0; + bool stub_pd = false; int cpu, ret; if (!dev || !nr_states || !cb) return -EINVAL; + if (!cb->active_power) { + if (!cb->get_cost || nr_states > 1 || microwatts) + return -EINVAL; + + /* Special case: a stub perf domain. */ + stub_pd = true; + } + /* * Use a mutex to serialize the registration of performance domains and * let the driver-defined callback functions sleep. @@ -590,6 +601,15 @@ int em_dev_register_perf_domain(struct d ret = -EEXIST; goto unlock; } + + /* + * The capacity need not be the same for all CPUs in a + * stub perf domain, so long as the average cost of + * running on each of them is approximately the same. + */ + if (stub_pd) + continue; + /* * All CPUs of a domain must have the same * micro-architecture since they all share the same From patchwork Fri Nov 8 16:40:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 13868513 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E53BD19415E; Fri, 8 Nov 2024 16:46:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731084395; cv=none; b=jXNS46LC6+t+FTZ1EMDdt7chSU10m7BHp9N1ykGBl1rECSt5y3QtXJ5EbVNFJuSx0WbmDhJf/RuKDGmGdTob/csG4hMzCiC7ILd+Y1ESxDWMvJ9tJNPaPtURbLYy+FIvb4kGqWfo5SmIze3KbN15nk6AwVu3bCGaA/F8jqESlpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731084395; c=relaxed/simple; bh=a6aZwa1LaDJUrUWhlEpL2OK9yCO3CgJqQ0flWFySIkE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZR/Lw7j9vOVDMZt1tw7AmqgbOEY2n//pkUA+u8PRjLk0s0Y/GLCQvzY2ApuIO8FayABKyzVcxPiqv1YGLmqADKhnEAZ3HHeH2Dm9sudAODC5ugJneLPYp+Lm5RtwdKElLGy5+K4dibTp0bSeLDS+/RAY7fEjtsKeg2sChzTj3RY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=TcP8y+xZ; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="TcP8y+xZ" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.1) id 2ee52bafb25240cc; Fri, 8 Nov 2024 17:46:25 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id C8A3B834811; Fri, 8 Nov 2024 17:46:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1731084384; bh=a6aZwa1LaDJUrUWhlEpL2OK9yCO3CgJqQ0flWFySIkE=; h=From:Subject:Date; b=TcP8y+xZec1zibPMd3rSHYuDZrlkkw3pqp22gJyG4t8AzPMAhO5YttS0FokY4iyAI h0sEXFDrNkhGw3TTA6al/g9Z/gGIx2qPrS6uzD7agOqZEAh7XtXyth+hE0TBmZc4AU y3kep/SXiz9d6nIjphUmgjdexJ1sG12AMos+QC/22jLuQR3dlpQUJDGxBSUsSKJuTv 6ryWlReHX+tNnVOZPhSVW0xiM9Az3G404N1sdO3IZwr7AriyFe5cNuuLjqOt2JumOg ahPp5ce7usuea8t0RKcnvVQWpq8xeW+J3M81sOnKl/d3bGy/+ydjmvWGwiSSMfjMHH AIJCq4a9M0CVA== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Lukasz Luba , Peter Zijlstra , Srinivas Pandruvada , Len Brown , Dietmar Eggemann , Morten Rasmussen , Vincent Guittot , Ricardo Neri Subject: [RFC][PATCH v0.1 4/6] PM: EM: Introduce em_dev_expand_perf_domain() Date: Fri, 08 Nov 2024 17:40:53 +0100 Message-ID: <2223963.Mh6RI2rZIc@rjwysocki.net> In-Reply-To: <3607404.iIbC2pHGDl@rjwysocki.net> References: <3607404.iIbC2pHGDl@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefuddrtdeigdeklecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopedutddprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthg X-DCC--Metrics: v370.home.net.pl 0; Body=10 Fuz1=10 Fuz2=10 From: Rafael J. Wysocki Introduce a helper function for adding a CPU to an existing EM perf domain. Subsequently, this will be used by the intel_pstate driver to add new CPUs to existing perf domains when those CPUs go online for the first time after the initialization of the driver. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- include/linux/energy_model.h | 5 +++++ kernel/power/energy_model.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) Index: linux-pm/kernel/power/energy_model.c =================================================================== --- linux-pm.orig/kernel/power/energy_model.c +++ linux-pm/kernel/power/energy_model.c @@ -696,6 +696,38 @@ void em_dev_unregister_perf_domain(struc } EXPORT_SYMBOL_GPL(em_dev_unregister_perf_domain); +/** + * em_dev_expand_perf_domain() - Expand CPU perf domain + * @dev: CPU device of a CPU in the perf domain. + * @new_cpu: CPU to add to the perf domain. + */ +int em_dev_expand_perf_domain(struct device *dev, int new_cpu) +{ + struct device *new_cpu_dev; + struct em_perf_domain *pd; + + if (IS_ERR_OR_NULL(dev) || !_is_cpu_device(dev)) + return -EINVAL; + + new_cpu_dev = get_cpu_device(new_cpu); + if (!new_cpu_dev) + return -EINVAL; + + guard(mutex)(&em_pd_mutex); + + if (em_pd_get(new_cpu_dev)) + return -EEXIST; + + pd = em_pd_get(dev); + if (!pd) + return -EINVAL; + + cpumask_set_cpu(new_cpu, em_span_cpus(pd)); + new_cpu_dev->em_pd = pd; + + return 0; +} + static struct em_perf_table __rcu *em_table_dup(struct em_perf_domain *pd) { struct em_perf_table __rcu *em_table; Index: linux-pm/include/linux/energy_model.h =================================================================== --- linux-pm.orig/include/linux/energy_model.h +++ linux-pm/include/linux/energy_model.h @@ -172,6 +172,7 @@ int em_dev_register_perf_domain(struct d struct em_data_callback *cb, cpumask_t *span, bool microwatts); void em_dev_unregister_perf_domain(struct device *dev); +int em_dev_expand_perf_domain(struct device *dev, int new_cpu); 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, @@ -354,6 +355,10 @@ int em_dev_register_perf_domain(struct d static inline void em_dev_unregister_perf_domain(struct device *dev) { } +static inline int em_dev_expand_perf_domain(struct device *dev, int new_cpu) +{ + return -EINVAL; +} static inline struct em_perf_domain *em_cpu_get(int cpu) { return NULL; From patchwork Fri Nov 8 16:41:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 13868512 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1773D192D66; Fri, 8 Nov 2024 16:46:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731084394; cv=none; b=trnWbRPHwCmjecFCrStK4T7N7SBS/8nTw02DjjLzvsJwdnEA8vGiZDrdXfVkiUPLw1iwnSDtdKtsNOFYiufg2LkFLppU96iZMooqHpSBJgSwRLtd1vWsbj337FrshwkE5lymFqPBJnKgFO87fdWEjEBC7OZmt0jwmyPk5TELaM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731084394; c=relaxed/simple; bh=cXtVfwFYXyFlu1k+EOgWZE3VZkVVkEP5zIbiuP7gwes=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=i+UXBn/az1/ZlVDjDPLXuktWhghAYCCBpqcXxYzqv4kTDHIp3vE0AgxrO3ia1D7NJAIHbIRhyVP7bQf9+rul4+quj2BQIuhtMvSe1W4mc10WJkISJ2boWDxYav2D7tYbstgltxO3lwMi7RRNIELkPeabiZY4IUjDIzilDb/aqj4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=p8U1bJIQ reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="p8U1bJIQ" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.1) id dbc142109ede4b49; Fri, 8 Nov 2024 17:46:24 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 61161834811; Fri, 8 Nov 2024 17:46:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1731084384; bh=cXtVfwFYXyFlu1k+EOgWZE3VZkVVkEP5zIbiuP7gwes=; h=From:Subject:Date; b=p8U1bJIQybDVQeK04Vd1xUPcQDDCOi4Vlb9UURclUy7kZHg2qmAMsnZafTJK6ro3J QSwjvOUlAOwR3AmUmjqROvC2R6v49YNfFYoKLp4+3c4xPGaSj+LIdaDhWd9XNsO7j2 XnnkOnGtvC22TxRvHoC1BxGZSIlSs/DwwxNw8e4w3Hioe83CWwKAqX7mEYFqfC3SMO ZmIwsRdzzNd2YqO5YN61Dk3KCf/ElMmcIsFpDmuYVBcIkHT8q8wsc2rOtgShU0BO/0 cVN7Q+RPv1bn1ZAuUkNnfm5wnqwiERtRtow8T5hKW/+Loa/BReL0lZruXa9orlyT91 enf2Y6yA9iHYg== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Lukasz Luba , Peter Zijlstra , Srinivas Pandruvada , Len Brown , Dietmar Eggemann , Morten Rasmussen , Vincent Guittot , Ricardo Neri Subject: [RFC][PATCH v0.1 5/6] sched/topology: Allow .setpolicy() cpufreq drivers to enable EAS Date: Fri, 08 Nov 2024 17:41:22 +0100 Message-ID: <1889415.atdPhlSkOF@rjwysocki.net> In-Reply-To: <3607404.iIbC2pHGDl@rjwysocki.net> References: <3607404.iIbC2pHGDl@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefuddrtdeigdeklecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopedutddprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthg X-DCC--Metrics: v370.home.net.pl 0; Body=10 Fuz1=10 Fuz2=10 From: Rafael J. Wysocki Some cpufreq drivers, like intel_pstate, have built-in governors that are used instead of regular cpufreq governors, schedutil in particular, but they can work with EAS just fine, so allow EAS to be used with those drivers. Also update the debug message printed when the cpufreq governor in use is not schedutil and the related comment, to better match the code after the change. Signed-off-by: Rafael J. Wysocki --- I'm not sure how much value there is in refusing to enable EAS without schedutil in general. For instance, if there are no crossover points between the cost curves for different perf domains, EAS may as well be used with the performance and powersave governors AFAICS. --- kernel/sched/topology.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) Index: linux-pm/kernel/sched/topology.c =================================================================== --- linux-pm.orig/kernel/sched/topology.c +++ linux-pm/kernel/sched/topology.c @@ -251,7 +251,7 @@ static bool sched_is_eas_possible(const return false; } - /* Do not attempt EAS if schedutil is not being used. */ + /* Do not attempt EAS with a cpufreq governor other than schedutil. */ for_each_cpu(i, cpu_mask) { policy = cpufreq_cpu_get(i); if (!policy) { @@ -263,9 +263,9 @@ static bool sched_is_eas_possible(const } gov = policy->governor; cpufreq_cpu_put(policy); - if (gov != &schedutil_gov) { + if (gov && gov != &schedutil_gov) { if (sched_debug()) { - pr_info("rd %*pbl: Checking EAS, schedutil is mandatory\n", + pr_info("rd %*pbl: Checking EAS, cpufreq governor is not schedutil\n", cpumask_pr_args(cpu_mask)); } return false; From patchwork Fri Nov 8 16:46:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 13868511 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A604513B29F; Fri, 8 Nov 2024 16:46:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731084394; cv=none; b=D7gtQ5AtqNKJZWuRP6cIX4n5U4VWAPFDSLdWfikN1kxNvcLRw22i7nkLebNfoyD8uVKNyJntkwRIXnw0kp/rFFDq8+QHO+G863x8bTzzClE3eTFaot/LVmCPJxV0K5Mt8QQMYIMTzG/X30LKz0n0kd0qc9zqCBQKZiHzNNKOZXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731084394; c=relaxed/simple; bh=j7p+8eYkmatrxwpdXfGxJJavtt0xbw5+drzotrnuAXQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hkPiD5tpLeyOCBwKELmB9JDScYTBn0zwLi2HKitinZXQ8zIHN4aDptm8hKPkxMOCapIgq2iUDsAHbGNfyVWNId/HUwpGNomp4yp2Pu5kxK9y9SwvWNhcqGhv2WyrIjN1yg/EFRX33E5T0tmrNsqUEEPmTrdoR1YMUoeTj6kz2jk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=GFi6Drdo reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="GFi6Drdo" Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.2.1) id eab63553db22e5e7; Fri, 8 Nov 2024 17:46:23 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 4598E8384AE; Fri, 8 Nov 2024 17:46:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1731084383; bh=j7p+8eYkmatrxwpdXfGxJJavtt0xbw5+drzotrnuAXQ=; h=From:Subject:Date; b=GFi6DrdoBt35wiSU0ClHNrocWF1/GSQ2cq9ryJyd/CvrpestHEWl2RWvxGOwZBece G82x7T8kq6lirpymncOvhZ6AtbTnoPf77xGK6TZAqs63sdbsgv9NOMTyRMw5IEeC1A alMWbBN3O1wE8G+VMAIyngo6Ouj0NOMKpw8AiR2NjrB4Q6sAwaR0MJqcz9TPsl2l4g AWskBB2rw8M4EkZt3eI7shcaaVzoun+WJwjh3YaCC6B8lJHMGMNdipB+t2+wOsPscV xX3pQwxL/nmAPoMmO37Zc6AJuvxNf44uQiG3ERed6XvlzKDv/FslYsDnke9b9Wxbnd a18eqWAHXI+4A== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Lukasz Luba , Peter Zijlstra , Srinivas Pandruvada , Len Brown , Dietmar Eggemann , Morten Rasmussen , Vincent Guittot , Ricardo Neri Subject: [RFC][PATCH v0.1 6/6] cpufreq: intel_pstate: Add basic EAS support on hybrid platforms Date: Fri, 08 Nov 2024 17:46:13 +0100 Message-ID: <115421572.nniJfEyVGO@rjwysocki.net> In-Reply-To: <3607404.iIbC2pHGDl@rjwysocki.net> References: <3607404.iIbC2pHGDl@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefuddrtdeigdeklecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpehrjhifsehrjhifhihsohgtkhhirdhnvghtpdhnsggprhgtphhtthhopedutddprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthg X-DCC--Metrics: v370.home.net.pl 0; Body=10 Fuz1=10 Fuz2=10 From: Rafael J. Wysocki Modify intel_pstate to register stub EM perf domains for CPUs on hybrid platforms via em_dev_register_perf_domain() and to use em_dev_expand_perf_domain() introduced previously for adding new CPUs to existing EM perf domains when those CPUs become online for the first time after driver initialization. This change is targeting platforms (for example, Lunar Lake) where "small" CPUs (E-cores) are always more energy-efficient than the "big" or "performance" CPUs (P-cores) when run at the same HWP performance level, so it is sufficient to tell the EAS that E-cores are always preferred (so long as there is enough spare capacity on one of them to run the given task). Accordingly, the perf domains are registered per CPU type (that is, all P-cores belong to one perf domain and all E-cores belong to another perf domain) and they are registered only if asymmetric CPU capacity is enabled. Each perf domain has a one-element states table and that element only contains the relative cost value (the other fields in it are not initialized, so they are all equal to zero), and the cost value for the E-core perf domain is lower. Signed-off-by: Rafael J. Wysocki --- drivers/cpufreq/intel_pstate.c | 110 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 104 insertions(+), 6 deletions(-) Index: linux-pm/drivers/cpufreq/intel_pstate.c =================================================================== --- linux-pm.orig/drivers/cpufreq/intel_pstate.c +++ linux-pm/drivers/cpufreq/intel_pstate.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -938,6 +939,12 @@ static struct freq_attr *hwp_cpufreq_att NULL, }; +enum hybrid_cpu_type { + HYBRID_PCORE = 0, + HYBRID_ECORE, + HYBRID_NR_TYPES +}; + static struct cpudata *hybrid_max_perf_cpu __read_mostly; /* * Protects hybrid_max_perf_cpu, the capacity_perf fields in struct cpudata, @@ -945,6 +952,86 @@ static struct cpudata *hybrid_max_perf_c */ static DEFINE_MUTEX(hybrid_capacity_lock); +#ifdef CONFIG_ENERGY_MODEL +struct hybrid_em_perf_domain { + cpumask_t cpumask; + struct device *dev; + struct em_data_callback cb; +}; + +static int hybrid_pcore_cost(struct device *dev, unsigned long freq, + unsigned long *cost) +{ + /* + * The number used here needs to be higher than the analogous + * one in hybrid_ecore_cost() below. The units and the actual + * values don't matter. + */ + *cost = 2; + return 0; +} + +static int hybrid_ecore_cost(struct device *dev, unsigned long freq, + unsigned long *cost) +{ + *cost = 1; + return 0; +} + +static struct hybrid_em_perf_domain perf_domains[HYBRID_NR_TYPES] = { + [HYBRID_PCORE] = { .cb.get_cost = hybrid_pcore_cost, }, + [HYBRID_ECORE] = { .cb.get_cost = hybrid_ecore_cost, } +}; + +static bool hybrid_register_perf_domain(struct hybrid_em_perf_domain *pd) +{ + /* + * Registering EM perf domains without asymmetric CPU capacity + * support enabled is wasteful, so don't do that. + */ + if (!hybrid_max_perf_cpu) + return false; + + pd->dev = get_cpu_device(cpumask_first(&pd->cpumask)); + if (!pd->dev) + return false; + + if (em_dev_register_perf_domain(pd->dev, 1, &pd->cb, &pd->cpumask, false)) { + pd->dev = NULL; + return false; + } + + return true; +} + +static void hybrid_register_all_perf_domains(void) +{ + enum hybrid_cpu_type type; + + for (type = HYBRID_PCORE; type < HYBRID_NR_TYPES; type++) + hybrid_register_perf_domain(&perf_domains[type]); +} + +static void hybrid_add_to_perf_domain(int cpu, enum hybrid_cpu_type type) +{ + struct hybrid_em_perf_domain *pd = &perf_domains[type]; + + guard(mutex)(&hybrid_capacity_lock); + + if (cpumask_test_cpu(cpu, &pd->cpumask)) + return; + + cpumask_set_cpu(cpu, &pd->cpumask); + if (pd->dev) + em_dev_expand_perf_domain(pd->dev, cpu); + else if (hybrid_register_perf_domain(pd)) + em_rebuild_perf_domains(); +} +#else /* CONFIG_ENERGY_MODEL */ +static inline void hybrid_register_all_perf_domains(void) {} +static inline void hybrid_add_to_perf_domain(int cpu, enum hybrid_cpu_type type) {} +#endif /* !CONFIG_ENERGY_MODEL */ + static void hybrid_set_cpu_capacity(struct cpudata *cpu) { arch_set_cpu_capacity(cpu->cpu, cpu->capacity_perf, @@ -1034,11 +1121,14 @@ static void __hybrid_refresh_cpu_capacit hybrid_update_cpu_capacity_scaling(); } -static void hybrid_refresh_cpu_capacity_scaling(void) +static void hybrid_refresh_cpu_capacity_scaling(bool register_perf_domains) { guard(mutex)(&hybrid_capacity_lock); __hybrid_refresh_cpu_capacity_scaling(); + + if (register_perf_domains) + hybrid_register_all_perf_domains(); } static void hybrid_init_cpu_capacity_scaling(bool refresh) @@ -1049,7 +1139,7 @@ static void hybrid_init_cpu_capacity_sca * operation mode. */ if (refresh) { - hybrid_refresh_cpu_capacity_scaling(); + hybrid_refresh_cpu_capacity_scaling(false); return; } @@ -1059,10 +1149,14 @@ static void hybrid_init_cpu_capacity_sca * do not do that when SMT is in use. */ if (hwp_is_hybrid && !sched_smt_active() && arch_enable_hybrid_capacity_scale()) { - hybrid_refresh_cpu_capacity_scaling(); + /* + * Perf domains are not registered before setting hybrid_max_perf_cpu, + * so register them all after setting up CPU capacity scaling. + */ + hybrid_refresh_cpu_capacity_scaling(true); /* * Disabling ITMT causes sched domains to be rebuilt to disable asym - * packing and enable asym capacity. + * packing and enable asym capacity and EAS. */ sched_clear_itmt_support(); } @@ -2215,12 +2309,16 @@ static int hwp_get_cpu_scaling(int cpu) smp_call_function_single(cpu, hybrid_get_type, &cpu_type, 1); /* P-cores have a smaller perf level-to-freqency scaling factor. */ - if (cpu_type == 0x40) + if (cpu_type == 0x40) { + hybrid_add_to_perf_domain(cpu, HYBRID_PCORE); return hybrid_scaling_factor; + } /* Use default core scaling for E-cores */ - if (cpu_type == 0x20) + if (cpu_type == 0x20) { + hybrid_add_to_perf_domain(cpu, HYBRID_ECORE); return core_get_scaling(); + } /* * If reached here, this system is either non-hybrid (like Tiger