From nobody Thu Oct 2 06:17:58 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 C7DBE288AD; Sun, 21 Sep 2025 03:19:58 +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=1758424800; cv=none; b=Iaw0K/2an0zLUaB3yvzpRSPyaLGmVVNHHcSEUWyfWZfobx0c+ydbMOw44faK4X+IrTpmI0DVDH03NdbDEm4D1gvWE3BB8hIvWlUiSoqKsIqnBsN/Yjd5INFcqVfETQr+nVdjNq4k5Yvr7np9+Gwio2R4LuxJQYE997nRlRWFHMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758424800; c=relaxed/simple; bh=IkKkOUgrYfrfI++CgQqK55HiHx+dTXxKBbBjq3m8pos=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r8Wdriu6r525zDY8FxbJosKg7rBrrq6l/s0zbte3q1AyZ2WyZkMz7z255O+lRg5KMB9OZ6/g7cLWX03OvXlmanISDRngyD4fiEQ0ZX6i+AygIBSyhPZzQJvGRjQemT9kuZ6gMGLHjvT3jmZAVExrRtOVFbWkcAM2VfRVKUFHKEc= 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=JE1ZQmqj; 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="JE1ZQmqj" 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=hq2n3geOz0i2CrRjSxWSg7ODeRVBE1QluJAJcN3K3OY=; b=JE1ZQmqjwI63A4G+byybHHFtaQ jrv6lYCMuFVW9IDlvbjwLsvPWqpps96hHFurW507tMQpKz30XQIMTwuMPZz/9HpV9TB/58/YtTnPM m0baaprpafolbVIMhLZS2+NW5OdJtV1J11GMzKFBS1370MvgwSEjzkqp87+Q7mzPnUz8EeQUn11rx HPmLIDZUiXLlO8p14W9yt0WOLuJRfFU0g3SuEVfNpVbUB3FKKxMKXoP00bI/2RjH+TOwdcBQrNSS3 fDZ+uXRCGFSc8RL2Jf035QftNoow2mQ2X8Dmxp0lN5zTJCNCrJrNinRIq6bsnBHFLoBCi8St2izBP nX+cJzZA==; 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 1v0Ac2-00Ecfh-7q; Sun, 21 Sep 2025 05:19: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 RESEND v4 01/10] PM: EM: Assign a unique ID when creating a performance domain Date: Sun, 21 Sep 2025 12:19:19 +0900 Message-ID: <20250921031928.205869-2-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250921031928.205869-1-changwoo@igalia.com> References: <20250921031928.205869-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 | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 36 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 8df55397414a..3fe562b6230e 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,13 @@ int em_dev_register_pd_no_update(struct device *dev, u= nsigned int nr_states, unlock: mutex_unlock(&em_pd_mutex); =20 + if (_is_cpu_device(dev)) + em_check_capacity_update(); + + 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 +703,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 +718,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 Thu Oct 2 06:17:58 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 26F0723ABB6; Sun, 21 Sep 2025 03:20: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=1758424803; cv=none; b=nEpQYFul9cOccHB4ae3NWccXkPGH+Qbm6SApNjKRMyz16wO36aSMRsdFg/ERjuJzlPt2n/3DuAtV6J22mr9bL3YMJHJjpy54isyQXU5S+w5BjfMe2ART79e7L4QDrqrcPNxq6SzgJJ7dZ69HqOQtoJpekNxAy8bLGeFlqSmXURk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758424803; c=relaxed/simple; bh=vzPToS00sAaSlBa/zWzdMB+aZcRjUHkgd92unQhEelA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=awEuJh1OFKBxShdBFLI+UpBoX00xXeN3bYjkgSSVrtGvzpCnQurQJShcHb3jAbSPherpMHvnyQsGpTUGAdFhEUCMeCXUrATKG/AP/JGzUPoOzWjmj8wCBWY8Kp2dQVhpIpduR8OpfsN9QDcV1l1qdQPrKos6wBA+dJ82iSzKyk8= 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=PClitsM0; 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="PClitsM0" 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=8CJZftMR/Gj0POFf8Bpzi7R4sOx8MiU/XCx/07J/Ugg=; b=PClitsM0i4zfF7NIOJV6pdGGnd 5n0flr0GIK0yJT3gz9BmkAgLnCdMlBHWw2spwRVdvjV0ADet7RAxMepwFxvgMxh9Tgfl7ur28UsHd l4coD1JAX0fNBu68ntoZaqZbtumbIxcqosZOcRNyl+28S5LESicabRKMBxyLHwb29iC1L0jXaSAYa e5vG5jvS8VdTsGAy3cnSYGHZrztgV+YHvoRY3kVKSovr5dUxImbdTjxISuLlB+AXLmYso+pNp/FXf pBsprKQHF4rvyItBhQkYjdqridM2PyGgjDkUsG9SIKj09LNiF77pah/wWL7cWwLn4auqRUIeQqagM nVBaMVjg==; 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 1v0Ac7-00EcgN-FA; Sun, 21 Sep 2025 05:19:48 +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 RESEND v4 02/10] PM: EM: Expose the ID of a performance domain via debugfs Date: Sun, 21 Sep 2025 12:19:20 +0900 Message-ID: <20250921031928.205869-3-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250921031928.205869-1-changwoo@igalia.com> References: <20250921031928.205869-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 3fe562b6230e..8998a7f4910a 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 Thu Oct 2 06:17:58 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 5F07919D8AC; Sun, 21 Sep 2025 03:20:00 +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=1758424802; cv=none; b=UN47qUyeRxdtyBTMXOFsuSbmVCyDRvKgHjMUQng4MPvF8l0RwfUxPKQ4lzso9Rf2MFRZYCftXgzCMrxXafYmg52eoAClg7DYJCnG3ssz9rW1cNjbxL5FcccWRShbtxCoIYLnBCFDJWiEDipx3r+M46OmfRyoEszCBXP/mPH7SE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758424802; c=relaxed/simple; bh=++DyOH7ugH24cdWoPjX9APMDPkk9z7CzN6Vn9Y7tBDI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bYUmt7GUWnEiJrdnyg4BiFbvfVnnTmjyA/Wcd61pvzd2YHWA7zb+Qo/7skWzDTEUKUPnz00BWxv/uOcIQj7KwmBD5oW9X/u51LRWFDtpLUVHTOZ/jhYNZT5lft5xVLBobZb45qzAZTIv8gzzwh8L1Cq+r8myUXTae9agsTlX3xY= 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=U2oh9fMP; 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="U2oh9fMP" 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=tGdlpJHxujfBfzqdZKtnvcATGt39HpMaCyzFMXZeR7w=; b=U2oh9fMPqXZII/pckcGc+0Yznb sa6Ippk12xdmDxZm6AGmQZmpMe3Ru8NpsHUbVwRSQAwS19pktlq95GSnI++6ET4YfshcsLfm57lFK 5pZbzgwlkISA4AQ/cN/6ZA6P8VIC8O9vpxCUQPmskMaJWdrYxFLdl211B8GfzmNvSGqkX7lCwAHn4 GBNxK5EzuW5KIF0Ap9dFOPjlPsmfcXeVgqVaT7/cuZtr0KTSo9ljE5/M+e1c2GmfeuGqFmkZSnWVP 9M3ZosaVdXC1RXlIlly+zxM8g5o9elsckL3Mdqbsc4M5HwDGr6+MDQmqFupHVE41wDiyEGlnkubJZ ob9DQxrQ==; 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 1v0AcC-00Ech4-1y; Sun, 21 Sep 2025 05:19:53 +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 RESEND v4 03/10] PM: EM: Add an iterator and accessor for the performance domain Date: Sun, 21 Sep 2025 12:19:21 +0900 Message-ID: <20250921031928.205869-4-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250921031928.205869-1-changwoo@igalia.com> References: <20250921031928.205869-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 43aa6153dc57..21279e779188 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -344,6 +344,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) { } @@ -420,6 +424,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 8998a7f4910a..740076d24479 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -1000,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 Thu Oct 2 06:17:58 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 AE46E2522B4; Sun, 21 Sep 2025 03:20:04 +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=1758424806; cv=none; b=m+c5EbCaviB9Oy0PGVOzswkrBLT7VuT5O4SVEhBUDeubu4XkrHSk/IAqWUBPPY+DwkIYSVjyFssFw6omg1bFhhD3dLq0jWJeX6zyoQz5bvl4l5Ubo3yrcsW252sZJ6B/VUdtq2cbHzS+fjnnCw+5X+rnv4Ak7F2rf+NUalapO0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758424806; c=relaxed/simple; bh=0lui1CIFw/bbcL22uc3zDTq8Ko9UPDJcZ2h6Lk1RNPc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mr9fTPZjrkmt5PrwANHlVj48Qfr99vixjU+qYo8zCgEGk4AZWq2ycGzFKg9QQmeB7xWJpqvlbE2SmOm9CSWBmfWYgZrsCFtKNXyAHafhp0ySTrVuzZs/Yp/SDbHJxwhHebHkfbzL30T6xpFw2agqMUawlJCg1QKO6UZo3BuR3lk= 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=VG7gFKUl; 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="VG7gFKUl" 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=U9/qW7Q5/RMnOg0rjcutlCmxAmxpKYP+p64WwAelGYI=; b=VG7gFKUllB9I40BtAFw7DjChOE OS9lpCQo6yAGmsxB+I0N5hxo6go+5yw5r7zYh4bAbQHxRcLe8/ROUWaLqLQEMJdDf/b4oh8rBzgGO Mt6vad+0JYzRhoGqLD7QM7KsgTH32GcQWqnl+8e7fOPz9f7jltyWv/94aR6BfvWBCwM5cf9YWeFyn 805e/LAQNDhAPA6YNbahbJnZfa6Bdk2I2pkhb/5voPIGjQ+7g083IfK8d036uV5G4Xkce8CWEtsk0 XthuuDMbacgKyRrnuuRn/vbye1OvcTLD6XE5fEBnP8kEuE+vJKCaRUmGw+8/iRx3ldsBUcDFjZEH8 A0NueKWw==; 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 1v0AcH-00Echd-G3; Sun, 21 Sep 2025 05:19:58 +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 RESEND v4 04/10] PM: EM: Add em.yaml and autogen files Date: Sun, 21 Sep 2025 12:19:22 +0900 Message-ID: <20250921031928.205869-5-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250921031928.205869-1-changwoo@igalia.com> References: <20250921031928.205869-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 520fb4e379a3..0992029d271d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9032,6 +9032,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 Thu Oct 2 06:17:58 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 2ACCC259CA0; Sun, 21 Sep 2025 03:20:10 +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=1758424811; cv=none; b=BTTMGDKVsOw2es044knVuitcUdsQ4TAn4SYx+IAeIVT2jMYN3fHl8hAOlozkBZDmPtPKqqjI7QG3SrjVQu9p3KSNFGxc4ThoKRb2wQKzyd2c6FlteH/BAtqbjW6XOiOXdUvFt/6Qx7BE2O8HpEYLgHqBp/lfXSq0RYPwHVaAR3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758424811; c=relaxed/simple; bh=ScyLwo8zMYYfoOxTvO5Qi5nLu/DBs1uRYWX1hBg6VCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B4RPIVP5e36V0H6kUMKs/hSldXJMArBA+fJB+wL4PVd/8SIRRm7LE6OKxDKtZFC2A0A4ho9UDWRKB9LegJ9QBNZBoRt1cnbd8ply613rX3z9Gczky/KOZlhAAwBfWjLl1t0vzd6SonHv82+OIqHu4PFLuOC8QOrS5o0bkKKe6r0= 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=A/j5aoRk; 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="A/j5aoRk" 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=xLNkeMaX2dqfCjmiXsOQxM2fwMxt2hf4V9zlpl9Cyrc=; b=A/j5aoRk9+YWvwmNFrWwz33/Bx 0Fc8YLbHXamwfpWxuc99Xbs2qm2LXJ4eBbE0CkhdSed3S9rogH6wQ/fK8UkwLcv9SYmKnq+hy7ACB 5yW7bMpZ7g/Y9G9t+Cg9uylmn3R4n4tnR5vtVytZMmk7UZryxWkC0i0A2mKN/CA/uOy+//f8+eR6w ILgpFxMQxBXiUsme3M0ofw966Hvi9upQJjhU1HWUUk2QTCQpm0DCQtui/9qp8/WL2XejNfFebOl/C xQqFIsygN4AyKVmGfAY8vVkHQjWwzUu0xx992tfFbqH+9jAB//Rxbi7Y020GNYJDFIG/O+1fdYI7R Bq8aUA/Q==; 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 1v0AcM-00Ecia-K4; Sun, 21 Sep 2025 05:20: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 RESEND v4 05/10] PM: EM: Add a skeleton code for netlink notification Date: Sun, 21 Sep 2025 12:19:23 +0900 Message-ID: <20250921031928.205869-6-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250921031928.205869-1-changwoo@igalia.com> References: <20250921031928.205869-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 0992029d271d..ba528836eac1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9034,7 +9034,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 Thu Oct 2 06:17:58 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 8DC0123BCED; Sun, 21 Sep 2025 03:20:15 +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=1758424817; cv=none; b=fT/4rBDMeOMrQlMnJMRGF1SA01P1/C1cNgzyNy+Q7f6EYoTmnakW+5uQ8XjkwLmf+tVmXDt2m4d+9mDlZVgwapxKaFWnFeEHBlbTl1Y8ztUBpuvR6VyXVJ2jzXBe4Z36tTbE3WOGJWdpGM0oS19OqOs7vzUmiam26M+orWM8hyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758424817; c=relaxed/simple; bh=h11SGtV5bb+zU+5RXvkBOpOEmZiHT6WNp4XydOTIj00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oW2zj/BoAzDiorJLyUBBdn9XaE6z1Ys5khwpxpTfe8b1qfG0p1TI65obKoxOWQBEC9SpPKGYi1tzeC35gcUt5V0pHU05d1JzzYn2bNvqHVG5TqExgN5CNCED+UxLyE1QXzFJDGaGCOTYmxD6kHI2kmBERSZFWNs1bEV6mvHXowY= 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=HTScwmjS; 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="HTScwmjS" 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=HTScwmjScqf9kfqQ0a8/qVovZI aIgtVb/bD8noKgj4//ipaskxxItfKFibf3CF8S1cpMQaJtF54miWc8ii5EcO/QCUiI22DjUoiKM6M qfcGFFCNTMBhQlfZFH8CX9rQv5vLODiMjkchUTOaNjwG2xxM/iu5jYE3HNDyji0UueVELGVh6t4Ft 9OPH+qKG5MITNnEteXnqFLcgv2goFsWrW3X6zLBuZu5iEfrpQ42A8SsfPu0I8mj6aAikrzn8iBY7B Yek34GJ9EeMkp6NQWe1vCaV3Xep4EoiHS7G3gN4xxAphF4trwYSDnKLVtRhk9AEY2yUO8WjXbwZi3 kCQqDwew==; 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 1v0AcR-00Eciq-Nj; Sun, 21 Sep 2025 05:20:08 +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 RESEND v4 06/10] PM: EM: Implement em_nl_get_pds_doit() Date: Sun, 21 Sep 2025 12:19:24 +0900 Message-ID: <20250921031928.205869-7-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250921031928.205869-1-changwoo@igalia.com> References: <20250921031928.205869-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 Thu Oct 2 06:17:58 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 B3F5223D7FB; Sun, 21 Sep 2025 03:20: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=1758424823; cv=none; b=ibuiTXp34JGGScA7dP3aRGQzqNqq4g523D6lRzbY9iKWdVWbLcoRq57DetrdJ2qlFPCXOcvGk3owiaUt7KNkz5R4KoDmEOw7Ln27zitY+/JwcaMOYEirtGaHZ8hmgVbxsKGCcFHZMIdDVJ9Fdv6lJ++nLC8275R7e8j+jHuRrCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758424823; c=relaxed/simple; bh=sIUC3+UBuDoJoZKfk7HtTe+i/bxz9UE8eXfzlcItyq0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G6exQ0beE039Q2pW5B5WnqYYs6uKibZbDaNDnPjqVXgsExLsS+LHOXlc/UB6LiNFRR11rMAbsfBClDl4OaXCiLISz3A6uyk2OxqP+9Y6aok9G83KaSg8F7y0v6iLFwEL3LoLfN9vGK6IyFhnNAYWFDq/PJaCodRpbFREpaQO08o= 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=sTWaG9tB; 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="sTWaG9tB" 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=sTWaG9tBDUEKgXea0X3Ryz/dJ+ tFqwztGs3qLjXS56VrnpQkOqlI8xAdMS2sx/SJUQ/thksbYN/Wiv9/EIelFX3TYKyvdAEhwmdmZ4j LScejMFowX2Mn2VPvv0mr0+9xAeiSODpU2nKf7mR6S8tHirWWm4ozQuHzlxoB9mVuxG7X0ciEsXYi bN2MFeFYJtbXn3xZnsiI1x35yMxMj+GF1lgsNcLx/e++y1fKA/17N3SV8Sk+HuYyANVpfBuJIpm0O 8Y2Qv2cQ4qPA9dUCVP3MpUQOZQHLdUEz+TMOLsCxffGBCUUHBcF6LRH3QJA5DpZTt1I2LXsfFtLcr /a7dOq3g==; 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 1v0AcX-00Ecj6-8F; Sun, 21 Sep 2025 05:20:14 +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 RESEND v4 07/10] PM: EM: Implement em_nl_get_pd_table_doit() Date: Sun, 21 Sep 2025 12:19:25 +0900 Message-ID: <20250921031928.205869-8-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250921031928.205869-1-changwoo@igalia.com> References: <20250921031928.205869-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 Thu Oct 2 06:17:58 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 AE3BA23D7FB; Sun, 21 Sep 2025 03:20:26 +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=1758424828; cv=none; b=JFbkPsg+KmVC5qAgXafan6gm8tQ7IRwv19f22iFBmD3hbcu/exVgshyRWqMZaIPVU2KiGGwPp0r+8pTiY8MMK++FMj10aSAp+hvmoaobQPpML8cEZS+Z/q+qn77lhIKawCRN8c73jK/hbvE3JHEqwLEfJ2qj54dUqcCGZ/BSuvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758424828; c=relaxed/simple; bh=KvOummY2bKQpR2xxdP6117iCBe1tIr1juyf2WSJug5s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BzSJdFcsfys3jWIe0iuK82RYsqJF4C7Ag46hmnFLong7V+wOw0izwyLnwcWZWgVNX6v6xf36PeUTGUyw1ts+Sy+oCfn5trQL09ZNMtPHcnOpKNMKDTzjVawAQw6MKX1YyRAgehPqcMmECZK3TtGCt0PYS1WUJyCSpxt7AVn94XE= 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=Y3XX8hId; 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="Y3XX8hId" 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=Y3XX8hIdPJ/GvfTz3MmWZbzqJy 0GLGDbNgxarQln+C2Bf66lh6gRfkDNSFdOr60zjXyX32um4uvZogta1wEXo660zq68MYReRxPfi0Z mBiT88jV6bK96pCDbOlm3+vivk2gH0QKf8cR17RdtL0anLxr/biqvlW5INOy3YE0apKBemqSc1lTt Kxu3NgM6SP05RafVB7Ar1Qo9gKTHBZebtD17TQC2bbhsWEcCz1elrB/dcZyISMXXQiCFyU9bSkiD4 pTOrAkaPhDoHiGw9piV12KejRCsTcTVKzW4HHJyYqMfOExj34ZOpMX8/F4LupiTQIeH73oOk2foVt tyXTH3QA==; 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 1v0Acc-00EcjK-Pa; Sun, 21 Sep 2025 05:20:20 +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 RESEND v4 08/10] PM: EM: Implement em_notify_pd_deleted() Date: Sun, 21 Sep 2025 12:19:26 +0900 Message-ID: <20250921031928.205869-9-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250921031928.205869-1-changwoo@igalia.com> References: <20250921031928.205869-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 Thu Oct 2 06:17:58 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 2FF70242D91; Sun, 21 Sep 2025 03:20:32 +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=1758424833; cv=none; b=els2zHRojpnFdInQ/CqMSxzcMfD0SN+C7ZhLJzhI0Q9WQJ60q5cpsYqp+emM5hM7pZnjU0GqTrZ/UAyZ/yXNuzp2nOORPPxj39ox8/ivTUYpXs3yCfII6FSLGzbYg2SnvzoSuf+3Ev8R9y0KN5ssTG/OAvnCmDLvYZk4fLgMPnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758424833; c=relaxed/simple; bh=0S+IcH+DOywjFMM8Qmh8T7Oe3P86Lks3htSrMJA2Ums=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DGSHUoQtz8mx3PwaoS/K/meQJHrGgjyVeakCuhW4/DK4D9lREnLV0hsGxF2F7R7dzLBuQRyJGYTzTFIwUnG6eNlDxnVK2HnrGRCU2jtAViN9LNRbcJEb2ewmsiGzEroK40JcEyvrYiY+WfWSvwjwVYqURxI+Eh+t80H7B5OPHt0= 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=mSfbdzmH; 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="mSfbdzmH" 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=mSfbdzmHSwzei2lCR8ut7ZzD3w Fi3ISWFWoPEC0pGkhMu6xYJy2J6pPLuTRJwybg2pJFMN7dYkDFv3zKTqyt9pecEZuslS6qHBxPSG+ TdAtfg0VVTT7MQTeneqAD4B69mhbDNC8E5XB4ktP/5yWnQjbToPEtf7SqjeJkh+oJXRYZiRGzi8ge ezECvlaKBUHNezlMG2rOtHdYQh5yWhgoOpTK/f6xaJWdLR43JLinXBax2SiXaG0w34CzwykOCceJr Ni/JU7TdqVBjhbUNBVvNQrHpk59K2/fkMSxoq3bZCrZGfOoqZPLMNZdIvkAZLIGA7IKjeVt1tobBl 52wwNwpQ==; 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 1v0Ach-00EcjW-QV; Sun, 21 Sep 2025 05:20:25 +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 RESEND v4 09/10] PM: EM: Implement em_notify_pd_created/updated() Date: Sun, 21 Sep 2025 12:19:27 +0900 Message-ID: <20250921031928.205869-10-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250921031928.205869-1-changwoo@igalia.com> References: <20250921031928.205869-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 Thu Oct 2 06:17:58 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 DBB41248F64; Sun, 21 Sep 2025 03:20:35 +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=1758424837; cv=none; b=tFzbbR6S+nGEILLhryHq9Uv0z0UOvSXEn0D8BwMlFdZW8X9dK3U/27WjDeejg4XIAfTz2R4em5+mLasAIIZKkhXDwX6j/axN6BGw9SSN739iNkFVtYfxCC6C0JaIsp2NzZXQpwedaQchUQWxAwVdi2XoeiG4Mu6kCCb6jGPKAh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758424837; c=relaxed/simple; bh=y+FOHX/go9wekysNkMc1iPBG8Iy8ApZybO4toHO6X/Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ctTfgGLCmSsub60K+jaGe9e97ZYOxA3lu/SyY/keqkp9tsfRG+xktkqZIVQMCb7VPfd5GMg3V89+y3fWJ2H6cPC3/bI2GYtyfy8mDMzFSEPUjmmU4j6vkvT/aXOFDCdmHe1FL6P95FWBNhjD2PWpsA2kHoAj8MmkEOehJjqv0Ps= 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=B6cincJY; 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="B6cincJY" 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=XzaDD1CcznY9UobS3SjpP6e1pWU64vfZ9Xs7KBz8zS4=; b=B6cincJYUySoF3WP5tE1SKk49n YwQb+Hk8fVC6Fa1w1t3IOx8bzcAvD6HyW4CnpxXR9rvXwrf3m/xoEdg3XLuTYwg1+OttWItT7SNmQ KKrUhwik/S9Ww5239Ubojk9JbvaK4vtIcY7lIGKWrpHhL4b21Nw2n753r/ay0BJDPZ291PY/RjT8K /8YL4TenyeZtJaod+y8OiZRnwJ6XcduUvjzI+xFwSaUbBhib7K6jaAPR9IrL+rLce6yqW7Gw+de/O N9FV+Z+ixQAboImBzOz1rXs5vYXjbv5lm6urf8JrO1q5gSUecR+nmMBNpvbIzid5AKDeiisvheMgw Sos6VYuA==; 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 1v0Acm-00Ecjh-Rj; Sun, 21 Sep 2025 05:20: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 RESEND v4 10/10] PM: EM: Notify an event when the performance domain changes Date: Sun, 21 Sep 2025 12:19:28 +0900 Message-ID: <20250921031928.205869-11-changwoo@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250921031928.205869-1-changwoo@igalia.com> References: <20250921031928.205869-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 740076d24479..fca32d1c6661 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); @@ -697,6 +701,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); @@ -719,6 +724,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