1*5630257fSFerruh Yigit.. SPDX-License-Identifier: BSD-3-Clause 2*5630257fSFerruh Yigit Copyright(c) 2015 Intel Corporation. 334287c69SSergio Gonzalez Monroy 434287c69SSergio Gonzalez MonroyReorder Library 534287c69SSergio Gonzalez Monroy================= 634287c69SSergio Gonzalez Monroy 734287c69SSergio Gonzalez MonroyThe Reorder Library provides a mechanism for reordering mbufs based on their 834287c69SSergio Gonzalez Monroysequence number. 934287c69SSergio Gonzalez Monroy 1034287c69SSergio Gonzalez MonroyOperation 1134287c69SSergio Gonzalez Monroy---------- 1234287c69SSergio Gonzalez Monroy 1334287c69SSergio Gonzalez MonroyThe reorder library is essentially a buffer that reorders mbufs. 1434287c69SSergio Gonzalez MonroyThe user inserts out of order mbufs into the reorder buffer and pulls in-order 1534287c69SSergio Gonzalez Monroymbufs from it. 1634287c69SSergio Gonzalez Monroy 1734287c69SSergio Gonzalez MonroyAt a given time, the reorder buffer contains mbufs whose sequence number are 1834287c69SSergio Gonzalez Monroyinside the sequence window. The sequence window is determined by the minimum 1934287c69SSergio Gonzalez Monroysequence number and the number of entries that the buffer was configured to hold. 2034287c69SSergio Gonzalez MonroyFor example, given a reorder buffer with 200 entries and a minimum sequence 2134287c69SSergio Gonzalez Monroynumber of 350, the sequence window has low and high limits of 350 and 550 2234287c69SSergio Gonzalez Monroyrespectively. 2334287c69SSergio Gonzalez Monroy 2434287c69SSergio Gonzalez MonroyWhen inserting mbufs, the reorder library differentiates between valid, early 2534287c69SSergio Gonzalez Monroyand late mbufs depending on the sequence number of the inserted mbuf: 2634287c69SSergio Gonzalez Monroy 2734287c69SSergio Gonzalez Monroy* valid: the sequence number is inside the window. 2834287c69SSergio Gonzalez Monroy* late: the sequence number is outside the window and less than the low limit. 2934287c69SSergio Gonzalez Monroy* early: the sequence number is outside the window and greater than the high 3034287c69SSergio Gonzalez Monroy limit. 3134287c69SSergio Gonzalez Monroy 3234287c69SSergio Gonzalez MonroyThe reorder buffer directly returns late mbufs and tries to accommodate early 3334287c69SSergio Gonzalez Monroymbufs. 3434287c69SSergio Gonzalez Monroy 3534287c69SSergio Gonzalez Monroy 3634287c69SSergio Gonzalez MonroyImplementation Details 3734287c69SSergio Gonzalez Monroy------------------------- 3834287c69SSergio Gonzalez Monroy 3934287c69SSergio Gonzalez MonroyThe reorder library is implemented as a pair of buffers, which referred to as 4034287c69SSergio Gonzalez Monroythe *Order* buffer and the *Ready* buffer. 4134287c69SSergio Gonzalez Monroy 4234287c69SSergio Gonzalez MonroyOn an insert call, valid mbufs are inserted directly into the Order buffer and 4334287c69SSergio Gonzalez Monroylate mbufs are returned to the user with an error. 4434287c69SSergio Gonzalez Monroy 4534287c69SSergio Gonzalez MonroyIn the case of early mbufs, the reorder buffer will try to move the window 4634287c69SSergio Gonzalez Monroy(incrementing the minimum sequence number) so that the mbuf becomes a valid one. 4734287c69SSergio Gonzalez MonroyTo that end, mbufs in the Order buffer are moved into the Ready buffer. 4834287c69SSergio Gonzalez MonroyAny mbufs that have not arrived yet are ignored and therefore will become 4934287c69SSergio Gonzalez Monroylate mbufs. 5034287c69SSergio Gonzalez MonroyThis means that as long as there is room in the Ready buffer, the window will 5134287c69SSergio Gonzalez Monroybe moved to accommodate early mbufs that would otherwise be outside the 5234287c69SSergio Gonzalez Monroyreordering window. 5334287c69SSergio Gonzalez Monroy 5434287c69SSergio Gonzalez MonroyFor example, assuming that we have a buffer of 200 entries with a 350 minimum 5534287c69SSergio Gonzalez Monroysequence number, and we need to insert an early mbuf with 565 sequence number. 5634287c69SSergio Gonzalez MonroyThat means that we would need to move the windows at least 15 positions to 5734287c69SSergio Gonzalez Monroyaccommodate the mbuf. 5834287c69SSergio Gonzalez MonroyThe reorder buffer would try to move mbufs from at least the next 15 slots in 5934287c69SSergio Gonzalez Monroythe Order buffer to the Ready buffer, as long as there is room in the Ready buffer. 6034287c69SSergio Gonzalez MonroyAny gaps in the Order buffer at that point are skipped, and those packet will 6134287c69SSergio Gonzalez Monroybe reported as late packets when they arrive. The process of moving packets 6234287c69SSergio Gonzalez Monroyto the Ready buffer continues beyond the minimum required until a gap, 6334287c69SSergio Gonzalez Monroyi.e. missing mbuf, in the Order buffer is encountered. 6434287c69SSergio Gonzalez Monroy 6534287c69SSergio Gonzalez MonroyWhen draining mbufs, the reorder buffer would return mbufs in the Ready 6634287c69SSergio Gonzalez Monroybuffer first and then from the Order buffer until a gap is found (mbufs that 6734287c69SSergio Gonzalez Monroyhave not arrived yet). 6834287c69SSergio Gonzalez Monroy 6934287c69SSergio Gonzalez MonroyUse Case: Packet Distributor 7034287c69SSergio Gonzalez Monroy------------------------------- 7134287c69SSergio Gonzalez Monroy 7234287c69SSergio Gonzalez MonroyAn application using the DPDK packet distributor could make use of the reorder 7334287c69SSergio Gonzalez Monroylibrary to transmit packets in the same order they were received. 7434287c69SSergio Gonzalez Monroy 7534287c69SSergio Gonzalez MonroyA basic packet distributor use case would consist of a distributor with 7634287c69SSergio Gonzalez Monroymultiple workers cores. 7734287c69SSergio Gonzalez MonroyThe processing of packets by the workers is not guaranteed to be in order, 7834287c69SSergio Gonzalez Monroyhence a reorder buffer can be used to order as many packets as possible. 7934287c69SSergio Gonzalez Monroy 8034287c69SSergio Gonzalez MonroyIn such a scenario, the distributor assigns a sequence number to mbufs before 8134287c69SSergio Gonzalez Monroydelivering them to the workers. 8234287c69SSergio Gonzalez MonroyAs the workers finish processing the packets, the distributor inserts those 8334287c69SSergio Gonzalez Monroymbufs into the reorder buffer and finally transmit drained mbufs. 8434287c69SSergio Gonzalez Monroy 8534287c69SSergio Gonzalez MonroyNOTE: Currently the reorder buffer is not thread safe so the same thread is 8634287c69SSergio Gonzalez Monroyresponsible for inserting and draining mbufs. 87