From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux PM list <linux-pm@vger.kernel.org>
Cc: Juri Lelli <juri.lelli@arm.com>,
Steve Muckle <steve.muckle@linaro.org>,
ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
Viresh Kumar <viresh.kumar@linaro.org>,
Vincent Guittot <vincent.guittot@linaro.org>,
Michael Turquette <mturquette@baylibre.com>,
Ingo Molnar <mingo@kernel.org>
Subject: [PATCH v4 1/7] cpufreq: sched: Helpers to add and remove update_util hooks
Date: Wed, 16 Mar 2016 15:43:27 +0100 [thread overview]
Message-ID: <32416894.5bqRvzUIYW@vostro.rjw.lan> (raw)
In-Reply-To: <1711281.bPmSjlBT7c@vostro.rjw.lan>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Replace the single helper for adding and removing cpufreq utilization
update hooks, cpufreq_set_update_util_data(), with a pair of helpers,
cpufreq_add_update_util_hook() and cpufreq_remove_update_util_hook(),
and modify the users of cpufreq_set_update_util_data() accordingly.
With the new helpers, the code using them doesn't need to worry
about the internals of struct update_util_data and in particular
it doesn't need to worry about populating the func field in it
properly upfront.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
New patch.
---
drivers/cpufreq/cpufreq_governor.c | 76 ++++++++++++++++++-------------------
drivers/cpufreq/intel_pstate.c | 8 +--
include/linux/sched.h | 5 +-
kernel/sched/cpufreq.c | 48 ++++++++++++++++++-----
4 files changed, 83 insertions(+), 54 deletions(-)
Index: linux-pm/include/linux/sched.h
===================================================================
--- linux-pm.orig/include/linux/sched.h
+++ linux-pm/include/linux/sched.h
@@ -3213,7 +3213,10 @@ struct update_util_data {
u64 time, unsigned long util, unsigned long max);
};
-void cpufreq_set_update_util_data(int cpu, struct update_util_data *data);
+void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data,
+ void (*func)(struct update_util_data *data, u64 time,
+ unsigned long util, unsigned long max));
+void cpufreq_remove_update_util_hook(int cpu);
#endif /* CONFIG_CPU_FREQ */
#endif
Index: linux-pm/kernel/sched/cpufreq.c
===================================================================
--- linux-pm.orig/kernel/sched/cpufreq.c
+++ linux-pm/kernel/sched/cpufreq.c
@@ -14,24 +14,50 @@
DEFINE_PER_CPU(struct update_util_data *, cpufreq_update_util_data);
/**
- * cpufreq_set_update_util_data - Populate the CPU's update_util_data pointer.
+ * cpufreq_add_update_util_hook - Populate the CPU's update_util_data pointer.
* @cpu: The CPU to set the pointer for.
* @data: New pointer value.
+ * @func: Callback function to set for the CPU.
*
- * Set and publish the update_util_data pointer for the given CPU. That pointer
- * points to a struct update_util_data object containing a callback function
- * to call from cpufreq_update_util(). That function will be called from an RCU
- * read-side critical section, so it must not sleep.
+ * Set and publish the update_util_data pointer for the given CPU.
*
- * Callers must use RCU-sched callbacks to free any memory that might be
- * accessed via the old update_util_data pointer or invoke synchronize_sched()
- * right after this function to avoid use-after-free.
+ * The update_util_data pointer of @cpu is set to @data and the callback
+ * function pointer in the target struct update_util_data is set to @func.
+ * That function will be called by cpufreq_update_util() from RCU-sched
+ * read-side critical sections, so it must not sleep. @data will always be
+ * passed to it as the first argument which allows the function to get to the
+ * target update_util_data structure and its container.
+ *
+ * The update_util_data pointer of @cpu must be NULL when this function is
+ * called or it will WARN() and return with no effect.
*/
-void cpufreq_set_update_util_data(int cpu, struct update_util_data *data)
+void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data,
+ void (*func)(struct update_util_data *data, u64 time,
+ unsigned long util, unsigned long max))
{
- if (WARN_ON(data && !data->func))
+ if (WARN_ON(!data || !func))
return;
+ if (WARN_ON(per_cpu(cpufreq_update_util_data, cpu)))
+ return;
+
+ data->func = func;
rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), data);
}
-EXPORT_SYMBOL_GPL(cpufreq_set_update_util_data);
+EXPORT_SYMBOL_GPL(cpufreq_add_update_util_hook);
+
+/**
+ * cpufreq_remove_update_util_hook - Clear the CPU's update_util_data pointer.
+ * @cpu: The CPU to clear the pointer for.
+ *
+ * Clear the update_util_data pointer for the given CPU.
+ *
+ * Callers must use RCU-sched callbacks to free any memory that might be
+ * accessed via the old update_util_data pointer or invoke synchronize_sched()
+ * right after this function to avoid use-after-free.
+ */
+void cpufreq_remove_update_util_hook(int cpu)
+{
+ rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), NULL);
+}
+EXPORT_SYMBOL_GPL(cpufreq_remove_update_util_hook);
Index: linux-pm/drivers/cpufreq/cpufreq_governor.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/cpufreq_governor.c
+++ linux-pm/drivers/cpufreq/cpufreq_governor.c
@@ -258,43 +258,6 @@ unsigned int dbs_update(struct cpufreq_p
}
EXPORT_SYMBOL_GPL(dbs_update);
-static void gov_set_update_util(struct policy_dbs_info *policy_dbs,
- unsigned int delay_us)
-{
- struct cpufreq_policy *policy = policy_dbs->policy;
- int cpu;
-
- gov_update_sample_delay(policy_dbs, delay_us);
- policy_dbs->last_sample_time = 0;
-
- for_each_cpu(cpu, policy->cpus) {
- struct cpu_dbs_info *cdbs = &per_cpu(cpu_dbs, cpu);
-
- cpufreq_set_update_util_data(cpu, &cdbs->update_util);
- }
-}
-
-static inline void gov_clear_update_util(struct cpufreq_policy *policy)
-{
- int i;
-
- for_each_cpu(i, policy->cpus)
- cpufreq_set_update_util_data(i, NULL);
-
- synchronize_sched();
-}
-
-static void gov_cancel_work(struct cpufreq_policy *policy)
-{
- struct policy_dbs_info *policy_dbs = policy->governor_data;
-
- gov_clear_update_util(policy_dbs->policy);
- irq_work_sync(&policy_dbs->irq_work);
- cancel_work_sync(&policy_dbs->work);
- atomic_set(&policy_dbs->work_count, 0);
- policy_dbs->work_in_progress = false;
-}
-
static void dbs_work_handler(struct work_struct *work)
{
struct policy_dbs_info *policy_dbs;
@@ -382,6 +345,44 @@ static void dbs_update_util_handler(stru
irq_work_queue(&policy_dbs->irq_work);
}
+static void gov_set_update_util(struct policy_dbs_info *policy_dbs,
+ unsigned int delay_us)
+{
+ struct cpufreq_policy *policy = policy_dbs->policy;
+ int cpu;
+
+ gov_update_sample_delay(policy_dbs, delay_us);
+ policy_dbs->last_sample_time = 0;
+
+ for_each_cpu(cpu, policy->cpus) {
+ struct cpu_dbs_info *cdbs = &per_cpu(cpu_dbs, cpu);
+
+ cpufreq_add_update_util_hook(cpu, &cdbs->update_util,
+ dbs_update_util_handler);
+ }
+}
+
+static inline void gov_clear_update_util(struct cpufreq_policy *policy)
+{
+ int i;
+
+ for_each_cpu(i, policy->cpus)
+ cpufreq_remove_update_util_hook(i);
+
+ synchronize_sched();
+}
+
+static void gov_cancel_work(struct cpufreq_policy *policy)
+{
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
+
+ gov_clear_update_util(policy_dbs->policy);
+ irq_work_sync(&policy_dbs->irq_work);
+ cancel_work_sync(&policy_dbs->work);
+ atomic_set(&policy_dbs->work_count, 0);
+ policy_dbs->work_in_progress = false;
+}
+
static struct policy_dbs_info *alloc_policy_dbs_info(struct cpufreq_policy *policy,
struct dbs_governor *gov)
{
@@ -404,7 +405,6 @@ static struct policy_dbs_info *alloc_pol
struct cpu_dbs_info *j_cdbs = &per_cpu(cpu_dbs, j);
j_cdbs->policy_dbs = policy_dbs;
- j_cdbs->update_util.func = dbs_update_util_handler;
}
return policy_dbs;
}
Index: linux-pm/drivers/cpufreq/intel_pstate.c
===================================================================
--- linux-pm.orig/drivers/cpufreq/intel_pstate.c
+++ linux-pm/drivers/cpufreq/intel_pstate.c
@@ -1089,8 +1089,8 @@ static int intel_pstate_init_cpu(unsigne
intel_pstate_busy_pid_reset(cpu);
intel_pstate_sample(cpu, 0);
- cpu->update_util.func = intel_pstate_update_util;
- cpufreq_set_update_util_data(cpunum, &cpu->update_util);
+ cpufreq_add_update_util_hook(cpunum, &cpu->update_util,
+ intel_pstate_update_util);
pr_debug("intel_pstate: controlling: cpu %d\n", cpunum);
@@ -1174,7 +1174,7 @@ static void intel_pstate_stop_cpu(struct
pr_debug("intel_pstate: CPU %d exiting\n", cpu_num);
- cpufreq_set_update_util_data(cpu_num, NULL);
+ cpufreq_remove_update_util_hook(cpu_num);
synchronize_sched();
if (hwp_active)
@@ -1442,7 +1442,7 @@ out:
get_online_cpus();
for_each_online_cpu(cpu) {
if (all_cpu_data[cpu]) {
- cpufreq_set_update_util_data(cpu, NULL);
+ cpufreq_remove_update_util_hook(cpu);
synchronize_sched();
kfree(all_cpu_data[cpu]);
}
next prev parent reply other threads:[~2016-03-16 15:01 UTC|newest]
Thread overview: 158+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-02 1:56 [PATCH 0/6] cpufreq: schedutil governor Rafael J. Wysocki
2016-03-02 2:04 ` [PATCH 1/6] cpufreq: Reduce cpufreq_update_util() overhead a bit Rafael J. Wysocki
2016-03-03 5:48 ` Viresh Kumar
2016-03-03 11:47 ` Juri Lelli
2016-03-03 13:04 ` Peter Zijlstra
2016-03-02 2:05 ` [PATCH 2/6][Resend] cpufreq: acpi-cpufreq: Make read and write operations more efficient Rafael J. Wysocki
2016-03-02 2:08 ` [PATCH 3/6] cpufreq: governor: New data type for management part of dbs_data Rafael J. Wysocki
2016-03-03 5:53 ` Viresh Kumar
2016-03-03 19:26 ` Rafael J. Wysocki
2016-03-04 5:49 ` Viresh Kumar
2016-03-02 2:10 ` [PATCH 4/6] cpufreq: governor: Move abstract gov_tunables code to a seperate file Rafael J. Wysocki
2016-03-03 6:03 ` Viresh Kumar
2016-03-02 2:12 ` [PATCH 5/6] cpufreq: Support for fast frequency switching Rafael J. Wysocki
2016-03-03 6:00 ` Viresh Kumar
2016-03-04 2:15 ` Rafael J. Wysocki
2016-03-03 11:16 ` Peter Zijlstra
2016-03-03 20:56 ` Rafael J. Wysocki
2016-03-03 21:12 ` Peter Zijlstra
2016-03-03 11:18 ` Peter Zijlstra
2016-03-03 19:39 ` Rafael J. Wysocki
2016-03-02 2:27 ` [PATCH 6/6] cpufreq: schedutil: New governor based on scheduler utilization data Rafael J. Wysocki
2016-03-02 17:10 ` Vincent Guittot
2016-03-02 17:58 ` Rafael J. Wysocki
2016-03-02 22:49 ` Rafael J. Wysocki
2016-03-03 12:20 ` Peter Zijlstra
2016-03-03 12:32 ` Juri Lelli
2016-03-03 16:24 ` Rafael J. Wysocki
2016-03-03 16:37 ` Peter Zijlstra
2016-03-03 16:47 ` Peter Zijlstra
2016-03-04 1:14 ` Rafael J. Wysocki
2016-03-03 16:55 ` Juri Lelli
2016-03-03 16:56 ` Peter Zijlstra
2016-03-03 17:14 ` Juri Lelli
2016-03-03 14:01 ` Vincent Guittot
2016-03-03 15:38 ` Peter Zijlstra
2016-03-03 16:28 ` Peter Zijlstra
2016-03-03 16:42 ` Peter Zijlstra
2016-03-03 17:28 ` Dietmar Eggemann
2016-03-03 18:26 ` Peter Zijlstra
2016-03-03 19:14 ` Dietmar Eggemann
2016-03-08 13:09 ` Peter Zijlstra
2016-03-03 18:58 ` Rafael J. Wysocki
2016-03-03 13:07 ` Vincent Guittot
2016-03-03 20:06 ` Steve Muckle
2016-03-03 20:20 ` Rafael J. Wysocki
2016-03-03 21:37 ` Steve Muckle
2016-03-07 2:41 ` Rafael J. Wysocki
2016-03-08 11:27 ` Peter Zijlstra
2016-03-08 18:00 ` Rafael J. Wysocki
2016-03-08 19:26 ` Peter Zijlstra
2016-03-08 20:05 ` Rafael J. Wysocki
2016-03-09 10:15 ` Juri Lelli
2016-03-09 23:41 ` Rafael J. Wysocki
2016-03-10 4:30 ` Juri Lelli
2016-03-10 21:01 ` Rafael J. Wysocki
2016-03-10 23:19 ` Michael Turquette
2016-03-09 16:39 ` Peter Zijlstra
2016-03-09 23:28 ` Rafael J. Wysocki
2016-03-10 3:44 ` Vincent Guittot
2016-03-10 10:07 ` Peter Zijlstra
2016-03-10 10:26 ` Vincent Guittot
[not found] ` <CAKfTPtCbjgbJn+68NJPCnmPFtcHD0wGmZRYaw37zSqPXNpo_Uw@mail.gmail.com>
2016-03-10 10:30 ` Peter Zijlstra
2016-03-10 10:56 ` Peter Zijlstra
2016-03-10 22:28 ` Rafael J. Wysocki
2016-03-10 8:43 ` Peter Zijlstra
2016-03-04 2:56 ` [PATCH v2 0/10] cpufreq: schedutil governor Rafael J. Wysocki
2016-03-04 2:58 ` [PATCH v2 1/10] cpufreq: Reduce cpufreq_update_util() overhead a bit Rafael J. Wysocki
2016-03-09 12:39 ` Peter Zijlstra
2016-03-09 14:17 ` Rafael J. Wysocki
2016-03-09 15:29 ` Peter Zijlstra
2016-03-09 21:35 ` Rafael J. Wysocki
2016-03-10 9:19 ` Peter Zijlstra
2016-03-04 2:59 ` [PATCH v2 2/10][Resend] cpufreq: acpi-cpufreq: Make read and write operations more efficient Rafael J. Wysocki
2016-03-04 3:01 ` [PATCH v2 3/10] cpufreq: governor: New data type for management part of dbs_data Rafael J. Wysocki
2016-03-04 5:52 ` Viresh Kumar
2016-03-04 3:03 ` [PATCH v2 4/10] cpufreq: governor: Move abstract gov_attr_set code to seperate file Rafael J. Wysocki
2016-03-04 5:52 ` Viresh Kumar
2016-03-04 3:05 ` [PATCH v2 5/10] cpufreq: Move governor attribute set headers to cpufreq.h Rafael J. Wysocki
2016-03-04 5:53 ` Viresh Kumar
2016-03-04 3:07 ` [PATCH v2 6/10] cpufreq: Support for fast frequency switching Rafael J. Wysocki
2016-03-04 22:18 ` Steve Muckle
2016-03-04 22:32 ` Rafael J. Wysocki
2016-03-04 22:40 ` Rafael J. Wysocki
2016-03-04 23:18 ` Rafael J. Wysocki
2016-03-04 23:56 ` Steve Muckle
2016-03-05 0:18 ` Rafael J. Wysocki
2016-03-05 11:58 ` Ingo Molnar
2016-03-05 16:49 ` Peter Zijlstra
2016-03-06 2:17 ` Rafael J. Wysocki
2016-03-07 8:00 ` Peter Zijlstra
2016-03-07 13:15 ` Rafael J. Wysocki
2016-03-07 13:32 ` Peter Zijlstra
2016-03-07 13:42 ` Rafael J. Wysocki
2016-03-04 22:58 ` Rafael J. Wysocki
2016-03-04 23:59 ` Steve Muckle
2016-03-04 3:12 ` [PATCH v2 7/10] cpufreq: Rework the scheduler hooks for triggering updates Rafael J. Wysocki
2016-03-04 3:14 ` [PATCH v2 8/10] cpufreq: Move scheduler-related code to the sched directory Rafael J. Wysocki
2016-03-04 3:18 ` [PATCH v2 9/10] cpufreq: sched: Re-introduce cpufreq_update_util() Rafael J. Wysocki
2016-03-04 10:50 ` Juri Lelli
2016-03-04 12:58 ` Rafael J. Wysocki
2016-03-04 13:30 ` [PATCH v3 " Rafael J. Wysocki
2016-03-04 21:21 ` Steve Muckle
2016-03-04 21:27 ` Rafael J. Wysocki
2016-03-04 21:36 ` Rafael J. Wysocki
2016-03-04 3:35 ` [PATCH v2 10/10] cpufreq: schedutil: New governor based on scheduler utilization data Rafael J. Wysocki
2016-03-04 11:26 ` Juri Lelli
2016-03-04 13:19 ` Rafael J. Wysocki
2016-03-04 15:56 ` Srinivas Pandruvada
2016-03-08 2:23 ` [PATCH v3 0/7] cpufreq: schedutil governor Rafael J. Wysocki
2016-03-08 2:25 ` [PATCH v3 1/7][Resend] cpufreq: Rework the scheduler hooks for triggering updates Rafael J. Wysocki
2016-03-09 13:41 ` Peter Zijlstra
2016-03-09 14:02 ` Rafael J. Wysocki
2016-03-08 2:26 ` [PATCH v3 2/7][Resend] cpufreq: Move scheduler-related code to the sched directory Rafael J. Wysocki
2016-03-08 2:28 ` [PATCH v3 3/7][Resend] cpufreq: governor: New data type for management part of dbs_data Rafael J. Wysocki
2016-03-08 2:29 ` [PATCH v3 4/7][Resend] cpufreq: governor: Move abstract gov_attr_set code to seperate file Rafael J. Wysocki
2016-03-08 2:38 ` [PATCH v3 5/7] cpufreq: Support for fast frequency switching Rafael J. Wysocki
2016-03-08 2:41 ` [PATCH v3 6/7] cpufreq: sched: Re-introduce cpufreq_update_util() Rafael J. Wysocki
2016-03-08 2:50 ` [PATCH v3 7/7] cpufreq: schedutil: New governor based on scheduler utilization data Rafael J. Wysocki
2016-03-16 14:41 ` [PATCH v4 0/7] cpufreq: schedutil governor Rafael J. Wysocki
2016-03-16 14:43 ` Rafael J. Wysocki [this message]
2016-03-16 14:44 ` [PATCH v4 2/7] cpufreq: governor: New data type for management part of dbs_data Rafael J. Wysocki
2016-03-16 14:45 ` [PATCH v4 3/7] cpufreq: governor: Move abstract gov_attr_set code to seperate file Rafael J. Wysocki
2016-03-16 14:46 ` [PATCH v4 4/7] cpufreq: Move governor attribute set headers to cpufreq.h Rafael J. Wysocki
2016-03-16 14:47 ` [PATCH v4 5/7] cpufreq: Move governor symbols " Rafael J. Wysocki
2016-03-16 14:52 ` [PATCH v4 6/7] cpufreq: Support for fast frequency switching Rafael J. Wysocki
2016-03-16 15:35 ` Peter Zijlstra
2016-03-16 16:58 ` Rafael J. Wysocki
2016-03-16 15:43 ` Peter Zijlstra
2016-03-16 16:58 ` Rafael J. Wysocki
2016-03-16 14:59 ` [PATCH v4 7/7] cpufreq: schedutil: New governor based on scheduler utilization data Rafael J. Wysocki
2016-03-16 17:35 ` Peter Zijlstra
2016-03-16 21:42 ` Rafael J. Wysocki
2016-03-16 17:36 ` Peter Zijlstra
2016-03-16 21:34 ` Rafael J. Wysocki
2016-03-16 17:52 ` Peter Zijlstra
2016-03-16 21:38 ` Rafael J. Wysocki
2016-03-16 22:39 ` Peter Zijlstra
2016-03-16 17:53 ` Peter Zijlstra
2016-03-16 21:48 ` Rafael J. Wysocki
2016-03-16 18:14 ` Peter Zijlstra
2016-03-16 21:38 ` Rafael J. Wysocki
2016-03-16 22:40 ` Peter Zijlstra
2016-03-16 22:53 ` Rafael J. Wysocki
2016-03-16 15:27 ` [PATCH v4 0/7] cpufreq: schedutil governor Peter Zijlstra
2016-03-16 16:20 ` Rafael J. Wysocki
2016-03-16 23:51 ` [PATCH v5 6/7][Update] cpufreq: Support for fast frequency switching Rafael J. Wysocki
2016-03-17 11:35 ` Juri Lelli
2016-03-17 11:40 ` Peter Zijlstra
2016-03-17 11:48 ` Juri Lelli
2016-03-17 12:53 ` Rafael J. Wysocki
2016-03-17 0:01 ` [PATCH v5 7/7][Update] cpufreq: schedutil: New governor based on scheduler utilization data Rafael J. Wysocki
2016-03-17 11:30 ` Juri Lelli
2016-03-17 12:54 ` Rafael J. Wysocki
2016-03-17 11:36 ` Peter Zijlstra
2016-03-17 12:54 ` Rafael J. Wysocki
2016-03-17 15:54 ` [PATCH v6 6/7][Update] cpufreq: Support for fast frequency switching Rafael J. Wysocki
2016-03-17 16:01 ` [PATCH v6 7/7][Update] cpufreq: schedutil: New governor based on scheduler utilization data Rafael J. Wysocki
2016-03-18 12:34 ` Patrick Bellasi
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=32416894.5bqRvzUIYW@vostro.rjw.lan \
--to=rjw@rjwysocki.net \
--cc=juri.lelli@arm.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mturquette@baylibre.com \
--cc=peterz@infradead.org \
--cc=srinivas.pandruvada@linux.intel.com \
--cc=steve.muckle@linaro.org \
--cc=vincent.guittot@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®