Quality RTOS & Embedded Software

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




Loading

WIN32 Port

Posted by Philip Stuyck on December 11, 2009
I am using the WIN32 simulation which is provided with FreeRTOS.
If I am reading the code correctly it is triggering preemption every tick. And there is a tick for every ms.
Is this intended ? If you run a test application with 3 tasks with the same priority to test the preemption I see that the time an individual thread runs is not really equal like I anticipated them to be.
I can understand having a tick every ms, to keep track of time but not to trigger preemption and to schedule the next task.
Further is you debug this code, and set a break on vTaskSwitchContext, I notice this is triggerred indeed very much, but the tasks are not really switching. Even though I do see a different tcb being selected and the thread being enabled. I have the feeling the next tick comes already before the task got a chance to run.
Isnt it more likely to have preempion say every 100 ticks ?
and to have a tick of 1ms to be able to make timers ?

RE: WIN32 Port

Posted by Dave on December 11, 2009
How do you mean the tasks are not really switching? How do you know. Remember this is just a simulator.

RE: WIN32 Port

Posted by Philip Stuyck on December 12, 2009
I am using following code :



static void vTestFunction1(void *pvParameters )
{
static int i=0;
for(;;){
i++;
printf("vTestFunction1 %d\n",i);
//vTaskDelay(0);
}
}

static void vTestFunction2(void *pvParameters )
{
static int i=0;
for(;;){
i++;
printf("vTestFunction2 %d\n",i);
//vTaskDelay(0);
}
}

xTaskCreate( vTestFunction1,"TST1",100,NULL,0,NULL);
xTaskCreate( vTestFunction2,"TST2",100,NULL,0,NULL);
vTaskStartScheduler();

then you can see visually that the tasks are switching but the switching rate seems erratic and not consistently switching say every 100ms but rather say every 10seconds or something. I can see this on the screen.
Even if the screen is slow that still does not mean that the times the switching occurs should not be a bit more predictable.
Then I also set a breakpoint on vTaskSwitchContext which is supposed to to the switch but does so every ms.
I am going to change the tick rate to 1s to see if that has any effect.

RE: WIN32 Port

Posted by Dave on December 12, 2009
I suspect you are printing out faster than the console can cope with, and that you are using printf() without any sort of mutual exclusion (two threads trying to access the console at the same time).

Use some sort of mutual exclusion (scheduler lock maybe as PCs can do weird things with interrupts) or even a single task to write to the console with other tasks sending messages to the console task.

RE: WIN32 Port

Posted by Philip Stuyck on December 12, 2009
I added a semaphore to protect the printing itself, that seems to yield better results.
Still I don't see why you would need to preempt every ms.

RE: WIN32 Port

Posted by Richard on December 12, 2009
> Still I don't see why you would need to preempt every ms.

You don't, in most cases. Demos are provided with a 1ms pre-emption in part to test the port. The documentation pages for (nearly?) all state it is faster than necessary for most applications.

Regards.

RE: WIN32 Port

Posted by Richard Damon on December 12, 2009
I will also add, that once you have determined the needed tick rate for an application based on resolution needed for things like timeouts, there generally isn't a reason you can't do task switching at this rate. You already have done the context save entering the tick interrupt, and need to do a lot of the scheduler work to see if someone higher has woken up, so switch to the next in line is fairly additional cost. Also the sort of processors FreeRTOS is aimed out don't tend to have things like caches or swap files that cause additional penalties for switching between tasks, which is one reason OSes on bigger machines use longer execution quanta for low priority tasks.


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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