All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org,
	sboyd@codeaurora.org, prarit@redhat.com, skannan@codeaurora.org
Subject: Re: [PATCH 04/18] cpufreq: Manage fallback policies in a list
Date: Tue, 03 Feb 2015 01:41:45 +0100	[thread overview]
Message-ID: <4877089.HgQ3LJW3cC@vostro.rjw.lan> (raw)
In-Reply-To: <43d728016b775d1b0fc02c981eb0520ac08297f5.1422346933.git.viresh.kumar@linaro.org>

On Tuesday, January 27, 2015 02:06:10 PM Viresh Kumar wrote:
> Policies manage a group of CPUs and tracking them on per-cpu basis isn't the
> best approach for sure.
> 
> The obvious loss is the amount of memory consumed for keeping a per-cpu copy of
> the same pointer. But the bigger problem is managing such a data structure as we
> need to update it for all policy->cpus.
> 
> To make it simple, lets manage fallback CPUs in a list rather than a per-cpu
> variable.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  drivers/cpufreq/cpufreq.c | 51 +++++++++++++++++++++++++++--------------------
>  include/linux/cpufreq.h   |  5 ++++-
>  2 files changed, 33 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index cf8ce523074f..f253cf45f910 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -37,6 +37,11 @@ static LIST_HEAD(cpufreq_policy_list);
>  #define for_each_policy(__policy)				\
>  	list_for_each_entry(__policy, &cpufreq_policy_list, policy_list)
>  
> +/* Iterate over offline CPUs policies */
> +static LIST_HEAD(cpufreq_fallback_list);
> +#define for_each_fallback_policy(__policy)			\
> +	list_for_each_entry(__policy, &cpufreq_fallback_list, fallback_list)
> +
>  /* Iterate over governors */
>  static LIST_HEAD(cpufreq_governor_list);
>  #define for_each_governor(__governor)				\
> @@ -49,7 +54,6 @@ static LIST_HEAD(cpufreq_governor_list);
>   */
>  static struct cpufreq_driver *cpufreq_driver;
>  static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
> -static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data_fallback);
>  static DEFINE_RWLOCK(cpufreq_driver_lock);
>  DEFINE_MUTEX(cpufreq_governor_lock);
>  
> @@ -999,13 +1003,16 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy,
>  
>  static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu)
>  {
> -	struct cpufreq_policy *policy;
> +	struct cpufreq_policy *policy = NULL, *temp;
>  	unsigned long flags;
>  
>  	read_lock_irqsave(&cpufreq_driver_lock, flags);
> -
> -	policy = per_cpu(cpufreq_cpu_data_fallback, cpu);
> -
> +	for_each_fallback_policy(temp) {
> +		if (cpumask_test_cpu(cpu, temp->related_cpus)) {
> +			policy = temp;
> +			break;
> +		}

This becomes quite inefficient on a system with many CPUs having different
policies.  My approach would be to somehow attach the fallback policy information
to the CPU device object.

> +	}
>  	read_unlock_irqrestore(&cpufreq_driver_lock, flags);
>  
>  	if (policy)
> @@ -1029,6 +1036,7 @@ static struct cpufreq_policy *cpufreq_policy_alloc(void)
>  		goto err_free_cpumask;
>  
>  	INIT_LIST_HEAD(&policy->policy_list);
> +	INIT_LIST_HEAD(&policy->fallback_list);
>  	init_rwsem(&policy->rwsem);
>  	spin_lock_init(&policy->transition_lock);
>  	init_waitqueue_head(&policy->transition_wait);
> @@ -1142,6 +1150,11 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
>  		policy = cpufreq_policy_alloc();
>  		if (!policy)
>  			goto nomem_out;
> +	} else {
> +		/* Don't need fallback list anymore */
> +		write_lock_irqsave(&cpufreq_driver_lock, flags);
> +		list_del(&policy->fallback_list);
> +		write_unlock_irqrestore(&cpufreq_driver_lock, flags);
>  	}
>  
>  	/*
> @@ -1296,11 +1309,8 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
>  	if (cpufreq_driver->exit)
>  		cpufreq_driver->exit(policy);
>  err_set_policy_cpu:
> -	if (recover_policy) {
> -		/* Do not leave stale fallback data behind. */
> -		per_cpu(cpufreq_cpu_data_fallback, cpu) = NULL;
> +	if (recover_policy)
>  		cpufreq_policy_put_kobj(policy);
> -	}
>  	cpufreq_policy_free(policy);
>  
>  nomem_out:
> @@ -1333,21 +1343,22 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
>  
>  	pr_debug("%s: unregistering CPU %u\n", __func__, cpu);
>  
> -	write_lock_irqsave(&cpufreq_driver_lock, flags);
> -
>  	policy = per_cpu(cpufreq_cpu_data, cpu);
> -
> -	/* Save the policy somewhere when doing a light-weight tear-down */
> -	if (cpufreq_suspended)
> -		per_cpu(cpufreq_cpu_data_fallback, cpu) = policy;
> -
> -	write_unlock_irqrestore(&cpufreq_driver_lock, flags);
> -
>  	if (!policy) {
>  		pr_debug("%s: No cpu_data found\n", __func__);
>  		return -EINVAL;
>  	}
>  
> +	down_read(&policy->rwsem);
> +	cpus = cpumask_weight(policy->cpus);
> +	up_read(&policy->rwsem);
> +
> +	/* Save the policy when doing a light-weight tear-down of last cpu */
> +	write_lock_irqsave(&cpufreq_driver_lock, flags);
> +	if (cpufreq_suspended && cpus == 1)
> +		list_add(&policy->fallback_list, &cpufreq_fallback_list);
> +	write_unlock_irqrestore(&cpufreq_driver_lock, flags);
> +
>  	if (has_target()) {
>  		ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
>  		if (ret) {
> @@ -1359,10 +1370,6 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
>  			policy->governor->name, CPUFREQ_NAME_LEN);
>  	}
>  
> -	down_read(&policy->rwsem);
> -	cpus = cpumask_weight(policy->cpus);
> -	up_read(&policy->rwsem);
> -
>  	if (cpu != policy->cpu) {
>  		sysfs_remove_link(&dev->kobj, "cpufreq");
>  	} else if (cpus > 1) {
> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
> index 2ee4888c1f47..df6af4cfa26a 100644
> --- a/include/linux/cpufreq.h
> +++ b/include/linux/cpufreq.h
> @@ -87,7 +87,10 @@ struct cpufreq_policy {
>  	struct cpufreq_real_policy	user_policy;
>  	struct cpufreq_frequency_table	*freq_table;
>  
> -	struct list_head        policy_list;
> +	/* Internal lists */
> +	struct list_head        policy_list;	/* policies of online CPUs */
> +	struct list_head	fallback_list;	/* policies of offline CPUs */
> +
>  	struct kobject		kobj;
>  	struct completion	kobj_unregister;
>  
> 


  reply	other threads:[~2015-02-03  0:18 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-27  8:36 [PATCH 00/18] cpufreq: don't loose cpufreq history on CPU hotplug Viresh Kumar
2015-01-27  8:36 ` [PATCH 01/18] cpufreq: Drop cpufreq_disabled() check from cpufreq_cpu_{get|put}() Viresh Kumar
2015-02-03 22:17   ` Saravana Kannan
2015-01-27  8:36 ` [PATCH 02/18] cpufreq: Create for_each_policy() Viresh Kumar
2015-02-03 22:22   ` Saravana Kannan
2015-02-04  4:53     ` Viresh Kumar
2015-01-27  8:36 ` [PATCH 03/18] cpufreq: Create for_each_governor() Viresh Kumar
2015-02-03 22:23   ` Saravana Kannan
2015-01-27  8:36 ` [PATCH 04/18] cpufreq: Manage fallback policies in a list Viresh Kumar
2015-02-03  0:41   ` Rafael J. Wysocki [this message]
2015-02-03  4:10     ` Viresh Kumar
2015-02-03 15:04       ` Rafael J. Wysocki
2015-02-04  6:18         ` Viresh Kumar
2015-02-03 22:28   ` Saravana Kannan
2015-02-04  6:20     ` Viresh Kumar
2015-02-04 22:28       ` Saravana Kannan
2015-02-04 23:20         ` Rafael J. Wysocki
2015-02-05  1:55           ` Saravana Kannan
2015-02-05 15:11             ` Rafael J. Wysocki
2015-02-05 22:55               ` Saravana Kannan
2015-02-17  8:06               ` Viresh Kumar
2015-02-17 18:15                 ` Rafael J. Wysocki
2015-02-18  4:23                   ` Viresh Kumar
2015-02-18 21:15                     ` Saravana Kannan
2015-02-19  3:24                       ` Viresh Kumar
2015-01-27  8:36 ` [PATCH 05/18] cpufreq: Manage governor usage history with 'policy->last_governor' Viresh Kumar
2015-02-12  3:03   ` Saravana Kannan
2015-02-12  7:44     ` Viresh Kumar
2015-02-12  8:00       ` skannan
2015-02-17  8:02         ` Viresh Kumar
2015-01-27  8:36 ` [PATCH 06/18] cpufreq: Reuse policy list instead of per-cpu variable 'cpufreq_cpu_data' Viresh Kumar
2015-02-12  3:13   ` Saravana Kannan
2015-02-12  7:48     ` Viresh Kumar
2015-01-27  8:36 ` [PATCH 07/18] cpufreq: Drop (now) useless check 'cpu > nr_cpu_ids' Viresh Kumar
2015-02-12  3:15   ` Saravana Kannan
2015-02-12  7:50     ` Viresh Kumar
2015-01-27  8:36 ` [PATCH 08/18] cpufreq: Add doc style comment about cpufreq_cpu_{get|put}() Viresh Kumar
2015-02-12  3:19   ` Saravana Kannan
2015-02-12  7:52     ` Viresh Kumar
2015-01-27  8:36 ` [PATCH 09/18] cpufreq: Mark policy->governor = NULL for fallback policies Viresh Kumar
2015-02-12  3:22   ` Saravana Kannan
2015-02-12  7:56     ` Viresh Kumar
2015-01-27  8:36 ` [PATCH 10/18] cpufreq: Don't allow updating inactive-policies from sysfs Viresh Kumar
2015-02-12  3:24   ` Saravana Kannan
2015-01-27  8:36 ` [PATCH 11/18] cpufreq: Track cpu managing sysfs kobjects separately Viresh Kumar
2015-01-27  8:36 ` [PATCH 12/18] cpufreq: Stop migrating sysfs files on hotplug Viresh Kumar
2015-01-27  8:36 ` [PATCH 13/18] cpufreq: Keep a single path for adding managed CPUs Viresh Kumar
2015-01-27  8:36 ` [PATCH 14/18] cpufreq: Remove cpufreq_update_policy() Viresh Kumar
2015-01-27  8:36 ` [PATCH 15/18] cpufreq: Initialize policy->kobj while allocating policy Viresh Kumar
2015-01-27  8:36 ` [PATCH 16/18] cpufreq: Call cpufreq_policy_put_kobj() from cpufreq_policy_free() Viresh Kumar
2015-01-27  8:36 ` [PATCH 17/18] cpufreq: Restart governor as soon as possible Viresh Kumar
2015-01-27  8:36 ` [PATCH 18/18] cpufreq: Merge __cpufreq_add_dev() and cpufreq_add_dev() Viresh Kumar
2015-01-27 15:06 ` [PATCH 00/18] cpufreq: don't loose cpufreq history on CPU hotplug Rafael J. Wysocki
2015-01-27 14:59   ` Viresh Kumar
2015-01-28 19:35 ` Saravana Kannan
2015-01-29  1:43   ` Viresh Kumar
2015-02-03  0:30 ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4877089.HgQ3LJW3cC@vostro.rjw.lan \
    --to=rjw@rjwysocki.net \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=prarit@redhat.com \
    --cc=sboyd@codeaurora.org \
    --cc=skannan@codeaurora.org \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.