sched/clock: Remove CLOCK_MONOTONIC option from Kconfig

here is the reason:
1.clock_systime_timespec(core function) always exist regardless the setting
2.CLOCK_MONOTONIC is a foundamental clock type required by many places

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-02-15 13:53:18 +08:00 committed by Xiang Xiao
parent 7b00c8bdb8
commit f1ed349dd9
28 changed files with 35 additions and 170 deletions

View File

@ -49,19 +49,18 @@ with NuttX. The list is the following:
``CONFIG_BOARDCTL_APP_SYMTAB=y`` ``CONFIG_NSH_LINELEN=64``
``CONFIG_BOARDCTL_OS_SYMTAB=y`` ``CONFIG_NSH_READLINE=y``
``CONFIG_BUILTIN=y`` ``CONFIG_NSH_ROMFSETC=y``
``CONFIG_CLOCK_MONOTONIC=y`` ``CONFIG_PSEUDOTERM=y``
``CONFIG_ELF=y`` ``CONFIG_PTHREAD_CLEANUP=y``
``CONFIG_FS_BINFS=y`` ``CONFIG_PTHREAD_MUTEX_TYPES=y``
``CONFIG_ELF=y`` ``CONFIG_PSEUDOTERM=y``
``CONFIG_FS_BINFS=y`` ``CONFIG_PTHREAD_CLEANUP=y``
``CONFIG_FS_PROCFS=y`` ``CONFIG_PTHREAD_MUTEX_TYPES=y``
``CONFIG_FS_PROCFS_REGISTER=y`` ``CONFIG_PTHREAD_STACK_MIN=1024``
``CONFIG_FS_ROMFS=y`` ``CONFIG_RR_INTERVAL=10``
``CONFIG_FS_TMPFS=y`` ``CONFIG_SCHED_WAITPID=y``
``CONFIG_IDLETHREAD_STACKSIZE=2048`` ``CONFIG_SERIAL_TERMIOS=y``
``CONFIG_LIBC_EXECFUNCS=y`` ``CONFIG_SYMTAB_ORDEREDBYNAME=y``
``CONFIG_LIBC_STRERROR=y`` ``CONFIG_SYSTEM_NSH=y``
``CONFIG_MAX_TASKS=16`` ``CONFIG_SYSTEM_NSH_STACKSIZE=4096``
``CONFIG_NSH_BUILTIN_APPS=y`` ``CONFIG_INIT_ENTRYPOINT="nsh_main"``
``CONFIG_NSH_FILEIOSIZE=512``
``CONFIG_FS_PROCFS_REGISTER=y`` ``CONFIG_PTHREAD_MUTEX_TYPES=y``
``CONFIG_FS_ROMFS=y`` ``CONFIG_PTHREAD_STACK_MIN=1024``
``CONFIG_FS_TMPFS=y`` ``CONFIG_RR_INTERVAL=10``
``CONFIG_IDLETHREAD_STACKSIZE=2048`` ``CONFIG_SCHED_WAITPID=y``
``CONFIG_LIBC_EXECFUNCS=y`` ``CONFIG_SERIAL_TERMIOS=y``
``CONFIG_LIBC_STRERROR=y`` ``CONFIG_SYMTAB_ORDEREDBYNAME=y``
``CONFIG_MAX_TASKS=16`` ``CONFIG_SYSTEM_NSH=y``
``CONFIG_NSH_BUILTIN_APPS=y`` ``CONFIG_SYSTEM_NSH_STACKSIZE=4096``
``CONFIG_NSH_FILEIOSIZE=512`` ``CONFIG_INIT_ENTRYPOINT="nsh_main"``
==================================== =====================================
In case you want to use Network and blocks like TCP or UDP, following configuration

View File

@ -127,11 +127,7 @@ static uint64_t _get_current_time64(void)
{
struct timespec ts;
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &ts);
#else
clock_gettime(CLOCK_REALTIME, &ts);
#endif
return (uint64_t)ts.tv_sec * NSEC_PER_SEC + (uint64_t)ts.tv_nsec;
}

View File

@ -147,10 +147,8 @@ static struct pm_callback_s pm_cb =
static int cboot = 1;
#endif /* CONFIG_RTC_DIV */
#ifdef CONFIG_CLOCK_MONOTONIC
static struct timespec lastupdate_mono;
static struct timespec lastupdate_rtc;
#endif
/****************************************************************************
* Public Data
@ -550,10 +548,8 @@ int up_rtc_settime(FAR const struct timespec *ts)
up_rtc_set_default_datetime(tp);
#endif /* CONFIG_RTC_SAVE_DEFAULT */
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &lastupdate_mono);
lastupdate_rtc = *ts;
#endif
/* Start rtc update */
@ -661,8 +657,6 @@ int up_rtc_cancelalarm(void)
int up_rtc_getrawtime(FAR struct timespec *ts)
{
struct tm tm;
#ifdef CONFIG_CLOCK_MONOTONIC
struct timespec now;
struct timespec diff;
@ -676,7 +670,6 @@ int up_rtc_getrawtime(FAR struct timespec *ts)
*ts = lastupdate_rtc;
return 0;
}
#endif
tm.tm_sec = getreg8(RTC_SEC);
tm.tm_min = getreg8(RTC_MIN);

View File

@ -851,11 +851,7 @@ static int esp32c3_i2c_polling_waitdone(struct esp32c3_i2c_priv_s *priv)
* forward and backwards.
*/
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &current_time);
#else
clock_gettime(CLOCK_REALTIME, &current_time);
#endif
clock_gettime(CLOCK_MONOTONIC, &current_time);
timeout.tv_sec = current_time.tv_sec + 10;
timeout.tv_nsec = current_time.tv_nsec + 0;
@ -896,11 +892,7 @@ static int esp32c3_i2c_polling_waitdone(struct esp32c3_i2c_priv_s *priv)
/* Update current time */
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &current_time);
#else
clock_gettime(CLOCK_REALTIME, &current_time);
#endif
clock_gettime(CLOCK_MONOTONIC, &current_time);
current_us = TIMESPEC_TO_US(current_time.tv_sec, current_time.tv_nsec);
}

View File

@ -784,11 +784,7 @@ static int esp32_i2c_polling_waitdone(struct esp32_i2c_priv_s *priv)
* forward and backwards.
*/
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &current_time);
#else
clock_gettime(CLOCK_REALTIME, &current_time);
#endif
clock_gettime(CLOCK_MONOTONIC, &current_time);
timeout.tv_sec = current_time.tv_sec + 10;
timeout.tv_nsec = current_time.tv_nsec + 0;
@ -829,11 +825,7 @@ static int esp32_i2c_polling_waitdone(struct esp32_i2c_priv_s *priv)
/* Update current time */
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &current_time);
#else
clock_gettime(CLOCK_REALTIME, &current_time);
#endif
clock_gettime(CLOCK_MONOTONIC, &current_time);
current_us = TIMESPEC_TO_US(current_time.tv_sec, current_time.tv_nsec);
}

View File

@ -643,11 +643,7 @@ static int bmp280_fetch(FAR struct sensor_lowerhalf_s *lower,
temp = bmp280_compensate_temp(priv, temp);
press = bmp280_compensate_press(priv, press);
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &ts);
#else
clock_gettime(CLOCK_REALTIME, &ts);
#endif
baro_data.timestamp = 1000000ull * ts.tv_sec + ts.tv_nsec / 1000;
baro_data.pressure = press / 100.0f;

View File

@ -549,12 +549,8 @@ static int ds18b20_set_alarm(FAR struct ds18b20_dev_s *dev,
static unsigned long ds18b20_curtime(void)
{
struct timespec ts;
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &ts);
#else
clock_gettime(CLOCK_REALTIME, &ts);
#endif
clock_gettime(CLOCK_MONOTONIC, &ts);
return 1000000ull * ts.tv_sec + ts.tv_nsec / 1000;
}

View File

@ -187,12 +187,8 @@ static void hyt271_temp_from_rawdata(FAR struct hyt271_sensor_data_s *data,
static unsigned long hyt271_curtime(void)
{
struct timespec ts;
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &ts);
#else
clock_gettime(CLOCK_REALTIME, &ts);
#endif
clock_gettime(CLOCK_MONOTONIC, &ts);
return 1000000ull * ts.tv_sec + ts.tv_nsec / 1000;
}

View File

@ -1667,11 +1667,7 @@ static int lis2dh_reboot(FAR struct lis2dh_dev_s *dev)
/* Prefer monotonic for timeout calculation when enabled. */
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &start);
#else
clock_gettime(CLOCK_REALTIME, &start);
#endif
/* Reboot to reset chip. */
@ -1696,11 +1692,7 @@ static int lis2dh_reboot(FAR struct lis2dh_dev_s *dev)
break;
}
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &curr);
#else
clock_gettime(CLOCK_REALTIME, &curr);
#endif
diff_msec = (curr.tv_sec - start.tv_sec) * 1000;
diff_msec += (curr.tv_nsec - start.tv_nsec) / (1000 * 1000);

View File

@ -157,12 +157,8 @@ static const struct sensor_ops_s g_sensor_ops =
static unsigned long ms5611_curtime(void)
{
struct timespec ts;
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &ts);
#else
clock_gettime(CLOCK_REALTIME, &ts);
#endif
clock_gettime(CLOCK_MONOTONIC, &ts);
return 1000000ull * ts.tv_sec + ts.tv_nsec / 1000;
}

View File

@ -105,17 +105,12 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
clock_gettime(CLOCK_REALTIME, &ts);
#elif defined(CONFIG_CLOCK_MONOTONIC)
#else
/* Prefer monotonic when enabled, as it can be synchronized to
* RTC with clock_resynchronize.
*/
clock_gettime(CLOCK_MONOTONIC, &ts);
#else
/* Otherwise, fall back to the system timer */
clock_systime_timespec(&ts);
#endif
/* Prepend the message with the current time, if available */

View File

@ -387,12 +387,7 @@ int epoll_pwait(int epfd, FAR struct epoll_event *evs,
expire.tv_sec = timeout / 1000;
expire.tv_nsec = timeout % 1000 * 1000;
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &curr);
#else
clock_gettime(CLOCK_REALTIME, &curr);
#endif
clock_timespec_add(&curr, &expire, &expire);
}
@ -403,11 +398,7 @@ again:
}
else
{
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &curr);
#else
clock_gettime(CLOCK_REALTIME, &curr);
#endif
clock_timespec_subtract(&expire, &curr, &diff);
rc = ppoll(eph->poll, eph->occupied + 1, &diff, sigmask);

View File

@ -540,12 +540,9 @@ int timerfd_create(int clockid, int flags)
/* Sanity checks. */
if (clockid != CLOCK_REALTIME
#ifdef CONFIG_CLOCK_MONOTONIC
&& clockid != CLOCK_MONOTONIC
&& clockid != CLOCK_BOOTTIME
#endif /* CONFIG_CLOCK_MONOTONIC */
)
if (clockid != CLOCK_REALTIME &&
clockid != CLOCK_MONOTONIC &&
clockid != CLOCK_BOOTTIME)
{
ret = -EINVAL;
goto errout;

View File

@ -182,7 +182,7 @@
#define TICK2SEC(tick) (((tick)+(TICK_PER_SEC/2))/TICK_PER_SEC) /* Rounds */
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_SYSTEM_TIME64) && \
defined(CONFIG_CLOCK_MONOTONIC) && !defined(CONFIG_SCHED_TICKLESS)
!defined(CONFIG_SCHED_TICKLESS)
/* Initial system timer ticks value close to maximum 32-bit value, to test
* 64-bit system-timer after going over 32-bit value. This is to make errors
* of casting 64-bit system-timer to 32-bit variables more visible.

View File

@ -204,11 +204,7 @@ static inline uint64_t touch_get_time(void)
{
struct timespec ts;
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &ts);
#else
clock_gettime(CLOCK_REALTIME, &ts);
#endif
return 1000000ull * ts.tv_sec + ts.tv_nsec / 1000;
}

View File

@ -44,12 +44,7 @@ static inline uint64_t lirc_get_timestamp(void)
{
struct timespec ts;
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &ts);
#else
clock_gettime(CLOCK_REALTIME, &ts);
#endif
return 1000000000ull * ts.tv_sec + ts.tv_nsec;
}

View File

@ -283,12 +283,7 @@ static inline uint64_t sensor_get_timestamp(void)
{
struct timespec ts;
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &ts);
#else
clock_gettime(CLOCK_REALTIME, &ts);
#endif
return 1000000ull * ts.tv_sec + ts.tv_nsec / 1000;
}

View File

@ -71,15 +71,11 @@
* system time-of-day clock.
*/
#ifdef CONFIG_CLOCK_MONOTONIC
# define CLOCK_MONOTONIC 1
#endif
#define CLOCK_MONOTONIC 1
/* Monotonic system-wide clock that includes time spent in suspension. */
#ifdef CONFIG_CLOCK_MONOTONIC
# define CLOCK_BOOTTIME 2
#endif
#define CLOCK_BOOTTIME 2
/* This is a flag that may be passed to the timer_settime() and
* clock_nanosleep() functions.

View File

@ -35,18 +35,6 @@
#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Use clock monotonic, if possible */
#ifdef CONFIG_CLOCK_MONOTONIC
# define DNS_CLOCK CLOCK_MONOTONIC
#else
# define DNS_CLOCK CLOCK_REALTIME
#endif
/****************************************************************************
* Private Types
****************************************************************************/
@ -148,9 +136,9 @@ void dns_save_answer(FAR const char *hostname,
entry = &g_dns_cache[ndx];
#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0
/* Get the current time, using CLOCK_MONOTONIC if possible */
/* Get the current time */
clock_gettime(DNS_CLOCK, &now);
clock_gettime(CLOCK_MONOTONIC, &now);
entry->ctime = (time_t)now.tv_sec;
#endif
@ -228,9 +216,9 @@ int dns_find_answer(FAR const char *hostname, FAR union dns_addr_u *addr,
dns_semtake();
#if CONFIG_NETDB_DNSCLIENT_LIFESEC > 0
/* Get the current time, using CLOCK_MONOTONIC if possible */
/* Get the current time */
ret = clock_gettime(DNS_CLOCK, &now);
ret = clock_gettime(CLOCK_MONOTONIC, &now);
#endif
for (ndx = g_dns_tail; ndx != g_dns_head; ndx = next)

View File

@ -181,7 +181,7 @@ static inline uint16_t dns_alloc_id(void)
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
clock_gettime(CLOCK_MONOTONIC, &ts);
return (uint32_t)ts.tv_nsec + ((uint32_t)ts.tv_nsec >> 16);
}

View File

@ -51,11 +51,8 @@ int pthread_condattr_setclock(FAR pthread_condattr_t *attr,
clockid_t clock_id)
{
if (!attr ||
(
#ifdef CONFIG_CLOCK_MONOTONIC
clock_id != CLOCK_MONOTONIC &&
#endif
clock_id != CLOCK_REALTIME))
(clock_id != CLOCK_MONOTONIC &&
clock_id != CLOCK_REALTIME))
{
return EINVAL;
}

View File

@ -46,11 +46,6 @@ hrtime_t gethrtime(void)
{
struct timespec ts;
#ifdef CONFIG_CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &ts);
#else
clock_gettime(CLOCK_REALTIME, &ts);
#endif
return (hrtime_t)1000000000 * ts.tv_sec + ts.tv_nsec;
}

View File

@ -225,11 +225,7 @@ long sysconf(int name)
return CONFIG_SMP_NCPUS;
case _SC_MONOTONIC_CLOCK:
#ifdef CONFIG_CLOCK_MONOTONIC
return 1;
#else
return 0;
#endif
case _SC_PAGESIZE:
#ifdef CONFIG_MM_PGSIZE

View File

@ -35,7 +35,6 @@ config LIBCXXMINI
config LIBCXX
bool "LLVM libc++ C++ Standard Library"
select CLOCK_MONOTONIC
select LIBC_WCHAR
select LIBC_LOCALE
---help---

View File

@ -162,20 +162,6 @@ config SYSTEM_TIME64
and/or if a very long "uptime" is required, then this option can be
selected to support a 64-bit wide timer.
config CLOCK_MONOTONIC
bool "Support CLOCK_MONOTONIC"
default n
---help---
CLOCK_MONOTONIC is an optional standard POSIX clock. Unlike
CLOCK_REALTIME which can move forward and backward when the
time-of-day changes, CLOCK_MONOTONIC is the elapsed time since some
arbitrary point in the post (the system start-up time for NuttX)
and, hence, is always monotonically increasing. CLOCK_MONOTONIC
is, hence, the more appropriate clock for determining time
differences.
The value of the CLOCK_MONOTONIC clock cannot be set via clock_settime().
config ARCH_HAVE_TIMEKEEPING
bool
default n

View File

@ -57,10 +57,8 @@ int clock_getres(clockid_t clock_id, struct timespec *res)
ret = ERROR;
break;
#ifdef CONFIG_CLOCK_MONOTONIC
case CLOCK_MONOTONIC:
case CLOCK_BOOTTIME:
#endif
case CLOCK_REALTIME:
/* Form the timspec using clock resolution in nanoseconds */

View File

@ -61,7 +61,6 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
sinfo("clock_id=%d\n", clock_id);
DEBUGASSERT(tp != NULL);
#ifdef CONFIG_CLOCK_MONOTONIC
/* CLOCK_MONOTONIC is an optional under POSIX: "If the Monotonic Clock
* option is supported, all implementations shall support a clock_id
* of CLOCK_MONOTONIC defined in <time.h>. This clock represents the
@ -82,8 +81,6 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
ret = clock_systime_timespec(tp);
}
else
#endif
/* CLOCK_REALTIME - POSIX demands this to be present. CLOCK_REALTIME
* represents the machine's best-guess as to the current wall-clock,
@ -91,7 +88,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
* backward as the system time-of-day clock is changed.
*/
if (clock_id == CLOCK_REALTIME)
else if (clock_id == CLOCK_REALTIME)
{
/* Get the elapsed time since the time-of-day was last set.
* clock_systime_timespec() provides the time since power was applied;

View File

@ -158,12 +158,8 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp,
/* Sanity checks. */
if (timerid == NULL || (clockid != CLOCK_REALTIME
#ifdef CONFIG_CLOCK_MONOTONIC
&& clockid != CLOCK_MONOTONIC
&& clockid != CLOCK_BOOTTIME
#endif /* CONFIG_CLOCK_MONOTONIC */
))
if (timerid == NULL || (clockid != CLOCK_REALTIME &&
clockid != CLOCK_MONOTONIC && clockid != CLOCK_BOOTTIME))
{
set_errno(EINVAL);
return ERROR;