diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index 912f9aede9..456176cf25 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -335,8 +335,7 @@ void clock_synchronize(void); * ****************************************************************************/ -#if defined(CONFIG_RTC) && !defined(CONFIG_SCHED_TICKLESS) && \ - !defined(CONFIG_CLOCK_TIMEKEEPING) +#if defined(CONFIG_RTC) && !defined(CONFIG_SCHED_TICKLESS) void clock_resynchronize(FAR struct timespec *rtc_diff); #endif diff --git a/sched/clock/clock.h b/sched/clock/clock.h index 7eaf40a388..6402d9a91d 100644 --- a/sched/clock/clock.h +++ b/sched/clock/clock.h @@ -81,10 +81,6 @@ extern volatile uint32_t g_system_timer; #ifndef CONFIG_CLOCK_TIMEKEEPING extern struct timespec g_basetime; - -#ifdef CONFIG_CLOCK_MONOTONIC -extern struct timespec g_monotonic_basetime; -#endif #endif /**************************************************************************** diff --git a/sched/clock/clock_gettime.c b/sched/clock/clock_gettime.c index d3f1cd34a7..4d5fe17e87 100644 --- a/sched/clock/clock_gettime.c +++ b/sched/clock/clock_gettime.c @@ -93,40 +93,11 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) * reset. */ -#if defined(CONFIG_CLOCK_TIMEKEEPING) - ret = clock_timekeeping_get_monotonic_time(tp); -#elif defined(CONFIG_SCHED_TICKLESS) +#if defined(CONFIG_SCHED_TICKLESS) ret = up_timer_gettime(tp); #else ret = clock_systimespec(tp); #endif - -#ifndef CONFIG_CLOCK_TIMEKEEPING - if (ret == OK) - { - irqstate_t flags; - - /* Add the offset time to this. The offset time allows - * CLOCK_MONOTONIC be introduced additional increases to systime. - */ - - flags = spin_lock_irqsave(); - - tp->tv_sec += (uint32_t)g_monotonic_basetime.tv_sec; - tp->tv_nsec += (uint32_t)g_monotonic_basetime.tv_nsec; - - spin_unlock_irqrestore(flags); - - /* Handle carry to seconds. */ - - if (tp->tv_nsec >= NSEC_PER_SEC) - { - carry = tp->tv_nsec / NSEC_PER_SEC; - tp->tv_sec += carry; - tp->tv_nsec -= (carry * NSEC_PER_SEC); - } - } -#endif /* CONFIG_CLOCK_TIMEKEEPING */ } else #endif diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index fea25eef81..71d0d18f95 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -73,10 +73,6 @@ volatile uint32_t g_system_timer; #ifndef CONFIG_CLOCK_TIMEKEEPING struct timespec g_basetime; - -#ifdef CONFIG_CLOCK_MONOTONIC -struct timespec g_monotonic_basetime; -#endif #endif /**************************************************************************** @@ -199,18 +195,6 @@ static void clock_inittime(void) g_basetime.tv_nsec += NSEC_PER_SEC; g_basetime.tv_sec--; } - -#ifdef CONFIG_CLOCK_MONOTONIC - /* Adjust monotonic clock offset to hide initial timer ticks. */ - - g_monotonic_basetime.tv_sec -= ts.tv_sec; - g_monotonic_basetime.tv_nsec -= ts.tv_nsec; - while (g_monotonic_basetime.tv_nsec < 0) - { - g_monotonic_basetime.tv_nsec += NSEC_PER_SEC; - g_monotonic_basetime.tv_sec--; - } -#endif /* CONFIG_CLOCK_MONOTONIC */ } #endif /* !CONFIG_SCHED_TICKLESS */ #else @@ -312,8 +296,7 @@ void clock_synchronize(void) * ****************************************************************************/ -#if defined(CONFIG_RTC) && !defined(CONFIG_SCHED_TICKLESS) && \ - !defined(CONFIG_CLOCK_TIMEKEEPING) +#if defined(CONFIG_RTC) && !defined(CONFIG_SCHED_TICKLESS) void clock_resynchronize(FAR struct timespec *rtc_diff) { struct timespec rtc_time, bias, curr_ts; @@ -384,35 +367,10 @@ void clock_resynchronize(FAR struct timespec *rtc_diff) } else { - /* Save RTC time as the new base time. */ - - g_basetime.tv_sec = rtc_time.tv_sec; - g_basetime.tv_nsec = rtc_time.tv_nsec; - - /* Subtract that bias from the basetime so that when the system - * timer is again added to the base time, the result is the current - * time relative to basetime. - */ - - if (g_basetime.tv_nsec < bias.tv_nsec) - { - g_basetime.tv_nsec += NSEC_PER_SEC; - g_basetime.tv_sec--; - } - - /* Result could be negative seconds */ - - g_basetime.tv_nsec -= bias.tv_nsec; - g_basetime.tv_sec -= bias.tv_sec; - - sinfo("basetime=(%ld,%lu) bias=(%ld,%lu)\n", - (long)g_basetime.tv_sec, (unsigned long)g_basetime.tv_nsec, - (long)bias.tv_sec, (unsigned long)bias.tv_nsec); - /* Output difference between time at entry and new current time. */ - rtc_diff->tv_sec = (bias.tv_sec + g_basetime.tv_sec) - curr_ts.tv_sec; - rtc_diff->tv_nsec = (bias.tv_nsec + g_basetime.tv_nsec) - curr_ts.tv_nsec; + rtc_diff->tv_sec = rtc_time.tv_sec - curr_ts.tv_sec; + rtc_diff->tv_nsec = rtc_time.tv_nsec - curr_ts.tv_nsec; /* Handle carry to seconds. */ @@ -429,29 +387,16 @@ void clock_resynchronize(FAR struct timespec *rtc_diff) carry = 0; } - if (carry) + if (carry != 0) { rtc_diff->tv_sec += carry; rtc_diff->tv_nsec -= (carry * NSEC_PER_SEC); } -#ifdef CONFIG_CLOCK_MONOTONIC - /* Monotonic clock follows wall time since system start-up. Adjust - * CLOCK_MONOTONIC same amount as CLOCK_REALTIME. - */ + /* Add the sleep time to correct system timer */ - g_monotonic_basetime.tv_sec += (uint32_t)rtc_diff->tv_sec; - g_monotonic_basetime.tv_nsec += (uint32_t)rtc_diff->tv_nsec; - - /* Handle carry to seconds. */ - - if (g_monotonic_basetime.tv_nsec >= NSEC_PER_SEC) - { - carry = g_monotonic_basetime.tv_nsec / NSEC_PER_SEC; - g_monotonic_basetime.tv_sec += carry; - g_monotonic_basetime.tv_nsec -= (carry * NSEC_PER_SEC); - } -#endif + g_system_timer += SEC2TICK(rtc_diff->tv_sec); + g_system_timer += NSEC2TICK(rtc_diff->tv_nsec); } skip: diff --git a/sched/clock/clock_systimer.c b/sched/clock/clock_systimer.c index 1c21ab45dc..8aff24aae7 100644 --- a/sched/clock/clock_systimer.c +++ b/sched/clock/clock_systimer.c @@ -97,11 +97,7 @@ clock_t clock_systimer(void) /* Get the time from the platform specific hardware */ -#ifndef CONFIG_CLOCK_TIMEKEEPING (void)up_timer_gettime(&ts); -#else - (void)clock_timekeeping_get_monotonic_time(&ts); -#endif /* Convert to a 64-bit value in microseconds, then in clock tick units */ @@ -114,11 +110,7 @@ clock_t clock_systimer(void) /* Get the time from the platform specific hardware */ -#ifndef CONFIG_CLOCK_TIMEKEEPING (void)up_timer_gettime(&ts); -#else - (void)clock_timekeeping_get_monotonic_time(&ts); -#endif /* Convert to a 64- then a 32-bit value */ diff --git a/sched/clock/clock_timekeeping.c b/sched/clock/clock_timekeeping.c index be83688f01..8c3914bee9 100644 --- a/sched/clock/clock_timekeeping.c +++ b/sched/clock/clock_timekeeping.c @@ -63,7 +63,6 @@ **********************************************************************/ static struct timespec g_clock_wall_time; -static struct timespec g_clock_monotonic_time; static uint64_t g_clock_last_counter; static uint64_t g_clock_mask; static long g_clock_adjust; @@ -118,15 +117,6 @@ errout_in_critical_section: * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: clock_timekeeping_get_monotonic_time - ****************************************************************************/ - -int clock_timekeeping_get_monotonic_time(FAR struct timespec *ts) -{ - return clock_get_current_time(ts, &g_clock_monotonic_time); -} - /**************************************************************************** * Name: clock_timekeeping_get_wall_time ****************************************************************************/ @@ -257,14 +247,6 @@ void clock_update_wall_time(void) sec = nsec / NSEC_PER_SEC; nsec -= sec * NSEC_PER_SEC; - g_clock_monotonic_time.tv_sec += sec; - g_clock_monotonic_time.tv_nsec += nsec; - if (g_clock_monotonic_time.tv_nsec > NSEC_PER_SEC) - { - g_clock_monotonic_time.tv_nsec -= NSEC_PER_SEC; - g_clock_monotonic_time.tv_sec += 1; - } - nsec += g_clock_wall_time.tv_nsec; if (nsec > NSEC_PER_SEC) { @@ -324,8 +306,6 @@ void clock_inittimekeeping(void) g_clock_wall_time.tv_sec = mktime(&rtctime); g_clock_wall_time.tv_nsec = 0; - - memset(&g_clock_monotonic_time, 0, sizeof(g_clock_monotonic_time)); } #endif /* CONFIG_CLOCK_TIMEKEEPING */ diff --git a/sched/clock/clock_timekeeping.h b/sched/clock/clock_timekeeping.h index 9bf21df743..4f85ebfc01 100644 --- a/sched/clock/clock_timekeeping.h +++ b/sched/clock/clock_timekeeping.h @@ -51,7 +51,6 @@ * Public Function Prototypes ****************************************************************************/ -int clock_timekeeping_get_monotonic_time(FAR struct timespec *ts); int clock_timekeeping_get_wall_time(FAR struct timespec *ts); int clock_timekeeping_set_wall_time(FAR struct timespec *ts);