mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
!sys/types.h: change time_t and clock_t to int64_t to align with other OSes
POSIX leaves the signedness of time_t and clock_t unspecified, but
mainstream implementations (Linux glibc/musl, the BSDs, macOS, RTEMS,
Zephyr's POSIX layer, Windows _time64) expose time_t as signed 64-bit.
NuttX has historically used uint64_t only because it was tied to the
CONFIG_SYSTEM_TIME64 knob; with that gone, switch:
time_t : uint64_t -> int64_t
clock_t : uint64_t -> int64_t
CLOCK_MAX: UINT64_MAX -> INT64_MAX
This lets (time_t)-1 sentinels, negative tick deltas, and host-side
headers behave as on every other POSIX system without source churn.
Headers updated:
- include/sys/types.h, include/limits.h, include/nuttx/clock.h
- include/nuttx/fs/hostfs.h (nuttx_time_t alias)
- include/nuttx/{mqueue.h,wdog.h,wqueue.h,timers/clkcnt.h}
Because clock_t is now signed 64-bit, the NuttX-internal sclock_t
alias becomes redundant: every sclock_t/SCLOCK_MAX use is folded
back to clock_t/CLOCK_MAX (notably in sched/wdog, sched/mqueue,
sched/sched, sched/clock, sched/timer, libs/libc/time, fs/vfs and
the drivers/arch consumers below).
Tick/period constants (NSEC_PER_SEC, USEC_PER_SEC, MSEC_PER_SEC,
SEC_PER_MIN, ...) in include/nuttx/clock.h are retyped from "long"
literals to INT64_C(...) so that 64-bit arithmetic no longer
depends on the host's long width.
Strip now-redundant (time_t)/(clock_t)/(unsigned long) casts and
unsigned-only branches across the tree:
- arch RTC / oneshot / tickless lowerhalfs:
arm: cxd56xx, efm32, imxrt, lc823450, max326xx, sam34, sama5,
samd5e5, samv7, stm32, stm32f7, stm32h7, stm32l4, stm32wb,
xmc4
mips: pic32mz sparc: bm3803 x86_64: intel64
risc-v/xtensa: espressif (esp_i2c[_slave], esp_rtc,
esp32c3{_i2c,_rtc,_wifi_adapter}, esp32{,s2,s3}_*),
mpfs_perf
- drivers: audio/tone, input/aw86225, power/pm/{activity,
stability}_governor, rpmsg/rpmsg_ping,
timers/{ds3231,mcp794xx,pcf85263,rx8010},
wireless/ieee80211/bcm43xxx, wireless/spirit/spirit_spi
- core: fs/vfs/{fs_poll,fs_timerfd}, mm/iob/iob_alloc,
libs/libc/{netdb/lib_dnscache,time/{lib_calendar2utc,
lib_time}}, net/icmp/icmp_pmtu, net/icmpv6/icmpv6_pmtu,
net/ipfrag, net/tcp/{tcp.h,tcp_timer},
net/utils/net_snoop, net/mld/mld_query (drop the now-dead
mld_mrc2mrd helper since signed math handles it directly),
sched/clock/{clock,clock_initialize},
sched/sched/{sched_profil,sched_setparam,sched_setscheduler},
sched/pthread/pthread_create,
sched/wdog/{wd_gettime,wd_start,wdog.h},
sched/timer/timer_gettime, sched/mqueue/*
Flip the few in-tree printf format strings that assumed an
unsigned 64-bit tv_sec:
* drivers/rpmsg/rpmsg_ping.c PRIu64 -> PRId64
* arch/xtensa/src/esp32{,s2,s3}/esp32*_oneshot_lowerhalf.c
PRIu32 (already wrong) -> PRId64
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
c6654b1106
commit
c47b1e2c5b
94 changed files with 207 additions and 262 deletions
|
|
@ -54,13 +54,11 @@
|
|||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* The system time in units of clock ticks is returned. If the processor
|
||||
* time used is not available or its value cannot be represented, the
|
||||
* function will return the value (clock_t)-1.
|
||||
* The system time in units of clock ticks is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
clock_t clock(void)
|
||||
{
|
||||
return (clock_t)clock_systime_ticks();
|
||||
return clock_systime_ticks();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ int clock_basetime(FAR struct timespec *tp)
|
|||
|
||||
/* Set the base time as seconds into this julian day. */
|
||||
|
||||
tp->tv_sec = jdn * (time_t)SEC_PER_DAY;
|
||||
tp->tv_sec = jdn * SEC_PER_DAY;
|
||||
tp->tv_nsec = 0;
|
||||
return OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ static void nxmq_rcvtimeout(wdparm_t arg)
|
|||
int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,
|
||||
FAR struct mqueue_msg_s **rcvmsg,
|
||||
FAR const struct timespec *abstime,
|
||||
sclock_t ticks)
|
||||
clock_t ticks)
|
||||
{
|
||||
FAR struct mqueue_msg_s *newmsg;
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ static
|
|||
ssize_t file_mq_timedreceive_internal(FAR struct file *mq, FAR char *msg,
|
||||
size_t msglen, FAR unsigned int *prio,
|
||||
FAR const struct timespec *abstime,
|
||||
sclock_t ticks)
|
||||
clock_t ticks)
|
||||
{
|
||||
FAR struct mqueue_inode_s *msgq;
|
||||
FAR struct mqueue_msg_s *mqmsg;
|
||||
|
|
@ -325,7 +325,7 @@ ssize_t file_mq_timedreceive(FAR struct file *mq, FAR char *msg,
|
|||
|
||||
ssize_t file_mq_tickreceive(FAR struct file *mq, FAR char *msg,
|
||||
size_t msglen, FAR unsigned int *prio,
|
||||
sclock_t ticks)
|
||||
clock_t ticks)
|
||||
{
|
||||
return file_mq_timedreceive_internal(mq, msg, msglen, prio, NULL, ticks);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -275,7 +275,7 @@ static
|
|||
int file_mq_timedsend_internal(FAR struct file *mq, FAR const char *msg,
|
||||
size_t msglen, unsigned int prio,
|
||||
FAR const struct timespec *abstime,
|
||||
sclock_t ticks)
|
||||
clock_t ticks)
|
||||
{
|
||||
FAR struct mqueue_inode_s *msgq;
|
||||
FAR struct mqueue_msg_s *mqmsg;
|
||||
|
|
@ -466,7 +466,7 @@ int file_mq_timedsend(FAR struct file *mq, FAR const char *msg,
|
|||
****************************************************************************/
|
||||
|
||||
int file_mq_ticksend(FAR struct file *mq, FAR const char *msg,
|
||||
size_t msglen, unsigned int prio, sclock_t ticks)
|
||||
size_t msglen, unsigned int prio, clock_t ticks)
|
||||
{
|
||||
return file_mq_timedsend_internal(mq, msg, msglen, prio, NULL, ticks);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ static void nxmq_sndtimeout(wdparm_t arg)
|
|||
|
||||
int nxmq_wait_send(FAR struct mqueue_inode_s *msgq,
|
||||
FAR const struct timespec *abstime,
|
||||
sclock_t ticks)
|
||||
clock_t ticks)
|
||||
{
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
|
||||
|
|
|
|||
|
|
@ -128,14 +128,14 @@ void nxmq_wait_irq(FAR struct tcb_s *wtcb, int errcode);
|
|||
int nxmq_wait_receive(FAR struct mqueue_inode_s *msgq,
|
||||
FAR struct mqueue_msg_s **rcvmsg,
|
||||
FAR const struct timespec *abstime,
|
||||
sclock_t ticks);
|
||||
clock_t ticks);
|
||||
void nxmq_notify_receive(FAR struct mqueue_inode_s *msgq);
|
||||
|
||||
/* mq_sndinternal.c *********************************************************/
|
||||
|
||||
int nxmq_wait_send(FAR struct mqueue_inode_s *msgq,
|
||||
FAR const struct timespec *abstime,
|
||||
sclock_t ticks);
|
||||
clock_t ticks);
|
||||
void nxmq_notify_send(FAR struct mqueue_inode_s *msgq);
|
||||
|
||||
/* mq_recover.c *************************************************************/
|
||||
|
|
|
|||
|
|
@ -328,8 +328,8 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
|
|||
if (policy == SCHED_SPORADIC)
|
||||
{
|
||||
FAR struct sporadic_s *sporadic;
|
||||
sclock_t repl_ticks;
|
||||
sclock_t budget_ticks;
|
||||
clock_t repl_ticks;
|
||||
clock_t budget_ticks;
|
||||
|
||||
/* Convert timespec values to system clock ticks */
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define PROFTICK NSEC2TICK((clock_t)(NSEC_PER_SEC / CONFIG_SCHED_PROFILE_TICKSPERSEC))
|
||||
#define PROFTICK NSEC2TICK(NSEC_PER_SEC / CONFIG_SCHED_PROFILE_TICKSPERSEC)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ int set_sporadic_param(FAR const struct sched_param *param,
|
|||
if ((rtcb->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_SPORADIC)
|
||||
{
|
||||
FAR struct sporadic_s *sporadic;
|
||||
sclock_t repl_ticks;
|
||||
sclock_t budget_ticks;
|
||||
clock_t repl_ticks;
|
||||
clock_t budget_ticks;
|
||||
|
||||
if (param->sched_ss_max_repl >= 1 &&
|
||||
param->sched_ss_max_repl <= CONFIG_SCHED_SPORADIC_MAXREPL)
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ int process_sporadic(FAR struct tcb_s *tcb,
|
|||
FAR const struct sched_param *param)
|
||||
{
|
||||
FAR struct sporadic_s *sporadic;
|
||||
sclock_t repl_ticks;
|
||||
sclock_t budget_ticks;
|
||||
clock_t repl_ticks;
|
||||
clock_t budget_ticks;
|
||||
int ret = -EINVAL;
|
||||
|
||||
if (param->sched_ss_max_repl >= 1 &&
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@
|
|||
int timer_gettime(timer_t timerid, FAR struct itimerspec *value)
|
||||
{
|
||||
FAR struct posix_timer_s *timer = timer_gethandle(timerid);
|
||||
sclock_t ticks;
|
||||
clock_t ticks;
|
||||
int ret = OK;
|
||||
|
||||
if (!timer || !value)
|
||||
|
|
|
|||
|
|
@ -52,12 +52,12 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
sclock_t wd_gettime(FAR struct wdog_s *wdog)
|
||||
clock_t wd_gettime(FAR struct wdog_s *wdog)
|
||||
{
|
||||
irqstate_t flags;
|
||||
clock_t expired;
|
||||
bool is_active;
|
||||
sclock_t delay = 0;
|
||||
clock_t delay = 0;
|
||||
|
||||
if (wdog != NULL && WDOG_ISACTIVE(wdog))
|
||||
{
|
||||
|
|
@ -68,7 +68,7 @@ sclock_t wd_gettime(FAR struct wdog_s *wdog)
|
|||
|
||||
if (is_active)
|
||||
{
|
||||
delay = (sclock_t)(expired - clock_systime_ticks());
|
||||
delay = expired - clock_systime_ticks();
|
||||
delay = delay >= 0 ? delay : 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -368,7 +368,7 @@ uint64_t wd_timer(const hrtimer_t *timer, uint64_t expired)
|
|||
|
||||
clock_t tick = div_const(expired, NSEC_PER_TICK);
|
||||
clock_t delay = wd_expiration(tick) - tick;
|
||||
uint64_t nsec = TICK2NSEC((uint64_t)delay);
|
||||
uint64_t nsec = TICK2NSEC(delay);
|
||||
return nsec <= HRTIMER_MAX_DELAY ? nsec : HRTIMER_MAX_DELAY;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -127,11 +127,11 @@ uint64_t wd_timer(const hrtimer_t *timer, uint64_t expired);
|
|||
#ifdef CONFIG_HRTIMER
|
||||
static inline_function void wd_timer_start(clock_t tick, bool in_expiration)
|
||||
{
|
||||
DEBUGASSERT((uint64_t)tick <= UINT64_MAX / NSEC_PER_TICK);
|
||||
DEBUGASSERT(tick <= INT64_MAX / NSEC_PER_TICK);
|
||||
if (!in_expiration)
|
||||
{
|
||||
hrtimer_start(&g_wdtimer, wd_timer,
|
||||
TICK2NSEC((uint64_t)tick), HRTIMER_MODE_ABS);
|
||||
TICK2NSEC(tick), HRTIMER_MODE_ABS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ static inline_function clock_t wd_get_next_expire(clock_t curr)
|
|||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
return (sclock_t)(next - curr) <= 0 ? 0u : next;
|
||||
return next - curr <= 0 ? 0 : next;
|
||||
}
|
||||
|
||||
#undef EXTERN
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue