Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reset kernel state for restarting scheduler #944

Merged
merged 73 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
ab0b337
PORT - Introduce optional portIDLE_HOOK and make use of it in POSIX p…
cmorganBE Nov 13, 2023
b48dd9f
POSIX - Switch from posix timers to a timer thread to fix signal hand…
cmorganBE Nov 28, 2023
2123c2e
POSIX port - Cancel and join all FreeRTOS managed pthreads upon shutdown
cmorganBE Nov 28, 2023
3b2ab2c
tasks.c - vTaskStartScheduler() should clean up state to enable vTask…
cmorganBE Nov 28, 2023
e8a508a
POSIX port - Fix subsequent scheduler starts by clearing xSchedulerEn…
cmorganBE Nov 28, 2023
201cc67
POSIX port - Switch from allowing the user to specify the stack, to a…
cmorganBE Nov 29, 2023
00a6e57
Merge branch 'main' into cmm_posix
chinglee-iot Dec 4, 2023
c0a741e
PORT - Introduce optional portHAS_IDLE_HOOK / vPortIdleHook and make …
cmorganBE Nov 13, 2023
6276ef0
POSIX - Switch from posix timers to a timer thread to fix signal hand…
cmorganBE Nov 28, 2023
9d7bad7
POSIX port - Cancel and join all FreeRTOS managed pthreads upon shutdown
cmorganBE Nov 28, 2023
f38dd73
tasks.c - vTaskStartScheduler() should clean up state to enable vTask…
cmorganBE Nov 28, 2023
5b90815
POSIX port - Fix subsequent scheduler starts by clearing xSchedulerEn…
cmorganBE Nov 28, 2023
45a6885
POSIX port - Switch from allowing the user to specify the stack, to a…
cmorganBE Nov 29, 2023
970631d
Update posix port for end scheduler
chinglee-iot Dec 6, 2023
641254e
Remove dummy testcancel
chinglee-iot Dec 6, 2023
1ae47ea
Merge branch 'main' into cmm_posix
Skptak Dec 6, 2023
ba884fb
Merge branch 'main' into cmm_posix
Skptak Dec 7, 2023
8dab8b3
Merge branch 'cmm_posix' of https://github.com/cmorganBE/FreeRTOS-Ker…
chinglee-iot Dec 8, 2023
c482fef
Revert tasks update
chinglee-iot Dec 8, 2023
aa59a0f
Merge branch 'fix-posix-port' into update-cmm_posix
chinglee-iot Dec 8, 2023
a8829bd
Update the posix port
chinglee-iot Dec 8, 2023
03eb28b
Create a cancellation point in tick handler
chinglee-iot Dec 8, 2023
16c9517
Merge branch 'freertos_main' into update-cmm_posix
chinglee-iot Dec 8, 2023
d87fe19
Remove portHAS_IDLE_HOOK
chinglee-iot Dec 8, 2023
30cd06f
Use nansleep for valgrind
chinglee-iot Dec 8, 2023
bb0e959
Add first version of re-initialise variables
chinglee-iot Jan 3, 2024
533dfaf
Merge branch 'add-initialize-internal-variables' into update-cmm_posi…
chinglee-iot Jan 4, 2024
030cb12
Fix for the tick timer
chinglee-iot Jan 4, 2024
ab0a0d9
Move reinitialize code before port end scheduler
chinglee-iot Jan 4, 2024
abf46bc
Merge branch 'add-initialize-internal-variables' into update-cmm_posi…
chinglee-iot Jan 4, 2024
4604bc9
Code refine
chinglee-iot Jan 4, 2024
774fc7d
Update for format and spell
chinglee-iot Jan 4, 2024
0e26b27
Fix typo again
chinglee-iot Jan 4, 2024
bd25545
Merge branch 'add-initialize-internal-variables' into update-cmm_posi…
chinglee-iot Jan 4, 2024
a17f8f8
Update comments
chinglee-iot Jan 4, 2024
edeedfd
Update format
chinglee-iot Jan 4, 2024
f77bf39
Move the reset code
chinglee-iot Jan 4, 2024
9e3cb13
Merge branch 'main' into update-cmm_posix-reinit
chinglee-iot Jan 4, 2024
b6cdf8b
Merge branch 'main' into update-cmm_posix-reinit
chinglee-iot Jan 5, 2024
291b32e
Update comments
chinglee-iot Jan 5, 2024
94e4039
Update for spelling
chinglee-iot Jan 5, 2024
96c37ba
Merge branch 'main' into update-cmm_posix-reinit
kar-rahul-aws Jan 8, 2024
160b684
Update tasks.c comment
chinglee-iot Jan 8, 2024
161ca8f
Move reinitialise code to start scheduler
chinglee-iot Jan 10, 2024
e0b99b7
Merge branch 'update-cmm_posix-reinit' of https://github.com/chinglee…
chinglee-iot Jan 10, 2024
61f5575
Remove redundant event_signal
chinglee-iot Jan 10, 2024
61ba7b9
Rename and remove macro
chinglee-iot Jan 10, 2024
2b9ac50
UPdate comment
chinglee-iot Jan 10, 2024
5df8ae2
Merge branch 'main' into update-cmm_posix-reinit
chinglee-iot Jan 10, 2024
9ee5b54
Merge branch 'main' into update-cmm_posix-reinit
kar-rahul-aws Jan 11, 2024
7792539
Merge branch 'main' into update-cmm_posix-reinit
chinglee-iot Jan 15, 2024
b691b5c
Merge branch 'main' into update-cmm_posix-reinit
Skptak Jan 18, 2024
e3021b9
Merge branch 'main' into update-cmm_posix-reinit
chinglee-iot Jan 22, 2024
f669ae1
Merge branch 'main' into update-cmm_posix-reinit
Skptak Jan 25, 2024
d20c95a
Review suggestions
aggarg Jan 25, 2024
d0e7bdc
Update task.h comment for spelling
chinglee-iot Jan 25, 2024
eefab50
Update croutine.h for comment
chinglee-iot Jan 25, 2024
aadf220
Update for comment
chinglee-iot Jan 25, 2024
f2eb5e2
Update tasks.c remove extra empty line
chinglee-iot Jan 25, 2024
b068161
Remove extra empty line in multiple files
chinglee-iot Jan 25, 2024
d18e8c1
Apply suggestions from code review
chinglee-iot Jan 26, 2024
6061dbd
Update variables default value to correspond to reset function
chinglee-iot Jan 26, 2024
b28c0f1
Merge branch 'main' into update-cmm_posix-reinit
chinglee-iot Jan 26, 2024
46a347d
Merge branch 'main' into update-cmm_posix-reinit
aggarg Jan 27, 2024
aa9ef10
Merge branch 'main' into update-cmm_posix-reinit
chinglee-iot Jan 29, 2024
82abe0a
Merge branch 'main' into update-cmm_posix-reinit
aggarg Jan 29, 2024
68d985a
Merge branch 'main' into update-cmm_posix-reinit
aggarg Jan 30, 2024
591c865
Update tasks.c to reset total runtime
chinglee-iot Jan 31, 2024
b738e87
Merge branch 'main' into update-cmm_posix-reinit
chinglee-iot Jan 31, 2024
a55c166
Merge branch 'main' into update-cmm_posix-reinit
aggarg Jan 31, 2024
c89c864
Merge branch 'main' into update-cmm_posix-reinit
chinglee-iot Feb 5, 2024
334676b
Merge branch 'main' into update-cmm_posix-reinit
aggarg Feb 5, 2024
f4c7106
Merge branch 'main' into update-cmm_posix-reinit
aggarg Feb 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions croutine.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,26 @@

return xReturn;
}
/*-----------------------------------------------------------*/

/*
* Reset state in this file. This state is normally initialized at start up.
* This function must be called by the application before restarting the
* scheduler.
*/
void vCoRoutineResetState( void )
{
/* Lists for ready and blocked co-routines. */
pxDelayedCoRoutineList = NULL;
pxOverflowDelayedCoRoutineList = NULL;

/* Other file private variables. */
pxCurrentCoRoutine = NULL;
uxTopCoRoutineReadyPriority = 0;
xCoRoutineTickCount = 0;
xLastTickCount = 0;
xPassedTicks = 0;
chinglee-iot marked this conversation as resolved.
Show resolved Hide resolved
}
/*-----------------------------------------------------------*/

#endif /* configUSE_CO_ROUTINES == 0 */
7 changes: 7 additions & 0 deletions include/croutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,13 @@ void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay,
*/
BaseType_t xCoRoutineRemoveFromEventList( const List_t * pxEventList );


/*
* This function resets the internal state of the coroutine module. It must be
* called by the application before restarting the scheduler.
*/
void vCoRoutineResetState( void ) PRIVILEGED_FUNCTION;

/* *INDENT-OFF* */
#ifdef __cplusplus
}
Expand Down
6 changes: 6 additions & 0 deletions include/portable.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION;
#define vPortFreeStack vPortFree
#endif

/*
* This function resets the internal state of the heap module. It must be called
* by the application before restarting the scheduler.
*/
void vPortHeapResetState( void ) PRIVILEGED_FUNCTION;

#if ( configUSE_MALLOC_FAILED_HOOK == 1 )

/**
Expand Down
14 changes: 14 additions & 0 deletions include/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -3438,6 +3438,20 @@ BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
*/
BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION;

/**
* task.h
* @code{c}
* void vTaskResetState( void );
* @endcode
*
* This function resets the internal state of the task. It must be called by the
* application before restarting the scheduler.
*
* \defgroup vTaskResetState vTaskResetState
* \ingroup SchedulerControl
*/
void vTaskResetState( void ) PRIVILEGED_FUNCTION;


/*-----------------------------------------------------------
* SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
Expand Down
6 changes: 6 additions & 0 deletions include/timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,12 @@ BaseType_t xTimerGenericCommandFromISR( TimerHandle_t xTimer,

#endif

/*
* This function resets the internal state of the timer module. It must be called
* by the application before restarting the scheduler.
*/
void vTimerResetState( void ) PRIVILEGED_FUNCTION;

/* *INDENT-OFF* */
#ifdef __cplusplus
}
Expand Down
13 changes: 13 additions & 0 deletions portable/MemMang/heap_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,16 @@ size_t xPortGetFreeHeapSize( void )
{
return( configADJUSTED_HEAP_SIZE - xNextFreeByte );
}

/*-----------------------------------------------------------*/

/*
* Reset the state in this file. This state is normally initialized at start up.
* This function must be called by the application before restarting the
* scheduler.
*/
void vPortHeapResetState( void )
{
xNextFreeByte = ( size_t ) 0;
chinglee-iot marked this conversation as resolved.
Show resolved Hide resolved
}
/*-----------------------------------------------------------*/
17 changes: 16 additions & 1 deletion portable/MemMang/heap_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ PRIVILEGED_DATA static BlockLink_t xStart, xEnd;
* fragmentation. */
PRIVILEGED_DATA static size_t xFreeBytesRemaining = configADJUSTED_HEAP_SIZE;

/* Indicates whether the heap has been initialised or not. */
PRIVILEGED_DATA static BaseType_t xHeapHasBeenInitialised = pdFALSE;

/*-----------------------------------------------------------*/

/*
Expand Down Expand Up @@ -155,7 +158,6 @@ void * pvPortMalloc( size_t xWantedSize )
BlockLink_t * pxBlock;
BlockLink_t * pxPreviousBlock;
BlockLink_t * pxNewBlockLink;
PRIVILEGED_DATA static BaseType_t xHeapHasBeenInitialised = pdFALSE;
void * pvReturn = NULL;
size_t xAdditionalRequiredSize;

Expand Down Expand Up @@ -384,3 +386,16 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
pxFirstFreeBlock->pxNextFreeBlock = &xEnd;
}
/*-----------------------------------------------------------*/

/*
* Reset the state in this file. This state is normally initialized at start up.
* This function must be called by the application before restarting the
* scheduler.
*/
void vPortHeapResetState( void )
{
xFreeBytesRemaining = configADJUSTED_HEAP_SIZE;

xHeapHasBeenInitialised = pdFALSE;
}
/*-----------------------------------------------------------*/
12 changes: 12 additions & 0 deletions portable/MemMang/heap_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,15 @@ void vPortFree( void * pv )
( void ) xTaskResumeAll();
}
}
/*-----------------------------------------------------------*/

/*
* Reset the state in this file. This state is normally initialized at start up.
* This function must be called by the application before restarting the
* scheduler.
*/
void vPortHeapResetState( void )
{
/* No state needs to be re-initialised in heap_3. */
}
/*-----------------------------------------------------------*/
16 changes: 16 additions & 0 deletions portable/MemMang/heap_4.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,19 @@ void vPortGetHeapStats( HeapStats_t * pxHeapStats )
taskEXIT_CRITICAL();
}
/*-----------------------------------------------------------*/

/*
* Reset the state in this file. This state is normally initialized at start up.
* This function must be called by the application before restarting the
* scheduler.
*/
void vPortHeapResetState( void )
{
pxEnd = NULL;

xFreeBytesRemaining = 0U;
xMinimumEverFreeBytesRemaining = 0U;
xNumberOfSuccessfulAllocations = 0;
xNumberOfSuccessfulFrees = 0;
chinglee-iot marked this conversation as resolved.
Show resolved Hide resolved
}
/*-----------------------------------------------------------*/
21 changes: 21 additions & 0 deletions portable/MemMang/heap_5.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,3 +707,24 @@ void vPortGetHeapStats( HeapStats_t * pxHeapStats )
taskEXIT_CRITICAL();
}
/*-----------------------------------------------------------*/

/*
* Reset the state in this file. This state is normally initialized at start up.
* This function must be called by the application before restarting the
* scheduler.
*/
void vPortHeapResetState( void )
{
pxEnd = NULL;

xFreeBytesRemaining = 0U;
xMinimumEverFreeBytesRemaining = 0U;
xNumberOfSuccessfulAllocations = 0;
xNumberOfSuccessfulFrees = 0;
chinglee-iot marked this conversation as resolved.
Show resolved Hide resolved

#if ( configENABLE_HEAP_PROTECTOR == 1 )
pucHeapHighAddress = NULL;
pucHeapLowAddress = NULL;
#endif /* #if ( configENABLE_HEAP_PROTECTOR == 1 ) */
}
/*-----------------------------------------------------------*/
58 changes: 58 additions & 0 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -8676,3 +8676,61 @@

#endif /* #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configKERNEL_PROVIDED_STATIC_MEMORY == 1 ) && ( portUSING_MPU_WRAPPERS == 0 ) ) */
/*-----------------------------------------------------------*/

/*
* Reset the state in this file. This state is normally initialized at start up.
* This function must be called by the application before restarting the
* scheduler.
*/
void vTaskResetState( void )

Check warning on line 8685 in tasks.c

View check run for this annotation

Codecov / codecov/patch

tasks.c#L8685

Added line #L8685 was not covered by tests
{
BaseType_t xCoreID;

/* Task control block. */
#if ( configNUMBER_OF_CORES == 1 )
{
pxCurrentTCB = NULL;

Check warning on line 8692 in tasks.c

View check run for this annotation

Codecov / codecov/patch

tasks.c#L8692

Added line #L8692 was not covered by tests
}
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */

#if ( INCLUDE_vTaskDelete == 1 )
{
uxDeletedTasksWaitingCleanUp = ( UBaseType_t ) 0U;

Check warning on line 8698 in tasks.c

View check run for this annotation

Codecov / codecov/patch

tasks.c#L8698

Added line #L8698 was not covered by tests
}
#endif /* #if ( INCLUDE_vTaskDelete == 1 ) */

#if ( configUSE_POSIX_ERRNO == 1 )
{
FreeRTOS_errno = 0;
}
#endif /* #if ( configUSE_POSIX_ERRNO == 1 ) */

/* Other file private variables. */
uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;
xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT;
uxTopReadyPriority = tskIDLE_PRIORITY;
xSchedulerRunning = pdFALSE;
xPendedTicks = ( TickType_t ) 0U;

Check warning on line 8713 in tasks.c

View check run for this annotation

Codecov / codecov/patch

tasks.c#L8709-L8713

Added lines #L8709 - L8713 were not covered by tests

for( xCoreID = 0; xCoreID < configNUMBER_OF_CORES; xCoreID++ )
{
xYieldPendings[ xCoreID ] = pdFALSE;

Check warning on line 8717 in tasks.c

View check run for this annotation

Codecov / codecov/patch

tasks.c#L8717

Added line #L8717 was not covered by tests
}

xNumOfOverflows = ( BaseType_t ) 0;
uxTaskNumber = ( UBaseType_t ) 0U;
xNextTaskUnblockTime = ( TickType_t ) 0U;

Check warning on line 8722 in tasks.c

View check run for this annotation

Codecov / codecov/patch

tasks.c#L8720-L8722

Added lines #L8720 - L8722 were not covered by tests

uxSchedulerSuspended = ( UBaseType_t ) 0U;

Check warning on line 8724 in tasks.c

View check run for this annotation

Codecov / codecov/patch

tasks.c#L8724

Added line #L8724 was not covered by tests

#if ( configGENERATE_RUN_TIME_STATS == 1 )
{
for( xCoreID = 0; xCoreID < configNUMBER_OF_CORES; xCoreID++ )
{
ulTaskSwitchedInTime[ xCoreID ] = 0U;
ulTotalRunTime[ configNUMBER_OF_CORES ] = 0U;
chinglee-iot marked this conversation as resolved.
Show resolved Hide resolved
}
}
#endif /* #if ( configGENERATE_RUN_TIME_STATS == 1 ) */
}

Check warning on line 8735 in tasks.c

View check run for this annotation

Codecov / codecov/patch

tasks.c#L8735

Added line #L8735 was not covered by tests
/*-----------------------------------------------------------*/
12 changes: 12 additions & 0 deletions timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,18 @@
#endif /* configUSE_TRACE_FACILITY */
/*-----------------------------------------------------------*/

/*
* Reset the state in this file. This state is normally initialized at start up.
* This function must be called by the application before restarting the
* scheduler.
*/
void vTimerResetState( void )

Check warning on line 1330 in timers.c

View check run for this annotation

Codecov / codecov/patch

timers.c#L1330

Added line #L1330 was not covered by tests
{
xTimerQueue = NULL;
xTimerTaskHandle = NULL;
}

Check warning on line 1334 in timers.c

View check run for this annotation

Codecov / codecov/patch

timers.c#L1332-L1334

Added lines #L1332 - L1334 were not covered by tests
/*-----------------------------------------------------------*/

/* This entire source file will be skipped if the application is not configured
* to include software timer functionality. If you want to include software timer
* functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
Expand Down
Loading