Use the last budgeted time from the last timer started
This commit is contained in:
parent
8c754ccd4f
commit
e66e2f5c0f
@ -272,14 +272,17 @@ struct sporadic_s
|
|||||||
uint8_t nrepls; /* Number of active replenishments */
|
uint8_t nrepls; /* Number of active replenishments */
|
||||||
uint32_t repl_period; /* Sporadic replenishment period */
|
uint32_t repl_period; /* Sporadic replenishment period */
|
||||||
uint32_t budget; /* Sporadic execution budget period */
|
uint32_t budget; /* Sporadic execution budget period */
|
||||||
uint32_t last; /* Last budget time */
|
|
||||||
uint32_t pending; /* Unrealized, pending execution budget */
|
uint32_t pending; /* Unrealized, pending execution budget */
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_TICKLESS
|
#ifdef CONFIG_SCHED_TICKLESS
|
||||||
struct timespec sched_time; /* Time in ticks last processed */
|
struct timespec sched_time; /* Time in ticks last processed */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This is the list of replenishment intervals */
|
/* This is the last interval timer activated */
|
||||||
|
|
||||||
|
FAR struct replenishment_s *active;
|
||||||
|
|
||||||
|
/* This is the list of replenishment interval timers */
|
||||||
|
|
||||||
struct replenishment_s replenishments[CONFIG_SCHED_SPORADIC_MAXREPL];
|
struct replenishment_s replenishments[CONFIG_SCHED_SPORADIC_MAXREPL];
|
||||||
};
|
};
|
||||||
|
@ -176,7 +176,6 @@ static int sporadic_budget_start(FAR struct tcb_s *tcb,
|
|||||||
uint32_t budget)
|
uint32_t budget)
|
||||||
{
|
{
|
||||||
FAR struct sporadic_s *sporadic;
|
FAR struct sporadic_s *sporadic;
|
||||||
int ret;
|
|
||||||
|
|
||||||
DEBUGASSERT(tcb && tcb->sporadic);
|
DEBUGASSERT(tcb && tcb->sporadic);
|
||||||
sporadic = tcb->sporadic;
|
sporadic = tcb->sporadic;
|
||||||
@ -184,7 +183,7 @@ static int sporadic_budget_start(FAR struct tcb_s *tcb,
|
|||||||
/* Start the next replenishment interval */
|
/* Start the next replenishment interval */
|
||||||
|
|
||||||
tcb->timeslice = budget;
|
tcb->timeslice = budget;
|
||||||
sporadic->last = budget;
|
sporadic->active = repl;
|
||||||
repl->budget = budget;
|
repl->budget = budget;
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_TICKLESS
|
#ifdef CONFIG_SCHED_TICKLESS
|
||||||
@ -229,13 +228,15 @@ static int sporadic_budget_next(FAR struct replenishment_s *repl)
|
|||||||
sporadic = tcb->sporadic;
|
sporadic = tcb->sporadic;
|
||||||
DEBUGASSERT(sporadic != NULL);
|
DEBUGASSERT(sporadic != NULL);
|
||||||
|
|
||||||
/* The budgeted interval will be the pending budget */
|
/* The budgeted interval will be the unrealized budget (unless the full
|
||||||
|
* budget was used on this timer in the last cycle)
|
||||||
|
*/
|
||||||
|
|
||||||
budget = sporadic->pending;
|
budget = sporadic->pending;
|
||||||
sporadic->pending = 0;
|
sporadic->pending = 0;
|
||||||
|
|
||||||
/* If the budget zero, then all of the pending budget has been utilized.
|
/* If the budget zero, then all of the budget has been utilized. There
|
||||||
* There are now two possibilities: (1) There are multiple, active
|
* are now two possibilities: (1) There are multiple, active
|
||||||
* replenishment threads so this one is no longer needed, or (2) there is
|
* replenishment threads so this one is no longer needed, or (2) there is
|
||||||
* only one and we need to restart the budget interval with the full
|
* only one and we need to restart the budget interval with the full
|
||||||
* budget.
|
* budget.
|
||||||
@ -253,7 +254,6 @@ static int sporadic_budget_next(FAR struct replenishment_s *repl)
|
|||||||
sporadic->nrepls--;
|
sporadic->nrepls--;
|
||||||
|
|
||||||
return sporadic_set_hipriority(tcb);
|
return sporadic_set_hipriority(tcb);
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -659,6 +659,7 @@ int sched_sporadic_start(FAR struct tcb_s *tcb)
|
|||||||
DEBUGASSERT(sporadic->max_repl <= CONFIG_SCHED_SPORADIC_MAXREPL);
|
DEBUGASSERT(sporadic->max_repl <= CONFIG_SCHED_SPORADIC_MAXREPL);
|
||||||
DEBUGASSERT(sporadic->budget > 0 && sporadic->budget <= sporadic->repl_period);
|
DEBUGASSERT(sporadic->budget > 0 && sporadic->budget <= sporadic->repl_period);
|
||||||
DEBUGASSERT(sporadic->nrepls == 0 && sporadic->pending == 0);
|
DEBUGASSERT(sporadic->nrepls == 0 && sporadic->pending == 0);
|
||||||
|
DEBUGASSERT(sporadic->active == NULL);
|
||||||
|
|
||||||
/* Allocate the first replenishment timer (should never fail) */
|
/* Allocate the first replenishment timer (should never fail) */
|
||||||
|
|
||||||
@ -768,6 +769,7 @@ int sched_sporadic_reset(FAR struct tcb_s *tcb)
|
|||||||
sporadic->repl_period = 0;
|
sporadic->repl_period = 0;
|
||||||
sporadic->budget = 0;
|
sporadic->budget = 0;
|
||||||
sporadic->pending = 0;
|
sporadic->pending = 0;
|
||||||
|
sporadic->active = NULL;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,6 +803,7 @@ int sched_sporadic_resume(FAR struct tcb_s *tcb)
|
|||||||
{
|
{
|
||||||
FAR struct sporadic_s *sporadic;
|
FAR struct sporadic_s *sporadic;
|
||||||
FAR struct replenishment_s *repl;
|
FAR struct replenishment_s *repl;
|
||||||
|
uint32_t last;
|
||||||
|
|
||||||
DEBUGASSERT(tcb && tcb->sporadic);
|
DEBUGASSERT(tcb && tcb->sporadic);
|
||||||
sporadic = tcb->sporadic;
|
sporadic = tcb->sporadic;
|
||||||
@ -813,18 +816,26 @@ int sched_sporadic_resume(FAR struct tcb_s *tcb)
|
|||||||
|
|
||||||
/* Check if are in the budget portion of the replenishment interval. We
|
/* Check if are in the budget portion of the replenishment interval. We
|
||||||
* know this is the case if the current timeslice is non-zero.
|
* know this is the case if the current timeslice is non-zero.
|
||||||
*
|
|
||||||
* This function could also be called before the budget period has had a
|
|
||||||
* chance to run, i.e., when the value of timeslice has not been decremented
|
|
||||||
* and is still equal to the initial value.
|
|
||||||
*
|
|
||||||
* This latter case could occur if the thread has never had a chance to
|
|
||||||
* run and is also very likely when the thread is just restarted after
|
|
||||||
* raising its priority at the beginning of the budget period. We would
|
|
||||||
* not want to start a new timer in these cases.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (tcb->timeslice > 0 && tcb->timeslice < sporadic->last)
|
if (tcb->timeslice > 0)
|
||||||
|
{
|
||||||
|
/* Get the last budgeted time */
|
||||||
|
|
||||||
|
DEBUGASSERT(sporadic->active);
|
||||||
|
last = sporadic->active->budget;
|
||||||
|
|
||||||
|
/* This function could also be called before the budget period has had
|
||||||
|
* a chance to run, i.e., when the value of timeslice has not been
|
||||||
|
* decremented and is still equal to the initial value.
|
||||||
|
*
|
||||||
|
* This latter case could occur if the thread has never had a chance
|
||||||
|
* to run and is also very likely when the thread is just restarted
|
||||||
|
* after raising its priority at the beginning of the budget period.
|
||||||
|
* We would not want to start a new timer in these cases.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (tcb->timeslice < last)
|
||||||
{
|
{
|
||||||
/* Allocate a new replenishment timer. This will limit us to
|
/* Allocate a new replenishment timer. This will limit us to
|
||||||
* to maximum number of replenishments (max_repl).
|
* to maximum number of replenishments (max_repl).
|
||||||
@ -843,6 +854,7 @@ int sched_sporadic_resume(FAR struct tcb_s *tcb)
|
|||||||
|
|
||||||
slldbg("Failed to allocate timer, nrepls=%d\n", sporadic->nrepls);
|
slldbg("Failed to allocate timer, nrepls=%d\n", sporadic->nrepls);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_TICKLESS
|
#ifdef CONFIG_SCHED_TICKLESS
|
||||||
/* Reset to the resume time */
|
/* Reset to the resume time */
|
||||||
@ -887,6 +899,7 @@ int sched_sporadic_suspend(FAR struct tcb_s *tcb,
|
|||||||
uint32_t elapsed_ticks;
|
uint32_t elapsed_ticks;
|
||||||
#endif
|
#endif
|
||||||
uint32_t pending = tcb->timeslice;
|
uint32_t pending = tcb->timeslice;
|
||||||
|
uint32_t last;
|
||||||
|
|
||||||
DEBUGASSERT(tcb && tcb->sporadic);
|
DEBUGASSERT(tcb && tcb->sporadic);
|
||||||
sporadic = tcb->sporadic;
|
sporadic = tcb->sporadic;
|
||||||
@ -945,6 +958,11 @@ int sched_sporadic_suspend(FAR struct tcb_s *tcb,
|
|||||||
tcb->timeslice -= (int32_t)elapsed_ticks;
|
tcb->timeslice -= (int32_t)elapsed_ticks;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Get the last budgeted time */
|
||||||
|
|
||||||
|
DEBUGASSERT(sporadic->active);
|
||||||
|
last = sporadic->active->budget;
|
||||||
|
|
||||||
/* Handle any part of the budget that was not utilized.
|
/* Handle any part of the budget that was not utilized.
|
||||||
*
|
*
|
||||||
* current = The initial budget at the beginning of the interval.
|
* current = The initial budget at the beginning of the interval.
|
||||||
@ -952,8 +970,8 @@ int sched_sporadic_suspend(FAR struct tcb_s *tcb,
|
|||||||
* not execute.
|
* not execute.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DEBUGASSERT(sporadic->last >= tcb->timeslice);
|
DEBUGASSERT(last >= tcb->timeslice);
|
||||||
pending = sporadic->last - tcb->timeslice;
|
pending = last - tcb->timeslice;
|
||||||
DEBUGASSERT(pending <= sporadic->budget);
|
DEBUGASSERT(pending <= sporadic->budget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user