linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpufreq: simplify for_each_suitable_policy() macro
@ 2016-02-21 18:53 Eric Biggers
  2016-02-22  5:33 ` Viresh Kumar
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Biggers @ 2016-02-21 18:53 UTC (permalink / raw)
  To: rjw; +Cc: viresh.kumar, linux-pm, linux-kernel, Eric Biggers

Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
---
 drivers/cpufreq/cpufreq.c | 44 +++-----------------------------------------
 1 file changed, 3 insertions(+), 41 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index e979ec7..3aa7b2b 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -38,48 +38,10 @@ static inline bool policy_is_inactive(struct cpufreq_policy *policy)
 	return cpumask_empty(policy->cpus);
 }
 
-static bool suitable_policy(struct cpufreq_policy *policy, bool active)
-{
-	return active == !policy_is_inactive(policy);
-}
-
-/* Finds Next Acive/Inactive policy */
-static struct cpufreq_policy *next_policy(struct cpufreq_policy *policy,
-					  bool active)
-{
-	do {
-		/* No more policies in the list */
-		if (list_is_last(&policy->policy_list, &cpufreq_policy_list))
-			return NULL;
-
-		policy = list_next_entry(policy, policy_list);
-	} while (!suitable_policy(policy, active));
-
-	return policy;
-}
-
-static struct cpufreq_policy *first_policy(bool active)
-{
-	struct cpufreq_policy *policy;
-
-	/* No policies in the list */
-	if (list_empty(&cpufreq_policy_list))
-		return NULL;
-
-	policy = list_first_entry(&cpufreq_policy_list, typeof(*policy),
-				  policy_list);
-
-	if (!suitable_policy(policy, active))
-		policy = next_policy(policy, active);
-
-	return policy;
-}
-
 /* Macros to iterate over CPU policies */
-#define for_each_suitable_policy(__policy, __active)	\
-	for (__policy = first_policy(__active);		\
-	     __policy;					\
-	     __policy = next_policy(__policy, __active))
+#define for_each_suitable_policy(__policy, __active)			 \
+	list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) \
+		if ((__active) == !policy_is_inactive(__policy))
 
 #define for_each_active_policy(__policy)		\
 	for_each_suitable_policy(__policy, true)
-- 
2.7.1


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

* Re: [PATCH] cpufreq: simplify for_each_suitable_policy() macro
  2016-02-21 18:53 [PATCH] cpufreq: simplify for_each_suitable_policy() macro Eric Biggers
@ 2016-02-22  5:33 ` Viresh Kumar
  2016-02-22 13:15   ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Viresh Kumar @ 2016-02-22  5:33 UTC (permalink / raw)
  To: Eric Biggers; +Cc: rjw, linux-pm, linux-kernel

On 21-02-16, 12:53, Eric Biggers wrote:
> Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
> ---
>  drivers/cpufreq/cpufreq.c | 44 +++-----------------------------------------
>  1 file changed, 3 insertions(+), 41 deletions(-)
> 
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index e979ec7..3aa7b2b 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -38,48 +38,10 @@ static inline bool policy_is_inactive(struct cpufreq_policy *policy)
>  	return cpumask_empty(policy->cpus);
>  }
>  
> -static bool suitable_policy(struct cpufreq_policy *policy, bool active)
> -{
> -	return active == !policy_is_inactive(policy);
> -}
> -
> -/* Finds Next Acive/Inactive policy */
> -static struct cpufreq_policy *next_policy(struct cpufreq_policy *policy,
> -					  bool active)
> -{
> -	do {
> -		/* No more policies in the list */
> -		if (list_is_last(&policy->policy_list, &cpufreq_policy_list))
> -			return NULL;
> -
> -		policy = list_next_entry(policy, policy_list);
> -	} while (!suitable_policy(policy, active));
> -
> -	return policy;
> -}
> -
> -static struct cpufreq_policy *first_policy(bool active)
> -{
> -	struct cpufreq_policy *policy;
> -
> -	/* No policies in the list */
> -	if (list_empty(&cpufreq_policy_list))
> -		return NULL;
> -
> -	policy = list_first_entry(&cpufreq_policy_list, typeof(*policy),
> -				  policy_list);
> -
> -	if (!suitable_policy(policy, active))
> -		policy = next_policy(policy, active);
> -
> -	return policy;
> -}
> -
>  /* Macros to iterate over CPU policies */
> -#define for_each_suitable_policy(__policy, __active)	\
> -	for (__policy = first_policy(__active);		\
> -	     __policy;					\
> -	     __policy = next_policy(__policy, __active))
> +#define for_each_suitable_policy(__policy, __active)			 \
> +	list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) \
> +		if ((__active) == !policy_is_inactive(__policy))
>  
>  #define for_each_active_policy(__policy)		\
>  	for_each_suitable_policy(__policy, true)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH] cpufreq: simplify for_each_suitable_policy() macro
  2016-02-22  5:33 ` Viresh Kumar
@ 2016-02-22 13:15   ` Rafael J. Wysocki
  0 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2016-02-22 13:15 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: Eric Biggers, linux-pm, linux-kernel

On Monday, February 22, 2016 11:03:15 AM Viresh Kumar wrote:
> On 21-02-16, 12:53, Eric Biggers wrote:
> > Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
> > ---
> >  drivers/cpufreq/cpufreq.c | 44 +++-----------------------------------------
> >  1 file changed, 3 insertions(+), 41 deletions(-)
> > 
> > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> > index e979ec7..3aa7b2b 100644
> > --- a/drivers/cpufreq/cpufreq.c
> > +++ b/drivers/cpufreq/cpufreq.c
> > @@ -38,48 +38,10 @@ static inline bool policy_is_inactive(struct cpufreq_policy *policy)
> >  	return cpumask_empty(policy->cpus);
> >  }
> >  
> > -static bool suitable_policy(struct cpufreq_policy *policy, bool active)
> > -{
> > -	return active == !policy_is_inactive(policy);
> > -}
> > -
> > -/* Finds Next Acive/Inactive policy */
> > -static struct cpufreq_policy *next_policy(struct cpufreq_policy *policy,
> > -					  bool active)
> > -{
> > -	do {
> > -		/* No more policies in the list */
> > -		if (list_is_last(&policy->policy_list, &cpufreq_policy_list))
> > -			return NULL;
> > -
> > -		policy = list_next_entry(policy, policy_list);
> > -	} while (!suitable_policy(policy, active));
> > -
> > -	return policy;
> > -}
> > -
> > -static struct cpufreq_policy *first_policy(bool active)
> > -{
> > -	struct cpufreq_policy *policy;
> > -
> > -	/* No policies in the list */
> > -	if (list_empty(&cpufreq_policy_list))
> > -		return NULL;
> > -
> > -	policy = list_first_entry(&cpufreq_policy_list, typeof(*policy),
> > -				  policy_list);
> > -
> > -	if (!suitable_policy(policy, active))
> > -		policy = next_policy(policy, active);
> > -
> > -	return policy;
> > -}
> > -
> >  /* Macros to iterate over CPU policies */
> > -#define for_each_suitable_policy(__policy, __active)	\
> > -	for (__policy = first_policy(__active);		\
> > -	     __policy;					\
> > -	     __policy = next_policy(__policy, __active))
> > +#define for_each_suitable_policy(__policy, __active)			 \
> > +	list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) \
> > +		if ((__active) == !policy_is_inactive(__policy))
> >  
> >  #define for_each_active_policy(__policy)		\
> >  	for_each_suitable_policy(__policy, true)
> 
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

Queued up for 4.6, thanks!

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

end of thread, other threads:[~2016-02-22 13:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-21 18:53 [PATCH] cpufreq: simplify for_each_suitable_policy() macro Eric Biggers
2016-02-22  5:33 ` Viresh Kumar
2016-02-22 13:15   ` Rafael J. Wysocki

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).