Problems in Timer Interrupt and Ticks on SMP systems

I am porting FreeRTOS V11.1.0 to my risc-v processor, the system can boot and run now but there’re still some problems with the function vTaskDelay().
I created a task for each core

void task_entry(void *parameter)
{
    while (1)
    {
        int id = csi_get_cpu_id();
        if (xSemaphoreTake(xMutex, portMAX_DELAY) == pdTRUE)
        {
            printf("[%s] in %lu core, count: %d\r\n", pcTaskGetName(NULL), (unsigned long)id, g_count++);
            xSemaphoreGive(xMutex);
        }
        vTaskDelay(pdMS_TO_TICKS(2000));
    }
}

But it only delayed 1000ms in 2-core system, and 500ms in 4-core system.

The function xTaskIncrementTick() was call in my xPortSysTickHandler. it’s in tick_irq_handler() and all the cpus can handle the Timer Interrupt. So the Tick is added repeatedly. This causes the problem.

So I only start the timer in core-0 and stop the timers on other cpus so only core-0 can handle the timer interrupt and send IPI to other cores to schedule. and this seems to work.

Is this the correct way to solve the problem?

Thanks for your response.

Yes, this is the correct way to solve the problem. Feel free to contribute your port to the following repo once you are done - GitHub - FreeRTOS/FreeRTOS-Kernel-Community-Supported-Ports.

Thank you! And I’d be glad to do that.

2 Likes