From 69555e8efd228fd2f61fb5ad74bb5bdffb0809ce Mon Sep 17 00:00:00 2001 From: Allan Stephens Date: Wed, 3 Jun 2015 15:39:21 -0400 Subject: [PATCH] Cleanup of nanokernel's fiber scheduling routine 1) Renames routine to conform to kernel naming conventions. 2) Relocates routine declaration to include files for non-public nanokernel APIs. 3) Relocates routine definition so that it resides with the nanokernel's other fiber manipulation routines. 4) Eliminates an unnecessary argument to the routine. Change-Id: Ia139280dfea36262ca8417708786b4989f3eaee1 Signed-off-by: Allan Stephens --- arch/arc/include/nanok.h | 2 +- arch/arm/include/nanok.h | 2 +- arch/x86/include/nanok.h | 2 +- kernel/nanokernel/include/wait_q.h | 2 +- kernel/nanokernel/nano_context.c | 40 ---------------------------- kernel/nanokernel/nano_fiber.c | 42 +++++++++++++++++++++++++++--- kernel/nanokernel/nano_stack.c | 4 +-- 7 files changed, 44 insertions(+), 50 deletions(-) diff --git a/arch/arc/include/nanok.h b/arch/arc/include/nanok.h index a25f3cb78cd..f092240a641 100644 --- a/arch/arc/include/nanok.h +++ b/arch/arc/include/nanok.h @@ -264,7 +264,7 @@ static ALWAYS_INLINE int _IS_IN_ISR(void) return ((act & 0xffff) != 0); } -extern void _insert_ccs(tCCS **, tCCS *); +extern void _nano_fiber_schedule(tCCS *ccs); extern void _nano_fiber_swap(void); extern void _NewContext(char *, unsigned, _ContextEntry, _ContextArg, _ContextArg, _ContextArg, diff --git a/arch/arm/include/nanok.h b/arch/arm/include/nanok.h index 15883269b04..90746e60f54 100644 --- a/arch/arm/include/nanok.h +++ b/arch/arm/include/nanok.h @@ -198,7 +198,7 @@ static ALWAYS_INLINE void fiberRtnValueSet( pEsf->a1 = value; } -extern void _insert_ccs(tCCS **, tCCS *); +extern void _nano_fiber_schedule(tCCS *ccs); extern void _nano_fiber_swap(void); extern void _NewContext(char *, unsigned, diff --git a/arch/x86/include/nanok.h b/arch/x86/include/nanok.h index e5cc838caa2..7e62ae920aa 100644 --- a/arch/x86/include/nanok.h +++ b/arch/x86/include/nanok.h @@ -857,7 +857,7 @@ typedef unsigned char __aligned(_EXC_STUB_ALIGN) NANO_EXC_STUB[_EXC_STUB_SIZE]; extern void nano_cpu_atomic_idle(unsigned int imask); extern unsigned _Swap(unsigned int mask); -extern void _insert_ccs(tCCS **queue, tCCS *ccs); +extern void _nano_fiber_schedule(tCCS *ccs); extern void _nano_fiber_swap(void); diff --git a/kernel/nanokernel/include/wait_q.h b/kernel/nanokernel/include/wait_q.h index 22d865a10fd..600cef5a221 100644 --- a/kernel/nanokernel/include/wait_q.h +++ b/kernel/nanokernel/include/wait_q.h @@ -63,7 +63,7 @@ static inline tCCS *_nano_wait_q_remove_no_check(struct _nano_queue *wait_q) } ccs->link = 0; - _insert_ccs((tCCS **)&_nanokernel.fiber, ccs); + _nano_fiber_schedule(ccs); return ccs; } diff --git a/kernel/nanokernel/nano_context.c b/kernel/nanokernel/nano_context.c index 4017c3312d5..d3f862df976 100644 --- a/kernel/nanokernel/nano_context.c +++ b/kernel/nanokernel/nano_context.c @@ -277,43 +277,3 @@ FUNC_NORETURN void _context_entry( CODE_UNREACHABLE; } -/******************************************************************************* -* -* _insert_ccs - add a context into the list of runnable contexts -* -* The list of runnable contexts is maintained via a single linked list -* in priority order. Numerically lower priorities represent higher priority -* contexts. -* -* \NOMANUAL -* -* RETURNS: N/A -*/ - -void _insert_ccs(tCCS **queue, tCCS *ccs) -{ - tCCS *pQ; - - pQ = (tCCS *)queue; - - /* - * Scan the "queue" until end of list or until context with numerically - * higher priority is located. A context will be placed at the end of - * the series of equal priority contexts. - */ - - while (pQ->link && (ccs->prio >= pQ->link->prio)) { - pQ = pQ->link; - } - - /* - * Insert context. A context will be placed at the end of equal - * priority - * contexts. - */ - - ccs->link = pQ->link; - pQ->link = ccs; -} - - diff --git a/kernel/nanokernel/nano_fiber.c b/kernel/nanokernel/nano_fiber.c index c9d6c3f878e..0decac5bce5 100644 --- a/kernel/nanokernel/nano_fiber.c +++ b/kernel/nanokernel/nano_fiber.c @@ -41,6 +41,40 @@ either in the form of an actual function or an alias to a function. #include #include +/******************************************************************************* +* +* _nano_fiber_schedule - add a fiber to the list of runnable fibers +* +* The list of runnable fibers is maintained via a single linked list +* in priority order. Numerically lower priorities represent higher priority +* contexts. +* +* Interrupts must already be locked to ensure list cannot change +* while this routine is executing! +* +* RETURNS: N/A +*/ + +void _nano_fiber_schedule(tCCS *ccs) +{ + tCCS *pQ = (tCCS *)&_nanokernel.fiber; + + /* + * Search until end of list or until a fiber with numerically + * higher priority is located. + */ + + while (pQ->link && (ccs->prio >= pQ->link->prio)) { + pQ = pQ->link; + } + + /* Insert fiber, following any equal priority fibers */ + + ccs->link = pQ->link; + pQ->link = ccs; +} + + /* currently the fiber and task implementations are identical */ FUNC_ALIAS(_fiber_start, fiber_fiber_start, void); @@ -92,13 +126,13 @@ void _fiber_start(char *pStack, /* _NewContext() has already set the flags depending on the 'options' * and 'priority' parameters passed to it */ - /* lock interrupts to prevent corruption of the runnable context list */ + /* lock interrupts to prevent corruption of the runnable fiber list */ imask = irq_lock(); - /* insert thew newly crafted CCS into the fiber runnable context list */ + /* make the newly crafted CCS a runnable fiber */ - _insert_ccs((tCCS **)&_nanokernel.fiber, ccs); + _nano_fiber_schedule(ccs); /* * Simply return to the caller if the current context is FIBER, @@ -137,7 +171,7 @@ void fiber_yield(void) * then swap to the context at the head of the fiber list. */ - _insert_ccs(&(_nanokernel.fiber), _nanokernel.current); + _nano_fiber_schedule(_nanokernel.current); _Swap(imask); } else irq_unlock_inline(imask); diff --git a/kernel/nanokernel/nano_stack.c b/kernel/nanokernel/nano_stack.c index b44dc589bd9..473c0d23ecb 100644 --- a/kernel/nanokernel/nano_stack.c +++ b/kernel/nanokernel/nano_stack.c @@ -110,7 +110,7 @@ void _stack_push_non_preemptible( if (ccs) { stack->fiber = 0; fiberRtnValueSet(ccs, data); - _insert_ccs((tCCS **)&_nanokernel.fiber, ccs); + _nano_fiber_schedule(ccs); } else { *(stack->next) = data; stack->next++; @@ -144,7 +144,7 @@ void nano_task_stack_push( if (ccs) { stack->fiber = 0; fiberRtnValueSet(ccs, data); - _insert_ccs((tCCS **)&_nanokernel.fiber, ccs); + _nano_fiber_schedule(ccs); _Swap(imask); return; } else {