1.. SPDX-License-Identifier: BSD-3-Clause 2 Copyright(c) 2017-2018 Cavium Networks. 3 4Compression Device Library 5========================== 6 7The compression framework provides a generic set of APIs to perform compression services 8as well as to query and configure compression devices both physical(hardware) and virtual(software) 9to perform those services. The framework currently only supports lossless compression schemes: 10Deflate and LZS. 11 12Device Management 13----------------- 14 15Device Creation 16~~~~~~~~~~~~~~~ 17 18Physical compression devices are discovered during the bus probe of the EAL function 19which is executed at DPDK initialization, based on their unique device identifier. 20For e.g. PCI devices can be identified using PCI BDF (bus/bridge, device, function). 21Specific physical compression devices, like other physical devices in DPDK can be 22listed using the EAL command line options. 23 24Virtual devices can be created by two mechanisms, either using the EAL command 25line options or from within the application using an EAL API directly. 26 27From the command line using the --vdev EAL option 28 29.. code-block:: console 30 31 --vdev '<PMD name>,socket_id=0' 32 33.. Note:: 34 35 * If a DPDK application requires multiple software compression PMD devices then the 36 required number of ``--vdev`` args with appropriate libraries are to be added. 37 38 * An application with multiple compression device instances exposed by the same PMD must 39 specify a unique name for each device. 40 41 Example: ``--vdev 'pmd0' --vdev 'pmd1'`` 42 43Or, by using the rte_vdev_init API within the application code. 44 45.. code-block:: c 46 47 rte_vdev_init("<pmd_name>","socket_id=0") 48 49All virtual compression devices support the following initialization parameters: 50 51* ``socket_id`` - socket on which to allocate the device resources on. 52 53Device Identification 54~~~~~~~~~~~~~~~~~~~~~ 55 56Each device, whether virtual or physical, is uniquely designated by two 57identifiers: 58 59- A unique device index used to designate the compression device in all functions 60 exported by the compressdev API. 61 62- A device name used to designate the compression device in console messages, for 63 administration or debugging purposes. 64 65Device Configuration 66~~~~~~~~~~~~~~~~~~~~ 67 68The configuration of each compression device includes the following operations: 69 70- Allocation of resources, including hardware resources if a physical device. 71- Resetting the device into a well-known default state. 72- Initialization of statistics counters. 73 74The ``rte_compressdev_configure`` API is used to configure a compression device. 75 76The ``rte_compressdev_config`` structure is used to pass the configuration 77parameters. 78 79See the `DPDK API Reference <https://doc.dpdk.org/api/rte__compressdev_8h.html>`_ for details. 80 81Configuration of Queue Pairs 82~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 83 84Each compression device queue pair is individually configured through the 85``rte_compressdev_queue_pair_setup`` API. 86 87The ``max_inflight_ops`` is used to pass maximum number of 88``rte_comp_op`` that could be present in a queue at a time. 89The PMD can then allocate resources accordingly on a specified socket. 90 91See the `DPDK API Reference <https://doc.dpdk.org/api/rte__compressdev_8h.html>`_ for details. 92 93Logical Cores, Memory and Queue Pair Relationships 94~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 95 96The Compressdev library supports NUMA similarly as described in Cryptodev library section. 97 98A queue pair cannot be shared, and should be exclusively used by a single processing 99context for enqueuing operations or dequeuing operations on the same compression device, 100since sharing would require global locks and hinder performance. It is however possible 101to use a different logical core to dequeue an operation on a queue pair from the logical 102core on which it was enqueued. This means that for a compression burst, enqueue/dequeue 103APIs are a logical place to transition from one logical core to another in a 104data processing pipeline. 105 106Device Features and Capabilities 107-------------------------------- 108 109Compression devices define their functionality through two mechanisms, global device 110features and algorithm features. Global device features identify device 111wide level features which are applicable to the whole device, such as supported hardware 112acceleration and CPU features. List of compression device features can be seen in the 113RTE_COMPDEV_FF_XXX macros. 114 115The algorithm features are features which the device supports per-algorithm, 116such as a stateful compression/decompression, checksums operation etc. 117The list of algorithm features can be seen in the RTE_COMP_FF_XXX macros. 118 119Capabilities 120~~~~~~~~~~~~ 121Each PMD has a list of capabilities, including algorithms listed in 122the enum ``rte_comp_algorithm``, its associated feature flag, and 123sliding window range in log base 2 value. The sliding window range 124defines the minimum and maximum size of a lookup window that an algorithm uses 125to find duplicates. 126 127See the `DPDK API Reference <https://doc.dpdk.org/api/rte__compressdev_8h.html>`_ for details. 128 129Each Compression poll mode driver defines its array of capabilities 130for each algorithm it supports. See the PMD implementation for capability 131initialization. 132 133Capabilities Discovery 134~~~~~~~~~~~~~~~~~~~~~~ 135 136PMD capability and features are discovered via the ``rte_compressdev_info_get`` function. 137 138The ``rte_compressdev_info`` structure contains all the relevant information for the device. 139 140See the `DPDK API Reference <https://doc.dpdk.org/api/rte__compressdev_8h.html>`_ for details. 141 142Compression Operation 143--------------------- 144 145DPDK compression supports two types of compression methodologies: 146 147- Stateless - data associated with a compression operation is compressed without any reference 148 to another compression operation. 149 150- Stateful - data in each compression operation is compressed with reference to previous compression 151 operations in the same data stream i.e. history of data is maintained between the operations. 152 153For more explanation, please refer to the RFC https://www.ietf.org/rfc/rfc1951.txt 154 155Operation Representation 156~~~~~~~~~~~~~~~~~~~~~~~~ 157 158A compression operation is described via ``struct rte_comp_op``, which contains both input and 159output data. The operation structure includes the operation type (stateless or stateful), 160the operation status, the priv_xform/stream handle, source, destination and checksum buffer 161pointers. It also contains the source mempool from which the operation is allocated. 162The PMD updates the consumed field with the amount of data read from the source buffer, 163and the produced field with the amount of data written into the destination buffer, 164along with status of operation. 165See the section :ref:`compressdev_prod_cons_op_status`: for more details. 166 167The compression operations mempool also has the ability to allocate private memory with the 168operation for the application's use. The application software is responsible for specifying 169all the operation specific fields in the ``rte_comp_op`` structure, which are then used 170by the compression PMD to process the requested operation. 171 172 173Operation Management and Allocation 174~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 175 176The compressdev library provides an API set for managing compression operations which 177utilize the Mempool Library to allocate operation buffers. Therefore, it ensures 178that the compression operation is interleaved optimally across the channels and 179ranks for optimal processing. 180 181A ``rte_comp_op`` contains a field indicating the pool it originated from. 182 183``rte_comp_op_alloc()`` and ``rte_comp_op_bulk_alloc()`` are used to allocate 184compression operations from a given compression operation mempool. 185The operation gets reset before being returned to a user so that the operation 186is always in a good known state before use by the application. 187 188``rte_comp_op_free()`` is called by the application to return an operation to 189its allocating pool. 190 191See the `DPDK API Reference <https://doc.dpdk.org/api/rte__compressdev_8h.html>`_ for details. 192 193Passing source data as mbuf-chain 194~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 195If input data is scattered across several different buffers, then 196the application can either parse through all such buffers and make one 197mbuf-chain and enqueue it for processing or, alternatively, it can 198make multiple sequential enqueue_burst() calls for each of them, 199processing them statefully. See :ref:`compressdev_stateful_op`: 200for stateful processing of ops. 201 202Operation Status 203~~~~~~~~~~~~~~~~ 204Each operation carries status information updated by the PMD after it is processed. 205The following are currently supported: 206 207- RTE_COMP_OP_STATUS_SUCCESS, 208 Operation is successfully completed 209 210- RTE_COMP_OP_STATUS_NOT_PROCESSED, 211 Operation has not yet been processed by the device 212 213- RTE_COMP_OP_STATUS_INVALID_ARGS, 214 Operation failed due to invalid arguments in request 215 216- RTE_COMP_OP_STATUS_ERROR, 217 Operation failed because of internal error 218 219- RTE_COMP_OP_STATUS_INVALID_STATE, 220 Operation is invoked in invalid state 221 222- RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED, 223 Output buffer ran out of space during processing. Error case, 224 PMD cannot continue from here. 225 226- RTE_COMP_OP_STATUS_OUT_OF_SPACE_RECOVERABLE, 227 Output buffer ran out of space before operation completed, but this 228 is not an error case. Output data up to op.produced can be used and 229 the next op in the stream should continue on from op.consumed+1. 230 231Operation status after enqueue / dequeue 232~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 233Some of the above values may arise in the op after an 234``rte_compressdev_enqueue_burst()``. If the number of ops enqueued < the number of ops requested 235then the app should check the op.status of nb_enqd+1. 236If the status is RTE_COMP_OP_STATUS_NOT_PROCESSED, it likely indicates a full-queue case for a 237hardware device, and a retry after dequeuing some ops is likely to be successful. 238If the op holds any other status, e.g. RTE_COMP_OP_STATUS_INVALID_ARGS, a retry with 239the same op is unlikely to be successful. 240 241 242.. _compressdev_prod_cons_op_status: 243 244Produced, Consumed And Operation Status 245~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 246 247- If the status is RTE_COMP_OP_STATUS_SUCCESS, 248 consumed = amount of data read from input buffer, and 249 produced = amount of data written in destination buffer 250- If status is RTE_COMP_OP_STATUS_ERROR, 251 consumed = produced = undefined 252- If status is RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED, 253 consumed = 0 and 254 produced = usually 0, but in decompression cases a PMD may return > 0 255 i.e. amount of data successfully produced until out of space condition 256 hit. Application can consume output data in this case, if required. 257- If status is RTE_COMP_OP_STATUS_OUT_OF_SPACE_RECOVERABLE, 258 consumed = amount of data read, and 259 produced = amount of data successfully produced until 260 out of space condition hit. The PMD has ability to recover 261 from here, so an application can submit the next op from 262 consumed+1, and a destination buffer with available space. 263 264Transforms 265---------- 266 267Compression transforms (``rte_comp_xform``) are the mechanism 268to specify the details of the compression operation such as algorithm, 269window size, and checksum. 270 271Compression API Hash support 272---------------------------- 273 274The compression API allows an application to enable digest calculation 275alongside compression and decompression of data. A PMD reflects its 276support for hash algorithms via capability algo feature flags. 277If supported, the PMD always calculates the digest on plaintext i.e. 278before compression and after decompression. 279 280Currently supported list of hash algos are SHA-1 and SHA2 family 281SHA256. 282 283See the `DPDK API Reference <https://doc.dpdk.org/api/rte__compressdev_8h.html>`_ for details. 284 285If required, the application should set the valid hash algo in compress 286or decompress xforms during ``rte_compressdev_stream_create()`` 287or ``rte_compressdev_private_xform_create()``, and pass a valid 288output buffer in ``rte_comp_op`` hash field struct to store the 289resulting digest. The buffer passed should be contiguous and large 290enough to store digest, which is 20 bytes for SHA-1 and 29132 bytes for SHA2-256. 292 293Compression API Stateless operation 294------------------------------------ 295 296An op is processed stateless if it has 297- op_type set to RTE_COMP_OP_STATELESS 298- flush value set to RTE_COMP_FLUSH_FULL or RTE_COMP_FLUSH_FINAL 299(required only on compression side), 300- All required input in source buffer 301 302When all of the above conditions are met, the PMD initiates stateless processing 303and releases acquired resources after processing of current operation is 304complete. The application can enqueue multiple stateless ops in a single burst 305and must attach priv_xform handle to such ops. 306 307priv_xform in Stateless operation 308~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 309 310A priv_xform is private data managed internally by the PMD to do stateless processing. 311A priv_xform is initialized by an application providing a generic xform structure 312to ``rte_compressdev_private_xform_create``, which returns an opaque priv_xform reference. 313If the PMD supports SHAREABLE priv_xform, indicated via algorithm feature flag, 314then the application can attach the same priv_xform with many stateless ops at a time. 315If not, then the application needs to create as many priv_xforms as it expects to have 316stateless operations in-flight. 317 318.. figure:: img/stateless-op.* 319 320 Stateless Ops using Non-Shareable priv_xform 321 322 323.. figure:: img/stateless-op-shared.* 324 325 Stateless Ops using Shareable priv_xform 326 327 328The application should call ``rte_compressdev_private_xform_create()`` and attach it to a stateless 329op before enqueuing them for processing and free via ``rte_compressdev_private_xform_free()`` 330during termination. 331 332An example pseudocode to setup and process NUM_OPS stateless ops with each of length OP_LEN 333using priv_xform would look like: 334 335.. code-block:: c 336 337 /* 338 * pseudocode for stateless compression 339 */ 340 341 uint8_t cdev_id = rte_compressdev_get_dev_id(<PMD name>); 342 343 /* configure the device. */ 344 if (rte_compressdev_configure(cdev_id, &conf) < 0) 345 rte_exit(EXIT_FAILURE, "Failed to configure compressdev %u", cdev_id); 346 347 if (rte_compressdev_queue_pair_setup(cdev_id, 0, NUM_MAX_INFLIGHT_OPS, 348 socket_id()) < 0) 349 rte_exit(EXIT_FAILURE, "Failed to setup queue pair\n"); 350 351 if (rte_compressdev_start(cdev_id) < 0) 352 rte_exit(EXIT_FAILURE, "Failed to start device\n"); 353 354 /* setup compress transform */ 355 struct rte_comp_xform compress_xform = { 356 .type = RTE_COMP_COMPRESS, 357 .compress = { 358 .algo = RTE_COMP_ALGO_DEFLATE, 359 .deflate = { 360 .huffman = RTE_COMP_HUFFMAN_DEFAULT 361 }, 362 .level = RTE_COMP_LEVEL_PMD_DEFAULT, 363 .chksum = RTE_COMP_CHECKSUM_NONE, 364 .window_size = DEFAULT_WINDOW_SIZE, 365 .hash_algo = RTE_COMP_HASH_ALGO_NONE 366 } 367 }; 368 369 /* create priv_xform and initialize it for the compression device. */ 370 rte_compressdev_info dev_info; 371 void *priv_xform = NULL; 372 int shareable = 1; 373 rte_compressdev_info_get(cdev_id, &dev_info); 374 if (dev_info.capabilities->comp_feature_flags & RTE_COMP_FF_SHAREABLE_PRIV_XFORM) { 375 rte_compressdev_private_xform_create(cdev_id, &compress_xform, &priv_xform); 376 } else { 377 shareable = 0; 378 } 379 380 /* create operation pool via call to rte_comp_op_pool_create and alloc ops */ 381 struct rte_comp_op *comp_ops[NUM_OPS]; 382 rte_comp_op_bulk_alloc(op_pool, comp_ops, NUM_OPS); 383 384 /* prepare ops for compression operations */ 385 for (i = 0; i < NUM_OPS; i++) { 386 struct rte_comp_op *op = comp_ops[i]; 387 if (!shareable) 388 rte_compressdev_private_xform_create(cdev_id, &compress_xform, &op->priv_xform) 389 else 390 op->private_xform = priv_xform; 391 op->op_type = RTE_COMP_OP_STATELESS; 392 op->flush_flag = RTE_COMP_FLUSH_FINAL; 393 394 op->src.offset = 0; 395 op->dst.offset = 0; 396 op->src.length = OP_LEN; 397 op->input_chksum = 0; 398 setup op->m_src and op->m_dst; 399 } 400 num_enqd = rte_compressdev_enqueue_burst(cdev_id, 0, comp_ops, NUM_OPS); 401 /* wait for this to complete before enqueuing next*/ 402 do { 403 num_deque = rte_compressdev_dequeue_burst(cdev_id, 0 , &processed_ops, NUM_OPS); 404 } while (num_dqud < num_enqd); 405 406 407Stateless and OUT_OF_SPACE 408~~~~~~~~~~~~~~~~~~~~~~~~~~ 409 410OUT_OF_SPACE is a condition when the output buffer runs out of space and where the PMD 411still has more data to produce. If the PMD runs into such condition, then the PMD returns 412RTE_COMP_OP_OUT_OF_SPACE_TERMINATED error. In such case, the PMD resets itself and can set 413consumed=0 and produced=amount of output it could produce before hitting out_of_space. 414The application would need to resubmit the whole input with a larger output buffer, if it 415wants the operation to be completed. 416 417Hash in Stateless 418~~~~~~~~~~~~~~~~~ 419If hash is enabled, the digest buffer will contain valid data after an op is successfully 420processed i.e. dequeued with status = RTE_COMP_OP_STATUS_SUCCESS. 421 422Checksum in Stateless 423~~~~~~~~~~~~~~~~~~~~~ 424If checksum is enabled, checksum will only be available after an op is successfully 425processed i.e. dequeued with status = RTE_COMP_OP_STATUS_SUCCESS. 426 427.. _compressdev_stateful_op: 428 429Compression API Stateful operation 430----------------------------------- 431 432The compression API provides RTE_COMP_FF_STATEFUL_COMPRESSION and 433RTE_COMP_FF_STATEFUL_DECOMPRESSION feature flag for the PMD to reflect 434its support for Stateful operations. 435 436A Stateful operation in DPDK compression means the application invokes enqueue 437burst() multiple times to process a related chunk of data because the 438application broke the data into several ops. 439 440In such cases 441- ops are setup with op_type RTE_COMP_OP_STATEFUL, 442- all ops except the last are set with flush value = RTE_COMP_FLUSH_NONE/SYNC 443and the last is set with flush value RTE_COMP_FLUSH_FULL/FINAL. 444 445In case of either one or all of the above conditions, the PMD initiates 446stateful processing and releases acquired resources after processing the 447operation with flush value = RTE_COMP_FLUSH_FULL/FINAL is complete. 448Unlike stateless, the application can enqueue only one stateful op from 449a particular stream at a time and must attach a stream handle 450to each op. 451 452Stream in Stateful operation 453~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 454 455A stream in DPDK compression is a logical entity which identifies a related set of ops. 456For example, one large file broken into multiple chunks, then the file is represented by a stream, 457and each chunk of that file is represented by a compression op ``rte_comp_op``. 458Whenever an application wants stateful processing of such data, then it must get a stream handle 459via making call to ``rte_compressdev_stream_create()`` with an xform, which will return an opaque 460stream handle to attach to all of the ops carrying data of that stream. 461In stateful processing, every op requires previous op data for compression/decompression. 462A PMD allocates and sets up resources such as history, states, etc. within a stream, 463which are maintained during the processing of related ops. 464 465Unlike priv_xforms, a stream is always a NON_SHAREABLE entity. One stream handle must be attached 466to only one set of related ops and cannot be reused until all of them are processed with a 467success/failure status. 468 469.. figure:: img/stateful-op.* 470 471 Stateful Ops 472 473 474An application should call ``rte_compressdev_stream_create()`` and attach it to the op before 475enqueuing them for processing and free via ``rte_compressdev_stream_free()`` during 476termination. All ops that are to be processed statefully should carry the *same* stream. 477 478See the `DPDK API Reference <https://doc.dpdk.org/api/rte__compressdev_8h.html>`_ for details. 479 480An example pseudocode to set up and process a stream having NUM_CHUNKS, 481with each chunk size of CHUNK_LEN, would look like: 482 483.. code-block:: c 484 485 /* 486 * pseudocode for stateful compression 487 */ 488 489 uint8_t cdev_id = rte_compressdev_get_dev_id(<PMD name>); 490 491 /* configure the device. */ 492 if (rte_compressdev_configure(cdev_id, &conf) < 0) 493 rte_exit(EXIT_FAILURE, "Failed to configure compressdev %u", cdev_id); 494 495 if (rte_compressdev_queue_pair_setup(cdev_id, 0, NUM_MAX_INFLIGHT_OPS, 496 socket_id()) < 0) 497 rte_exit(EXIT_FAILURE, "Failed to setup queue pair\n"); 498 499 if (rte_compressdev_start(cdev_id) < 0) 500 rte_exit(EXIT_FAILURE, "Failed to start device\n"); 501 502 /* setup compress transform. */ 503 struct rte_comp_xform compress_xform = { 504 .type = RTE_COMP_COMPRESS, 505 .compress = { 506 .algo = RTE_COMP_ALGO_DEFLATE, 507 .deflate = { 508 .huffman = RTE_COMP_HUFFMAN_DEFAULT 509 }, 510 .level = RTE_COMP_LEVEL_PMD_DEFAULT, 511 .chksum = RTE_COMP_CHECKSUM_NONE, 512 .window_size = DEFAULT_WINDOW_SIZE, 513 .hash_algo = RTE_COMP_HASH_ALGO_NONE 514 } 515 }; 516 517 /* create stream */ 518 void *stream; 519 rte_compressdev_stream_create(cdev_id, &compress_xform, &stream); 520 521 /* create an op pool and allocate ops */ 522 rte_comp_op_bulk_alloc(op_pool, comp_ops, NUM_CHUNKS); 523 524 /* Prepare source and destination mbufs for compression operations */ 525 unsigned int i; 526 for (i = 0; i < NUM_CHUNKS; i++) { 527 if (rte_pktmbuf_append(mbufs[i], CHUNK_LEN) == NULL) 528 rte_exit(EXIT_FAILURE, "Not enough room in the mbuf\n"); 529 comp_ops[i]->m_src = mbufs[i]; 530 if (rte_pktmbuf_append(dst_mbufs[i], CHUNK_LEN) == NULL) 531 rte_exit(EXIT_FAILURE, "Not enough room in the mbuf\n"); 532 comp_ops[i]->m_dst = dst_mbufs[i]; 533 } 534 535 /* Set up the compress operations. */ 536 for (i = 0; i < NUM_CHUNKS; i++) { 537 struct rte_comp_op *op = comp_ops[i]; 538 op->stream = stream; 539 op->m_src = src_buf[i]; 540 op->m_dst = dst_buf[i]; 541 op->op_type = RTE_COMP_OP_STATEFUL; 542 if (i == NUM_CHUNKS-1) { 543 /* set to final, if last chunk*/ 544 op->flush_flag = RTE_COMP_FLUSH_FINAL; 545 } else { 546 /* set to NONE, for all intermediary ops */ 547 op->flush_flag = RTE_COMP_FLUSH_NONE; 548 } 549 op->src.offset = 0; 550 op->dst.offset = 0; 551 op->src.length = CHUNK_LEN; 552 op->input_chksum = 0; 553 num_enqd = rte_compressdev_enqueue_burst(cdev_id, 0, &op[i], 1); 554 /* wait for this to complete before enqueuing next*/ 555 do { 556 num_deqd = rte_compressdev_dequeue_burst(cdev_id, 0 , &processed_ops, 1); 557 } while (num_deqd < num_enqd); 558 /* analyze the amount of consumed and produced data before pushing next op*/ 559 } 560 561 562Stateful and OUT_OF_SPACE 563~~~~~~~~~~~~~~~~~~~~~~~~~ 564 565If a PMD supports stateful operation, then an OUT_OF_SPACE status is not an actual 566error for the PMD. In such a case, the PMD returns with status 567RTE_COMP_OP_STATUS_OUT_OF_SPACE_RECOVERABLE with consumed = number of input bytes 568read, and produced = length of complete output buffer. 569The application should enqueue the next op with source starting at consumed+1, and an 570output buffer with available space. 571 572Hash in Stateful 573~~~~~~~~~~~~~~~~ 574If enabled, the digest buffer will contain valid digest after the last op in a stream 575(having flush = RTE_COMP_FLUSH_FINAL) is successfully processed i.e. dequeued 576with status = RTE_COMP_OP_STATUS_SUCCESS. 577 578Checksum in Stateful 579~~~~~~~~~~~~~~~~~~~~ 580If enabled, the checksum will only be available after the last op in a stream 581(having flush = RTE_COMP_FLUSH_FINAL) is successfully processed i.e. dequeued 582with status = RTE_COMP_OP_STATUS_SUCCESS. 583 584Burst in compression API 585------------------------ 586 587Scheduling of compression operations on DPDK's application data path is 588performed using a burst oriented asynchronous API set. A queue pair on a compression 589device accepts a burst of compression operations using the enqueue burst API. 590On physical devices the enqueue burst API will place the operations to be processed 591on the device's hardware input queue, for virtual devices the processing of the 592operations is usually completed during the enqueue call to the compression 593device. The dequeue burst API will retrieve any processed operations available 594from the queue pair on the compression device, from physical devices this is usually 595directly from the devices processed queue, and for virtual device's from an 596``rte_ring`` where processed operations are placed after being processed on the 597enqueue call. 598 599A burst in DPDK compression can be a combination of stateless and stateful operations with a 600condition that for stateful ops only one op at a time should be enqueued from a particular stream 601i.e. two ops should never belong to the same stream in a single burst. 602However, a burst may contain multiple stateful ops, as long as each op is attached to a different 603stream, i.e. a burst can look like: 604 605+---------------+--------------+--------------+-----------------+--------------+--------------+ 606| enqueue_burst | op1.no_flush | op2.no_flush | op3.flush_final | op4.no_flush | op5.no_flush | 607+---------------+--------------+--------------+-----------------+--------------+--------------+ 608 609Where, op1 .. op5 all belong to different independent data units. op1, op2, op4, op5 must be 610stateful as stateless ops can only use flush full or final and op3 can be of type stateless or 611stateful. Every op with type set to RTE_COMP_OP_STATELESS must be attached to priv_xform and 612every op with type set to RTE_COMP_OP_STATEFUL *must* be attached to stream. 613 614Since each operation in a burst is independent and thus can be completed 615out of order, applications which need ordering should setup a per-op user data 616area, with reordering information so that it can determine enqueue order at 617dequeue. 618 619Also, if multiple threads calls enqueue_burst() on the same queue pair then it's 620the application's responsibility to use a proper locking mechanism to ensure 621exclusive enqueuing of operations. 622 623Enqueue / Dequeue Burst APIs 624~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 625 626The burst enqueue API uses a compression device identifier and a queue pair 627identifier to specify the compression device queue pair to schedule the processing on. 628The ``nb_ops`` parameter is the number of operations to process which are 629supplied in the ``ops`` array of ``rte_comp_op`` structures. 630The enqueue function returns the number of operations it actually enqueued for 631processing, a return value equal to ``nb_ops`` means that all packets have been 632enqueued. 633 634The dequeue API uses the same format as the enqueue API but 635the ``nb_ops`` and ``ops`` parameters are now used to specify the max processed 636operations the user wishes to retrieve and the location in which to store them. 637The API call returns the actual number of processed operations returned, this 638can never be larger than ``nb_ops``. 639 640Sample code 641----------- 642 643There are unit test applications that show how to use the compressdev library inside 644``app/test/test_compressdev.c`` 645 646Compression Device API 647~~~~~~~~~~~~~~~~~~~~~~ 648 649The compressdev Library API is described in the 650`DPDK API Reference <https://doc.dpdk.org/api/rte__compressdev_8h.html>`_. 651