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

View file

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

View file

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

View file

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

View file

@ -865,7 +865,7 @@ extern void nano_cpu_atomic_idle(unsigned int imask);
extern unsigned _Swap(unsigned int mask); extern unsigned _Swap(unsigned int mask);
extern void _insert_ccs(tCCS **queue, tCCS *ccs); extern void _insert_ccs(tCCS **queue, tCCS *ccs);
extern void *_NewContext(char *pStack, extern void _NewContext(char *pStack,
unsigned stackSize, unsigned stackSize,
_ContextEntry pEntry, _ContextEntry pEntry,
_ContextArg arg1, _ContextArg arg1,

View file

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

View file

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

View file

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