* [PATCH] cpufreq: stats: Improve the performance of cpufreq_stats_create_table()
@ 2023-08-18 9:50 Liao Chang
2023-08-21 6:52 ` Viresh Kumar
2023-08-21 9:13 ` Dhruva Gole
0 siblings, 2 replies; 4+ messages in thread
From: Liao Chang @ 2023-08-18 9:50 UTC (permalink / raw)
To: rafael, viresh.kumar; +Cc: linux-pm, linux-kernel
In the worst case, the freq_table of policy data is not sorted and
contains duplicate frequencies, this means that it needs to iterate
through the entire freq_table of policy to ensure each frequency is
unique in the freq_table of stats data, this has a time complexity of
O(N^2), where N is the number of frequencies in the freq_table of
policy.
However, if the policy.freq_table is already sorted and contains no
duplicate frequencices, it can reduce the time complexity of creating
stats.freq_table to O(N), the 'freq_table_sorted' field of policy data
can be used to indicate whether the policy.freq_table is sorted.
Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
drivers/cpufreq/cpufreq_stats.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 55c7ffd37d1c..fcb74050711a 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -243,7 +243,8 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy)
/* Find valid-unique entries */
cpufreq_for_each_valid_entry(pos, policy->freq_table)
- if (freq_table_get_index(stats, pos->frequency) == -1)
+ if ((policy->freq_table_sorted != CPUFREQ_TABLE_UNSORTED) ||
+ (freq_table_get_index(stats, pos->frequency) == -1))
stats->freq_table[i++] = pos->frequency;
stats->state_num = i;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] cpufreq: stats: Improve the performance of cpufreq_stats_create_table()
2023-08-18 9:50 [PATCH] cpufreq: stats: Improve the performance of cpufreq_stats_create_table() Liao Chang
@ 2023-08-21 6:52 ` Viresh Kumar
2023-08-21 9:13 ` Dhruva Gole
1 sibling, 0 replies; 4+ messages in thread
From: Viresh Kumar @ 2023-08-21 6:52 UTC (permalink / raw)
To: Liao Chang; +Cc: rafael, linux-pm, linux-kernel
On 18-08-23, 09:50, Liao Chang wrote:
> In the worst case, the freq_table of policy data is not sorted and
> contains duplicate frequencies, this means that it needs to iterate
> through the entire freq_table of policy to ensure each frequency is
> unique in the freq_table of stats data, this has a time complexity of
> O(N^2), where N is the number of frequencies in the freq_table of
> policy.
>
> However, if the policy.freq_table is already sorted and contains no
> duplicate frequencices, it can reduce the time complexity of creating
> stats.freq_table to O(N), the 'freq_table_sorted' field of policy data
> can be used to indicate whether the policy.freq_table is sorted.
>
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> ---
> drivers/cpufreq/cpufreq_stats.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
> index 55c7ffd37d1c..fcb74050711a 100644
> --- a/drivers/cpufreq/cpufreq_stats.c
> +++ b/drivers/cpufreq/cpufreq_stats.c
> @@ -243,7 +243,8 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy)
>
> /* Find valid-unique entries */
> cpufreq_for_each_valid_entry(pos, policy->freq_table)
> - if (freq_table_get_index(stats, pos->frequency) == -1)
> + if ((policy->freq_table_sorted != CPUFREQ_TABLE_UNSORTED) ||
> + (freq_table_get_index(stats, pos->frequency) == -1))
> stats->freq_table[i++] = pos->frequency;
>
> stats->state_num = i;
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cpufreq: stats: Improve the performance of cpufreq_stats_create_table()
2023-08-18 9:50 [PATCH] cpufreq: stats: Improve the performance of cpufreq_stats_create_table() Liao Chang
2023-08-21 6:52 ` Viresh Kumar
@ 2023-08-21 9:13 ` Dhruva Gole
2023-08-21 19:00 ` Rafael J. Wysocki
1 sibling, 1 reply; 4+ messages in thread
From: Dhruva Gole @ 2023-08-21 9:13 UTC (permalink / raw)
To: Liao Chang; +Cc: rafael, viresh.kumar, linux-pm, linux-kernel
On Aug 18, 2023 at 09:50:00 +0000, Liao Chang wrote:
> In the worst case, the freq_table of policy data is not sorted and
> contains duplicate frequencies, this means that it needs to iterate
> through the entire freq_table of policy to ensure each frequency is
> unique in the freq_table of stats data, this has a time complexity of
> O(N^2), where N is the number of frequencies in the freq_table of
> policy.
>
> However, if the policy.freq_table is already sorted and contains no
> duplicate frequencices, it can reduce the time complexity of creating
s/frequencices/frequencies?
> stats.freq_table to O(N), the 'freq_table_sorted' field of policy data
> can be used to indicate whether the policy.freq_table is sorted.
>
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> ---
> drivers/cpufreq/cpufreq_stats.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
> index 55c7ffd37d1c..fcb74050711a 100644
> --- a/drivers/cpufreq/cpufreq_stats.c
> +++ b/drivers/cpufreq/cpufreq_stats.c
> @@ -243,7 +243,8 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy)
>
> /* Find valid-unique entries */
> cpufreq_for_each_valid_entry(pos, policy->freq_table)
> - if (freq_table_get_index(stats, pos->frequency) == -1)
> + if ((policy->freq_table_sorted != CPUFREQ_TABLE_UNSORTED) ||
[...]
Otherwise looks okay to me,
Reviewed-by: Dhruva Gole <d-gole@ti.com>
--
Best regards,
Dhruva Gole <d-gole@ti.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cpufreq: stats: Improve the performance of cpufreq_stats_create_table()
2023-08-21 9:13 ` Dhruva Gole
@ 2023-08-21 19:00 ` Rafael J. Wysocki
0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2023-08-21 19:00 UTC (permalink / raw)
To: Dhruva Gole, Liao Chang; +Cc: viresh.kumar, linux-pm, linux-kernel
On Mon, Aug 21, 2023 at 11:14 AM Dhruva Gole <d-gole@ti.com> wrote:
>
> On Aug 18, 2023 at 09:50:00 +0000, Liao Chang wrote:
> > In the worst case, the freq_table of policy data is not sorted and
> > contains duplicate frequencies, this means that it needs to iterate
> > through the entire freq_table of policy to ensure each frequency is
> > unique in the freq_table of stats data, this has a time complexity of
> > O(N^2), where N is the number of frequencies in the freq_table of
> > policy.
> >
> > However, if the policy.freq_table is already sorted and contains no
> > duplicate frequencices, it can reduce the time complexity of creating
>
> s/frequencices/frequencies?
I've fixed this when applying the patch.
> > stats.freq_table to O(N), the 'freq_table_sorted' field of policy data
> > can be used to indicate whether the policy.freq_table is sorted.
> >
> > Signed-off-by: Liao Chang <liaochang1@huawei.com>
> > ---
> > drivers/cpufreq/cpufreq_stats.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
> > index 55c7ffd37d1c..fcb74050711a 100644
> > --- a/drivers/cpufreq/cpufreq_stats.c
> > +++ b/drivers/cpufreq/cpufreq_stats.c
> > @@ -243,7 +243,8 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy)
> >
> > /* Find valid-unique entries */
> > cpufreq_for_each_valid_entry(pos, policy->freq_table)
> > - if (freq_table_get_index(stats, pos->frequency) == -1)
> > + if ((policy->freq_table_sorted != CPUFREQ_TABLE_UNSORTED) ||
I've also removed the redundant parens from this check.
>
> [...]
>
> Otherwise looks okay to me,
>
> Reviewed-by: Dhruva Gole <d-gole@ti.com>
Applied as 6.6 material (with the changes mentioned above), thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-21 19:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-18 9:50 [PATCH] cpufreq: stats: Improve the performance of cpufreq_stats_create_table() Liao Chang
2023-08-21 6:52 ` Viresh Kumar
2023-08-21 9:13 ` Dhruva Gole
2023-08-21 19:00 ` Rafael J. Wysocki
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.