[RFC,04/19] cpufreq: bring data structures close to their locks

Message ID 20160112112125.GA7015@e106622-lin
State New
Headers show

Commit Message

Juri Lelli Jan. 12, 2016, 11:21 a.m.
Hi,

On 12/01/16 14:57, Viresh Kumar wrote:
> On 11-01-16, 23:07, Peter Zijlstra wrote:

> > On Mon, Jan 11, 2016 at 05:35:45PM +0000, Juri Lelli wrote:

> > > +/**

> > > + * Iterate over governors

> > > + *

> > > + * cpufreq_governor_list is protected by cpufreq_governor_mutex.

> > > + */

> > > +static LIST_HEAD(cpufreq_governor_list);

> > > +static DEFINE_MUTEX(cpufreq_governor_mutex);

> > > +#define for_each_governor(__governor)				\

> > > +	list_for_each_entry(__governor, &cpufreq_governor_list, governor_list)

> > 

> > So you could stuff the lockdep_assert_held() you later add intididually

> > into the for_each_governor macro, impossible to forget that way.

> 

> How exactly? I couldn't see how it can be done in a neat and clean

> way.

> 


I tried to see if something like for_each_domain() can be done, but here
we use list_for_each_entry() macro. Peter, do you mean something like
the following?


Since for_each_governor() is not used in if conditions that should be
fine?

Thanks,

- Juri
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Juri Lelli Jan. 12, 2016, 12:36 p.m. | #1
On 12/01/16 12:58, Peter Zijlstra wrote:
> On Tue, Jan 12, 2016 at 11:21:25AM +0000, Juri Lelli wrote:

> > I tried to see if something like for_each_domain() can be done, but here

> > we use list_for_each_entry() macro. Peter, do you mean something like

> > the following?

> > 

> > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c

> > index 78b1e2f..1a847a6 100644

> > --- a/drivers/cpufreq/cpufreq.c

> > +++ b/drivers/cpufreq/cpufreq.c

> > @@ -39,6 +39,7 @@

> >  static LIST_HEAD(cpufreq_governor_list);

> >  static DEFINE_MUTEX(cpufreq_governor_mutex);

> >  #define for_each_governor(__governor)				\

> > +	lockdep_assert_held(&cpufreq_governor_mutex);		\

> >  	list_for_each_entry(__governor, &cpufreq_governor_list, governor_list)

> 

> That fails for things like:

> 

> 	if (blah)

> 		for_each_governor(...) {

> 		}

> 

> which looks like valid C -- even though our Coding Style says the if

> should have { } on.

> 

> I was thinking of either open coding the for statement and adding it to

> the first statement like:

> 

> 	#define for_each_governor(__g) \

> 		for (_g = list_first_entry(&cpufreq_governor_list, typeof(*_g), governor_list, lockdep_assert_held(), \

> 		     ..... )

> 

> Or use something like this:

> 

>   lkml.kernel.org/r/20150422154212.GE3007@worktop.Skamania.guest

> 

> 	#define for_each_governor(_g) \

> 		list_for_each_entry(_g, &cpufreq_governor_list, governor_list)

> 			if (lockdep_assert_held(..), false)

> 				;

> 			else

> 

> Which should preserve C syntax rules.

> 


Oh, nice this! I'll try it.

Thanks,

- Juri
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 78b1e2f..1a847a6 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -39,6 +39,7 @@ 
 static LIST_HEAD(cpufreq_governor_list);
 static DEFINE_MUTEX(cpufreq_governor_mutex);
 #define for_each_governor(__governor)				\
+	lockdep_assert_held(&cpufreq_governor_mutex);		\
 	list_for_each_entry(__governor, &cpufreq_governor_list, governor_list)
 
 /**
@@ -508,7 +509,6 @@  static struct cpufreq_governor *find_governor(const char *str_governor)
 {
 	struct cpufreq_governor *t;
 
-	lockdep_assert_held(&cpufreq_governor_mutex);
 	for_each_governor(t)
 		if (!strncasecmp(str_governor, t->name, CPUFREQ_NAME_LEN))
 			return t;