RTEMS tasks timesliced instead of running to completion. TIMESLICE flag is not active!

Fernando Domínguez Pousa fdpousa at gmv.com
Thu Apr 30 15:29:52 UTC 2020


Yes, of course!

The Init function

rtems_task Init(rtems_task_argument argument)
{
    rtems_status_code status;
    rtems_name Task_name[TASKS]; /* task names */
    rtems_id Task_id[TASKS]; /* task ids */
    int i;

    all_OK = 1;
    g_init_task_id = rtems_task_self();
    for(i = 0; i < TASKS; i++)
    {
        // Initialize Task name
        Task_name[i] = rtems_build_name('T', 'T', "0" + i / 10, "0" + i % 10);

        // Create Task
        status = rtems_task_create(
            Task_name[i],
            (rtems_task_priority) 2,
            RTEMS_MINIMUM_STACK_SIZE,
            RTEMS_DEFAULT_MODES,
            (i%2) == 0 ? RTEMS_FLOATING_POINT : RTEMS_DEFAULT_ATTRIBUTES,
            &Task_id[i]);
                if (status != RTEMS_SUCCESSFUL) {
                    printf(
                "[MAIN] Failed to rtems_task_create... status:%0x\n",
                status);
            rtems_task_delete(RTEMS_SELF);
                }

        // Start Task
        status = rtems_task_start(
            Task_id[i],
            (i%2) == 0 ? Task1_EntryPoint : Task2_EntryPoint,
            i);
    }
    // To give coverage code the opportunity to work, wait for children tasks
    // to die first. RTEMS events are used for synchronization.
    {
        printf("[MAIN] Waiting for testing tasks to complete...\n");
        rtems_option options = (RTEMS_EVENT_ANY | RTEMS_WAIT);
        rtems_event_set in = 0;
        for (i=0; i<TASKS; i++)
            in |= (RTEMS_EVENT_0 << i);
        rtems_event_set out;
        rtems_event_set non_completed = in;
        while (non_completed) {
            status = rtems_event_receive(in, options, RTEMS_NO_TIMEOUT, &out);
            if ( status == RTEMS_SUCCESSFUL ) {
                non_completed &= ~out;
                printf("[MAIN] Task completed.\n");
                fflush(stdout);
            }
        }
        printf("[MAIN] All testing tasks completed.\n");
        if (!all_OK)
            printf("[MAIN] Some tests failed... :-(\n");
        else
            printf("[MAIN] All tests passed! :-)\n");
        fflush(stdout);
    }
    exit(0);
}

The system.h flags:

// Comment this to skip memory checks at startup
#include <rtems.h>

rtems_task Init(rtems_task_argument argument);
rtems_task Task1_EntryPoint(rtems_task_argument argument);
rtems_task Task2_EntryPoint(rtems_task_argument argument);
void task_begin(int task_no);
void task_end(int task_no);
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_TASKS           64
#define CONFIGURE_TICKS_PER_TIMESLICE     100
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER

#define CONFIGURE_MAXIMUM_PROCESSORS  1

#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
#ifndef DEFINE_VARS
#define GLOBAL
#else
#define GLOBAL extern
#endif

GLOBAL rtems_id g_init_task_id;
GLOBAL int all_OK;

#include <rtems/confdefs.h>


Regards,

From: Joel Sherrill [mailto:joel at rtems.org]
Sent: 30 April 2020 17:25
To: Fernando Domínguez Pousa <fdpousa at gmv.com>
Cc: rtems-users at rtems.org <users at rtems.org>
Subject: Re: RTEMS tasks timesliced instead of running to completion. TIMESLICE flag is not active!


On Thu, Apr 30, 2020, 10:14 AM Fernando Domínguez Pousa <fdpousa at gmv.com<mailto:fdpousa at gmv.com>> wrote:
Hello,

I am executing a program which executes four different task with testing operations. These tasks were created and launched in this way:

status = rtems_task_create(Task_name[i], (rtems_task_priority) 2, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES,
            (i%2) == 0 ? RTEMS_FLOATING_POINT : RTEMS_DEFAULT_ATTRIBUTES, &Task_id[i]);

status = rtems_task_start(Task_id[i], (i%2) == 0 ? Task1_EntryPoint : Task2_EntryPoint, i);

As you can see all task are created with the same priority, and launched one after the other inside a for loop. They are configured in default modes, so time slicing is disabled by default  (all mode bits are 0). This result would be expected due to each task would run-to-completion because all tasks have the same priority:

The expected result:
[MAIN] Waiting for testing tasks to complete...
[TASK 0] Starting...
[TASK 0] Computed the correct floating point result.
[TASK 1] Starting...
[TASK 1] Computed the correct integer result.
[TASK 2] Starting...
[TASK 2] Computed the correct floating point result.
[TASK 3] Starting...
[TASK 3] Computed the correct integer result.
[MAIN] All testing tasks completed.

Nevertheless, using RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_MODES | RTEMS_TIMESLICE or RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT either as rtems_mode, the result is always the same.

The actual result:
[MAIN] Waiting for testing tasks to complete...
[TASK 0] Starting...
[TASK 1] Starting...
[TASK 2] Starting...
[TASK 3] Starting...
[TASK 0] Computed the correct floating point result.
[TASK 1] Computed the correct integer result.
[TASK 2] Computed the correct floating point result.
[TASK 3] Computed the correct integer result.
[MAIN] All testing tasks completed.

At RTEMS API Guide:

The timeslicing component is used by the RTEMS scheduler to determine how the processor is allocated to tasks of equal priority. If timeslicing is enabled (RTEMS_TIMESLICE), then RTEMS will limit the amount of time the task can execute before the processor is allocated to another ready task of equal priority.

The length of the timeslice is application dependent and specified in the Configuration Table. If timeslicing is disabled (RTEMS_NO_TIMESLICE), then the task will be allowed to execute until a task of higher priority is made ready. However I have not any task with higher priority, Init task priority is lower.

If RTEMS_NO_PREEMPT is selected, then the timeslicing component is ignored by the scheduler.

How can I execute this tasks in a run to completion fashion for same priority tasks? Task 0 starts and ends, then Task1 starts and ends… etc,

There are many things that could be happening. Can you post the program?

Regards,

Fer.


P Please consider the environment before printing this e-mail.
_______________________________________________
users mailing list
users at rtems.org<mailto:users at rtems.org>
http://lists.rtems.org/mailman/listinfo/users<https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.rtems.org_mailman_listinfo_users&d=DwMFaQ&c=CIoxZ4z5BqFvKvSGFOTo726QZIiNTc_M9CmngT-Pla4&r=JJRyTkGL8xI4YFJLjo7JWw&m=eA8anYgLQgGFwVgCLATXru_x-4j7u20NTGRywCGAw9Y&s=guJu7NictdpU__9Y8_UI5N6v59ZBZISZj4UhMXuCJkU&e=>

P Please consider the environment before printing this e-mail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20200430/e3168773/attachment-0001.html>


More information about the users mailing list