All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] cpufreq: vexpress-spc: use macros instead of hardcoded values for cluster ids
@ 2019-10-23 11:08 Sudeep Holla
  2019-10-23 11:08 ` [PATCH 2/2] cpufreq: vexpress-spc: find and skip duplicates when merging frequencies Sudeep Holla
  2019-10-24  3:11 ` [PATCH 1/2] cpufreq: vexpress-spc: use macros instead of hardcoded values for cluster ids Viresh Kumar
  0 siblings, 2 replies; 6+ messages in thread
From: Sudeep Holla @ 2019-10-23 11:08 UTC (permalink / raw)
  To: Viresh Kumar, Rafael J . Wysocki; +Cc: Sudeep Holla, linux-pm, linux-kernel

A15 and A7 cluster identifiers are fixed to 0 and 1 respectively. There are
macros for the same and used in most of the places except this instance.

Lets use macros instead of hardcoded values for cluster ids even here.

Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/cpufreq/vexpress-spc-cpufreq.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/vexpress-spc-cpufreq.c b/drivers/cpufreq/vexpress-spc-cpufreq.c
index 3259498d7eaa..093ef8d3a8d4 100644
--- a/drivers/cpufreq/vexpress-spc-cpufreq.c
+++ b/drivers/cpufreq/vexpress-spc-cpufreq.c
@@ -380,8 +380,9 @@ static int get_cluster_clk_and_freq_table(struct device *cpu_dev,
 		goto put_clusters;
 
 	/* Assuming 2 cluster, set clk_big_min and clk_little_max */
-	clk_big_min = get_table_min(freq_table[0]);
-	clk_little_max = VIRT_FREQ(1, get_table_max(freq_table[1]));
+	clk_big_min = get_table_min(freq_table[A15_CLUSTER]);
+	clk_little_max = VIRT_FREQ(A7_CLUSTER,
+				   get_table_max(freq_table[A7_CLUSTER]));
 
 	return 0;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] cpufreq: vexpress-spc: find and skip duplicates when merging frequencies
  2019-10-23 11:08 [PATCH 1/2] cpufreq: vexpress-spc: use macros instead of hardcoded values for cluster ids Sudeep Holla
@ 2019-10-23 11:08 ` Sudeep Holla
  2019-10-23 11:25   ` Viresh Kumar
  2019-10-23 12:18   ` [PATCH v2 " Sudeep Holla
  2019-10-24  3:11 ` [PATCH 1/2] cpufreq: vexpress-spc: use macros instead of hardcoded values for cluster ids Viresh Kumar
  1 sibling, 2 replies; 6+ messages in thread
From: Sudeep Holla @ 2019-10-23 11:08 UTC (permalink / raw)
  To: Viresh Kumar, Rafael J . Wysocki; +Cc: Sudeep Holla, linux-pm, linux-kernel

Currently the cpufreq core aborts the validation and return error
immediately when it encounter duplicate frequency table entries.
This change was introduced long back since commit da0c6dc00c69
("cpufreq: Handle sorted frequency tables more efficiently").

However, this missed the testing with modified firmware for long time.
Inorder to make it work with default settings, we need to ensure the
merged table for bL switcher contains no duplicates. Find the duplicates
and skip them when merging the frequenct tables of A15 and A7 clusters.

Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/cpufreq/vexpress-spc-cpufreq.c | 35 ++++++++++++++++++++------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/drivers/cpufreq/vexpress-spc-cpufreq.c b/drivers/cpufreq/vexpress-spc-cpufreq.c
index 093ef8d3a8d4..921dbd42b3bb 100644
--- a/drivers/cpufreq/vexpress-spc-cpufreq.c
+++ b/drivers/cpufreq/vexpress-spc-cpufreq.c
@@ -242,6 +242,19 @@ static inline u32 get_table_max(struct cpufreq_frequency_table *table)
 	return max_freq;
 }
 
+static bool search_frequency(struct cpufreq_frequency_table *table, int size,
+			     unsigned int freq)
+{
+	int count;
+
+	for (count = 0; count < size; count++) {
+		if (table[count].frequency == freq)
+			return true;
+	}
+
+	return false;
+}
+
 static int merge_cluster_tables(void)
 {
 	int i, j, k = 0, count = 1;
@@ -256,13 +269,21 @@ static int merge_cluster_tables(void)
 
 	freq_table[MAX_CLUSTERS] = table;
 
-	/* Add in reverse order to get freqs in increasing order */
-	for (i = MAX_CLUSTERS - 1; i >= 0; i--) {
-		for (j = 0; freq_table[i][j].frequency != CPUFREQ_TABLE_END;
-		     j++, k++) {
-			table[k].frequency =
-				VIRT_FREQ(i, freq_table[i][j].frequency);
-		}
+	/* Add A7_CLUSTER first to get freqs in increasing order */
+	for (j = 0; freq_table[A7_CLUSTER][j].frequency != CPUFREQ_TABLE_END;
+	     j++, k++) {
+		table[k].frequency =
+			VIRT_FREQ(A7_CLUSTER, freq_table[A7_CLUSTER][j].frequency);
+	}
+	count = k;
+
+	/* And then A15_CLUSTER checking for duplicates */
+	for (j = 0; freq_table[A15_CLUSTER][j].frequency != CPUFREQ_TABLE_END;
+	     j++) {
+		if (search_frequency(table, count,
+				     freq_table[A15_CLUSTER][j].frequency))
+			continue; /* skip duplicates */
+		table[k++].frequency = freq_table[A15_CLUSTER][j].frequency;
 	}
 
 	table[k].driver_data = k;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] cpufreq: vexpress-spc: find and skip duplicates when merging frequencies
  2019-10-23 11:08 ` [PATCH 2/2] cpufreq: vexpress-spc: find and skip duplicates when merging frequencies Sudeep Holla
@ 2019-10-23 11:25   ` Viresh Kumar
  2019-10-23 11:38     ` Sudeep Holla
  2019-10-23 12:18   ` [PATCH v2 " Sudeep Holla
  1 sibling, 1 reply; 6+ messages in thread
From: Viresh Kumar @ 2019-10-23 11:25 UTC (permalink / raw)
  To: Sudeep Holla; +Cc: Rafael J . Wysocki, linux-pm, linux-kernel

On 23-10-19, 12:08, Sudeep Holla wrote:
> Currently the cpufreq core aborts the validation and return error
> immediately when it encounter duplicate frequency table entries.
> This change was introduced long back since commit da0c6dc00c69
> ("cpufreq: Handle sorted frequency tables more efficiently").
> 
> However, this missed the testing with modified firmware for long time.
> Inorder to make it work with default settings, we need to ensure the
> merged table for bL switcher contains no duplicates. Find the duplicates
> and skip them when merging the frequenct tables of A15 and A7 clusters.
> 
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>  drivers/cpufreq/vexpress-spc-cpufreq.c | 35 ++++++++++++++++++++------
>  1 file changed, 28 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/cpufreq/vexpress-spc-cpufreq.c b/drivers/cpufreq/vexpress-spc-cpufreq.c
> index 093ef8d3a8d4..921dbd42b3bb 100644
> --- a/drivers/cpufreq/vexpress-spc-cpufreq.c
> +++ b/drivers/cpufreq/vexpress-spc-cpufreq.c
> @@ -242,6 +242,19 @@ static inline u32 get_table_max(struct cpufreq_frequency_table *table)
>  	return max_freq;
>  }
>  
> +static bool search_frequency(struct cpufreq_frequency_table *table, int size,
> +			     unsigned int freq)
> +{
> +	int count;
> +
> +	for (count = 0; count < size; count++) {
> +		if (table[count].frequency == freq)
> +			return true;
> +	}
> +
> +	return false;
> +}
> +
>  static int merge_cluster_tables(void)
>  {
>  	int i, j, k = 0, count = 1;
> @@ -256,13 +269,21 @@ static int merge_cluster_tables(void)
>  
>  	freq_table[MAX_CLUSTERS] = table;
>  
> -	/* Add in reverse order to get freqs in increasing order */
> -	for (i = MAX_CLUSTERS - 1; i >= 0; i--) {
> -		for (j = 0; freq_table[i][j].frequency != CPUFREQ_TABLE_END;
> -		     j++, k++) {
> -			table[k].frequency =
> -				VIRT_FREQ(i, freq_table[i][j].frequency);
> -		}

I think we can still use this single loop, which already starts from
A7 cluster. Just that we can add an if (A15) block inside it as the
first line.

> +	/* Add A7_CLUSTER first to get freqs in increasing order */
> +	for (j = 0; freq_table[A7_CLUSTER][j].frequency != CPUFREQ_TABLE_END;
> +	     j++, k++) {
> +		table[k].frequency =
> +			VIRT_FREQ(A7_CLUSTER, freq_table[A7_CLUSTER][j].frequency);
> +	}
> +	count = k;
> +
> +	/* And then A15_CLUSTER checking for duplicates */
> +	for (j = 0; freq_table[A15_CLUSTER][j].frequency != CPUFREQ_TABLE_END;
> +	     j++) {
> +		if (search_frequency(table, count,
> +				     freq_table[A15_CLUSTER][j].frequency))
> +			continue; /* skip duplicates */
> +		table[k++].frequency = freq_table[A15_CLUSTER][j].frequency;
>  	}

How many duplicate entries are there anyway in the firmware? Or do we
really need to make it that generic? I mean, only the last of A7 and
first of A15 should be overlapping, in that case why search entire
table again ?

>  
>  	table[k].driver_data = k;
> -- 
> 2.17.1

-- 
viresh

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] cpufreq: vexpress-spc: find and skip duplicates when merging frequencies
  2019-10-23 11:25   ` Viresh Kumar
@ 2019-10-23 11:38     ` Sudeep Holla
  0 siblings, 0 replies; 6+ messages in thread
From: Sudeep Holla @ 2019-10-23 11:38 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: Rafael J . Wysocki, linux-pm, linux-kernel

On Wed, Oct 23, 2019 at 04:55:37PM +0530, Viresh Kumar wrote:
> On 23-10-19, 12:08, Sudeep Holla wrote:
> > Currently the cpufreq core aborts the validation and return error
> > immediately when it encounter duplicate frequency table entries.
> > This change was introduced long back since commit da0c6dc00c69
> > ("cpufreq: Handle sorted frequency tables more efficiently").
> >
> > However, this missed the testing with modified firmware for long time.
> > Inorder to make it work with default settings, we need to ensure the
> > merged table for bL switcher contains no duplicates. Find the duplicates
> > and skip them when merging the frequenct tables of A15 and A7 clusters.
> >
> > Cc: Viresh Kumar <viresh.kumar@linaro.org>
> > Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> > Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> > ---
> >  drivers/cpufreq/vexpress-spc-cpufreq.c | 35 ++++++++++++++++++++------
> >  1 file changed, 28 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/cpufreq/vexpress-spc-cpufreq.c b/drivers/cpufreq/vexpress-spc-cpufreq.c
> > index 093ef8d3a8d4..921dbd42b3bb 100644
> > --- a/drivers/cpufreq/vexpress-spc-cpufreq.c
> > +++ b/drivers/cpufreq/vexpress-spc-cpufreq.c
> > @@ -242,6 +242,19 @@ static inline u32 get_table_max(struct cpufreq_frequency_table *table)
> >  	return max_freq;
> >  }
> >
> > +static bool search_frequency(struct cpufreq_frequency_table *table, int size,
> > +			     unsigned int freq)
> > +{
> > +	int count;
> > +
> > +	for (count = 0; count < size; count++) {
> > +		if (table[count].frequency == freq)
> > +			return true;
> > +	}
> > +
> > +	return false;
> > +}
> > +
> >  static int merge_cluster_tables(void)
> >  {
> >  	int i, j, k = 0, count = 1;
> > @@ -256,13 +269,21 @@ static int merge_cluster_tables(void)
> >
> >  	freq_table[MAX_CLUSTERS] = table;
> >
> > -	/* Add in reverse order to get freqs in increasing order */
> > -	for (i = MAX_CLUSTERS - 1; i >= 0; i--) {
> > -		for (j = 0; freq_table[i][j].frequency != CPUFREQ_TABLE_END;
> > -		     j++, k++) {
> > -			table[k].frequency =
> > -				VIRT_FREQ(i, freq_table[i][j].frequency);
> > -		}
>
> I think we can still use this single loop, which already starts from
> A7 cluster. Just that we can add an if (A15) block inside it as the
> first line.
>

Yes, I can do that.

> > +	/* Add A7_CLUSTER first to get freqs in increasing order */
> > +	for (j = 0; freq_table[A7_CLUSTER][j].frequency != CPUFREQ_TABLE_END;
> > +	     j++, k++) {
> > +		table[k].frequency =
> > +			VIRT_FREQ(A7_CLUSTER, freq_table[A7_CLUSTER][j].frequency);
> > +	}
> > +	count = k;
> > +
> > +	/* And then A15_CLUSTER checking for duplicates */
> > +	for (j = 0; freq_table[A15_CLUSTER][j].frequency != CPUFREQ_TABLE_END;
> > +	     j++) {
> > +		if (search_frequency(table, count,
> > +				     freq_table[A15_CLUSTER][j].frequency))
> > +			continue; /* skip duplicates */
> > +		table[k++].frequency = freq_table[A15_CLUSTER][j].frequency;
> >  	}
>
> How many duplicate entries are there anyway in the firmware? Or do we
> really need to make it that generic? I mean, only the last of A7 and
> first of A15 should be overlapping, in that case why search entire
> table again ?
>

Yes I thought about the same. But since one can play with the firmware
table, I thought it's better to keep it generic instead of assuming that.
Since I had changed the firmware table, I didn't notice this issue. I
don't want to get into similar situation again ;)

But if you still insist that we can assume and work only for default, I
am fine by that, just that someone else may face the same issue if they
have some modified/experimental firmware table.

--
Regards,
Sudeep

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] cpufreq: vexpress-spc: find and skip duplicates when merging frequencies
  2019-10-23 11:08 ` [PATCH 2/2] cpufreq: vexpress-spc: find and skip duplicates when merging frequencies Sudeep Holla
  2019-10-23 11:25   ` Viresh Kumar
@ 2019-10-23 12:18   ` Sudeep Holla
  1 sibling, 0 replies; 6+ messages in thread
From: Sudeep Holla @ 2019-10-23 12:18 UTC (permalink / raw)
  To: Viresh Kumar, Rafael J . Wysocki; +Cc: Sudeep Holla, linux-pm, linux-kernel

Currently the cpufreq core aborts the validation and return error
immediately when it encounter duplicate frequency table entries.
This change was introduced long back since commit da0c6dc00c69
("cpufreq: Handle sorted frequency tables more efficiently").

However, this missed the testing with modified firmware for long time.
Inorder to make it work with default settings, we need to ensure the
merged table for bL switcher contains no duplicates. Find the duplicates
and skip them when merging the frequenct tables of A15 and A7 clusters.

Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/cpufreq/vexpress-spc-cpufreq.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

v1->v2:
	- Removed loop unrolling for clusters

diff --git a/drivers/cpufreq/vexpress-spc-cpufreq.c b/drivers/cpufreq/vexpress-spc-cpufreq.c
index 093ef8d3a8d4..506e3f2bf53a 100644
--- a/drivers/cpufreq/vexpress-spc-cpufreq.c
+++ b/drivers/cpufreq/vexpress-spc-cpufreq.c
@@ -242,6 +242,19 @@ static inline u32 get_table_max(struct cpufreq_frequency_table *table)
 	return max_freq;
 }

+static bool search_frequency(struct cpufreq_frequency_table *table, int size,
+			     unsigned int freq)
+{
+	int count;
+
+	for (count = 0; count < size; count++) {
+		if (table[count].frequency == freq)
+			return true;
+	}
+
+	return false;
+}
+
 static int merge_cluster_tables(void)
 {
 	int i, j, k = 0, count = 1;
@@ -257,10 +270,13 @@ static int merge_cluster_tables(void)
 	freq_table[MAX_CLUSTERS] = table;
 
 	/* Add in reverse order to get freqs in increasing order */
-	for (i = MAX_CLUSTERS - 1; i >= 0; i--) {
+	for (i = MAX_CLUSTERS - 1; i >= 0; i--, count = k) {
 		for (j = 0; freq_table[i][j].frequency != CPUFREQ_TABLE_END;
-		     j++, k++) {
-			table[k].frequency =
+		     j++) {
+			if (i == A15_CLUSTER &&
+			    search_frequency(table, count, freq_table[i][j].frequency))
+				continue; /* skip duplicates */
+			table[k++].frequency =
 				VIRT_FREQ(i, freq_table[i][j].frequency);
 		}
 	}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] cpufreq: vexpress-spc: use macros instead of hardcoded values for cluster ids
  2019-10-23 11:08 [PATCH 1/2] cpufreq: vexpress-spc: use macros instead of hardcoded values for cluster ids Sudeep Holla
  2019-10-23 11:08 ` [PATCH 2/2] cpufreq: vexpress-spc: find and skip duplicates when merging frequencies Sudeep Holla
@ 2019-10-24  3:11 ` Viresh Kumar
  1 sibling, 0 replies; 6+ messages in thread
From: Viresh Kumar @ 2019-10-24  3:11 UTC (permalink / raw)
  To: Sudeep Holla; +Cc: Rafael J . Wysocki, linux-pm, linux-kernel

On 23-10-19, 12:08, Sudeep Holla wrote:
> A15 and A7 cluster identifiers are fixed to 0 and 1 respectively. There are
> macros for the same and used in most of the places except this instance.
> 
> Lets use macros instead of hardcoded values for cluster ids even here.
> 
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>  drivers/cpufreq/vexpress-spc-cpufreq.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Applied both. Thanks.

-- 
viresh

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-10-24  3:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-23 11:08 [PATCH 1/2] cpufreq: vexpress-spc: use macros instead of hardcoded values for cluster ids Sudeep Holla
2019-10-23 11:08 ` [PATCH 2/2] cpufreq: vexpress-spc: find and skip duplicates when merging frequencies Sudeep Holla
2019-10-23 11:25   ` Viresh Kumar
2019-10-23 11:38     ` Sudeep Holla
2019-10-23 12:18   ` [PATCH v2 " Sudeep Holla
2019-10-24  3:11 ` [PATCH 1/2] cpufreq: vexpress-spc: use macros instead of hardcoded values for cluster ids Viresh Kumar

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.