linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: "Gautham R. Shenoy" <ego@linux.vnet.ibm.com>
To: linuxppc-dev@ozlabs.org, linux-pm@vger.kernel.org
Cc: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>,
	"Gautham R. Shenoy" <ego@linux.vnet.ibm.com>
Subject: [PATCH v3 2/5] powernv, cpufreq:Add per-core locking to serialize frequency transitions
Date: Thu, 20 Mar 2014 17:40:57 +0530	[thread overview]
Message-ID: <1395317460-14811-3-git-send-email-ego@linux.vnet.ibm.com> (raw)
In-Reply-To: <1395317460-14811-1-git-send-email-ego@linux.vnet.ibm.com>

From: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>

On POWER systems, the CPU frequency is controlled at a core-level and
hence we need to serialize so that only one of the threads in the core
switches the core's frequency at a time.

Using a global mutex lock would needlessly serialize _all_ frequency
transitions in the system (across all cores). So introduce per-core
locking to enable finer-grained synchronization and thereby enhance
the speed and responsiveness of the cpufreq driver to varying workload
demands.

The design of per-core locking is very simple and straight-forward: we
first define a Per-CPU lock and use the ones that belongs to the first
thread sibling of the core.

cpu_first_thread_sibling() macro is used to find the *common* lock for
all thread siblings belonging to a core.

Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Signed-off-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
---
 drivers/cpufreq/powernv-cpufreq.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index ab1551f..66dae0d 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -24,8 +24,15 @@
 #include <linux/of.h>
 #include <asm/cputhreads.h>
 
-/* FIXME: Make this per-core */
-static DEFINE_MUTEX(freq_switch_mutex);
+/* Per-Core locking for frequency transitions */
+static DEFINE_PER_CPU(struct mutex, freq_switch_lock);
+
+#define lock_core_freq(cpu)				\
+			mutex_lock(&per_cpu(freq_switch_lock,\
+				cpu_first_thread_sibling(cpu)));
+#define unlock_core_freq(cpu)				\
+			mutex_unlock(&per_cpu(freq_switch_lock,\
+				cpu_first_thread_sibling(cpu)));
 
 #define POWERNV_MAX_PSTATES	256
 
@@ -221,7 +228,7 @@ static int powernv_cpufreq_target(struct cpufreq_policy *policy,
 	freqs.new = powernv_freqs[new_index].frequency;
 	freqs.cpu = policy->cpu;
 
-	mutex_lock(&freq_switch_mutex);
+	lock_core_freq(policy->cpu);
 	cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE);
 
 	pr_debug("setting frequency for cpu %d to %d kHz index %d pstate %d",
@@ -233,7 +240,7 @@ static int powernv_cpufreq_target(struct cpufreq_policy *policy,
 	rc = powernv_set_freq(policy->cpus, new_index);
 
 	cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE);
-	mutex_unlock(&freq_switch_mutex);
+	unlock_core_freq(policy->cpu);
 
 	return rc;
 }
@@ -250,7 +257,7 @@ static struct cpufreq_driver powernv_cpufreq_driver = {
 
 static int __init powernv_cpufreq_init(void)
 {
-	int rc = 0;
+	int cpu, rc = 0;
 
 	/* Discover pstates from device tree and init */
 
@@ -260,6 +267,10 @@ static int __init powernv_cpufreq_init(void)
 		pr_info("powernv-cpufreq disabled\n");
 		return rc;
 	}
+	/* Init per-core mutex */
+	for_each_possible_cpu(cpu) {
+		mutex_init(&per_cpu(freq_switch_lock, cpu));
+	}
 
 	rc = cpufreq_register_driver(&powernv_cpufreq_driver);
 	return rc;
-- 
1.8.3.1

  parent reply	other threads:[~2014-03-20 12:11 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-20 12:10 [PATCH v3 0/5] powernv: Enable Dynamic Frequency Gautham R. Shenoy
2014-03-20 12:10 ` [PATCH v3 1/5] powernv: cpufreq driver for powernv platform Gautham R. Shenoy
2014-03-21  8:41   ` Viresh Kumar
2014-03-21 10:43     ` Gautham R Shenoy
2014-03-21 10:54       ` Viresh Kumar
2014-03-21 11:40         ` Srivatsa S. Bhat
2014-03-21 13:23         ` Gautham R Shenoy
2014-03-21 13:34           ` Viresh Kumar
2014-03-21 14:54         ` Gautham R Shenoy
2014-03-22  3:43           ` Viresh Kumar
2014-03-21 14:48       ` Vaidyanathan Srinivasan
2014-03-22  3:43         ` Viresh Kumar
2014-03-21 11:45     ` Srivatsa S. Bhat
2014-03-21 11:47       ` Viresh Kumar
2014-03-20 12:10 ` Gautham R. Shenoy [this message]
2014-03-21  6:24   ` [PATCH v3 2/5] powernv, cpufreq:Add per-core locking to serialize frequency transitions Gautham R Shenoy
2014-03-21  8:42   ` Viresh Kumar
2014-03-21  9:56     ` Srivatsa S. Bhat
2014-03-20 12:10 ` [PATCH v3 3/5] powernv:cpufreq: Create pstate_id_to_freq() helper Gautham R. Shenoy
2014-03-21  6:24   ` Gautham R Shenoy
2014-03-20 12:10 ` [PATCH v3 4/5] powernv:cpufreq: Export nominal frequency via sysfs Gautham R. Shenoy
2014-03-21  8:47   ` Viresh Kumar
2014-03-21  9:55     ` Gautham R Shenoy
2014-03-21  9:57       ` Viresh Kumar
2014-03-20 12:11 ` [PATCH v3 5/5] powernv:cpufreq: Implement the driver->get() method Gautham R. Shenoy
2014-03-21  6:25   ` Gautham R Shenoy
2014-03-21  9:31   ` Viresh Kumar
2014-03-21 11:04     ` Gautham R Shenoy
2014-03-21 11:45       ` Viresh Kumar
2014-03-21 12:01         ` David Laight
2014-03-21 12:31           ` Gautham R Shenoy
2014-03-21 12:34           ` Viresh Kumar
2014-03-21 15:01             ` David Laight
2014-03-21 13:04         ` Gautham R Shenoy
2014-03-21 13:12           ` Viresh Kumar
2014-03-21 14:25             ` Gautham R Shenoy
2014-03-21 22:56       ` Benjamin Herrenschmidt
2014-03-22  7:53         ` Gautham R Shenoy
2014-03-21  7:46 ` [PATCH v3 0/5] powernv: Enable Dynamic Frequency Viresh Kumar
2014-03-21  8:19   ` Gautham R Shenoy

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=1395317460-14811-3-git-send-email-ego@linux.vnet.ibm.com \
    --to=ego@linux.vnet.ibm.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=srivatsa.bhat@linux.vnet.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).