This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

J784S4XEVM: TIOVX Target Priority

Part Number: J784S4XEVM

Tool/software:

Hello,
We need to run a custom TIOVX kernel on the A72 core with high/real-time priority on both QNX and Linux.

It appears there is a provision for this in tivx_task.c under the following section:
                #if 0
                {
                    struct sched_param schedprm;
                    uint32_t pri;

                    if(task->stack_size>0)
                    {
                        status |= pthread_attr_setstacksize(&thread_attr, task->stack_size);
                    }
                    status |= pthread_attr_setschedpolicy(&thread_attr, SCHED_RR);

                    pri = PRI_MIN;
                    if(task->priority==TIVX_TASK_PRI_HIGHEST)
                    {
                        pri = PRI_MAX;
                    }
                    else
                    if(task->priority==TIVX_TASK_PRI_LOWEST)
                    {
                        pri = PRI_MIN;
                    }

                    schedprm.sched_priority = pri;
                    status |= pthread_attr_setschedparam(&thread_attr, &schedprm);
                }
                #endif
However, this code is currently disabled with #if 0.

When I enable it by changing #if 0 to #if 1, the application crashes.

To address this, we implemented a workaround, which is attached as a patch file.

We would like to know:
  1. What is TI's recommendation for setting higher task priority in a production use case?
  2. Will the #if 0 block be removed or properly implemented in the next release?

Thank you,

From 3a861516201e386a991fcadd71f35f905edcc84c Mon Sep 17 00:00:00 2001
From: Semyon Sylka <semyon.sylka@cogentembedded.com>
Date: Thu, 5 Dec 2024 23:00:15 +0300
Subject: [PATCH] TIOVX: Add Realtime task creation API for posix

---
 tiovx/include/TI/tivx_task.h                  | 12 +++++
 tiovx/source/platform/os/posix/tivx_task.c    | 51 +++++++++----------
 tiovx/source/platform/os/win32/tivx_task.c    |  5 ++
 .../source/platform/psdk_j7/rtos/tivx_task.c  |  5 ++
 4 files changed, 47 insertions(+), 26 deletions(-)

diff --git a/tiovx/include/TI/tivx_task.h b/tiovx/include/TI/tivx_task.h
index 220b6248..3cd48ab1 100755
--- a/tiovx/include/TI/tivx_task.h
+++ b/tiovx/include/TI/tivx_task.h
@@ -220,6 +220,18 @@ void tivxTaskSetDefaultCreateParams(tivx_task_create_params_t *params);
  */
 vx_status tivxTaskCreate(tivx_task *task, const tivx_task_create_params_t *params);
 
+/*!
+ * \brief Create a "real-time" scheduled task
+ *
+ * \param task [out] Pointer to task object
+ * \param params [in] Task create parameters
+ *
+ * \return VX_SUCCESS on success
+ *
+ * \ingroup group_tivx_task
+ */
+vx_status tivxTaskCreateRt(tivx_task *task, const tivx_task_create_params_t *params);
+
 /*!
  * \brief Delete a task
  *
diff --git a/tiovx/source/platform/os/posix/tivx_task.c b/tiovx/source/platform/os/posix/tivx_task.c
index a4d78533..a3eb1f20 100644
--- a/tiovx/source/platform/os/posix/tivx_task.c
+++ b/tiovx/source/platform/os/posix/tivx_task.c
@@ -100,7 +100,9 @@ static void *tivxTaskMain(void *arg)
     return NULL;
 }
 
-vx_status tivxTaskCreate(tivx_task *task, const tivx_task_create_params_t *params)
+static vx_status tivxTaskCreateWithPriority(tivx_task *task,
+                                            const tivx_task_create_params_t *params,
+                                            bool set_priority)
 {
     vx_status status = (vx_status)VX_SUCCESS;
 
@@ -131,37 +133,24 @@ vx_status tivxTaskCreate(tivx_task *task, const tivx_task_create_params_t *param
 
             if(status==0)
             {
-                #if 0
+                status = pthread_create(&context->hndl, &thread_attr, tivxTaskMain, task);
+
+                if(status==0 && set_priority)
                 {
-                    struct sched_param schedprm;
-                    uint32_t pri;
+                    struct sched_param param;
+                    int policy = SCHED_FIFO; // Use SCHED_FIFO for real-time
+                    int max_priority = sched_get_priority_max(policy);
 
-                    if(task->stack_size>0)
-                    {
-                        status |= pthread_attr_setstacksize(&thread_attr, task->stack_size);
-                    }
-                    status |= pthread_attr_setschedpolicy(&thread_attr, SCHED_RR);
+                    param.sched_priority = max_priority;
 
-                    pri = PRI_MIN;
-                    if(task->priority==TIVX_TASK_PRI_HIGHEST)
-                    {
-                        pri = PRI_MAX;
-                    }
-                    else
-                    if(task->priority==TIVX_TASK_PRI_LOWEST)
-                    {
-                        pri = PRI_MIN;
-                    }
+                    // Set scheduling policy and priority
+                    status = pthread_setschedparam(context->hndl, policy, &param);
 
-                    schedprm.sched_priority = pri;
-                    status |= pthread_attr_setschedparam(&thread_attr, &schedprm);
+                    if (status != 0) {
+                        VX_PRINT(VX_ZONE_ERROR, "Failed to setup sched params\n");
+                    }
                 }
-                #endif
 
-                if(status==0)
-                {
-                    status = pthread_create(&context->hndl, &thread_attr, tivxTaskMain, task);
-                }
                 (void)pthread_attr_destroy(&thread_attr);
             }
             if (status == 0)
@@ -187,6 +176,16 @@ vx_status tivxTaskCreate(tivx_task *task, const tivx_task_create_params_t *param
     return (status);
 }
 
+vx_status tivxTaskCreate(tivx_task *task, const tivx_task_create_params_t *params)
+{
+    return tivxTaskCreateWithPriority(task, params, false);
+}
+
+vx_status tivxTaskCreateRt(tivx_task *task, const tivx_task_create_params_t *params)
+{
+    return tivxTaskCreateWithPriority(task, params, true);
+}
+
 vx_status tivxTaskDelete(tivx_task *task)
 {
     vx_status status = (vx_status)VX_SUCCESS;
diff --git a/tiovx/source/platform/os/win32/tivx_task.c b/tiovx/source/platform/os/win32/tivx_task.c
index e13771ca..4ce11cc6 100644
--- a/tiovx/source/platform/os/win32/tivx_task.c
+++ b/tiovx/source/platform/os/win32/tivx_task.c
@@ -143,6 +143,11 @@ vx_status tivxTaskCreate(tivx_task *task, tivx_task_create_params_t *params)
     return (status);
 }
 
+vx_status tivxTaskCreateRt(tivx_task *task, const tivx_task_create_params_t *params)
+{
+    return tivxTaskCreate(task, params);
+}
+
 vx_status tivxTaskDelete(tivx_task *task)
 {
     vx_status status = (vx_status)VX_SUCCESS;
diff --git a/tiovx/source/platform/psdk_j7/rtos/tivx_task.c b/tiovx/source/platform/psdk_j7/rtos/tivx_task.c
index 3200b0ec..e93f7451 100644
--- a/tiovx/source/platform/psdk_j7/rtos/tivx_task.c
+++ b/tiovx/source/platform/psdk_j7/rtos/tivx_task.c
@@ -104,6 +104,11 @@ vx_status tivxTaskCreate(tivx_task *task, const tivx_task_create_params_t *param
     return (status);
 }
 
+vx_status tivxTaskCreateRt(tivx_task *task, const tivx_task_create_params_t *params)
+{
+    return tivxTaskCreate(task, params);
+}
+
 vx_status tivxTaskDelete(tivx_task *task)
 {
     vx_status status = (vx_status)VX_SUCCESS;
-- 
2.34.1

  • Hi Petr,

     I will check this internally and get back to you.

    Regards,
    Gokul

  • Hi Petr,

    This unused code will be removed in the next release, The primary purpose of this API is to enable functionality in the framework with the added benefit that it also can be used by the application, customers can extend this API to implement threads with desired priority within their application. The patch will not be integrated in the sdk.

    Thank you for posting this information.

    Regards,
    Gokul