xref: /rockchip-linux_mpp/doc/design/4.mpp_task.txt (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
1MPP task design (2017.4.7)
2================================================================================
3
4Mpp task is the contain component for transaction with external user in advanced
5mode. The target of advanced mode is to provide flexible, multiple input/output
6content for extension.
7
8Mpp task has mpp_meta as the rich content carrier. Mpp meta uses KEY and value
9pair for extension. One task can carries multiple data into or out of mpp.
10The typical case is encoder with OSD and motion detection. One task may contain
11OSD buffer, motion detection buffer, frame buffer and stream buffer as input and
12output stream buffer and motion detection buffer with data. And this case can
13also be used on decoder if decoder wants to output some side information.
14
15
16Mpp task transaction
17================================================================================
18
191. Mpp task queue
20Mpp task queue is the manager of tasks. Due to user may incorrectly use the task
21we choose the design that hold all task inside mpp. Task queue will create and
22release task. But task queue will not interact with user directly. We use port
23and task status to control the transaction.
24
252. Mpp port
26Mpp port is the transaction interface of task queue. External user and internal
27worker thread will use mpp_port_poll / mpp_port_dequeue / mpp_port_enqueue
28interface to poll / dequeue / enqueue the task task queue. Mpp advanced mode is
29using port to connect external user, interface storage and internal process
30thread. Each task queue has two port: input port and output port. And from a
31global view the task will always flow from input port to output port.
32
333. Mpp task status
34There are four status for one task. Mpp use list_head to represent the status.
35
36INPUT_PORT : Initial status for input port user to dequeue. Or when output port
37             successfully enqueue a task then the task is on this status.
38
39INPUT_HOLD : When input port user successfully dequeue a task then the task is
40             on this status.
41
42OUTPUT_PORT: When input port user successfully enqueue a task then the task is
43             on OUTPUT_PORT status. And this task is ready for dequeue from
44             output port.
45
46OUTPUT_HOLD: When output port user successfully dequeue a task then the task is
47             on this status.
48
494. Mpp task / port transaction
50There are three transaction functions on a port: poll / dequeue / enqueue.
51When port user call the transaction function task will be transfer from one
52status to next status. The status transform flow is unidirectional from input
53port to output port.
54
55The overall relationship graph of task / port / status is shown below.
56
57                               1. task queue
58                       +------------------------------+
59                       |                              |
60                  +----+----+  +--------------+  +----+----+
61                  |    4    |  |       3      |  |   2.1   |
62         +--------+ dequeue <--+    status    <--+ enqueue <---------+
63         |        |         |  |  INPUT_PORT  |  |         |         |
64         |        +---------+  |              |  +---------+         |
65  +------v-----+  |         |  +--------------+  |         |  +------+------+
66  |      3     |  |    2    |                    |    2    |  |      3      |
67  |   status   |  |  input  |                    |  output |  |   status    |
68  | INPUT_HOLD |  |   port  |                    |   port  |  | OUTPUT_HOLD |
69  |            |  |         |                    |         |  |             |
70  +------+-----+  |         |  +--------------+  |         |  +------^------+
71         |        +---------+  |       3      |  +---------+         |
72         |        |    4    |  |    status    |  |   2.1   |         |
73         +--------> enqueue +-->  INPUT_PORT  +--> dequeue +---------+
74                  |         |  |              |  |         |
75                  +----+----+  +--------------+  -----+----+
76                       |                              |
77                       +------------------------------+
78
79
80Mpp task transaction of a complete work flow
81================================================================================
82
83On advanced mode mpp uses two task queue: input task queue and output task
84queue.
85Input task queue connects input side external user to internal worker thread.
86Output task queue connects internal worker thread to output side external user.
87Then there will be three threads to parallelize internal process and external
88transation. This will maximize mpp efficiency.
89
90The work flow is demonstrated as below graph.
91
92            +-------------------+           +-------------------+
93            |  input side user  |           | output side user  |
94            +----^---------+----+           +----^---------+----+
95                 |         |                     |         |
96            +----+----+----v----+           +----+----+----v----+
97            | dequeue | enqueue |           | dequeue | enqueue |
98            +----^----+----+----+           +----^----+----+----+
99                 |         |                     |         |
100            +----+---------+----+    MPP    +----+---------v----+
101        +---+     input port    +-----------+    output port    +---+
102        |   +-------------------+           +-------------------+   |
103        |   |  input task queue |           | output task queue |   |
104        |   +-------------------+           +-------------------+   |
105        |   |    output port    |           |     input port    |   |
106        |   +----+---------^----+           +----+---------^----+   |
107        |        |         |                     |         |        |
108        |   +----v----+----+----+           +----v----+----+----+   |
109        |   | dequeue | enqueue |           | dequeue | enqueue |   |
110        |   +----+----+----^----+           +----+----+----^----+   |
111        |        |         |                     |         |        |
112        |   +----v---------+---------------------v---------+----+   |
113        |   |              internal work thread                 |   |
114        |   +---------------------------------------------------+   |
115        |                                                           |
116        +-----------------------------------------------------------+
117
118