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