xref: /dpdk/doc/guides/cryptodevs/scheduler.rst (revision ee9586dd15fbd07d82bd674eb26b5c7bf4c309db)
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
16d58a3f31SFan ZhangThe Cryptodev Scheduler PMD library (**librte_pmd_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
19d58a3f31SFan Zhangslaves, and distributes the crypto workload to them with certain behavior.
20d58a3f31SFan ZhangThe behaviors are categorizes as different "modes". Basically, a scheduling
21d58a3f31SFan Zhangmode defines certain actions for scheduling crypto ops to its slaves.
22d58a3f31SFan Zhang
23d58a3f31SFan ZhangThe librte_pmd_crypto_scheduler library exports a C API which provides an API
24d58a3f31SFan Zhangfor attaching/detaching slaves, 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 ZhangInstallation
36d58a3f31SFan Zhang------------
37d58a3f31SFan Zhang
38d58a3f31SFan ZhangTo build DPDK with CRYTPO_SCHEDULER_PMD the user is required to set
39d58a3f31SFan ZhangCONFIG_RTE_LIBRTE_PMD_CRYPTO_SCHEDULER=y in config/common_base, and
40d58a3f31SFan Zhangrecompile DPDK
41d58a3f31SFan Zhang
42d58a3f31SFan Zhang
43d58a3f31SFan ZhangInitialization
44d58a3f31SFan Zhang--------------
45d58a3f31SFan Zhang
46d58a3f31SFan ZhangTo use the PMD in an application, user must:
47d58a3f31SFan Zhang
487fe90a66SPablo de Lara* Call rte_vdev_init("crypto_scheduler") within the application.
49d58a3f31SFan Zhang
507fe90a66SPablo de Lara* Use --vdev="crypto_scheduler" in the EAL options, which will call
512f6fec53SThomas Monjalon  rte_vdev_init() internally.
52d58a3f31SFan Zhang
53d58a3f31SFan Zhang
54d58a3f31SFan ZhangThe following parameters (all optional) can be provided in the previous
55d58a3f31SFan Zhangtwo calls:
56d58a3f31SFan Zhang
57d58a3f31SFan Zhang* socket_id: Specify the socket where the memory for the device is going
58d58a3f31SFan Zhang  to be allocated (by default, socket_id will be the socket where the core
59d58a3f31SFan Zhang  that is creating the PMD is running on).
60d58a3f31SFan Zhang
61d58a3f31SFan Zhang* max_nb_sessions: Specify the maximum number of sessions that can be
62d58a3f31SFan Zhang  created. This value may be overwritten internally if there are too
63d58a3f31SFan Zhang  many devices are attached.
64d58a3f31SFan Zhang
65d58a3f31SFan Zhang* slave: If a cryptodev has been initialized with specific name, it can be
66d58a3f31SFan Zhang  attached to the scheduler using this parameter, simply filling the name
67d58a3f31SFan Zhang  here. Multiple cryptodevs can be attached initially by presenting this
68d58a3f31SFan Zhang  parameter multiple times.
69d58a3f31SFan Zhang
70a0e805eeSFan Zhang* mode: Specify the scheduling mode of the PMD. The supported scheduling
71a0e805eeSFan Zhang  mode parameter values are specified in the "Cryptodev Scheduler Modes
72a0e805eeSFan Zhang  Overview" section.
73a0e805eeSFan Zhang
74*ee9586ddSFan Zhang* mode_param: Specify the mode-specific parameter. Some scheduling modes
75*ee9586ddSFan Zhang  may be initialized with specific parameters other than the default ones,
76*ee9586ddSFan Zhang  such as the **threshold** packet size of **packet-size-distr** mode. This
77*ee9586ddSFan Zhang  parameter fulfills the purpose.
78*ee9586ddSFan Zhang
79a0e805eeSFan Zhang* ordering: Specify the status of the crypto operations ordering feature.
80a0e805eeSFan Zhang  The value of this parameter can be "enable" or "disable". This feature
81a0e805eeSFan Zhang  is disabled by default.
82a0e805eeSFan Zhang
83d58a3f31SFan ZhangExample:
84d58a3f31SFan Zhang
85d58a3f31SFan Zhang.. code-block:: console
86d58a3f31SFan Zhang
877fe90a66SPablo de Lara    ... --vdev "crypto_aesni_mb0,name=aesni_mb_1" --vdev "crypto_aesni_mb1,name=aesni_mb_2" --vdev "crypto_scheduler,slave=aesni_mb_1,slave=aesni_mb_2" ...
88d58a3f31SFan Zhang
89d58a3f31SFan Zhang.. note::
90d58a3f31SFan Zhang
91d58a3f31SFan Zhang    * The scheduler cryptodev cannot be started unless the scheduling mode
92d58a3f31SFan Zhang      is set and at least one slave is attached. Also, to configure the
93d58a3f31SFan Zhang      scheduler in the run-time, like attach/detach slave(s), change
94d58a3f31SFan Zhang      scheduling mode, or enable/disable crypto op ordering, one should stop
95d58a3f31SFan Zhang      the scheduler first, otherwise an error will be returned.
96d58a3f31SFan Zhang
97d58a3f31SFan Zhang    * The crypto op reordering feature requires using the userdata field of
98d58a3f31SFan Zhang      every mbuf to be processed to store temporary data. By the end of
99d58a3f31SFan Zhang      processing, the field is set to pointing to NULL, any previously
100d58a3f31SFan Zhang      stored value of this field will be lost.
101d58a3f31SFan Zhang
102d58a3f31SFan Zhang
103d58a3f31SFan ZhangCryptodev Scheduler Modes Overview
104d58a3f31SFan Zhang----------------------------------
105d58a3f31SFan Zhang
106d58a3f31SFan ZhangCurrently the Crypto Scheduler PMD library supports following modes of
107d58a3f31SFan Zhangoperation:
108d58a3f31SFan Zhang
109d58a3f31SFan Zhang*   **CDEV_SCHED_MODE_ROUNDROBIN:**
110d58a3f31SFan Zhang
111a0e805eeSFan Zhang   *Initialization mode parameter*: **round-robin**
112a0e805eeSFan Zhang
113d58a3f31SFan Zhang   Round-robin mode, which distributes the enqueued burst of crypto ops
114d58a3f31SFan Zhang   among its slaves in a round-robin manner. This mode may help to fill
115d58a3f31SFan Zhang   the throughput gap between the physical core and the existing cryptodevs
116d58a3f31SFan Zhang   to increase the overall performance.
117a783aa63SFan Zhang
118a783aa63SFan Zhang*   **CDEV_SCHED_MODE_PKT_SIZE_DISTR:**
119a783aa63SFan Zhang
120a0e805eeSFan Zhang   *Initialization mode parameter*: **packet-size-distr**
121a0e805eeSFan Zhang
122a783aa63SFan Zhang   Packet-size based distribution mode, which works with 2 slaves, the primary
123a783aa63SFan Zhang   slave and the secondary slave, and distributes the enqueued crypto
124a783aa63SFan Zhang   operations to them based on their data lengths. A crypto operation will be
125a783aa63SFan Zhang   distributed to the primary slave if its data length is equal to or bigger
126a783aa63SFan Zhang   than the designated threshold, otherwise it will be handled by the secondary
127a783aa63SFan Zhang   slave.
128a783aa63SFan Zhang
129a783aa63SFan Zhang   A typical usecase in this mode is with the QAT cryptodev as the primary and
130a783aa63SFan Zhang   a software cryptodev as the secondary slave. This may help applications to
131a783aa63SFan Zhang   process additional crypto workload than what the QAT cryptodev can handle on
132a783aa63SFan Zhang   its own, by making use of the available CPU cycles to deal with smaller
133a783aa63SFan Zhang   crypto workloads.
13437f075daSFan Zhang
1354e30ead5SFan Zhang   The threshold is set to 128 bytes by default. It can be updated by calling
1364e30ead5SFan Zhang   function **rte_cryptodev_scheduler_option_set**. The parameter of
1374e30ead5SFan Zhang   **option_type** must be **CDEV_SCHED_OPTION_THRESHOLD** and **option** should
1384e30ead5SFan Zhang   point to a rte_cryptodev_scheduler_threshold_option structure filled with
1394e30ead5SFan Zhang   appropriate threshold value. Please NOTE this threshold has be a power-of-2
1404e30ead5SFan Zhang   unsigned integer.
1414e30ead5SFan Zhang
14237f075daSFan Zhang*   **CDEV_SCHED_MODE_FAILOVER:**
14337f075daSFan Zhang
144a0e805eeSFan Zhang   *Initialization mode parameter*: **fail-over**
145a0e805eeSFan Zhang
14637f075daSFan Zhang   Fail-over mode, which works with 2 slaves, the primary slave and the
14737f075daSFan Zhang   secondary slave. In this mode, the scheduler will enqueue the incoming
14837f075daSFan Zhang   crypto operation burst to the primary slave. When one or more crypto
14937f075daSFan Zhang   operations fail to be enqueued, then they will be enqueued to the secondary
15037f075daSFan Zhang   slave.
1514c07e055SKirill Rybalchenko
1524c07e055SKirill Rybalchenko*   **CDEV_SCHED_MODE_MULTICORE:**
1534c07e055SKirill Rybalchenko
1544c07e055SKirill Rybalchenko   *Initialization mode parameter*: **multi-core**
1554c07e055SKirill Rybalchenko
1564c07e055SKirill Rybalchenko   Multi-core mode, which distributes the workload with several (up to eight)
1574c07e055SKirill Rybalchenko   worker cores. The enqueued bursts are distributed among the worker cores in a
1584c07e055SKirill Rybalchenko   round-robin manner. If scheduler cannot enqueue entire burst to the same worker,
1594c07e055SKirill Rybalchenko   it will enqueue the remaining operations to the next available worker.
1604c07e055SKirill Rybalchenko   For pure small packet size (64 bytes) traffic however the multi-core mode is not
1614c07e055SKirill Rybalchenko   an optimal solution, as it doesn't give significant per-core performance improvement.
1624c07e055SKirill Rybalchenko   For mixed traffic (IMIX) the optimal number of worker cores is around 2-3.
1634c07e055SKirill Rybalchenko   For large packets (1.5 Kbytes) scheduler shows linear scaling in performance
1644c07e055SKirill Rybalchenko   up to eight cores.
1654c07e055SKirill Rybalchenko   Each worker uses its own slave cryptodev. Only software cryptodevs
1664c07e055SKirill Rybalchenko   are supported. Only the same type of cryptodevs should be used concurrently.
1674c07e055SKirill Rybalchenko
1684c07e055SKirill Rybalchenko   The multi-core mode uses one extra parameter:
1694c07e055SKirill Rybalchenko
1704c07e055SKirill Rybalchenko   * corelist: Semicolon-separated list of logical cores to be used as workers.
1714c07e055SKirill Rybalchenko     The number of worker cores should be equal to the number of slave cryptodevs.
1722b28344bSKirill Rybalchenko     These cores should be present in EAL core list parameter and
1732b28344bSKirill Rybalchenko     should not be used by the application or any other process.
1744c07e055SKirill Rybalchenko
1754c07e055SKirill Rybalchenko   Example:
1764c07e055SKirill Rybalchenko    ... --vdev "crypto_aesni_mb1,name=aesni_mb_1" --vdev "crypto_aesni_mb_pmd2,name=aesni_mb_2" \
1774c07e055SKirill Rybalchenko    --vdev "crypto_scheduler,slave=aesni_mb_1,slave=aesni_mb_2,mode=multi-core,corelist=23;24" ...
178