New upstream version 17.11-rc3
[deb_dpdk.git] / doc / guides / sample_app_ug / dist_app.rst
1 ..  BSD LICENSE
2     Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
3     All rights reserved.
4
5     Redistribution and use in source and binary forms, with or without
6     modification, are permitted provided that the following conditions
7     are met:
8
9     * Redistributions of source code must retain the above copyright
10     notice, this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright
12     notice, this list of conditions and the following disclaimer in
13     the documentation and/or other materials provided with the
14     distribution.
15     * Neither the name of Intel Corporation nor the names of its
16     contributors may be used to endorse or promote products derived
17     from this software without specific prior written permission.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23     OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 Distributor Sample Application
32 ==============================
33
34 The distributor sample application is a simple example of packet distribution
35 to cores using the Data Plane Development Kit (DPDK).
36
37 Overview
38 --------
39
40 The distributor application performs the distribution of packets that are received
41 on an RX_PORT to different cores. When processed by the cores, the destination
42 port of a packet is the port from the enabled port mask adjacent to the one on
43 which the packet was received, that is, if the first four ports are enabled
44 (port mask 0xf), ports 0 and 1 RX/TX into each other, and ports 2 and 3 RX/TX
45 into each other.
46
47 This application can be used to benchmark performance using the traffic
48 generator as shown in the figure below.
49
50 .. _figure_dist_perf:
51
52 .. figure:: img/dist_perf.*
53
54    Performance Benchmarking Setup (Basic Environment)
55
56 Compiling the Application
57 -------------------------
58
59 To compile the sample application see :doc:`compiling`.
60
61 The application is located in the ``distributor`` sub-directory.
62
63 Running the Application
64 -----------------------
65
66 #. The application has a number of command line options:
67
68    ..  code-block:: console
69
70        ./build/distributor_app [EAL options] -- -p PORTMASK
71
72    where,
73
74    *   -p PORTMASK: Hexadecimal bitmask of ports to configure
75
76 #. To run the application in linuxapp environment with 10 lcores, 4 ports,
77    issue the command:
78
79    ..  code-block:: console
80
81        $ ./build/distributor_app -l 1-9,22 -n 4 -- -p f
82
83 #. Refer to the DPDK Getting Started Guide for general information on running
84    applications and the Environment Abstraction Layer (EAL) options.
85
86 Explanation
87 -----------
88
89 The distributor application consists of four types of threads: a receive
90 thread (``lcore_rx()``), a distributor thread (``lcore_dist()``), a set of
91 worker threads (``lcore_worker()``), and a transmit thread(``lcore_tx()``).
92 How these threads work together is shown in :numref:`figure_dist_app` below.
93 The ``main()`` function launches  threads of these four types.  Each thread
94 has a while loop which will be doing processing and which is terminated
95 only upon SIGINT or ctrl+C.
96
97 The receive thread receives the packets using ``rte_eth_rx_burst()`` and will
98 enqueue them to an rte_ring. The distributor thread will dequeue the packets
99 from the ring and assign them to workers (using ``rte_distributor_process()`` API).
100 This assignment is based on the tag (or flow ID) of the packet - indicated by
101 the hash field in the mbuf. For IP traffic, this field is automatically filled
102 by the NIC with the "usr" hash value for the packet, which works as a per-flow
103 tag.  The distributor thread communicates with the worker threads using a
104 cache-line swapping mechanism, passing up to 8 mbuf pointers at a time
105 (one cache line) to each worker.
106
107 More than one worker thread can exist as part of the application, and these
108 worker threads do simple packet processing by requesting packets from
109 the distributor, doing a simple XOR operation on the input port mbuf field
110 (to indicate the output port which will be used later for packet transmission)
111 and then finally returning the packets back to the distributor thread.
112
113 The distributor thread will then call the distributor api
114 ``rte_distributor_returned_pkts()`` to get the processed packets, and will enqueue
115 them to another rte_ring for transfer to the TX thread for transmission on the
116 output port. The transmit thread will dequeue the packets from the ring and
117 transmit them on the output port specified in packet mbuf.
118
119 Users who wish to terminate the running of the application have to press ctrl+C
120 (or send SIGINT to the app). Upon this signal, a signal handler provided
121 in the application will terminate all running threads gracefully and print
122 final statistics to the user.
123
124 .. _figure_dist_app:
125
126 .. figure:: img/dist_app.*
127
128    Distributor Sample Application Layout
129
130
131 Debug Logging Support
132 ---------------------
133
134 Debug logging is provided as part of the application; the user needs to uncomment
135 the line "#define DEBUG" defined in start of the application in main.c to enable debug logs.
136
137 Statistics
138 ----------
139
140 The main function will print statistics on the console every second. These
141 statistics include the number of packets enqueued and dequeued at each stage
142 in the application, and also key statistics per worker, including how many
143 packets of each burst size (1-8) were sent to each worker thread.
144
145 Application Initialization
146 --------------------------
147
148 Command line parsing is done in the same way as it is done in the L2 Forwarding Sample
149 Application. See :ref:`l2_fwd_app_cmd_arguments`.
150
151 Mbuf pool initialization is done in the same way as it is done in the L2 Forwarding
152 Sample Application. See :ref:`l2_fwd_app_mbuf_init`.
153
154 Driver Initialization is done in same way as it is done in the L2 Forwarding Sample
155 Application. See :ref:`l2_fwd_app_dvr_init`.
156
157 RX queue initialization is done in the same way as it is done in the L2 Forwarding
158 Sample Application. See :ref:`l2_fwd_app_rx_init`.
159
160 TX queue initialization is done in the same way as it is done in the L2 Forwarding
161 Sample Application. See :ref:`l2_fwd_app_tx_init`.