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. BUG=chrome-os-partner:19420 TEST=Built and booted on pit. Used cbmem to check the timestamps and saw that they were now monotonically ascending and within reasonable bounds. BRANCH=None Change-Id: I3048028ddea0657b01b0c94f312764b38d1397e4 Signed-off-by: Gabe Black <gabeblack@google.com> Reviewed-on: https://gerrit.chromium.org/gerrit/65302 Reviewed-by: Ronald G. Minnich <rminnich@chromium.org> Commit-Queue: Stefan Reinauer <reinauer@google.com> Reviewed-by: Stefan Reinauer <reinauer@google.com> Tested-by: Stefan Reinauer <reinauer@google.com>
This commit is contained in:
parent
e2e5c1ef3b
commit
6a3fde9a5b
2 changed files with 8 additions and 48 deletions
|
|
@ -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;
|
||||
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;
|
||||
}
|
||||
|
||||
/* Save result. */
|
||||
*mt = mono_counter.time;
|
||||
mono_time_set_usecs(mt, mct_raw_value() / clocks_per_usec);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
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;
|
||||
}
|
||||
|
||||
/* Save result. */
|
||||
*mt = mono_counter.time;
|
||||
mono_time_set_usecs(mt, mct_raw_value() / clocks_per_usec);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue