Multiprocessor Tasks Overview

The Multiprocessor (MP) library provides a simple mechanism for distributing computational tasks across multiple CPU cores.

Task

The MP library implements individual tasks using the MPTask structure. Each task consists of:

Task Queue

Individual tasks are collected and processed using a Task Queue mechanism. The MP library implements task queues using the MPTaskQ structure. The implementation is multicore and thread-safe, which facilitates creating and processing a single task queue across multiple CPU cores. If necessary, applications can further divide tasks by implementing multiple task queue objects.

The MPTaskQ mechanism allows tasks to be created and enqueued from threads running on any CPU core. Conversely any thread can initiate the processing of items in the task queue.

Task Processing

API functions in the MP library can process task queues manually or automatically.

Manual Processing

The MPDequeTask function can dequeue tasks individually using, and the MPDequeTasks function can dequeue multiple tasks simultaneously. Tasks removed from the queue in this manner must be manually processed by using the MPRunTask function. The task is scheduled to run on the CPU core that called MPRunTask.

Figure 1: Manual Task Processing
static int Sub1Main(int intArg, void *ptrArg)
{
    MPTask* pTask;

    // wait till the state of task queue is MP_TASKQ_RUN
    MPWaitTaskQ(&TaskQueue, MP_WAIT_TASKQ_RUN);

    // dequeue and execute the task
    while ( (pTask = MPDequeTask(&TaskQueue)) != NULL )
    {
        MPRunTask(pTask);
    }

    return 0;
}

Automatic Processing

API functions in the MP library can automatically process task queues. First, the queue must be put into a runnable state by using the MPStartTaskQ function. Actual task processing commences after the MPRunTasksFromTaskQ function is in the task queue from any thread or threads. Tasks are automatically processed on each core that calls the MPRunTasksFromTaskQ function until the queue is empty or until processing is manually halted by using the MPStopTaskQ function.

Figure 2: Automatic Task Processing
static int Sub2Main(int intArg, void *ptrArg)
{
    u32    coreId = OSGetCoreId;

    // wait till the state of task queue is MP_TASKQ_RUN
    MPWaitTaskQ(&TaskQueue, MP_WAIT_TASKQ_RUN);

    while (1)
    {
        // execute the task
        if (MPRunTasksFromTaskQ(&TaskQueue, 1) == TRUE)
        {
            break;
        }
    }

    return 0;
}


Revision History

2013/05/08 Automated cleanup pass.
2013/02/15 Initial version.


CONFIDENTIAL