From nobody Sun Oct 5 01:49:56 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 9B8892367CC; Sun, 10 Aug 2025 23:34:18 +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=1754868860; cv=none; b=sd8yIGQ8Vu6sF3kiWqggeicA7XRYXZL6xNCA5nouA3LD5a9oOvrXGzm6xprEoIuVSupNoq2/7OkK/LjCjpYcFBbWum7VJ3mHhlK2JrWKIZ+OgjmboaLHx2Wor99uhFLflbMN+a3R2vxHaTzPbSQFRc4rqw+2Xw8YWFQq4VGw8aU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868860; c=relaxed/simple; bh=csFyHHqw2UVh1UOK4suT0f6iGb8jOrvGaniiiZiETpg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hpo3zqg7jQGFoiC27FsNOaBo7i9iCCdhpa9ATkv30wo6cZjxVlKG8WtCrXFiKXXoiM19pkc0CxjhznXQo7fSoZnz+bQEKhz9RV6r7EeC5rHFbERrvr+fmJQT8ReOhgMx+57kucUwZTEic5aEePK98y+UgTOQtsSO1zhp7IEYYT8= 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=JNHjqa4m; 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="JNHjqa4m" 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=iwqaYza46G/jEr4j/KTejCm96/NCUMl2piN5+b5Sui8=; b=JNHjqa4m0iP0nwWsEGaCZQnxrp ShjrCxWW11C2+Oupgz/lXOZcq+btJ8JqMhtDqkANmbpdilI12O6SVDqiMT2FG+fvVXstrGWPkTU0O cllUTFfWfvt86/Au929vy4nQ1VqDTuS1mvRFCZP8BbrfyTiSCqjCxLlSCs9iS26B3s38ZLtHHbVEB FptH1mwNlxFJd6DjpmJuPReFNMwaFh4fo+5jo0YQWilllD0Z1yLkCbT7ZcpIBjkofyzKHyw+6rcDX xAOaH2MZ58eEedTxLpc955oKQp2ObYBNk0I3w2wf95ZE3qrNoZpPMgR5sypxJ+kFSR3s16AYwNDmz OliuyL7g==; 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 1ulFY8-00CW9E-8Z; Mon, 11 Aug 2025 01:34:01 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH RESEND v3 01/10] PM: EM: Add em.yaml and autogen files. Date: Mon, 11 Aug 2025 08:33:38 +0900 Message-ID: <20250810233347.81957-2-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250810233347.81957-1-changwoo@igalia.com> References: <20250810233347.81957-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 fe168477caa4..0451c024cd8c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9013,6 +9013,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.1 From nobody Sun Oct 5 01:49:56 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 C09432D8360; Sun, 10 Aug 2025 23:34:19 +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=1754868861; cv=none; b=PtgZpgl2rcEcrK4s9a60tF3mkQ+0uZTJOCJ4Kpkr34AKQ71qGCazkF4XKfp5rectmLMZ+zhQN9Kdc2LYCE6bX3Nk3DjTWyOu2ykc+Ox9oMnAj4h4TqDs/6kySDGOQIjbKZ/3B3hJ2wTg/FNuqYmqZKDWmd4eDcu2II0JljbnY6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868861; c=relaxed/simple; bh=gVezLP5md3FgnUPIEs09XxC/g9DYJAy/KynA3tBWncQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r9p0G/f3G28ztQJbCTsW+xmLfjzkHLPPDTH51t9Xpi4lzrbW1BbEqbnYOP0Rs0HtLCIBCZrO9KJ7OnKlk82RbxqWDPP86b2QuyikJyzZY+ozO3Mc8LQc6nOfLRvFzUxAhMOc5M0fIau2fwCSdQSOrFfFCx/yMPQWY+GINQyzyeE= 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=qbjPdRYg; 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="qbjPdRYg" 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=qV1nwYU0a/fMMS0yVafBciQRhGjLTWSKLyU0gCNYBwg=; b=qbjPdRYgCYgaztYfUEmHQbtfLR BMVmuQh0ai9Hdj8bMfR6CG+3EjHed/NDfId57kSq6HjqEwkNYGcwKaLjsvg3GaKvEepaGgsonrLqz zlAPN2aaS2i819lYZAL/krRSNqAB5Oru1wppqXqFBdLO0pUwdCRENrKMB9ZXog93efwnxxztjofsT lDX+UTSUoNylATrAcTV9HpZs9wSMP5CAfZBWclf7dc79WWesu4YGq6NakvXlfSh64PO88ogLTCCAd BsZmbsZ3IpmyhA30jQ71smOvFDAFoDV4Yf/yIlzJT5VmLnSkSxMtfFYqRqTx3LEv+Rf0WAJMrUCqy JeDfL7qQ==; 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 1ulFYD-00CW9P-TC; Mon, 11 Aug 2025 01:34:07 +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 v3 02/10] PM: EM: Add a skeleton code for netlink notification. Date: Mon, 11 Aug 2025 08:33:39 +0900 Message-ID: <20250810233347.81957-3-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250810233347.81957-1-changwoo@igalia.com> References: <20250810233347.81957-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 0451c024cd8c..747493a9320e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9015,7 +9015,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.1 From nobody Sun Oct 5 01:49:56 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 C0BAE2D8368; Sun, 10 Aug 2025 23:34:18 +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=1754868861; cv=none; b=u7ke+3b96PAKye4ozIJcAbEUBVfD959oU4a5zZo9nO/DcQGnP/YL1JJTVCZisEcf6u/GFzE8foAyaigsf6aEzHeKPAbwAdsWbZZDu2oVCUJhrUOqqJFnJZDleVnrafwJkJc5zZTYLtIC5HopB2EMeWznTE9DtRls8amVi7XOv10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868861; c=relaxed/simple; bh=30TV8BWWsW2LWGXbV5qhtHSGeXnt4xXpLwHswvPE3AY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pa7eRuy4/ZeWt5O1izbvDj/L4oCQfBXKyBk4CsidJt+pD8wTt9I4bj8yDxPsTVpv/1G/ZpYj4PeR7GCydzlKz7aMTvK/5qdxC3HekJNtNsXCQ/nrspnvNBgwqDbxrVGgxvK2xuNFH5JPKUoKA7eOqBFFIQOgF5yuYJpNu9EZs2Q= 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=Xl/ANfZW; 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="Xl/ANfZW" 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=nuvwQE8CZ9GhmnevmWAN29NMr++UwfHdn/dwIi+gxFU=; b=Xl/ANfZW/8mkVf55uvFYC27vVA O9iz4OewT7Uulx7/vVYb1VYINY3Hcuai5yoZVeHvsLffagw7Ned0a6wYJxy1bF5SIJnoDj27Gjp8l AGmU9hWfySmiBlkJT6tpdkpJWgDOfk9W/BkDwyRNBB+HvDinX/SSYQNOJsP0I/yQqLjnOOpL7Bvpc Eu1lT/IdawYknDhGYMdTd+oD9tkKS4uQJcP2Epy09s3XDpR2pQLLR0cOXJSlfBSuIiDPa7AI6rZnI Coc9z7JDuX9OuEyUB1BvgunDS+7cYTXtwXf/D48Xx6VUbI0eX7mXqPhoTVeIA9IWxbrDGDcuhxXW+ XGOwflyA==; 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 1ulFYJ-00CW9Y-4c; Mon, 11 Aug 2025 01:34:12 +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 v3 03/10] PM: EM: Assign a unique ID when creating a performance domain. Date: Mon, 11 Aug 2025 08:33:40 +0900 Message-ID: <20250810233347.81957-4-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250810233347.81957-1-changwoo@igalia.com> References: <20250810233347.81957-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.1 From nobody Sun Oct 5 01:49:56 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 51D9E2D8DDF; Sun, 10 Aug 2025 23:34:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868865; cv=none; b=nUIbq287ecP2bjOznw5CDRSgCgIH3hvtteEtUOsf4M6A1sIJUN5X728aN2AzB6R5fu4XP3S5b8G1+nEZSVu6weXFmwkcmnFRLB7deNn2KbO4OGczp4Df/WWt6SIGD1Wa/01Yug81pZeHx/2pcjdvZQpj5plAKwbk8fx/AOpDuGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868865; c=relaxed/simple; bh=MvpC6IFbkoVOh8W2BVLWP4cG7B9UcfBApA8Xt5123Mw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OzJlpqGOMDXUDHQl0eTI0P2GzTHgtQh7fi5jOAB5f9VQGop6lGyu2ddN5CPhLl1ci4rPHr2Iuoa+jYciRqiLpxqvoZhgEr6TQ3ewiNBWs8sQ0dtkgDURBAHLfk1QKxdDAL3Kgm4qcfs/aTAUh0MzkqedNPp8xlFOwPg7gVaVpBA= 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=HFhmSwnz; 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="HFhmSwnz" 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=Hxo+NYLiFnADINm6/scBdHgiUPH9N0/lq+OnC1dkE3Q=; b=HFhmSwnzY0xRPVPOVYzLzguQVE hYLpfsaUp4pN67xcFIlhajjm0MbP/5rWZUg1aZSkEHq1LhhoGgLmbD7D6UMABnTHm0NdXQ3+PP0R5 /ecemedL+DupMVPKH59riqnc6dzSUZc+7i0ei6C+din94/qts85U3KRxmYuz5vp5i6PuVzBGRlXqN HAkA3sAVQgp/E4q+eSl7lJvCvz8gihAw89h1iE36cJ1yCSThDIg/1oL8ahQuFgJpbcWBZkePgS17r /bFq0NN+fdDdIiuaI4s2JIOSms1p7CI2jJFMNFxaINDyqIyv5lb4p4+uV7/A6wJbqxEeCdqc//YkK ggZt37uw==; 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 1ulFYO-00CW9n-LF; Mon, 11 Aug 2025 01:34:17 +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 v3 04/10] PM: EM: Expose the ID of a performance domain via debugfs. Date: Mon, 11 Aug 2025 08:33:41 +0900 Message-ID: <20250810233347.81957-5-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250810233347.81957-1-changwoo@igalia.com> References: <20250810233347.81957-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.1 From nobody Sun Oct 5 01:49:56 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 8C0532D8383; Sun, 10 Aug 2025 23:34:29 +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=1754868871; cv=none; b=ehg6PVC1uvtvyXRiNR6pNVOv8q13g8KNTcRf0RCdfqqzNtyj0ZvRLef2TEyhyuzov3tqVPZhAJ9CtF7N6dOMh6dpYa5nQaPiUd1ITdbR4ov1rNAYU3kDtVQeu+KYLrZl3+7qqMwbKqxVY8ljI8DcYa0vWZJhc8jKP0HtZ3CYPjg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868871; c=relaxed/simple; bh=+E8p1LPAxIi35xQjjyrVIbHLLESyNjX0YAOV8iDtAdg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FyE0Gk12saZfWm1WQs+OlQBJ+SIYsK5LiGf5iqrGPXsd3X73H/29Wcrbt5k0zXg0h5C+8Bf1QtJeOUW7LgWotQuhMkvSzBUgi9sA5nuQgXAL/2QQmXbLAHyM9wsZYAZNycmCtIpFJA2Pxe/tvXwjJT4tYVTrC1o4VCTlXWPcn1s= 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=ioQzHc79; 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="ioQzHc79" 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=XSF8RjyBVZ6UX7DL/VCIElBWNCH7oHr3sUBcfJ43jro=; b=ioQzHc79QvS0zwtpyOYY1LPS2Q w1hanXEmOGUn+t5n9qIOrrFO8bk77caf5R3J/a6ad6P3uwuUWiakRijtwmrJB2Mbjw7SxAnjVPTht cq8vhhoqrd76GzzUfHL3dy7TMLGK6iJ+drnHuIO1dB5IK80Ad4H9vIM69f0feliJ48V0Ida0yKvND CFafxY2ITSGw6WDqTejcXE3tpSKvoiWKBOquvuHTV5U0MrWB8JswaoIRpqL4F9cAo/aD3/ziIRcM1 8fIeY+3bePeQcsCJqA24QFiglmvrfVNNklT+Jar9J7bVoR5ueDEWQcVEu+5auTr8MXi0HD82mjVpK dNvQ/p8Q==; 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 1ulFYT-00CWAD-VO; Mon, 11 Aug 2025 01:34:23 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH RESEND v3 05/10] PM: EM: Add an iterator and accessor for the performance domain. Date: Mon, 11 Aug 2025 08:33:42 +0900 Message-ID: <20250810233347.81957-6-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250810233347.81957-1-changwoo@igalia.com> References: <20250810233347.81957-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.1 From nobody Sun Oct 5 01:49:56 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 ED7782D8383; Sun, 10 Aug 2025 23:34:34 +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=1754868876; cv=none; b=l5naotm0mY79kaXOzFhgLsan9l0HOFIvXSoOOlDGAJkwdU8SH27g1zqnZLrk2KU17cRSWtsDYBAk3OZGXTU33wEapQ6Gkyq0vOYG6hO9/ktldFOdt/YRD2ivpbGrhKOXUoCdT1i/doT0T3BuqGDAJ/FFPzZtZWEiX7nac02oNL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868876; c=relaxed/simple; bh=wTf9+IPFuSPZzgB4fouB+vEMy7ZlfUGMAVLqori3IKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Db6JSGomhLPJLI56Sq5E1CMFp61+Iw1hJoqeVVUTLEnRjz3vaP9h42Qxt/n9PHxW4whcKqYGl9QOkvDij6PvXUPis9KX7pja+a4eMqBcP+Cj+pHl2ajHWefcBj0ecPpTwt6vgXuwwFaac4Beu+ovkEcu5T+lpZgJIyNWhR7OWL8= 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=UolthroP; 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="UolthroP" 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=IB3X0ruD2WaC+ftlfX1Tr8GRv8zTLyN3wbNC9065dts=; b=UolthroPMmt/QKIrgWa3XlHulx fNjvF7W/ygebwzUhgguTIb0pEi03m4i9OArNpXHeo2S9wf3vPM+rVYP0Ua+rgxdBkX2Doe1uXl3QQ e6EYZwX+0XkYyYNvUF77nwWSNnLg5knwiRqJOEM53ECHvnYqzA/KnHU0WHm6sJRvGbxgywixrSj2O TR/FT5GhpcRB31J2IAV8QhobN0KrJfIY+iCS1Ktv1alVHCP0oVZz6vnVw+WvaqpsU20i/hjx5oOHu oNmqgU/u55eAAFnR7ghdVBwEYk5S3l9Q1tzDY7+SfqmK3EZhPvWnPvvO+SO/jRKIMot+6ZTTX0a6A sRhmTapw==; 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 1ulFYZ-00CWAR-7A; Mon, 11 Aug 2025 01:34:28 +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 v3 06/10] PM: EM: Implement em_nl_get_pds_doit(). Date: Mon, 11 Aug 2025 08:33:43 +0900 Message-ID: <20250810233347.81957-7-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250810233347.81957-1-changwoo@igalia.com> References: <20250810233347.81957-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.1 From nobody Sun Oct 5 01:49:56 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 E150D2D8383; Sun, 10 Aug 2025 23:34:41 +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=1754868883; cv=none; b=NhZ8hSi/ri/sUxJM0Bj3t+R711JhvcZiHAfDyGDaaU5ttkV9f2NxsnbGALhLXsX1WpNPULVpaiTIlx2J1dKVpAE0TBtiB2aFFQrGCHdKIAUSiFFaGMxUpGP4Y9iWZq9tLP5gxjbuqaQevudxrkSy5lgMlhf2+6MCEPtZBbeLTR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868883; c=relaxed/simple; bh=cX7QUQniChzvES2NL9XRfje40gkHYXGgM9979ueWV4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ptz+I2oE14xLlEM0YIHRTXpUN5dxy2XO90bRHxFQGRXA5f3IlgBSVRWeDXfx7RhKCcYC0tbq08tCFEkgg7HWOdUVxawA8NbDIIy9F4DbQr9pGLA96fxoqe/1CnS2vfS4X5tRzZT+Ofq4bkHSSlZIu8GgRwo4/EZTQ6hVrrREldE= 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=BqadHHmI; 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="BqadHHmI" 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=u2IFU1K7GlYI5CyrfdCgSx0k96T+09JcpgXk+Jmsq/U=; b=BqadHHmIZtBJVJINp1++jnKzVl 0JSJmyUaeeUG3PHLUtObT8bMVy5UK+J5MuBfa9OtwJ63vtcqVn+iFDsmLSyOnuSLLk4QWVQ2CVE22 vialt3v9zlNSoHCESeyjll8OgnFzRwdtRVr8rBnP3bz8CE3GT228Gqrec4Z3jFm02ndtZmK2EDFL8 nHUS5zpG9OErrmBisFjlIm34W3eIQWFhKP2a4DBjm+T7kbYGHG6mISSkl1/K7/oFIXRuN6K9pTH1f GvZC7FefaBh6sZSJ4KE1fUgZuVPE/8QYJLI+jBA4kRLgsmgFAe7LKS02/wPaiIqnqmfSsibN1meF3 w1lKxYBA==; 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 1ulFYe-00CWAf-Gw; Mon, 11 Aug 2025 01:34:33 +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 v3 07/10] PM: EM: Implement em_nl_get_pd_table_doit(). Date: Mon, 11 Aug 2025 08:33:44 +0900 Message-ID: <20250810233347.81957-8-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250810233347.81957-1-changwoo@igalia.com> References: <20250810233347.81957-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.50.1 From nobody Sun Oct 5 01:49:56 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 842E82D9794; Sun, 10 Aug 2025 23:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868888; cv=none; b=ICKzeN0yrHm38GBe74xOUFYG6ffeNzbP7Jn0XhwePHNuCVPISV+h2S1y8NBByCoUgmrXdd8egMu9xJ5uIlofsyoBu+2t/WCMCbBmUJi2UVjyOBVlTyx3ufXH3v1weAMoyMZIxHXy4UyKv53TfDlj8ir9nZVrLPt46EVKAcIj7Kk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868888; c=relaxed/simple; bh=y9g54dEyqPniZfmITAtKPrchV6fDO67tC4k+Z0pGkgs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gq/hoa4GgiVBXBRuOoZUICGId6GaokQOrAxAVyTOKA8n3NMv1SvxXcV9WleH6MlMrHO19qOvioRrkEsLu6ekDn5aWNTh55BsRGoRAks0uEOjXulV7OOHEcJX3cTA4tyUisDlF1+hUWEZg2i8Vv8N/zMVDYBiDkXSTV68ZmkbSKc= 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=WMFs+hMt; 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="WMFs+hMt" 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=U9RnMf03xQmDO2hEx4IyzU2d3Nh98t5HMVZIR7ByVfk=; b=WMFs+hMt8Sn0nDyTXzjmCXBfn0 pK0i1DxkHk0m8HbLFYv4IWLep4bKwxUxp3gZckPP87KbkohoepH6KvV31OvmNWoX4WCVesreMim4W AoaX9+On1/ViEdyDm3DiGlUbnB6U/miETNVx5pEBQ5laIDRXanYl4vPS/siD/tBYeqXdzyY7crUw7 6bfWJAust9ZsN37Gw395XXyLsPWqBXkA53tn52jyvUjz5ETLxU2te4wGbfUG5Cy5C/UHGLlZaFBp5 poQ33fahTLUFsjGxRlTHBTeAvdtQrWx9Rlg3lGSiR+x98TVPzi3aiv4Vfk5vRlYcf4OCz+7B/TXkl x3cpS5aQ==; 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 1ulFYk-00CWAs-54; Mon, 11 Aug 2025 01:34:39 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH RESEND v3 08/10] PM: EM: Implement em_notify_pd_deleted(). Date: Mon, 11 Aug 2025 08:33:45 +0900 Message-ID: <20250810233347.81957-9-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250810233347.81957-1-changwoo@igalia.com> References: <20250810233347.81957-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.50.1 From nobody Sun Oct 5 01:49:56 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 2E7762D97A0; Sun, 10 Aug 2025 23:34: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=1754868891; cv=none; b=o/4nlFRq0Ti3auVa/OFspiw3A7hTpvikyyJqodysdW5dxAa/NmRjyA8liQs1MZsgHMsC8IXV6EvTq7Mh0IPYKaGzdUEtTBVLjYvf67bpXnoz93Tuhi44rfL80TbWCffb3shkpywamtj4+9x9fFbz66pFI3yrkAN0Y6JFFd0sg7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868891; c=relaxed/simple; bh=Oa2ikAhncCGU9JYgMteZNviLeRQr7b8wO6BUSqUIYyk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tcy1Ih/JtAjFpEh3xe6KkyaSCcFn+XJZ0gCG19l2OwvRVbllPVfaIyiGZTAAKnYgrlSF9OR5V0T6BEhewNkmOl42hjZnKEpdNl/SJMjT5O3tzXi74xWpOSrtyOT4dwItMvY/PgPTGDCenNRrc8Qo4qWarOGxLnTqWa5XGD8g6WU= 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=ofzosT26; 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="ofzosT26" 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=19TkK/wQmFixulKIuREFy0xupeNLlFDct+zAu8O96hM=; b=ofzosT26AByj1PgrgdU3t6ExNj kjhRnXFrV5ex4laijePjClGIrZtEEn9V6tcgrqUAvJ1Nuexgab7lGt9iOfVp8WWANcCUEqr+TbILr l3vm6mA/1OrFL5xvMP3CspyKE2BS4+Z9WeV8VLSvhR+gx+7Y4D1H+17acTFjURQxKNgc69J7ivsEv FbpoUMplF9SXBNhOCzPCTW0M18gLamjF0Vca/Dtkh2L/NmuCwxvpb7WcVVpgVMDCueyaJ4yBD3R0w PpxOZ8x8GooEVgbzbcN50pXW455lnIt1oke7b7n4DA0Sdn9FjVpyQIUQR16BCNRouhTGVIVNX76Wp GhXwgFcA==; 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 1ulFYp-00CWBA-Fc; Mon, 11 Aug 2025 01:34:44 +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 v3 09/10] PM: EM: Implement em_notify_pd_created/updated(). Date: Mon, 11 Aug 2025 08:33:46 +0900 Message-ID: <20250810233347.81957-10-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250810233347.81957-1-changwoo@igalia.com> References: <20250810233347.81957-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.50.1 From nobody Sun Oct 5 01:49:56 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 5577E2D876D; Sun, 10 Aug 2025 23:34:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868897; cv=none; b=nbSi93MMQn7RQH96HNEnqdBRG3WUtdo8biWJ72dD6R1Cn7HbiSPH/bgkR9+DkUszbnLjh2laKPEjvxmR5VdD1BKF8vJwVw3C0IrZouWpp0fn3tPc8CwBe4UYpnKEwdw6NKSUA3+FVV75cgoe9uGBLkujR2ygzUcfP432CYpqow8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754868897; c=relaxed/simple; bh=tH/5vvG+nJo42vQ0Dn/dK3z7XDWN7KkPYZ8gO/iweCw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MyXUqYX05UUFo08ZDhGixGAi7PsJJaesnIN4XumaY3E7uz9mZWppDi6D5vA5+qEw3e8+TXiRiuBO47eKNqR5GbyK0tzUi/R05MGOeM3fvp+A8nQYLVxvK4IXWQZAou+g7fnzGhLmTCkCYKxRBW9F8MjZFM82OZMkdmW8N4WF8YI= 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=ZQg2RqdV; 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="ZQg2RqdV" 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=/sQxHmfDttCLi7HgkpNucR8JfcipNG5wNYUUdmrAhWU=; b=ZQg2RqdVj5r97ts0jOxMAkMTRv xuyZoogVTffSJyVYXQ1jHZYZS6EApaiVym9pUKcE/LUzKolFhS4Stw81RccUSUdyrO3t8KiuQyzoV ZhaNmp+tEHuEp7ln59uafqZVrwKzGqAtkFjmLv8Ap1o+wOf1g7yNDCmWZ78sZH70E7sa/+/ivdV5I pjS7uveAfOZw9UqwKoC4OhUIQHMYcz7pu90GYFbV4J4R9P7KJhYqmVle4lH3h2sYyfGSwJNyQsq1M jYQ/mLzdJJ3tRhQZBhWGYGkvVun4BkWEoPfi2BnOkB8jZ5nmL7+fxAjcsltvmAtsoxcXFsL9vaFAM ls6zsM5Q==; 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 1ulFYv-00CWBm-0A; Mon, 11 Aug 2025 01:34:50 +0200 From: Changwoo Min To: lukasz.luba@arm.com, rafael@kernel.org, len.brown@intel.com, pavel@kernel.org Cc: christian.loehle@arm.com, tj@kernel.org, kernel-dev@igalia.com, linux-pm@vger.kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, Changwoo Min Subject: [PATCH RESEND v3 10/10] PM: EM: Notify an event when the performance domain changes. Date: Mon, 11 Aug 2025 08:33:47 +0900 Message-ID: <20250810233347.81957-11-changwoo@igalia.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250810233347.81957-1-changwoo@igalia.com> References: <20250810233347.81957-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.1