xref: /spdk/doc/accel_fw.md (revision 4fbe1f5b46a242fc4b5943a6aad0b33a496d440e)
1e9b3a0e1Spaul luse# Acceleration Framework {#accel_fw}
2e9b3a0e1Spaul luse
3e9b3a0e1Spaul luseSPDK provides a framework for abstracting general acceleration capabilities
4e9b3a0e1Spaul lusethat can be implemented through plug-in modules and low-level libraries. These
5e9b3a0e1Spaul luseplug-in modules include support for hardware acceleration engines such as
6e9b3a0e1Spaul lusethe Intel(R) I/O Acceleration Technology (IOAT) engine and the Intel(R) Data
7e9b3a0e1Spaul luseStreaming Accelerator (DSA) engine. Additionally, a software plug-in module
8e9b3a0e1Spaul luseexists to enable use of the framework in environments without hardware
9e9b3a0e1Spaul luseacceleration capabilities. ISA/L is used for optimized CRC32C calculation within
10e9b3a0e1Spaul lusethe software module.
11e9b3a0e1Spaul luse
121e1fd9acSwawryk## Acceleration Framework Functions {#accel_functions}
13e9b3a0e1Spaul luse
14e9b3a0e1Spaul luseFunctions implemented via the framework can be found in the DoxyGen documentation of the
15081f080aSBen Walkerframework public header file here [accel.h](https://spdk.io/doc/accel_8h.html)
16e9b3a0e1Spaul luse
171e1fd9acSwawryk## Acceleration Framework Design Considerations {#accel_dc}
18e9b3a0e1Spaul luse
19081f080aSBen WalkerThe general interface is defined by `/include/spdk/accel.h` and implemented
20e9b3a0e1Spaul lusein `/lib/accel`.  These functions may be called by an SPDK application and in
21e9b3a0e1Spaul lusemost cases, except where otherwise documented, are asynchronous and follow the
22e9b3a0e1Spaul lusestandard SPDK model for callbacks with a callback argument.
23e9b3a0e1Spaul luse
24e9b3a0e1Spaul luseIf the acceleration framework is started without initializing a hardware module,
25d71a91bbSpaul luseoptimized software implementations of the operations will back the public API. All
26d71a91bbSpaul luseoperations supported by the framework have a backing software implementation in
27d71a91bbSpaul lusethe event that no hardware accelerators have been enabled for that operation.
28d71a91bbSpaul luse
29712e8cb7SBen WalkerWhen multiple hardware modules are enabled the framework will assign each operation to
30712e8cb7SBen Walkera module based on the order in which it was initialized. So, for example if two modules are
31712e8cb7SBen Walkerenabled, IOAT and software, the software module will be used for every operation except those
32d71a91bbSpaul lusesupported by IOAT.
33e9b3a0e1Spaul luse
341e1fd9acSwawryk## Acceleration Low Level Libraries {#accel_libs}
35e9b3a0e1Spaul luse
36e9b3a0e1Spaul luseLow level libraries provide only the most basic functions that are specific to
37e9b3a0e1Spaul lusethe hardware. Low level libraries are located in the '/lib' directory with the
38e9b3a0e1Spaul luseexception of the software implementation which is implemented as part of the
39e9b3a0e1Spaul luseframework itself. The software low level library does not expose a public API.
40e9b3a0e1Spaul luseApplications may choose to interact directly with a low level library if there are
41e9b3a0e1Spaul lusespecific needs/considerations not met via accessing the library through the
42e9b3a0e1Spaul luseframework/module. Note that when using the low level libraries directly, the
43e9b3a0e1Spaul luseframework abstracted interface is bypassed as the application will call the public
44e9b3a0e1Spaul lusefunctions exposed by the individual low level libraries. Thus, code written this
45e9b3a0e1Spaul luseway needs to be certain that the underlying hardware exists everywhere that it runs.
46e9b3a0e1Spaul luse
47e9b3a0e1Spaul luseThe low level library for IOAT is located in `/lib/ioat`.  The low level library
48d71a91bbSpaul lusefor DSA and IAA is in `/lib/idxd` (IDXD stands for Intel(R) Data Acceleration Driver and
49d71a91bbSpaul lusesupports both DSA and IAA hardware accelerators). In `/lib/idxd` folder, SPDK supports the ability
50d71a91bbSpaul luseto use either user space and kernel space drivers. The following describes each usage scenario:
51749ec909SZiye Yang
52d71a91bbSpaul luseLeveraging user space idxd driver: The DSA devices are managed by the SPDK user space
53749ec909SZiye Yangdriver in a dedicated SPDK process, then the device cannot be shared by another
54749ec909SZiye Yangprocess. The benefit of this usage is no kernel dependency.
55749ec909SZiye Yang
56749ec909SZiye YangLeveraging kernel space driver: The DSA devices are managed by kernel
57749ec909SZiye Yangspace drivers. And the Work queues inside the DSA device can be shared among
58a82b365bSJosh Sorefdifferent processes. Naturally, it can be used in cloud native scenario. The drawback of
59d71a91bbSpaul lusethis usage is the kernel dependency, i.e., idxd kernel driver must be supported and loaded
60749ec909SZiye Yangin the kernel.
61e9b3a0e1Spaul luse
621e1fd9acSwawryk## Acceleration Plug-In Modules {#accel_modules}
63e9b3a0e1Spaul luse
64e9b3a0e1Spaul lusePlug-in modules depend on low level libraries to interact with the hardware and
65e9b3a0e1Spaul luseadd additional functionality such as queueing during busy conditions or flow
66e9b3a0e1Spaul lusecontrol in some cases. The framework in turn depends on the modules to provide
67e9b3a0e1Spaul lusethe complete implementation of the acceleration component. A module must be
68e9b3a0e1Spaul luseselected via startup RPC when the application is started. Otherwise, if no startup
69e9b3a0e1Spaul luseRPC is provided, the framework is available and will use the software plug-in module.
70e9b3a0e1Spaul luse
711e1fd9acSwawryk### IOAT Module {#accel_ioat}
72e9b3a0e1Spaul luse
73712e8cb7SBen WalkerTo use the IOAT module, use the RPC [`ioat_scan_accel_module`](https://spdk.io/doc/jsonrpc.html) before starting the application.
74e9b3a0e1Spaul luse
75ffef30aeSpaul luse### DSA Module {#accel_dsa}
76ffef30aeSpaul luse
77ffef30aeSpaul luseThe DSA module supports the DSA hardware and relies on the low level IDXD library.
78e9b3a0e1Spaul luse
79712e8cb7SBen WalkerTo use the DSA module, use the RPC
80712e8cb7SBen Walker[`dsa_scan_accel_module`](https://spdk.io/doc/jsonrpc.html). By default, this
81f0bf4e75SBen Walkerwill attempt to load the SPDK user-space idxd driver. To use the built-in
82f0bf4e75SBen Walkerkernel driver on Linux, add the `-k` parameter. See the next section for
83f0bf4e75SBen Walkerdetails on using the kernel driver.
84e9b3a0e1Spaul luse
85f0bf4e75SBen WalkerThe DSA hardware supports a limited queue depth and channels. This means that
86f0bf4e75SBen Walkeronly a limited number of `spdk_thread`s will be able to acquire a channel.
87f0bf4e75SBen WalkerDesign software to deal with the inability to get a channel.
88504bf591Speluse
89*4fbe1f5bSSlawomir Ptak**Important**: The devices `PCI_DEVICE_ID_INTEL_DSA_SPR0` and `PCI_DEVICE_ID_INTEL_IAX_SPR0`
90*4fbe1f5bSSlawomir Ptakhave been added to the vfio_pci denylist. This prevents the use of userspace DSA and IAA drivers
91*4fbe1f5bSSlawomir Ptakfrom SPDK on systems that are affected.
92*4fbe1f5bSSlawomir Ptak
93*4fbe1f5bSSlawomir Ptak**Additionally**, to use the kernel DSA driver from SPDK, users are required to possess
94*4fbe1f5bSSlawomir Ptakthe `CAP_SYS_RAWIO` capability.
95*4fbe1f5bSSlawomir Ptak
9661fbb000SAlexey Marchuk#### How to use kernel idxd driver {#accel_idxd_kernel}
97749ec909SZiye Yang
98f0bf4e75SBen WalkerThere are several dependencies to leverage the Linux idxd driver for driving DSA devices.
99749ec909SZiye Yang
100f0bf4e75SBen Walker1 Linux kernel support: You need to have a Linux kernel with the `idxd` driver
1013f912cf0SMichal Bergerloaded. Further, add the following command line options to the kernel boot
102f0bf4e75SBen Walkercommands:
103749ec909SZiye Yang
104f0bf4e75SBen Walker```bash
105f0bf4e75SBen Walkerintel_iommu=on,sm_on
106f0bf4e75SBen Walker```
107f0bf4e75SBen Walker
1088b29c211Spaul luse2 User library dependency: Users need to install the developer version of the
1098b29c211Spaul luse`accel-config` library. This is often packaged, but the source is available on
110f0bf4e75SBen Walker[GitHub](https://github.com/intel/idxd-config). After the library is installed,
111f0bf4e75SBen Walkerusers can use the `accel-config` command to configure the work queues(WQs) of
112f0bf4e75SBen Walkerthe idxd devices managed by the kernel with the following steps:
113749ec909SZiye Yang
114d71a91bbSpaul luseNote: this library must be installed before you run `configure`
115d71a91bbSpaul luse
116749ec909SZiye Yang```bash
117749ec909SZiye Yangaccel-config disable-wq dsa0/wq0.1
118749ec909SZiye Yangaccel-config disable-device dsa0
119f0bf4e75SBen Walkeraccel-config config-wq --group-id=0 --mode=dedicated --wq-size=128 --type=user --name="MyApp1"
120749ec909SZiye Yang --priority=10 --block-on-fault=1 dsa0/wq0.1
121f0bf4e75SBen Walkeraccel-config config-engine dsa0/engine0.0 --group-id=0
122749ec909SZiye Yangaccel-config config-engine dsa0/engine0.1 --group-id=0
123f0bf4e75SBen Walkeraccel-config config-engine dsa0/engine0.2 --group-id=0
124f0bf4e75SBen Walkeraccel-config config-engine dsa0/engine0.3 --group-id=0
125749ec909SZiye Yangaccel-config enable-device dsa0
126749ec909SZiye Yangaccel-config enable-wq dsa0/wq0.1
127749ec909SZiye Yang```
128749ec909SZiye Yang
129f0bf4e75SBen WalkerDSA can be configured in many ways, but the above configuration is needed for use with SPDK.
13059af87d4Spaul luseBefore you can run using the kernel driver you need to make sure that the hardware is bound
13159af87d4Spaul luseto the kernel driver and not VFIO.  By default when you run `setup.sh` DSA devices will be
13259af87d4Spaul lusebound to VFIO.  To exclude DSA devices, pass a whitespace separated list of DSA devices BDF
13359af87d4Spaul luseusing the PCI_BLOCKED parameter as shown below.
13459af87d4Spaul luse
135a7315744Swanghailiangx```bash
136a7315744Swanghailiangxsudo PCI_BLOCKED="0000:04:00.0 0000:05:00.0" ./setup.sh
137a7315744Swanghailiangx```
13859af87d4Spaul luse
13959af87d4Spaul luseNote: you might need to run `sudo ./setup.sh reset` to unbind all drivers before performing
14059af87d4Spaul lusethe step above.
141749ec909SZiye Yang
1421e1fd9acSwawryk### Software Module {#accel_sw}
143e9b3a0e1Spaul luse
144712e8cb7SBen WalkerThe software module is enabled by default. If no hardware module is explicitly
145e9b3a0e1Spaul luseenabled via startup RPC as discussed earlier, the software module will use ISA-L
146e9b3a0e1Spaul luseif available for functions such as CRC32C. Otherwise, standard glibc calls are
147e9b3a0e1Spaul luseused to back the framework API.
148d49c9274Spaul luse
14961fbb000SAlexey Marchuk### dpdk_cryptodev {#accel_dpdk_cryptodev}
15061fbb000SAlexey Marchuk
15161fbb000SAlexey MarchukThe dpdk_cryptodev module uses DPDK CryptoDev API to implement crypto operations.
15261fbb000SAlexey MarchukThe following ciphers and PMDs are supported:
15361fbb000SAlexey Marchuk
15461fbb000SAlexey Marchuk- AESN-NI Multi Buffer Crypto Poll Mode Driver: RTE_CRYPTO_CIPHER_AES128_CBC
15561fbb000SAlexey Marchuk- Intel(R) QuickAssist (QAT) Crypto Poll Mode Driver: RTE_CRYPTO_CIPHER_AES128_CBC,
15661fbb000SAlexey Marchuk  RTE_CRYPTO_CIPHER_AES128_XTS
15761fbb000SAlexey Marchuk  (Note: QAT is functional however is marked as experimental until the hardware has
15861fbb000SAlexey Marchuk  been fully integrated with the SPDK CI system.)
15961fbb000SAlexey Marchuk- MLX5 Crypto Poll Mode Driver: RTE_CRYPTO_CIPHER_AES256_XTS, RTE_CRYPTO_CIPHER_AES512_XTS
16013603217SZhangfei Gao- UADK Crypto Poll Mode Driver: RTE_CRYPTO_CIPHER_AES256_XTS, RTE_CRYPTO_CIPHER_AES512_XTS
16161fbb000SAlexey Marchuk
16261fbb000SAlexey MarchukTo enable this module, use [`dpdk_cryptodev_scan_accel_module`](https://spdk.io/doc/jsonrpc.html),
16361fbb000SAlexey Marchukthis RPC is available in STARTUP state and the SPDK application needs to be run with `--wait-for-rpc`
16461fbb000SAlexey MarchukCLI parameter. To select a specific PMD, use [`dpdk_cryptodev_set_driver`](https://spdk.io/doc/jsonrpc.html)
16561fbb000SAlexey Marchuk
166712e8cb7SBen Walker### Module to Operation Code Assignment {#accel_assignments}
167d49c9274Spaul luse
168712e8cb7SBen WalkerWhen multiple modules are initialized, the accel framework will assign op codes to
169712e8cb7SBen Walkermodules by first assigning all op codes to the Software Module and then overriding
170712e8cb7SBen Walkerop code assignments to Hardware Modules in the order in which they were initialized.
171d49c9274Spaul luseThe RPC `accel_get_opc_assignments` can be used at any time to see the current
172d49c9274Spaul luseassignment map including the names of valid operations.  The RPC `accel_assign_opc`
173712e8cb7SBen Walkercan be used after initializing the desired Hardware Modules but before starting the
174d49c9274Spaul luseframework in the event that a specific override is desired.  Note that to start an
175d49c9274Spaul luseapplication and send startup RPC's use the `--wait-for-rpc` parameter and then use the
176712e8cb7SBen Walker`framework_start_init` RPC to continue. For example, assume the DSA Module is initialized
177d49c9274Spaul lusebut for some reason the desire is to have the Software Module handle copies instead.
178d49c9274Spaul luseThe following RPCs would accomplish the copy override:
179d49c9274Spaul luse
180a7315744Swanghailiangx```bash
181a7315744Swanghailiangx./scripts/rpc.py dsa_scan_accel_module
1823afa8c2fSwanghailiangx./scripts/rpc.py accel_assign_opc -o copy -m software
183d49c9274Spaul luse./scripts/rpc.py framework_start_init
184d49c9274Spaul luse./scripts/rpc.py accel_get_opc_assignments
185d49c9274Spaul luse{
186d49c9274Spaul luse  "copy": "software",
187d49c9274Spaul luse  "fill": "dsa",
188d49c9274Spaul luse  "dualcast": "dsa",
189d49c9274Spaul luse  "compare": "dsa",
190d49c9274Spaul luse  "crc32c": "dsa",
191d49c9274Spaul luse  "copy_crc32c": "dsa",
192d49c9274Spaul luse  "compress": "software",
193d49c9274Spaul luse  "decompress": "software"
194a7315744Swanghailiangx}
195a7315744Swanghailiangx```
196d49c9274Spaul luse
1973f912cf0SMichal BergerTo determine the name of available modules and their supported operations use the
198712e8cb7SBen WalkerRPC `accel_get_module_info`.
199