Quality RTOS & Embedded Software

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


Loading

xStreamBufferReset and Mutex is buggy

Posted by seagull_kamome on June 15, 2018

I guess that my previous post got filtered. So, this is second post.

Hi FreeRTOS developer team.

I’m currently testing FreeRTOS kernel for our project. And, found something weird.

1.

xStreamBufferReset doesn’t save a STATICALLY_ALLOCATED flag in ucFlags. So, it will crashes our system at vStreamBufferDelete by calling free(). 2.

xSemaphoreGet with Mutex doesn’t give priority back to that mutex holder when timed out

Sorry. I can’t explain well in english so I’ll show the unit test code.

Task1

static SemaphoreHandle_t mx1;

static unsigned int volatile test_counter;

static TaskHandlet testtask;

static void testtaskmain_1(void* args __unused) {

xSemaphoreTake(mx1, 10); // will be fail.

++test_counter;

ulTaskNotifyTake(0, portMAX_DELAY);

++test_counter;

xSemaphoreTake(mx1, portMAX_DELAY);

++test_counter;

ulTaskNotifyTake(0, portMAX_DELAY);

++test_counter;

xSemaphoreGive(mx1);

vTaskDelete(NULL);

}

and test task. This task has priority (tskIDLE_PRIORITY + 2).

should_eq(xTaskGetCurrentTaskHandle(), xSemaphoreGetMutexHolder(mx1)); // precondition check

shouldeq(tskIDLEPRIORITY + 2, uxTaskPriorityGet(NULL)); // precondition check

test_counter = 0;

shouldeq(pdTRUE, xTaskCreate(testtaskmain1, "TSK", configMINIMALSTACKSIZE, NULL, tskIDLEPRIORITY + 3, &testtask));

shouldeq(tskIDLEPRIORITY + 3, uxTaskPriorityGet(NULL)); // OK. the priority is inherited.

shouldeq(0, testcounter); // OK. the task still waiting.

vTaskDelay(11);

shouldeq(1, testcounter); // OK. the task already timed out

// All tests is OK until here.

// BUG? FreeRTOS never descent priority into base when the waiting task got timeout.

shouldeq(tskIDLEPRIORITY + 2, uxTaskPriorityGet(NULL)); // Fail: actual is tskIDLE_PRIORITY + 3

xTaskNotifyGive(test_task); // elevate again. the task will preempt control.

taskYIELD(); // but actually not.

shouldeq(2, testcounter); // OK. the task waiting again.

shouldeq(tskIDLEPRIORITY + 3, uxTaskPriorityGet(NULL)); // OK

should_eq(pdTRUE, xSemaphoreGive(mx1)); // OK

shouldeq(3, testcounter); // OK

shouldeq(testtask, xSemaphoreGetMutexHolder(mx1)); // OK

shouldeq(tskIDLEPRIORITY + 2, uxTaskPriorityGet(NULL)); // Fail:! I'm still in tskIDLE_PRIORITY + 3!!!

Thanks


xStreamBufferReset and Mutex is buggy

Posted by seagull_kamome on June 18, 2018

Finally. I found this comment .

            /* Only disinherit if no other mutexes are held.  This is a
			simplification in the priority inheritance implementation.  If
			the task that holds the mutex is also holding other mutexes then
			the other mutexes may have caused the priority inheritance. */

Attachments

alternate (17283 bytes)


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


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

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo, Nuvoton Cortex-M23 demo & STM32H745 dual core (AMP) demo.

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

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

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Mediatek

Renesas

RISC-V

SiFIve RISC-V

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