Add logic to reset the replenish the sporadic scheduler when a task is resumed

This commit is contained in:
Gregory Nutt 2015-07-24 09:55:02 -06:00
parent ea7dbc984b
commit 4490744def
7 changed files with 138 additions and 7 deletions

@ -1 +1 @@
Subproject commit 7c8ccb29d28c128d70fa052c5d71e507de583feb
Subproject commit 0ac15c4ce3c71f25aa923eebb0529dd571850f4a

2
arch

@ -1 +1 @@
Subproject commit a5d400650765ca63bccd82101f5b60d4f9631015
Subproject commit d0dcd3c458ded300407756c300bc39bbfdd9489a

View File

@ -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)
}

View File

@ -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

View File

@ -41,7 +41,7 @@
#include "sched/sched.h"
/************************************************************************
* Global Functions
* Public Functions
************************************************************************/
/************************************************************************

View File

@ -0,0 +1,99 @@
/************************************************************************
* sched/sched/sched_resumescheduler.c
*
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <nuttx/config.h>
#include <assert.h>
#include <nuttx/sched.h>
#include <nuttx/clock.h>
#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 */

View File

@ -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);