Quality RTOS & Embedded Software

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


Task switch on 8051 - stack-copy overhead?

Posted by Mark on March 20, 2008
I am looking at FreeRTOS for an 8051 device. I was wondering how the task switch handles the stack. As I understand things the 8051 stack is limited to a single 256 byte memory space and so on a task switch everything has to copied out to / in from XDATA. That does not strike me as optimal (but hardly the OS's fault) and so are there some clever solutions FreeRTOS uses to get around it? Maybe it requires a modified 8051 that can map in XDATA to the stack space or something? Any advice and insight would be greatly appreciated.


RE: Task switch on 8051 - stack-copy overhead?

Posted by woops_ on March 20, 2008
That is how the 8051 works its fixed, and by todays standard its not good. It was never designed to be use in larger applications so it is a shame the otherwise very nice Sil Labs parts use 8051.

RE: Task switch on 8051 - stack-copy overhead?

Posted by Mark on March 21, 2008
Thanks for the response. I kinda expected that would be the case. I guess that sometimes we forget that just adding memory and running at faster clock speeds doesn't solve everything. It doesn't make the 8051 a bad processor though - just defines a limit of what it can/should be used for.

RE: Task switch on 8051 - stack-copy overhead

Posted by David Hawks on March 21, 2008
Some of the more exotic devices have 16-bit stack pointers, but most 8051 variants are locked in to an 8-bit stack pointer. Not much an OS can do about that.

The 8051 FreeRTOS port copies the used portion of the internal stack to/from XDATA on a context switch. The stack copy adds a significant amount of overhead to a context switch. If you expect your application to use most of the processing power of the controller, you probably ought to look elsewhere. However, if you can handle the overhead, FreeRTOS on an 8051 works pretty nicely.

I use FreeRTOS on several SiLabs 8051 parts. I run the system clock at 100 MHz with a FreeRTOS tick rate of 1 kHz. The average context switch time is 42 us (worst case of 62 us with a full stack). This leaves a task with about 950 us of execution time (~95,000 cycles). In other words, my configuration has a context switch overhead of about 5%. My average processor utilization is under 50%, so I can afford the overhead.

Good Luck!

RE: Task switch on 8051 - stack-copy overhead?

Posted by Mark on April 14, 2008
Thanks for your answers - I have a clear picture of the issues now.

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

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

Latest News

Version 10.1.0 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.


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


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