From nobody Fri Dec 19 17:18:44 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 549012BAF4; Tue, 14 Oct 2025 00:11:20 +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=1760400682; cv=none; b=OVHccasKXxX+7P6wIDV9HR7TrXtnKnGiXiW71CDUs4Aqxcz3KOMJJjzgTl98gXVaTpHoL1KvQlDUhfSXA1lu4HljUhjvna7RntL0RoOUpL9mQ+Wo6lMZ73CjTwuShNohVja1ZPDUXHCWo+d7dvFVWKg5CS55LRShyFeNeYhgdwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760400682; c=relaxed/simple; bh=wlQBcPZyWi4XJKZtUGEByh7ydZiyuKMFouVRuIWp7Pc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b9fz0y5t19yPMflzngAgVAouqVju1XOUviAEbkiNT0WP1y/gkRk4LMfhl0ZXVpq44yZDqHF2LPFTgXwbLGz41kUqY4/qPdNT/PfLV9K1whov+Xqzqw/ezB0I8qYB1gscHJcqlwkwZuEtSb7TxXfCGPiS6krZ919lneubLuJb/9U= 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=GYVdnbke; 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="GYVdnbke" 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=wNeq7npuhqJJtVTAMtq3WXXIqglRKR2ENbm4FZ5tNQY=; b=GYVdnbkeEIxkc2QJBuvlxoZgdR cmw0WSfI+49dAgoHHRrEchRyLzAIZ97V3cKblKQn2XcwpOU9mgafO5WmAaN5QS9O+Q1H0IqBTlbC0 UrLTkiX7WPkFuMFF29tT8vMdgZJXBGK10VoCs0HbnkHTtf+TGcppN+98fVHDSDXak5jCwpyJo303n ozL2ccPk9zpol5o+Px2eKoCJeOmUqq97uksXjqDJJ2mo3sSOMf2hAfu8e3KdG+QWLpy3j+2nUBdvB G4ZKZ9QtxlNjQn99EN7cI8vgS8R1ozvHhu1SlHN9QJfJ65haaa2Gs4MOLSKUwkpYu3ShmX8C5gVLc gS+JizYQ==; 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 1v8SdC-009A0V-G8; Tue, 14 Oct 2025 02:11:11 +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 v5 01/10] PM: EM: Assign a unique ID when creating a performance domain Date: Tue, 14 Oct 2025 09:10:46 +0900 Message-ID: <20251014001055.772422-2-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251014001055.772422-1-changwoo@igalia.com> References: <20251014001055.772422-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 Reviewed-by: Lukasz Luba --- 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 61d50571ad88..43aa6153dc57 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 5f17d2e8e954..2047b546ad11 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 @@ -660,6 +678,10 @@ int em_dev_register_pd_no_update(struct device *dev, u= nsigned int nr_states, unlock: mutex_unlock(&em_pd_mutex); =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_pd_no_update); @@ -678,6 +700,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. @@ -689,6 +715,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 Dec 19 17:18:44 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 020EA14B96E; Tue, 14 Oct 2025 00:11:24 +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=1760400686; cv=none; b=bm5cLCg5Ebrj/LSIuDUZJGTxaaeIjOZrJIb5fJiYrVETYAaee3yb7HEmdrb1+WEXObTEXsGDmWc4KfbhD7enIVt2tgYyTFVoZHz+K8lj/tOm7x3jLA/MdGjCQpWIwetZWUmSGrYbFRvKzAjMP6DvTX8WuwGnU9btXiah4B2GCJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760400686; c=relaxed/simple; bh=9jbdxG/yYl45/d2BFNEixkOPueLzjLBmv5pZ2mERtM8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RUKceY1fVUqIV3MEv2FycB9cZ8GSYPLk1LjWWPBCkUUNZcrkMF6/ngKLXDDZ5FAnyPJFn1YjK0A477D46nmIFaPffmdhI4ohHYuMPptAOG9o8Ym9HJ9U2ijzzDLlVC1o2gg+FvWHaVYmW7bDea4/EDu8U4qR2AsGbznrsh9oxDk= 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=V8cPcTW3; 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="V8cPcTW3" 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=5GE2n1kb1gICkuq1rlxBJhLURqi1QRDOFHOZQlp1fSc=; b=V8cPcTW3tnrWYdCacnhR05mbzX 5aiXu+CFxvFtH4vahmLz68We70FTNF8yU13QyCKePLdbxxcIIJAmBCEWBqNyg2NOaitIcDRpxentM RwR/oLz6MkhrruuFemoXScHhn63qmq08Q4/5nOi68v/agUEDDJpH652nz+Xheqgi4u/MHq8VhSyXl Y2PLcsQ3+87J2y0k3MDB6uUYOLFLrJvYMUVaQZown8mVnFJ5uXVYffxFKe7e1UmghaHxJw4I6WYp3 unaIWv8qOhswIclbrkGK/RlxcbEumSsBwDgp+maVPsy5jW7ChUL2hg1nF+7940Nim6IzwPf78g+zg RvZEIyBA==; 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 1v8SdJ-009A0g-IX; Tue, 14 Oct 2025 02:11: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 v5 02/10] PM: EM: Expose the ID of a performance domain via debugfs Date: Tue, 14 Oct 2025 09:10:47 +0900 Message-ID: <20251014001055.772422-3-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251014001055.772422-1-changwoo@igalia.com> References: <20251014001055.772422-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 Reviewed-by: Lukasz Luba --- 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 2047b546ad11..756debf5406a 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 Dec 19 17:18:44 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 BD9C7335C7; Tue, 14 Oct 2025 00:11:31 +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=1760400693; cv=none; b=esnnAvWAVfeWZKSUIGIGf5haLeyNpfVxhD26zSWQ0gny3F1/19xOUHLQNnHEEkSd9y+JeZw5hXt/8D+OL6VNDrvRgr/t7GSVOrsWfVFgH03MmoJ5kKbh+L5HoxydzfFiap9j4pd128SQCb6EeUrwQg9YH79cB+SfZtMOIoJq/y4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760400693; c=relaxed/simple; bh=+E3hC8f00PdEY77K+CAO/v0c/7BBnNHQrZNmKV/CU7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I0MT7N6GTEkxA4ZwxKhTCld3+SyG7cMe2vN2vTLVCBDi4iS1kq61pYy5CogsMOhCADtXINtvDcsyDDB3nc5Hl5mQ0Xc/9JiRuw/WtacyuECaszN2o3uZirACjRXAFUtNgiSJYeEXaRZPOo+0nwiv1KTL+zkQklil7Ri9LnuYRmQ= 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=PdO7+T5C; 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="PdO7+T5C" 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=+9roA4MsBeAUM5B0n67pGgmkCsdD4rrGFfEhIW1D+0o=; b=PdO7+T5CszkGFQ9//jO0RQALvc 6SkTRrxLTSJKcM51m3/70kEDAldTIcv5E7CI6T4FG0T/aJzsXXD2bK8whCFShcOBbWFhMrfVcS7lX 4vgue79IutyHZENkDV2NSYH4GADX/i3AwtVrQwVuEp6tLHmB0/AkEX2VGCRbMlnHLRXMvC0/6KuR5 koSdxwNxhwA599pTmDrH1ryifct2sOIw52vmfu+n0aLUr5RYIxS/JL1duYYLYFh8CIRjDpdT9KDdX pv2qTPmsxrhOZe3r6JlQOi/HA9db2ChqHR7D2/0Ixd7pAEJAsfRaZ6XIcjTx3TS2Kv6Pio2lLyb8g 6uVstKCw==; 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 1v8SdP-009A0q-H4; Tue, 14 Oct 2025 02:11:24 +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 v5 03/10] PM: EM: Add em.yaml and autogen files Date: Tue, 14 Oct 2025 09:10:48 +0900 Message-ID: <20251014001055.772422-4-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251014001055.772422-1-changwoo@igalia.com> References: <20251014001055.772422-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 Reviewed-by: Lukasz Luba --- 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 46126ce2f968..babd7088fc1c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9180,6 +9180,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 Dec 19 17:18:44 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 5343A335C7; Tue, 14 Oct 2025 00:11:38 +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=1760400700; cv=none; b=Hoj+yKPuwfYUBUgJ2flyx3hEFyRmek7d0B0yDw9rBX+D7Wqe2mN4eXNgViMkjhAPtCdl8pUjgJeQFQ9bKpm1u426vYLOLUwRIRi37bjUgL2nwmcAxu6Yu/PlQECABnwhccvmQUIiHXRA5f7wAd9Ef7fvMAZj0lZqvM04m7kX2oA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760400700; c=relaxed/simple; bh=YAl1vjzFbZOL3qiork99EDV0zJFx7mUIQCWmcJ0hq2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A0pFrnpUpucUsgWjG9off3R+u1YKwq7odsvueIH9ezsTcbeXTbdr1Z7zbu+4cabbmD6fCKp8hJqBUjn023m0j/36TV8f/crzLbmsuFVRPknkZ/tWIHS7v2pGCWrNEEggm6ef7NeXqHLlONPsWsOiyuiPlgI4HcaytqSbTvKIkRU= 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=eF65qDtV; 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="eF65qDtV" 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=15vV3+SPFyZkjQKr1uAMsry2Dahq4tig7wyOGWaFCi4=; b=eF65qDtV9EMX7j7QKS8fW9Pm1a Uhbn9TiUy5JY/IM1MKkJlVvd9/fk2KNqOZKdmR8kO9o3UWlfqdMXsEJr62YSBuJwYj47vf3oupHrY 2wYEBt+qRp9ieYH0/Ya8ky9mIlZR2WOTasqDILvcPh4WTia/JusmVjwt9j2Y9VYVwHGB/aVxCWLC5 tIwmR9aPydusWiB7BbCivbRDw6V+MJZl2ulFQ53d6CCZrKNnwmjpn/xOw2A08/xr/sOAac3KvTLPW LOKUMXqaP3rSxbQjYov7f9I4VhWgxR3UpKZg5xTU6dm/NDF7h6vQ6VE8Cd3jHHZzJf1/7vri+pWp8 YAzuDnMA==; 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 1v8SdV-009A17-Ri; Tue, 14 Oct 2025 02:11:31 +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 v5 04/10] PM: EM: Add a skeleton code for netlink notification Date: Tue, 14 Oct 2025 09:10:49 +0900 Message-ID: <20251014001055.772422-5-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251014001055.772422-1-changwoo@igalia.com> References: <20251014001055.772422-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 Reviewed-by: Lukasz Luba --- 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 babd7088fc1c..bc2c08e6f0ac 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9182,7 +9182,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 Dec 19 17:18:44 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 AEA202E63C; Tue, 14 Oct 2025 00:11:44 +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=1760400706; cv=none; b=muUmOOQD0gMdONd/eafnR50khn1cZ/T7YTROWhBHJAhhLH8+FqT1PFE7x0QDtzkBYlkyXuRsgsuQHqWN/HhJKBWBFEmcVZaxnMTTQNppXOmSGRuJls5cM+Fxy2l8o5KapadSyAFH1cNP9Qt5Bonsx93FYYBeVDri03w7JQRMTaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760400706; c=relaxed/simple; bh=/4jHAXXsE6z0esH6njaFLFzCZF6GLER/C4lS3jif4/A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gtHWvNFYE/InP9wHaAjoFIemHoyXI6SjLssSEao8qihmqYxikoZja1naYUuJfpKN8/EAE/alTNVT/58tHuiABnvH39r3NRIHfgYIeTQJtsPkg2SWUsS1vY4qnrGg7XybIRxOg6m6JJKUrOOaBVuHD4oXWyY9oIak7WK6baiAYzY= 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=JhKbuU29; 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="JhKbuU29" 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=rTY551GlcEu5wlZKVwikaNPYgNimBgZh0bFw9SyMiUE=; b=JhKbuU29H6tWdvIh+ML3GKSFEq 3qjrmhvBFath50j4A1sXDebXhfz+6I4wBGazApsH+p4wDjEFlHvuo396IQqAspNPrKRnYw0JH/SS6 qIh23sH/omK7NOF84LG2WjdxXK3HjoEPUFjrePIzAfeVE2re14oX0Fcakoh9rvZ2UhABZcP+BcHzR wdYv+I3RQ2iBmfqyt14QVLtDSlWK0OjblBsA6VXoWAZDznh0c1AupDHo4qgJ0b4IS9Zc0ojlJ9WSg iGY+nVmWK+OcqGT/xfBHY85K/nkeqoDW1r07UUKcsiApa+psOy1cZj74j7eBTxrCZ7GAUI7TCt3WK 2lrG/xmQ==; 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 1v8Sdc-009A1O-77; Tue, 14 Oct 2025 02:11:37 +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 v5 05/10] PM: EM: Add an iterator and accessor for the performance domain Date: Tue, 14 Oct 2025 09:10:50 +0900 Message-ID: <20251014001055.772422-6-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251014001055.772422-1-changwoo@igalia.com> References: <20251014001055.772422-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 Reviewed-by: Lukasz Luba --- kernel/power/em_netlink.h | 14 ++++++++++++++ kernel/power/energy_model.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/kernel/power/em_netlink.h b/kernel/power/em_netlink.h index acd186c92d6b..8114b018c73b 100644 --- a/kernel/power/em_netlink.h +++ b/kernel/power/em_netlink.h @@ -10,7 +10,21 @@ #define _EM_NETLINK_H =20 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_NET) +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 +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 /* _EM_NETLINK_H */ diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 756debf5406a..43a243f9cfa2 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. @@ -998,3 +1000,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 Dec 19 17:18:44 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 9466E2E63C; Tue, 14 Oct 2025 00:11:49 +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=1760400711; cv=none; b=X+qStaHodTUjxLesn4fkE+M5V8otXw3eSOdi2JHeBRhq8BPhWbgqlPx8ockxvjRXHUOC5vVe27PP/XRb02dFnBhSC7IV+bs87TmtSq2rIp8C0LMSkDhZmEwQ+Zl7zGhgHe/p3ZSyE9aVGwJmSGvoNXQTWNZlDHF2GQ+gXkIa0+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760400711; c=relaxed/simple; bh=XUV4wmTBsIzd42W2BwVmtZRZ9e30c95ouxD1hmQOu4g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Se53AdeNJqItFFkPgI8ztpyi7rUHUIawGgjPZPhAvfSpscKLhHpFBIO11Eahb7kybr6QOrXoefmdAoGEqGr25q4Vg11/FlAvApvp3NBjaLx+L04iAQd4vjiMq6HIeu43SpTma8v2jhq6geoCsCMjUYykdxS/ccdK8hWAIrNUUYU= 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=b/QEKTjx; 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="b/QEKTjx" 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=Z3QqZYj8x3M5weQ58upVJvB8rBfrK+5sn5Z3iFMUmg4=; b=b/QEKTjx20XMXw83BaCJLpBBfJ hq4mPjpyuCh3sfDlkRkzQjoLx6kV0DkeB+C8xPjmtU66EjU9ZNHcPHIZ+l4gCfV2zeBLjHYU23UxM W3oZFsanRVDxg/kJBkzzJpS1+koeqn9M9XzR7V4OvGLZ7T7+4NJXLzYn0IECpd20XNJoIImZRFtri g1HHkAN9fzVJikbLkrlFhXN0Vzc5JrBolvxBZx2ORdDH4+r937Zy8e77oPv/eMlkY5EhFIwyqWgBK NsBUyUrVbi2k3THynO9NLLQcZGaWN3T4iiYqmMqPYloIZXiXA0E/WwV7S8TjpqnGZwdgcli9jMEwB mn1Y72RQ==; 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 1v8Sdi-009A1t-Ko; Tue, 14 Oct 2025 02:11:43 +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 v5 06/10] PM: EM: Implement em_nl_get_pds_doit() Date: Tue, 14 Oct 2025 09:10:51 +0900 Message-ID: <20251014001055.772422-7-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251014001055.772422-1-changwoo@igalia.com> References: <20251014001055.772422-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 Reviewed-by: Lukasz Luba --- 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 Dec 19 17:18:44 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 22D012C181; Tue, 14 Oct 2025 00:11:55 +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=1760400717; cv=none; b=I9hnap46/iQglL4wUwcn7DQ07pxHSwva4VHUB3F7FfwYZJ8QwnTsiozvrCPqSIZ8vn7ka/zGU449BAqigl9ki78549PPUcxEvd5ROD5W1aPFJBwCaYD4zuVO2TuVWKYnUR5L2Xeva10feb8ayQ2NZP0ufEUjZH7Y+pOJp9Bb9kE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760400717; c=relaxed/simple; bh=U2DU/OTOiZcEtlNkovdScE3xUBQyMEceDKpAFmRh8vI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mJgHT+Xf8dPQ/HV8cLYMjZJS5nkWX5zZkGVQX8vwsWvHrsYRX6E5hHD/Sv2UkuMVh66Rz18vQWn+1QKfEI48tRf/OlfEG+fOOae1EmsYWwC28hGDPzYKMcFj3xAks0NRLgcgLvqTpom1Uayc+nLl55WhOz868b5JJxC/y8EDKiw= 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=l+RaTSd9; 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="l+RaTSd9" 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=SdcuKc3Ph6/H1B4oeOgafml9S/6yxxMJCamUPzZsoNA=; b=l+RaTSd9PYMAmBUyh88AgbW6Vc tsvqaO7uJAz9fUUtklVEGdbhCU+vjCswoh3sR3JZZYt+RKLlb6/sdB3HWjxxLb1CDgk7hJvkVatm7 zY6AW6PDTSePd5BDZAu2ksWxeg6LJkYXQVkhgcdqmY2B3qq9mp5KqoWZ6c14wYcMArlfN4DidYrgD JYCDSOfypRrAa2hakFAyDPcnF+3lxaH2b9lqngWhodoIIeZFgBOBpN9tz7YtXTF5cXEsqgs2iHRLF m4XXNjlk9O5pR/sO5LOmFq4uVgZeeRoeyCZBf7qSL1rYtmllCCcUOkvhqH/0zdefLdpE3MZKwhrPh MZ30JGRg==; 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 1v8Sdp-009A2J-7A; Tue, 14 Oct 2025 02:11: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 v5 07/10] PM: EM: Implement em_nl_get_pd_table_doit() Date: Tue, 14 Oct 2025 09:10:52 +0900 Message-ID: <20251014001055.772422-8-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251014001055.772422-1-changwoo@igalia.com> References: <20251014001055.772422-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 performance 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 Reviewed-by: Lukasz Luba --- 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..2addc143401b 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; + int cmd =3D info->genlhdr->cmd; + int msg_sz, ret =3D -EMSGSIZE; + struct em_perf_domain *pd; + struct sk_buff *msg; + void *hdr; + + 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 Dec 19 17:18:44 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 29D7B2C181; Tue, 14 Oct 2025 00:12:02 +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=1760400724; cv=none; b=VIrl4c5LJOFq66lYCyItwii7Vp5f9zKcdR3mOs31CZIXrvGb1qKaBVAMeIJwA5xja28IAUXUSeWgpmJEBqtsmrV/i2VgDvSdii06aW/XR09Kzl7/CZQMojPYtJ54g+lHPkPn5eYY+LlW6Rpg/XlZ0bRc24tZbF1Ye1i9CpgUiTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760400724; c=relaxed/simple; bh=unBWwyUCpqVk8l15y0T4LgLhNCWui4FMxZcqxbWUnzY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M+zmGEyBRtf+nVOn4ptEtBunX2tqJWfBcQMJ1cREiTl0W+gTW7o8vhai/z4ZeVbLR6Wmpm/NXY24ftu9niBI3Qth+pULPSuOSdwnkIvGx6Xz6ZfKp7aVKFNZcXz8MJ0wbNheAa6Qis0Stflg4DB4sqLvGkk3SpXXeDkiAWzA6So= 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=qqKPXk8F; 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="qqKPXk8F" 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=S4CFnS0FJ49zkyKs61+rLYVBZXH7FuGUo/kfw+zIWQo=; b=qqKPXk8FwVhxdQxz0P29FrgsG9 kS0QvYEsrB16TICm7NQHEtE/+F9vVQZ47fFldPXL0rXyN8mIYHFzmDy7bMfxZXCdFYyUqUU7f/S0V U3FSnihbxao9s/wixz/iD2N2AyA9w5g3DeIHGIPY91vhvngfRbVGSOU/+XrMYfRem32RNqPdTIyj2 SlrmxG1TEkhT7INf49Zchy4ALgRXDjshQDTBAOHjadQ3yi9Yul+HydCMuaoMCwwlI2kH6miP8n4E4 LDPfpUUAS3DvYESjDNnHSY1YW5m5hGH6SE0rF0a59NfiKvANJb74A+mQo2DSmwPZ7beGQEACOa72H NszO8l2w==; 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 1v8Sdv-009A2h-Ok; Tue, 14 Oct 2025 02:11: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 v5 08/10] PM: EM: Implement em_notify_pd_deleted() Date: Tue, 14 Oct 2025 09:10:53 +0900 Message-ID: <20251014001055.772422-9-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251014001055.772422-1-changwoo@igalia.com> References: <20251014001055.772422-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 Reviewed-by: Lukasz Luba --- kernel/power/em_netlink.c | 46 +++++++++++++++++++++++++++++++++++++++ kernel/power/em_netlink.h | 3 +++ 2 files changed, 49 insertions(+) diff --git a/kernel/power/em_netlink.c b/kernel/power/em_netlink.c index 2addc143401b..90ae6f1c9c9a 100644 --- a/kernel/power/em_netlink.c +++ b/kernel/power/em_netlink.c @@ -213,6 +213,52 @@ int em_nl_get_pd_table_doit(struct sk_buff *skb, struc= t genl_info *info) return ret; } =20 + +/**************************** Event encoding *****************************= ****/ +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)); +} + +void 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; + + msg_sz =3D __em_notify_pd_deleted_size(pd); + + msg =3D genlmsg_new(msg_sz, GFP_KERNEL); + if (!msg) + return; + + 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; + +out_free_msg: + nlmsg_free(msg); + return; +} + +/**************************** 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 8114b018c73b..d56e5865e1ed 100644 --- a/kernel/power/em_netlink.h +++ b/kernel/power/em_netlink.h @@ -13,6 +13,7 @@ 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); +void em_notify_pd_deleted(const struct em_perf_domain *pd); #else static inline int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *), @@ -25,6 +26,8 @@ struct em_perf_domain *em_perf_domain_get_by_id(int id) { return NULL; } + +static inline void em_notify_pd_deleted(const struct em_perf_domain *pd) {} #endif =20 #endif /* _EM_NETLINK_H */ --=20 2.51.0 From nobody Fri Dec 19 17:18:44 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 224B81DB54C; Tue, 14 Oct 2025 00:12:09 +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=1760400730; cv=none; b=pS3ayfdlmO1LWyjv1o4Rn3BaKH5EDz1tZOChT7ZI9fOYQAK7UGM75HcJ/wemNGJWVd21MEt9iU1JLuz7F8Iq5rE2pfe+aVwpr2JPSqgKu/jsxzTYPQ+3va6vkf35838R3hPWvJME8J6Lhy6qqA9e0+LqOJpx5MinnQ/75yqrQIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760400730; c=relaxed/simple; bh=/16L3h3rPcUia/KBdLLqDT3dFEA2tNiKZtoA+scMIE4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EiGkforxyI6W/JA0ljX3W+SeeK+dCnLjIRk8PF3Fhtr2ZEnD7ZlHu6JHJbR9qmohNrBmjQy3K+WGZnU+nXYbdD06kL/Ik/C5R5Jn5vEGO1VRbCQWEeLIeewz4m/ATF1AlRWdBK7USVKpFbljC6q1sBpNtArXNwOfE0xFQz/aI3Q= 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=N/bFgZtp; 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="N/bFgZtp" 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=k2PC+Jj1kTBOAx0B4bO5XOI3bA9NYDYZCPNoelOj53M=; b=N/bFgZtphU9PHGFre2zIMXcNH3 kH+xSuzFfGL/B0CUJkem4YA5jpxM6vrB3krA8DbncfhzjWSvuEoMeuBeJDWDBHfqT84a5tSDJPVFx us8ed43Fh22gUG2Cdv78vjf9jXqNosBkUzyqi7cREAwIDZ0m8+UeDWRLq3Zhx34cwSQ/UiGVQ9PIF xKUy8+m5ENrSPMCFOwhwMycX0Q+EInhB0rF5npFDK90CJ2OVG3gtVVlM/UQgEf3cIeYz9m9nwYCZb 9Q9VRaHp4IKWXYL3hfoJjhm6xIRqvETIfw2C/e+oXuTH6Fa1Cy9vfQjR48VT4KXEOEQFUUwjDDiWW BCgAnFpg==; 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 1v8Se2-009A2z-24; Tue, 14 Oct 2025 02:12:03 +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 v5 09/10] PM: EM: Implement em_notify_pd_created/updated() Date: Tue, 14 Oct 2025 09:10:54 +0900 Message-ID: <20251014001055.772422-10-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251014001055.772422-1-changwoo@igalia.com> References: <20251014001055.772422-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 | 44 +++++++++++++++++++++++++++++++++++++++ kernel/power/em_netlink.h | 6 ++++++ 2 files changed, 50 insertions(+) diff --git a/kernel/power/em_netlink.c b/kernel/power/em_netlink.c index 90ae6f1c9c9a..2c55c758de6b 100644 --- a/kernel/power/em_netlink.c +++ b/kernel/power/em_netlink.c @@ -215,6 +215,50 @@ int em_nl_get_pd_table_doit(struct sk_buff *skb, struc= t genl_info *info) =20 =20 /**************************** Event encoding *****************************= ****/ +static void __em_notify_pd_table(const struct em_perf_domain *pd, int ntf_= type) +{ + 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; + + msg_sz =3D __em_nl_get_pd_table_size(pd); + + msg =3D genlmsg_new(msg_sz, GFP_KERNEL); + if (!msg) + return; + + 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; + +out_free_msg: + nlmsg_free(msg); + return; +} + +void em_notify_pd_created(const struct em_perf_domain *pd) +{ + __em_notify_pd_table(pd, EM_CMD_PD_CREATED); +} + +void em_notify_pd_updated(const struct em_perf_domain *pd) +{ + __em_notify_pd_table(pd, EM_CMD_PD_UPDATED); +} + 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 */ diff --git a/kernel/power/em_netlink.h b/kernel/power/em_netlink.h index d56e5865e1ed..583d7f1c3939 100644 --- a/kernel/power/em_netlink.h +++ b/kernel/power/em_netlink.h @@ -13,7 +13,9 @@ 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); +void em_notify_pd_created(const struct em_perf_domain *pd); void em_notify_pd_deleted(const struct em_perf_domain *pd); +void em_notify_pd_updated(const struct em_perf_domain *pd); #else static inline int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *), @@ -27,7 +29,11 @@ struct em_perf_domain *em_perf_domain_get_by_id(int id) return NULL; } =20 +static inline void em_notify_pd_created(const struct em_perf_domain *pd) {} + static inline void em_notify_pd_deleted(const struct em_perf_domain *pd) {} + +static inline void em_notify_pd_updated(const struct em_perf_domain *pd) {} #endif =20 #endif /* _EM_NETLINK_H */ --=20 2.51.0 From nobody Fri Dec 19 17:18:44 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 4AFB24086A; Tue, 14 Oct 2025 00:12:17 +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=1760400739; cv=none; b=VfEPi7WH8KwWJ4PUBkyQwo1CE/8RoCEsLqoXymcYexz2/WdPNK/LnLANs69Bwl0R6NrVOP3r/K521yerVL1bWOn2cQzcEo6LEcFk1n0TuXm4XT4GT10zAlY7JSnY5rBxidBFoGQtd1szOYj+Xbl0pPtoUN2znH0silRHKCy8yBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760400739; c=relaxed/simple; bh=lBfJGD9vPAbkBHzVdKJoFEgWZ+a3EijfTwd7BO0hgfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IrC7Ep3CBh7bGqhMYDPSornh2J4w5QSXLrAIbwX/+Fy/NT9FUiyx1p/om5dwjAGjKhLRYOHEVAsUMhBqbU7uljtLF223eUR8qFLwwyRkm7Vnz1BJo6yH1E6lwyqUFr2poLbW8GkZiipRiYvqmGKvDjVJmw15KUGPu/LDAD8ThdU= 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=fMFnHTbe; 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="fMFnHTbe" 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=JirnQ7lX6Pekhu8u3oHRBRn+9V7t+JwCPP9RGW/kYxc=; b=fMFnHTbeUFMNwEvTyz525K2doP b6yyhec0cf1uT7amehASwDieV7D3l/U40ZM/zzjGY8sVxJM0T3KU2WLzY8uTtPvfTJNwScfrSzVRO i7DzYh2aPENhikPNw+VTGE0cnpPuKhD9JbBS3vKGdSLrVsbsk9aqXbvehvAfiOo/BWKWOh7y4G2R1 4jeZd7z3QxIptMHNpIPALtqTBxtqnwjM++eAcV6RmdxCLjoMqvRrdpmIHbgiQpCfZjvIj55CZ0Rv+ a6q/HTNgDFkhItlC82/Ofw3VVlAFJ1vef3B/Fxrolb6khVWfJ9/zfhd/VYZlpI7zYq2AdeoZV5KB8 HepV8V8Q==; 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 1v8Se8-009A3C-Sg; Tue, 14 Oct 2025 02:12:10 +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 v5 10/10] PM: EM: Notify an event when the performance domain changes Date: Tue, 14 Oct 2025 09:10:55 +0900 Message-ID: <20251014001055.772422-11-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251014001055.772422-1-changwoo@igalia.com> References: <20251014001055.772422-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 Reviewed-by: Lukasz Luba --- kernel/power/energy_model.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 43a243f9cfa2..92c12b5983ed 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -352,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); @@ -696,6 +698,7 @@ int em_dev_register_pd_no_update(struct device *dev, un= signed 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_pd_no_update); @@ -718,6 +721,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