Re: [PATCH V6 2/3] soc: qcom: boot_stat: Add Driver Support for Boot Stats

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 9 May 2023 at 15:27, Souradeep Chowdhury
<quic_schowdhu@xxxxxxxxxxx> wrote:
>
>
>
> On 5/9/2023 5:09 PM, Dmitry Baryshkov wrote:
> > On Tue, 9 May 2023 at 13:53, Souradeep Chowdhury
> > <quic_schowdhu@xxxxxxxxxxx> wrote:


> >> diff --git a/drivers/soc/qcom/boot_stats.c b/drivers/soc/qcom/boot_stats.c
> >> new file mode 100644
> >> index 000000000000..ca67b6b5d8eb
> >> --- /dev/null
> >> +++ b/drivers/soc/qcom/boot_stats.c
> >> @@ -0,0 +1,100 @@
> >> +// 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/debugfs.h>
> >> +#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>
> >> +
> >> +#define TO_MS(timestamp) ((timestamp * 1000) / 32768)
> >
> > Quoting v4 question, which got no answer:
> >
> > Some of the platforms DTs define 32KHz clock instead of 32.768 KHz
> > What should be the divisor in this case?
>
> This is the standard divisor used to calculate the pre_abl and abl times
> across most QCOM SoCs. Can you give an example where the sleep_stat
> counter has a different frequency?

Following SoCs declare 37000 as sleep_clk frequency:
ipq6018, qdu1000, qru1000, sc7280, sm6125, sm6375, sm8350, sm8450, sm8550.

This might be an error in the dtsi, or might be not.

>
> >
> >> +
> >> +/**
> >> + *  struct boot_stats - timestamp information related to boot stats
> >> + *  @abl_start: Time for the starting point of the abl
> >> + *  @abl_end: Time when the kernel starts loading from abl
> >> + */
> >> +struct boot_stats {
> >> +       u32 abl_start;
> >> +       u32 abl_end;
> >> +} __packed;
> >> +
> >> +struct bs_data {
> >> +       struct boot_stats __iomem *b_stats;
> >> +       struct dentry *dbg_dir;
> >> +};
> >> +
> >> +static void populate_boot_stats(char *abl_str, char *pre_abl_str, struct bs_data *drvdata)
> >> +{
> >> +        u32 abl_time, pre_abl_time;
> >> +
> >> +        abl_time = TO_MS(drvdata->b_stats->abl_end) - TO_MS(drvdata->b_stats->abl_start);
> >> +        sprintf(abl_str, "%u ms", abl_time);
> >> +
> >> +        pre_abl_time =  TO_MS(drvdata->b_stats->abl_start);
> >> +        sprintf(pre_abl_str, "%u ms", pre_abl_time);
> >
> > Another point from v4:
> >
> > It would be better to move the unit to the file name and include just
> > the number.
>
> Clarified from your first comment
>
> >
> >> +}
> >> +
> >> +static int boot_stats_probe(struct platform_device *pdev)
> >> +{
> >> +       char abl_str[20], pre_abl_str[20], *abl, *pre_abl;
> >> +       struct device *bootstat_dev = &pdev->dev;
> >> +       struct bs_data *drvdata;
> >> +
> >> +       drvdata = devm_kzalloc(bootstat_dev, sizeof(*drvdata), GFP_KERNEL);
> >> +       if (!drvdata)
> >> +               return dev_err_probe(bootstat_dev, -ENOMEM, "failed to allocate memory");
> >> +       platform_set_drvdata(pdev, drvdata);
> >> +
> >> +       drvdata->b_stats = devm_of_iomap(bootstat_dev, bootstat_dev->of_node, 0, NULL);
> >> +       if (IS_ERR(drvdata->b_stats))
> >> +               return dev_err_probe(bootstat_dev, PTR_ERR(drvdata->b_stats),
> >> +                                    "failed to map imem region");
> >> +
> >> +       drvdata->dbg_dir = debugfs_create_dir("qcom_boot_stats", NULL);
> >> +       if (IS_ERR(drvdata->dbg_dir))
> >> +               return dev_err_probe(bootstat_dev, PTR_ERR(drvdata->dbg_dir),
> >> +                                    "failed to create debugfs directory");
> >> +
> >> +       populate_boot_stats(abl_str, pre_abl_str, drvdata);
> >> +       abl = abl_str;
> >> +       pre_abl = pre_abl_str;
> >> +
> >> +       debugfs_create_str("pre_abl_time", 0400, drvdata->dbg_dir, (char **)&pre_abl);
> >> +       debugfs_create_str("abl_time", 0400, drvdata->dbg_dir, (char **)&abl);
> >> +
> >> +       return 0;
> >> +}
> >> +
> >> +void boot_stats_remove(struct platform_device *pdev)
> >> +{
> >> +       struct bs_data *drvdata = platform_get_drvdata(pdev);
> >> +
> >> +       debugfs_remove_recursive(drvdata->dbg_dir);
> >> +}
> >> +
> >> +static const struct of_device_id boot_stats_dt_match[] = {
> >> +       { .compatible = "qcom,imem-bootstats" },
> >> +       { }
> >> +};
> >> +MODULE_DEVICE_TABLE(of, boot_stats_dt_match);
> >> +
> >> +static struct platform_driver boot_stat_driver = {
> >> +       .probe  = boot_stats_probe,
> >> +       .remove_new = 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");
> >> --
> >> 2.17.1
> >>
> >
> >



-- 
With best wishes
Dmitry



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux