Skip to contentSkip to conversation

init: skip calibration delay if previously done

PATCH In review Sameer Nanda 5 participants 6 messages May 24, 2011 – Jun 3, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 init: skip calibration delay if previously done

For each CPU, do the calibration delay only once. For subsequent calls, use the cached per-CPU value of loops_per_jiffy.

This saves about 200ms of resume time on dual core Intel Atom N5xx based systems. This helps bring down the kernel resume time on such systems from about 500ms to about 300ms.

---
 init/calibrate.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
init/calibrate.c +9 -1
index 76ac919..47d3408 100644
@@ -183,11 +183,18 @@ recalibrate:
 	return lpj;
 }
 
+DEFINE_PER_CPU(unsigned long, cpu_loops_per_jiffy) = { 0 };
+
 void __cpuinit calibrate_delay(void)
 {
 	static bool printed;
+	int this_cpu = smp_processor_id();
 
-	if (preset_lpj) {
+	if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
+		loops_per_jiffy = per_cpu(cpu_loops_per_jiffy, this_cpu);
+		pr_info("Calibrating delay loop (skipped) "
+				"already calibrated this CPU previously.. ");
+	} else if (preset_lpj) {
 		loops_per_jiffy = preset_lpj;
 		if (!printed)
 			pr_info("Calibrating delay loop (skipped) "
@@ -205,6 +212,7 @@ void __cpuinit calibrate_delay(void)
 			pr_info("Calibrating delay loop... ");
 		loops_per_jiffy = calibrate_delay_converge();
 	}
+	per_cpu(cpu_loops_per_jiffy, this_cpu) = loops_per_jiffy;
 	if (!printed)
 		pr_cont("%lu.%02lu BogoMIPS (lpj=%lu)\n",
 			loops_per_jiffy/(500000/HZ),
Signature · 1 line
1.7.3.1
#1 lore raw
Quoted 37 lines · On Tue, 24 May 2011 16:19:06 -0700 Sameer Nanda <[email protected]> wrote:

For each CPU, do the calibration delay only once. For subsequent calls, use the cached per-CPU value of loops_per_jiffy.

This saves about 200ms of resume time on dual core Intel Atom N5xx based systems. This helps bring down the kernel resume time on such systems from about 500ms to about 300ms.

---
 init/calibrate.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
init/calibrate.c +8 -1
index 76ac919..47d3408 100644
@@ -183,11 +183,18 @@ recalibrate:
 	return lpj;
 }
 
+DEFINE_PER_CPU(unsigned long, cpu_loops_per_jiffy) = { 0 };
+
 void __cpuinit calibrate_delay(void)
 {
 	static bool printed;
+	int this_cpu = smp_processor_id();
 
-	if (preset_lpj) {
+	if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
+		loops_per_jiffy = per_cpu(cpu_loops_per_jiffy, this_cpu);
+		pr_info("Calibrating delay loop (skipped) "
+				"already calibrated this CPU previously.. ");
+	} else if (preset_lpj) {
 		loops_per_jiffy = preset_lpj;
 		if (!printed)
 			pr_info("Calibrating delay loop (skipped) "

init/calibrate.c void __cpuinit calibrate_delay(void) · line 218

Quoted 7 lines
init/calibrate.c +1 -0
@@ -205,6 +212,7 @@ void __cpuinit calibrate_delay(void)
 			pr_info("Calibrating delay loop... ");
 		loops_per_jiffy = calibrate_delay_converge();
 	}
+	per_cpu(cpu_loops_per_jiffy, this_cpu) = loops_per_jiffy;
 	if (!printed)
 		pr_cont("%lu.%02lu BogoMIPS (lpj=%lu)\n",
 			loops_per_jiffy/(500000/HZ),

Seems reasonable.

On resume, the kernel will print "already calibrated this CPU previously.." in all situations, such as when preset_lpj was set. I don't see a problem with that.

Let's be nice to the namespace:

init/calibrate.c renamed from init/calibrate.c~init-skip-calibration-delay-if-previously-done-fix +1 -1
@@ -246,7 +246,7 @@ recalibrate:
 	return lpj;
 }
 
-DEFINE_PER_CPU(unsigned long, cpu_loops_per_jiffy) = { 0 };
+static DEFINE_PER_CPU(unsigned long, cpu_loops_per_jiffy) = { 0 };
 
 void __cpuinit calibrate_delay(void)
 {

_

#2 lore raw
Quoted 30 lines · Andrew Morton
Quoted 27 lines · On Tue, 24 May 2011 16:19:06 -0700 Sameer Nanda<[email protected]> wrote:

For each CPU, do the calibration delay only once. For subsequent calls, use the cached per-CPU value of loops_per_jiffy.

This saves about 200ms of resume time on dual core Intel Atom N5xx based systems. This helps bring down the kernel resume time on such systems from about 500ms to about 300ms.

---
  init/calibrate.c |   10 +++++++++-
  1 files changed, 9 insertions(+), 1 deletions(-)
init/calibrate.c +3 -0
index 76ac919..47d3408 100644
@@ -183,11 +183,18 @@ recalibrate:
  	return lpj;
  }
 
+DEFINE_PER_CPU(unsigned long, cpu_loops_per_jiffy) = { 0 };
+
  void __cpuinit calibrate_delay(void)
  {
  	static bool printed;
+	int this_cpu = smp_processor_id();
 
Quoted 5 lines

init/calibrate.c recalibrate: · line 196

Quoted 5 lines
init/calibrate.c +4 -1
-	if (preset_lpj) {
+	if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
+		loops_per_jiffy = per_cpu(cpu_loops_per_jiffy, this_cpu);
+		pr_info("Calibrating delay loop (skipped) "
+				"already calibrated this CPU previously.. ");

That wording seems a little redundant, and there are two '.' at the end.

How about:
s/"already calibrated this CPU previously.. "/", this CPU previously calibrated."/

David Daney

#3 lore raw
Quoted 39 lines · On Fri, 03 Jun 2011 14:08:01 -0700 David Daney <[email protected]>…
Quoted 30 lines · Andrew Morton
Quoted 27 lines · On Tue, 24 May 2011 16:19:06 -0700 Sameer Nanda<[email protected]> wrote:

For each CPU, do the calibration delay only once. For subsequent calls, use the cached per-CPU value of loops_per_jiffy.

This saves about 200ms of resume time on dual core Intel Atom N5xx based systems. This helps bring down the kernel resume time on such systems from about 500ms to about 300ms.

---
  init/calibrate.c |   10 +++++++++-
  1 files changed, 9 insertions(+), 1 deletions(-)
init/calibrate.c +3 -0
index 76ac919..47d3408 100644
@@ -183,11 +183,18 @@ recalibrate:
  	return lpj;
  }
 
+DEFINE_PER_CPU(unsigned long, cpu_loops_per_jiffy) = { 0 };
+
  void __cpuinit calibrate_delay(void)
  {
  	static bool printed;
+	int this_cpu = smp_processor_id();
 
Quoted 5 lines

init/calibrate.c recalibrate: · line 196

Quoted 5 lines
init/calibrate.c +4 -1
-	if (preset_lpj) {
+	if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
+		loops_per_jiffy = per_cpu(cpu_loops_per_jiffy, this_cpu);
+		pr_info("Calibrating delay loop (skipped) "
+				"already calibrated this CPU previously.. ");

That wording seems a little redundant, and there are two '.' at the end.

Quoted 4 lines

How about:
s/"already calibrated this CPU previously.. "/", this CPU previously calibrated."/

Pedant ;)

init/calibrate.c renamed from init/calibrate.c~init-skip-calibration-delay-if-previously-done-fix-fix +1 -1
@@ -256,7 +256,7 @@ void __cpuinit calibrate_delay(void)
 	if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
 		loops_per_jiffy = per_cpu(cpu_loops_per_jiffy, this_cpu);
 		pr_info("Calibrating delay loop (skipped) "
-				"already calibrated this CPU previously.. ");
+				"already calibrated this CPU");
 	} else if (preset_lpj) {
 		loops_per_jiffy = preset_lpj;
 		if (!printed)

_

But the whole thing is a bit weird. Does this look better?

From: Andrew Morton <[email protected]>

Make these messages more gramatically pleasing, more consistent and remove strange ellipses.

Cc Andrew Worsley <[email protected]>
Cc Phil Carmody <[email protected]>
Cc Sameer Nanda <[email protected]>
Cc David Daney <[email protected]>

---

 init/calibrate.c |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
init/calibrate.c renamed from init/calibrate.c~init-calibratec-calibrate_delay-tidy-up-the-pr_info-messages +9 -9
diff -puN init/calibrate.c~init-calibratec-calibrate_delay-tidy-up-the-pr_info-messages init/calibrate.c
@@ -255,24 +255,24 @@ void __cpuinit calibrate_delay(void)
 
 	if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
 		loops_per_jiffy = per_cpu(cpu_loops_per_jiffy, this_cpu);
-		pr_info("Calibrating delay loop (skipped) "
-				"already calibrated this CPU");
+		pr_info("Calibrating delay loop.  Skipped: already calibrated "
+				"this CPU");
 	} else if (preset_lpj) {
 		loops_per_jiffy = preset_lpj;
 		if (!printed)
-			pr_info("Calibrating delay loop (skipped) "
-				"preset value.. ");
+			pr_info("Calibrating delay loop.  Skipped: "
+				"preset value");
 	} else if ((!printed) && lpj_fine) {
 		loops_per_jiffy = lpj_fine;
-		pr_info("Calibrating delay loop (skipped), "
-			"value calculated using timer frequency.. ");
+		pr_info("Calibrating delay loop.  Skipped: value calculated "
+				"using timer frequency");
 	} else if ((loops_per_jiffy = calibrate_delay_direct()) != 0) {
 		if (!printed)
-			pr_info("Calibrating delay using timer "
-				"specific routine.. ");
+			pr_info("Calibrating delay loop using timer-specific "
+					"routine");
 	} else {
 		if (!printed)
-			pr_info("Calibrating delay loop... ");
+			pr_info("Calibrating delay loop");
 		loops_per_jiffy = calibrate_delay_converge();
 	}
 	per_cpu(cpu_loops_per_jiffy, this_cpu) = loops_per_jiffy;

_

#4 lore raw
Quoted 3 lines · Andrew Morton

But the whole thing is a bit weird. Does this look better? Make these messages more gramatically pleasing, more consistent and remove strange ellipses.

or maybe something like this:

 init/calibrate.c |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)
init/calibrate.c +20 -14
index cfd7000..827a45c 100644
@@ -246,32 +246,38 @@ recalibrate:
 	return lpj;
 }
 
+static DEFINE_PER_CPU(unsigned long, cpu_loops_per_jiffy) = { 0 };
+
 void __cpuinit calibrate_delay(void)
 {
+	int this_cpu = smp_processor_id();
 	static bool printed;
+	const char *msg;
 
-	if (preset_lpj) {
+	if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
+		loops_per_jiffy = per_cpu(cpu_loops_per_jiffy, this_cpu);
+		msg = " CPU previously calibrated";
+	} else if (preset_lpj) {
 		loops_per_jiffy = preset_lpj;
-		if (!printed)
-			pr_info("Calibrating delay loop (skipped) "
-				"preset value.. ");
+		msg = " preset value";
 	} else if ((!printed) && lpj_fine) {
 		loops_per_jiffy = lpj_fine;
-		pr_info("Calibrating delay loop (skipped), "
-			"value calculated using timer frequency.. ");
+		msg = " using timer frequency";
 	} else if ((loops_per_jiffy = calibrate_delay_direct()) != 0) {
-		if (!printed)
-			pr_info("Calibrating delay using timer "
-				"specific routine.. ");
+		msg = " using timer specific routine";
 	} else {
-		if (!printed)
-			pr_info("Calibrating delay loop... ");
+		pr_info("Calibrating delay loop...\n");
 		loops_per_jiffy = calibrate_delay_converge();
+		per_cpu(cpu_loops_per_jiffy, this_cpu) = loops_per_jiffy;
+		msg = "";
 	}
-	if (!printed)
-		pr_cont("%lu.%02lu BogoMIPS (lpj=%lu)\n",
+
+	if (!printed) {
+		pr_info("Delay loop calibration:%s %lu.%02lu BogoMIPS (lpj=%lu)\n",
+			msg,
 			loops_per_jiffy/(500000/HZ),
 			(loops_per_jiffy/(5000/HZ)) % 100, loops_per_jiffy);
 
-	printed = true;
+		printed = true;
+	}
 }
#5 lore raw
In reply to Andrew Morton
Quoted 117 lines · Andrew Morton
Quoted 39 lines · On Fri, 03 Jun 2011 14:08:01 -0700 David Daney <[email protected]>…
Quoted 30 lines · Andrew Morton
Quoted 27 lines · On Tue, 24 May 2011 16:19:06 -0700 Sameer Nanda<[email protected]>  wrote:

For each CPU, do the calibration delay only once. For subsequent calls, use the cached per-CPU value of loops_per_jiffy.

This saves about 200ms of resume time on dual core Intel Atom N5xx based systems. This helps bring down the kernel resume time on such systems from about 500ms to about 300ms.

---
  init/calibrate.c |   10 +++++++++-

  1 files changed, 9 insertions(+), 1 deletions(-)
init/calibrate.c +3 -0
index 76ac919..47d3408 100644
@@ -183,11 +183,18 @@ recalibrate:
    return lpj;
   }
 
+DEFINE_PER_CPU(unsigned long, cpu_loops_per_jiffy) = { 0 };
+
   void __cpuinit calibrate_delay(void)
   {
    static bool printed;
+  int this_cpu = smp_processor_id();
 
Quoted 5 lines

init/calibrate.c recalibrate: · line 196

Quoted 5 lines
init/calibrate.c +4 -1
-  if (preset_lpj) {
+  if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
+          loops_per_jiffy = per_cpu(cpu_loops_per_jiffy, this_cpu);
+          pr_info("Calibrating delay loop (skipped) "
+                          "already calibrated this CPU previously.. ");

That wording seems a little redundant, and there are two '.' at the end.

Quoted 4 lines

How about:
s/"already calibrated this CPU previously.. "/", this CPU previously calibrated."/

Pedant ;)

init/calibrate.c renamed from init/calibrate.c~init-skip-calibration-delay-if-previously-done-fix-fix +0 -0
@@ -256,7 +256,7 @@ void __cpuinit calibrate_delay(void)
        if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
                loops_per_jiffy = per_cpu(cpu_loops_per_jiffy, this_cpu);

               pr_info("Calibrating delay loop (skipped) "
-                               "already calibrated this CPU previously.. ");
+                               "already calibrated this CPU");
       } else if (preset_lpj) {
               loops_per_jiffy = preset_lpj;
               if (!printed)
_

But the whole thing is a bit weird.  Does this look better?

From: Andrew Morton <[email protected]>

Make these messages more gramatically pleasing, more consistent and remove strange ellipses.

Cc Andrew Worsley <[email protected]>
Cc Phil Carmody <[email protected]>
Cc Sameer Nanda <[email protected]>
Cc David Daney <[email protected]>

---

 init/calibrate.c |   18 +++++++++---------

 1 file changed, 9 insertions(+), 9 deletions(-)

diff -puN init/calibrate.c~init-calibratec-calibrate_delay-tidy-up-the-pr_info-messages init/calibrate.c

init/calibrate.c renamed from init/calibrate.c~init-calibratec-calibrate_delay-tidy-up-the-pr_info-messages +9 -9
@@ -255,24 +255,24 @@ void __cpuinit calibrate_delay(void)
 
        if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
                loops_per_jiffy = per_cpu(cpu_loops_per_jiffy, this_cpu);
-               pr_info("Calibrating delay loop (skipped) "
-                               "already calibrated this CPU");
+               pr_info("Calibrating delay loop.  Skipped: already calibrated "
+                               "this CPU");
        } else if (preset_lpj) {
                loops_per_jiffy = preset_lpj;
                if (!printed)
-                       pr_info("Calibrating delay loop (skipped) "
-                               "preset value.. ");
+                       pr_info("Calibrating delay loop.  Skipped: "
+                               "preset value");
        } else if ((!printed) && lpj_fine) {
                loops_per_jiffy = lpj_fine;
-               pr_info("Calibrating delay loop (skipped), "
-                       "value calculated using timer frequency.. ");
+               pr_info("Calibrating delay loop.  Skipped: value calculated "
+                               "using timer frequency");
        } else if ((loops_per_jiffy = calibrate_delay_direct()) != 0) {
                if (!printed)
-                       pr_info("Calibrating delay using timer "
-                               "specific routine.. ");
+                       pr_info("Calibrating delay loop using timer-specific "
+                                       "routine");
        } else {
                if (!printed)
-                       pr_info("Calibrating delay loop... ");
+                       pr_info("Calibrating delay loop");
                loops_per_jiffy = calibrate_delay_converge();
        }
        per_cpu(cpu_loops_per_jiffy, this_cpu) = loops_per_jiffy;
Quoted 2 lines

_

Thanks for picking this up.
Mind adding the following to this patch to prevent ARM build breakage :)

init/calibrate.c +1 -0
index ec1e528..1b76597 100644
@@ -9,6 +9,7 @@
 #include <linux/init.h>
 #include <linux/timex.h>
 #include <linux/smp.h>
+#include <linux/percpu.h>
 
 unsigned long lpj_fine;
 unsigned long preset_lpj;

--
Sameer