crypto: benchmark - add the crypto benchmark
Subsystems (3)
cover crypto: benchmark - add the crypto benchmark
Add crypto benchmark - A tool to help the users quickly get the performance of a algorithm registered in crypto.
The tool tries to use the same API to unify the processes of different algorithms. The algorithm can do some private operations in the callbacks. For users, they can see the unified configuration parameters, rather than a set of configuration parameters corresponding to each algorithm.
This tool can provide users with the ability to test the performance of algorithms in some specific scenarios. At present, the following parameters are selected for users configuration: block size, block number, thread number, bound numa and request number for per tfm. These parameters can help users simulate approximate business scenarios.
For the RFC version, the compression benchmark test is supported. I did some verification on Kunpeng920.
The first test case is for zlib-deflate software algorithm. The cpu frequency is 2.6 GHz. I want to show you the influence of these parameters.
The configuration is following:
run set: algorithm zlib-deflate, algtype CRYPTO_COMPRESS, inputsize 1024, loop 1, numamask 0x0, optype 0, reqnum 1, threadnum 1, time 1. The result is :
Crypto benchmark result:
throughput pps time
150 MB/s 150 kPP/s 1000 msAnd then change the block size:
run set: algorithm zlib-deflate, algtype CRYPTO_COMPRESS, inputsize 8192, loop 1, numamask 0x0, optype 0, reqnum 1, threadnum 1, time 1. Crypto benchmark result:
throughput pps time
473 MB/s 59 kPP/s 1005 msrun set: algorithm zlib-deflate, algtype CRYPTO_COMPRESS, inputsize 65536, loop 1, numamask 0x0, optype 0, reqnum 1, threadnum 1, time 1. Crypto benchmark result:
throughput pps time
421 MB/s 6 kPP/s 1038 msWith the test, users can know that the throughput and pps are both influenced by block size on this server. And the throughput has a peak value while the pps is inverse ratio with bolck size increasing. Due to the software algorithm, thread number will linear increase the result while it is less than cpu number and other parameters have little influence on performance.
The second test case is for zlib-deflate hardware. The tested parameters has the same effect on hardware. Here I test the parameter 'reqnum'. The software algorithm register to synchronous process. So here it is useless for software performance.
run set: algorithm zlib-deflate, algtype CRYPTO_COMPRESS, inputsize 8192, loop 1, numamask 0x0, optype 0, reqnum 1, threadnum 1, time 1. Crypto benchmark result:
throughput pps time
367 MB/s 46 kPP/s 941 msrun set: algorithm zlib-deflate, algtype CRYPTO_COMPRESS, inputsize 8192, loop 1, numamask 0x0, optype 0, reqnum 10, threadnum 1, time 1. Crypto benchmark result:
throughput pps time
3507 MB/s 438 kPP/s 1003 msrun set: algorithm zlib-deflate, algtype CRYPTO_COMPRESS, inputsize 8192, loop 1, numamask 0x0, optype 0, reqnum 100, threadnum 1, time 1. Crypto benchmark result:
throughput pps time
6318 MB/s 790 kPP/s 1093 msSo we can know that for asynchronous algorithms, request number for per tfm also influence the throughput and pps until a peak value.
So with this tool, we can get a quick verification for different platform and get some reference for business scenarios configuration.
Yang Shen (6):
moduleparams: Add hexulong type parameter
crypto: benchmark - add a crypto benchmark tool
crytpo: benchmark - support compression/decompresssion
crypto: benchmark - add help information
crypto: benchmark - add API documentation
MAINTAINERS: add crypto benchmark MAINTAINER
Documentation/crypto/benchmark.rst | 104 +++++ MAINTAINERS | 7 + crypto/Kconfig | 2 + crypto/Makefile | 5 + crypto/benchmark/Kconfig | 11 + crypto/benchmark/Makefile | 3 + crypto/benchmark/benchmark.c | 599 +++++++++++++++++++++++++++++ crypto/benchmark/benchmark.h | 76 ++++ crypto/benchmark/bm_comp.c | 435 +++++++++++++++++++++ crypto/benchmark/bm_comp.h | 19 + include/linux/moduleparam.h | 7 +- kernel/params.c | 1 + 12 files changed, 1268 insertions(+), 1 deletion(-) create mode 100644 Documentation/crypto/benchmark.rst create mode 100644 crypto/benchmark/Kconfig create mode 100644 crypto/benchmark/Makefile create mode 100644 crypto/benchmark/benchmark.c create mode 100644 crypto/benchmark/benchmark.h create mode 100644 crypto/benchmark/bm_comp.c create mode 100644 crypto/benchmark/bm_comp.h
--
2.24.0
RFC PATCH 1/6 moduleparams: Add hexulong type parameter
Due to the bitmap.h uses a unsigned long pointer for bitmap variable, Add an 'hexulong' is more convenient.
--- include/linux/moduleparam.h | 7 ++++++- kernel/params.c | 1 + 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/moduleparam.h +6 -1
@@ -118,7 +118,7 @@ struct kparam_array* you can create your own by defining those variables. * * Standard types are: -* byte, hexint, short, ushort, int, uint, long, ulong +* byte, hexint, hexulong, short, ushort, int, uint, long, ulong * charp: a character pointer * bool: a bool, values 0/1, y/n, Y/N. * invbool: the above, only sense-reversed (N = true).
@@ -455,6 +455,11 @@ extern int param_set_hexint(const char *val, const struct kernel_param *kp);extern int param_get_hexint (char *buffer,const struct kernel_param *kp);#define param_check_hexint (name, p) param_check_uint(name, p) +extern const struct kernel_param_ops param_ops_hexulong; +extern int param_set_hexulong (const char *val,const struct kernel_param *kp); +extern int param_get_hexulong (char *buffer,const struct kernel_param *kp); +#define param_check_hexulong (name, p) param_check_ulong(name, p) +extern const struct kernel_param_ops param_ops_charp;extern int param_set_charp (const char *val,const struct kernel_param *kp);extern int param_get_charp (char *buffer,const struct kernel_param *kp);
kernel/params.c +1 -0
@@ -242,6 +242,7 @@ STANDARD_PARAM_DEF(long, long, "%li", kstrtol); STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", kstrtoul); STANDARD_PARAM_DEF(ullong, unsigned long long, "%llu", kstrtoull); STANDARD_PARAM_DEF(hexint, unsigned int, "%#08x", kstrtouint); +STANDARD_PARAM_DEF(hexulong, unsigned long, "%#016lx", kstrtoul);int param_set_uint_minmax (const char *val,const struct kernel_param *kp,unsigned int min,unsigned int max)
Signature · 1 line
2.24.0
RFC PATCH 2/6 crypto: benchmark - add a crypto benchmark tool
In reply to Yang ShenProvide a crypto benchmark to help the developer quickly get the performance of a algorithm registered in crypto.
Due to the crypto algorithms have multifarious parameters, the tool cannot support all test scenes. In order to provide users with simple and easy-to-use tools and support as many test scenarios as possible, benchmark refers to the crypto method to provide a unified struct 'crypto_bm_ops'. And the algorithm registers its own callbacks to parse the user's input. In crypto, a algorithm class has multiple algorithms, but all of them uses the same API. So in the benchmark, a algorithm class uses the same 'ops' and distinguish specific algorithm by name.
First, consider the performance calculation model. Considering the crypto subsystem model, a reasonable process code based on crypto api should create a numa node based 'crypto_tfm' in advance and apply for a certain amount of 'crypto_req' according to their own business. In the real business processing stage, the thread send tasks based on 'crypto_req' and wait for completion.
Therefore, the benchmark will create 'crypto_tfm' and 'crypto_req' at first, and then count all requests time to calculate performance. So the result is the pure algorithm performance. When each algorithm class implements its own 'ops', it needs to pay attention to the content completed in the callback. Before the 'ops.perf', the tool had better prepare the request data set. And in order to avoid the false high performance of the algorithm caused by the false cache and TLB hit rate, the size of data set should be larger than 'crypto_req' number. The 'crypto_bm_ops' has following api:
- init & uninit
The initialize related functions. Algorithm can do some private setting.
- create_tfm & release_tfm
The 'crypto_tfm' related functions. Algorithm has different tfm name in crypto. But they both has a member named tfm, so use tfm to stand for algorithm handle. The benchmark has provides the tfm array.
- create_req & release_req
The 'crypto_req' related functions. The callbacks should create a 'reqnum' 'crypto_req' group in struct 'crypto_bm_base'. And the also suggest prepare the request data in this function. In order to avoid the false high performance of the algorithm caused by the false cache and TLB hit rate, the size of data set should be larger than 'crypto_req' number.
- perf
The request sending functions. The registrant should use parameter 'loop' to send requests repeatly. And update the count in struct 'crypto_bm_thread_data'.
Then consider the parameters that user can configure. Generally speaking, the following parameters will affect the performance of the algorithm:
tfm number, request number, block size, numa node. And some parameters will affect the stability of performance: testing time and requests sent number. To sum up, the benchmark has following parameters:
- algorithm
The testing algorithm name. Showed in /proc/crypto.
- algtype
The testing algorithm class. Can get the algorithm class by echo 'algtype' to /sys/module/crypto_benchmark/parameters/help.
- inputsize
The testing length that can greatly impact performance. Such as data size for compress or key length for encryption.
- loop
The testing loop times. Avoid performance fluctuations caused by environment.
- numamask
The testing bind numamask. Used for allocate memory, create threads and create 'crypto_tfm'.
- optype
The testing algorithm operation type. Can get the algorithm available operation types by cat /sys/module/crypto_benchmark/parameters/help with specified 'algtype'.
- reqnum
The testing request number for per tfm. Used for test asynchrony api performance.
- threadnum
The testing thread number. To simplify model, create a 'crypto_tfm' per thread.
- time
The testing time. Used for stop the test thread.
- run
Start or stop the test.
Users can configure parameters under /sys/modules/crypto_benchmark/parameters/.
Then echo 1 to 'run' to start the test. And if they want to stop the test, just echo 0 to 'run'.
--- crypto/Kconfig | 2 + crypto/Makefile | 5 + crypto/benchmark/Kconfig | 11 + crypto/benchmark/Makefile | 3 + crypto/benchmark/benchmark.c | 509 +++++++++++++++++++++++++++++++++++ crypto/benchmark/benchmark.h | 76 ++++++ 6 files changed, 606 insertions(+) create mode 100644 crypto/benchmark/Kconfig create mode 100644 crypto/benchmark/Makefile create mode 100644 crypto/benchmark/benchmark.c create mode 100644 crypto/benchmark/benchmark.h
crypto/Kconfig +2 -0
@@ -1438,4 +1438,6 @@ source "drivers/crypto/Kconfig" source "crypto/asymmetric_keys/Kconfig" source "certs/Kconfig" +source "crypto/benchmark/Kconfig" + endif # if CRYPTO
crypto/Makefile +5 -0
@@ -212,3 +212,8 @@ obj-$(CONFIG_CRYPTO_SIMD) += crypto_simd.o # Key derivation function # obj-$(CONFIG_CRYPTO_KDF800108_CTR) += kdf_sp800108.o + +# +# crypto benchmark +# +obj-y += benchmark/
crypto/benchmark/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 + +config CRYPTO_BENCHMARK + bool "Testing performance of crypto algorithms" + depends on CRYPTO + help + This option support test crypto async api performance. + Select this if you want to test crypto algorithms performance + conveniently. + Before use it, you should check whether the algorithm class is + supported.
crypto/benchmark/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_CRYPTO_BENCHMARK) += crypto_benchmark.o +crypto_benchmark-objs += benchmark.o
crypto/benchmark/benchmark.c new file +509 -0
509 lines not on this page · raw message
crypto/benchmark/benchmark.h new file +76 -0
76 lines not on this page · raw message
--
2.24.0
Re: [RFC PATCH 2/6] crypto: benchmark - add a crypto benchmark tool
Quoted 79 lines · Yang Shen
Provide a crypto benchmark to help the developer quickly get the performance of a algorithm registered in crypto.
Due to the crypto algorithms have multifarious parameters, the tool cannot support all test scenes. In order to provide users with simple and easy-to-use tools and support as many test scenarios as possible, benchmark refers to the crypto method to provide a unified struct '
crypto_bm_ops'. And the algorithm registers its own callbacks to parse the user's input. In crypto, a algorithm class has multiple algorithms, but all of them uses the same API. So in the benchmark, a algorithm class uses the same 'ops' and distinguish specific algorithm by name.First, consider the performance calculation model. Considering the crypto subsystem model, a reasonable process code based on crypto api should create a numa node based '
crypto_tfm' in advance and apply for a certain amount of 'crypto_req' according to their own business. In the real business processing stage, the thread send tasks based on 'crypto_req' and wait for completion.Therefore, the benchmark will create '
crypto_tfm' and 'crypto_req' at first, and then count all requests time to calculate performance. So the result is the pure algorithm performance. When each algorithm class implements its own 'ops', it needs to pay attention to the content completed in the callback. Before the 'ops.perf', the tool had better prepare the request data set. And in order to avoid the false high performance of the algorithm caused by the false cache and TLB hit rate, the size of data set should be larger than 'crypto_req' number. The 'crypto_bm_ops' has following api:
- init & uninit
The initialize related functions. Algorithm can do some private setting.
-create_tfm&release_tfm
The 'crypto_tfm' related functions. Algorithm has different tfm name in crypto. But they both has a member named tfm, so use tfm to stand for algorithm handle. The benchmark has provides the tfm array.
-create_req&release_req
The 'crypto_req' related functions. The callbacks should create a 'reqnum' 'crypto_req' group in struct 'crypto_bm_base'. And the also suggest prepare the request data in this function. In order to avoid the false high performance of the algorithm caused by the false cache and TLB hit rate, the size of data set should be larger than 'crypto_req' number.
- perf
The request sending functions. The registrant should use parameter 'loop' to send requests repeatly. And update the count in struct 'crypto_bm_thread_data'.Then consider the parameters that user can configure. Generally speaking, the following parameters will affect the performance of the algorithm:
tfm number, request number, block size, numa node. And some parameters will affect the stability of performance: testing time and requests sent number. To sum up, the benchmark has following parameters:
- algorithm
The testing algorithm name. Showed in/proc/crypto.
- algtype
The testing algorithm class. Can get the algorithm class by echo 'algtype' to/sys/module/crypto_benchmark/parameters/help.
- inputsize
The testing length that can greatly impact performance. Such as data size for compress or key length for encryption.
- loop
The testing loop times. Avoid performance fluctuations caused by environment.
- numamask
The testing bind numamask. Used for allocate memory, create threads and create 'crypto_tfm'.
- optype
The testing algorithm operation type. Can get the algorithm available operation types by cat/sys/module/crypto_benchmark/parameters/helpwith specified 'algtype'.
- reqnum
The testing request number for per tfm. Used for test asynchrony api performance.
- threadnum
The testing thread number. To simplify model, create a 'crypto_tfm' per thread.
- time
The testing time. Used for stop the test thread.
- run
Start or stop the test.
Quoted 2 lines
Users can configure parameters under
/sys/modules/crypto_benchmark/parameters/.
Please don't use module parameters for stuff like this, use configfs which was designed for this type of interactions.
thanks,
greg k-h
Re: [RFC PATCH 2/6] crypto: benchmark - add a crypto benchmark tool
Quoted 80 lines · Greg KH
Quoted 79 lines · Yang Shen
Provide a crypto benchmark to help the developer quickly get the performance of a algorithm registered in crypto.
Due to the crypto algorithms have multifarious parameters, the tool cannot support all test scenes. In order to provide users with simple and easy-to-use tools and support as many test scenarios as possible, benchmark refers to the crypto method to provide a unified struct '
crypto_bm_ops'. And the algorithm registers its own callbacks to parse the user's input. In crypto, a algorithm class has multiple algorithms, but all of them uses the same API. So in the benchmark, a algorithm class uses the same 'ops' and distinguish specific algorithm by name.First, consider the performance calculation model. Considering the crypto subsystem model, a reasonable process code based on crypto api should create a numa node based '
crypto_tfm' in advance and apply for a certain amount of 'crypto_req' according to their own business. In the real business processing stage, the thread send tasks based on 'crypto_req' and wait for completion.Therefore, the benchmark will create '
crypto_tfm' and 'crypto_req' at first, and then count all requests time to calculate performance. So the result is the pure algorithm performance. When each algorithm class implements its own 'ops', it needs to pay attention to the content completed in the callback. Before the 'ops.perf', the tool had better prepare the request data set. And in order to avoid the false high performance of the algorithm caused by the false cache and TLB hit rate, the size of data set should be larger than 'crypto_req' number. The 'crypto_bm_ops' has following api:
- init & uninit
The initialize related functions. Algorithm can do some private setting.
-create_tfm&release_tfm
The 'crypto_tfm' related functions. Algorithm has different tfm name in crypto. But they both has a member named tfm, so use tfm to stand for algorithm handle. The benchmark has provides the tfm array.
-create_req&release_req
The 'crypto_req' related functions. The callbacks should create a 'reqnum' 'crypto_req' group in struct 'crypto_bm_base'. And the also suggest prepare the request data in this function. In order to avoid the false high performance of the algorithm caused by the false cache and TLB hit rate, the size of data set should be larger than 'crypto_req' number.
- perf
The request sending functions. The registrant should use parameter 'loop' to send requests repeatly. And update the count in struct 'crypto_bm_thread_data'.Then consider the parameters that user can configure. Generally speaking, the following parameters will affect the performance of the algorithm:
tfm number, request number, block size, numa node. And some parameters will affect the stability of performance: testing time and requests sent number. To sum up, the benchmark has following parameters:
- algorithm
The testing algorithm name. Showed in/proc/crypto.
- algtype
The testing algorithm class. Can get the algorithm class by echo 'algtype' to/sys/module/crypto_benchmark/parameters/help.
- inputsize
The testing length that can greatly impact performance. Such as data size for compress or key length for encryption.
- loop
The testing loop times. Avoid performance fluctuations caused by environment.
- numamask
The testing bind numamask. Used for allocate memory, create threads and create 'crypto_tfm'.
- optype
The testing algorithm operation type. Can get the algorithm available operation types by cat/sys/module/crypto_benchmark/parameters/helpwith specified 'algtype'.
- reqnum
The testing request number for per tfm. Used for test asynchrony api performance.
- threadnum
The testing thread number. To simplify model, create a 'crypto_tfm' per thread.
- time
The testing time. Used for stop the test thread.
- run
Start or stop the test.
Quoted 8 lines
Quoted 2 lines
Users can configure parameters under
/sys/modules/crypto_benchmark/parameters/.Please don't use module parameters for stuff like this, use configfs which was designed for this type of interactions.
thanks,
greg k-h
Got it!
Thanks,
Yang
RFC PATCH 3/6 crytpo: benchmark - support compression/decompresssion
In reply to Yang ShenRegister compression algorithms to crypto benchmark. Users can echo 0 to 'algtype' to appoint the compression/decompression.
Due to the compression protocol, the tool cannot set the compressed data length to 'inputsize'. So in this algorithm class, the 'inputsize' is used as origin data size in decompression.
To avoid the false high performance of the algorithm caused by the false cache and TLB hit rate, the size of data set is four times of crypto_req number at most.
--- crypto/benchmark/Makefile | 2 +- crypto/benchmark/benchmark.c | 11 + crypto/benchmark/bm_comp.c | 425 +++++++++++++++++++++++++++++++++++ crypto/benchmark/bm_comp.h | 18 ++ 4 files changed, 455 insertions(+), 1 deletion(-) create mode 100644 crypto/benchmark/bm_comp.c create mode 100644 crypto/benchmark/bm_comp.h
crypto/benchmark/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_CRYPTO_BENCHMARK) += crypto_benchmark.o -crypto_benchmark-objs += benchmark.o +crypto_benchmark-objs += benchmark.o bm_comp.o
crypto/benchmark/benchmark.c +11 -0
@@ -11,6 +11,7 @@#include <linux/wait.h> #include "benchmark.h" +#include "bm_comp.h" enum crypto_bm_status {CRYPTO_BM_STOP ,
@@ -18,6 +19,7 @@ enum crypto_bm_status { };enum crypto_bm_alg { +CRYPTO_BM_COMP ,CRYPTO_BM_ALG_MAX , };
@@ -65,6 +67,15 @@ static struct task_struct *test_thread;static struct crypto_bm_alg_ops benchmark_ops[] = { { + .alg ="CRYPTO_COMPRESS" , + .init = crypto_bm_init_comp, + .uninit = crypto_bm_uninit_comp, + .create_tfm = crypto_bm_create_tfm_comp, + .release_tfm = crypto_bm_release_tfm_comp, + .create_req = crypto_bm_create_req_comp, + .release_req = crypto_bm_release_req_comp, + .perf = crypto_bm_perf_comp, + }, {/* sentinel */ } };
crypto/benchmark/bm_comp.c new file +425 -0
425 lines not on this page · raw message
crypto/benchmark/bm_comp.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2022 HiSilicon Limited. +*/ +#ifndef CRYPTO_BM_COMP_H +#define CRYPTO_BM_COMP_H + +#include <linux/types.h> + +int crypto_bm_init_comp (struct crypto_bm_base *base); +void crypto_bm_uninit_comp (struct crypto_bm_base *base); +int crypto_bm_create_tfm_comp (struct crypto_bm_base *base,u32 idx); +void crypto_bm_release_tfm_comp (struct crypto_bm_base *base,u32 idx); +int crypto_bm_create_req_comp (struct crypto_bm_base *base,u32 idx); +void crypto_bm_release_req_comp (struct crypto_bm_base *base,u32 idx); +int crypto_bm_perf_comp (struct crypto_bm_thread_data *data); + +#endif
--
2.24.0
RFC PATCH 4/6 crypto: benchmark - add help information
In reply to Yang ShenAdd a new module parameters 'help' to make users understand the benchmark module parameters. And due to the algorithms have different notes, add a new callback 'help' to show the differences.
--- crypto/benchmark/benchmark.c | 79 ++++++++++++++++++++++++++++++++++++ crypto/benchmark/bm_comp.c | 10 +++++ crypto/benchmark/bm_comp.h | 1 + 3 files changed, 90 insertions(+)
crypto/benchmark/benchmark.c +79 -0
@@ -32,6 +32,12 @@ struct crypto_bm_alg_ops {int (*create_req)(struct crypto_bm_base *base,u32 idx);void (*release_req)(struct crypto_bm_base *base,u32 idx);int (*perf)(struct crypto_bm_thread_data *data); +void (*help)(void ); +}; + +struct crypto_bm_mp_info { +const char *mp; +const char *help_info; };struct {
@@ -51,6 +57,9 @@ struct {#define threadnum_desc "Testing thread number, one 'crypto_tfm' per thread. 0/1 (default 1 thread), 2(2 threads) ..."#define time_desc "Testing time, the unit is second, 0/1 (default 1 s), 2(2 s) ..."#define run_desc "Start/stop all the tests based on the configuration, 0(default, not run, stop), or run" +#define help_desc "Some help information. Echo a module parameter can get the info " \ + "of module parameter. Cat 'help' directly can get the help "\ + "information provided by 'algtype'."static atomic_t benchmark_status;
@@ -75,11 +84,47 @@ static struct crypto_bm_alg_ops benchmark_ops[] = { .create_req = crypto_bm_create_req_comp, .release_req = crypto_bm_release_req_comp, .perf = crypto_bm_perf_comp, + .help = crypto_bm_help_comp, }, {/* sentinel */ } }; +static struct crypto_bm_mp_info modules_help[] = { + { + .mp ="algorithm" , + .help_info ="Please input a crypto supported algorithm name.\n" +"The algorithm name can be found on /proc/crypto." , + }, { + .mp ="algtype" , + .help_info ="Please input a valid value to choose algorithm class.\n" +"0: CRYPTO_BM_COMP" , + }, { + .mp ="inputsize" , + .help_info ="Please input a valid value as testing input size." , + }, { + .mp ="loop" , + .help_info ="Please input the send loop times." , + }, { + .mp ="numamask" , + .help_info ="Please input a bitmap as testing numa nodes." , + }, { + .mp ="optype" , + .help_info ="Please input a valid value for testing operation.\n" +"Can get the algorithm type support optype by cat 'help'." + }, { + .mp ="reqnum" , + .help_info ="Please input a valid value for per thread request number." , + }, { + .mp ="threadnum" , + .help_info ="Please input a valid value for creating threads.\n" +"One thread will create a crypto_tfm." , + }, { + .mp ="time" , + .help_info ="Please input a valid value for testing time." , + } +}; +static int crypto_bm_algorithm_param_set (const char *val,const struct kernel_param *kp) {char *s =strstrip ((char *)val);
@@ -103,6 +148,40 @@ static const struct kernel_param_ops alg_ops = {module_param_cb (algorithm, &alg_ops, &benchmark_attrs.algorithm,0644 );MODULE_PARM_DESC (algorithm, algorithm_desc); +static int crypto_bm_help_param_set (const char *val,const struct kernel_param *kp) +{ +int size =ARRAY_SIZE (modules_help); +char *s =strstrip ((char *)val); +int i; + +for (i =0 ; i < size; i++) { +if (!strcmp (s, modules_help[i].mp)) +pr_err ("%s\n" , modules_help[i].help_info); + } + +return 0 ; +} + +static int crypto_bm_help_param_get (char *val,const struct kernel_param *kp) +{ +u32 idx = benchmark_attrs.algtype; + +if (idx >=CRYPTO_BM_ALG_MAX ) +return -EINVAL ; + + benchmark_ops[idx].help (); + +return 0 ; +} + +static const struct kernel_param_ops help_ops = { + .set = crypto_bm_help_param_set, + .get = crypto_bm_help_param_get, +}; + +module_param_cb (help, &help_ops,NULL ,0644 ); +MODULE_PARM_DESC (help, help_desc); +static int crypto_bm_numamask_param_set (const char *val,const struct kernel_param *kp) {if (atomic_read (&benchmark_status))
crypto/benchmark/bm_comp.c +10 -0
@@ -423,3 +423,13 @@ int crypto_bm_perf_comp(struct crypto_bm_thread_data *data)return ret; } + +void crypto_bm_help_comp (void ) +{ +pr_err ("Welcome to use the crypto benchmark to test compress algorithm!\n" +"There ars some different moduel parameters requirement:\n" +"optype: 0 for compression, 1 for decompression\n" +"inputsize: for compression, the inputsize is src_len,\n" +" for decompression, the inputsize is dst_len, and the src_len will depend on the data compression ratio.\n" + ); +}
crypto/benchmark/bm_comp.h +1 -0
@@ -14,5 +14,6 @@ void crypto_bm_release_tfm_comp(struct crypto_bm_base *base, u32 idx);int crypto_bm_create_req_comp (struct crypto_bm_base *base,u32 idx);void crypto_bm_release_req_comp (struct crypto_bm_base *base,u32 idx);int crypto_bm_perf_comp (struct crypto_bm_thread_data *data); +void crypto_bm_help_comp (void );#endif
Signature · 1 line
2.24.0
RFC PATCH 5/6 crypto: benchmark - add API documentation
In reply to Yang ShenProvide a crypto benchmark to help the developer quickly get the performance of a crypto-registed algorithm.
To simulate more scenes, the tool has following parameters under '/sys/modules/crypto_benchmark/parameters/' to configure: algorithm, algtype, inputsize, loop, numamask, optype, reqnum, threadnum and time.
To shield the differences between different algorithms, the tool has following interface to do a crypto request: init, uninit, create_tfm, release_tfm, create_req, release_req, perf and help.
--- Documentation/crypto/benchmark.rst | 104 +++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Documentation/crypto/benchmark.rst
Documentation/crypto/benchmark.rst new file +104 -0
@@ -0,0 +1,104 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Crypto Benchmark +================ + +Overview +-------- +The crypto benchmark is a crypto algorithm performance tool. + +Designed Scheme +--------------- + +1. Parameters + +The crypto benchmark is used for test the algorithm registered in crypto +subsystem. Users can use module parameters to simulate different scenarios. +Both considering the test scenarios and the use complexity, the benchmark +tool has following module parameters: + +- algorithm +The 'algorithm' is used to create a 'crypto_tfm'. The right algorithm name +can be found in /proc/crypto. + +- algtype +The 'algtype' is used to find the operations of algorithm. Can get the +algorithm class by echo 'algtype' to +/sys/module/crypto_benchmark/parameters/help. + +- inputsize +The 'inputsize' is used as testing inputsize, outputsize will be set +according to algorithm. + +- loop +The 'loop' is used as times to try to send request for one 'crypto_req'. +Avoid performance fluctuations caused by environment. +For synchronization mode, the loop times is equal to send times. +But for asynchronization, the send times is often less than loop times. + +- numamask +The 'numamask' is used as testing binding numa nodes. The input will be +analyzed as a bitmap. + +- optype +The 'optype' is used for choose algorithm operation function. Can get the +algorithm available operation types by cat +/sys/module/crypto_benchmark/parameters/help with specified 'algtype'. +For example, choose the compress and decompress when test crypto comp. + +- reqnum +The 'reqnum' is used as requests number of a crypto tfm. For asynchronization, +one thread may used plural 'crypto_req' to improve performance. One request +a thread is a synchronous model + +- threadnum +The 'threadnum' is used for creating testing threads. To simplify model, +create a 'crypto_tfm' per thread. Notice that all threads will be divided +equally to the specified NUMA node, and threads that cannot be divided +equally will be created on the last node. + +- time +The 'time' is used for testing. Used for stop the test thread. If the time +is not enough, the thread will send another group loop times requests. + +- run +The 'run' is used to trigger the test. Echo 0 for stop all test threads, +and others for starting test. + +- help +The 'help' is used to guide users to use the test interface. Echo a module +parameter name to 'help' can get the detailed information. Cat the 'help' +can get some private information according to 'algtype'. + +2. Register + +There are too many differences between crypto algorithms. Therefore, the +crypto benchmark only completes the general work. All the different parts +are put into the callback of the algorithm to complete. The usual crypto +task can be divided into three parts: alloc tfm, alloc request, and send +request. + +A new algorithm class want to register to crypto benchmark should realize +following callbacks: + +- init & uninit +The initialize related functions. Algorithm can do some private setting. + +- create_tfm & release_tfm +The crypto_tfm related functions. Algorithm has different tfm name. +But they both has a member named tfm, so use tfm to stand for algorithm +handle. The benchmark has provides the tfm array. + +- create_req & release_req +The crypto_req related functions. The registrant should create a 'reqnum' +'crypto_req' group in struct 'crypto_bm_base'. And the also suggest +prepare the request data in this function. To simulate real cache and TLB +hit rate, using a big data groups is a good plan. + +- perf +The request sending functions. The registrant should use parameter 'loop' +to send requests repeatly. And update the count in struct +'crypto_bm_thread_data'. + +- help +The algorithm private parameters meaning functions.
Signature · 1 line
2.24.0
RFC PATCH 6/6 MAINTAINERS: add crypto benchmark MAINTAINER
In reply to Yang ShenAdd the maintainer information for the crypto benchmark.
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -5445,6 +5445,13 @@ F: include/crypto/ F: include/linux/crypto* F: lib/crypto/ +CRYPTO BENCHMARK TOOL +M: Yang Shen <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/crypto/benchmark.rst +F: crypto/benchmark/ + CRYPTOGRAPHIC RANDOM NUMBER GENERATOR M: Neil Horman <[email protected]> L: [email protected]
Signature · 1 line
2.24.0
Herbert Xu
maintainerQuoted 2 lines · Yang Shen
Add crypto benchmark - A tool to help the users quickly get the performance of a algorithm registered in crypto.
Please explain how this relates to the existing speed testing functionality in tcrypt.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 7 lines · Herbert Xu
Quoted 2 lines · Yang Shen
Add crypto benchmark - A tool to help the users quickly get the performance of a algorithm registered in crypto.
Please explain how this relates to the existing speed testing functionality in tcrypt.
Thanks,
In fact, the purpose for I is to get a crypto benchmark tool which is customizable and easy to called. For example, I test the hardware performance every rc1 to check whether the modification of the common module affects it. For me, I need to test the mutil threads, mutil numas, mutil requests of one tfm and so on. These test cases are used to simulate some service scenarios. And in these cases, I can find if any common module apply a patch that has an impact on us.
I know the tcrypt.ko has the speed test cases. But the tcrypt.ko test case is fixed. If I understand correctly, the design model of tcrypt.ko is test the algorithms with determined case conditions. It can provide some standardized testing to ensure that the implementation of the algorithm meets the requirements. This is a reasonable developer test tool, but it is not flexible enough for testers and users.
There are two main reasons for this:
1> For testers, the performance is not only related to algorithms and algorithm configurations. Many configurations may have obvious effect on performance which are not provided on tcrypt.ko. Of course, this problem can fix by add these as module parameters.
2> For users, a friendly tool is that they can use the tool directly rather to need to watch the source code to know how to use it. In tcrypt.ko, users need to get the 'mode' number of case they want to test if exist.
So this tool's original intention is to allow users test more complex scenarios and get the parameters usage directly.
If I have any misunderstanding about tcrypt.ko, please correct me. And I'll try to use the tcrytp.ko to meet my request.
Thanks,
Yang
Herbert Xu
maintainerQuoted 10 lines · Yang Shen
I know the tcrypt.ko has the speed test cases. But the tcrypt.ko test case is fixed.
If I understand correctly, the design model of tcrypt.ko is test the algorithms with
determined case conditions. It can provide some standardized testing to ensure
that the implementation of the algorithm meets the requirements. This is a reasonable developer test tool, but it is not flexible enough for testers and users.
How about improving tcrypt then? We're not going to have two things in the kernel that do the same thing unless you provide a clear path of eliminating one of them.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 10 lines · Herbert Xu
Quoted 9 lines · Yang Shen
I know the tcrypt.ko has the speed test cases. But the tcrypt.ko test case is fixed.
If I understand correctly, the design model of tcrypt.ko is test the algorithms with
determined case conditions. It can provide some standardized testing to ensure
that the implementation of the algorithm meets the requirements. This is a reasonable developer test tool, but it is not flexible enough for testers and users.
Quoted 5 lines
How about improving tcrypt then? We're not going to have two things in the kernel that do the same thing unless you provide a clear path of eliminating one of them.
Cheers,
Got it. I'll try to support this on the tcrypt.
Thanks,
Yang
Herbert Xu
maintainerQuoted 2 lines · Yang Shen
Got it. I'll try to support this on the tcrypt.
Before you get too far into this, please note that I have no preference as to whether you go with tcrypt or your new benchmark code.
My only requirement is that we pick one mechanism.
But obivously others might have a preference so you should try to produce RFCs as early as possible.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt