xref: /dpdk/doc/guides/cryptodevs/scheduler.rst (revision 9c30a6f3c9a456e8111a2b1e5f6c2c02a62025b6)
15630257fSFerruh Yigit..  SPDX-License-Identifier: BSD-3-Clause
25630257fSFerruh Yigit    Copyright(c) 2017 Intel Corporation.
3d58a3f31SFan Zhang
4d58a3f31SFan ZhangCryptodev Scheduler Poll Mode Driver Library
5d58a3f31SFan Zhang============================================
6d58a3f31SFan Zhang
7d58a3f31SFan ZhangScheduler PMD is a software crypto PMD, which has the capabilities of
8d58a3f31SFan Zhangattaching hardware and/or software cryptodevs, and distributes ingress
9d58a3f31SFan Zhangcrypto ops among them in a certain manner.
10d58a3f31SFan Zhang
11d58a3f31SFan Zhang.. figure:: img/scheduler-overview.*
12d58a3f31SFan Zhang
13d58a3f31SFan Zhang   Cryptodev Scheduler Overview
14d58a3f31SFan Zhang
15d58a3f31SFan Zhang
16*8809f78cSBruce RichardsonThe Cryptodev Scheduler PMD library (**librte_crypto_scheduler**) acts as
17d58a3f31SFan Zhanga software crypto PMD and shares the same API provided by librte_cryptodev.
18d58a3f31SFan ZhangThe PMD supports attaching multiple crypto PMDs, software or hardware, as
1985b00824SAdam Dybkowskiworkers, and distributes the crypto workload to them with certain behavior.
20d58a3f31SFan ZhangThe behaviors are categorizes as different "modes". Basically, a scheduling
2185b00824SAdam Dybkowskimode defines certain actions for scheduling crypto ops to its workers.
22d58a3f31SFan Zhang
23*8809f78cSBruce RichardsonThe librte_crypto_scheduler library exports a C API which provides an API
2485b00824SAdam Dybkowskifor attaching/detaching workers, set/get scheduling modes, and enable/disable
25d58a3f31SFan Zhangcrypto ops reordering.
26d58a3f31SFan Zhang
27d58a3f31SFan ZhangLimitations
28d58a3f31SFan Zhang-----------
29d58a3f31SFan Zhang
30d58a3f31SFan Zhang* Sessionless crypto operation is not supported
31d58a3f31SFan Zhang* OOP crypto operation is not supported when the crypto op reordering feature
32d58a3f31SFan Zhang  is enabled.
33d58a3f31SFan Zhang
34d58a3f31SFan Zhang
35d58a3f31SFan ZhangInitialization
36d58a3f31SFan Zhang--------------
37d58a3f31SFan Zhang
38d58a3f31SFan ZhangTo use the PMD in an application, user must:
39d58a3f31SFan Zhang
407fe90a66SPablo de Lara* Call rte_vdev_init("crypto_scheduler") within the application.
41d58a3f31SFan Zhang
427fe90a66SPablo de Lara* Use --vdev="crypto_scheduler" in the EAL options, which will call
432f6fec53SThomas Monjalon  rte_vdev_init() internally.
44d58a3f31SFan Zhang
45d58a3f31SFan Zhang
46d58a3f31SFan ZhangThe following parameters (all optional) can be provided in the previous
47d58a3f31SFan Zhangtwo calls:
48d58a3f31SFan Zhang
49d58a3f31SFan Zhang* socket_id: Specify the socket where the memory for the device is going
50d58a3f31SFan Zhang  to be allocated (by default, socket_id will be the socket where the core
51d58a3f31SFan Zhang  that is creating the PMD is running on).
52d58a3f31SFan Zhang
53d58a3f31SFan Zhang* max_nb_sessions: Specify the maximum number of sessions that can be
54d58a3f31SFan Zhang  created. This value may be overwritten internally if there are too
55d58a3f31SFan Zhang  many devices are attached.
56d58a3f31SFan Zhang
5785b00824SAdam Dybkowski* worker: If a cryptodev has been initialized with specific name, it can be
58d58a3f31SFan Zhang  attached to the scheduler using this parameter, simply filling the name
59d58a3f31SFan Zhang  here. Multiple cryptodevs can be attached initially by presenting this
60d58a3f31SFan Zhang  parameter multiple times.
61d58a3f31SFan Zhang
62a0e805eeSFan Zhang* mode: Specify the scheduling mode of the PMD. The supported scheduling
63a0e805eeSFan Zhang  mode parameter values are specified in the "Cryptodev Scheduler Modes
64a0e805eeSFan Zhang  Overview" section.
65a0e805eeSFan Zhang
66ee9586ddSFan Zhang* mode_param: Specify the mode-specific parameter. Some scheduling modes
67ee9586ddSFan Zhang  may be initialized with specific parameters other than the default ones,
68ee9586ddSFan Zhang  such as the **threshold** packet size of **packet-size-distr** mode. This
69ee9586ddSFan Zhang  parameter fulfills the purpose.
70ee9586ddSFan Zhang
71a0e805eeSFan Zhang* ordering: Specify the status of the crypto operations ordering feature.
72a0e805eeSFan Zhang  The value of this parameter can be "enable" or "disable". This feature
73a0e805eeSFan Zhang  is disabled by default.
74a0e805eeSFan Zhang
75d58a3f31SFan ZhangExample:
76d58a3f31SFan Zhang
77d58a3f31SFan Zhang.. code-block:: console
78d58a3f31SFan Zhang
7985b00824SAdam Dybkowski    ... --vdev "crypto_aesni_mb0,name=aesni_mb_1" --vdev "crypto_aesni_mb1,name=aesni_mb_2" --vdev "crypto_scheduler,worker=aesni_mb_1,worker=aesni_mb_2" ...
80d58a3f31SFan Zhang
81d58a3f31SFan Zhang.. note::
82d58a3f31SFan Zhang
83d58a3f31SFan Zhang    * The scheduler cryptodev cannot be started unless the scheduling mode
8485b00824SAdam Dybkowski      is set and at least one worker is attached. Also, to configure the
8585b00824SAdam Dybkowski      scheduler in the run-time, like attach/detach worker(s), change
86d58a3f31SFan Zhang      scheduling mode, or enable/disable crypto op ordering, one should stop
87d58a3f31SFan Zhang      the scheduler first, otherwise an error will be returned.
88d58a3f31SFan Zhang
89d58a3f31SFan Zhang    * The crypto op reordering feature requires using the userdata field of
90d58a3f31SFan Zhang      every mbuf to be processed to store temporary data. By the end of
91d58a3f31SFan Zhang      processing, the field is set to pointing to NULL, any previously
92d58a3f31SFan Zhang      stored value of this field will be lost.
93d58a3f31SFan Zhang
94d58a3f31SFan Zhang
95d58a3f31SFan ZhangCryptodev Scheduler Modes Overview
96d58a3f31SFan Zhang----------------------------------
97d58a3f31SFan Zhang
98d58a3f31SFan ZhangCurrently the Crypto Scheduler PMD library supports following modes of
99d58a3f31SFan Zhangoperation:
100d58a3f31SFan Zhang
101d58a3f31SFan Zhang*   **CDEV_SCHED_MODE_ROUNDROBIN:**
102d58a3f31SFan Zhang
103a0e805eeSFan Zhang   *Initialization mode parameter*: **round-robin**
104a0e805eeSFan Zhang
105d58a3f31SFan Zhang   Round-robin mode, which distributes the enqueued burst of crypto ops
10685b00824SAdam Dybkowski   among its workers in a round-robin manner. This mode may help to fill
107d58a3f31SFan Zhang   the throughput gap between the physical core and the existing cryptodevs
108d58a3f31SFan Zhang   to increase the overall performance.
109a783aa63SFan Zhang
110a783aa63SFan Zhang*   **CDEV_SCHED_MODE_PKT_SIZE_DISTR:**
111a783aa63SFan Zhang
112a0e805eeSFan Zhang   *Initialization mode parameter*: **packet-size-distr**
113a0e805eeSFan Zhang
11485b00824SAdam Dybkowski   Packet-size based distribution mode, which works with 2 workers, the primary
11585b00824SAdam Dybkowski   worker and the secondary worker, and distributes the enqueued crypto
116a783aa63SFan Zhang   operations to them based on their data lengths. A crypto operation will be
11785b00824SAdam Dybkowski   distributed to the primary worker if its data length is equal to or bigger
118a783aa63SFan Zhang   than the designated threshold, otherwise it will be handled by the secondary
11985b00824SAdam Dybkowski   worker.
120a783aa63SFan Zhang
121a783aa63SFan Zhang   A typical use case in this mode is with the QAT cryptodev as the primary and
12285b00824SAdam Dybkowski   a software cryptodev as the secondary worker. This may help applications to
123a783aa63SFan Zhang   process additional crypto workload than what the QAT cryptodev can handle on
124a783aa63SFan Zhang   its own, by making use of the available CPU cycles to deal with smaller
125a783aa63SFan Zhang   crypto workloads.
12637f075daSFan Zhang
1274e30ead5SFan Zhang   The threshold is set to 128 bytes by default. It can be updated by calling
1284e30ead5SFan Zhang   function **rte_cryptodev_scheduler_option_set**. The parameter of
1294e30ead5SFan Zhang   **option_type** must be **CDEV_SCHED_OPTION_THRESHOLD** and **option** should
1304e30ead5SFan Zhang   point to a rte_cryptodev_scheduler_threshold_option structure filled with
1314e30ead5SFan Zhang   appropriate threshold value. Please NOTE this threshold has be a power-of-2
1326760463cSFan Zhang   unsigned integer. It is possible to use **mode_param** initialization
1336760463cSFan Zhang   parameter to achieve the same purpose. For example:
1346760463cSFan Zhang
1356760463cSFan Zhang   ... --vdev "crypto_scheduler,mode=packet-size-distr,mode_param=threshold:512" ...
1366760463cSFan Zhang
1376760463cSFan Zhang   The above parameter will overwrite the threshold value to 512.
1384e30ead5SFan Zhang
13937f075daSFan Zhang*   **CDEV_SCHED_MODE_FAILOVER:**
14037f075daSFan Zhang
141a0e805eeSFan Zhang   *Initialization mode parameter*: **fail-over**
142a0e805eeSFan Zhang
14385b00824SAdam Dybkowski   Fail-over mode, which works with 2 workers, the primary worker and the
14485b00824SAdam Dybkowski   secondary worker. In this mode, the scheduler will enqueue the incoming
14585b00824SAdam Dybkowski   crypto operation burst to the primary worker. When one or more crypto
14637f075daSFan Zhang   operations fail to be enqueued, then they will be enqueued to the secondary
14785b00824SAdam Dybkowski   worker.
1484c07e055SKirill Rybalchenko
1494c07e055SKirill Rybalchenko*   **CDEV_SCHED_MODE_MULTICORE:**
1504c07e055SKirill Rybalchenko
1514c07e055SKirill Rybalchenko   *Initialization mode parameter*: **multi-core**
1524c07e055SKirill Rybalchenko
1534c07e055SKirill Rybalchenko   Multi-core mode, which distributes the workload with several (up to eight)
1544c07e055SKirill Rybalchenko   worker cores. The enqueued bursts are distributed among the worker cores in a
1554c07e055SKirill Rybalchenko   round-robin manner. If scheduler cannot enqueue entire burst to the same worker,
1564c07e055SKirill Rybalchenko   it will enqueue the remaining operations to the next available worker.
1574c07e055SKirill Rybalchenko   For pure small packet size (64 bytes) traffic however the multi-core mode is not
1584c07e055SKirill Rybalchenko   an optimal solution, as it doesn't give significant per-core performance improvement.
1594c07e055SKirill Rybalchenko   For mixed traffic (IMIX) the optimal number of worker cores is around 2-3.
160d629b7b5SJohn McNamara   For large packets (1.5 kbytes) scheduler shows linear scaling in performance
1614c07e055SKirill Rybalchenko   up to eight cores.
16285b00824SAdam Dybkowski   Each worker uses its own cryptodev. Only software cryptodevs
1634c07e055SKirill Rybalchenko   are supported. Only the same type of cryptodevs should be used concurrently.
1644c07e055SKirill Rybalchenko
1654c07e055SKirill Rybalchenko   The multi-core mode uses one extra parameter:
1664c07e055SKirill Rybalchenko
1674c07e055SKirill Rybalchenko   * corelist: Semicolon-separated list of logical cores to be used as workers.
16885b00824SAdam Dybkowski     The number of worker cores should be equal to the number of worker cryptodevs.
1692b28344bSKirill Rybalchenko     These cores should be present in EAL core list parameter and
1702b28344bSKirill Rybalchenko     should not be used by the application or any other process.
1714c07e055SKirill Rybalchenko
1724c07e055SKirill Rybalchenko   Example:
1734c07e055SKirill Rybalchenko    ... --vdev "crypto_aesni_mb1,name=aesni_mb_1" --vdev "crypto_aesni_mb_pmd2,name=aesni_mb_2" \
17485b00824SAdam Dybkowski    --vdev "crypto_scheduler,worker=aesni_mb_1,worker=aesni_mb_2,mode=multi-core,corelist=23;24" ...
175