linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpufreq: stats: Use lock by stat to replace global spin lock
@ 2019-03-25  7:29 Kyle Lin
  2019-03-26 18:43 ` Matthias Kaehlcke
  0 siblings, 1 reply; 3+ messages in thread
From: Kyle Lin @ 2019-03-25  7:29 UTC (permalink / raw)
  To: Rafael J . Wysocki, Viresh Kumar; +Cc: linux-pm, linux-kernel, linkyle0915

Stats is updated by each policy, using the lock by stat can
reduce the contention.

Signed-off-by: Kyle Lin <linkyle0915@gmail.com>
---
 drivers/cpufreq/cpufreq_stats.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index e2db5581489a..17beb1bc7e16 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -14,7 +14,6 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 
-static DEFINE_SPINLOCK(cpufreq_stats_lock);
 
 struct cpufreq_stats {
 	unsigned int total_trans;
@@ -23,6 +22,7 @@ struct cpufreq_stats {
 	unsigned int state_num;
 	unsigned int last_index;
 	u64 *time_in_state;
+	spinlock_t lock;        /*spinlock for stats update*/
 	unsigned int *freq_table;
 	unsigned int *trans_table;
 };
@@ -39,12 +39,12 @@ static void cpufreq_stats_clear_table(struct cpufreq_stats *stats)
 {
 	unsigned int count = stats->max_state;
 
-	spin_lock(&cpufreq_stats_lock);
+	spin_lock(&stats->lock);
 	memset(stats->time_in_state, 0, count * sizeof(u64));
 	memset(stats->trans_table, 0, count * count * sizeof(int));
 	stats->last_time = get_jiffies_64();
 	stats->total_trans = 0;
-	spin_unlock(&cpufreq_stats_lock);
+	spin_unlock(&stats->lock);
 }
 
 static ssize_t show_total_trans(struct cpufreq_policy *policy, char *buf)
@@ -62,9 +62,9 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)
 	if (policy->fast_switch_enabled)
 		return 0;
 
-	spin_lock(&cpufreq_stats_lock);
+	spin_lock(&stats->lock);
 	cpufreq_stats_update(stats);
-	spin_unlock(&cpufreq_stats_lock);
+	spin_unlock(&stats->lock);
 
 	for (i = 0; i < stats->state_num; i++) {
 		len += sprintf(buf + len, "%u %llu\n", stats->freq_table[i],
@@ -211,6 +211,7 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy)
 	stats->state_num = i;
 	stats->last_time = get_jiffies_64();
 	stats->last_index = freq_table_get_index(stats, policy->cur);
+	spin_lock_init(&stats->lock);
 
 	policy->stats = stats;
 	ret = sysfs_create_group(&policy->kobj, &stats_attr_group);
@@ -242,11 +243,11 @@ void cpufreq_stats_record_transition(struct cpufreq_policy *policy,
 	if (old_index == -1 || new_index == -1 || old_index == new_index)
 		return;
 
-	spin_lock(&cpufreq_stats_lock);
+	spin_lock(&stats->lock);
 	cpufreq_stats_update(stats);
 
 	stats->last_index = new_index;
 	stats->trans_table[old_index * stats->max_state + new_index]++;
 	stats->total_trans++;
-	spin_unlock(&cpufreq_stats_lock);
+	spin_unlock(&stats->lock);
 }
-- 
2.21.0.392.gf8f6787159e-goog


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

* Re: [PATCH] cpufreq: stats: Use lock by stat to replace global spin lock
  2019-03-25  7:29 [PATCH] cpufreq: stats: Use lock by stat to replace global spin lock Kyle Lin
@ 2019-03-26 18:43 ` Matthias Kaehlcke
  2019-04-08  5:39   ` Viresh Kumar
  0 siblings, 1 reply; 3+ messages in thread
From: Matthias Kaehlcke @ 2019-03-26 18:43 UTC (permalink / raw)
  To: Kyle Lin; +Cc: Rafael J . Wysocki, Viresh Kumar, linux-pm, linux-kernel

On Mon, Mar 25, 2019 at 03:29:33PM +0800, Kyle Lin wrote:
> Stats is updated by each policy, using the lock by stat can
> reduce the contention.
> 
> Signed-off-by: Kyle Lin <linkyle0915@gmail.com>
> ---
>  drivers/cpufreq/cpufreq_stats.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
> index e2db5581489a..17beb1bc7e16 100644
> --- a/drivers/cpufreq/cpufreq_stats.c
> +++ b/drivers/cpufreq/cpufreq_stats.c
> @@ -14,7 +14,6 @@
>  #include <linux/module.h>
>  #include <linux/slab.h>
>  
> -static DEFINE_SPINLOCK(cpufreq_stats_lock);
>  
>  struct cpufreq_stats {
>  	unsigned int total_trans;
> @@ -23,6 +22,7 @@ struct cpufreq_stats {
>  	unsigned int state_num;
>  	unsigned int last_index;
>  	u64 *time_in_state;
> +	spinlock_t lock;        /*spinlock for stats update*/

nit: not sure if the comment adds much value. If it stay there it
needs a blank after '/*' and another before '*/'

>  	unsigned int *freq_table;
>  	unsigned int *trans_table;
>  };
> @@ -39,12 +39,12 @@ static void cpufreq_stats_clear_table(struct cpufreq_stats *stats)
>  {
>  	unsigned int count = stats->max_state;
>  
> -	spin_lock(&cpufreq_stats_lock);
> +	spin_lock(&stats->lock);
>  	memset(stats->time_in_state, 0, count * sizeof(u64));
>  	memset(stats->trans_table, 0, count * count * sizeof(int));
>  	stats->last_time = get_jiffies_64();
>  	stats->total_trans = 0;
> -	spin_unlock(&cpufreq_stats_lock);
> +	spin_unlock(&stats->lock);
>  }
>  
>  static ssize_t show_total_trans(struct cpufreq_policy *policy, char *buf)
> @@ -62,9 +62,9 @@ static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)
>  	if (policy->fast_switch_enabled)
>  		return 0;
>  
> -	spin_lock(&cpufreq_stats_lock);
> +	spin_lock(&stats->lock);
>  	cpufreq_stats_update(stats);
> -	spin_unlock(&cpufreq_stats_lock);
> +	spin_unlock(&stats->lock);
>  
>  	for (i = 0; i < stats->state_num; i++) {
>  		len += sprintf(buf + len, "%u %llu\n", stats->freq_table[i],
> @@ -211,6 +211,7 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy)
>  	stats->state_num = i;
>  	stats->last_time = get_jiffies_64();
>  	stats->last_index = freq_table_get_index(stats, policy->cur);
> +	spin_lock_init(&stats->lock);
>  
>  	policy->stats = stats;
>  	ret = sysfs_create_group(&policy->kobj, &stats_attr_group);
> @@ -242,11 +243,11 @@ void cpufreq_stats_record_transition(struct cpufreq_policy *policy,
>  	if (old_index == -1 || new_index == -1 || old_index == new_index)
>  		return;
>  
> -	spin_lock(&cpufreq_stats_lock);
> +	spin_lock(&stats->lock);
>  	cpufreq_stats_update(stats);
>  
>  	stats->last_index = new_index;
>  	stats->trans_table[old_index * stats->max_state + new_index]++;
>  	stats->total_trans++;
> -	spin_unlock(&cpufreq_stats_lock);
> +	spin_unlock(&stats->lock);
>  }

Reviewed-by: Matthias Kaehlcke <mka@chromium.org>

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

* Re: [PATCH] cpufreq: stats: Use lock by stat to replace global spin lock
  2019-03-26 18:43 ` Matthias Kaehlcke
@ 2019-04-08  5:39   ` Viresh Kumar
  0 siblings, 0 replies; 3+ messages in thread
From: Viresh Kumar @ 2019-04-08  5:39 UTC (permalink / raw)
  To: Matthias Kaehlcke; +Cc: Kyle Lin, Rafael J . Wysocki, linux-pm, linux-kernel

On 26-03-19, 11:43, Matthias Kaehlcke wrote:
> On Mon, Mar 25, 2019 at 03:29:33PM +0800, Kyle Lin wrote:
> > Stats is updated by each policy, using the lock by stat can
> > reduce the contention.
> > 
> > Signed-off-by: Kyle Lin <linkyle0915@gmail.com>
> > ---
> >  drivers/cpufreq/cpufreq_stats.c | 15 ++++++++-------
> >  1 file changed, 8 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
> > index e2db5581489a..17beb1bc7e16 100644
> > --- a/drivers/cpufreq/cpufreq_stats.c
> > +++ b/drivers/cpufreq/cpufreq_stats.c
> > @@ -14,7 +14,6 @@
> >  #include <linux/module.h>
> >  #include <linux/slab.h>
> >  
> > -static DEFINE_SPINLOCK(cpufreq_stats_lock);
> >  
> >  struct cpufreq_stats {
> >  	unsigned int total_trans;
> > @@ -23,6 +22,7 @@ struct cpufreq_stats {
> >  	unsigned int state_num;
> >  	unsigned int last_index;
> >  	u64 *time_in_state;
> > +	spinlock_t lock;        /*spinlock for stats update*/
> 
> nit: not sure if the comment adds much value. If it stay there it
> needs a blank after '/*' and another before '*/'

Just drop the comment please.

-- 
viresh

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

end of thread, other threads:[~2019-04-08  5:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-25  7:29 [PATCH] cpufreq: stats: Use lock by stat to replace global spin lock Kyle Lin
2019-03-26 18:43 ` Matthias Kaehlcke
2019-04-08  5:39   ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).