app/crypto-perf-test: fix unset crc algorithm

Message ID 20240313145448.26264-1-arkadiuszx.kusztal@intel.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series app/crypto-perf-test: fix unset crc algorithm |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-amd64-testing fail Testing issues
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS

Commit Message

Arkadiusz Kusztal March 13, 2024, 2:54 p.m. UTC
  Because net crc api is not thread-safe, setting crc algorithm
by the application will prevent race condition in the calc function.
Race condition still may occur when any of the threads will call this
function again. Function is called with the highest possible SIMD
extension, which is AVX512, but if this is not found, CRC API will
pick the other highest possible extension, or scalar if no SIMD
available.

Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application")

Signed-off-by: Arkadiusz Kusztal <arkadiuszx.kusztal@intel.com>
---
 app/test-crypto-perf/main.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Akhil Goyal March 13, 2024, 6:22 p.m. UTC | #1
> Because net crc api is not thread-safe, setting crc algorithm
> by the application will prevent race condition in the calc function.
> Race condition still may occur when any of the threads will call this
> function again. Function is called with the highest possible SIMD
> extension, which is AVX512, but if this is not found, CRC API will
> pick the other highest possible extension, or scalar if no SIMD
> available.
> 
> Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test application")
> 
> Signed-off-by: Arkadiusz Kusztal <arkadiuszx.kusztal@intel.com>
> ---
>  app/test-crypto-perf/main.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
> index 40c0b4b54f..58496797d7 100644
> --- a/app/test-crypto-perf/main.c
> +++ b/app/test-crypto-perf/main.c
> @@ -11,6 +11,7 @@
>  #include <rte_eal.h>
>  #include <rte_errno.h>
>  #include <rte_cryptodev.h>
> +#include <rte_net_crc.h>
>  #ifdef RTE_CRYPTO_SCHEDULER
>  #include <rte_cryptodev_scheduler.h>
>  #endif
> @@ -599,6 +600,8 @@ main(int argc, char **argv)
>  		goto err;
>  	}
> 
> +	rte_net_crc_set_alg(RTE_NET_CRC_AVX512);
> +
>  	ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
>  			nb_cryptodevs);
>  	if (ret) {
> --
Not sure what is the use of this API here.
Which calc function is it fixing.

Also will it ever pick neon handler?
  
Arkadiusz Kusztal March 13, 2024, 10:15 p.m. UTC | #2
> -----Original Message-----
> From: Akhil Goyal <gakhil@marvell.com>
> Sent: Wednesday, March 13, 2024 7:22 PM
> To: Kusztal, ArkadiuszX <arkadiuszx.kusztal@intel.com>; dev@dpdk.org
> Cc: Power, Ciara <ciara.power@intel.com>
> Subject: RE: [EXTERNAL] [PATCH] app/crypto-perf-test: fix unset crc algorithm
> 
> > Because net crc api is not thread-safe, setting crc algorithm by the
> > application will prevent race condition in the calc function.
> > Race condition still may occur when any of the threads will call this
> > function again. Function is called with the highest possible SIMD
> > extension, which is AVX512, but if this is not found, CRC API will
> > pick the other highest possible extension, or scalar if no SIMD
> > available.
> >
> > Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test
> > application")
> >
> > Signed-off-by: Arkadiusz Kusztal <arkadiuszx.kusztal@intel.com>
> > ---
> >  app/test-crypto-perf/main.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
> > index 40c0b4b54f..58496797d7 100644
> > --- a/app/test-crypto-perf/main.c
> > +++ b/app/test-crypto-perf/main.c
> > @@ -11,6 +11,7 @@
> >  #include <rte_eal.h>
> >  #include <rte_errno.h>
> >  #include <rte_cryptodev.h>
> > +#include <rte_net_crc.h>
> >  #ifdef RTE_CRYPTO_SCHEDULER
> >  #include <rte_cryptodev_scheduler.h>
> >  #endif
> > @@ -599,6 +600,8 @@ main(int argc, char **argv)
> >  		goto err;
> >  	}
> >
> > +	rte_net_crc_set_alg(RTE_NET_CRC_AVX512);
> > +
> >  	ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
> >  			nb_cryptodevs);
> >  	if (ret) {
> > --
> Not sure what is the use of this API here.
> Which calc function is it fixing.

Yes, this deserves some explanation, rte_net_crc_calc function, when alg not set, will first try to set it during the first run.
Yet it is done in thread-unsafe manner, causing perf-test to most likely segfault because of that, when more than one thread used.
 
> 
> Also will it ever pick neon handler?

No, it won't, currently only qat is using this api though.
This api needs to be fixed, so eventually this will look different, but for now, not many choices available.
  
Akhil Goyal March 14, 2024, 12:49 p.m. UTC | #3
> > Subject: RE: [EXTERNAL] [PATCH] app/crypto-perf-test: fix unset crc algorithm
> >
> > > Because net crc api is not thread-safe, setting crc algorithm by the
> > > application will prevent race condition in the calc function.
> > > Race condition still may occur when any of the threads will call this
> > > function again. Function is called with the highest possible SIMD
> > > extension, which is AVX512, but if this is not found, CRC API will
> > > pick the other highest possible extension, or scalar if no SIMD
> > > available.
> > >
> > > Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test
> > > application")
> > >
> > > Signed-off-by: Arkadiusz Kusztal <arkadiuszx.kusztal@intel.com>
> > > ---
> > >  app/test-crypto-perf/main.c | 3 +++
> > >  1 file changed, 3 insertions(+)
> > >
> > > diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
> > > index 40c0b4b54f..58496797d7 100644
> > > --- a/app/test-crypto-perf/main.c
> > > +++ b/app/test-crypto-perf/main.c
> > > @@ -11,6 +11,7 @@
> > >  #include <rte_eal.h>
> > >  #include <rte_errno.h>
> > >  #include <rte_cryptodev.h>
> > > +#include <rte_net_crc.h>
> > >  #ifdef RTE_CRYPTO_SCHEDULER
> > >  #include <rte_cryptodev_scheduler.h>
> > >  #endif
> > > @@ -599,6 +600,8 @@ main(int argc, char **argv)
> > >  		goto err;
> > >  	}
> > >
> > > +	rte_net_crc_set_alg(RTE_NET_CRC_AVX512);
> > > +
> > >  	ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
> > >  			nb_cryptodevs);
> > >  	if (ret) {
> > > --
> > Not sure what is the use of this API here.
> > Which calc function is it fixing.
> 
> Yes, this deserves some explanation, rte_net_crc_calc function, when alg not set,
> will first try to set it during the first run.
> Yet it is done in thread-unsafe manner, causing perf-test to most likely segfault
> because of that, when more than one thread used.
> 
Still it is not clear. Which use case of test-crypto-perf need setting this?
If it is specific to a usecase, then it should be under checks or it should be inside PMD.

> >
> > Also will it ever pick neon handler?
> 
> No, it won't, currently only qat is using this api though.
> This api needs to be fixed, so eventually this will look different, but for now, not
> many choices available.
  
Arkadiusz Kusztal March 15, 2024, 9:56 a.m. UTC | #4
> -----Original Message-----
> From: Akhil Goyal <gakhil@marvell.com>
> Sent: Thursday, March 14, 2024 1:50 PM
> To: Kusztal, ArkadiuszX <arkadiuszx.kusztal@intel.com>; dev@dpdk.org
> Cc: Power, Ciara <ciara.power@intel.com>
> Subject: RE: [EXTERNAL] [PATCH] app/crypto-perf-test: fix unset crc algorithm
> 
> > > Subject: RE: [EXTERNAL] [PATCH] app/crypto-perf-test: fix unset crc
> > > algorithm
> > >
> > > > Because net crc api is not thread-safe, setting crc algorithm by
> > > > the application will prevent race condition in the calc function.
> > > > Race condition still may occur when any of the threads will call
> > > > this function again. Function is called with the highest possible
> > > > SIMD extension, which is AVX512, but if this is not found, CRC API
> > > > will pick the other highest possible extension, or scalar if no
> > > > SIMD available.
> > > >
> > > > Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test
> > > > application")
> > > >
> > > > Signed-off-by: Arkadiusz Kusztal <arkadiuszx.kusztal@intel.com>
> > > > ---
> > > >  app/test-crypto-perf/main.c | 3 +++
> > > >  1 file changed, 3 insertions(+)
> > > >
> > > > diff --git a/app/test-crypto-perf/main.c
> > > > b/app/test-crypto-perf/main.c index 40c0b4b54f..58496797d7 100644
> > > > --- a/app/test-crypto-perf/main.c
> > > > +++ b/app/test-crypto-perf/main.c
> > > > @@ -11,6 +11,7 @@
> > > >  #include <rte_eal.h>
> > > >  #include <rte_errno.h>
> > > >  #include <rte_cryptodev.h>
> > > > +#include <rte_net_crc.h>
> > > >  #ifdef RTE_CRYPTO_SCHEDULER
> > > >  #include <rte_cryptodev_scheduler.h>  #endif @@ -599,6 +600,8 @@
> > > > main(int argc, char **argv)
> > > >  		goto err;
> > > >  	}
> > > >
> > > > +	rte_net_crc_set_alg(RTE_NET_CRC_AVX512);
> > > > +
> > > >  	ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
> > > >  			nb_cryptodevs);
> > > >  	if (ret) {
> > > > --
> > > Not sure what is the use of this API here.
> > > Which calc function is it fixing.
> >
> > Yes, this deserves some explanation, rte_net_crc_calc function, when
> > alg not set, will first try to set it during the first run.
> > Yet it is done in thread-unsafe manner, causing perf-test to most
> > likely segfault because of that, when more than one thread used.
> >
> Still it is not clear. Which use case of test-crypto-perf need setting this?
`-optype docsis` currently, so I can narrow down it to docsis only.
> If it is specific to a usecase, then it should be under checks or it should be inside
> PMD.
It would be the best to have it inside the PMD, the problem is that it changes algorithm for entire process,
so until changes made to the API, it should be under user control.
> 
> > >
> > > Also will it ever pick neon handler?
> >
> > No, it won't, currently only qat is using this api though.
> > This api needs to be fixed, so eventually this will look different,
> > but for now, not many choices available.
  

Patch

diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index 40c0b4b54f..58496797d7 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -11,6 +11,7 @@ 
 #include <rte_eal.h>
 #include <rte_errno.h>
 #include <rte_cryptodev.h>
+#include <rte_net_crc.h>
 #ifdef RTE_CRYPTO_SCHEDULER
 #include <rte_cryptodev_scheduler.h>
 #endif
@@ -599,6 +600,8 @@  main(int argc, char **argv)
 		goto err;
 	}
 
+	rte_net_crc_set_alg(RTE_NET_CRC_AVX512);
+
 	ret = cperf_verify_devices_capabilities(&opts, enabled_cdevs,
 			nb_cryptodevs);
 	if (ret) {