Optimizations to _NewContext() and _NewContextInternal()

Since the address of the new context is known before _NewContext() is invoked
(due to it being passed a properly aligned stack), there is no longer any
need for _NewContext to return the pointer to the context.

Furthermore, as a direct result of the properly aligned stack, the pointer to
the new context does not need to be passed as a separate parameter since it
will always match the passed stack pointer.

Change-Id: Ie57a9c4ad17f6f13e8b3f659cd701d4f8950ea97
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
This commit is contained in:
Peter Mitsis 2015-05-25 10:21:57 -04:00 committed by Anas Nashif
commit 40b5200c73
9 changed files with 24 additions and 34 deletions

View file

@ -108,7 +108,7 @@ static ALWAYS_INLINE void context_monitor_init(struct s_CCS *pCcs /* context */
* RETURNS: N/A
*/
void *_NewContext(
void _NewContext(
char *pStackMem, /* pointer to aligned stack memory */
unsigned stackSize, /* stack size in bytes */
_ContextEntry pEntry, /* context (thread) entry point routine */
@ -166,6 +166,4 @@ void *_NewContext(
/* initial values in all other registers/CCS entries are irrelevant */
CONTEXT_MONITOR_INIT(pCcs);
return pCcs;
}

View file

@ -265,7 +265,7 @@ static ALWAYS_INLINE int _IS_IN_ISR(void)
}
extern void _insert_ccs(tCCS **, tCCS *);
extern void *_NewContext(char *, unsigned, _ContextEntry,
extern void _NewContext(char *, unsigned, _ContextEntry,
_ContextArg, _ContextArg, _ContextArg,
int, unsigned);

View file

@ -102,7 +102,7 @@ static ALWAYS_INLINE void _context_monitor_init(struct s_CCS *pCcs /* context */
* RETURNS: N/A
*/
void *_NewContext(
void _NewContext(
char *pStackMem, /* aligned stack memory */
unsigned stackSize, /* stack size in bytes */
_ContextEntry pEntry, /* entry point */
@ -146,6 +146,4 @@ void *_NewContext(
/* initial values in all other registers/CCS entries are irrelevant */
CONTEXT_MONITOR_INIT(pCcs);
return pCcs;
}

View file

@ -199,7 +199,7 @@ static ALWAYS_INLINE void fiberRtnValueSet(
}
extern void _insert_ccs(tCCS **, tCCS *);
extern void *_NewContext(char *,
extern void _NewContext(char *,
unsigned,
_ContextEntry,
_ContextArg,

View file

@ -75,7 +75,6 @@ void _ContextEntryWrapper(_ContextEntry, _ContextArg, _ContextArg, _ContextArg);
*/
static void _NewContextInternal(
tCCS *ccs, /* pointer to the new task's ccs */
char *pStackMem, /* pointer to context stack memory */
unsigned stackSize, /* size of stack in bytes */
int priority, /* context priority */
@ -83,6 +82,7 @@ static void _NewContextInternal(
)
{
unsigned long *pInitialCtx;
tCCS *ccs = (tCCS *) pStackMem; /* pointer to the new task's ccs */
#ifndef CONFIG_FP_SHARING
ARG_UNUSED(options);
@ -288,7 +288,7 @@ __asm__("\t.globl _context_entry\n"
* \NOMANUAL
*/
void *_NewContext(
void _NewContext(
char *pStackMem, /* pointer to aligned stack memory */
unsigned stackSize, /* size of stack in bytes */
_ContextEntry pEntry, /* context entry point function */
@ -299,7 +299,6 @@ void *_NewContext(
unsigned options /* context options: USE_FP, USE_SSE */
)
{
tCCS *ccs;
unsigned long *pInitialContext;
/* carve the context entry struct from the "base" of the stack */
@ -354,10 +353,5 @@ void *_NewContext(
* stack
*/
ccs = (tCCS *) pStackMem;
_NewContextInternal(ccs, pStackMem, stackSize, priority, options);
return ((void *)ccs);
_NewContextInternal(pStackMem, stackSize, priority, options);
}

View file

@ -865,7 +865,7 @@ 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 *_NewContext(char *pStack,
extern void _NewContext(char *pStack,
unsigned stackSize,
_ContextEntry pEntry,
_ContextArg arg1,

View file

@ -205,7 +205,6 @@ void start_task(struct k_proc *X, /* ptr to task control block */
)
{
unsigned int contextOptions;
void *pNewContext;
/* Note: the field X->worksize now represents the task size in bytes */
@ -225,7 +224,7 @@ void start_task(struct k_proc *X, /* ptr to task control block */
* the context is a task, rather than a fiber.
*/
pNewContext = (tCCS *)_NewContext((char *)X->workspace, /* pStackMem */
_NewContext((char *)X->workspace, /* pStackMem */
X->worksize, /* stackSize */
(_ContextEntry)func, /* pEntry */
(void *)0, /* parameter1 */
@ -235,7 +234,6 @@ void start_task(struct k_proc *X, /* ptr to task control block */
contextOptions /* options */
);
X->workspace = (char *)pNewContext;
X->fabort = NULL;
reset_state_bit(X, TF_STOP | TF_TERM);

View file

@ -83,7 +83,8 @@ void _fiber_start(char *pStack,
memset((char *)pStack, 0xaa, stackSize);
#endif
ccs = _NewContext((char *)pStack,
ccs = (tCCS *) pStack;
_NewContext(pStack,
stackSize,
(_ContextEntry)pEntry,
(void *)parameter1,

View file

@ -152,7 +152,8 @@ static void nano_init(tCCS *dummyOutContext)
* (or idle task). The entry point for this context is 'main'.
*/
_nanokernel.task =
_nanokernel.task = (tCCS *) main_task_stack;
_NewContext(main_task_stack, /* pStackMem */
CONFIG_MAIN_STACK_SIZE, /* stackSize */
(_ContextEntry)main, /* pEntry */