From: Changwoo Min <changwoo@igalia.com>
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, linux-kernel@vger.kernel.org,
Changwoo Min <changwoo@igalia.com>
Subject: [PATCH 08/11] PM: EM: Implement EM_GENL_CMD_PD_GET_ID.
Date: Thu, 29 May 2025 09:13:12 +0900 [thread overview]
Message-ID: <20250529001315.233492-9-changwoo@igalia.com> (raw)
In-Reply-To: <20250529001315.233492-1-changwoo@igalia.com>
When a userspace requests EM_GENL_CMD_PD_GET_ID, the kernel responds with
information on all performance domains. The message format of the response
is as follows:
EM_GENL_ATTR_PD (NLA_NESTED)
EM_PD_ENTRY_GENL_ATTR_PD (NLA_NESTED)*
EM_PD_GENL_ATTR_ID (NLA_U32)
EM_PD_GENL_ATTR_FLAGS (NLA_U64)
EM_PD_GENL_ATTR_CPUS (NLA_STRING)
Where EM_PD_ENTRY_GENL_ATTR_PD can be repeated as many times as there are
performance domains, and EM_PD_GENL_ATTR_CPUS is a hexadecimal string
representing a CPU bitmask.
Signed-off-by: Changwoo Min <changwoo@igalia.com>
---
include/uapi/linux/energy_model.h | 25 ++++++++++++++
kernel/power/em_netlink.c | 55 ++++++++++++++++++++++++++++++-
2 files changed, 79 insertions(+), 1 deletion(-)
diff --git a/include/uapi/linux/energy_model.h b/include/uapi/linux/energy_model.h
index 42a19e614c7d..66339ace6fcb 100644
--- a/include/uapi/linux/energy_model.h
+++ b/include/uapi/linux/energy_model.h
@@ -10,10 +10,35 @@
/* Attributes of em_genl_family */
enum em_genl_attr {
EM_GENL_ATTR_UNSPEC,
+ EM_GENL_ATTR_PAD = EM_GENL_ATTR_UNSPEC,
+ EM_GENL_ATTR_PD, /* Performance domain */
__EM_GENL_ATTR_MAX,
};
#define EM_GENL_ATTR_MAX (__EM_GENL_ATTR_MAX - 1)
+enum em_pd_entry_genl_attr {
+ EM_PD_ENTRY_GENL_ATTR_UNSPEC,
+ EM_PD_ENTRY_GENL_ATTR_PAD = EM_PD_ENTRY_GENL_ATTR_UNSPEC,
+ EM_PD_ENTRY_GENL_ATTR_PD,
+ __EM_PD_ENTRY_GENL_ATTR_MAX,
+};
+#define EM_PD_ENTRY_GENL_ATTR_MAX (__EM_PD_ENTRY_GENL_ATTR_MAX - 1)
+
+enum em_pd_genl_attr {
+ EM_PD_GENL_ATTR_UNSPEC,
+ EM_PD_GENL_ATTR_PAD = EM_PD_GENL_ATTR_UNSPEC,
+
+ /* Performance domain */
+ EM_PD_GENL_ATTR_ID,
+ EM_PD_GENL_ATTR_FLAGS,
+ EM_PD_GENL_ATTR_CPUS,
+
+ __EM_PD_GENL_ATTR_MAX,
+};
+#define EM_PD_GENL_ATTR_MAX (__EM_PD_GENL_ATTR_MAX - 1)
+
+#define EM_PD_CPUS_LENGTH 256
+
/* Events of em_genl_family */
enum em_genl_event {
EM_GENL_EVENT_UNSPEC,
diff --git a/kernel/power/em_netlink.c b/kernel/power/em_netlink.c
index edbaecebd0b4..ea975ca6272f 100644
--- a/kernel/power/em_netlink.c
+++ b/kernel/power/em_netlink.c
@@ -21,6 +21,8 @@ static const struct genl_multicast_group em_genl_mcgrps[] = {
};
static const struct nla_policy em_genl_policy[EM_GENL_ATTR_MAX + 1] = {
+ /* Performance domain */
+ [EM_GENL_ATTR_PD] = { .type = NLA_NESTED },
};
struct param {
@@ -34,9 +36,60 @@ static struct genl_family em_genl_family;
/*************************** Command encoding ********************************/
+static int __em_genl_cmd_pd_get_id(struct em_perf_domain *pd, void *data)
+{
+ char cpus_buf[EM_PD_CPUS_LENGTH];
+ struct sk_buff *msg = data;
+ struct nlattr *entry;
+
+ entry = nla_nest_start(msg, EM_PD_ENTRY_GENL_ATTR_PD);
+ if (!entry)
+ goto out_cancel_nest;
+
+ if (nla_put_u32(msg, EM_PD_GENL_ATTR_ID, pd->id))
+ goto out_cancel_nest;
+
+ if (nla_put_u64_64bit(msg, EM_PD_GENL_ATTR_FLAGS, pd->flags,
+ EM_PD_GENL_ATTR_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_PD_GENL_ATTR_CPUS, cpus_buf))
+ goto out_cancel_nest;
+
+ nla_nest_end(msg, entry);
+
+ return 0;
+
+out_cancel_nest:
+ nla_nest_cancel(msg, entry);
+
+ return -EMSGSIZE;
+}
+
static int em_genl_cmd_pd_get_id(struct param *p)
{
- return -ENOTSUPP;
+ struct sk_buff *msg = p->msg;
+ struct nlattr *start_pd;
+ int ret;
+
+ start_pd = nla_nest_start(msg, EM_GENL_ATTR_PD);
+ if (!start_pd)
+ return -EMSGSIZE;
+
+ ret = for_each_em_perf_domain(__em_genl_cmd_pd_get_id, msg);
+ if (ret)
+ goto out_cancel_nest;
+
+ nla_nest_end(msg, start_pd);
+
+ return 0;
+
+out_cancel_nest:
+ nla_nest_cancel(msg, start_pd);
+
+ return ret;
}
static int em_genl_cmd_pd_get_tbl(struct param *p)
--
2.49.0
next prev parent reply other threads:[~2025-05-29 0:14 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-29 0:13 [PATCH 00/11] PM: EM: Add netlink support for the energy model Changwoo Min
2025-05-29 0:13 ` [PATCH 01/11] PM: EM: Add ENERGY_MODEL_NETLINK Kconfig Changwoo Min
2025-05-29 0:13 ` [PATCH 02/11] PM: EM: Add a skeleton code for netlink notification Changwoo Min
2025-06-02 19:53 ` Lukas Wunner
2025-06-03 6:01 ` Changwoo Min
2025-05-29 0:13 ` [PATCH 03/11] PM: EM: Initialize the netlink notification during booting Changwoo Min
2025-05-29 0:13 ` [PATCH 04/11] PM: EM: Add the infrastructure for command processing Changwoo Min
2025-06-02 19:59 ` Lukas Wunner
2025-06-04 16:11 ` Changwoo Min
2025-05-29 0:13 ` [PATCH 05/11] PM: EM: Assign a unique ID when creating a performance domain Changwoo Min
2025-05-29 0:13 ` [PATCH 06/11] PM: EM: Expose the ID of a performance domain via debugfs Changwoo Min
2025-05-29 0:13 ` [PATCH 07/11] PM: EM: Add an iterator and accessor for the performance domain Changwoo Min
2025-05-29 0:13 ` Changwoo Min [this message]
2025-05-29 0:13 ` [PATCH 09/11] PM: EM: Implement EM_GENL_CMD_PD_GET_TBL Changwoo Min
2025-05-29 0:13 ` [PATCH 10/11] PM: EM: Implement event notification Changwoo Min
2025-05-29 0:13 ` [PATCH 11/11] PM: EM: Notify an event when the performance domain changes Changwoo Min
2025-06-02 11:52 ` [PATCH 00/11] PM: EM: Add netlink support for the energy model Lukasz Luba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250529001315.233492-9-changwoo@igalia.com \
--to=changwoo@igalia.com \
--cc=christian.loehle@arm.com \
--cc=kernel-dev@igalia.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®