From nobody Fri Oct 3 12:14:28 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 89C52FBF6; Mon, 1 Sep 2025 02:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692038; cv=none; b=dIXLNeuWBUlCL9UATsSYBxUtPIlbHbqNRvXYuvCn+YyPX9D+yytJjR/wEryIoUPPwV25c5Qm3Zm2uBPaKXar4oqOhzq35Qv5n/jiF91MZvK5E6Pmaax9z3QzlnsZh8JSt0gp1j2i09b7kYxry1B+hFTtDKn98uue1FX+zRDXn7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692038; c=relaxed/simple; bh=P5Awroh17x0XqlcxcqmVpnCVryubtEO+jzcXszttKgM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sDyAYMOPmdDs4US6ihXqjCcv3jHmk7X4i/FB3xvNE0GZRBMCja0FvN0IJBF852mny5W6r34PSu/NE8eS/5WruhJCi1+KIPS0saFXg3ShyZ1ZptAGeIFe38OkRwR/2Frq8HRaHh7gbnVJfRUdeS9zrveIvfNZc3DVu2oNlOXxMNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=si2ZiN/d; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="si2ZiN/d" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=UCiLReF3B/6Yv4GikF6ajClBF6WoGbglfmsHVOTHltM=; b=si2ZiN/dHkns8YVdcEv1ynCPUi ak5O/muyhSxWmsw0vrHfV7yW44tAPwzHvUedD5UyhD6iMHG/AhKn6hQwSHnIPMrp0NaVj9Z2F6S1P mjfef1YNg+KjYaYyVE9nrx7XPuO82KkiWnxiuG5pOZ/xkVrXLIjI1sM9mfNVNHoekBjmUJw0tokQ7 Vic1dDZ/REX1seYrdOrUU+baJElVZEwfE57/SmcaalcE6vHpVrdjMlH8K6FRgcO4vYj5/V52hR7Qh 0c5yI/G3+DzxKTsmnk4yJ4Gm6Snc0rnYnS6BIRuLtv3PTmDtlSdVM8m6AraS/NaU1wzme0EqqHT3Y B2ROcEDQ==; Received: from [58.29.143.236] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ustqD-0054TS-Eb; Mon, 01 Sep 2025 04:00:18 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH v4 01/10] PM: EM: Assign a unique ID when creating a performance domain Date: Mon, 1 Sep 2025 10:59:54 +0900 Message-ID: <20250901020003.86415-2-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250901020003.86415-1-changwoo@igalia.com> References: <20250901020003.86415-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It is necessary to refer to a specific performance domain from a userspace. For example, the energy model of a particular performance domain is updated. To this end, assign a unique ID to each performance domain to address it, and manage them in a global linked list to look up a specific one by matching ID. IDA is used for ID assignment, and the mutex is used to protect the global list from concurrent access. Note that the mutex (em_pd_list_mutex) is not supposed to hold while holding em_pd_mutex to avoid ABBA deadlock. Signed-off-by: Changwoo Min --- include/linux/energy_model.h | 4 ++++ kernel/power/energy_model.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 7fa1eb3cc823..2f5c73fcdfe5 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -54,6 +54,8 @@ struct em_perf_table { /** * struct em_perf_domain - Performance domain * @em_table: Pointer to the runtime modifiable em_perf_table + * @node: node in em_pd_list (in energy_model.c) + * @id: A unique ID number for each performance domain * @nr_perf_states: Number of performance states * @min_perf_state: Minimum allowed Performance State index * @max_perf_state: Maximum allowed Performance State index @@ -71,6 +73,8 @@ struct em_perf_table { */ struct em_perf_domain { struct em_perf_table __rcu *em_table; + struct list_head node; + int id; int nr_perf_states; int min_perf_state; int max_perf_state; diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index ea7995a25780..58671ac142db 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -23,6 +23,16 @@ */ static DEFINE_MUTEX(em_pd_mutex); =20 +/* + * Manage performance domains with IDs. One can iterate the performance do= mains + * through the list and pick one with their associated ID. The mutex seria= lizes + * the list access. When holding em_pd_list_mutex, em_pd_mutex should not = be + * taken to avoid potential deadlock. + */ +static DEFINE_IDA(em_pd_ida); +static LIST_HEAD(em_pd_list); +static DEFINE_MUTEX(em_pd_list_mutex); + static void em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table); static void em_check_capacity_update(void); @@ -396,7 +406,7 @@ static int em_create_pd(struct device *dev, int nr_stat= es, struct em_perf_table *em_table; struct em_perf_domain *pd; struct device *cpu_dev; - int cpu, ret, num_cpus; + int cpu, ret, num_cpus, id; =20 if (_is_cpu_device(dev)) { num_cpus =3D cpumask_weight(cpus); @@ -420,6 +430,13 @@ static int em_create_pd(struct device *dev, int nr_sta= tes, =20 pd->nr_perf_states =3D nr_states; =20 + INIT_LIST_HEAD(&pd->node); + + id =3D ida_alloc(&em_pd_ida, GFP_KERNEL); + if (id < 0) + return -ENOMEM; + pd->id =3D id; + em_table =3D em_table_alloc(pd); if (!em_table) goto free_pd; @@ -444,6 +461,7 @@ static int em_create_pd(struct device *dev, int nr_stat= es, kfree(em_table); free_pd: kfree(pd); + ida_free(&em_pd_ida, id); return -EINVAL; } =20 @@ -639,6 +657,10 @@ int em_dev_register_perf_domain(struct device *dev, un= signed int nr_states, if (_is_cpu_device(dev)) em_check_capacity_update(); =20 + mutex_lock(&em_pd_list_mutex); + list_add_tail(&dev->em_pd->node, &em_pd_list); + mutex_unlock(&em_pd_list_mutex); + return ret; } EXPORT_SYMBOL_GPL(em_dev_register_perf_domain); @@ -657,6 +679,10 @@ void em_dev_unregister_perf_domain(struct device *dev) if (_is_cpu_device(dev)) return; =20 + mutex_lock(&em_pd_list_mutex); + list_del_init(&dev->em_pd->node); + mutex_unlock(&em_pd_list_mutex); + /* * The mutex separates all register/unregister requests and protects * from potential clean-up/setup issues in the debugfs directories. @@ -668,6 +694,8 @@ void em_dev_unregister_perf_domain(struct device *dev) em_table_free(rcu_dereference_protected(dev->em_pd->em_table, lockdep_is_held(&em_pd_mutex))); =20 + ida_free(&em_pd_ida, dev->em_pd->id); + kfree(dev->em_pd); dev->em_pd =3D NULL; mutex_unlock(&em_pd_mutex); --=20 2.51.0 From nobody Fri Oct 3 12:14:28 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 8042F157493; Mon, 1 Sep 2025 02:00:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692039; cv=none; b=s+tbtbjt+CfGP44Nso79dPXhyGbTe+q8NPyCnj73TeI9ERp6DyYsLX5xsQxb4hgxsjUxsfKrfNisvETM1YSb5l/O3TvMBO6zfBOiCAhKTJHHCPc/1cNAoam9wbcIJEd3J/4eW5lhNifjgHMBPLsuDRSFFEXkJGhWop35k5kMcKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692039; c=relaxed/simple; bh=H91L/j65Ys5yJfXKrAdE0GL1zhyY3X6kZtS8EKcLQIU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cCDMcNHqCYh12QkSeaatkFEERmUwHsXKEe1F9n8Ls0CIEnoj0ylYtddVUfUb6zmpZu3bobvN8e4mZ9b1RLL99KCiZ9h/v3SRYhabgVL0ZBq+pAzbd55z2L1Mtu5eaf1jgZS3C2qOvou12HIlf5xsBjLLNWOz2ofMImW/sCcxynE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=jBOsGklZ; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="jBOsGklZ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=/P6KrSUVg6/xnpaU4Wu3I9Tw06U0B/Y3pbKy5U5GQJw=; b=jBOsGklZvCrtN9dgpQc51Crsgz xjFUqvMQQAZYeirfiKkPoMQTRLdBU1UC3QTEq89k55JjdSiCQ3fvkod2iX9TLiQzMi/3W5br5tPCl 6g2UMu83xSu9s1P9p3tLhu8gQUAk7Gi00UekARXq7h4s0YLZcH8bvrWEZhrVka1PhX0H3lW+ikLhO iB7zyat01kUFEAFjOpQySG20Zqn6tdqrZETWKvQbXpx4qevke1jtjXtGIbViDC+QowexiF3Jy4sum bRfRndeIQ+AdcMVtDmmaHAmUi7lXrfz28+WuZet7rBbHzwUbvZJEVEBUwTE3rGOhXNpTpiEGiLbHV VX5/g81Q==; Received: from [58.29.143.236] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ustqI-0054Tc-I4; Mon, 01 Sep 2025 04:00:23 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH v4 02/10] PM: EM: Expose the ID of a performance domain via debugfs Date: Mon, 1 Sep 2025 10:59:55 +0900 Message-ID: <20250901020003.86415-3-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250901020003.86415-1-changwoo@igalia.com> References: <20250901020003.86415-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For ease of debugging, let's expose the assigned ID of a performance domain through debugfs (e.g., /sys/kernel/debug/energy_model/cpu0/id). Signed-off-by: Changwoo Min --- kernel/power/energy_model.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 58671ac142db..6e5e70dbec88 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -126,6 +126,16 @@ static int em_debug_flags_show(struct seq_file *s, voi= d *unused) } DEFINE_SHOW_ATTRIBUTE(em_debug_flags); =20 +static int em_debug_id_show(struct seq_file *s, void *unused) +{ + struct em_perf_domain *pd =3D s->private; + + seq_printf(s, "%d\n", pd->id); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(em_debug_id); + static void em_debug_create_pd(struct device *dev) { struct em_dbg_info *em_dbg; @@ -142,6 +152,8 @@ static void em_debug_create_pd(struct device *dev) debugfs_create_file("flags", 0444, d, dev->em_pd, &em_debug_flags_fops); =20 + debugfs_create_file("id", 0444, d, dev->em_pd, &em_debug_id_fops); + em_dbg =3D devm_kcalloc(dev, dev->em_pd->nr_perf_states, sizeof(*em_dbg), GFP_KERNEL); if (!em_dbg) --=20 2.51.0 From nobody Fri Oct 3 12:14:28 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 A7DF4218EA8; Mon, 1 Sep 2025 02:00:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692042; cv=none; b=NWskaiUswmLkkhgeIGi1v2uhD7OLSirDf75b9F5q6gWDnpQ/5ARFn9Va4CIWFtcJW46HwyseETZtShmx9v2S2gIiho1w0ZQOEfyyulYBCyxerGl5bj3OoZ9lZvIX9iu54nSvlLvFuFpAcB4D0t/2FIXeFptj75cFwqFbrIPJ9I0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692042; c=relaxed/simple; bh=YzJtKgREI7me3nXsCfQvSwyRWNKrJPREpQJqT4gzfeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xz4KujEfh+HybzwDL4BmPcy9P+wZA/5okyJLiZPOeomi43tkBior/1A0cjoSewcTPwsFOR+K+VwttFWd6+SB5CVFwFTEL6cacyYbtwcoIFpR3K7+1/YArwwOukBJv6FQpGv+IR9wfikRe0/g+4DhUSZtj+Lq9Z7LBD1pEKw1IEc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=j9JiVWWO; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="j9JiVWWO" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=t318W7NevJgtDnAIJPsPhF+OfAPFrrXL/khmfEo3q5M=; b=j9JiVWWOp9Ee2xFtBD4hwUCImM 3Aok3lxH3o7n4vw9+a/5KtCdqLiDg0Ywvkk0HEDgofq/Vxazg0ZJ6itNC++DbfZuF4b041ksu62zF 94QymN2n1dsPDnHx+l9V7Cq4VMyJao/SXnMh4d2AeAishDBbxxe4FCN6LdZVu1b5f+JLGioitLGtm /IIBqvwaTvjYMHsVfWWqUQ6nxgoeIA7j8ZRYAlzmakhJGaljKcAGANAc2JlWu6CxPHL7hijLlCMGd HKMQI2lISici9q/3FRrmZEDhjidIMdKQgfoR0M3Itw4YVTSkiaOckEU4BbN7z+a2FyezmpJk4gHk5 MsHN25Vw==; Received: from [58.29.143.236] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ustqO-0054To-2w; Mon, 01 Sep 2025 04:00:29 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH v4 03/10] PM: EM: Add an iterator and accessor for the performance domain Date: Mon, 1 Sep 2025 10:59:56 +0900 Message-ID: <20250901020003.86415-4-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250901020003.86415-1-changwoo@igalia.com> References: <20250901020003.86415-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add an iterator function (for_each_em_perf_domain) that iterates all the performance domains in the global list. A passed callback function (cb) is called for each performance domain. Additionally, add a lookup function (em_perf_domain_get_by_id) that searches for a performance domain by matching the ID in the global list. Signed-off-by: Changwoo Min --- include/linux/energy_model.h | 15 +++++++++++++++ kernel/power/energy_model.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 2f5c73fcdfe5..ce70e664fcd4 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -341,6 +341,10 @@ struct em_perf_state *em_perf_state_from_pd(struct em_= perf_domain *pd) return rcu_dereference(pd->em_table)->state; } =20 +int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *), + void *data); +struct em_perf_domain *em_perf_domain_get_by_id(int id); + #else struct em_data_callback {}; #define EM_ADV_DATA_CB(_active_power_cb, _cost_cb) { } @@ -410,6 +414,17 @@ int em_update_performance_limits(struct em_perf_domain= *pd, } static inline void em_adjust_cpu_capacity(unsigned int cpu) {} static inline void em_rebuild_sched_domains(void) {} +static inline +int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *), + void *data) +{ + return -EINVAL; +} +static inline +struct em_perf_domain *em_perf_domain_get_by_id(int id) +{ + return NULL; +} #endif =20 #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 6e5e70dbec88..f125262a93c9 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -976,3 +976,37 @@ void em_rebuild_sched_domains(void) */ schedule_work(&rebuild_sd_work); } + +int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *), + void *data) +{ + struct em_perf_domain *pd; + + lockdep_assert_not_held(&em_pd_mutex); + guard(mutex)(&em_pd_list_mutex); + + list_for_each_entry(pd, &em_pd_list, node) { + int ret; + + ret =3D cb(pd, data); + if (ret) + return ret; + } + + return 0; +} + +struct em_perf_domain *em_perf_domain_get_by_id(int id) +{ + struct em_perf_domain *pd; + + lockdep_assert_not_held(&em_pd_mutex); + guard(mutex)(&em_pd_list_mutex); + + list_for_each_entry(pd, &em_pd_list, node) { + if (pd->id =3D=3D id) + return pd; + } + + return NULL; +} --=20 2.51.0 From nobody Fri Oct 3 12:14:28 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 D2E08219A8D; Mon, 1 Sep 2025 02:00:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692043; cv=none; b=Tlz+ZT/Akkgqhyu3jmw7Oj6n2k5t6zSvI8v2JzZo6rBL27sp9QkesaYbrbVGDrwxYW3HuqObKdydw26IT3WKZAijubsohP4l5MdfOVm5n+/LvAUFAn7rAa7ytGzxbkCfnK7hu4iS/EHU7jKQvO3T5c1sNfRmFD7kkFRPXEs4yVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692043; c=relaxed/simple; bh=dsCMGD/7CHdus/6QYTXaZOkmaWXblr8JC8+GVHl1lY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c9AmeC38jm/Rj0sdducX3+gdf1DR/h5Zmx+pMDFK/C2bQAuRF8bE8MW/irVyWgE5gBPldTgpcY1hUyzODCgL+fmyWvOAH9WtLpx7wBplxFudk9hHj4q2Z6I0qjddGmgUKTkgVXqJyNN4AqfMlZ8X6KtJoCyX1ARjGZtgWz0Qr84= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=oTVamgvk; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="oTVamgvk" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Y4aTvxu/44cDdKCEwC4qrk+bUJCVLM13hCu0G1Ejf98=; b=oTVamgvkDFHmvDg4EILIERApeg 4gMz2r72+WytsoYE3/VYtqwGjuEZ8Kqvsu+9Xg6vJI7MrdG/2yls4ewvb0EK1WP98UEwnOUMB/hE4 y+iq8thbfX+/HWNsCoNem7kfOtHL+fnbcuj8q7LRm2H+iM81q0MmHFFYMFzSK+S3BnmdXnlPzXgBw kN+kyZ1+F4RSboTsVUDXAystY7WjXBwgSprnfEAc9ntY5o+EauH928r+cQUUJQIKA3c8QQY+w8bj6 TmDMHice87KSDqz+mufTtTQ5w8lGeMS3u/DGld3NSVtaQsd9aqlPEGZ4WZQ1QdHKaZToW70FONccu 4Nz8qm6Q==; Received: from [58.29.143.236] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ustqT-0054Tz-Ak; Mon, 01 Sep 2025 04:00:34 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH v4 04/10] PM: EM: Add em.yaml and autogen files Date: Mon, 1 Sep 2025 10:59:57 +0900 Message-ID: <20250901020003.86415-5-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250901020003.86415-1-changwoo@igalia.com> References: <20250901020003.86415-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a generic netlink spec in YAML format and autogenerate boilerplate code using ynl-regen.sh to introduce a generic netlink for the energy model. It allows a userspace program to read the performance domain and its energy model. It notifies the userspace program when a performance domain is created or deleted or its energy model is updated through a multicast interface. Specifically, it supports two commands: - EM_CMD_GET_PDS: Get the list of information for all performance domains. - EM_CMD_GET_PD_TABLE: Get the energy model table of a performance domain. Also, it supports three notification events: - EM_CMD_PD_CREATED: When a performance domain is created. - EM_CMD_PD_DELETED: When a performance domain is deleted. - EM_CMD_PD_UPDATED: When the energy model table of a performance domain is updated. Finally, update MAINTAINERS to include new files. Signed-off-by: Changwoo Min --- Documentation/netlink/specs/em.yaml | 113 ++++++++++++++++++++++++++++ MAINTAINERS | 3 + include/uapi/linux/energy_model.h | 62 +++++++++++++++ kernel/power/em_netlink_autogen.c | 48 ++++++++++++ kernel/power/em_netlink_autogen.h | 23 ++++++ 5 files changed, 249 insertions(+) create mode 100644 Documentation/netlink/specs/em.yaml create mode 100644 include/uapi/linux/energy_model.h create mode 100644 kernel/power/em_netlink_autogen.c create mode 100644 kernel/power/em_netlink_autogen.h diff --git a/Documentation/netlink/specs/em.yaml b/Documentation/netlink/sp= ecs/em.yaml new file mode 100644 index 000000000000..9905ca482325 --- /dev/null +++ b/Documentation/netlink/specs/em.yaml @@ -0,0 +1,113 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cla= use) + +name: em + +doc: | + Energy model netlink interface to notify its changes. + +protocol: genetlink + +uapi-header: linux/energy_model.h + +attribute-sets: + - + name: pds + attributes: + - + name: pd + type: nest + nested-attributes: pd + multi-attr: true + - + name: pd + attributes: + - + name: pad + type: pad + - + name: pd-id + type: u32 + - + name: flags + type: u64 + - + name: cpus + type: string + - + name: pd-table + attributes: + - + name: pd-id + type: u32 + - + name: ps + type: nest + nested-attributes: ps + multi-attr: true + - + name: ps + attributes: + - + name: pad + type: pad + - + name: performance + type: u64 + - + name: frequency + type: u64 + - + name: power + type: u64 + - + name: cost + type: u64 + - + name: flags + type: u64 + +operations: + list: + - + name: get-pds + attribute-set: pds + doc: Get the list of information for all performance domains. + do: + reply: + attributes: + - pd + - + name: get-pd-table + attribute-set: pd-table + doc: Get the energy model table of a performance domain. + do: + request: + attributes: + - pd-id + reply: + attributes: + - pd-id + - ps + - + name: pd-created + doc: A performance domain is created. + notify: get-pd-table + mcgrp: event + - + name: pd-updated + doc: A performance domain is updated. + notify: get-pd-table + mcgrp: event + - + name: pd-deleted + doc: A performance domain is deleted. + attribute-set: pd-table + event: + attributes: + - pd-id + mcgrp: event + +mcast-groups: + list: + - + name: event diff --git a/MAINTAINERS b/MAINTAINERS index 6dcfbd11efef..0151a0bddd3b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9024,6 +9024,9 @@ S: Maintained F: kernel/power/energy_model.c F: include/linux/energy_model.h F: Documentation/power/energy-model.rst +F: Documentation/netlink/specs/em.yaml +F: include/uapi/linux/energy_model.h +F: kernel/power/em_netlink_autogen.* =20 EPAPR HYPERVISOR BYTE CHANNEL DEVICE DRIVER M: Laurentiu Tudor diff --git a/include/uapi/linux/energy_model.h b/include/uapi/linux/energy_= model.h new file mode 100644 index 000000000000..4ec4c0eabbbb --- /dev/null +++ b/include/uapi/linux/energy_model.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cl= ause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/em.yaml */ +/* YNL-GEN uapi header */ + +#ifndef _UAPI_LINUX_ENERGY_MODEL_H +#define _UAPI_LINUX_ENERGY_MODEL_H + +#define EM_FAMILY_NAME "em" +#define EM_FAMILY_VERSION 1 + +enum { + EM_A_PDS_PD =3D 1, + + __EM_A_PDS_MAX, + EM_A_PDS_MAX =3D (__EM_A_PDS_MAX - 1) +}; + +enum { + EM_A_PD_PAD =3D 1, + EM_A_PD_PD_ID, + EM_A_PD_FLAGS, + EM_A_PD_CPUS, + + __EM_A_PD_MAX, + EM_A_PD_MAX =3D (__EM_A_PD_MAX - 1) +}; + +enum { + EM_A_PD_TABLE_PD_ID =3D 1, + EM_A_PD_TABLE_PS, + + __EM_A_PD_TABLE_MAX, + EM_A_PD_TABLE_MAX =3D (__EM_A_PD_TABLE_MAX - 1) +}; + +enum { + EM_A_PS_PAD =3D 1, + EM_A_PS_PERFORMANCE, + EM_A_PS_FREQUENCY, + EM_A_PS_POWER, + EM_A_PS_COST, + EM_A_PS_FLAGS, + + __EM_A_PS_MAX, + EM_A_PS_MAX =3D (__EM_A_PS_MAX - 1) +}; + +enum { + EM_CMD_GET_PDS =3D 1, + EM_CMD_GET_PD_TABLE, + EM_CMD_PD_CREATED, + EM_CMD_PD_UPDATED, + EM_CMD_PD_DELETED, + + __EM_CMD_MAX, + EM_CMD_MAX =3D (__EM_CMD_MAX - 1) +}; + +#define EM_MCGRP_EVENT "event" + +#endif /* _UAPI_LINUX_ENERGY_MODEL_H */ diff --git a/kernel/power/em_netlink_autogen.c b/kernel/power/em_netlink_au= togen.c new file mode 100644 index 000000000000..a7a09ab1d1c2 --- /dev/null +++ b/kernel/power/em_netlink_autogen.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cl= ause) +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/em.yaml */ +/* YNL-GEN kernel source */ + +#include +#include + +#include "em_netlink_autogen.h" + +#include + +/* EM_CMD_GET_PD_TABLE - do */ +static const struct nla_policy em_get_pd_table_nl_policy[EM_A_PD_TABLE_PD_= ID + 1] =3D { + [EM_A_PD_TABLE_PD_ID] =3D { .type =3D NLA_U32, }, +}; + +/* Ops table for em */ +static const struct genl_split_ops em_nl_ops[] =3D { + { + .cmd =3D EM_CMD_GET_PDS, + .doit =3D em_nl_get_pds_doit, + .flags =3D GENL_CMD_CAP_DO, + }, + { + .cmd =3D EM_CMD_GET_PD_TABLE, + .doit =3D em_nl_get_pd_table_doit, + .policy =3D em_get_pd_table_nl_policy, + .maxattr =3D EM_A_PD_TABLE_PD_ID, + .flags =3D GENL_CMD_CAP_DO, + }, +}; + +static const struct genl_multicast_group em_nl_mcgrps[] =3D { + [EM_NLGRP_EVENT] =3D { "event", }, +}; + +struct genl_family em_nl_family __ro_after_init =3D { + .name =3D EM_FAMILY_NAME, + .version =3D EM_FAMILY_VERSION, + .netnsok =3D true, + .parallel_ops =3D true, + .module =3D THIS_MODULE, + .split_ops =3D em_nl_ops, + .n_split_ops =3D ARRAY_SIZE(em_nl_ops), + .mcgrps =3D em_nl_mcgrps, + .n_mcgrps =3D ARRAY_SIZE(em_nl_mcgrps), +}; diff --git a/kernel/power/em_netlink_autogen.h b/kernel/power/em_netlink_au= togen.h new file mode 100644 index 000000000000..78ce609641f1 --- /dev/null +++ b/kernel/power/em_netlink_autogen.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Cl= ause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/em.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_EM_GEN_H +#define _LINUX_EM_GEN_H + +#include +#include + +#include + +int em_nl_get_pds_doit(struct sk_buff *skb, struct genl_info *info); +int em_nl_get_pd_table_doit(struct sk_buff *skb, struct genl_info *info); + +enum { + EM_NLGRP_EVENT, +}; + +extern struct genl_family em_nl_family; + +#endif /* _LINUX_EM_GEN_H */ --=20 2.51.0 From nobody Fri Oct 3 12:14:28 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 7EEE8239E63; Mon, 1 Sep 2025 02:00:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692048; cv=none; b=LP1jExJ48+ZHkzBWNdalidTeEPZpmj3wsfesHMhc/8wRtyTR1KQfOuq4guz2xOEMOiBvLMyG5jbMImWUZulgIzN/FcOQIQdhEjA9S3JntO3AcSAoMTk+aEJ8jvIgafAm3eRNEHvxpXxlucfJkCfinql65RnV20pvuY8qifsDHm0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692048; c=relaxed/simple; bh=LyakN45UOS+F8rqmwwILdrFazmjfMUiYFyzoJcdivKs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=umRFLEYzKQRkccfvtqcLtl2/3/FHso3MhaTH5yoDZwfbYgo5V6E3R8LO4jTAm/4ne4U5d+xocZC01JpfQnudMnVqWMFCtiLavcAAanNUbhCr5ZXtrGOIdtjTK8YgolrNqwqODSWiFyrorjAMciAeGRJqXmqSoce3OMdSDACmSas= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=UMZOPZRU; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="UMZOPZRU" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=5dxvfgME0EuBtetIgZsGnsG1UO3q1LjYxquXtFj+L2A=; b=UMZOPZRUTqiiY7V0hSAa7AyW2e 7BoA29pjr34dj+B6qJJ/NexOi6u1BpV6qteYnECyWf7Kk4sWUkKp7rC5kBh3A0+Hd5QI9RQADItr0 p5+plFnzHLHKo5R1Pp67uxfisZ6plYvb1ihQPt7PrBMl3S9/z4FMJMpNSFQ0ULpCtyrznGU0yeoz8 h4lzdG6lLxGyCZeq/8cX6sks3w3VUodz2/IJqP61UzLHAGfubN9LfsBQfhH6Xt++QR+vFF9pRSkYR e1TA0cF9DSbRrrvy9r/eo2cf2uR9Hx+6NOPbGrAtzcTmSeOxmaIEKQc2j2OipBieGq81b5bPtsHgm DdMSiajQ==; Received: from [58.29.143.236] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ustqY-0054UE-O2; Mon, 01 Sep 2025 04:00:39 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH v4 05/10] PM: EM: Add a skeleton code for netlink notification Date: Mon, 1 Sep 2025 10:59:58 +0900 Message-ID: <20250901020003.86415-6-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250901020003.86415-1-changwoo@igalia.com> References: <20250901020003.86415-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a boilerplate code for netlink notification to register the new protocol family. Also, initialize and register the netlink during booting. The initialization is called at the postcore level, which is late enough after the generic netlink is initialized. Finally, update MAINTAINERS to include new files. Signed-off-by: Changwoo Min --- MAINTAINERS | 2 +- kernel/power/Makefile | 5 ++++- kernel/power/em_netlink.c | 35 +++++++++++++++++++++++++++++++++++ kernel/power/em_netlink.h | 16 ++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 kernel/power/em_netlink.c create mode 100644 kernel/power/em_netlink.h diff --git a/MAINTAINERS b/MAINTAINERS index 0151a0bddd3b..964bb09920c3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9026,7 +9026,7 @@ F: include/linux/energy_model.h F: Documentation/power/energy-model.rst F: Documentation/netlink/specs/em.yaml F: include/uapi/linux/energy_model.h -F: kernel/power/em_netlink_autogen.* +F: kernel/power/em_netlink*.* =20 EPAPR HYPERVISOR BYTE CHANNEL DEVICE DRIVER M: Laurentiu Tudor diff --git a/kernel/power/Makefile b/kernel/power/Makefile index 874ad834dc8d..284a760aade7 100644 --- a/kernel/power/Makefile +++ b/kernel/power/Makefile @@ -21,4 +21,7 @@ obj-$(CONFIG_PM_WAKELOCKS) +=3D wakelock.o =20 obj-$(CONFIG_MAGIC_SYSRQ) +=3D poweroff.o =20 -obj-$(CONFIG_ENERGY_MODEL) +=3D energy_model.o +obj-$(CONFIG_ENERGY_MODEL) +=3D em.o +em-y :=3D energy_model.o +em-$(CONFIG_NET) +=3D em_netlink_autogen.o em_netlink.o + diff --git a/kernel/power/em_netlink.c b/kernel/power/em_netlink.c new file mode 100644 index 000000000000..f3fbfeff29a4 --- /dev/null +++ b/kernel/power/em_netlink.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * + * Generic netlink for energy model. + * + * Copyright (c) 2025 Valve Corporation. + * Author: Changwoo Min + */ + +#define pr_fmt(fmt) "energy_model: " fmt + +#include +#include +#include +#include + +#include "em_netlink.h" +#include "em_netlink_autogen.h" + +int em_nl_get_pds_doit(struct sk_buff *skb, struct genl_info *info) +{ + return -EOPNOTSUPP; +} + +int em_nl_get_pd_table_doit(struct sk_buff *skb, struct genl_info *info) +{ + return -EOPNOTSUPP; +} + +static int __init em_netlink_init(void) +{ + return genl_register_family(&em_nl_family); +} +postcore_initcall(em_netlink_init); + diff --git a/kernel/power/em_netlink.h b/kernel/power/em_netlink.h new file mode 100644 index 000000000000..acd186c92d6b --- /dev/null +++ b/kernel/power/em_netlink.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * + * Generic netlink for energy model. + * + * Copyright (c) 2025 Valve Corporation. + * Author: Changwoo Min + */ +#ifndef _EM_NETLINK_H +#define _EM_NETLINK_H + +#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_NET) +#else +#endif + +#endif /* _EM_NETLINK_H */ --=20 2.51.0 From nobody Fri Oct 3 12:14:28 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 EF39A20C038; Mon, 1 Sep 2025 02:00:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692054; cv=none; b=FMLepAHWQauLFlxH62lzodlbRezsBJNg0yutuWpb9ZLRcjtQOKqC69MY2cdtCdRbBvVNJRJbvTKOm7Pu7/KWY7efoFlIWi+rT6QiqHdfy+s1yteNxiJqoZtWiu6/NwZKBX4wEnXm6zy8MJL8XfgJd/R38rXdl+sSwHFSjA6qRl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692054; c=relaxed/simple; bh=h11SGtV5bb+zU+5RXvkBOpOEmZiHT6WNp4XydOTIj00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iN/yAfURo8dG3kvOcmBSDdt73YYsqQsoIit74RtI9/DY69gOFPLdWxqzSRutaYgoa88SKcHIT4yUjgC6eTriTRFDRkJ19Ggdz9Ruhdhfi+I6m6CaQp3jjWc1mk1rhlM4JgJvN3fcQtVBn0JBR7DH8kaUQ6eVbDBHJFq/GXqI9eg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=Hw1gBB6L; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="Hw1gBB6L" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=TIBfhTObXQDjnOaizlcq1EWJ8ASUl0ca19LxkyMR434=; b=Hw1gBB6Lm4S1tpVdof2zW3VCEQ u1qf/f42xcZwm3KIXav5WkS/O8X9o//YlvOYEiB2A4qtutBnMhN9zDp3j4nhM4RJoG9MaxkVdEzhX tfzfXgC0Hei+toFP+jdLy/jGwVAMprSfqSwK2ou57AcbEQy8gcDhtAFgSDC1F+4+AEtp4FxjsD1Ds VQyZ7EqinzIT/PO9m9TzPh1EOkWf8sc5/w3x7uzN7igyJYIEYPQiOft2TkRBPx9Ez9cHgQzgFcUFg fYiMujMYppBuwAp5g0upepNUXyIPDFjPU8WomjMd0sJjRWJc1rHMjWpV4zSSmY4WuroG3sKd8e31z Vk+zs4pQ==; Received: from [58.29.143.236] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ustqe-0054Uf-8u; Mon, 01 Sep 2025 04:00:45 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH v4 06/10] PM: EM: Implement em_nl_get_pds_doit() Date: Mon, 1 Sep 2025 10:59:59 +0900 Message-ID: <20250901020003.86415-7-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250901020003.86415-1-changwoo@igalia.com> References: <20250901020003.86415-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a userspace requests EM_CMD_GET_PDS, the kernel responds with information on all performance domains. The message format of the response is as follows: EM_A_PDS_PD (NLA_NESTED)* EM_A_PD_PD_ID (NLA_U32) EM_A_PD_FLAGS (NLA_U64) EM_A_PD_CPUS (NLA_STRING) where EM_A_PDS_PD can be repeated as many times as there are performance domains, and EM_A_PD_CPUS is a hexadecimal string representing a CPU bitmask. Signed-off-by: Changwoo Min --- kernel/power/em_netlink.c | 82 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/kernel/power/em_netlink.c b/kernel/power/em_netlink.c index f3fbfeff29a4..31b27c6fe3c9 100644 --- a/kernel/power/em_netlink.c +++ b/kernel/power/em_netlink.c @@ -17,9 +17,89 @@ #include "em_netlink.h" #include "em_netlink_autogen.h" =20 +#define EM_A_PD_CPUS_LEN 256 + +/*************************** Command encoding ****************************= ****/ +static int __em_nl_get_pd_size(struct em_perf_domain *pd, void *data) +{ + char cpus_buf[EM_A_PD_CPUS_LEN]; + int *tot_msg_sz =3D data; + int msg_sz, cpus_sz; + + cpus_sz =3D snprintf(cpus_buf, sizeof(cpus_buf), "%*pb", + cpumask_pr_args(to_cpumask(pd->cpus))); + + msg_sz =3D nla_total_size(0) + /* EM_A_PDS_PD */ + nla_total_size(sizeof(u32)) + /* EM_A_PD_PD_ID */ + nla_total_size_64bit(sizeof(u64)) + /* EM_A_PD_FLAGS */ + nla_total_size(cpus_sz); /* EM_A_PD_CPUS */ + + *tot_msg_sz +=3D nlmsg_total_size(genlmsg_msg_size(msg_sz)); + return 0; +} + +static int __em_nl_get_pd(struct em_perf_domain *pd, void *data) +{ + char cpus_buf[EM_A_PD_CPUS_LEN]; + struct sk_buff *msg =3D data; + struct nlattr *entry; + + entry =3D nla_nest_start(msg, EM_A_PDS_PD); + if (!entry) + goto out_cancel_nest; + + if (nla_put_u32(msg, EM_A_PD_PD_ID, pd->id)) + goto out_cancel_nest; + + if (nla_put_u64_64bit(msg, EM_A_PD_FLAGS, pd->flags, EM_A_PD_PAD)) + goto out_cancel_nest; + + snprintf(cpus_buf, sizeof(cpus_buf), "%*pb", + cpumask_pr_args(to_cpumask(pd->cpus))); + if (nla_put_string(msg, EM_A_PD_CPUS, cpus_buf)) + goto out_cancel_nest; + + nla_nest_end(msg, entry); + + return 0; + +out_cancel_nest: + nla_nest_cancel(msg, entry); + + return -EMSGSIZE; +} + int em_nl_get_pds_doit(struct sk_buff *skb, struct genl_info *info) { - return -EOPNOTSUPP; + struct sk_buff *msg; + void *hdr; + int cmd =3D info->genlhdr->cmd; + int ret =3D -EMSGSIZE, msg_sz =3D 0; + + for_each_em_perf_domain(__em_nl_get_pd_size, &msg_sz); + + msg =3D genlmsg_new(msg_sz, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + hdr =3D genlmsg_put_reply(msg, info, &em_nl_family, 0, cmd); + if (!hdr) + goto out_free_msg; + + ret =3D for_each_em_perf_domain(__em_nl_get_pd, msg); + if (ret) + goto out_cancel_msg; + + genlmsg_end(msg, hdr); + + return genlmsg_reply(msg, info); + +out_cancel_msg: + genlmsg_cancel(msg, hdr); +out_free_msg: + nlmsg_free(msg); + + return ret; } =20 int em_nl_get_pd_table_doit(struct sk_buff *skb, struct genl_info *info) --=20 2.51.0 From nobody Fri Oct 3 12:14:28 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 CE66B212545; Mon, 1 Sep 2025 02:00:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692058; cv=none; b=nrm+NbqNRVzoQ8wWf2c8IJFhFRj8hAWU5QuOwcsTmv24sLJgfrRlbXpr2Tou1B3shjmluuvOwLnBLUq5Vfpkm1R25CP1iK5WqIGDJLvYsjlUBygFCEs4oi12twn8nWroAygC3KXxEutAfwkUVbOnm+yqYQmYeSFo9eGShdmmFEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692058; c=relaxed/simple; bh=sIUC3+UBuDoJoZKfk7HtTe+i/bxz9UE8eXfzlcItyq0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S2ewTUIrUajPLqstlTNzZZFFEPv3D3pHjr3n+hBDQFLJgTLorITXV6cAYl5jyAQopSa+7V6aZ99GXzMJhpcIOuT6erIgpG7y9ejkLPRpu2zE8uREg2pGSGtD+VWKQU/ox0ThQbvA9dc4Lkdw+noMHW+3giXEeDYv7eqSVr4Epy8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=Lgr9WUDN; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="Lgr9WUDN" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=PWEPzpF6RxNqTtrALNVAxf12IenjDGCjXp1MKrJXdqU=; b=Lgr9WUDN5oT+9h7Y7yK3AtYcYL 1eSxO+34DXvoxgMsvX8uP2cgF7mlxGazyQTU+KFlKesG9fMLCQDSpxg4sEk8Kif43yUL+BEl9J8bI jKJ2QrGt1LBiBFzuPnzvfO4j7yIiTuVAEhecxzt1ODJ2HhQAR28VpZiNbN4pT4PwdG3ZC4Zjepmnv mTl+PNeJ9OGShcfqbCzbMyyu3T9/tJYzItRmGsianBSxpWv2elTCRyoDsuaiPCMSHUmq1yirq1ogV xVCq9rwB1dJmJiSJbZfcItCkhuiA88qtvYPtPvcS3MjwhYGSw1QaxlCvtOOyH/jCxTeqEimQNy3NE OsppazzQ==; Received: from [58.29.143.236] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ustqj-0054Uu-H9; Mon, 01 Sep 2025 04:00:50 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH v4 07/10] PM: EM: Implement em_nl_get_pd_table_doit() Date: Mon, 1 Sep 2025 11:00:00 +0900 Message-ID: <20250901020003.86415-8-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250901020003.86415-1-changwoo@igalia.com> References: <20250901020003.86415-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a userspace requests EM_CMD_GET_PD_TABLE with an ID of a performancei domain, the kernel reports back the energy model table of the specified performance domain. The message format of the response is as follows: EM_A_PD_TABLE_PD_ID (NLA_U32) EM_A_PD_TABLE_PS (NLA_NESTED)* EM_A_PS_PERFORMANCE (NLA_U64) EM_A_PS_FREQUENCY (NLA_U64) EM_A_PS_POWER (NLA_U64) EM_A_PS_COST (NLA_U64) EM_A_PS_FLAGS (NLA_U64) where EM_A_PD_TABLE_PS can be repeated as many times as there are performance states (struct em_perf_state). Signed-off-by: Changwoo Min --- kernel/power/em_netlink.c | 108 +++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/kernel/power/em_netlink.c b/kernel/power/em_netlink.c index 31b27c6fe3c9..59953cfedf78 100644 --- a/kernel/power/em_netlink.c +++ b/kernel/power/em_netlink.c @@ -102,9 +102,115 @@ int em_nl_get_pds_doit(struct sk_buff *skb, struct ge= nl_info *info) return ret; } =20 +static struct em_perf_domain *__em_nl_get_pd_table_id(struct nlattr **attr= s) +{ + struct em_perf_domain *pd; + int id; + + if (!attrs[EM_A_PD_TABLE_PD_ID]) + return NULL; + + id =3D nla_get_u32(attrs[EM_A_PD_TABLE_PD_ID]); + pd =3D em_perf_domain_get_by_id(id); + return pd; +} + +static int __em_nl_get_pd_table_size(const struct em_perf_domain *pd) +{ + int id_sz, ps_sz; + + id_sz =3D nla_total_size(sizeof(u32)); /* EM_A_PD_TABLE_PD_ID */ + ps_sz =3D nla_total_size(0) + /* EM_A_PD_TABLE_PS */ + nla_total_size_64bit(sizeof(u64)) + /* EM_A_PS_PERFORMANCE */ + nla_total_size_64bit(sizeof(u64)) + /* EM_A_PS_FREQUENCY */ + nla_total_size_64bit(sizeof(u64)) + /* EM_A_PS_POWER */ + nla_total_size_64bit(sizeof(u64)) + /* EM_A_PS_COST */ + nla_total_size_64bit(sizeof(u64)); /* EM_A_PS_FLAGS */ + ps_sz *=3D pd->nr_perf_states; + + return nlmsg_total_size(genlmsg_msg_size(id_sz + ps_sz)); +} + +static int __em_nl_get_pd_table(struct sk_buff *msg, const struct em_perf_= domain *pd) +{ + struct em_perf_state *table, *ps; + struct nlattr *entry; + int i; + + if (nla_put_u32(msg, EM_A_PD_TABLE_PD_ID, pd->id)) + goto out_err; + + rcu_read_lock(); + table =3D em_perf_state_from_pd((struct em_perf_domain *)pd); + + for (i =3D 0; i < pd->nr_perf_states; i++) { + ps =3D &table[i]; + + entry =3D nla_nest_start(msg, EM_A_PD_TABLE_PS); + if (!entry) + goto out_unlock_ps; + + if (nla_put_u64_64bit(msg, EM_A_PS_PERFORMANCE, + ps->performance, EM_A_PS_PAD)) + goto out_cancel_ps_nest; + if (nla_put_u64_64bit(msg, EM_A_PS_FREQUENCY, + ps->frequency, EM_A_PS_PAD)) + goto out_cancel_ps_nest; + if (nla_put_u64_64bit(msg, EM_A_PS_POWER, + ps->power, EM_A_PS_PAD)) + goto out_cancel_ps_nest; + if (nla_put_u64_64bit(msg, EM_A_PS_COST, + ps->cost, EM_A_PS_PAD)) + goto out_cancel_ps_nest; + if (nla_put_u64_64bit(msg, EM_A_PS_FLAGS, + ps->flags, EM_A_PS_PAD)) + goto out_cancel_ps_nest; + + nla_nest_end(msg, entry); + } + rcu_read_unlock(); + return 0; + +out_cancel_ps_nest: + nla_nest_cancel(msg, entry); +out_unlock_ps: + rcu_read_unlock(); +out_err: + return -EMSGSIZE; +} + int em_nl_get_pd_table_doit(struct sk_buff *skb, struct genl_info *info) { - return -EOPNOTSUPP; + struct sk_buff *msg; + struct em_perf_domain *pd; + void *hdr; + int cmd =3D info->genlhdr->cmd; + int msg_sz, ret =3D -EMSGSIZE; + + pd =3D __em_nl_get_pd_table_id(info->attrs); + if (!pd) + return -EINVAL; + + msg_sz =3D __em_nl_get_pd_table_size(pd); + + msg =3D genlmsg_new(msg_sz, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + hdr =3D genlmsg_put_reply(msg, info, &em_nl_family, 0, cmd); + if (!hdr) + goto out_free_msg; + + ret =3D __em_nl_get_pd_table(msg, pd); + if (ret) + goto out_free_msg; + + genlmsg_end(msg, hdr); + return genlmsg_reply(msg, info); + +out_free_msg: + nlmsg_free(msg); + return ret; } =20 static int __init em_netlink_init(void) --=20 2.51.0 From nobody Fri Oct 3 12:14:28 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 044322459D9; Mon, 1 Sep 2025 02:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692063; cv=none; b=OQH5pOsK64EuZ1ZJFYkF/Do1zZr2dQ7ZtkQigdUFU2CeJVOyNZWoXnjLNrhfz74QpnqQAB+i/ygX6cVOcPY34hj/DC/a/Rl5hjNVYDehFZqgYrFC+0eIfwkeMnUYwzZUIkXtLU9lBmr8s263/8HxPW4nzHF96ObXHU0YmBQx2RA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692063; c=relaxed/simple; bh=KvOummY2bKQpR2xxdP6117iCBe1tIr1juyf2WSJug5s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HN5M13fgfuQYAFgJWDANzikaLE1V4OhonUn6ztvWehoasqp3zU3ezCHbPSr4CWT3cYPngQK/km4MfxfifND+QE1MSxrzpSc1Zf2JTwgRbdeUfccslqWeRuzrUr30OYDjDzyR0JqKOYHhEQwC5uXwxBr+NYWnDJsFO+fmRN5zRfE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=dvI3HbIj; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="dvI3HbIj" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=1WXvdkFJ0S0JfYEwMNPSC8cw/ahSA4Cx3+jCWy0UJRI=; b=dvI3HbIjdu1IULLtHe/jAI5bmi Dx/ITK9p5s2jsDVzxNwTeh2jz1YZ31uwyLwDpeRRUtAtrORBryYLzKm5tlmwLDm910c4IgEZPrFd/ LDSNTEtWWq1GJ637dIl3puLHbZYUosEwS5BK3mrtvManJRxmRrPenGq5HYBaJ0zbvUxhWDlkOCa46 mRE4krguLaKla3rrrKTZlMtiqIlsCDFDowbHzHwjFGKkTneOqKiWa7nH7MMlhwQQe6tjXKCZMLDSf Dl0kVNQYARcPDhEsl83zqu9HZ628qBtY8bjCx9Mkq+aaI8huLxcMBxUjUQBMhKORUEetZeKUwM4WP NwCty8Cg==; Received: from [58.29.143.236] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ustqo-0054VC-Qf; Mon, 01 Sep 2025 04:00:56 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH v4 08/10] PM: EM: Implement em_notify_pd_deleted() Date: Mon, 1 Sep 2025 11:00:01 +0900 Message-ID: <20250901020003.86415-9-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250901020003.86415-1-changwoo@igalia.com> References: <20250901020003.86415-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the event notification infrastructure and implement the event notification for when a performance domain is deleted (EM_CMD_PD_DELETED). The event contains the ID of the performance domain (EM_A_PD_TABLE_PD_ID) so the userspace can identify the changed performance domain for further processing. Signed-off-by: Changwoo Min --- kernel/power/em_netlink.c | 56 +++++++++++++++++++++++++++++++++++++++ kernel/power/em_netlink.h | 18 +++++++++++++ 2 files changed, 74 insertions(+) diff --git a/kernel/power/em_netlink.c b/kernel/power/em_netlink.c index 59953cfedf78..ff6aa848d998 100644 --- a/kernel/power/em_netlink.c +++ b/kernel/power/em_netlink.c @@ -213,6 +213,62 @@ int em_nl_get_pd_table_doit(struct sk_buff *skb, struc= t genl_info *info) return ret; } =20 + +/**************************** Event encoding *****************************= ****/ +int em_notify_pd_created(const struct em_perf_domain *pd) +{ + return -EOPNOTSUPP; +} + +int em_notify_pd_updated(const struct em_perf_domain *pd) +{ + return -EOPNOTSUPP; +} + +static int __em_notify_pd_deleted_size(const struct em_perf_domain *pd) +{ + int id_sz =3D nla_total_size(sizeof(u32)); /* EM_A_PD_TABLE_PD_ID */ + + return nlmsg_total_size(genlmsg_msg_size(id_sz)); +} + +int em_notify_pd_deleted(const struct em_perf_domain *pd) +{ + struct sk_buff *msg; + int ret =3D -EMSGSIZE; + void *hdr; + int msg_sz; + + if (!genl_has_listeners(&em_nl_family, &init_net, EM_NLGRP_EVENT)) + return 0; + + msg_sz =3D __em_notify_pd_deleted_size(pd); + + msg =3D genlmsg_new(msg_sz, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + hdr =3D genlmsg_put(msg, 0, 0, &em_nl_family, 0, EM_CMD_PD_DELETED); + if (!hdr) + goto out_free_msg; + + if (nla_put_u32(msg, EM_A_PD_TABLE_PD_ID, pd->id)) { + ret =3D -EMSGSIZE; + goto out_free_msg; + } + + genlmsg_end(msg, hdr); + + genlmsg_multicast(&em_nl_family, msg, 0, EM_NLGRP_EVENT, GFP_KERNEL); + + return 0; + +out_free_msg: + nlmsg_free(msg); + return ret; +} + +/**************************** Initialization *****************************= ****/ static int __init em_netlink_init(void) { return genl_register_family(&em_nl_family); diff --git a/kernel/power/em_netlink.h b/kernel/power/em_netlink.h index acd186c92d6b..938c84ca1f40 100644 --- a/kernel/power/em_netlink.h +++ b/kernel/power/em_netlink.h @@ -10,7 +10,25 @@ #define _EM_NETLINK_H =20 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_NET) +int em_notify_pd_created(const struct em_perf_domain *pd); +int em_notify_pd_deleted(const struct em_perf_domain *pd); +int em_notify_pd_updated(const struct em_perf_domain *pd); + #else +static inline int em_notify_pd_created(const struct em_perf_domain *pd) +{ + return 0; +} + +static inline int em_notify_pd_deleted(const struct em_perf_domain *pd) +{ + return 0; +} + +static inline int em_notify_pd_updated(const struct em_perf_domain *pd) +{ + return 0; +} #endif =20 #endif /* _EM_NETLINK_H */ --=20 2.51.0 From nobody Fri Oct 3 12:14:28 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 F10FC21507F; Mon, 1 Sep 2025 02:01:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692068; cv=none; b=rvrOrb4gioEWBkjsxJoX57JZTA21ra3WaJrTJVcE2wHOHOh6YCkJyoFlk7NnJPzI7bWOAMJ8N4ei9IwClKhFc6Ol2nsdu9bGz8A+aDBxSJ3kNmcm3sIR4/A00MUjuhMnyg+NpLtHsWBRDr3P7NuDTuDNjhPtq+VIq0gt08rYaU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692068; c=relaxed/simple; bh=0S+IcH+DOywjFMM8Qmh8T7Oe3P86Lks3htSrMJA2Ums=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ktTvBS4CuEZ1lvZaFWg1qmFMnNAxmMWWjnyuCiXnK6rtX12PcrCDeL5NlamhG0wX4PWzQaI8Jsv2YqR3TS0z1CqrgC3sVMLF9fnkr9gH+0Z7/WkRcoWG3qeys0pK+djmOx5KI0l5KGZ6zAhAhFOrSRCIfZV5JMqcLWysbnS7pgs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=NIB2mQJv; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="NIB2mQJv" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=5hWjRQ4uHs+TIl+F6dv0p+5QABRD/gqhJJCYS4oKpSQ=; b=NIB2mQJvwnjd7zvIvqvQ4sqE36 MQktOShaFUoVp2GVEUakxXy/E3vrUal519ImW0B6tWyV6zcutkymwDhy+36pY+Zlvh7cAYLUKp+sZ VygErBhKtw4fxtNulKOMH1mxgfWUYSK4e792zjzulrinVcLpUQJ38EaUp2SGkp33TmOUHecoN4xRM VuVQDxeQP2dPbIBi/ujL7lQo4KueyvvgbB+prlPgWQOSdRPrSInPE3QE6lR4a+b1XmR53Um9ZFL3J NhX3B7L86+me4mf0P3J4xRShZa6xQSL3CyoeTukft4ijZQYH6ZDhEZUN/tKwm79RAsqJesxu4jVQj 3wAYJtJQ==; Received: from [58.29.143.236] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ustqu-0054VW-B7; Mon, 01 Sep 2025 04:01:01 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH v4 09/10] PM: EM: Implement em_notify_pd_created/updated() Date: Mon, 1 Sep 2025 11:00:02 +0900 Message-ID: <20250901020003.86415-10-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250901020003.86415-1-changwoo@igalia.com> References: <20250901020003.86415-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement two event notifications when a performance domain is created (EM_CMD_PD_CREATED) and updated (EM_CMD_PD_UPDATED). The message format of these two event notifications is the same as EM_CMD_GET_PD_TABLE -- containing the performance domain's ID and its energy model table. Signed-off-by: Changwoo Min --- kernel/power/em_netlink.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/kernel/power/em_netlink.c b/kernel/power/em_netlink.c index ff6aa848d998..ff3eab078546 100644 --- a/kernel/power/em_netlink.c +++ b/kernel/power/em_netlink.c @@ -215,14 +215,48 @@ int em_nl_get_pd_table_doit(struct sk_buff *skb, stru= ct genl_info *info) =20 =20 /**************************** Event encoding *****************************= ****/ +static int __em_notify_pd_table(const struct em_perf_domain *pd, int ntf_t= ype) +{ + struct sk_buff *msg; + int msg_sz, ret =3D -EMSGSIZE; + void *hdr; + + if (!genl_has_listeners(&em_nl_family, &init_net, EM_NLGRP_EVENT)) + return 0; + + msg_sz =3D __em_nl_get_pd_table_size(pd); + + msg =3D genlmsg_new(msg_sz, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + hdr =3D genlmsg_put(msg, 0, 0, &em_nl_family, 0, ntf_type); + if (!hdr) + goto out_free_msg; + + ret =3D __em_nl_get_pd_table(msg, pd); + if (ret) + goto out_free_msg; + + genlmsg_end(msg, hdr); + + genlmsg_multicast(&em_nl_family, msg, 0, EM_NLGRP_EVENT, GFP_KERNEL); + + return 0; + +out_free_msg: + nlmsg_free(msg); + return ret; +} + int em_notify_pd_created(const struct em_perf_domain *pd) { - return -EOPNOTSUPP; + return __em_notify_pd_table(pd, EM_CMD_PD_CREATED); } =20 int em_notify_pd_updated(const struct em_perf_domain *pd) { - return -EOPNOTSUPP; + return __em_notify_pd_table(pd, EM_CMD_PD_UPDATED); } =20 static int __em_notify_pd_deleted_size(const struct em_perf_domain *pd) --=20 2.51.0 From nobody Fri Oct 3 12:14:28 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 9FBBD21507F; Mon, 1 Sep 2025 02:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692074; cv=none; b=r/Q0mL6AsAqEv9NyaQgDw+o2zB+fB6JKk4IFoChqiJewU523CbqHpOVOJ45Go1lP90YhuAed64jCnklDDR033dV/gDxnSKA7REMJDCGuv2Nh6YZYNmXpgpGWLe9n6Pp8/BxqG6+mffaa+vz6WjPD33i+ZW5LzcqQnxt8l+KoIaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756692074; c=relaxed/simple; bh=Q/z7LI47wr9pn1YEATow99dNBdZHfjMqq5CdG8/pbJk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OBVfm4CO4ij21KJFpfiXysJdO9wXvXkXJ0do5soT2PRTmtFbudWskYml0szRPS35rwXfrsr2XLPGgQ5VT8Ya+ayLddxBtlbIvAqx1tbCqlTSPOhdQVOkw6M3Tt0kOSWfhCj+nwEWHBkbkEqgo7us0cVcymt5AyB6YbYYnu/zdNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=PxcNI5nS; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="PxcNI5nS" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=dfYbmrCczlNVG1eBqr4LEnZbYXkxcRDqXj5cgSmNT+c=; b=PxcNI5nSAmQGBfHf6v0tSJlQPU eiVG/sM8fLz44IrfC9lM/bWwWyFFrwR+6nc+V/wRt9iW+EUaWOoxQ0G2omjf3u6i7Wd0bnlm0m2r3 K0vCuXgL22VhD9txcGAWYFGqFuFR5lY8a96uW6VdNSq6MVJCYxlpmbyTfJ11KiV9Tm3vndM42hvaZ +bWhxpTTJKja068uM1mTDNnfM7by9gVJ2zN/JCGPMeaY7SCf7g7rt7carBBGr3ZXda3lynm9/JwUM hcL6pOUDQrQ1WPmQe82ph1MfRnNFxmOsDbO2b9/NfBKS5FIfXykD6/IJti6N7ghC+uoijqoEVl9MV 9iyLkGtg==; Received: from [58.29.143.236] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ustqz-0054Vm-SV; Mon, 01 Sep 2025 04:01:06 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH v4 10/10] PM: EM: Notify an event when the performance domain changes Date: Mon, 1 Sep 2025 11:00:03 +0900 Message-ID: <20250901020003.86415-11-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250901020003.86415-1-changwoo@igalia.com> References: <20250901020003.86415-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Send an event to userspace when a performance domain is created or deleted, or its energy model is updated. Signed-off-by: Changwoo Min --- kernel/power/energy_model.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index f125262a93c9..c72ac1585f59 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -17,6 +17,8 @@ #include #include =20 +#include "em_netlink.h" + /* * Mutex serializing the registrations of performance domains and letting * callbacks defined by drivers sleep. @@ -350,6 +352,8 @@ int em_dev_update_perf_domain(struct device *dev, em_table_free(old_table); =20 mutex_unlock(&em_pd_mutex); + + em_notify_pd_updated(pd); return 0; } EXPORT_SYMBOL_GPL(em_dev_update_perf_domain); @@ -673,6 +677,7 @@ int em_dev_register_perf_domain(struct device *dev, uns= igned int nr_states, list_add_tail(&dev->em_pd->node, &em_pd_list); mutex_unlock(&em_pd_list_mutex); =20 + em_notify_pd_created(dev->em_pd); return ret; } EXPORT_SYMBOL_GPL(em_dev_register_perf_domain); @@ -695,6 +700,8 @@ void em_dev_unregister_perf_domain(struct device *dev) list_del_init(&dev->em_pd->node); mutex_unlock(&em_pd_list_mutex); =20 + em_notify_pd_deleted(dev->em_pd); + /* * The mutex separates all register/unregister requests and protects * from potential clean-up/setup issues in the debugfs directories. --=20 2.51.0