From f348e6806972214d95d90cbe6098ae769cffb251 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 21 Jan 2016 11:54:26 -0600 Subject: [PATCH] Update to use 64-bit timer when available --- drivers/mmcsd/mmcsd_sdio.c | 12 ++++---- drivers/mmcsd/mmcsd_spi.c | 18 +++++------ drivers/mtd/sst39vf.c | 8 ++--- drivers/net/enc28j60.c | 6 ++-- drivers/net/encx24j600.c | 10 +++--- drivers/net/slip.c | 4 +-- drivers/power/pm.h | 5 +-- drivers/power/pm_activity.c | 2 +- drivers/power/pm_checkstate.c | 4 +-- fs/procfs/fs_procfsuptime.c | 27 +++++----------- fs/vfs/fs_poll.c | 2 +- include/nuttx/clock.h | 49 ++++++++++++++++++++---------- include/nuttx/sched.h | 19 ++++++------ include/nuttx/semaphore.h | 5 +-- include/nuttx/wqueue.h | 8 +++-- include/sys/syscall.h | 6 +++- libc/wqueue/work_usrthread.c | 12 ++++---- net/icmp/icmp_ping.c | 6 ++-- net/icmpv6/icmpv6_ping.c | 6 ++-- net/neighbor/neighbor.h | 3 +- net/neighbor/neighbor_initialize.c | 2 +- net/neighbor/neighbor_periodic.c | 6 ++-- net/socket/net_close.c | 2 +- net/socket/net_sendfile.c | 4 +-- net/socket/net_timeo.c | 6 ++-- net/socket/recvfrom.c | 4 +-- net/socket/socket.h | 3 +- net/tcp/tcp_send_unbuffered.c | 4 +-- net/udp/udp_psock_sendto.c | 4 +-- sched/Kconfig | 2 +- sched/clock/clock_systimer.c | 8 ++--- sched/paging/pg_worker.c | 2 +- sched/sched/sched_sporadic.c | 4 +-- sched/semaphore/sem_tickwait.c | 6 ++-- sched/signal/sig_nanosleep.c | 8 ++--- sched/wqueue/kwork_process.c | 30 +++++------------- sched/wqueue/wqueue.h | 12 +++++--- syscall/syscall.csv | 3 +- syscall/syscall_clock_systimer.c | 13 ++++++-- syscall/syscall_funclookup.c | 6 +++- syscall/syscall_lookup.h | 6 +++- 41 files changed, 182 insertions(+), 165 deletions(-) diff --git a/drivers/mmcsd/mmcsd_sdio.c b/drivers/mmcsd/mmcsd_sdio.c index d8ae4561af7..e3097d48126 100644 --- a/drivers/mmcsd/mmcsd_sdio.c +++ b/drivers/mmcsd/mmcsd_sdio.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/mmcsd/mmcsd_sdio.c * - * Copyright (C) 2009-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -1120,10 +1120,10 @@ static int mmcsd_eventwait(FAR struct mmcsd_state_s *priv, static int mmcsd_transferready(FAR struct mmcsd_state_s *priv) { - uint32_t starttime; - uint32_t elapsed; + systime_t starttime; + systime_t elapsed; uint32_t r1; - int ret; + int ret; /* First, check if the card has been removed. */ @@ -2714,9 +2714,9 @@ static int mmcsd_sdinitialize(FAR struct mmcsd_state_s *priv) static int mmcsd_cardidentify(FAR struct mmcsd_state_s *priv) { uint32_t response; - uint32_t start; - uint32_t elapsed; uint32_t sdcapacity = MMCSD_ACMD41_STDCAPACITY; + systime_t start; + systime_t elapsed; int ret; /* Assume failure to identify the card */ diff --git a/drivers/mmcsd/mmcsd_spi.c b/drivers/mmcsd/mmcsd_spi.c index 72196488452..b5ab0cd8e3a 100644 --- a/drivers/mmcsd/mmcsd_spi.c +++ b/drivers/mmcsd/mmcsd_spi.c @@ -443,8 +443,8 @@ static int mmcsd_waitready(FAR struct mmcsd_slot_s *slot) { FAR struct spi_dev_s *spi = slot->spi; uint8_t response; - uint32_t start; - uint32_t elapsed; + systime_t start; + systime_t elapsed; /* Wait until the card is no longer busy (up to 500MS) */ @@ -548,8 +548,8 @@ static uint32_t mmcsd_sendcmd(FAR struct mmcsd_slot_s *slot, case MMCSD_CMDRESP_R1B: { uint32_t busy = 0; - uint32_t start; - uint32_t elapsed; + systime_t start; + systime_t elapsed; start = START_TIME; do @@ -963,9 +963,9 @@ static int mmcsd_recvblock(FAR struct mmcsd_slot_s *slot, uint8_t *buffer, int nbytes) { FAR struct spi_dev_s *spi = slot->spi; - uint32_t start; - uint32_t elapsed; - uint8_t token; + systime_t start; + systime_t elapsed; + uint8_t token; /* Wait up to the maximum to receive a valid data token. taccess is the * time from when the command is sent until the first byte of data is @@ -1579,8 +1579,8 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot) FAR struct spi_dev_s *spi = slot->spi; uint8_t csd[16]; uint32_t result = MMCSD_SPIR1_IDLESTATE; - uint32_t start; - uint32_t elapsed; + systime_t start; + systime_t elapsed; int i; int j; diff --git a/drivers/mtd/sst39vf.c b/drivers/mtd/sst39vf.c index e2fe862c9eb..5386427587b 100644 --- a/drivers/mtd/sst39vf.c +++ b/drivers/mtd/sst39vf.c @@ -417,8 +417,8 @@ static int sst39vf_chiperase(FAR struct sst39vf_dev_s *priv) { #if 0 struct sst39vf_wrinfo_s wrinfo; - uint32_t start; - uint32_t elapsed; + systime_t start; + systime_t elapsed; #endif /* Send the sequence to erase the chip */ @@ -488,8 +488,8 @@ static int sst39vf_sectorerase(FAR struct sst39vf_dev_s *priv, { struct sst39vf_wrinfo_s wrinfo; #if 0 - uint32_t start; - uint32_t elapsed; + systime_t start; + systime_t elapsed; #endif /* Set up the sector address */ diff --git a/drivers/net/enc28j60.c b/drivers/net/enc28j60.c index 4a940a71ee7..b619c59b31b 100644 --- a/drivers/net/enc28j60.c +++ b/drivers/net/enc28j60.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/net/enc28j60.c * - * Copyright (C) 2010-2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2012, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * References: @@ -750,8 +750,8 @@ static void enc_wrbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg, static int enc_waitbreg(FAR struct enc_driver_s *priv, uint8_t ctrlreg, uint8_t bits, uint8_t value) { - uint32_t start = clock_systimer(); - uint32_t elapsed; + systime_t start = clock_systimer(); + systime_t elapsed; uint8_t rddata; /* Loop until the exit condition is met */ diff --git a/drivers/net/encx24j600.c b/drivers/net/encx24j600.c index 4de0d694cad..fcd36f87a0c 100644 --- a/drivers/net/encx24j600.c +++ b/drivers/net/encx24j600.c @@ -679,8 +679,8 @@ static void enc_wrreg(FAR struct enc_driver_s *priv, uint16_t ctrlreg, static int enc_waitreg(FAR struct enc_driver_s *priv, uint16_t ctrlreg, uint16_t bits, uint16_t value) { - uint32_t start = clock_systimer(); - uint32_t elapsed; + systime_t start = clock_systimer(); + systime_t elapsed; uint16_t rddata; /* Loop until the exit condition is met */ @@ -1533,7 +1533,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) arp_ipin(&priv->dev); ret = ipv4_input(&priv->dev); - if (ret == OK || (clock_systimer() - descr->ts) > ENC_RXTIMEOUT) + if (ret == OK || (clock_systimer() - (systime_t)descr->ts) > ENC_RXTIMEOUT) { /* If packet has been successfully processed or has timed out, * free it. @@ -1580,7 +1580,7 @@ static void enc_rxdispatch(FAR struct enc_driver_s *priv) ret = ipv6_input(&priv->dev); - if (ret == OK || (clock_systimer() - descr->ts) > ENC_RXTIMEOUT) + if (ret == OK || (clock_systimer() - (systime_t)descr->ts) > ENC_RXTIMEOUT) { /* If packet has been successfully processed or has timed out, * free it. @@ -1728,7 +1728,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv) /* Set current timestamp */ - descr->ts = clock_systimer(); + descr->ts = (uint32_t)clock_systimer(); /* Store the start address of the frame without the enc's header */ diff --git a/drivers/net/slip.c b/drivers/net/slip.c index 6026ec3d5bf..d1ecef3aca7 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -434,8 +434,8 @@ static void slip_txtask(int argc, FAR char *argv[]) FAR struct slip_driver_s *priv; unsigned int index = *(argv[1]) - '0'; net_lock_t flags; - unsigned int msec_start; - unsigned int msec_now; + systime_t msec_start; + systime_t msec_now; unsigned int hsec; ndbg("index: %d\n", index); diff --git a/drivers/power/pm.h b/drivers/power/pm.h index 8ed66d3d301..9df1ec5c0cc 100644 --- a/drivers/power/pm.h +++ b/drivers/power/pm.h @@ -45,8 +45,9 @@ #include #include -#include +#include #include +#include #ifdef CONFIG_PM @@ -136,7 +137,7 @@ struct pm_global_s /* stime - The time (in ticks) at the start of the current time slice */ - uint32_t stime; + systime_t stime; /* This semaphore manages mutually exclusive access to the power management * registry. It must be initialized to the value 1. diff --git a/drivers/power/pm_activity.c b/drivers/power/pm_activity.c index e15cc78b1ec..2bf96b08c28 100644 --- a/drivers/power/pm_activity.c +++ b/drivers/power/pm_activity.c @@ -103,7 +103,7 @@ void pm_activity(int priority) { - uint32_t now; + systime_t now; uint32_t accum; irqstate_t flags; diff --git a/drivers/power/pm_checkstate.c b/drivers/power/pm_checkstate.c index 85f44153233..b085cbe0beb 100644 --- a/drivers/power/pm_checkstate.c +++ b/drivers/power/pm_checkstate.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/power/pm_checkstate.c * - * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -108,7 +108,7 @@ enum pm_state_e pm_checkstate(void) { - uint32_t now; + systime_t now; irqstate_t flags; /* Check for the end of the current time slice. This must be performed diff --git a/fs/procfs/fs_procfsuptime.c b/fs/procfs/fs_procfsuptime.c index c5f8c719a59..fd273badbba 100644 --- a/fs/procfs/fs_procfsuptime.c +++ b/fs/procfs/fs_procfsuptime.c @@ -212,23 +212,16 @@ static ssize_t uptime_read(FAR struct file *filep, FAR char *buffer, size_t linesize; off_t offset; ssize_t ret; - -#ifdef CONFIG_SYSTEM_TIME64 - uint64_t ticktime; -#if !defined(CONFIG_HAVE_DOUBLE) || !defined(CONFIG_LIBC_FLOATINGPOINT) - uint64_t sec; -#endif - -#else - uint32_t ticktime; -#if !defined(CONFIG_HAVE_DOUBLE) || !defined(CONFIG_LIBC_FLOATINGPOINT) - uint32_t sec; -#endif -#endif + systime ticktime; #if defined(CONFIG_HAVE_DOUBLE) && defined(CONFIG_LIBC_FLOATINGPOINT) double now; #else +# if defined(CONFIG_SYSTEM_TIME64) + uint64_t sec; +# else + uint32_t sec; +# endif unsigned int remainder; unsigned int csec; #endif @@ -249,15 +242,9 @@ static ssize_t uptime_read(FAR struct file *filep, FAR char *buffer, if (filep->f_pos == 0) { -#ifdef CONFIG_SYSTEM_TIME64 - /* 64-bit timer */ - - ticktime = clock_systimer64(); -#else - /* 32-bit timer */ + /* System time */ ticktime = clock_systimer(); -#endif #if defined(CONFIG_HAVE_DOUBLE) && defined(CONFIG_LIBC_FLOATINGPOINT) /* Convert the system up time to a seconds + hundredths of seconds string */ diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index f13148288c8..2385f85a259 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -1,7 +1,7 @@ /**************************************************************************** * fs/vfs/fs_poll.c * - * Copyright (C) 2008-2009, 2012-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009, 2012-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index 49659f04cb0..cc6eccd14c0 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -1,7 +1,8 @@ /**************************************************************************** * include/nuttx/clock.h * - * Copyright (C) 2007-2009, 2011-2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2012, 2014, 2016 Gregory Nutt. + All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -164,6 +165,14 @@ #define TICK2DSEC(tick) (((tick)+(TICK_PER_DSEC/2))/TICK_PER_DSEC) /* Rounds */ #define TICK2SEC(tick) (((tick)+(TICK_PER_SEC/2))/TICK_PER_SEC) /* Rounds */ +/* Select the access to the system timer using its natural with */ + +#ifdef CONFIG_SYSTEM_TIME64 +# define clock_systimer() clock_systimer64() +#else +# define clock_systimer() clock_systimer32() +#endif + /**************************************************************************** * Public Types ****************************************************************************/ @@ -177,10 +186,26 @@ struct cpuload_s }; #endif +/* This type is the natural with of the system timer */ + +#ifdef CONFIG_SYSTEM_TIME64 +typedef uint64_t systime_t; +#else +typedef uint32_t systime_t; +#endif + /**************************************************************************** * Public Data ****************************************************************************/ +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + /* Access to raw system clock ***********************************************/ /* Direct access to the system timer/counter is supported only if (1) the * system timer counter is available (i.e., we are not configured to use @@ -191,14 +216,14 @@ struct cpuload_s #ifdef __HAVE_KERNEL_GLOBALS # ifdef CONFIG_SYSTEM_TIME64 -extern volatile uint64_t g_system_timer; -#define clock_systimer() (uint32_t)(g_system_timer & 0x00000000ffffffff) +EXTERN volatile uint64_t g_system_timer; +#define clock_systimer32() (uint32_t)(g_system_timer & 0x00000000ffffffff) #define clock_systimer64() g_system_timer # else -extern volatile uint32_t g_system_timer; -#define clock_systimer() g_system_timer +EXTERN volatile uint32_t g_system_timer; +#define clock_systimer32() g_system_timer # endif #endif @@ -207,14 +232,6 @@ extern volatile uint32_t g_system_timer; * Public Function Prototypes ****************************************************************************/ -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - /**************************************************************************** * Function: clock_synchronize * @@ -248,7 +265,7 @@ void clock_synchronize(void); #endif /**************************************************************************** - * Function: clock_systimer + * Function: clock_systimer32 * * Description: * Return the current value of the 32-bit system timer counter. Indirect @@ -268,9 +285,9 @@ void clock_synchronize(void); #ifndef __HAVE_KERNEL_GLOBALS # ifdef CONFIG_SYSTEM_TIME64 -# define clock_systimer() (uint32_t)(clock_systimer64() & 0x00000000ffffffff) +# define clock_systimer32() (uint32_t)(clock_systimer64() & 0x00000000ffffffff) # else -uint32_t clock_systimer(void); +uint32_t clock_systimer32(void); # endif #endif diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 07ec74cd82c..b25f64e219a 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -1,7 +1,7 @@ /******************************************************************************** * include/nuttx/sched.h * - * Copyright (C) 2007-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -51,6 +51,7 @@ #include #include +#include #include #include #include @@ -273,14 +274,14 @@ struct replenishment_s struct sporadic_s { - bool suspended; /* Thread is currently suspended */ - uint8_t hi_priority; /* Sporadic high priority */ - uint8_t low_priority; /* Sporadic low priority */ - uint8_t max_repl; /* Maximum number of replenishments */ - uint8_t nrepls; /* Number of active replenishments */ - uint32_t repl_period; /* Sporadic replenishment period */ - uint32_t budget; /* Sporadic execution budget period */ - uint32_t eventtime; /* Time thread suspended or [re-]started */ + bool suspended; /* Thread is currently suspended */ + uint8_t hi_priority; /* Sporadic high priority */ + uint8_t low_priority; /* Sporadic low priority */ + uint8_t max_repl; /* Maximum number of replenishments */ + uint8_t nrepls; /* Number of active replenishments */ + uint32_t repl_period; /* Sporadic replenishment period */ + uint32_t budget; /* Sporadic execution budget period */ + systime_t eventtime; /* Time thread suspended or [re-]started */ /* This is the last interval timer activated */ diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index cfd0feb19d8..691e2f96243 100644 --- a/include/nuttx/semaphore.h +++ b/include/nuttx/semaphore.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/semaphore.h * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,7 @@ #include +#include #include /**************************************************************************** @@ -110,7 +111,7 @@ extern "C" * ****************************************************************************/ -int sem_tickwait(FAR sem_t *sem, uint32_t start, uint32_t delay); +int sem_tickwait(FAR sem_t *sem, systime_t start, uint32_t delay); #undef EXTERN #ifdef __cplusplus diff --git a/include/nuttx/wqueue.h b/include/nuttx/wqueue.h index a194783978b..59fa8f0a920 100644 --- a/include/nuttx/wqueue.h +++ b/include/nuttx/wqueue.h @@ -47,6 +47,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -290,8 +292,8 @@ struct work_s struct dq_entry_s dq; /* Implements a doubly linked list */ worker_t worker; /* Work callback */ FAR void *arg; /* Callback argument */ - uint32_t qtime; /* Time work queued */ - uint32_t delay; /* Delay until work performed */ + systime_t qtime; /* Time work queued */ + systime_t delay; /* Delay until work performed */ }; /**************************************************************************** @@ -359,7 +361,7 @@ int work_usrstart(void); ****************************************************************************/ int work_queue(int qid, FAR struct work_s *work, worker_t worker, - FAR void *arg, uint32_t delay); + FAR void *arg, systime_t delay); /**************************************************************************** * Name: work_cancel diff --git a/include/sys/syscall.h b/include/sys/syscall.h index c7d9b086c49..362a8b2dac7 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -211,7 +211,11 @@ * NuttX configuration. */ -#define SYS_clock_systimer (__SYS_clock+0) +#ifdef CONFIG_SYSTEM_TIME64 +# define SYS_clock_systimer64 (__SYS_clock+0) +#endif +# define SYS_clock_systimer32 (__SYS_clock+0) +#endif #define SYS_clock_getres (__SYS_clock+1) #define SYS_clock_gettime (__SYS_clock+2) #define SYS_clock_settime (__SYS_clock+3) diff --git a/libc/wqueue/work_usrthread.c b/libc/wqueue/work_usrthread.c index 21bd65916e3..f0815ac0c7a 100644 --- a/libc/wqueue/work_usrthread.c +++ b/libc/wqueue/work_usrthread.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/wqueue/work_usrthread.c * - * Copyright (C) 2009-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -122,11 +122,11 @@ void work_process(FAR struct usr_wqueue_s *wqueue) volatile FAR struct work_s *work; worker_t worker; FAR void *arg; - uint32_t elapsed; - uint32_t remaining; - uint32_t stick; - uint32_t ctick; - uint32_t next; + systime_t elapsed; + systime_t remaining; + systime_t stick; + systime_t ctick; + systime_t next; int ret; /* Then process queued work. Lock the work queue while we process items diff --git a/net/icmp/icmp_ping.c b/net/icmp/icmp_ping.c index 767bceec160..4b62bd1c827 100644 --- a/net/icmp/icmp_ping.c +++ b/net/icmp/icmp_ping.c @@ -83,8 +83,8 @@ struct icmp_ping_s FAR struct devif_callback_s *png_cb; /* Reference to callback instance */ sem_t png_sem; /* Use to manage the wait for the response */ - uint32_t png_time; /* Start time for determining timeouts */ - uint32_t png_ticks; /* System clock ticks to wait */ + systime_t png_time; /* Start time for determining timeouts */ + systime_t png_ticks; /* System clock ticks to wait */ int png_result; /* 0: success; <0:negated errno on fail */ in_addr_t png_addr; /* The peer to be ping'ed */ uint16_t png_id; /* Used to match requests with replies */ @@ -124,7 +124,7 @@ struct icmp_ping_s static inline int ping_timeout(FAR struct icmp_ping_s *pstate) { - uint32_t elapsed = clock_systimer() - pstate->png_time; + systime_t elapsed = clock_systimer() - pstate->png_time; if (elapsed >= pstate->png_ticks) { return TRUE; diff --git a/net/icmpv6/icmpv6_ping.c b/net/icmpv6/icmpv6_ping.c index 956c18c6564..b6f8edd299d 100644 --- a/net/icmpv6/icmpv6_ping.c +++ b/net/icmpv6/icmpv6_ping.c @@ -86,8 +86,8 @@ struct icmpv6_ping_s FAR struct devif_callback_s *png_cb; /* Reference to callback instance */ sem_t png_sem; /* Use to manage the wait for the response */ - uint32_t png_time; /* Start time for determining timeouts */ - uint32_t png_ticks; /* System clock ticks to wait */ + systime_t png_time; /* Start time for determining timeouts */ + systime_t png_ticks; /* System clock ticks to wait */ int png_result; /* 0: success; <0:negated errno on fail */ net_ipv6addr_t png_addr; /* The peer to be ping'ed */ uint16_t png_id; /* Used to match requests with replies */ @@ -127,7 +127,7 @@ struct icmpv6_ping_s static inline int ping_timeout(FAR struct icmpv6_ping_s *pstate) { - uint32_t elapsed = clock_systimer() - pstate->png_time; + systime_t elapsed = clock_systimer() - pstate->png_time; if (elapsed >= pstate->png_ticks) { return TRUE; diff --git a/net/neighbor/neighbor.h b/net/neighbor/neighbor.h index 0a2a1c287fb..d6330f16a97 100644 --- a/net/neighbor/neighbor.h +++ b/net/neighbor/neighbor.h @@ -49,6 +49,7 @@ #include +#include #include #ifdef CONFIG_NET_IPv6 @@ -100,7 +101,7 @@ extern struct neighbor_entry g_neighbors[CONFIG_NET_IPv6_NCONF_ENTRIES]; /* This is the time, in clock ticks, of the last poll */ -extern uint32_t g_neighbor_polltime; +extern systime_t g_neighbor_polltime; /**************************************************************************** * Public Function Prototypes diff --git a/net/neighbor/neighbor_initialize.c b/net/neighbor/neighbor_initialize.c index ce4ebdb562f..124e0f9a890 100644 --- a/net/neighbor/neighbor_initialize.c +++ b/net/neighbor/neighbor_initialize.c @@ -58,7 +58,7 @@ struct neighbor_entry g_neighbors[CONFIG_NET_IPv6_NCONF_ENTRIES]; /* This is the time, in clock ticks, of the last poll */ -uint32_t g_neighbor_polltime; +systime_t g_neighbor_polltime; /**************************************************************************** * Public Functions diff --git a/net/neighbor/neighbor_periodic.c b/net/neighbor/neighbor_periodic.c index 2a9f0d99fdd..c242b099d23 100644 --- a/net/neighbor/neighbor_periodic.c +++ b/net/neighbor/neighbor_periodic.c @@ -75,8 +75,8 @@ void neighbor_periodic(void) { - uint32_t now; - uint32_t ticks; + systime_t now; + systime_t ticks; uint32_t hsecs; int i; @@ -84,7 +84,7 @@ void neighbor_periodic(void) now = clock_systimer(); ticks = now - g_neighbor_polltime; - hsecs = TICK2HSEC(ticks); + hsecs = (uint32_t)TICK2HSEC(ticks); /* Reset the time of the last poll */ diff --git a/net/socket/net_close.c b/net/socket/net_close.c index c76baacaf2d..0635bab504a 100644 --- a/net/socket/net_close.c +++ b/net/socket/net_close.c @@ -82,7 +82,7 @@ struct tcp_close_s FAR struct socket *cl_psock; /* Reference to the TCP socket */ sem_t cl_sem; /* Signals disconnect completion */ int cl_result; /* The result of the close */ - uint32_t cl_start; /* Time close started (in ticks) */ + systime_t cl_start; /* Time close started (in ticks) */ #endif }; #endif diff --git a/net/socket/net_sendfile.c b/net/socket/net_sendfile.c index 0769662ce54..a8b7b9f1628 100644 --- a/net/socket/net_sendfile.c +++ b/net/socket/net_sendfile.c @@ -2,7 +2,7 @@ * net/socket/net_sendfile.c * * Copyright (C) 2013 UVC Ingenieure. All rights reserved. - * Copyright (C) 2007-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2016 Gregory Nutt. All rights reserved. * Authors: Gregory Nutt * Max Holtzberg * @@ -103,7 +103,7 @@ struct sendfile_s uint32_t snd_isn; /* Initial sequence number */ uint32_t snd_acked; /* The number of bytes acked */ #ifdef CONFIG_NET_SOCKOPTS - uint32_t snd_time; /* Last send time for determining timeout */ + systime_t snd_time; /* Last send time for determining timeout */ #endif }; diff --git a/net/socket/net_timeo.c b/net/socket/net_timeo.c index 70f670dacdd..47099d205d5 100644 --- a/net/socket/net_timeo.c +++ b/net/socket/net_timeo.c @@ -69,10 +69,10 @@ * ****************************************************************************/ -int net_timeo(uint32_t start_time, socktimeo_t timeo) +int net_timeo(systime_t start_time, socktimeo_t timeo) { - uint32_t timeo_ticks = DSEC2TICK(timeo); - uint32_t elapsed = clock_systimer() - start_time; + systime_t timeo_ticks = DSEC2TICK(timeo); + systime_t elapsed = clock_systimer() - start_time; if (elapsed >= timeo_ticks) { diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index a14b673542e..a6921315fd1 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/socket/recvfrom.c * - * Copyright (C) 2007-2009, 2011-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -93,7 +93,7 @@ struct recvfrom_s { FAR struct socket *rf_sock; /* The parent socket structure */ #ifdef CONFIG_NET_SOCKOPTS - uint32_t rf_starttime; /* rcv start time for determining timeout */ + systime_t rf_starttime; /* rcv start time for determining timeout */ #endif FAR struct devif_callback_s *rf_cb; /* Reference to callback instance */ sem_t rf_sem; /* Semaphore signals recv completion */ diff --git a/net/socket/socket.h b/net/socket/socket.h index 3793573961c..e9bfa161db3 100644 --- a/net/socket/socket.h +++ b/net/socket/socket.h @@ -47,6 +47,7 @@ #include #include +#include #include /**************************************************************************** @@ -345,7 +346,7 @@ int net_close(int sockfd); ****************************************************************************/ #ifdef CONFIG_NET_SOCKOPTS -int net_timeo(uint32_t start_time, socktimeo_t timeo); +int net_timeo(systime_t start_time, socktimeo_t timeo); #endif /**************************************************************************** diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index 559820b1ddd..bb53b11d58c 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/tcp/tcp_send_unbuffered.c * - * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -103,7 +103,7 @@ struct send_s uint32_t snd_isn; /* Initial sequence number */ uint32_t snd_acked; /* The number of bytes acked */ #ifdef CONFIG_NET_SOCKOPTS - uint32_t snd_time; /* Last send time for determining timeout */ + systime_t snd_time; /* Last send time for determining timeout */ #endif #if defined(CONFIG_NET_TCP_SPLIT) bool snd_odd; /* True: Odd packet in pair transaction */ diff --git a/net/udp/udp_psock_sendto.c b/net/udp/udp_psock_sendto.c index 7714db60c6b..71fbe55af18 100644 --- a/net/udp/udp_psock_sendto.c +++ b/net/udp/udp_psock_sendto.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/udp/udp_psock_sendto.c * - * Copyright (C) 2007-2009, 2011-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -99,7 +99,7 @@ struct sendto_s FAR struct socket *st_sock; /* Points to the parent socket structure */ #endif #ifdef CONFIG_NET_SENDTO_TIMEOUT - uint32_t st_time; /* Last send time for determining timeout */ + systime_t st_time; /* Last send time for determining timeout */ #endif FAR struct devif_callback_s *st_cb; /* Reference to callback instance */ sem_t st_sem; /* Semaphore signals sendto completion */ diff --git a/sched/Kconfig b/sched/Kconfig index 5dd5ab72bfe..26e32376429 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -147,7 +147,7 @@ config SYSTEM_TIME64 USEC_PER_TICK, typically at 100Hz. The count at any given time is then the "uptime" in units of system timer ticks. By default, the system time is 32-bits wide. Those defaults provide a range of about - 13.6 years which is probably a sufficient range for "uptime". + 497 days which is probably a sufficient range for "uptime". However, if the system timer rate is significantly higher than 100Hz and/or if a very long "uptime" is required, then this option can be diff --git a/sched/clock/clock_systimer.c b/sched/clock/clock_systimer.c index a87f36a0afb..650587b32a8 100644 --- a/sched/clock/clock_systimer.c +++ b/sched/clock/clock_systimer.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/clock/clock_systimer.c * - * Copyright (C) 2011, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -51,7 +51,7 @@ ****************************************************************************/ /* See nuttx/clock.h */ -#undef clock_systimer +#undef cloc_systimer32 #undef clock_systimer64 /**************************************************************************** @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: clock_systimer + * Name: cloc_systimer32 * * Description: * Return the current value of the 32-bit system timer counter @@ -78,7 +78,7 @@ * ****************************************************************************/ -uint32_t clock_systimer(void) +uint32_t cloc_systimer32(void) { #ifdef CONFIG_SCHED_TICKLESS struct timespec ts; diff --git a/sched/paging/pg_worker.c b/sched/paging/pg_worker.c index 1a661a8af23..a50f917d092 100644 --- a/sched/paging/pg_worker.c +++ b/sched/paging/pg_worker.c @@ -110,7 +110,7 @@ static int g_fillresult; */ #ifdef CONFIG_PAGING_TIMEOUT_TICKS -status uint32_t g_starttime; +static systime_t g_starttime; #endif #endif diff --git a/sched/sched/sched_sporadic.c b/sched/sched/sched_sporadic.c index 7cfa152b093..235d987044b 100644 --- a/sched/sched/sched_sporadic.c +++ b/sched/sched/sched_sporadic.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_sporadic.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -975,9 +975,9 @@ int sched_sporadic_resume(FAR struct tcb_s *tcb) { FAR struct sporadic_s *sporadic; FAR struct replenishment_s *repl; + systime_t now; uint32_t unrealized; uint32_t last; - uint32_t now; DEBUGASSERT(tcb && tcb->sporadic); sporadic = tcb->sporadic; diff --git a/sched/semaphore/sem_tickwait.c b/sched/semaphore/sem_tickwait.c index a72370383e0..804e1ed83c0 100644 --- a/sched/semaphore/sem_tickwait.c +++ b/sched/semaphore/sem_tickwait.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/semaphore/sem_tickdwait.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -80,11 +80,11 @@ * ****************************************************************************/ -int sem_tickwait(FAR sem_t *sem, uint32_t start, uint32_t delay) +int sem_tickwait(FAR sem_t *sem, systime_t start, uint32_t delay) { FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; irqstate_t flags; - uint32_t elapsed; + systime_t elapsed; int ret; DEBUGASSERT(sem != NULL && up_interrupt_context() == false && diff --git a/sched/signal/sig_nanosleep.c b/sched/signal/sig_nanosleep.c index 25f9f30231b..da87609ea3a 100644 --- a/sched/signal/sig_nanosleep.c +++ b/sched/signal/sig_nanosleep.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/signal/sig/nanosleep.c * - * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -124,7 +124,7 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp) { irqstate_t flags; - uint32_t starttick; + systime_t starttick; sigset_t set; struct siginfo value; int errval; @@ -183,8 +183,8 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp) if (rmtp) { - uint32_t elapsed; - uint32_t remaining; + systime_t elapsed; + systime_t remaining; int ticks; /* First get the number of clock ticks that we were requested to diff --git a/sched/wqueue/kwork_process.c b/sched/wqueue/kwork_process.c index ff854fe83ad..b5c44be5ae1 100644 --- a/sched/wqueue/kwork_process.c +++ b/sched/wqueue/kwork_process.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/wqueue/work_process.c * - * Copyright (C) 2009-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2009-2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -72,22 +72,6 @@ # define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -109,17 +93,17 @@ * ****************************************************************************/ -void work_process(FAR struct kwork_wqueue_s *wqueue, uint32_t period, int wndx) +void work_process(FAR struct kwork_wqueue_s *wqueue, systime_t period, int wndx) { volatile FAR struct work_s *work; worker_t worker; irqstate_t flags; FAR void *arg; - uint32_t elapsed; - uint32_t remaining; - uint32_t stick; - uint32_t ctick; - uint32_t next; + systime_t elapsed; + systime_t remaining; + systime_t stick; + systime_t ctick; + systime_t next; /* Then process queued work. We need to keep interrupts disabled while * we process items in the work list. diff --git a/sched/wqueue/wqueue.h b/sched/wqueue/wqueue.h index 14bf74b44c8..701af9b300d 100644 --- a/sched/wqueue/wqueue.h +++ b/sched/wqueue/wqueue.h @@ -1,7 +1,7 @@ /**************************************************************************** * sched/wqueue/wqueue.h * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,6 +46,8 @@ #include #include +#include + #ifdef CONFIG_SCHED_WORKQUEUE /**************************************************************************** @@ -72,7 +74,7 @@ struct kworker_s struct kwork_wqueue_s { - uint32_t delay; /* Delay between polling cycles (ticks) */ + systime_t delay; /* Delay between polling cycles (ticks) */ struct dq_queue_s q; /* The queue of pending work */ struct kworker_s worker[1]; /* Describes a worker thread */ }; @@ -84,7 +86,7 @@ struct kwork_wqueue_s #ifdef CONFIG_SCHED_HPWORK struct hp_wqueue_s { - uint32_t delay; /* Delay between polling cycles (ticks) */ + systime_t delay; /* Delay between polling cycles (ticks) */ struct dq_queue_s q; /* The queue of pending work */ struct kworker_s worker[1]; /* Describes the single high priority worker */ }; @@ -97,7 +99,7 @@ struct hp_wqueue_s #ifdef CONFIG_SCHED_LPWORK struct lp_wqueue_s { - uint32_t delay; /* Delay between polling cycles (ticks) */ + systime_t delay; /* Delay between polling cycles (ticks) */ struct dq_queue_s q; /* The queue of pending work */ /* Describes each thread in the low priority queue's thread pool */ @@ -183,7 +185,7 @@ int work_lpstart(void); * ****************************************************************************/ -void work_process(FAR struct kwork_wqueue_s *wqueue, uint32_t period, int wndx); +void work_process(FAR struct kwork_wqueue_s *wqueue, systime_t period, int wndx); #endif /* CONFIG_SCHED_WORKQUEUE */ #endif /* __SCHED_WQUEUE_WQUEUE_H */ diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 647ee8f4c4e..43e8e9175f1 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -11,7 +11,8 @@ "clock_getres","time.h","","int","clockid_t","struct timespec*" "clock_gettime","time.h","","int","clockid_t","struct timespec*" "clock_settime","time.h","","int","clockid_t","const struct timespec*" -"clock_systimer","nuttx/clock.h","!defined(__HAVE_KERNEL_GLOBALS)","uint32_t" +"clock_systimer32","nuttx/clock.h","!defined(__HAVE_KERNEL_GLOBALS) && !defined(CONFIG_SYSTEM_TIME64)","uint32_t" +"clock_systimer64","nuttx/clock.h","!defined(__HAVE_KERNEL_GLOBALS) && defined(CONFIG_SYSTEM_TIME64)","uint64_t" "close","unistd.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","int","int" "closedir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR DIR*" "connect","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","FAR const struct sockaddr*","socklen_t" diff --git a/syscall/syscall_clock_systimer.c b/syscall/syscall_clock_systimer.c index 18801debbd3..b6bbc00cac3 100644 --- a/syscall/syscall_clock_systimer.c +++ b/syscall/syscall_clock_systimer.c @@ -60,7 +60,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: syscall_clock_systimer + * Name: syscall_clock_systimer32/64 * * Description: * In the kernel build, proxying for clock_systimer() must be handled @@ -74,7 +74,14 @@ * ****************************************************************************/ -uint32_t syscall_clock_systimer(void) +#ifdef CONFIG_SYSTEM_TIME64 +uint64_t syscall_clock_systimer64(void) { - return clock_systimer(); + return clock_systimer64(); } +#else +uint32_t syscall_clock_systimer32(void) +{ + return clock_systimer32(); +} +#endif diff --git a/syscall/syscall_funclookup.c b/syscall/syscall_funclookup.c index 8aa14a6926b..b1545fb4f1b 100644 --- a/syscall/syscall_funclookup.c +++ b/syscall/syscall_funclookup.c @@ -99,7 +99,11 @@ * have an address that can be included in the g_funclookup[] table. */ -uint32_t syscall_clock_systimer(void); +#ifdef CONFIG_SYSTEM_TIME64 +uint64_t syscall_clock_systimer64(void); +#else +uint32_t syscall_clock_systimer32(void); +#endif /**************************************************************************** * Pre-processor Definitions diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index 6ad246ba5ba..ca378b07e68 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -148,7 +148,11 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) * NuttX configuration. */ - SYSCALL_LOOKUP(syscall_clock_systimer, 0, STUB_clock_systimer) +#ifdef CONFIG_SYSTEM_TIME64 + SYSCALL_LOOKUP(syscall_clock_systimer64, 0, STUB_clock_systimer64) +#endif + SYSCALL_LOOKUP(syscall_clock_systimer32, 0, STUB_clock_systimer32) +#endif SYSCALL_LOOKUP(clock_getres, 2, STUB_clock_getres) SYSCALL_LOOKUP(clock_gettime, 2, STUB_clock_gettime) SYSCALL_LOOKUP(clock_settime, 2, STUB_clock_settime)