xref: /dpdk/doc/guides/prog_guide/packet_distrib_lib.rst (revision fc1f2750a3ec6da919e3c86e59d56f34ec97154b)
1*fc1f2750SBernard Iremonger..  BSD LICENSE
2*fc1f2750SBernard Iremonger    Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
3*fc1f2750SBernard Iremonger    All rights reserved.
4*fc1f2750SBernard Iremonger
5*fc1f2750SBernard Iremonger    Redistribution and use in source and binary forms, with or without
6*fc1f2750SBernard Iremonger    modification, are permitted provided that the following conditions
7*fc1f2750SBernard Iremonger    are met:
8*fc1f2750SBernard Iremonger
9*fc1f2750SBernard Iremonger    * Redistributions of source code must retain the above copyright
10*fc1f2750SBernard Iremonger    notice, this list of conditions and the following disclaimer.
11*fc1f2750SBernard Iremonger    * Redistributions in binary form must reproduce the above copyright
12*fc1f2750SBernard Iremonger    notice, this list of conditions and the following disclaimer in
13*fc1f2750SBernard Iremonger    the documentation and/or other materials provided with the
14*fc1f2750SBernard Iremonger    distribution.
15*fc1f2750SBernard Iremonger    * Neither the name of Intel Corporation nor the names of its
16*fc1f2750SBernard Iremonger    contributors may be used to endorse or promote products derived
17*fc1f2750SBernard Iremonger    from this software without specific prior written permission.
18*fc1f2750SBernard Iremonger
19*fc1f2750SBernard Iremonger    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20*fc1f2750SBernard Iremonger    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21*fc1f2750SBernard Iremonger    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22*fc1f2750SBernard Iremonger    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23*fc1f2750SBernard Iremonger    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24*fc1f2750SBernard Iremonger    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25*fc1f2750SBernard Iremonger    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26*fc1f2750SBernard Iremonger    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27*fc1f2750SBernard Iremonger    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28*fc1f2750SBernard Iremonger    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29*fc1f2750SBernard Iremonger    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*fc1f2750SBernard Iremonger
31*fc1f2750SBernard IremongerPacket Distributor Library
32*fc1f2750SBernard Iremonger==========================
33*fc1f2750SBernard Iremonger
34*fc1f2750SBernard IremongerThe Intel® DPDK Packet Distributor library is a library designed to be used for dynamic load balancing of traffic
35*fc1f2750SBernard Iremongerwhile supporting single packet at a time operation.
36*fc1f2750SBernard IremongerWhen using this library, the logical cores in use are to be considered in two roles: firstly a distributor lcore,
37*fc1f2750SBernard Iremongerwhich is responsible for load balancing or distributing packets,
38*fc1f2750SBernard Iremongerand a set of worker lcores which are responsible for receiving the packets from the distributor and operating on them.
39*fc1f2750SBernard IremongerThe model of operation is shown in the diagram below.
40*fc1f2750SBernard Iremonger
41*fc1f2750SBernard Iremonger|packet_distributor1|
42*fc1f2750SBernard Iremonger
43*fc1f2750SBernard IremongerDistributor Core Operation
44*fc1f2750SBernard Iremonger--------------------------
45*fc1f2750SBernard Iremonger
46*fc1f2750SBernard IremongerThe distributor core does the majority of the processing for ensuring that packets are fairly shared among workers.
47*fc1f2750SBernard IremongerThe operation of the distributor is as follows:
48*fc1f2750SBernard Iremonger
49*fc1f2750SBernard Iremonger#.  Packets are passed to the distributor component by having the distributor lcore thread call the "rte_distributor_process()" API
50*fc1f2750SBernard Iremonger
51*fc1f2750SBernard Iremonger#.  The worker lcores all share a single cache line with the distributor core in order to pass messages and packets to and from the worker.
52*fc1f2750SBernard Iremonger    The process API call will poll all the worker cache lines to see what workers are requesting packets.
53*fc1f2750SBernard Iremonger
54*fc1f2750SBernard Iremonger#.  As workers request packets, the distributor takes packets from the set of packets passed in and distributes them to the workers.
55*fc1f2750SBernard Iremonger    As it does so, it examines the "tag" -- stored in the RSS hash field in the mbuf -- for each packet
56*fc1f2750SBernard Iremonger    and records what tags are being processed by each  worker.
57*fc1f2750SBernard Iremonger
58*fc1f2750SBernard Iremonger#.  If the next packet in the input set has a tag which is already being processed by a worker,
59*fc1f2750SBernard Iremonger    then that packet will be queued up for processing by that worker
60*fc1f2750SBernard Iremonger    and given to it in preference to other packets when that work next makes a request for work.
61*fc1f2750SBernard Iremonger    This ensures that no two packets with the same tag are processed in parallel,
62*fc1f2750SBernard Iremonger    and that all packets with the same tag are processed in input order.
63*fc1f2750SBernard Iremonger
64*fc1f2750SBernard Iremonger#.  Once all input packets passed to the process API have either been distributed to workers
65*fc1f2750SBernard Iremonger    or been queued up for a worker which is processing a given tag,
66*fc1f2750SBernard Iremonger    then the process API returns to the caller.
67*fc1f2750SBernard Iremonger
68*fc1f2750SBernard IremongerOther functions which are available to the distributor lcore are:
69*fc1f2750SBernard Iremonger
70*fc1f2750SBernard Iremonger*   rte_distributor_returned_pkts()
71*fc1f2750SBernard Iremonger
72*fc1f2750SBernard Iremonger*   rte_distributor_flush()
73*fc1f2750SBernard Iremonger
74*fc1f2750SBernard Iremonger*   rte_distributor_clear_returns()
75*fc1f2750SBernard Iremonger
76*fc1f2750SBernard IremongerOf these the most important API call is "rte_distributor_returned_pkts()"
77*fc1f2750SBernard Iremongerwhich should only be called on the lcore which also calls the process API.
78*fc1f2750SBernard IremongerIt returns to the caller all packets which have finished processing by all worker cores.
79*fc1f2750SBernard IremongerWithin this set of returned packets, all packets sharing the same tag will be returned in their original order.
80*fc1f2750SBernard Iremonger
81*fc1f2750SBernard Iremonger**NOTE:**
82*fc1f2750SBernard IremongerIf worker lcores buffer up packets internally for transmission in bulk afterwards,
83*fc1f2750SBernard Iremongerthe packets sharing a tag will likely get out of order.
84*fc1f2750SBernard IremongerOnce a worker lcore requests a new packet, the distributor assumes that it has completely finished with the previous packet and
85*fc1f2750SBernard Iremongertherefore that additional packets with the same tag can safely be distributed to other workers --
86*fc1f2750SBernard Iremongerwho may then flush their buffered packets sooner and cause packets to get out of order.
87*fc1f2750SBernard Iremonger
88*fc1f2750SBernard Iremonger**NOTE:**
89*fc1f2750SBernard IremongerNo packet ordering guarantees are made about packets which do not share a common packet tag.
90*fc1f2750SBernard Iremonger
91*fc1f2750SBernard IremongerUsing the process and returned_pkts API, the following application workflow can be used,
92*fc1f2750SBernard Iremongerwhile allowing packet order within a packet flow -- identified by a tag -- to be maintained.
93*fc1f2750SBernard Iremonger
94*fc1f2750SBernard Iremonger.. image41_png has been renamed
95*fc1f2750SBernard Iremonger
96*fc1f2750SBernard Iremonger|packet_distributor2|
97*fc1f2750SBernard Iremonger
98*fc1f2750SBernard IremongerThe flush and clear_returns API calls, mentioned previously,
99*fc1f2750SBernard Iremongerare likely of less use that the process and returned_pkts APIS, and are principally provided to aid in unit testing of the library.
100*fc1f2750SBernard IremongerDescriptions of these functions and their use can be found in the Intel® DPDK API Reference document.
101*fc1f2750SBernard Iremonger
102*fc1f2750SBernard IremongerWorker Operation
103*fc1f2750SBernard Iremonger----------------
104*fc1f2750SBernard Iremonger
105*fc1f2750SBernard IremongerWorker cores are the cores which do the actual manipulation of the packets distributed by the packet distributor.
106*fc1f2750SBernard IremongerEach worker calls "rte_distributor_get_pkt()" API to request a new packet when it has finished processing the previous one.
107*fc1f2750SBernard Iremonger[The previous packet should be returned to the distributor component by passing it as the final parameter to this API call.]
108*fc1f2750SBernard Iremonger
109*fc1f2750SBernard IremongerSince it may be desirable to vary the number of worker cores, depending on the traffic load
110*fc1f2750SBernard Iremongeri.e. to save power at times of lighter load,
111*fc1f2750SBernard Iremongerit is possible to have a worker stop processing packets by calling "rte_distributor_return_pkt()" to indicate that
112*fc1f2750SBernard Iremongerit has finished the current packet and does not want a new one.
113*fc1f2750SBernard Iremonger
114*fc1f2750SBernard Iremonger.. |packet_distributor1| image:: img/packet_distributor1.png
115*fc1f2750SBernard Iremonger
116*fc1f2750SBernard Iremonger.. |packet_distributor2| image:: img/packet_distributor2.png
117