Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

Why systick decreases real time responsiveness by masking interrupts for all the service routine ?

Posted by pstepien on February 9, 2016

Systick interrupt should be at lowest possible level but indeed through its implementation it is at the highest system level by using portSETINTERRUPTMASKFROMISR/portCLEARINTERRUPTMASKFROMISR at entry/exit and thus masking interrupts using rtos api for all the systick isr routine execution where only during tasks list manipulation it should mask/unmask interrupts

(FreeRTOS V8.2.3) SourceportableGCCARMCM4Fport.c: ~~~~ void xPortSysTickHandler( void ) { /* The SysTick runs at the lowest interrupt priority, so when this interrupt executes all interrupts must be unmasked. There is therefore no need to save and then restore the interrupt mask value as its value is already known. */ ( void ) portSETINTERRUPTMASKFROMISR(); { /* Increment the RTOS tick. / if( xTaskIncrementTick() != pdFALSE ) { / A context switch is required. Context switching is performed in the PendSV interrupt. Pend the PendSV interrupt. */ portNVICINTCTRLREG = portNVICPENDSVSETBIT; } } portCLEARINTERRUPTMASKFROMISR( 0 ); } ~~~~ When taking a look into xTaskIncrementTick we see that there is code that does delayed tasks list manipulation, removing woken tasks from blocked state list and event waiting lists, adding to ready list 1. delayed tasks list manipulation may be executed only from thread so does not need to be inside citical section (under masked interrupts) (bad idea, maybe done in isr) 2. only removing woken tasks from blocked state list and event waiting lists and adding to ready list should be inside critical section (under masked interrupts)

(FreeRTOS V8.2.3) tasks.c: ~~~~ for( ;; ) { <---- begin critical section here if( listLISTISEMPTY( pxDelayedTaskList ) != pdFALSE ) { /* The delayed list is empty. Set xNextTaskUnblockTime to the maximum possible value so it is extremely unlikely that the if( xTickCount >= xNextTaskUnblockTime ) test will pass next time through. / xNextTaskUnblockTime = portMAX_DELAY; <---- end critical section here break; } else { / The delayed list is not empty, get the value of the item at the head of the delayed list. This is the time at which the task at the head of the delayed list must be removed from the Blocked state. */ pxTCB = ( TCBt * ) listGETOWNEROFHEADENTRY( pxDelayedTaskList ); xItemValue = listGETLISTITEMVALUE( &( pxTCB->xGenericListItem ) );

					if( xConstTickCount < xItemValue )
					{
						/* It is not time to unblock this item yet, but the
						item value is the time at which the task at the head
						of the blocked list must be removed from the Blocked
						state -	so record the item value in
						xNextTaskUnblockTime. */
						xNextTaskUnblockTime = xItemValue;
						break;
					}
					else
					{
						mtCOVERAGE_TEST_MARKER();
					}

					/* It is time to remove the item from the Blocked state. */
					( void ) uxListRemove( &( pxTCB->xGenericListItem ) );

					/* Is the task waiting on an event also?  If so remove
					it from the event list. */
					if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )
					{
						( void ) uxListRemove( &( pxTCB->xEventListItem ) );
					}
					else
					{
						mtCOVERAGE_TEST_MARKER();
					}

					/* Place the unblocked task into the appropriate ready
					list. */
					prvAddTaskToReadyList( pxTCB );

<---- end critical section here ~~~~ Please let me know if I am right.

If yes shouldn't it be considered in next versions of RTOS improve the real time responsiveness ?

Best regards, Piotr


Why systick decreases real time responsiveness by masking interrupts for all the service routine ?

Posted by davedoors on February 9, 2016

Are you suggesting the critical section could only be around "removing woken tasks from blocked state list and event waiting lists and adding to ready list should be inside critical section" and not also around "delayed tasks list manipulation" to make it shorter? Did you consider also that other interrupts can move a task out of a delayed task list? For example if a semaphore is used in an interrupt it can move a task from a delayed list to an ready list.


Why systick decreases real time responsiveness by masking interrupts for all the service routine ?

Posted by pstepien on February 9, 2016

Dave, You are right, removing from delayed tasks list can be done in isr and must be under critical section.

My point is rather if it is necessary to mask interrupts for whole systick isr. Critical section should be as small as possible. My idea is to divide big block of critical section in systick into smaller parts allowing better response to higher priority interrupt. I have updated the code above with suggested placement of critical section

Regards, Piotr


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner