tools/crypto/tcrypt/tcrypt_speed_compare.py

Source file repositories/reference/linux-study-clean/tools/crypto/tcrypt/tcrypt_speed_compare.py

File Facts

System
Linux kernel
Corpus path
tools/crypto/tcrypt/tcrypt_speed_compare.py
Extension
.py
Size
5831 bytes
Lines
191
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (C) xFusion Digital Technologies Co., Ltd., 2023
#
# Author: Wang Jinchao <wangjinchao@xfusion.com>
#
"""
A tool for comparing tcrypt speed test logs.

Please note that for such a comparison, stability depends
on whether we allow frequency to float or pin the frequency.

Both support tests for operations within one second and
cycles of operation.
For example, use it in the bash script below.

```bash
#!/bin/bash

# log file prefix
seq_num=0

# When sec=0, it will perform cycle tests;
# otherwise, it indicates the duration of a single test
sec=0
num_mb=8
mode=211

# base speed test
lsmod | grep pcrypt && modprobe -r pcrypt
dmesg -C
modprobe tcrypt alg="pcrypt(rfc4106(gcm(aes)))" type=3
modprobe tcrypt mode=${mode} sec=${sec} num_mb=${num_mb}
dmesg > ${seq_num}_base_dmesg.log

# new speed test
lsmod | grep pcrypt && modprobe -r pcrypt
dmesg -C
modprobe tcrypt alg="pcrypt(rfc4106(gcm(aes)))" type=3
modprobe tcrypt mode=${mode} sec=${sec} num_mb=${num_mb}
dmesg > ${seq_num}_new_dmesg.log
lsmod | grep pcrypt && modprobe -r pcrypt

tools/crypto/tcrypt/tcrypt_speed_compare.py \
    ${seq_num}_base_dmesg.log \
    ${seq_num}_new_dmesg.log  \
        >${seq_num}_compare.log
grep 'average' -A2 -B0 --group-separator="" ${seq_num}_compare.log
```
"""

import sys
import re


def parse_title(line):
    pattern = r'tcrypt: testing speed of (.*?) (encryption|decryption)'
    match = re.search(pattern, line)
    if match:
        alg = match.group(1)
        op = match.group(2)
        return alg, op
    else:
        return "", ""


def parse_item(line):
    pattern_operations = r'\((\d+) bit key, (\d+) byte blocks\): (\d+) operations'
    pattern_cycles = r'\((\d+) bit key, (\d+) byte blocks\): 1 operation in (\d+) cycles'

Annotation

Implementation Notes