Skip to contentSkip to conversation

Introduce RPM Master stats

PATCH Superseded Konrad Dybcio 3 participants 8 messages Apr 14, 2023 – Apr 17, 2023

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover Introduce RPM Master stats

v2 -> v3:
- rename rpm-master-stats.yaml to qcom,rpm-master-stats.yaml

v2: https://lore.kernel.org/r/[email protected]

v1 -> v2:
- Drop the - in /properties/compatible to make our entry be of the correct type [1/2]
- Change %s to %d for printing out the iterator [2/2]

v1: https://lore.kernel.org/r/[email protected]

The RPM MSG ram includes per-subsystem low-power mode entry/exit/ residence/etc. statistics which are very useful for trying to debug what I'd call "SoC insomnia", or IOW the plaftorm refusing to drop the voltage rails to a minimum and gate the non-critical clocks.

This series adds a very short and simple driver to query that data and expose it through debugfs.

The base used for writing this driver is:
https://github.com/sonyxperiadev/kernel/blob/aosp/LA.UM.9.14.r1/drivers/soc/qcom/rpm_master_stat.c

---
Konrad Dybcio (2):
dt-bindings: soc: qcom: Add RPM Master stats
soc: qcom: Introduce RPM master stats driver

 .../bindings/soc/qcom/qcom,rpm-master-stats.yaml   |  53 +++++++
 drivers/soc/qcom/Kconfig                           |  11 ++
 drivers/soc/qcom/Makefile                          |   1 +
 drivers/soc/qcom/rpm_master_stats.c                | 160 +++++++++++++++++++++
 4 files changed, 225 insertions(+)

---
base-commit: e3342532ecd39bbd9c2ab5b9001cec1589bc37e9
change-id: 20230405-topic-master_stats-ba201a9af93d

Best regards,

Signature · 1 line
Konrad Dybcio <[email protected]>
#1 lore raw

PATCH v3 1/2 dt-bindings: soc: qcom: Add RPM Master stats

The RPM MSG RAM contains per-RPM-master (e.g. APPS, ADSP etc.) sleep statistics. They let one assess which core is actively preventing the system from entering a true low-power mode.

---
 .../bindings/soc/qcom/qcom,rpm-master-stats.yaml   | 53 ++++++++++++++++++++++
 1 file changed, 53 insertions(+)
Documentation/devicetree/bindings/soc/qcom/qcom,rpm-master-stats.yaml new file +53 -0
new file mode 100644
index 000000000000..d7e58cbd3344
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/qcom/qcom,rpm-master-stats.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies, Inc. (QTI) RPM Master Stats
+
+maintainers:
+  - Konrad Dybcio <[email protected]>
+
+description:
+  Per-RPM-Master (e.g. APSS, ADSP, etc.) sleep statistics.
+
+properties:
+  compatible:
+    const: qcom,rpm-master-stats
+
+  qcom,rpm-msg-ram:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    description: Phandle to an RPM MSG RAM slice containing the master stats
+    minItems: 1
+    maxItems: 5
+
+  qcom,master-names:
+    $ref: /schemas/types.yaml#/definitions/string-array
+    description: RPM Master name
+    minItems: 1
+    maxItems: 5
+
+required:
+  - compatible
+  - qcom,rpm-msg-ram
+  - qcom,master-names
+
+additionalProperties: false
+
+examples:
+  - |
+    stats {
+      compatible = "qcom,rpm-master-stats";
+      qcom,rpm-msg-ram = <&apss_master_stats>,
+                         <&mpss_master_stats>,
+                         <&adsp_master_stats>,
+                         <&cdsp_master_stats>,
+                         <&tz_master_stats>;
+      qcom,master-names = "APSS",
+                          "MPSS",
+                          "ADSP",
+                          "CDSP",
+                          "TZ";
+    };
+...
Signature · 1 line
2.40.0
#2 lore raw

Re: [PATCH v3 1/2] dt-bindings: soc: qcom: Add RPM Master stats

Quoted 18 lines · Konrad Dybcio

The RPM MSG RAM contains per-RPM-master (e.g. APPS, ADSP etc.) sleep statistics. They let one assess which core is actively preventing the system from entering a true low-power mode.

---
 .../bindings/soc/qcom/qcom,rpm-master-stats.yaml   | 53 ++++++++++++++++++++++
 1 file changed, 53 insertions(+)
Documentation/devicetree/bindings/soc/qcom/qcom,rpm-master-stats.yaml new file +3 -0
new file mode 100644
index 000000000000..d7e58cbd3344
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---

Documentation/devicetree/bindings/soc/qcom/qcom,rpm-master-stats.yaml line 13

Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,rpm-master-stats.yaml new file +10 -0
+$id: http://devicetree.org/schemas/soc/qcom/qcom,rpm-master-stats.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies, Inc. (QTI) RPM Master Stats
+
+maintainers:
+  - Konrad Dybcio <[email protected]>
+
+description:
+  Per-RPM-Master (e.g. APSS, ADSP, etc.) sleep statistics.

Explain what is RPM-Master and what do you mean by "sleep".

Quoted 4 lines
Documentation/devicetree/bindings/soc/qcom/qcom,rpm-master-stats.yaml new file +4 -0
+
+properties:
+  compatible:
+    const: qcom,rpm-master-stats

Documentation/devicetree/bindings/soc/qcom/qcom,rpm-master-stats.yaml line 27

Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,rpm-master-stats.yaml new file +10 -0
+
+  qcom,rpm-msg-ram:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    description: Phandle to an RPM MSG RAM slice containing the master stats
+    minItems: 1
+    maxItems: 5
+
+  qcom,master-names:
+    $ref: /schemas/types.yaml#/definitions/string-array
+    description: RPM Master name

There is a relation between this and qcom,rpm-msg-ram which you do not describe. It's not just RPM master name...

Best regards,
Krzysztof

#3 lore raw

PATCH v3 2/2 soc: qcom: Introduce RPM master stats driver

In reply to Konrad Dybcio

Introduce a driver to query and expose detailed, per-subsystem (as opposed to the existing qcom_stats driver which exposes SoC-wide data) about low power mode states of a given RPM master. That includes the APSS (ARM), MPSS (modem) and other remote cores, depending on the platform configuration.

This is a vastly cleaned up and restructured version of a similar driver found in msm-5.4.

---
 drivers/soc/qcom/Kconfig            |  11 +++
 drivers/soc/qcom/Makefile           |   1 +
 drivers/soc/qcom/rpm_master_stats.c | 160 ++++++++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+)
drivers/soc/qcom/Kconfig +11 -0
index a491718f8064..e597799e8121 100644
@@ -135,6 +135,17 @@ config QCOM_RMTFS_MEM
 
 	  Say y here if you intend to boot the modem remoteproc.
 
+config QCOM_RPM_MASTER_STATS
+	tristate "Qualcomm RPM Master stats"
+	depends on ARCH_QCOM || COMPILE_TEST
+	help
+	  The RPM Master sleep stats driver provides detailed per-subsystem
+	  sleep/wake data, read from the RPM message RAM. It can be used to
+	  assess whether all the low-power modes available are entered as
+	  expected or to check which part of the SoC prevents it from sleeping.
+
+	  Say y here if you intend to debug or monitor platform sleep.
+
 config QCOM_RPMH
 	tristate "Qualcomm RPM-Hardened (RPMH) Communication"
 	depends on ARCH_QCOM || COMPILE_TEST
drivers/soc/qcom/Makefile +1 -0
index 0f43a88b4894..7349371fdea1 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_QCOM_QMI_HELPERS)	+= qmi_helpers.o
 qmi_helpers-y	+= qmi_encdec.o qmi_interface.o
 obj-$(CONFIG_QCOM_RAMP_CTRL)	+= ramp_controller.o
 obj-$(CONFIG_QCOM_RMTFS_MEM)	+= rmtfs_mem.o
+obj-$(CONFIG_QCOM_RPM_MASTER_STATS)	+= rpm_master_stats.o
 obj-$(CONFIG_QCOM_RPMH)		+= qcom_rpmh.o
 qcom_rpmh-y			+= rpmh-rsc.o
 qcom_rpmh-y			+= rpmh.o
drivers/soc/qcom/rpm_master_stats.c new file +160 -0

160 lines not on this page · raw message

Signature · 1 line
2.40.0
#4 lore raw

Re: [PATCH v3 2/2] soc: qcom: Introduce RPM master stats driver

Quoted 56 lines · Konrad Dybcio

Introduce a driver to query and expose detailed, per-subsystem (as opposed to the existing qcom_stats driver which exposes SoC-wide data) about low power mode states of a given RPM master. That includes the APSS (ARM), MPSS (modem) and other remote cores, depending on the platform configuration.

This is a vastly cleaned up and restructured version of a similar driver found in msm-5.4.

---
 drivers/soc/qcom/Kconfig            |  11 +++
 drivers/soc/qcom/Makefile           |   1 +
 drivers/soc/qcom/rpm_master_stats.c | 160 ++++++++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+)
drivers/soc/qcom/Kconfig +11 -0
index a491718f8064..e597799e8121 100644
@@ -135,6 +135,17 @@ config QCOM_RMTFS_MEM
 
 	  Say y here if you intend to boot the modem remoteproc.
 
+config QCOM_RPM_MASTER_STATS
+	tristate "Qualcomm RPM Master stats"
+	depends on ARCH_QCOM || COMPILE_TEST
+	help
+	  The RPM Master sleep stats driver provides detailed per-subsystem
+	  sleep/wake data, read from the RPM message RAM. It can be used to
+	  assess whether all the low-power modes available are entered as
+	  expected or to check which part of the SoC prevents it from sleeping.
+
+	  Say y here if you intend to debug or monitor platform sleep.
+
 config QCOM_RPMH
 	tristate "Qualcomm RPM-Hardened (RPMH) Communication"
 	depends on ARCH_QCOM || COMPILE_TEST
drivers/soc/qcom/Makefile +1 -0
index 0f43a88b4894..7349371fdea1 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_QCOM_QMI_HELPERS)	+= qmi_helpers.o
 qmi_helpers-y	+= qmi_encdec.o qmi_interface.o
 obj-$(CONFIG_QCOM_RAMP_CTRL)	+= ramp_controller.o
 obj-$(CONFIG_QCOM_RMTFS_MEM)	+= rmtfs_mem.o
+obj-$(CONFIG_QCOM_RPM_MASTER_STATS)	+= rpm_master_stats.o
 obj-$(CONFIG_QCOM_RPMH)		+= qcom_rpmh.o
 qcom_rpmh-y			+= rpmh-rsc.o
 qcom_rpmh-y			+= rpmh.o
drivers/soc/qcom/rpm_master_stats.c new file +0 -0
new file mode 100644
index 000000000000..73080c92bf89

drivers/soc/qcom/rpm_master_stats.c line 7

Quoted 7 lines
drivers/soc/qcom/rpm_master_stats.c new file +7 -0
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2023, Linaro Limited
+ *
+ * This driver supports what is known as "Master Stats v2", which seems to be
+ * the only version which has ever shipped, all the way from 2013 to 2023.

It'd better to mention "Qualcomm downstream" in the somewhere above comment to make it clear for users.

Quoted 20 lines
drivers/soc/qcom/rpm_master_stats.c new file +20 -0
+ */
+
+#include <linux/debugfs.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+
+struct master_stats_data {
+	void __iomem *base;
+	const char *label;
+};
+
+struct rpm_master_stats {
+	uint32_t active_cores;
+	uint32_t num_shutdowns;
+	uint64_t shutdown_req;
+	uint64_t wakeup_idx;
+	uint64_t bringup_req;

drivers/soc/qcom/rpm_master_stats.c line 37

Quoted 10 lines
drivers/soc/qcom/rpm_master_stats.c new file +10 -0
+	uint64_t bringup_ack;
+	uint32_t wakeup_reason; /* 0 = "rude wakeup", 1 = scheduled wakeup */
+	uint32_t last_sleep_trans_dur;
+	uint32_t last_wake_trans_dur;
+
+	/* Per-subsystem (*not necessarily* SoC-wide) XO shutdown stats */
+	uint32_t xo_count;
+	uint64_t xo_last_enter;
+	uint64_t last_exit;
+	uint64_t xo_total_dur;

Why can't you use u64, u32?

Also, sort these members as below:

u64
u32

Quoted 24 lines
drivers/soc/qcom/rpm_master_stats.c new file +24 -0
+};
+
+static int master_stats_show(struct seq_file *s, void *unused)
+{
+	struct master_stats_data *d = s->private;
+	struct rpm_master_stats stat;
+
+	memcpy_fromio(&stat, d->base, sizeof(stat));
+
+	seq_printf(s, "%s:\n", d->label);
+
+	seq_printf(s, "\tLast shutdown @ %llu\n", stat.shutdown_req);
+	seq_printf(s, "\tLast bringup req @ %llu\n", stat.bringup_req);
+	seq_printf(s, "\tLast bringup ack @ %llu\n", stat.bringup_ack);
+	seq_printf(s, "\tLast wakeup idx: %llu\n", stat.wakeup_idx);
+	seq_printf(s, "\tLast XO shutdown enter @ %llu\n", stat.xo_last_enter);
+	seq_printf(s, "\tLast XO shutdown exit @ %llu\n", stat.last_exit);
+	seq_printf(s, "\tXO total duration: %llu\n", stat.xo_total_dur);
+	seq_printf(s, "\tLast sleep transition duration: %u\n", stat.last_sleep_trans_dur);
+	seq_printf(s, "\tLast wake transition duration: %u\n", stat.last_wake_trans_dur);
+	seq_printf(s, "\tXO shutdown count: %u\n", stat.xo_count);
+	seq_printf(s, "\tWakeup reason: 0x%x\n", stat.wakeup_reason);
+	seq_printf(s, "\tShutdown count: %u\n", stat.num_shutdowns);
+	seq_printf(s, "\tActive cores bitmask: 0x%x\n", stat.active_cores);

drivers/soc/qcom/rpm_master_stats.c line 71

Quoted 10 lines
drivers/soc/qcom/rpm_master_stats.c new file +10 -0
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(master_stats);
+
+static int master_stats_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *msgram_np;
+	struct master_stats_data *d;

"d" is not a good choice for a local variable (might be OK above but definitely not here)

drivers/soc/qcom/rpm_master_stats.c line 84

Quoted 13 lines
drivers/soc/qcom/rpm_master_stats.c new file +13 -0
+	struct dentry *dent, *root;
+	struct resource res;
+	int count, i, ret;
+
+	count = of_property_count_strings(dev->of_node, "qcom,master-names");
+	if (count < 0)
+		return count;
+
+	d = devm_kzalloc(dev, count * sizeof(*d), GFP_KERNEL);
+	if (!d)
+		return -ENOMEM;
+
+	root = debugfs_create_dir("rpm_master_stats", NULL);

It's better to use "qcom_rpm_master_stats".

drivers/soc/qcom/rpm_master_stats.c line 91

Quoted 7 lines
drivers/soc/qcom/rpm_master_stats.c new file +7 -0
+	platform_set_drvdata(pdev, root);
+
+	for (i = 0; i < count; i++) {
+		msgram_np = of_parse_phandle(dev->of_node, "qcom,rpm-msg-ram", i);
+		if (!msgram_np) {
+			debugfs_remove_recursive(root);
+			return dev_err_probe(dev, -EINVAL,

-ENODEV

drivers/soc/qcom/rpm_master_stats.c line 99

Quoted 8 lines
drivers/soc/qcom/rpm_master_stats.c new file +8 -0
+					     "Couldn't parse MSG RAM phandle idx %d", i);
+		}
+
+		/*
+		 * Purposefully skip devm_platform helpers as we're using a
+		 * shared resource.
+		 */
+		ret = of_address_to_resource(msgram_np, 0, &res);

Missing of_node_put() here due to of_parse_phandle().

Quoted 17 lines
drivers/soc/qcom/rpm_master_stats.c new file +17 -0
+		if (ret < 0) {
+			debugfs_remove_recursive(root);
+			return ret;
+		}
+
+		d[i].base = devm_ioremap(dev, res.start, resource_size(&res));
+		if (IS_ERR(d[i].base)) {
+			debugfs_remove_recursive(root);
+			return dev_err_probe(dev, -EINVAL,
+					     "Could not map the MSG RAM slice idx %d!\n", i);
+		}
+
+		ret = of_property_read_string_index(dev->of_node, "qcom,master-names", i,
+						    &d[i].label);
+		if (ret < 0) {
+			debugfs_remove_recursive(root);
+			return dev_err_probe(dev, ret,

drivers/soc/qcom/rpm_master_stats.c line 126

Quoted 10 lines
drivers/soc/qcom/rpm_master_stats.c new file +10 -0
+					     "Could not read name idx %d!\n", i);
+		}
+
+		/*
+		 * Generally it's not advised to fail on debugfs errors, but this
+		 * driver's only job is exposing data therein.
+		 */
+		dent = debugfs_create_file(d[i].label, 0444, root,
+					   &d[i], &master_stats_fops);
+		if (!dent) {

Don't check for NULL, instead use IS_ERR() if you really care about error checking here.

Quoted 23 lines
drivers/soc/qcom/rpm_master_stats.c new file +23 -0
+			debugfs_remove_recursive(root);
+			return -EINVAL;
+		}
+	}
+
+	device_set_pm_not_required(dev);
+
+	return 0;
+}
+
+static void master_stats_remove(struct platform_device *pdev)
+{
+	struct dentry *root = platform_get_drvdata(pdev);
+
+	debugfs_remove_recursive(root);
+}
+
+static const struct of_device_id rpm_master_table[] = {
+	{ .compatible = "qcom,rpm-master-stats" },
+	{ },
+};
+
+static struct platform_driver master_stats_driver = {

drivers/soc/qcom/rpm_master_stats.c line 159

Quoted 10 lines
drivers/soc/qcom/rpm_master_stats.c new file +10 -0
+	.probe = master_stats_probe,
+	.remove_new = master_stats_remove,
+	.driver = {
+		.name = "rpm_master_stats",
+		.of_match_table = rpm_master_table,
+	},
+};
+module_platform_driver(master_stats_driver);
+
+MODULE_DESCRIPTION("RPM Master Statistics driver");

Qualcomm RPM Master Statistics driver

- Mani

Quoted 5 lines
drivers/soc/qcom/rpm_master_stats.c new file +1 -0
+MODULE_LICENSE("GPL");
Signature · 2 lines
-- 
2.40.0
Signature · 1 line
மணிவண்ணன் சதாசிவம்
#5 lore raw

Re: [PATCH v3 2/2] soc: qcom: Introduce RPM master stats driver

Quoted 59 lines · Manivannan Sadhasivam
Quoted 58 lines · Konrad Dybcio

Introduce a driver to query and expose detailed, per-subsystem (as opposed to the existing qcom_stats driver which exposes SoC-wide data) about low power mode states of a given RPM master. That includes the APSS (ARM), MPSS (modem) and other remote cores, depending on the platform configuration.

This is a vastly cleaned up and restructured version of a similar driver found in msm-5.4.

---
 drivers/soc/qcom/Kconfig            |  11 +++
 drivers/soc/qcom/Makefile           |   1 +
 drivers/soc/qcom/rpm_master_stats.c | 160 ++++++++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+)
drivers/soc/qcom/Kconfig +11 -0
index a491718f8064..e597799e8121 100644
@@ -135,6 +135,17 @@ config QCOM_RMTFS_MEM
 
 	  Say y here if you intend to boot the modem remoteproc.
 
+config QCOM_RPM_MASTER_STATS
+	tristate "Qualcomm RPM Master stats"
+	depends on ARCH_QCOM || COMPILE_TEST
+	help
+	  The RPM Master sleep stats driver provides detailed per-subsystem
+	  sleep/wake data, read from the RPM message RAM. It can be used to
+	  assess whether all the low-power modes available are entered as
+	  expected or to check which part of the SoC prevents it from sleeping.
+
+	  Say y here if you intend to debug or monitor platform sleep.
+
 config QCOM_RPMH
 	tristate "Qualcomm RPM-Hardened (RPMH) Communication"
 	depends on ARCH_QCOM || COMPILE_TEST
drivers/soc/qcom/Makefile +1 -0
index 0f43a88b4894..7349371fdea1 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_QCOM_QMI_HELPERS)	+= qmi_helpers.o
 qmi_helpers-y	+= qmi_encdec.o qmi_interface.o
 obj-$(CONFIG_QCOM_RAMP_CTRL)	+= ramp_controller.o
 obj-$(CONFIG_QCOM_RMTFS_MEM)	+= rmtfs_mem.o
+obj-$(CONFIG_QCOM_RPM_MASTER_STATS)	+= rpm_master_stats.o
 obj-$(CONFIG_QCOM_RPMH)		+= qcom_rpmh.o
 qcom_rpmh-y			+= rpmh-rsc.o
 qcom_rpmh-y			+= rpmh.o
drivers/soc/qcom/rpm_master_stats.c new file +2 -0
new file mode 100644
index 000000000000..73080c92bf89
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
Quoted 8 lines

drivers/soc/qcom/rpm_master_stats.c line 7

Quoted 5 lines
drivers/soc/qcom/rpm_master_stats.c new file +5 -0
+ * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2023, Linaro Limited
+ *
+ * This driver supports what is known as "Master Stats v2", which seems to be
+ * the only version which has ever shipped, all the way from 2013 to 2023.

It'd better to mention "Qualcomm downstream" in the somewhere above comment to make it clear for users.

Ack

Quoted 25 lines
Quoted 25 lines
drivers/soc/qcom/rpm_master_stats.c new file +24 -0
+ */
+
+#include <linux/debugfs.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+
+struct master_stats_data {
+	void __iomem *base;
+	const char *label;
+};
+
+struct rpm_master_stats {
+	uint32_t active_cores;
+	uint32_t num_shutdowns;
+	uint64_t shutdown_req;
+	uint64_t wakeup_idx;
+	uint64_t bringup_req;
+	uint64_t bringup_ack;
+	uint32_t wakeup_reason; /* 0 = "rude wakeup", 1 = scheduled wakeup */
+	uint32_t last_sleep_trans_dur;
+	uint32_t last_wake_trans_dur;
Quoted 8 lines

drivers/soc/qcom/rpm_master_stats.c line 37

Quoted 6 lines
drivers/soc/qcom/rpm_master_stats.c new file +6 -0
+
+	/* Per-subsystem (*not necessarily* SoC-wide) XO shutdown stats */
+	uint32_t xo_count;
+	uint64_t xo_last_enter;
+	uint64_t last_exit;
+	uint64_t xo_total_dur;

Why can't you use u64, u32?

Brain derp!

Quoted 5 lines

Also, sort these members as below:

u64
u32

No, it's the way this data is structured in the memory and we copy it as a whole.

Quoted 30 lines
Quoted 30 lines
drivers/soc/qcom/rpm_master_stats.c new file +29 -0
+};
+
+static int master_stats_show(struct seq_file *s, void *unused)
+{
+	struct master_stats_data *d = s->private;
+	struct rpm_master_stats stat;
+
+	memcpy_fromio(&stat, d->base, sizeof(stat));
+
+	seq_printf(s, "%s:\n", d->label);
+
+	seq_printf(s, "\tLast shutdown @ %llu\n", stat.shutdown_req);
+	seq_printf(s, "\tLast bringup req @ %llu\n", stat.bringup_req);
+	seq_printf(s, "\tLast bringup ack @ %llu\n", stat.bringup_ack);
+	seq_printf(s, "\tLast wakeup idx: %llu\n", stat.wakeup_idx);
+	seq_printf(s, "\tLast XO shutdown enter @ %llu\n", stat.xo_last_enter);
+	seq_printf(s, "\tLast XO shutdown exit @ %llu\n", stat.last_exit);
+	seq_printf(s, "\tXO total duration: %llu\n", stat.xo_total_dur);
+	seq_printf(s, "\tLast sleep transition duration: %u\n", stat.last_sleep_trans_dur);
+	seq_printf(s, "\tLast wake transition duration: %u\n", stat.last_wake_trans_dur);
+	seq_printf(s, "\tXO shutdown count: %u\n", stat.xo_count);
+	seq_printf(s, "\tWakeup reason: 0x%x\n", stat.wakeup_reason);
+	seq_printf(s, "\tShutdown count: %u\n", stat.num_shutdowns);
+	seq_printf(s, "\tActive cores bitmask: 0x%x\n", stat.active_cores);
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(master_stats);
+
Quoted 8 lines

drivers/soc/qcom/rpm_master_stats.c line 71

Quoted 5 lines
drivers/soc/qcom/rpm_master_stats.c new file +5 -0
+static int master_stats_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *msgram_np;
+	struct master_stats_data *d;

"d" is not a good choice for a local variable (might be OK above but definitely not here)

Sure, I can change it.

Quoted 16 lines
Quoted 4 lines
drivers/soc/qcom/rpm_master_stats.c new file +3 -0
+	struct dentry *dent, *root;
+	struct resource res;
+	int count, i, ret;

drivers/soc/qcom/rpm_master_stats.c line 84

Quoted 10 lines
drivers/soc/qcom/rpm_master_stats.c new file +10 -0
+
+	count = of_property_count_strings(dev->of_node, "qcom,master-names");
+	if (count < 0)
+		return count;
+
+	d = devm_kzalloc(dev, count * sizeof(*d), GFP_KERNEL);
+	if (!d)
+		return -ENOMEM;
+
+	root = debugfs_create_dir("rpm_master_stats", NULL);

It's better to use "qcom_rpm_master_stats".

Ack

Quoted 10 lines

drivers/soc/qcom/rpm_master_stats.c line 91

Quoted 8 lines
drivers/soc/qcom/rpm_master_stats.c new file +7 -0
+	platform_set_drvdata(pdev, root);
+
+	for (i = 0; i < count; i++) {
+		msgram_np = of_parse_phandle(dev->of_node, "qcom,rpm-msg-ram", i);
+		if (!msgram_np) {
+			debugfs_remove_recursive(root);
+			return dev_err_probe(dev, -EINVAL,

-ENODEV

Ack

Quoted 11 lines

drivers/soc/qcom/rpm_master_stats.c line 99

Quoted 9 lines
drivers/soc/qcom/rpm_master_stats.c new file +8 -0
+					     "Couldn't parse MSG RAM phandle idx %d", i);
+		}
+
+		/*
+		 * Purposefully skip devm_platform helpers as we're using a
+		 * shared resource.
+		 */
+		ret = of_address_to_resource(msgram_np, 0, &res);

Missing of_node_put() here due to of_parse_phandle().

Ack

Quoted 23 lines
Quoted 23 lines
drivers/soc/qcom/rpm_master_stats.c new file +22 -0
+		if (ret < 0) {
+			debugfs_remove_recursive(root);
+			return ret;
+		}
+
+		d[i].base = devm_ioremap(dev, res.start, resource_size(&res));
+		if (IS_ERR(d[i].base)) {
+			debugfs_remove_recursive(root);
+			return dev_err_probe(dev, -EINVAL,
+					     "Could not map the MSG RAM slice idx %d!\n", i);
+		}
+
+		ret = of_property_read_string_index(dev->of_node, "qcom,master-names", i,
+						    &d[i].label);
+		if (ret < 0) {
+			debugfs_remove_recursive(root);
+			return dev_err_probe(dev, ret,
+					     "Could not read name idx %d!\n", i);
+		}
+
+		/*
+		 * Generally it's not advised to fail on debugfs errors, but this
Quoted 8 lines

drivers/soc/qcom/rpm_master_stats.c line 126

Quoted 5 lines
drivers/soc/qcom/rpm_master_stats.c new file +5 -0
+		 * driver's only job is exposing data therein.
+		 */
+		dent = debugfs_create_file(d[i].label, 0444, root,
+					   &d[i], &master_stats_fops);
+		if (!dent) {

Don't check for NULL, instead use IS_ERR() if you really care about error checking here.

"This function will return a pointer to a dentry if it succeeds. This pointer must be passed to the debugfs_remove function when the file is to be removed (no automatic cleanup happens if your module is unloaded, you are responsible here.) If an error occurs, NULL will be returned."

Quoted 28 lines
Quoted 28 lines
drivers/soc/qcom/rpm_master_stats.c new file +27 -0
+			debugfs_remove_recursive(root);
+			return -EINVAL;
+		}
+	}
+
+	device_set_pm_not_required(dev);
+
+	return 0;
+}
+
+static void master_stats_remove(struct platform_device *pdev)
+{
+	struct dentry *root = platform_get_drvdata(pdev);
+
+	debugfs_remove_recursive(root);
+}
+
+static const struct of_device_id rpm_master_table[] = {
+	{ .compatible = "qcom,rpm-master-stats" },
+	{ },
+};
+
+static struct platform_driver master_stats_driver = {
+	.probe = master_stats_probe,
+	.remove_new = master_stats_remove,
+	.driver = {
+		.name = "rpm_master_stats",
Quoted 8 lines

drivers/soc/qcom/rpm_master_stats.c line 159

Quoted 6 lines
drivers/soc/qcom/rpm_master_stats.c new file +6 -0
+		.of_match_table = rpm_master_table,
+	},
+};
+module_platform_driver(master_stats_driver);
+
+MODULE_DESCRIPTION("RPM Master Statistics driver");

Qualcomm RPM Master Statistics driver

Ack

Konrad

Quoted 9 lines

- Mani

Quoted 5 lines
drivers/soc/qcom/rpm_master_stats.c new file +1 -0
+MODULE_LICENSE("GPL");
Signature · 2 lines
-- 
2.40.0
#6 lore raw

Re: [PATCH v3 2/2] soc: qcom: Introduce RPM master stats driver

Quoted 108 lines · Konrad Dybcio
Quoted 59 lines · Manivannan Sadhasivam
Quoted 58 lines · Konrad Dybcio

Introduce a driver to query and expose detailed, per-subsystem (as opposed to the existing qcom_stats driver which exposes SoC-wide data) about low power mode states of a given RPM master. That includes the APSS (ARM), MPSS (modem) and other remote cores, depending on the platform configuration.

This is a vastly cleaned up and restructured version of a similar driver found in msm-5.4.

---
 drivers/soc/qcom/Kconfig            |  11 +++
 drivers/soc/qcom/Makefile           |   1 +
 drivers/soc/qcom/rpm_master_stats.c | 160 ++++++++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+)
drivers/soc/qcom/Kconfig +11 -0
index a491718f8064..e597799e8121 100644
@@ -135,6 +135,17 @@ config QCOM_RMTFS_MEM
 
 	  Say y here if you intend to boot the modem remoteproc.
 
+config QCOM_RPM_MASTER_STATS
+	tristate "Qualcomm RPM Master stats"
+	depends on ARCH_QCOM || COMPILE_TEST
+	help
+	  The RPM Master sleep stats driver provides detailed per-subsystem
+	  sleep/wake data, read from the RPM message RAM. It can be used to
+	  assess whether all the low-power modes available are entered as
+	  expected or to check which part of the SoC prevents it from sleeping.
+
+	  Say y here if you intend to debug or monitor platform sleep.
+
 config QCOM_RPMH
 	tristate "Qualcomm RPM-Hardened (RPMH) Communication"
 	depends on ARCH_QCOM || COMPILE_TEST
drivers/soc/qcom/Makefile +1 -0
index 0f43a88b4894..7349371fdea1 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_QCOM_QMI_HELPERS)	+= qmi_helpers.o
 qmi_helpers-y	+= qmi_encdec.o qmi_interface.o
 obj-$(CONFIG_QCOM_RAMP_CTRL)	+= ramp_controller.o
 obj-$(CONFIG_QCOM_RMTFS_MEM)	+= rmtfs_mem.o
+obj-$(CONFIG_QCOM_RPM_MASTER_STATS)	+= rpm_master_stats.o
 obj-$(CONFIG_QCOM_RPMH)		+= qcom_rpmh.o
 qcom_rpmh-y			+= rpmh-rsc.o
 qcom_rpmh-y			+= rpmh.o
drivers/soc/qcom/rpm_master_stats.c new file +2 -0
new file mode 100644
index 000000000000..73080c92bf89
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
Quoted 8 lines

drivers/soc/qcom/rpm_master_stats.c line 7

Quoted 5 lines
drivers/soc/qcom/rpm_master_stats.c new file +5 -0
+ * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2023, Linaro Limited
+ *
+ * This driver supports what is known as "Master Stats v2", which seems to be
+ * the only version which has ever shipped, all the way from 2013 to 2023.

It'd better to mention "Qualcomm downstream" in the somewhere above comment to make it clear for users.

Ack

Quoted 25 lines
Quoted 25 lines
drivers/soc/qcom/rpm_master_stats.c new file +24 -0
+ */
+
+#include <linux/debugfs.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+
+struct master_stats_data {
+	void __iomem *base;
+	const char *label;
+};
+
+struct rpm_master_stats {
+	uint32_t active_cores;
+	uint32_t num_shutdowns;
+	uint64_t shutdown_req;
+	uint64_t wakeup_idx;
+	uint64_t bringup_req;
+	uint64_t bringup_ack;
+	uint32_t wakeup_reason; /* 0 = "rude wakeup", 1 = scheduled wakeup */
+	uint32_t last_sleep_trans_dur;
+	uint32_t last_wake_trans_dur;
Quoted 8 lines

drivers/soc/qcom/rpm_master_stats.c line 37

Quoted 6 lines
drivers/soc/qcom/rpm_master_stats.c new file +6 -0
+
+	/* Per-subsystem (*not necessarily* SoC-wide) XO shutdown stats */
+	uint32_t xo_count;
+	uint64_t xo_last_enter;
+	uint64_t last_exit;
+	uint64_t xo_total_dur;

Why can't you use u64, u32?

Brain derp!

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

Also, sort these members as below:

u64
u32

No, it's the way this data is structured in the memory and we copy it as a whole.

Ok, in that case you'd need __packed.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/soc/qcom/rpm_master_stats.c new file +2 -0
+};
+

[...]

Quoted 10 lines
Quoted 10 lines

drivers/soc/qcom/rpm_master_stats.c line 126

Quoted 7 lines
drivers/soc/qcom/rpm_master_stats.c new file +7 -0
+		/*
+		 * Generally it's not advised to fail on debugfs errors, but this
+		 * driver's only job is exposing data therein.
+		 */
+		dent = debugfs_create_file(d[i].label, 0444, root,
+					   &d[i], &master_stats_fops);
+		if (!dent) {

Don't check for NULL, instead use IS_ERR() if you really care about error checking here.

Quoted 6 lines

"This function will return a pointer to a dentry if it succeeds. This pointer must be passed to the debugfs_remove function when the file is to be removed (no automatic cleanup happens if your module is unloaded, you are responsible here.) If an error occurs, NULL will be returned."

This seems to be the old comment. Take a look at the updated one in mainline:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/debugfs/inode.c#n468

Greg changed the semantics of the debugfs APIs a while back but the kernel doc was updated recently:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/fs/debugfs/inode.c?id=d3002468cb5d5da11e22145c9af32facd5c34352

- Mani

Quoted 49 lines
Quoted 29 lines
Quoted 29 lines
drivers/soc/qcom/rpm_master_stats.c new file +27 -0
+			debugfs_remove_recursive(root);
+			return -EINVAL;
+		}
+	}
+
+	device_set_pm_not_required(dev);
+
+	return 0;
+}
+
+static void master_stats_remove(struct platform_device *pdev)
+{
+	struct dentry *root = platform_get_drvdata(pdev);
+
+	debugfs_remove_recursive(root);
+}
+
+static const struct of_device_id rpm_master_table[] = {
+	{ .compatible = "qcom,rpm-master-stats" },
+	{ },
+};
+
+static struct platform_driver master_stats_driver = {
+	.probe = master_stats_probe,
+	.remove_new = master_stats_remove,
+	.driver = {
+		.name = "rpm_master_stats",
Quoted 8 lines

drivers/soc/qcom/rpm_master_stats.c line 159

Quoted 6 lines
drivers/soc/qcom/rpm_master_stats.c new file +6 -0
+		.of_match_table = rpm_master_table,
+	},
+};
+module_platform_driver(master_stats_driver);
+
+MODULE_DESCRIPTION("RPM Master Statistics driver");

Qualcomm RPM Master Statistics driver

Ack

Konrad

Quoted 9 lines

- Mani

Quoted 5 lines

+MODULE_LICENSE("GPL");

Signature · 1 line
2.40.0
Signature · 1 line
மணிவண்ணன் சதாசிவம்
#7 lore raw

Re: [PATCH v3 2/2] soc: qcom: Introduce RPM master stats driver

Quoted 142 lines · Manivannan Sadhasivam
Quoted 108 lines · Konrad Dybcio
Quoted 59 lines · Manivannan Sadhasivam
Quoted 58 lines · Konrad Dybcio

Introduce a driver to query and expose detailed, per-subsystem (as opposed to the existing qcom_stats driver which exposes SoC-wide data) about low power mode states of a given RPM master. That includes the APSS (ARM), MPSS (modem) and other remote cores, depending on the platform configuration.

This is a vastly cleaned up and restructured version of a similar driver found in msm-5.4.

---
 drivers/soc/qcom/Kconfig            |  11 +++
 drivers/soc/qcom/Makefile           |   1 +
 drivers/soc/qcom/rpm_master_stats.c | 160 ++++++++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+)
drivers/soc/qcom/Kconfig +11 -0
index a491718f8064..e597799e8121 100644
@@ -135,6 +135,17 @@ config QCOM_RMTFS_MEM
 
 	  Say y here if you intend to boot the modem remoteproc.
 
+config QCOM_RPM_MASTER_STATS
+	tristate "Qualcomm RPM Master stats"
+	depends on ARCH_QCOM || COMPILE_TEST
+	help
+	  The RPM Master sleep stats driver provides detailed per-subsystem
+	  sleep/wake data, read from the RPM message RAM. It can be used to
+	  assess whether all the low-power modes available are entered as
+	  expected or to check which part of the SoC prevents it from sleeping.
+
+	  Say y here if you intend to debug or monitor platform sleep.
+
 config QCOM_RPMH
 	tristate "Qualcomm RPM-Hardened (RPMH) Communication"
 	depends on ARCH_QCOM || COMPILE_TEST
drivers/soc/qcom/Makefile +1 -0
index 0f43a88b4894..7349371fdea1 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_QCOM_QMI_HELPERS)	+= qmi_helpers.o
 qmi_helpers-y	+= qmi_encdec.o qmi_interface.o
 obj-$(CONFIG_QCOM_RAMP_CTRL)	+= ramp_controller.o
 obj-$(CONFIG_QCOM_RMTFS_MEM)	+= rmtfs_mem.o
+obj-$(CONFIG_QCOM_RPM_MASTER_STATS)	+= rpm_master_stats.o
 obj-$(CONFIG_QCOM_RPMH)		+= qcom_rpmh.o
 qcom_rpmh-y			+= rpmh-rsc.o
 qcom_rpmh-y			+= rpmh.o
drivers/soc/qcom/rpm_master_stats.c new file +2 -0
new file mode 100644
index 000000000000..73080c92bf89
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
Quoted 8 lines

drivers/soc/qcom/rpm_master_stats.c line 7

Quoted 5 lines
drivers/soc/qcom/rpm_master_stats.c new file +5 -0
+ * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2023, Linaro Limited
+ *
+ * This driver supports what is known as "Master Stats v2", which seems to be
+ * the only version which has ever shipped, all the way from 2013 to 2023.

It'd better to mention "Qualcomm downstream" in the somewhere above comment to make it clear for users.

Ack

Quoted 25 lines
Quoted 25 lines
drivers/soc/qcom/rpm_master_stats.c new file +24 -0
+ */
+
+#include <linux/debugfs.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+
+struct master_stats_data {
+	void __iomem *base;
+	const char *label;
+};
+
+struct rpm_master_stats {
+	uint32_t active_cores;
+	uint32_t num_shutdowns;
+	uint64_t shutdown_req;
+	uint64_t wakeup_idx;
+	uint64_t bringup_req;
+	uint64_t bringup_ack;
+	uint32_t wakeup_reason; /* 0 = "rude wakeup", 1 = scheduled wakeup */
+	uint32_t last_sleep_trans_dur;
+	uint32_t last_wake_trans_dur;
Quoted 8 lines

drivers/soc/qcom/rpm_master_stats.c line 37

Quoted 6 lines
drivers/soc/qcom/rpm_master_stats.c new file +6 -0
+
+	/* Per-subsystem (*not necessarily* SoC-wide) XO shutdown stats */
+	uint32_t xo_count;
+	uint64_t xo_last_enter;
+	uint64_t last_exit;
+	uint64_t xo_total_dur;

Why can't you use u64, u32?

Brain derp!

Quoted 1 line
Quoted 7 lines
Quoted 4 lines

Also, sort these members as below:

u64
u32

No, it's the way this data is structured in the memory and we copy it as a whole.

Ok, in that case you'd need __packed.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/soc/qcom/rpm_master_stats.c new file +2 -0
+};
+

[...]

Quoted 10 lines
Quoted 10 lines

drivers/soc/qcom/rpm_master_stats.c line 126

Quoted 7 lines
drivers/soc/qcom/rpm_master_stats.c new file +7 -0
+		/*
+		 * Generally it's not advised to fail on debugfs errors, but this
+		 * driver's only job is exposing data therein.
+		 */
+		dent = debugfs_create_file(d[i].label, 0444, root,
+					   &d[i], &master_stats_fops);
+		if (!dent) {

Don't check for NULL, instead use IS_ERR() if you really care about error checking here.

Quoted 6 lines

"This function will return a pointer to a dentry if it succeeds. This pointer must be passed to the debugfs_remove function when the file is to be removed (no automatic cleanup happens if your module is unloaded, you are responsible here.) If an error occurs, NULL will be returned."

Quoted 6 lines

This seems to be the old comment. Take a look at the updated one in mainline:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/debugfs/inode.c#n468

Greg changed the semantics of the debugfs APIs a while back but the kernel doc was updated recently:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/fs/debugfs/inode.c?id=d3002468cb5d5da11e22145c9af32facd5c34352

Okay, ack to both. I'll fix all that and resend!

Konrad

Quoted 53 lines

- Mani

Quoted 49 lines
Quoted 29 lines
Quoted 29 lines
drivers/soc/qcom/rpm_master_stats.c new file +27 -0
+			debugfs_remove_recursive(root);
+			return -EINVAL;
+		}
+	}
+
+	device_set_pm_not_required(dev);
+
+	return 0;
+}
+
+static void master_stats_remove(struct platform_device *pdev)
+{
+	struct dentry *root = platform_get_drvdata(pdev);
+
+	debugfs_remove_recursive(root);
+}
+
+static const struct of_device_id rpm_master_table[] = {
+	{ .compatible = "qcom,rpm-master-stats" },
+	{ },
+};
+
+static struct platform_driver master_stats_driver = {
+	.probe = master_stats_probe,
+	.remove_new = master_stats_remove,
+	.driver = {
+		.name = "rpm_master_stats",
Quoted 8 lines

drivers/soc/qcom/rpm_master_stats.c line 159

Quoted 6 lines
drivers/soc/qcom/rpm_master_stats.c new file +6 -0
+		.of_match_table = rpm_master_table,
+	},
+};
+module_platform_driver(master_stats_driver);
+
+MODULE_DESCRIPTION("RPM Master Statistics driver");

Qualcomm RPM Master Statistics driver

Ack

Konrad

Quoted 9 lines

- Mani

Quoted 5 lines

+MODULE_LICENSE("GPL");

Signature · 1 line
2.40.0