diff --git a/Documentation b/Documentation index 7c8ccb29d2..0ac15c4ce3 160000 --- a/Documentation +++ b/Documentation @@ -1 +1 @@ -Subproject commit 7c8ccb29d28c128d70fa052c5d71e507de583feb +Subproject commit 0ac15c4ce3c71f25aa923eebb0529dd571850f4a diff --git a/arch b/arch index a5d4006507..d0dcd3c458 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit a5d400650765ca63bccd82101f5b60d4f9631015 +Subproject commit d0dcd3c458ded300407756c300bc39bbfdd9489a diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 2f672cd970..d838f62682 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -728,6 +728,27 @@ FAR struct task_tcb_s *task_vforksetup(start_t retaddr); pid_t task_vforkstart(FAR struct task_tcb_s *child); void task_vforkabort(FAR struct task_tcb_s *child, int errcode); +/******************************************************************************** + * Name: sched_resume_scheduler + * + * Description: + * Called by architecture specific implementation of up_unblock_task() in + * order to prepare the scheduler for the thread that is about to be restarted. + * + * Input Parameters: + * tcb - The TCB of the thread to be restarted. + * + * Returned Value: + * None + * + ********************************************************************************/ + +#if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC) +void sched_resume_scheduler(FAR struct tcb_s *tcb); +#else +# define sched_resume_scheduler(tcb) +#endif + #undef EXTERN #if defined(__cplusplus) } diff --git a/sched/sched/Make.defs b/sched/sched/Make.defs index a9cb8a49c0..ee848808b8 100644 --- a/sched/sched/Make.defs +++ b/sched/sched/Make.defs @@ -54,6 +54,14 @@ CSRCS += sched_waitid.c sched_wait.c endif endif +ifneq ($(CONFIG_RR_INTERVAL),0) +CSRCS += sched_resumescheduler.c +else +ifeq ($(CONFIG_SCHED_SPORADIC),y) +CSRCS += sched_resumescheduler.c +endif +endif + ifeq ($(CONFIG_SCHED_SPORADIC),y) CSRCS += sched_sporadic.c endif diff --git a/sched/sched/sched_foreach.c b/sched/sched/sched_foreach.c index 67badcedda..016aef79bf 100644 --- a/sched/sched/sched_foreach.c +++ b/sched/sched/sched_foreach.c @@ -41,7 +41,7 @@ #include "sched/sched.h" /************************************************************************ - * Global Functions + * Public Functions ************************************************************************/ /************************************************************************ diff --git a/sched/sched/sched_resumescheduler.c b/sched/sched/sched_resumescheduler.c new file mode 100644 index 0000000000..95a08c9d3b --- /dev/null +++ b/sched/sched/sched_resumescheduler.c @@ -0,0 +1,99 @@ +/************************************************************************ + * sched/sched/sched_resumescheduler.c + * + * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************/ + +/************************************************************************ + * Included Files + ************************************************************************/ + +#include + +#include + +#include +#include + +#include "sched/sched.h" + +#if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC) + +/************************************************************************ + * Global Functions + ************************************************************************/ + +/******************************************************************************** + * Name: sched_resume_scheduler + * + * Description: + * Called by architecture specific implementation of up_unblock_task() in + * order to prepare the scheduler for the thread that is about to be restarted. + * + * Input Parameters: + * tcb - The TCB of the thread to be restarted. + * + * Returned Value: + * None + * + ********************************************************************************/ + +void sched_resume_scheduler(FAR struct tcb_s *tcb) +{ +#if CONFIG_RR_INTERVAL > 0 +#ifdef CONFIG_SCHED_SPORADIC + if ((tcb->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_RR) +#endif + { + /* Reset its timeslice. This is only meaningful for round robin tasks but + * it doesn't here to do it for everything (as long as CONFIG_SCHED_SPORADIC + * is not defined. + */ + + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); + } +#endif + +#ifdef CONFIG_SCHED_SPORADIC +#if CONFIG_RR_INTERVAL > 0 + else +#endif + if ((tcb->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_SPORADIC) + { + /* Reset the replenishment cycle if it is appropriate to do so */ + + DEBUGVERIFY(sched_sporadic_resume(tcb)); + } +#endif +} + +#endif /* CONFIG_RR_INTERVAL > 0 || CONFIG_SCHED_SPORADIC */ diff --git a/sched/sched/sched_sporadic.c b/sched/sched/sched_sporadic.c index 7d6e48da4e..7eb1ba35f2 100644 --- a/sched/sched/sched_sporadic.c +++ b/sched/sched/sched_sporadic.c @@ -260,14 +260,17 @@ int sched_sporadic_stop(FAR struct tcb_s *tcb) } /************************************************************************ - * Name: sched_sporadic_replenish_resume + * Name: sched_sporadic_resume * * Description: * Called to start the next replenishment interval. This function is * called in the following circumstances: * - * - When a task using the sporadic scheduling policy is resumed - * while in the budget interval of the replenishment cycle. + * - From up_unblocktask() via sched_resume_scheduler() when a task + * using the sporadic scheduling policy. + * + * This function does nothing if the budget phase as already elapsed or + * the maximum numer of replenishments have already been performed. * * Parameters: * tcb - The TCB of the thread that is beginning sporadic scheduling. @@ -282,7 +285,7 @@ int sched_sporadic_stop(FAR struct tcb_s *tcb) * ************************************************************************/ -int sched_sporadic_replenish_resume(FAR struct tcb_s *tcb) +int sched_sporadic_resume(FAR struct tcb_s *tcb) { DEBUGASSERT(tcb);