diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index a703d2806c..10f195ed39 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/nuttx/arch.h * - * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -119,6 +119,23 @@ typedef CODE void (*phy_enable_t)(bool enable); * Public Variables ****************************************************************************/ +#ifdef CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP +/* By default, the RTOS tickless logic assumes that range of times that can + * be represented by the underlying hardware time is so large that no special + * precautions need to taken. That is not always the case. If there is a + * limit to the maximum timing interval that be represented by the timer, + * then that limit must be respected. + * + * If CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP is defined, then a 64-bit global + * variable called g_oneshot_max_delay_usec variable is enabled. The variable + * is initialized by platform-specific logic at runtime to the maximum delay + * that the timer can wait (in microseconds). The RTOS tickless logic will + * then limit all requested delays to this value (in ticks). + */ + +extern uint64_t g_oneshot_max_delay_usec; +#endif + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/sched/Kconfig b/sched/Kconfig index 10b34fe01c..a82466d320 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -66,6 +66,7 @@ config SCHED_TICKLESS defined include/nuttx/arch.h if SCHED_TICKLESS + config SCHED_TICKLESS_ALARM bool "Tickless alarm" default n @@ -80,6 +81,15 @@ config SCHED_TICKLESS_ALARM errors; the advantage of the use of the interval timer is that the hardware requirement may be less. +config SCHED_TICKLESS_LIMIT_MAX_SLEEP + bool "Max sleep period (in microseconds)" + default n + ---help--- + Enables g_oneshot_max_delay_usec variable. The variable is + initialized by platform-specific logic at runtime to the maximum + delay that the timer can wait (in microseconds). The RTOS tickless + logic will then limit all requested delays to this value (in ticks). + endif config USEC_PER_TICK diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index d56827ed19..b1ed1833f4 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -1,7 +1,7 @@ /************************************************************************ * sched/sched/sched_timerexpiration.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -84,12 +84,25 @@ #endif /************************************************************************ - * Private Type Declarations + * Public Data ************************************************************************/ -/************************************************************************ - * Public Variables - ************************************************************************/ +#ifdef CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP +/* By default, the RTOS tickless logic assumes that range of times that can + * be represented by the underlying hardware time is so large that no special + * precautions need to taken. That is not always the case. If there is a + * limit to the maximum timing interval that be represented by the timer, + * then that limit must be respected. + * + * If CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP is defined, then a 64-bit global + * variable called g_oneshot_max_delay_usec variable is enabled. The variable + * is initialized by platform-specific logic at runtime to the maximum delay + * that the timer can wait (in microseconds). The RTOS tickless logic will + * then limit all requested delays to this value (in ticks). + */ + +uint64_t g_oneshot_max_delay_usec; +#endif /************************************************************************ * Private Variables @@ -431,6 +444,13 @@ static void sched_timer_start(unsigned int ticks) { struct timespec ts; +#if CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP + if (ticks > (g_oneshot_max_delay_usec / CONFIG_USEC_PER_TICK)) + { + ticks = (g_oneshot_max_delay_usec / CONFIG_USEC_PER_TICK); + } +#endif + /* Save new timer interval */ g_timer_interval = ticks;