Skip to contentSkip to conversation

How to benchmark kernel crypto performance?

Openvpn-devel Tony He 3 participants 6 messages Apr 2, 2022 – Apr 5, 2022

lore
Share & tools
lore

Tony He

author
#0 lore raw

Hi Antonio,

I am porting ovpn-dco to embedded ARMv8 device with hardware crypto engine. However the performance is not very good.
It's about 130-140Mbps. I expect more. The SDK already provides kernel CryptoAPI(CFI) interface to access the crypto engine.
I want to know if the crypto operation is the bottleneck. Do you know how to benchmark crypto performance in the kernel space? Any advice is welcome. Thank you!

Tony

author
#1 lore raw

Hi,

I used below ugly way to benchmark the performance roughly. In POC, confirmed the hardware crypto engine is the bottleneck and not very fast
for packet not over than 1500 bytes. Overhead is required for queuing the data to crypto engine and sending data back to kernel.

        ktime_get_real_ts64(&init_time);
        ret = crypto_wait_req(crypto_aead_encrypt(req), &wait);
        ktime_get_real_ts64(&comp_time);

        init_usecs  = (init_time.tv_sec * 1000 * 1000) +
(init_time.tv_nsec / 1000);
        comp_usecs  = (comp_time.tv_sec * 1000 * 1000) +
(comp_time.tv_nsec / 1000);
        delta_usecs += comp_usecs - init_usecs;

        total_size += skb->len - head_size;
        if(total_size > 100000000){
                mbits = total_size * 8;
                printk("total_size is %u bytes, time is %u, the rate
is %u\n", total_size, delta_usecs,  mbits/delta_usecs);
                total_size = 0;
                delta_usecs = 0;
        }

......
......
Tony

Quoted 12 lines · Tony He <[email protected]...> 于2022年4月2日周六 17:40写道:

Hi Antonio,

I am porting ovpn-dco to embedded ARMv8 device with hardware crypto engine. However the performance is not very good.
It's about 130-140Mbps. I expect more. The SDK already provides kernel CryptoAPI(CFI) interface to access the crypto engine.
I want to know if the crypto operation is the bottleneck. Do you know how to benchmark crypto performance in the kernel space? Any advice is welcome. Thank you!

Tony

#2 lore raw

Hey Tony,

Quoted 1 line · Tony He
Quoted 1 line

Any advice is welcome. Thank you!

Debugging/profiling the fast path is never easy, but your method is definitely a reasonable approach.

Glad you already found the bottleneck.

An alternative is using the perf kernel tool, which tells you the amount of time spent in the various routines.

Signature · 1 line
Antonio Quartulli
#3 lore raw
In reply to Tony He

hi Tony,

Quoted 10 lines · Tony He

Hi Antonio,

I am porting ovpn-dco to embedded ARMv8 device with hardware crypto engine. However the performance is not very good.
It's about 130-140Mbps. I expect more. The SDK already provides kernel CryptoAPI(CFI) interface to access the crypto engine.
I want to know if the crypto operation is the bottleneck. Do you know how to benchmark crypto performance in the kernel space? Any advice is welcome. Thank you!

a quick & dirty way to test the hardware crypto engine is to use the Linux cryptodev engine in combination with openssl ; it's a bit tricky to get it working but it *is* a nice way to test hardware crypto.

* https://github.com/cryptodev-linux/cryptodev-linux.git
* do a custom openssl build with
    ./Configure -DHAVE_CRYPTODEV -DUSE_CRYPTODEV_DIGESTS enable-engine enable-dso enable-devcryptoeng <platform>
* run openssl speed using
  ./openssl speed -elapsed -engine devcrypto -evp aes-128-cbc

and compare the results with "-engine devcrypto" removed.

HTH,

JJK

author
#4 lore raw

Hi JJK,

Yeah, I know this way, but there is still context switching in the kernel space and user space. I have been looking for a way
to benchmark in the kernel space. I expect there is a kernel module like below:

insmod benchmark.ko AES-256-GCM
(After it's done, this module will exit automatically)

Tony

Quoted 33 lines · Jan Just Keijser <[email protected]...> 于2022年4月5日周二 19:26写道:

hi Tony,

Quoted 10 lines · Tony He

Hi Antonio,

I am porting ovpn-dco to embedded ARMv8 device with hardware crypto engine. However the performance is not very good.
It's about 130-140Mbps. I expect more. The SDK already provides kernel CryptoAPI(CFI) interface to access the crypto engine.
I want to know if the crypto operation is the bottleneck. Do you know how to benchmark crypto performance in the kernel space? Any advice is welcome. Thank you!

a quick & dirty way to test the hardware crypto engine is to use the Linux cryptodev engine in combination with openssl ; it's a bit tricky to get it working but it *is* a nice way to test hardware crypto.

* https://github.com/cryptodev-linux/cryptodev-linux.git
* do a custom openssl build with
./Configure -DHAVE_CRYPTODEV -DUSE_CRYPTODEV_DIGESTS enable-engine
enable-dso enable-devcryptoeng <platform>
* run openssl speed using
./openssl speed -elapsed -engine devcrypto -evp aes-128-cbc

and compare the results with "-engine devcrypto" removed.

HTH,

JJK

#5 lore raw

Hi Tony,

Quoted 8 lines · Tony He

Hi JJK,

Yeah, I know this way, but there is still context switching in the kernel space and user space. I have been looking for a way
to benchmark in the kernel space. I expect there is a kernel module like below:

insmod benchmark.ko AES-256-GCM
(After it's done, this module will exit automatically)

that would be 'tcrypt' then, I guess ; on my Fedora boxen I have
#  modinfo tcrypt
filename: /lib/modules/5.16.18-100.fc34.x86_64/kernel/crypto/tcrypt.ko.xz
author:         James Morris <[email protected]...>
description:    Quick & dirty crypto testing module
[...]
parm:           alg:charp
parm:           type:uint
parm:           mask:uint
parm:           mode:int
parm:           sec:Length in seconds of speed tests (defaults to zero which uses CPU cycles instead) (uint) parm:           num_mb:Number of concurrent requests to be used in mb speed tests (defaults to 8) (uint) parm:           klen:Key length (defaults to 0) (uint)

cheers,

JJK

Quoted 33 lines
Quoted 32 lines · Jan Just Keijser <[email protected]...> 于2022年4月5日周二 19:26写道:

hi Tony,

Quoted 10 lines · Tony He

Hi Antonio,

I am porting ovpn-dco to embedded ARMv8 device with hardware crypto engine. However the performance is not very good.
It's about 130-140Mbps. I expect more. The SDK already provides kernel CryptoAPI(CFI) interface to access the crypto engine.
I want to know if the crypto operation is the bottleneck. Do you know how to benchmark crypto performance in the kernel space? Any advice is welcome. Thank you!

a quick & dirty way to test the hardware crypto engine is to use the Linux cryptodev engine in combination with openssl ; it's a bit tricky to get it working but it *is* a nice way to test hardware crypto.

* https://github.com/cryptodev-linux/cryptodev-linux.git
* do a custom openssl build with
./Configure -DHAVE_CRYPTODEV -DUSE_CRYPTODEV_DIGESTS enable-engine
enable-dso enable-devcryptoeng <platform>
* run openssl speed using
./openssl speed -elapsed -engine devcrypto -evp aes-128-cbc

and compare the results with "-engine devcrypto" removed.

HTH,

JJK