All of lore.kernel.org
 help / color / mirror / Atom feed
From: Souradeep Chowdhury <quic_schowdhu@quicinc.com>
To: Andy Gross <agross@kernel.org>,
	Konrad Dybcio <konrad.dybcio@somainline.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Rob Herring <robh+dt@kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <linux-arm-msm@vger.kernel.org>,
	<devicetree@vger.kernel.org>,
	Sibi Sankar <quic_sibis@quicinc.com>,
	Rajendra Nayak <quic_rjendra@quicinc.com>,
	Souradeep Chowdhury <quic_schowdhu@quicinc.com>
Subject: [PATCH V1 3/4] soc: qcom: boot_stat: Add Driver Support for Boot Stats
Date: Tue, 21 Mar 2023 19:21:50 +0530	[thread overview]
Message-ID: <3f385562845ae26d519940ca8098fde89282991b.1679403696.git.quic_schowdhu@quicinc.com> (raw)
In-Reply-To: <cover.1679403696.git.quic_schowdhu@quicinc.com>

All of Qualcomm's proprietary Android boot-loaders capture boot time
stats, like the time when the bootloader started execution and at what
point the bootloader handed over control to the kernel etc. in the IMEM
region. This information is captured in a specific format by this driver
by mapping a structure to the IMEM memory region and then accessing the
members of the structure to print the information. This information is
useful in verifying if the existing boot KPIs have regressed or not.
A sample log in SM8450(waipio) device is as follows:-

KPI: Pre ABL Time = 3s
KPI: ABL Time = 14s
KPI: Kernel MPM timestamp = 890206

The Module Power Manager(MPM) sleep counter starts ticking at the PBL
stage and the timestamp generated by the sleep counter is logged by
the Qualcomm proprietary bootloader(ABL) at two points-> First when it
starts execution which is logged here as "Pre ABL Time" and the second
when it is about to load the kernel logged as "ABL Time". Both are
logged in the unit of seconds. The current kernel timestamp is
printed by the boot_stats driver as well.

Signed-off-by: Souradeep Chowdhury <quic_schowdhu@quicinc.com>
---
 drivers/soc/qcom/Kconfig      |   7 +++
 drivers/soc/qcom/Makefile     |   1 +
 drivers/soc/qcom/boot_stats.c | 108 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 drivers/soc/qcom/boot_stats.c

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index d11bda2..2cfdbb7 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -79,6 +79,13 @@ config QCOM_DCC
 	  driver provides interface to configure DCC block and read back
 	  captured data from DCC's internal SRAM.

+config QCOM_BOOTSTAT
+	tristate "Qualcomm Technologies, Boot Stat driver"
+	depends on ARCH_QCOM || COMPILE_TEST
+	help
+	  This option enables driver for boot stats. Boot stat driver prints
+	  the kernel bootloader information by accessing the imem region.
+
 config QCOM_KRYO_L2_ACCESSORS
 	bool
 	depends on ARCH_QCOM && ARM64 || COMPILE_TEST
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index 3b92c6c..e9b1e52 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_QCOM_GENI_SE) +=	qcom-geni-se.o
 obj-$(CONFIG_QCOM_COMMAND_DB) += cmd-db.o
 obj-$(CONFIG_QCOM_CPR)		+= cpr.o
 obj-$(CONFIG_QCOM_DCC) += dcc.o
+obj-$(CONFIG_QCOM_BOOTSTAT) += boot_stats.o
 obj-$(CONFIG_QCOM_GSBI)	+=	qcom_gsbi.o
 obj-$(CONFIG_QCOM_MDT_LOADER)	+= mdt_loader.o
 obj-$(CONFIG_QCOM_OCMEM)	+= ocmem.o
diff --git a/drivers/soc/qcom/boot_stats.c b/drivers/soc/qcom/boot_stats.c
new file mode 100644
index 0000000..59b5ab6
--- /dev/null
+++ b/drivers/soc/qcom/boot_stats.c
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2013-2019, 2021 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ */
+
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+
+/**
+ *  struct boot_stats - timestamp information related to boot stats
+ *  @bootloader_start:	Time for the starting point of the abl bootloader
+ *  @bootloader_end:	Time when the kernel starts loading from abl bootloader
+ */
+struct boot_stats {
+	u32 bootloader_start;
+	u32 bootloader_end;
+} __packed;
+
+static struct boot_stats __iomem *boot_stats;
+static void __iomem *mpm_counter_base;
+static u32 mpm_counter_freq;
+
+static int mpm_parse_dt(void)
+{
+	struct device_node *np_imem, *np_mpm2;
+
+	np_imem = of_find_compatible_node(NULL, NULL,
+					  "qcom,imem-boot_stats");
+	if (!np_imem) {
+		pr_err("can't find qcom,imem node\n");
+		return -ENODEV;
+	}
+	boot_stats = of_iomap(np_imem, 0);
+	if (!boot_stats) {
+		pr_err("boot_stats: Can't map imem\n");
+		goto err1;
+	}
+
+	np_mpm2 = of_find_compatible_node(NULL, NULL,
+					  "qcom,mpm2-sleep-counter");
+	if (!np_mpm2) {
+		pr_err("mpm_counter: can't find DT node\n");
+		goto err2;
+	}
+
+	if (of_property_read_u32(np_mpm2, "clock-frequency", &mpm_counter_freq))
+		goto err2;
+
+	if (of_get_address(np_mpm2, 0, NULL, NULL)) {
+		mpm_counter_base = of_iomap(np_mpm2, 0);
+		if (!mpm_counter_base) {
+			pr_err("mpm_counter: can't map counter base\n");
+			goto err2;
+		}
+	} else {
+		goto err2;
+	}
+
+	return 0;
+
+err2:
+	of_node_put(np_mpm2);
+err1:
+	of_node_put(np_imem);
+	return -ENODEV;
+}
+
+static void print_boot_stats(void)
+{
+	u32 pre_abl_time = readl_relaxed(&boot_stats->bootloader_start) / mpm_counter_freq;
+	u32 abl_time = readl_relaxed(&boot_stats->bootloader_end) / mpm_counter_freq;
+
+	pr_info("KPI: Pre ABL Time = %us\n", pre_abl_time);
+	pr_info("KPI: ABL Time = %us\n", abl_time);
+	pr_info("KPI: Kernel MPM timestamp = %u\n", readl_relaxed(mpm_counter_base));
+}
+
+static int __init boot_stats_init(void)
+{
+	int ret;
+
+	ret = mpm_parse_dt();
+	if (ret < 0)
+		return -ENODEV;
+
+	print_boot_stats();
+
+	iounmap(boot_stats);
+	iounmap(mpm_counter_base);
+
+	return 0;
+}
+module_init(boot_stats_init);
+
+static void __exit boot_stats_exit(void)
+{
+}
+module_exit(boot_stats_exit)
+
+MODULE_DESCRIPTION("Qualcomm Technologies Inc. Boot Stat driver");
+MODULE_LICENSE("GPL");
--
2.7.4


WARNING: multiple messages have this Message-ID (diff)
From: Souradeep Chowdhury <quic_schowdhu@quicinc.com>
To: Andy Gross <agross@kernel.org>,
	Konrad Dybcio <konrad.dybcio@somainline.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Rob Herring <robh+dt@kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <linux-arm-msm@vger.kernel.org>,
	<devicetree@vger.kernel.org>,
	Sibi Sankar <quic_sibis@quicinc.com>,
	Rajendra Nayak <quic_rjendra@quicinc.com>,
	Souradeep Chowdhury <quic_schowdhu@quicinc.com>
Subject: [PATCH V1 3/4] soc: qcom: boot_stat: Add Driver Support for Boot Stats
Date: Tue, 21 Mar 2023 19:21:50 +0530	[thread overview]
Message-ID: <3f385562845ae26d519940ca8098fde89282991b.1679403696.git.quic_schowdhu@quicinc.com> (raw)
In-Reply-To: <cover.1679403696.git.quic_schowdhu@quicinc.com>

All of Qualcomm's proprietary Android boot-loaders capture boot time
stats, like the time when the bootloader started execution and at what
point the bootloader handed over control to the kernel etc. in the IMEM
region. This information is captured in a specific format by this driver
by mapping a structure to the IMEM memory region and then accessing the
members of the structure to print the information. This information is
useful in verifying if the existing boot KPIs have regressed or not.
A sample log in SM8450(waipio) device is as follows:-

KPI: Pre ABL Time = 3s
KPI: ABL Time = 14s
KPI: Kernel MPM timestamp = 890206

The Module Power Manager(MPM) sleep counter starts ticking at the PBL
stage and the timestamp generated by the sleep counter is logged by
the Qualcomm proprietary bootloader(ABL) at two points-> First when it
starts execution which is logged here as "Pre ABL Time" and the second
when it is about to load the kernel logged as "ABL Time". Both are
logged in the unit of seconds. The current kernel timestamp is
printed by the boot_stats driver as well.

Signed-off-by: Souradeep Chowdhury <quic_schowdhu@quicinc.com>
---
 drivers/soc/qcom/Kconfig      |   7 +++
 drivers/soc/qcom/Makefile     |   1 +
 drivers/soc/qcom/boot_stats.c | 108 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 drivers/soc/qcom/boot_stats.c

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index d11bda2..2cfdbb7 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -79,6 +79,13 @@ config QCOM_DCC
 	  driver provides interface to configure DCC block and read back
 	  captured data from DCC's internal SRAM.

+config QCOM_BOOTSTAT
+	tristate "Qualcomm Technologies, Boot Stat driver"
+	depends on ARCH_QCOM || COMPILE_TEST
+	help
+	  This option enables driver for boot stats. Boot stat driver prints
+	  the kernel bootloader information by accessing the imem region.
+
 config QCOM_KRYO_L2_ACCESSORS
 	bool
 	depends on ARCH_QCOM && ARM64 || COMPILE_TEST
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index 3b92c6c..e9b1e52 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_QCOM_GENI_SE) +=	qcom-geni-se.o
 obj-$(CONFIG_QCOM_COMMAND_DB) += cmd-db.o
 obj-$(CONFIG_QCOM_CPR)		+= cpr.o
 obj-$(CONFIG_QCOM_DCC) += dcc.o
+obj-$(CONFIG_QCOM_BOOTSTAT) += boot_stats.o
 obj-$(CONFIG_QCOM_GSBI)	+=	qcom_gsbi.o
 obj-$(CONFIG_QCOM_MDT_LOADER)	+= mdt_loader.o
 obj-$(CONFIG_QCOM_OCMEM)	+= ocmem.o
diff --git a/drivers/soc/qcom/boot_stats.c b/drivers/soc/qcom/boot_stats.c
new file mode 100644
index 0000000..59b5ab6
--- /dev/null
+++ b/drivers/soc/qcom/boot_stats.c
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2013-2019, 2021 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ */
+
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+
+/**
+ *  struct boot_stats - timestamp information related to boot stats
+ *  @bootloader_start:	Time for the starting point of the abl bootloader
+ *  @bootloader_end:	Time when the kernel starts loading from abl bootloader
+ */
+struct boot_stats {
+	u32 bootloader_start;
+	u32 bootloader_end;
+} __packed;
+
+static struct boot_stats __iomem *boot_stats;
+static void __iomem *mpm_counter_base;
+static u32 mpm_counter_freq;
+
+static int mpm_parse_dt(void)
+{
+	struct device_node *np_imem, *np_mpm2;
+
+	np_imem = of_find_compatible_node(NULL, NULL,
+					  "qcom,imem-boot_stats");
+	if (!np_imem) {
+		pr_err("can't find qcom,imem node\n");
+		return -ENODEV;
+	}
+	boot_stats = of_iomap(np_imem, 0);
+	if (!boot_stats) {
+		pr_err("boot_stats: Can't map imem\n");
+		goto err1;
+	}
+
+	np_mpm2 = of_find_compatible_node(NULL, NULL,
+					  "qcom,mpm2-sleep-counter");
+	if (!np_mpm2) {
+		pr_err("mpm_counter: can't find DT node\n");
+		goto err2;
+	}
+
+	if (of_property_read_u32(np_mpm2, "clock-frequency", &mpm_counter_freq))
+		goto err2;
+
+	if (of_get_address(np_mpm2, 0, NULL, NULL)) {
+		mpm_counter_base = of_iomap(np_mpm2, 0);
+		if (!mpm_counter_base) {
+			pr_err("mpm_counter: can't map counter base\n");
+			goto err2;
+		}
+	} else {
+		goto err2;
+	}
+
+	return 0;
+
+err2:
+	of_node_put(np_mpm2);
+err1:
+	of_node_put(np_imem);
+	return -ENODEV;
+}
+
+static void print_boot_stats(void)
+{
+	u32 pre_abl_time = readl_relaxed(&boot_stats->bootloader_start) / mpm_counter_freq;
+	u32 abl_time = readl_relaxed(&boot_stats->bootloader_end) / mpm_counter_freq;
+
+	pr_info("KPI: Pre ABL Time = %us\n", pre_abl_time);
+	pr_info("KPI: ABL Time = %us\n", abl_time);
+	pr_info("KPI: Kernel MPM timestamp = %u\n", readl_relaxed(mpm_counter_base));
+}
+
+static int __init boot_stats_init(void)
+{
+	int ret;
+
+	ret = mpm_parse_dt();
+	if (ret < 0)
+		return -ENODEV;
+
+	print_boot_stats();
+
+	iounmap(boot_stats);
+	iounmap(mpm_counter_base);
+
+	return 0;
+}
+module_init(boot_stats_init);
+
+static void __exit boot_stats_exit(void)
+{
+}
+module_exit(boot_stats_exit)
+
+MODULE_DESCRIPTION("Qualcomm Technologies Inc. Boot Stat driver");
+MODULE_LICENSE("GPL");
--
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2023-03-21 13:53 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21 13:51 [PATCH V1 0/4] soc: qcom: boot_stats: Add driver support for boot_stats Souradeep Chowdhury
2023-03-21 13:51 ` Souradeep Chowdhury
2023-03-21 13:51 ` [PATCH V1 1/4] dt-bindings: sram: qcom,imem: Add Boot Stat region within IMEM Souradeep Chowdhury
2023-03-21 13:51   ` Souradeep Chowdhury
2023-03-21 17:31   ` Krzysztof Kozlowski
2023-03-21 17:31     ` Krzysztof Kozlowski
2023-03-22 13:34     ` Souradeep Chowdhury
2023-03-22 13:34       ` Souradeep Chowdhury
2023-03-22 16:27       ` Krzysztof Kozlowski
2023-03-22 16:27         ` Krzysztof Kozlowski
2023-03-23 13:46         ` Souradeep Chowdhury
2023-03-23 13:46           ` Souradeep Chowdhury
2023-03-21 13:51 ` [PATCH V1 2/4] dt-bindings: soc: qcom,mpm-sleep-counter: Add the dtschema Souradeep Chowdhury
2023-03-21 13:51   ` Souradeep Chowdhury
2023-03-21 17:33   ` Krzysztof Kozlowski
2023-03-21 17:33     ` Krzysztof Kozlowski
2023-03-22 13:46     ` Souradeep Chowdhury
2023-03-22 13:46       ` Souradeep Chowdhury
2023-03-22 16:29       ` Krzysztof Kozlowski
2023-03-22 16:29         ` Krzysztof Kozlowski
2023-03-23 13:49         ` Souradeep Chowdhury
2023-03-23 13:49           ` Souradeep Chowdhury
2023-03-21 17:39   ` Krzysztof Kozlowski
2023-03-21 17:39     ` Krzysztof Kozlowski
2023-03-22 14:02     ` Souradeep Chowdhury
2023-03-22 14:02       ` Souradeep Chowdhury
2023-03-22 16:31       ` Krzysztof Kozlowski
2023-03-22 16:31         ` Krzysztof Kozlowski
2023-03-23 13:51         ` Souradeep Chowdhury
2023-03-23 13:51           ` Souradeep Chowdhury
2023-03-21 13:51 ` Souradeep Chowdhury [this message]
2023-03-21 13:51   ` [PATCH V1 3/4] soc: qcom: boot_stat: Add Driver Support for Boot Stats Souradeep Chowdhury
2023-03-21 17:37   ` Krzysztof Kozlowski
2023-03-21 17:37     ` Krzysztof Kozlowski
2023-03-22 13:54     ` Souradeep Chowdhury
2023-03-22 13:54       ` Souradeep Chowdhury
2023-03-22 14:53       ` Krzysztof Kozlowski
2023-03-22 14:53         ` Krzysztof Kozlowski
2023-03-23 13:45         ` Souradeep Chowdhury
2023-03-23 13:45           ` Souradeep Chowdhury
2023-03-24  8:56           ` Krzysztof Kozlowski
2023-03-24  8:56             ` Krzysztof Kozlowski
2023-03-21 13:51 ` [PATCH V1 4/4] MAINTAINERS: Add the entry for boot_stats driver support Souradeep Chowdhury
2023-03-21 13:51   ` Souradeep Chowdhury

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=3f385562845ae26d519940ca8098fde89282991b.1679403696.git.quic_schowdhu@quicinc.com \
    --to=quic_schowdhu@quicinc.com \
    --cc=agross@kernel.org \
    --cc=andersson@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=konrad.dybcio@somainline.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_rjendra@quicinc.com \
    --cc=quic_sibis@quicinc.com \
    --cc=robh+dt@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.