2020-08-04 14:16:13

by Gaurav Kohli

[permalink] [raw]
Subject: [PATCH] arm64: Skip apply SSBS call for non SSBS system

In a system where no cpu's implement SSBS, for
them no need to set pstate. This might help to save
few cpu cycles during context switch.

Signed-off-by: Gaurav Kohli <[email protected]>

diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 6089638..79f80f1 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -477,6 +477,13 @@ static void ssbs_thread_switch(struct task_struct *next)
struct pt_regs *regs = task_pt_regs(next);

/*
+ * For Targets which don't have SSBS support, they
+ * can return from here.
+ */
+ if (!IS_ENABLED(CONFIG_ARM64_SSBD))
+ return;
+
+ /*
* Nothing to do for kernel threads, but 'regs' may be junk
* (e.g. idle task) so check the flags and bail early.
*/
--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center,
Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project


2020-08-04 14:20:10

by Gaurav Kohli

[permalink] [raw]
Subject: [PATCH] nvmem: core: add support to NVMEM_NO_SYSFS_ENTRY

From: Srinivas Kandagatla <[email protected]>

Some users might not want to expose nvmem entry to sysfs and
only intend to use kernel interface so add such provision.

Signed-off-by: Srinivas Kandagatla <[email protected]>
---
Documentation/ABI/stable/sysfs-bus-nvmem | 2 ++
drivers/nvmem/Kconfig | 5 +++++
drivers/nvmem/core.c | 11 ++++++-----
3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/Documentation/ABI/stable/sysfs-bus-nvmem
b/Documentation/ABI/stable/sysfs-bus-nvmem
index 5923ab4620c5..12aab0a85fea 100644
--- a/Documentation/ABI/stable/sysfs-bus-nvmem
+++ b/Documentation/ABI/stable/sysfs-bus-nvmem
@@ -6,6 +6,8 @@ Description:
This file allows user to read/write the raw NVMEM contents.
Permissions for write to this file depends on the nvmem
provider configuration.
+ Note: This file is not present if CONFIG_NVMEM_NO_SYSFS_ENTRY
+ is enabled

ex:
hexdump /sys/bus/nvmem/devices/qfprom0/nvmem
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index 0a7a470ee859..6ab3276d287c 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -192,4 +192,9 @@ config SC27XX_EFUSE
This driver can also be built as a module. If so, the module
will be called nvmem-sc27xx-efuse.

+config NVMEM_NO_SYSFS_ENTRY
+ bool "No nvmem sysfs entry"
+
+ help
+ Say Yes if you do not want to add nvmem entry to sysfs.
endif
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index b9a0270883a0..c70f183fe379 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -216,7 +216,7 @@ static const struct attribute_group
nvmem_bin_rw_group = {
.attrs = nvmem_attrs,
};

-static const struct attribute_group *nvmem_rw_dev_groups[] = {
+static const __maybe_unused struct attribute_group
*nvmem_rw_dev_groups[] = {
&nvmem_bin_rw_group,
NULL,
};
@@ -240,7 +240,7 @@ static const struct attribute_group
nvmem_bin_ro_group = {
.attrs = nvmem_attrs,
};

-static const struct attribute_group *nvmem_ro_dev_groups[] = {
+static const __maybe_unused struct attribute_group
*nvmem_ro_dev_groups[] = {
&nvmem_bin_ro_group,
NULL,
};
@@ -265,7 +265,7 @@ static const struct attribute_group
nvmem_bin_rw_root_group = {
.attrs = nvmem_attrs,
};

-static const struct attribute_group *nvmem_rw_root_dev_groups[] = {
+static const __maybe_unused struct attribute_group
*nvmem_rw_root_dev_groups[] = {
&nvmem_bin_rw_root_group,
NULL,
};
@@ -289,7 +289,7 @@ static const struct attribute_group
nvmem_bin_ro_root_group = {
.attrs = nvmem_attrs,
};

-static const struct attribute_group *nvmem_ro_root_dev_groups[] = {
+static const __maybe_unused struct attribute_group
*nvmem_ro_root_dev_groups[] = {
&nvmem_bin_ro_root_group,
NULL,
};
@@ -688,6 +688,7 @@ struct nvmem_device *nvmem_register(const struct
nvmem_config *config)
nvmem->read_only = device_property_present(config->dev, "read-only") |
config->read_only;

+#if !defined(CONFIG_NVMEM_NO_SYSFS_ENTRY)
if (config->root_only)
nvmem->dev.groups = nvmem->read_only ?
nvmem_ro_root_dev_groups :
@@ -696,7 +697,7 @@ struct nvmem_device *nvmem_register(const struct
nvmem_config *config)
nvmem->dev.groups = nvmem->read_only ?
nvmem_ro_dev_groups :
nvmem_rw_dev_groups;
-
+#endif
device_initialize(&nvmem->dev);

dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name);
--
2.21.0

2020-08-04 14:26:57

by Gaurav Kohli

[permalink] [raw]
Subject: Re: [PATCH] nvmem: core: add support to NVMEM_NO_SYSFS_ENTRY

Please ignore this patch, some problem in my git send mail.
Apologies for the spam.


On 8/4/2020 7:44 PM, Gaurav Kohli wrote:
> From: Srinivas Kandagatla <[email protected]>
>
> Some users might not want to expose nvmem entry to sysfs and
> only intend to use kernel interface so add such provision.
>
> Signed-off-by: Srinivas Kandagatla <[email protected]>
> ---
> Documentation/ABI/stable/sysfs-bus-nvmem | 2 ++
> drivers/nvmem/Kconfig | 5 +++++
> drivers/nvmem/core.c | 11 ++++++-----
> 3 files changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/ABI/stable/sysfs-bus-nvmem
> b/Documentation/ABI/stable/sysfs-bus-nvmem
> index 5923ab4620c5..12aab0a85fea 100644
> --- a/Documentation/ABI/stable/sysfs-bus-nvmem
> +++ b/Documentation/ABI/stable/sysfs-bus-nvmem
> @@ -6,6 +6,8 @@ Description:
> This file allows user to read/write the raw NVMEM contents.
> Permissions for write to this file depends on the nvmem
> provider configuration.
> + Note: This file is not present if CONFIG_NVMEM_NO_SYSFS_ENTRY
> + is enabled
>
> ex:
> hexdump /sys/bus/nvmem/devices/qfprom0/nvmem
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index 0a7a470ee859..6ab3276d287c 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -192,4 +192,9 @@ config SC27XX_EFUSE
> This driver can also be built as a module. If so, the module
> will be called nvmem-sc27xx-efuse.
>
> +config NVMEM_NO_SYSFS_ENTRY
> + bool "No nvmem sysfs entry"
> +
> + help
> + Say Yes if you do not want to add nvmem entry to sysfs.
> endif
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index b9a0270883a0..c70f183fe379 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -216,7 +216,7 @@ static const struct attribute_group
> nvmem_bin_rw_group = {
> .attrs = nvmem_attrs,
> };
>
> -static const struct attribute_group *nvmem_rw_dev_groups[] = {
> +static const __maybe_unused struct attribute_group
> *nvmem_rw_dev_groups[] = {
> &nvmem_bin_rw_group,
> NULL,
> };
> @@ -240,7 +240,7 @@ static const struct attribute_group
> nvmem_bin_ro_group = {
> .attrs = nvmem_attrs,
> };
>
> -static const struct attribute_group *nvmem_ro_dev_groups[] = {
> +static const __maybe_unused struct attribute_group
> *nvmem_ro_dev_groups[] = {
> &nvmem_bin_ro_group,
> NULL,
> };
> @@ -265,7 +265,7 @@ static const struct attribute_group
> nvmem_bin_rw_root_group = {
> .attrs = nvmem_attrs,
> };
>
> -static const struct attribute_group *nvmem_rw_root_dev_groups[] = {
> +static const __maybe_unused struct attribute_group
> *nvmem_rw_root_dev_groups[] = {
> &nvmem_bin_rw_root_group,
> NULL,
> };
> @@ -289,7 +289,7 @@ static const struct attribute_group
> nvmem_bin_ro_root_group = {
> .attrs = nvmem_attrs,
> };
>
> -static const struct attribute_group *nvmem_ro_root_dev_groups[] = {
> +static const __maybe_unused struct attribute_group
> *nvmem_ro_root_dev_groups[] = {
> &nvmem_bin_ro_root_group,
> NULL,
> };
> @@ -688,6 +688,7 @@ struct nvmem_device *nvmem_register(const struct
> nvmem_config *config)
> nvmem->read_only = device_property_present(config->dev, "read-only") |
> config->read_only;
>
> +#if !defined(CONFIG_NVMEM_NO_SYSFS_ENTRY)
> if (config->root_only)
> nvmem->dev.groups = nvmem->read_only ?
> nvmem_ro_root_dev_groups :
> @@ -696,7 +697,7 @@ struct nvmem_device *nvmem_register(const struct
> nvmem_config *config)
> nvmem->dev.groups = nvmem->read_only ?
> nvmem_ro_dev_groups :
> nvmem_rw_dev_groups;
> -
> +#endif
> device_initialize(&nvmem->dev);
>
> dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name);
>

--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center,
Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.

2020-08-11 04:50:02

by Gaurav Kohli

[permalink] [raw]
Subject: Re: [PATCH] arm64: Skip apply SSBS call for non SSBS system

Hi,

Please let us know, is below patch good to have
or not for non ssbs systems.

On 8/4/2020 7:44 PM, Gaurav Kohli wrote:
> In a system where no cpu's implement SSBS, for
> them no need to set pstate. This might help to save
> few cpu cycles during context switch.
>
> Signed-off-by: Gaurav Kohli <[email protected]>
>
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index 6089638..79f80f1 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -477,6 +477,13 @@ static void ssbs_thread_switch(struct task_struct *next)
> struct pt_regs *regs = task_pt_regs(next);
>
> /*
> + * For Targets which don't have SSBS support, they
> + * can return from here.
> + */
> + if (!IS_ENABLED(CONFIG_ARM64_SSBD))
> + return;
> +
> + /*
> * Nothing to do for kernel threads, but 'regs' may be junk
> * (e.g. idle task) so check the flags and bail early.
> */
>

--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center,
Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.

2020-08-12 13:32:02

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH] arm64: Skip apply SSBS call for non SSBS system

On Tue, Aug 04, 2020 at 07:44:42PM +0530, Gaurav Kohli wrote:
> In a system where no cpu's implement SSBS, for
> them no need to set pstate. This might help to save
> few cpu cycles during context switch.
>
> Signed-off-by: Gaurav Kohli <[email protected]>
>
> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
> index 6089638..79f80f1 100644
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -477,6 +477,13 @@ static void ssbs_thread_switch(struct task_struct *next)
> struct pt_regs *regs = task_pt_regs(next);
>
> /*
> + * For Targets which don't have SSBS support, they
> + * can return from here.
> + */
> + if (!IS_ENABLED(CONFIG_ARM64_SSBD))
> + return;

Does this actually make a measurable difference?

Will

2020-08-12 14:20:09

by Gaurav Kohli

[permalink] [raw]
Subject: Re: [PATCH] arm64: Skip apply SSBS call for non SSBS system



On 8/12/2020 7:00 PM, Will Deacon wrote:
> On Tue, Aug 04, 2020 at 07:44:42PM +0530, Gaurav Kohli wrote:
>> In a system where no cpu's implement SSBS, for
>> them no need to set pstate. This might help to save
>> few cpu cycles during context switch.
>>
>> Signed-off-by: Gaurav Kohli <[email protected]>
>>
>> diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
>> index 6089638..79f80f1 100644
>> --- a/arch/arm64/kernel/process.c
>> +++ b/arch/arm64/kernel/process.c
>> @@ -477,6 +477,13 @@ static void ssbs_thread_switch(struct task_struct *next)
>> struct pt_regs *regs = task_pt_regs(next);
>>
>> /*
>> + * For Targets which don't have SSBS support, they
>> + * can return from here.
>> + */
>> + if (!IS_ENABLED(CONFIG_ARM64_SSBD))
>> + return;
>
> Does this actually make a measurable difference?
>
> Will
>

Hi Will,

While doing code review between older kernel and latest kernel for
context switch case, there i have found this and thought it is good to
have for non-ssbs system to return early(as this might improve).

Please let me know if you want to run some tests.

Regards
Gaurav