From nobody Tue Oct 7 08:53:53 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 993B4125B9; Fri, 11 Jul 2025 00:53:33 +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=1752195216; cv=none; b=A6QLIm42Kq+rkxBiafz1VpsVJoSFC81cxSavbYk3eAHoAjAVSPa4iLEGA3bjQPWKKTZ73OrfkMBodYwFKlhTjzzp5nRJRwNe2NehyW7uT4wS9DefguHUtt+1zH3H6/LHUIjUhAI+Y8wq8jWnSrL8AWBlWviuBM6N9jyiPlOeoZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752195216; c=relaxed/simple; bh=j/CAF38kchxEBYHrqfatHX5g2vxglcYD7doSgu6sHic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VWcgQdnJCgetvwblMeXeg8j6yclFGeowWpvHFINwA+/E6ea3vzT558Ow3cGkja/Wj2k3lTwEkZ3wSJbQnjviKFCPNXkeB1Qa0hRYBGU0wjz7VJlJ3g9oOpHFVNpxOVev/P3QKE6S28MY4REgj9yvsGJ/UomcPJ6gV6cJBexjBXI= 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=IQqQ4qGh; 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="IQqQ4qGh" 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=/qBxAwpjN5y2Oc166TCmLzp/96iH+Zc8bUKnvuALDk8=; b=IQqQ4qGhXvB/QZ01nozINazZEy ZKp8SsNGox81V5IXfkT9CLlMC10BV/Pattm5TDjhoqaKO65MM6kieI8jp8Req9a8Zwlri2dslIosc BpDsxWPUmLf39b/bY4j81fdOtYryN5xvTl5+bturF7dCOGPvwKzI9A2woOVEvIztlV8Jta6N1Qzir 922CK/9LV88RqogN8OSrDcwYGer9ayE+OuJVJhL9OlVqunmsA1c+jJsg0BQx/5OZYDaVspYHuGrXq df4P+xr0uULJ+QJnqNfARWrPUHtfQqs3ZsxYFExOXMqyk8CL+t4AIujSGOKZ4r6pSR44TBVoA4Cy0 lOYhWhtA==; Received: from [59.10.240.225] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ua20z-00FAmM-Dq; Fri, 11 Jul 2025 02:53:26 +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 v3 01/10] PM: EM: Add em.yaml and autogen files. Date: Fri, 11 Jul 2025 09:53:01 +0900 Message-ID: <20250711005310.20740-2-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250711005310.20740-1-changwoo@igalia.com> References: <20250711005310.20740-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 eb7616d241b9..e31d22abba6e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8867,6 +8867,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.50.0 From nobody Tue Oct 7 08:53:53 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 3D609125B9; Fri, 11 Jul 2025 00:53:39 +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=1752195223; cv=none; b=g8v3L8vU8tUIS26qwanykXbXl9zcUbXjG7RwUXJUVlhjqeifk9O7qH+PMKe7Ge5lVo8eutN20LX9nacZqqNkvAjssI0OCLIYbIkMa26jVgro6yXLxShz7N6/VNKEG/mS4SAmNBQyP2e16tmz7Bp6pevDrLYCu7ZTXRdEUDChE3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752195223; c=relaxed/simple; bh=mYu+Lr5bImRnBvbn2u/2HQqBZwMQTSDJ1jPyeJnrs94=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k577Eqj7jS8X8s4Ct7wsmUCg3msEYiIH5MdsGpyEZDuOwjqOAUDcsFAn3vN0pFWdfkjBPZkAbQ4P26H2AQF188K2L15BocwJOtcuK8Z8DUyI/Z+ZO6UelvvaOK5j+ZHqUuKxpKFtVtgf1N334DHeOziR0SppYXs5GJys5g6YdGM= 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=Wm64Eqyh; 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="Wm64Eqyh" 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=TuDAjpodSMl9dnfEvWO7S5GY7MOPrpZFj8+NfZKLDi0=; b=Wm64Eqyhsgib35mn1fx6+Dq193 NlF7g565rALpM3HxBYriVR/A99LnRcrJg55ucIXF1w4g56+BBtUOc4Z5+gHNb0eM5EBMoCMPMZ1eD f3Ow2KKd69MmQQGOLiXcNPimTCZYkE2Bg6iZIlpuZLhCqOjVrOxhb2jyaRM/CY/BaueoOZjy9sj/W S9GV8qXZzCQV7yxqKpmxr/6j07QIQQeywCETR06vYsjaWUaOGdkKk1w+VZBWggSdHgau/1czn9lWN EB2bbSBBpjPSttVhsv44fIkVtcbFBGq++qyCvS69Gm5ODztSCHeGrXBe+efBeLyvcaDav9H5vHTF1 vUJ1jU5Q==; Received: from [59.10.240.225] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ua214-00FAmT-Vr; Fri, 11 Jul 2025 02:53:32 +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 v3 02/10] PM: EM: Add a skeleton code for netlink notification. Date: Fri, 11 Jul 2025 09:53:02 +0900 Message-ID: <20250711005310.20740-3-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250711005310.20740-1-changwoo@igalia.com> References: <20250711005310.20740-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 e31d22abba6e..2795562bfd73 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8869,7 +8869,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.50.0 From nobody Tue Oct 7 08:53:53 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 63E087FBA1; Fri, 11 Jul 2025 00:53: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=1752195226; cv=none; b=hahICiaAsNEnXpMzFpyPFYq7hNDGvsTN8ujNcs8w7U51zXhVOI/RvNScILEirx5DuPAwP69YCgyNmCVw+nNYZz8DiSDZt+4H4iTX43QpC0s2nFu/AjpQyaeBHcBZEmTh25i7ov3B+zVcHUIHjbPyts/Kpy1VCddIwc3yBjGql+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752195226; c=relaxed/simple; bh=2HgT+WN2UxSuaxVoGYR4Mk3NCTQms2rlYvrqmGgkFGM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ep+kgspg5GIn7jYzEqKJl9+Jwqtdd1Qt96jtFW46N2XIcI65lSUUBDSbDpNlvleWd4Te4v1XcuTA7aA4GFyotepb0J3XN3cxlSp2FukVK1Zgk8GBGpkXygxQQykmjOe7x1VqYGH0rd5G39cry++K3ywHIpsL78jYHINkrMvOB3s= 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=i6h8AFrn; 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="i6h8AFrn" 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=axmYQghQ8qyycEuVlszvS6P+XkO6VAObIC7vNTuWQ38=; b=i6h8AFrnvSSGnzwRhOaW/IWfN+ rSf5HHTg9h3HViNes5nmMJrd68DrOf4I08Kjw6eWVJ1oeOKre6jxulqWEUZluZVG5RtN0ujio8t/m 9riI3p9YqupJdqyW1RpR+wlADQRv9C9YKVGPDHaGjwJ5Fbd1PkHBK/a7HAfscyGvvAoTZAVLeOQhi o8/dcs6b3PxyJN73kVix68JMlibZSsrYl23f4W/HkIWSJGa/OdRe9wMaIrYCY2N2TqA4qD9ROV9Ya 4xhsnsiTh/44/6M46Faq9LqJdP4HHi4ZSPs85zpgk/m8ZOwyTy0h74lijAwyRlXbesk3J2QKp83kz gBJ+lV6Q==; Received: from [59.10.240.225] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ua21A-00FAmd-Q0; Fri, 11 Jul 2025 02:53: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 v3 03/10] PM: EM: Assign a unique ID when creating a performance domain. Date: Fri, 11 Jul 2025 09:53:03 +0900 Message-ID: <20250711005310.20740-4-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250711005310.20740-1-changwoo@igalia.com> References: <20250711005310.20740-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It is necessary to refer to a specific performance domain from a userspace. For example, the energy model of a particular performance domain is updated. To this end, assign a unique ID to each performance domain to address it, and manage them in a global linked list to look up a specific one by matching ID. IDA is used for ID assignment, and the mutex is used to protect the global list from concurrent access. Note that the mutex (em_pd_list_mutex) is not supposed to hold while holding em_pd_mutex to avoid ABBA deadlock. Signed-off-by: Changwoo Min --- include/linux/energy_model.h | 4 ++++ kernel/power/energy_model.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 7fa1eb3cc823..2f5c73fcdfe5 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -54,6 +54,8 @@ struct em_perf_table { /** * struct em_perf_domain - Performance domain * @em_table: Pointer to the runtime modifiable em_perf_table + * @node: node in em_pd_list (in energy_model.c) + * @id: A unique ID number for each performance domain * @nr_perf_states: Number of performance states * @min_perf_state: Minimum allowed Performance State index * @max_perf_state: Maximum allowed Performance State index @@ -71,6 +73,8 @@ struct em_perf_table { */ struct em_perf_domain { struct em_perf_table __rcu *em_table; + struct list_head node; + int id; int nr_perf_states; int min_perf_state; int max_perf_state; diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index ea7995a25780..58671ac142db 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -23,6 +23,16 @@ */ static DEFINE_MUTEX(em_pd_mutex); =20 +/* + * Manage performance domains with IDs. One can iterate the performance do= mains + * through the list and pick one with their associated ID. The mutex seria= lizes + * the list access. When holding em_pd_list_mutex, em_pd_mutex should not = be + * taken to avoid potential deadlock. + */ +static DEFINE_IDA(em_pd_ida); +static LIST_HEAD(em_pd_list); +static DEFINE_MUTEX(em_pd_list_mutex); + static void em_cpufreq_update_efficiencies(struct device *dev, struct em_perf_state *table); static void em_check_capacity_update(void); @@ -396,7 +406,7 @@ static int em_create_pd(struct device *dev, int nr_stat= es, struct em_perf_table *em_table; struct em_perf_domain *pd; struct device *cpu_dev; - int cpu, ret, num_cpus; + int cpu, ret, num_cpus, id; =20 if (_is_cpu_device(dev)) { num_cpus =3D cpumask_weight(cpus); @@ -420,6 +430,13 @@ static int em_create_pd(struct device *dev, int nr_sta= tes, =20 pd->nr_perf_states =3D nr_states; =20 + INIT_LIST_HEAD(&pd->node); + + id =3D ida_alloc(&em_pd_ida, GFP_KERNEL); + if (id < 0) + return -ENOMEM; + pd->id =3D id; + em_table =3D em_table_alloc(pd); if (!em_table) goto free_pd; @@ -444,6 +461,7 @@ static int em_create_pd(struct device *dev, int nr_stat= es, kfree(em_table); free_pd: kfree(pd); + ida_free(&em_pd_ida, id); return -EINVAL; } =20 @@ -639,6 +657,10 @@ int em_dev_register_perf_domain(struct device *dev, un= signed int nr_states, if (_is_cpu_device(dev)) em_check_capacity_update(); =20 + mutex_lock(&em_pd_list_mutex); + list_add_tail(&dev->em_pd->node, &em_pd_list); + mutex_unlock(&em_pd_list_mutex); + return ret; } EXPORT_SYMBOL_GPL(em_dev_register_perf_domain); @@ -657,6 +679,10 @@ void em_dev_unregister_perf_domain(struct device *dev) if (_is_cpu_device(dev)) return; =20 + mutex_lock(&em_pd_list_mutex); + list_del_init(&dev->em_pd->node); + mutex_unlock(&em_pd_list_mutex); + /* * The mutex separates all register/unregister requests and protects * from potential clean-up/setup issues in the debugfs directories. @@ -668,6 +694,8 @@ void em_dev_unregister_perf_domain(struct device *dev) em_table_free(rcu_dereference_protected(dev->em_pd->em_table, lockdep_is_held(&em_pd_mutex))); =20 + ida_free(&em_pd_ida, dev->em_pd->id); + kfree(dev->em_pd); dev->em_pd =3D NULL; mutex_unlock(&em_pd_mutex); --=20 2.50.0 From nobody Tue Oct 7 08:53:53 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 641C63C463; Fri, 11 Jul 2025 00:53:50 +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=1752195231; cv=none; b=ZzStwlENFg8NgAexzaTu3y4KhkWDDHtYQ0+O8SSTDZkOQJBZDSkYgjvi/JhP36TiZ/dnJyWkj93SKiFfAp8kooMy3GdchFWKqlji5PVg0cYNP/ByMSPmJKf02gknJqTQoySMRwxfjXoJnu8Y8S5rEZnRykpUjzn34wIRw59FGWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752195231; c=relaxed/simple; bh=bZFjAqMpNX2Bn1HjMR0wNV/ZWX63RPlUWsVc3P8BUrQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tBonDQ3UTKOpqWMD0pYbguwiDBt0RoZV7H984FjqFck4+NnhiDiiJEAi7oyR6H79avJHg4FZ8A7hC93Aa0upenBYt0OWLJu45BStxnhg9shldT7LWXoX7tJM+rhL5iiSvbImrlifd+FUKomxHEQuyAGnQ2eNkJX7CaDoaqgCr48= 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=X/Az6YkM; 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="X/Az6YkM" 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=EObnO+cc/WgACxN797nf72JFs15byawobYYMIsyjHdw=; b=X/Az6YkMNNcic6hXrX7D+Dd4it lnZSzd+WGoZ16RgOf4sCYbCcKfEb5OYstcg5S5RElUe77RSbTnhLhjWOa4DAbPMteuJVnldLCse1D 9Gv+z0/Q9Ylh1YGqFXyEHKmUFJ/Jq6463Qkvb3dhxwuWSlnhOHEH1uglfFisHbXJnTnqT7xetcWS3 QCW5i+fMgfvbKz4nMU05lT7ApIIB75pPNaV3YR6I4iONJLeqm2aF5IuqMjDi8A7QB6F5dbEIWdLdY FdaarAPDnGuBuFlzrN0gXIYOjepLZqekdzO8cORtju0ks86JleJGkBAGKngGr8ui6tPU5vld+drQZ a/ytKRvg==; Received: from [59.10.240.225] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ua21G-00FAms-EJ; Fri, 11 Jul 2025 02:53: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 v3 04/10] PM: EM: Expose the ID of a performance domain via debugfs. Date: Fri, 11 Jul 2025 09:53:04 +0900 Message-ID: <20250711005310.20740-5-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250711005310.20740-1-changwoo@igalia.com> References: <20250711005310.20740-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For ease of debugging, let's expose the assigned ID of a performance domain through debugfs (e.g., /sys/kernel/debug/energy_model/cpu0/id). Signed-off-by: Changwoo Min --- kernel/power/energy_model.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 58671ac142db..6e5e70dbec88 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -126,6 +126,16 @@ static int em_debug_flags_show(struct seq_file *s, voi= d *unused) } DEFINE_SHOW_ATTRIBUTE(em_debug_flags); =20 +static int em_debug_id_show(struct seq_file *s, void *unused) +{ + struct em_perf_domain *pd =3D s->private; + + seq_printf(s, "%d\n", pd->id); + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(em_debug_id); + static void em_debug_create_pd(struct device *dev) { struct em_dbg_info *em_dbg; @@ -142,6 +152,8 @@ static void em_debug_create_pd(struct device *dev) debugfs_create_file("flags", 0444, d, dev->em_pd, &em_debug_flags_fops); =20 + debugfs_create_file("id", 0444, d, dev->em_pd, &em_debug_id_fops); + em_dbg =3D devm_kcalloc(dev, dev->em_pd->nr_perf_states, sizeof(*em_dbg), GFP_KERNEL); if (!em_dbg) --=20 2.50.0 From nobody Tue Oct 7 08:53:53 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 03C6515383A; Fri, 11 Jul 2025 00:53: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=1752195236; cv=none; b=fIRnaFh/usgR0KgTSsEc96kDThVgoiQQ+jVA/0BZGv4grvopssk4nE7HOVAo6R/UViUCTKrHBaY7F/x1klCyinm9/23yC8bre8J+2eSh8Pwn35yAm1VQ44jbO6v0IeuR0qbJJe+nr+6W9pVYxxY2VNrGGB1YQjbCkmhgz+XW9+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752195236; c=relaxed/simple; bh=jJFbpYkqy/73E55orbSOkvpZKd5oXEt4d72vTkDPWw0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AcBlBKoxj3diixfQ1Ljb0+vLzsTKsBplIMIOj1s0DdkKNycqz8p6I1oUWSAPt4y89YdNsbQoAveail6q91098ImEYBNqq3CaSqDCbNkdgUFGvg7YQjNXxAKWUm7EUpxvoyc1d9PRAztkU3dF9C/tmKUDObrQ1DUBuWsOBmIFBWc= 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=OlA5hLBo; 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="OlA5hLBo" 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=90fpkRptMwqv5G71uZtM9Sdw0kmNk4iO7k1dGUX2nEA=; b=OlA5hLBocSgnIcc0xONkuLCU+f dxgESMiix3yuzx1IRavrN7tMVJBH5qm3r+R/3dhSGnc8hewirBuitvLa+NYMKY3DqyFXHRyd9rNRS gWc+0N1GdKSZBUIBKlninYvAXdvXN7Q1CilV1iQiiCJN62onhYmbyg5rxPGnUKGFInqi506ubBUBK zx77m3bxtqx+lxrOX8yP7wbv33RqCuSBX/83ywLF+eRYf0sGfa9ORdmU7yJTCkR5zRerb1aXnScQC jsachZDKHN5hYhsXM4UaUp2P9KZcYZFS7AsKb7TZzULK4nE8N+l+BnleW0uRhdRwfxM8Vu3byA5A7 pC+zOv2w==; Received: from [59.10.240.225] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ua21L-00FAn5-V1; Fri, 11 Jul 2025 02:53:49 +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 v3 05/10] PM: EM: Add an iterator and accessor for the performance domain. Date: Fri, 11 Jul 2025 09:53:05 +0900 Message-ID: <20250711005310.20740-6-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250711005310.20740-1-changwoo@igalia.com> References: <20250711005310.20740-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add an iterator function (for_each_em_perf_domain) that iterates all the performance domains in the global list. A passed callback function (cb) is called for each performance domain. Additionally, add a lookup function (em_perf_domain_get_by_id) that searches for a performance domain by matching the ID in the global list. Signed-off-by: Changwoo Min --- include/linux/energy_model.h | 15 +++++++++++++++ kernel/power/energy_model.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 2f5c73fcdfe5..ce70e664fcd4 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -341,6 +341,10 @@ struct em_perf_state *em_perf_state_from_pd(struct em_= perf_domain *pd) return rcu_dereference(pd->em_table)->state; } =20 +int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *), + void *data); +struct em_perf_domain *em_perf_domain_get_by_id(int id); + #else struct em_data_callback {}; #define EM_ADV_DATA_CB(_active_power_cb, _cost_cb) { } @@ -410,6 +414,17 @@ int em_update_performance_limits(struct em_perf_domain= *pd, } static inline void em_adjust_cpu_capacity(unsigned int cpu) {} static inline void em_rebuild_sched_domains(void) {} +static inline +int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *), + void *data) +{ + return -EINVAL; +} +static inline +struct em_perf_domain *em_perf_domain_get_by_id(int id) +{ + return NULL; +} #endif =20 #endif diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index 6e5e70dbec88..f125262a93c9 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -976,3 +976,37 @@ void em_rebuild_sched_domains(void) */ schedule_work(&rebuild_sd_work); } + +int for_each_em_perf_domain(int (*cb)(struct em_perf_domain*, void *), + void *data) +{ + struct em_perf_domain *pd; + + lockdep_assert_not_held(&em_pd_mutex); + guard(mutex)(&em_pd_list_mutex); + + list_for_each_entry(pd, &em_pd_list, node) { + int ret; + + ret =3D cb(pd, data); + if (ret) + return ret; + } + + return 0; +} + +struct em_perf_domain *em_perf_domain_get_by_id(int id) +{ + struct em_perf_domain *pd; + + lockdep_assert_not_held(&em_pd_mutex); + guard(mutex)(&em_pd_list_mutex); + + list_for_each_entry(pd, &em_pd_list, node) { + if (pd->id =3D=3D id) + return pd; + } + + return NULL; +} --=20 2.50.0 From nobody Tue Oct 7 08:53:53 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 409E470808; Fri, 11 Jul 2025 00:54: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=1752195243; cv=none; b=qhToM224fViV0nuRTdMTSJ9Gjum506NRYIskvVtyo90gLWJWKoSKQPyzCQTuAXnLDvBADAZP1FtWgejGUSnFrheANMiVFrzcWRS3XiRDFLLrMr1lVmbbsZs9ILpSPuArgWyWqLphpQy+AIMX1sEEO360JG6a+V7pLNuKU3NdNxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752195243; c=relaxed/simple; bh=3nq+Zpaoz0vofbgy7lGNC229UafBwcUkt2i5z8B5iKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OQN1pztgVWRNCp2JFUFzWo+bPms4hsLwrbTuoThbAsXvgx9xNDODXBlemB1VI+Vh65b02AxxhBDnygHoYDyx6ikeLes0n152bGDW2GYKAT334AKve7IrSu9GD/my2uk+axoIL1T0nd6EWglK3Xr/+03VOJYpx3ZvBZ3cLWLUAQs= 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=ZqOQzadf; 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="ZqOQzadf" 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=/5sfDfCawEqLoHI72Ky4Jp2pUlYZAT/IGUfojeFwu7k=; b=ZqOQzadfoHMQOP8j/GDD7yg1xv hfrJDZOrwJ8qDmKEv4uPzoHm/9V1SaZxx4Kwc8QZj6xhFVGFcX/DxfSGBgoMWThWFnF7FdwUruKO1 mbQD/jCi3f7pnVF0RNAbd2uEoqKo8qzEOpv2G7OBL89vz/gUgt2BZw6GzV+CKYgEwj/KMvKw1uBx0 y/zYtsiAzNHvz6ofiwbjs2pb0XVb0rCta63mYCeOPVQ1hA5OouRDlg09f5YDNmTbQH4jKOD3H0h0g 0mMiTSCKDyMuOOliKUD8Q0p2dStktXUbD3Md+wYwDyDjpgOcyGDZhJYzH2WzEDSImnmnbyHPl1yfF GfPtAaEQ==; Received: from [59.10.240.225] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ua21R-00FAnO-CL; Fri, 11 Jul 2025 02:53:54 +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 v3 06/10] PM: EM: Implement em_nl_get_pds_doit(). Date: Fri, 11 Jul 2025 09:53:06 +0900 Message-ID: <20250711005310.20740-7-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250711005310.20740-1-changwoo@igalia.com> References: <20250711005310.20740-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.50.0 From nobody Tue Oct 7 08:53:53 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 057CA22EF5; Fri, 11 Jul 2025 00:54:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752195247; cv=none; b=nYWXOMHOTQ98c9LMsvI7xR3p+AT5LgxLM4GMs2pXZIHNtYK+B1JrEzoCR9utT19KjSM49tYjNj09Rejx1nsgMCJrw0ysnfxRJxXzazMctXhIM4oOZBn/RC/m7bN9EC5W/AR/XQAgTr5uHS7Diteb4Tidzfvbysf0hmxY74jeWto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752195247; c=relaxed/simple; bh=AhwR42dayljc9bEkrbiQc0PjHUMwGewblKYbQfefg7w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ReEhLmmf8WhmeCRNzDinOSXK3GMq68M+ptEGppgZhMFcN3rqIgpGHRs/XpsJwiFkLppMo9ZZos1uIHzfO/lcipHYAZRa/23goN1TGqCwu9CJ0WGFbX4rXaH5ytOzo3w9ay9qsCyvnMq7yiWuj1NJXdSHqvtyIfK8pecP4W6/n2g= 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=CkxaYK4D; 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="CkxaYK4D" 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=LqtVml4aE1q9zaYJU42nZ1ow/53bY4ktZWJuzFoJRLI=; b=CkxaYK4DDQcBjSw6hf1adCm+T4 8v+uPadMuWEgI2bqMQgu27T8yMXdzcbZbom46IjDC/AXqEbDg63hns7CcoRh70LExNPt7TQxiyEhs ldtf8qvVnYwraw65uwhkKuIqzchvLnOgWcmAxUXWz/w4go7XX6GWRKUonyVHU7DJmj8yvn8AiQXDS rnFEr9qO8RVN82nwPye+CgZa0jbyMX+7NflEVyNcQqf7vIUhRX4tbcP5iV6P3emJaCd9IfdPd1epS nN024BwptKCzKUCApuCqDJD/LhNW7QJtMp73EpCwEeaZikf01GIZ4IBxQE37kX1xoy3+1NZNh3xUF TNZ3quHg==; Received: from [59.10.240.225] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ua21W-00FAnk-Q6; Fri, 11 Jul 2025 02:54:00 +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 v3 07/10] PM: EM: Implement em_nl_get_pd_table_doit(). Date: Fri, 11 Jul 2025 09:53:07 +0900 Message-ID: <20250711005310.20740-8-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250711005310.20740-1-changwoo@igalia.com> References: <20250711005310.20740-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..981bbf1f9a2f 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; + + 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 -EMSGSIZE; } =20 static int __init em_netlink_init(void) --=20 2.50.0 From nobody Tue Oct 7 08:53:53 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 8719822EF5; Fri, 11 Jul 2025 00:54:11 +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=1752195253; cv=none; b=mRcqSDh47VDiBO+suQ8eECbjFB2KV++UJqqDx1C1VdwCVapA06JVIAooWYMRuodoeM+eISSN/pNYZp0EcBkSRrURRKoWJzAQ/RFfS55IkhgTZESDrXCVv2ptAeFX+kG4EBBlP2TM89JM2uosM5eXzr2Ey2IdA6+HXAHrrwk/itU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752195253; c=relaxed/simple; bh=WY7Vxbyrm8d5xb1dWIHruUkQF6evV0jTFNlKdLbCjIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qtZNTppPFYB0/WhjhZmP1+zLRQq+lFwRVoqBs8oYxPEUpMuBaHf1fNotHsvbsG1Z6a2kM8LsyaPBv0MozsTSeALVEj5WbOAdDSP594q3ZuRslwiKC3VRxLB4k6kAwFZwJYTtwUfhPV9sOY4BchG62+OgVo5RpKdjkEKqWMBo/IQ= 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=dj7GPZHf; 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="dj7GPZHf" 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=B2Wy/uiyH6Gsn8O5ANZK9dqF4uxVCmI7U35c17/w8kg=; b=dj7GPZHfoh2gKiUgdvHmA3iF6g +2FcCxj214wgt60uujDuUNiF+nIJbGCUOzEnXraxPQpNYIpSKp6XZVgHCLwtMy38GJVm5lpUg/aij I/bGhQJSdFPyWG8vpF3tarQDST+htlTsg77N1yJdQRm5Z/BwSmj1zfJqDDybwV6eYqMte2al/AhZP oVQkRDUGQcHPoIyaUN2C7+BKPeLY+cpLJG5v7DnikKBhIhtILIwTMBt0HLKbg9ZbXAp01JQZGrlNu WIndlJRHUiFG0opUdezoLcWWmnXC60Gu8MmrNJ74QVy2Gc55MZueDeUjKytSF8pjC1KN+/iL01dIN AeH7/cew==; Received: from [59.10.240.225] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ua21c-00FAo6-B3; Fri, 11 Jul 2025 02:54:05 +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 v3 08/10] PM: EM: Implement em_notify_pd_deleted(). Date: Fri, 11 Jul 2025 09:53:08 +0900 Message-ID: <20250711005310.20740-9-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250711005310.20740-1-changwoo@igalia.com> References: <20250711005310.20740-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 | 54 +++++++++++++++++++++++++++++++++++++++ kernel/power/em_netlink.h | 18 +++++++++++++ 2 files changed, 72 insertions(+) diff --git a/kernel/power/em_netlink.c b/kernel/power/em_netlink.c index 981bbf1f9a2f..b9a2d1a538e7 100644 --- a/kernel/power/em_netlink.c +++ b/kernel/power/em_netlink.c @@ -213,6 +213,60 @@ int em_nl_get_pd_table_doit(struct sk_buff *skb, struc= t genl_info *info) return -EMSGSIZE; } =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)) + 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.50.0 From nobody Tue Oct 7 08:53:53 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 DC83919DF5F; Fri, 11 Jul 2025 00:54:16 +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=1752195258; cv=none; b=mqXpsBpbweHMQ24lqWqLbm5CSUAmARNFJF4wkXCIvuAB/43wFzA8oH5YF/rvrLBeFYLSm0Mz58qPJjl+H4WQqN0bdiDpXeUzxxn9pOvm6WAMkwcF0wvQkvtE+ZvQlbyMMCSgmdsgJCww65UNloTQMNInxvPgJ3KsxIN4i662sY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752195258; c=relaxed/simple; bh=7Js4D9luViSOnl7yqUbC5Zq6n1b6VggPul/4nId5ZxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SvN3etUj3wQRsdBpnK0hMTUpWtyo0vnyRuaaWJvP81sYXfej/BSnvR6u+8KL9I5tC/jmTeE6iICwkMCKGo3vvIQGpVuijh1UYY0lvSONHn0EWp4NNdxOKjHY3rwgx7vn66z3rsGW68bagPnp7BaTBOwfl9ayeWBAZ8dWqcwxtZ4= 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=CtyWLN2g; 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="CtyWLN2g" 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=BfNhjyz2JMtll9iGsUO7uQWzfu5EovsXmIYde8nZ3xs=; b=CtyWLN2g13jEHbzdoMdxwp1HP4 bligWl3mYjV5m5UFXrXzGh02UyClGmS4qfSUsvyhTRAbh27YepWKo6mxgSXHt7nLKa1dHWVE8y5qj nBMzbGT7PABjzNqCNxzajY7sqxUvFjuEwijKg+WVWoPB+meg8jrDyXfxxsHsZ1gO8jlq+BrehYEJx 0mU2DY9DKjUtwG3joiycWvvPM3fFIbKH6d2m6QB6j2kDMERPP6D6GZDz1slFj3c/RewKou9+ZGDXE agIamK03w07oRud0dF63F5q1uIU538Af29mcWzvamBdgI/qcqO4UU74qRT7lm99uHV3Yo8DS2Sx7y 8F3cUNaA==; Received: from [59.10.240.225] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ua21h-00FAoO-SD; Fri, 11 Jul 2025 02:54: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 v3 09/10] PM: EM: Implement em_notify_pd_created/updated(). Date: Fri, 11 Jul 2025 09:53:09 +0900 Message-ID: <20250711005310.20740-10-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250711005310.20740-1-changwoo@igalia.com> References: <20250711005310.20740-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 b9a2d1a538e7..f133b3170fe1 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.50.0 From nobody Tue Oct 7 08:53:53 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 DC412141987; Fri, 11 Jul 2025 00:54:22 +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=1752195264; cv=none; b=i5OKjw6UQpdqoCbXlFf8lUm95DgH5Hh5r1Vt3WitP4y529DrXjixdW66Iamyy38B1tYS2GYfi4ms1xWqychdVvJZ2Uv4UffMdS549kDGm/NPet3i+90TrAHCA+dY3ygHxviJBRM/qSuRH+oel9eKq6KV8VPmYdyuZ9UP5at4B+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752195264; c=relaxed/simple; bh=CSolf0jBOXS5NB4nXpcpm4XgLXu5ES6UWlXb/raa5Yo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BcwtyrX00DB39s5rzcgYDiZYjfVAtmsAwZEtJFo5FodcvraYzL365B8zR5sDZ4D5Sq1LqJThZWQPAha1Uz8irw12nm26Q7+iBlien6690wg9zXZa8tsMBF75zV0XS979r3gDEoUsz81ctBM3jAo+KC2H3fl5KZ+cagZsVbxJRpQ= 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=ZIvqrJ9H; 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="ZIvqrJ9H" 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=TxVY9oGT+pZdbf2gjYB9WLnvsRz4IlcdJ5TO+IaTQes=; b=ZIvqrJ9Hg3Vex5MI3qVIuGP+QA XElMyv4humyH4K+F3TMiPoJfs/0eJyZ/rZbeDLt/vxQ8Nc/m7zLy7Pt/dD/xHDOHV/b2Smja6oXDF m/THG88h4hB9M2vYPX9NSUvZ/RbsCcvU21woxT3ZxSrE26msJhjKBYBcqXkBGtU5H1CaVrc1y6bWn fH04h+MfcNFAymuQTyppxKK04vPiJJhGeWsTt5UIcdPXrfvJr7z0epuQvPrB53M82Br/SavPyXCcr DrRXJDl0jRADPmmhO57yRgEqWIWr08zWbQFA3NnjCzc+lDiSkRyKaE9vodOZQBiRCMYSvJJ4506fz G5J1xFNA==; Received: from [59.10.240.225] (helo=localhost) by fanzine2.igalia.com with utf8esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1ua21n-00FAog-Jn; Fri, 11 Jul 2025 02:54:16 +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 v3 10/10] PM: EM: Notify an event when the performance domain changes. Date: Fri, 11 Jul 2025 09:53:10 +0900 Message-ID: <20250711005310.20740-11-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250711005310.20740-1-changwoo@igalia.com> References: <20250711005310.20740-1-changwoo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Send an event to userspace when a performance domain is created or deleted, or its energy model is updated. Signed-off-by: Changwoo Min --- kernel/power/energy_model.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/power/energy_model.c b/kernel/power/energy_model.c index f125262a93c9..c72ac1585f59 100644 --- a/kernel/power/energy_model.c +++ b/kernel/power/energy_model.c @@ -17,6 +17,8 @@ #include #include =20 +#include "em_netlink.h" + /* * Mutex serializing the registrations of performance domains and letting * callbacks defined by drivers sleep. @@ -350,6 +352,8 @@ int em_dev_update_perf_domain(struct device *dev, em_table_free(old_table); =20 mutex_unlock(&em_pd_mutex); + + em_notify_pd_updated(pd); return 0; } EXPORT_SYMBOL_GPL(em_dev_update_perf_domain); @@ -673,6 +677,7 @@ int em_dev_register_perf_domain(struct device *dev, uns= igned int nr_states, list_add_tail(&dev->em_pd->node, &em_pd_list); mutex_unlock(&em_pd_list_mutex); =20 + em_notify_pd_created(dev->em_pd); return ret; } EXPORT_SYMBOL_GPL(em_dev_register_perf_domain); @@ -695,6 +700,8 @@ void em_dev_unregister_perf_domain(struct device *dev) list_del_init(&dev->em_pd->node); mutex_unlock(&em_pd_list_mutex); =20 + em_notify_pd_deleted(dev->em_pd); + /* * The mutex separates all register/unregister requests and protects * from potential clean-up/setup issues in the debugfs directories. --=20 2.50.0