mbox series

[V1,0/4] soc: qcom: boot_stats: Add driver support for boot_stats

Message ID cover.1679403696.git.quic_schowdhu@quicinc.com
Headers show
Series soc: qcom: boot_stats: Add driver support for boot_stats | expand

Message

Souradeep Chowdhury March 21, 2023, 1:51 p.m. UTC
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 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 these
values are read up by the driver from IMEM region and printed as above.
The current sleep counter timestamp is also logged by the driver.

Souradeep Chowdhury (4):
  dt-bindings: sram: qcom,imem: Add Boot Stat region within IMEM
  dt-bindings: soc: qcom,mpm-sleep-counter: Add the dtschema
  soc: qcom: boot_stat: Add Driver Support for Boot Stats
  MAINTAINERS: Add the entry for boot_stats driver support

 .../bindings/soc/qcom/qcom,mpm-sleep-counter.yaml  |  40 ++++++++
 .../devicetree/bindings/sram/qcom,imem.yaml        |  20 ++++
 MAINTAINERS                                        |   7 ++
 drivers/soc/qcom/Kconfig                           |   7 ++
 drivers/soc/qcom/Makefile                          |   1 +
 drivers/soc/qcom/boot_stats.c                      | 108 +++++++++++++++++++++
 6 files changed, 183 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,mpm-sleep-counter.yaml
 create mode 100644 drivers/soc/qcom/boot_stats.c

Comments

Krzysztof Kozlowski March 21, 2023, 5:37 p.m. UTC | #1
On 21/03/2023 14:51, Souradeep Chowdhury wrote:
> 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 regre


> +/**
> + *  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;

No file-scope variables. Does not scale, not easy for review and
maintenance. Avoid such code.

> +
> +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");

So you are printing errors everywhere, on every soc and with compile
test on every platform there is in the world... sorry, it does not work
like that.

> +		return -ENODEV;
> +	}
> +	boot_stats = of_iomap(np_imem, 0);
> +	if (!boot_stats) {
> +		pr_err("boot_stats: Can't map imem\n");
> +		goto err1;
> +	}


> +
> +static void __exit boot_stats_exit(void)
> +{
> +}
> +module_exit(boot_stats_exit)


I don't think this is some special code which deserves init calls. Make
it module_platform_driver().


Best regards,
Krzysztof
Souradeep Chowdhury March 22, 2023, 1:54 p.m. UTC | #2
On 3/21/2023 11:07 PM, Krzysztof Kozlowski wrote:
> On 21/03/2023 14:51, Souradeep Chowdhury wrote:
>> 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 regre
> 
> 
>> +/**
>> + *  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;
> 
> No file-scope variables. Does not scale, not easy for review and
> maintenance. Avoid such code.

Ack
> 
>> +
>> +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");
> 
> So you are printing errors everywhere, on every soc and with compile
> test on every platform there is in the world... sorry, it does not work
> like that.

Ack
> 
>> +		return -ENODEV;
>> +	}
>> +	boot_stats = of_iomap(np_imem, 0);
>> +	if (!boot_stats) {
>> +		pr_err("boot_stats: Can't map imem\n");
>> +		goto err1;
>> +	}
> 
> 
>> +
>> +static void __exit boot_stats_exit(void)
>> +{
>> +}
>> +module_exit(boot_stats_exit)
> 
> 
> I don't think this is some special code which deserves init calls. Make
> it module_platform_driver().

Since this just reads some values from the Imem region and prints it to 
the user and doesn't have a specific device associated with it, a 
generic module code is written for it and not a module_platform_driver().

> 
> 
> Best regards,
> Krzysztof
>
Krzysztof Kozlowski March 22, 2023, 2:53 p.m. UTC | #3
On 22/03/2023 14:54, Souradeep Chowdhury wrote:
> 
> 
> On 3/21/2023 11:07 PM, Krzysztof Kozlowski wrote:
>> On 21/03/2023 14:51, Souradeep Chowdhury wrote:
>>> 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 regre
>>
>>
>>> +/**
>>> + *  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;
>>
>> No file-scope variables. Does not scale, not easy for review and
>> maintenance. Avoid such code.
> 
> Ack
>>
>>> +
>>> +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");
>>
>> So you are printing errors everywhere, on every soc and with compile
>> test on every platform there is in the world... sorry, it does not work
>> like that.
> 
> Ack
>>
>>> +		return -ENODEV;
>>> +	}
>>> +	boot_stats = of_iomap(np_imem, 0);
>>> +	if (!boot_stats) {
>>> +		pr_err("boot_stats: Can't map imem\n");
>>> +		goto err1;
>>> +	}
>>
>>
>>> +
>>> +static void __exit boot_stats_exit(void)
>>> +{
>>> +}
>>> +module_exit(boot_stats_exit)
>>
>>
>> I don't think this is some special code which deserves init calls. Make
>> it module_platform_driver().
> 
> Since this just reads some values from the Imem region and prints it to 
> the user and doesn't have a specific device associated with it, a 

Which is not really an argument for such antipattern, but okay...

> generic module code is written for it and not a module_platform_driver().

... so how do you handle deferred probe?

Best regards,
Krzysztof
Souradeep Chowdhury March 23, 2023, 1:45 p.m. UTC | #4
On 3/22/2023 8:23 PM, Krzysztof Kozlowski wrote:
> On 22/03/2023 14:54, Souradeep Chowdhury wrote:
>>
>>
>> On 3/21/2023 11:07 PM, Krzysztof Kozlowski wrote:
>>> On 21/03/2023 14:51, Souradeep Chowdhury wrote:
>>>> 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 regre
>>>
>>>
>>>> +/**
>>>> + *  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;
>>>
>>> No file-scope variables. Does not scale, not easy for review and
>>> maintenance. Avoid such code.
>>
>> Ack
>>>
>>>> +
>>>> +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");
>>>
>>> So you are printing errors everywhere, on every soc and with compile
>>> test on every platform there is in the world... sorry, it does not work
>>> like that.
>>
>> Ack
>>>
>>>> +		return -ENODEV;
>>>> +	}
>>>> +	boot_stats = of_iomap(np_imem, 0);
>>>> +	if (!boot_stats) {
>>>> +		pr_err("boot_stats: Can't map imem\n");
>>>> +		goto err1;
>>>> +	}
>>>
>>>
>>>> +
>>>> +static void __exit boot_stats_exit(void)
>>>> +{
>>>> +}
>>>> +module_exit(boot_stats_exit)
>>>
>>>
>>> I don't think this is some special code which deserves init calls. Make
>>> it module_platform_driver().
>>
>> Since this just reads some values from the Imem region and prints it to
>> the user and doesn't have a specific device associated with it, a
> 
> Which is not really an argument for such antipattern, but okay...
> 
>> generic module code is written for it and not a module_platform_driver().
> 
> ... so how do you handle deferred probe?

This has no dependency on other resources except that it parses some 
information from DT nodes, so deferred probe handling is not needed
in this case.

> 
> Best regards,
> Krzysztof
>
Krzysztof Kozlowski March 24, 2023, 8:56 a.m. UTC | #5
On 23/03/2023 14:45, Souradeep Chowdhury wrote:
> 
> 
> On 3/22/2023 8:23 PM, Krzysztof Kozlowski wrote:
>> On 22/03/2023 14:54, Souradeep Chowdhury wrote:
>>>
>>>
>>> On 3/21/2023 11:07 PM, Krzysztof Kozlowski wrote:
>>>> On 21/03/2023 14:51, Souradeep Chowdhury wrote:
>>>>> 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 regre
>>>>
>>>>
>>>>> +/**
>>>>> + *  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;
>>>>
>>>> No file-scope variables. Does not scale, not easy for review and
>>>> maintenance. Avoid such code.
>>>
>>> Ack
>>>>
>>>>> +
>>>>> +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");
>>>>
>>>> So you are printing errors everywhere, on every soc and with compile
>>>> test on every platform there is in the world... sorry, it does not work
>>>> like that.
>>>
>>> Ack
>>>>
>>>>> +		return -ENODEV;
>>>>> +	}
>>>>> +	boot_stats = of_iomap(np_imem, 0);
>>>>> +	if (!boot_stats) {
>>>>> +		pr_err("boot_stats: Can't map imem\n");
>>>>> +		goto err1;
>>>>> +	}
>>>>
>>>>
>>>>> +
>>>>> +static void __exit boot_stats_exit(void)
>>>>> +{
>>>>> +}
>>>>> +module_exit(boot_stats_exit)
>>>>
>>>>
>>>> I don't think this is some special code which deserves init calls. Make
>>>> it module_platform_driver().
>>>
>>> Since this just reads some values from the Imem region and prints it to
>>> the user and doesn't have a specific device associated with it, a
>>
>> Which is not really an argument for such antipattern, but okay...
>>
>>> generic module code is written for it and not a module_platform_driver().
>>
>> ... so how do you handle deferred probe?
> 
> This has no dependency on other resources except that it parses some 
> information from DT nodes, so deferred probe handling is not needed
> in this case.

Yes, I know, but if we would ever add it how this driver can handle it?
This is antipattern.

Best regards,
Krzysztof