[coreboot-gerrit] New patch to review for coreboot: 3260f12 timer: Add functions to initialize absolute timer structures.

Isaac Christensen (isaac.christensen@se-eng.com) gerrit at coreboot.org
Tue Jul 29 22:00:51 CEST 2014


Isaac Christensen (isaac.christensen at se-eng.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6406

-gerrit

commit 3260f12e3dd6c9798a77dcb14e2522f3e796d3a3
Author: Gabe Black <gabeblack at google.com>
Date:   Fri Aug 9 00:48:06 2013 -0700

    timer: Add functions to initialize absolute timer structures.
    
    Otherwise there's no good way to create an absolute timer structure without
    fiddling with its internal structure or assuming a zero initialized structure
    has a value of zero.
    
    Old-Change-Id: Iffe3b6b25ed7963fcfb66f749c531ea445ea4aeb
    Signed-off-by: Gabe Black <gabeblack at google.com>
    Reviewed-on: https://gerrit.chromium.org/gerrit/65301
    Reviewed-by: Aaron Durbin <adurbin at chromium.org>
    Commit-Queue: Stefan Reinauer <reinauer at google.com>
    Reviewed-by: Stefan Reinauer <reinauer at google.com>
    Tested-by: Stefan Reinauer <reinauer at google.com>
    (cherry picked from commit e2e5c1ef3bb2df95fdf0e33cb2d975a990d07a4a)
    
    exynos: Simplify the monotonic timer implementation.
    
    The previous implementation was overly complicated, and when used in the
    timestamp implementation produced some weird and broken results.
    
    Old-Change-Id: I3048028ddea0657b01b0c94f312764b38d1397e4
    Signed-off-by: Gabe Black <gabeblack at google.com>
    Reviewed-on: https://gerrit.chromium.org/gerrit/65302
    Reviewed-by: Ronald G. Minnich <rminnich at chromium.org>
    Commit-Queue: Stefan Reinauer <reinauer at google.com>
    Reviewed-by: Stefan Reinauer <reinauer at google.com>
    Tested-by: Stefan Reinauer <reinauer at google.com>
    (cherry picked from commit 6a3fde9a5b80cdac76d79c65d20d7dd1f1d9e557)
    
    Squashed two closely related commits.
    
    Change-Id: Ifc32d773f4f93d34275a81781001d080357fe8ef
    Signed-off-by: Isaac Christensen <isaac.christensen at se-eng.com>
---
 src/cpu/samsung/exynos5250/monotonic_timer.c | 28 ++++------------------------
 src/cpu/samsung/exynos5420/monotonic_timer.c | 28 ++++------------------------
 src/include/timer.h                          | 12 ++++++++++++
 3 files changed, 20 insertions(+), 48 deletions(-)

diff --git a/src/cpu/samsung/exynos5250/monotonic_timer.c b/src/cpu/samsung/exynos5250/monotonic_timer.c
index 57e3ae3..267d9c3 100644
--- a/src/cpu/samsung/exynos5250/monotonic_timer.c
+++ b/src/cpu/samsung/exynos5250/monotonic_timer.c
@@ -18,40 +18,20 @@
  */
 
 #include <stdint.h>
-#include <delay.h>
 #include <timer.h>
 
 #include "clk.h"
 
-static struct monotonic_counter {
-	int initialized;
-	struct mono_time time;
-	uint64_t last_value;
-} mono_counter;
+static int initialized;
 
 static const uint32_t clocks_per_usec = MCT_HZ/1000000;
 
 void timer_monotonic_get(struct mono_time *mt)
 {
-	uint64_t current_tick;
-	uint64_t usecs_elapsed;
-
-	if (!mono_counter.initialized) {
+	if (!initialized) {
 		mct_start();
-		mono_counter.last_value = mct_raw_value();
-		mono_counter.initialized = 1;
-	}
-
-	current_tick = mct_raw_value();
-	usecs_elapsed = (current_tick - mono_counter.last_value) /
-							clocks_per_usec;
-
-	/* Update current time and tick values only if a full tick occurred. */
-	if (usecs_elapsed) {
-		mono_time_add_usecs(&mono_counter.time, usecs_elapsed);
-		mono_counter.last_value = current_tick;
+		initialized = 1;
 	}
 
-	/* Save result. */
-	*mt = mono_counter.time;
+	mono_time_set_usecs(mt, mct_raw_value() / clocks_per_usec);
 }
diff --git a/src/cpu/samsung/exynos5420/monotonic_timer.c b/src/cpu/samsung/exynos5420/monotonic_timer.c
index 57e3ae3..267d9c3 100644
--- a/src/cpu/samsung/exynos5420/monotonic_timer.c
+++ b/src/cpu/samsung/exynos5420/monotonic_timer.c
@@ -18,40 +18,20 @@
  */
 
 #include <stdint.h>
-#include <delay.h>
 #include <timer.h>
 
 #include "clk.h"
 
-static struct monotonic_counter {
-	int initialized;
-	struct mono_time time;
-	uint64_t last_value;
-} mono_counter;
+static int initialized;
 
 static const uint32_t clocks_per_usec = MCT_HZ/1000000;
 
 void timer_monotonic_get(struct mono_time *mt)
 {
-	uint64_t current_tick;
-	uint64_t usecs_elapsed;
-
-	if (!mono_counter.initialized) {
+	if (!initialized) {
 		mct_start();
-		mono_counter.last_value = mct_raw_value();
-		mono_counter.initialized = 1;
-	}
-
-	current_tick = mct_raw_value();
-	usecs_elapsed = (current_tick - mono_counter.last_value) /
-							clocks_per_usec;
-
-	/* Update current time and tick values only if a full tick occurred. */
-	if (usecs_elapsed) {
-		mono_time_add_usecs(&mono_counter.time, usecs_elapsed);
-		mono_counter.last_value = current_tick;
+		initialized = 1;
 	}
 
-	/* Save result. */
-	*mt = mono_counter.time;
+	mono_time_set_usecs(mt, mct_raw_value() / clocks_per_usec);
 }
diff --git a/src/include/timer.h b/src/include/timer.h
index 06128ce..b37cea4 100644
--- a/src/include/timer.h
+++ b/src/include/timer.h
@@ -67,6 +67,18 @@ int timers_run(void);
  * 0 returned on success, < 0 on error. */
 int timer_sched_callback(struct timeout_callback *tocb, unsigned long us);
 
+/* Set an absolute time to a number of microseconds. */
+static inline void mono_time_set_usecs(struct mono_time *mt, long us)
+{
+	mt->microseconds = us;
+}
+
+/* Set an absolute time to a number of milliseconds. */
+static inline void mono_time_set_msecs(struct mono_time *mt, long ms)
+{
+	mt->microseconds = ms * USECS_PER_MSEC;
+}
+
 /* Add microseconds to an absolute time. */
 static inline void mono_time_add_usecs(struct mono_time *mt, long us)
 {



More information about the coreboot-gerrit mailing list