From patchwork Fri Apr 7 14:04:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souradeep Chowdhury X-Patchwork-Id: 13204943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68B2FC77B6C for ; Fri, 7 Apr 2023 14:07:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WBjWzIhz2AQSsl9kqLcE9i2SS/HrROEYHx3RUWC4VLI=; b=aQEF8WKnE/2AI9 GTSto6WxLczrgTRQPz/OqeTaLC/+NAwsEYCOaCKfLtMu4MDB5GZaPlmC4zwcM4IJcv2AIzOIkZq5Z oh/Nq9naw+gDkysS3HvkPjWnHOjlRi7cV2bFn4EtuKiq9snn6vtJHsBnQJpNmiNS319K8OHza4doB pHbd+q/srS5ybPxon2R6GPEYaEAWl0pf/9dvELLPCkVB3xa9bKXC125Z2O373rnlHZdMBcXGAVcx0 E71196nmY99HF+/AsY01B6ujTooVLssdo+b+k/3zSp7RSGO0TekmB2vHqXb2zwIhhJsyuR1JgxDFv Hdy/HRCiAFsLbSB+rffQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pkmju-00ASsv-2X; Fri, 07 Apr 2023 14:06:54 +0000 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pkmjl-00ASpE-21 for linux-arm-kernel@lists.infradead.org; Fri, 07 Apr 2023 14:06:47 +0000 Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 337E1hs3024072; Fri, 7 Apr 2023 14:06:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=dR5hsH0YjVOrcxCTKV/JJnRf8WXDP6gF0YttNyCiG9k=; b=C9W7xb88LSAfAgfcvjxqKMQcd+tObj8IZO4xjOaSnHTxxeTejFW5cQ0aMYPFGnSMpaIc p4mJkNIAAEXNIGkBUXhszlX9Q2HMDLwe80cln0uZw0SW0oK7V5WxZD1pwjqmIMsFYQSC 2eDLQtWpm3PkA51VPqMWWlK5G9O2+8/fXPbZiLLc3igwjWS79a5Hv/yLacLuVwofvz8e tN/KDV/PChYFzl4DTN4JRYyMvasGJKdnqiDe6USOPcPaVa9QNSW9PfLruBXfMj/cPeOo s77fECQcrl92J0PzJVWCzD/Sp+J2iogEvo2wPVmHCppWc2QTGMlfm/PYZzrA+k5VKLJ5 TA== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ptb9wh2r2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 07 Apr 2023 14:06:42 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 337E6fQk029617 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 7 Apr 2023 14:06:41 GMT Received: from blr-ubuntu-525.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Fri, 7 Apr 2023 07:06:36 -0700 From: Souradeep Chowdhury To: Andy Gross , Konrad Dybcio , Krzysztof Kozlowski , Bjorn Andersson , Rob Herring CC: , , , , Sibi Sankar , Rajendra Nayak , Souradeep Chowdhury Subject: [PATCH V2 2/3] soc: qcom: boot_stat: Add Driver Support for Boot Stats Date: Fri, 7 Apr 2023 19:34:36 +0530 Message-ID: <5eeeb46e9b3f61656a37cb77c2ad6a04e383c16d.1680874520.git.quic_schowdhu@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: a2q5MDYc7Vq_tJORb45hiNNKpu5zcY-p X-Proofpoint-ORIG-GUID: a2q5MDYc7Vq_tJORb45hiNNKpu5zcY-p X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-07_08,2023-04-06_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 spamscore=0 phishscore=0 malwarescore=0 bulkscore=0 adultscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 impostorscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304070129 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230407_070645_676518_907002F7 X-CRM114-Status: GOOD ( 32.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- drivers/soc/qcom/Kconfig | 7 ++++ drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/boot_stats.c | 95 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 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..8a9d995 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_new.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..080e820 --- /dev/null +++ b/drivers/soc/qcom/boot_stats.c @@ -0,0 +1,95 @@ +// 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 +#include +#include +#include +#include +#include +#include +#include + +#define MPM_COUNTER_FREQ 32768 + +/** + * 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; + +struct boot_stats __iomem *boot_stats; +void __iomem *mpm_counter_base; + +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 boot_stats_probe(struct platform_device *pdev) +{ + struct device_node *np_mpm2; + struct device *boot_stat = &pdev->dev; + + boot_stats = of_iomap(boot_stat->of_node->child, 0); + if (!boot_stats) + return dev_err_probe(&pdev->dev, -ENOMEM, + "failed to map imem region\n"); + + np_mpm2 = of_find_compatible_node(NULL, NULL, + "qcom,mpm2-sleep-counter"); + if (!np_mpm2) { + return dev_err_probe(&pdev->dev, -EINVAL, + "failed to get the counter node\n"); + } + + if (of_get_address(np_mpm2, 0, NULL, NULL)) { + mpm_counter_base = of_iomap(np_mpm2, 0); + if (!mpm_counter_base) { + return dev_err_probe(&pdev->dev, -ENOMEM, + "failed to map the counter\n"); + } + } + print_boot_stats(); + + return 0; +} + +static int boot_stats_remove(struct platform_device *pdev) +{ + iounmap(boot_stats); + iounmap(mpm_counter_base); + + return 0; +} + +static const struct of_device_id boot_stats_dt_match[] = { + { .compatible = "qcom,sm8450-imem" }, + { } +}; +MODULE_DEVICE_TABLE(of, boot_stats_dt_match); + +static struct platform_driver boot_stat_driver = { + .probe = boot_stats_probe, + .remove = boot_stats_remove, + .driver = { + .name = "qcom-boot-stats", + .of_match_table = boot_stats_dt_match, + }, +}; +module_platform_driver(boot_stat_driver); + +MODULE_DESCRIPTION("Qualcomm Technologies Inc. Boot Stat driver"); +MODULE_LICENSE("GPL");