* [PATCH] ACPI: platform_profile: Optimize _aggregate_choices()
@ 2025-03-22 21:03 Kurt Borja
2025-03-24 14:25 ` Mario Limonciello
2025-03-25 19:36 ` Armin Wolf
0 siblings, 2 replies; 4+ messages in thread
From: Kurt Borja @ 2025-03-22 21:03 UTC (permalink / raw)
To: Rafael J. Wysocki, Ilpo Järvinen, Mark Pearson
Cc: Mario Limonciello, Armin Wolf, Len Brown, linux-acpi,
linux-kernel, Kurt Borja
Choices aggregates passed to _aggregate_choices() are already filled
with ones, therefore we can avoid copying a new bitmap on the first
iteration.
This makes setting the PLATFORM_PROFILE_LAST bit on aggregates
unnecessary, so drop it as well.
While at it, add a couple empty lines to improve style.
Signed-off-by: Kurt Borja <kuurtb@gmail.com>
---
drivers/acpi/platform_profile.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
index ef9444482db1982b19d2a17884e1c3ab0e5cb55c..b5b24b075af6dfa612d56eb95342c6af87a60d3e 100644
--- a/drivers/acpi/platform_profile.c
+++ b/drivers/acpi/platform_profile.c
@@ -256,12 +256,10 @@ static int _aggregate_choices(struct device *dev, void *arg)
struct platform_profile_handler *handler;
lockdep_assert_held(&profile_lock);
+
handler = to_pprof_handler(dev);
bitmap_or(tmp, handler->choices, handler->hidden_choices, PLATFORM_PROFILE_LAST);
- if (test_bit(PLATFORM_PROFILE_LAST, data->aggregate))
- bitmap_copy(data->aggregate, tmp, PLATFORM_PROFILE_LAST);
- else
- bitmap_and(data->aggregate, tmp, data->aggregate, PLATFORM_PROFILE_LAST);
+ bitmap_and(data->aggregate, tmp, data->aggregate, PLATFORM_PROFILE_LAST);
data->count++;
return 0;
@@ -305,7 +303,6 @@ static ssize_t platform_profile_choices_show(struct device *dev,
};
int err;
- set_bit(PLATFORM_PROFILE_LAST, data.aggregate);
scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
err = class_for_each_device(&platform_profile_class, NULL,
&data, _aggregate_choices);
@@ -422,7 +419,7 @@ static ssize_t platform_profile_store(struct device *dev,
i = sysfs_match_string(profile_names, buf);
if (i < 0 || i == PLATFORM_PROFILE_CUSTOM)
return -EINVAL;
- set_bit(PLATFORM_PROFILE_LAST, data.aggregate);
+
scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
ret = class_for_each_device(&platform_profile_class, NULL,
&data, _aggregate_choices);
@@ -502,7 +499,6 @@ int platform_profile_cycle(void)
enum platform_profile_option profile = PLATFORM_PROFILE_LAST;
int err;
- set_bit(PLATFORM_PROFILE_LAST, data.aggregate);
scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
err = class_for_each_device(&platform_profile_class, NULL,
&profile, _aggregate_profiles);
---
base-commit: 9a43102daf64dd0d172d8b39836dbc1dba4da1ea
change-id: 20250322-pprof-opt-caa7f7f349b8
Best regards,
--
Kurt Borja <kuurtb@gmail.com>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ACPI: platform_profile: Optimize _aggregate_choices()
2025-03-22 21:03 [PATCH] ACPI: platform_profile: Optimize _aggregate_choices() Kurt Borja
@ 2025-03-24 14:25 ` Mario Limonciello
2025-03-25 19:36 ` Armin Wolf
1 sibling, 0 replies; 4+ messages in thread
From: Mario Limonciello @ 2025-03-24 14:25 UTC (permalink / raw)
To: Kurt Borja, Rafael J. Wysocki, Ilpo Järvinen, Mark Pearson
Cc: Armin Wolf, Len Brown, linux-acpi, linux-kernel
On 3/22/2025 16:03, Kurt Borja wrote:
> Choices aggregates passed to _aggregate_choices() are already filled
> with ones, therefore we can avoid copying a new bitmap on the first
> iteration.
>
> This makes setting the PLATFORM_PROFILE_LAST bit on aggregates
> unnecessary, so drop it as well.
>
> While at it, add a couple empty lines to improve style.
>
> Signed-off-by: Kurt Borja <kuurtb@gmail.com>
Good find! This optimization is valid because of the changes in
commit 778b94d7ac17b ("ACPI: platform_profile: Add support for hidden
choices")
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> drivers/acpi/platform_profile.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
> index ef9444482db1982b19d2a17884e1c3ab0e5cb55c..b5b24b075af6dfa612d56eb95342c6af87a60d3e 100644
> --- a/drivers/acpi/platform_profile.c
> +++ b/drivers/acpi/platform_profile.c
> @@ -256,12 +256,10 @@ static int _aggregate_choices(struct device *dev, void *arg)
> struct platform_profile_handler *handler;
>
> lockdep_assert_held(&profile_lock);
> +
> handler = to_pprof_handler(dev);
> bitmap_or(tmp, handler->choices, handler->hidden_choices, PLATFORM_PROFILE_LAST);
> - if (test_bit(PLATFORM_PROFILE_LAST, data->aggregate))
> - bitmap_copy(data->aggregate, tmp, PLATFORM_PROFILE_LAST);
> - else
> - bitmap_and(data->aggregate, tmp, data->aggregate, PLATFORM_PROFILE_LAST);
> + bitmap_and(data->aggregate, tmp, data->aggregate, PLATFORM_PROFILE_LAST);
> data->count++;
>
> return 0;
> @@ -305,7 +303,6 @@ static ssize_t platform_profile_choices_show(struct device *dev,
> };
> int err;
>
> - set_bit(PLATFORM_PROFILE_LAST, data.aggregate);
> scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
> err = class_for_each_device(&platform_profile_class, NULL,
> &data, _aggregate_choices);
> @@ -422,7 +419,7 @@ static ssize_t platform_profile_store(struct device *dev,
> i = sysfs_match_string(profile_names, buf);
> if (i < 0 || i == PLATFORM_PROFILE_CUSTOM)
> return -EINVAL;
> - set_bit(PLATFORM_PROFILE_LAST, data.aggregate);
> +
> scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
> ret = class_for_each_device(&platform_profile_class, NULL,
> &data, _aggregate_choices);
> @@ -502,7 +499,6 @@ int platform_profile_cycle(void)
> enum platform_profile_option profile = PLATFORM_PROFILE_LAST;
> int err;
>
> - set_bit(PLATFORM_PROFILE_LAST, data.aggregate);
> scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
> err = class_for_each_device(&platform_profile_class, NULL,
> &profile, _aggregate_profiles);
>
> ---
> base-commit: 9a43102daf64dd0d172d8b39836dbc1dba4da1ea
> change-id: 20250322-pprof-opt-caa7f7f349b8
>
> Best regards,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ACPI: platform_profile: Optimize _aggregate_choices()
2025-03-22 21:03 [PATCH] ACPI: platform_profile: Optimize _aggregate_choices() Kurt Borja
2025-03-24 14:25 ` Mario Limonciello
@ 2025-03-25 19:36 ` Armin Wolf
2025-03-25 20:06 ` Kurt Borja
1 sibling, 1 reply; 4+ messages in thread
From: Armin Wolf @ 2025-03-25 19:36 UTC (permalink / raw)
To: Kurt Borja, Rafael J. Wysocki, Ilpo Järvinen, Mark Pearson
Cc: Mario Limonciello, Len Brown, linux-acpi, linux-kernel
Am 22.03.25 um 22:03 schrieb Kurt Borja:
> Choices aggregates passed to _aggregate_choices() are already filled
> with ones, therefore we can avoid copying a new bitmap on the first
> iteration.
>
> This makes setting the PLATFORM_PROFILE_LAST bit on aggregates
> unnecessary, so drop it as well.
>
> While at it, add a couple empty lines to improve style.
>
Please add a comment to signal future developers that the bitmap needs to be filled with ones
before being passed to _aggregate_choices().
With this being addressed:
Reviewed-by: Armin Wolf <W_Armin@gmx.de>
> Signed-off-by: Kurt Borja <kuurtb@gmail.com>
> ---
> drivers/acpi/platform_profile.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
> index ef9444482db1982b19d2a17884e1c3ab0e5cb55c..b5b24b075af6dfa612d56eb95342c6af87a60d3e 100644
> --- a/drivers/acpi/platform_profile.c
> +++ b/drivers/acpi/platform_profile.c
> @@ -256,12 +256,10 @@ static int _aggregate_choices(struct device *dev, void *arg)
> struct platform_profile_handler *handler;
>
> lockdep_assert_held(&profile_lock);
> +
> handler = to_pprof_handler(dev);
> bitmap_or(tmp, handler->choices, handler->hidden_choices, PLATFORM_PROFILE_LAST);
> - if (test_bit(PLATFORM_PROFILE_LAST, data->aggregate))
> - bitmap_copy(data->aggregate, tmp, PLATFORM_PROFILE_LAST);
> - else
> - bitmap_and(data->aggregate, tmp, data->aggregate, PLATFORM_PROFILE_LAST);
> + bitmap_and(data->aggregate, tmp, data->aggregate, PLATFORM_PROFILE_LAST);
> data->count++;
>
> return 0;
> @@ -305,7 +303,6 @@ static ssize_t platform_profile_choices_show(struct device *dev,
> };
> int err;
>
> - set_bit(PLATFORM_PROFILE_LAST, data.aggregate);
> scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
> err = class_for_each_device(&platform_profile_class, NULL,
> &data, _aggregate_choices);
> @@ -422,7 +419,7 @@ static ssize_t platform_profile_store(struct device *dev,
> i = sysfs_match_string(profile_names, buf);
> if (i < 0 || i == PLATFORM_PROFILE_CUSTOM)
> return -EINVAL;
> - set_bit(PLATFORM_PROFILE_LAST, data.aggregate);
> +
> scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
> ret = class_for_each_device(&platform_profile_class, NULL,
> &data, _aggregate_choices);
> @@ -502,7 +499,6 @@ int platform_profile_cycle(void)
> enum platform_profile_option profile = PLATFORM_PROFILE_LAST;
> int err;
>
> - set_bit(PLATFORM_PROFILE_LAST, data.aggregate);
> scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &profile_lock) {
> err = class_for_each_device(&platform_profile_class, NULL,
> &profile, _aggregate_profiles);
>
> ---
> base-commit: 9a43102daf64dd0d172d8b39836dbc1dba4da1ea
> change-id: 20250322-pprof-opt-caa7f7f349b8
>
> Best regards,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ACPI: platform_profile: Optimize _aggregate_choices()
2025-03-25 19:36 ` Armin Wolf
@ 2025-03-25 20:06 ` Kurt Borja
0 siblings, 0 replies; 4+ messages in thread
From: Kurt Borja @ 2025-03-25 20:06 UTC (permalink / raw)
To: Armin Wolf, Rafael J. Wysocki, Ilpo Järvinen, Mark Pearson
Cc: Mario Limonciello, Len Brown, linux-acpi, linux-kernel
On Tue Mar 25, 2025 at 4:36 PM -03, Armin Wolf wrote:
> Am 22.03.25 um 22:03 schrieb Kurt Borja:
>
>> Choices aggregates passed to _aggregate_choices() are already filled
>> with ones, therefore we can avoid copying a new bitmap on the first
>> iteration.
>>
>> This makes setting the PLATFORM_PROFILE_LAST bit on aggregates
>> unnecessary, so drop it as well.
>>
>> While at it, add a couple empty lines to improve style.
>>
> Please add a comment to signal future developers that the bitmap needs to be filled with ones
> before being passed to _aggregate_choices().
Sure, I'll mention it in the kernel-doc for v2.
>
> With this being addressed:
>
> Reviewed-by: Armin Wolf <W_Armin@gmx.de>
Thank you Mario and Armin for the reviews!
--
~ Kurt
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-25 20:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-22 21:03 [PATCH] ACPI: platform_profile: Optimize _aggregate_choices() Kurt Borja
2025-03-24 14:25 ` Mario Limonciello
2025-03-25 19:36 ` Armin Wolf
2025-03-25 20:06 ` Kurt Borja
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox