From nobody Sat Dec 27 17:03:02 2025 Received: from wxsgout04.xfusion.com (wxsgout04.xfusion.com [36.139.87.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74BAB3A1B7; Mon, 18 Dec 2023 13:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xfusion.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xfusion.com Received: from wuxshcsitd00600.xfusion.com (unknown [10.32.133.213]) by wxsgout04.xfusion.com (SkyGuard) with ESMTPS id 4Sv0Zm32HmzB1CfX; Mon, 18 Dec 2023 21:11:28 +0800 (CST) Received: from localhost (10.82.147.3) by wuxshcsitd00600.xfusion.com (10.32.133.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 18 Dec 2023 21:15:01 +0800 Date: Mon, 18 Dec 2023 21:15:01 +0800 From: WangJinchao To: Herbert Xu , "David S. Miller" , Tim Chen , , CC: , Subject: [PATCH v2] crypto:tcrypt: add script tcrypt_speed_compare.py Message-ID: <202312182113+0800-wangjinchao@xfusion.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-ClientProxiedBy: wuxshcsitd00602.xfusion.com (10.32.132.250) To wuxshcsitd00600.xfusion.com (10.32.133.213) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Create a script for comparing tcrypt speed test logs. The script will systematically analyze differences item by item and provide a summary (average). This tool is useful for evaluating the stability of cryptographic module algorithms and assisting with performance optimization. Please note that for such a comparison, stability depends on whether we allow frequency to float or pin the frequency. The script produces comparisons in two scenes: 1. For operations in seconds =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D rfc4106(gcm(aes)) (pcrypt(rfc4106(gcm_base(ctr(aes-generic),ghash-generic))= )) encryption ---------------------------------------------------------------------------= ----- bit key | byte blocks | base ops | new ops | differ(%) 160 | 16 | 66439 | 63063 | -5.08 160 | 64 | 62220 | 57439 | -7.68 ... 288 | 4096 | 15059 | 16278 | 8.09 288 | 8192 | 9043 | 9526 | 5.34 ---------------------------------------------------------------------------= ----- average differ(%s) | total_differ(%) ---------------------------------------------------------------------------= ----- 5.70 | -4.49 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D 2. For avg cycles of operation =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D rfc4106(gcm(aes)) (pcrypt(rfc4106(gcm_base(ctr(aes-generic),ghash-generic))= )) encryption ---------------------------------------------------------------------------= ----- bit key | byte blocks | base cycles | new cycles | differ(%) 160 | 16 | 32500 | 35847 | 10.3 160 | 64 | 33175 | 45808 | 38.08 ... 288 | 4096 | 131369 | 132132 | 0.58 288 | 8192 | 229503 | 234581 | 2.21 ---------------------------------------------------------------------------= ----- average differ(%s) | total_differ(%) ---------------------------------------------------------------------------= ----- 8.41 | -6.70 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D Signed-off-by: WangJinchao --- MAINTAINERS | 6 + tools/crypto/tcrypt/tcrypt_speed_compare.py | 190 ++++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100755 tools/crypto/tcrypt/tcrypt_speed_compare.py diff --git a/MAINTAINERS b/MAINTAINERS index bba17f97eda7..b9c8dd607bce 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5524,6 +5524,12 @@ F: include/crypto/ F: include/linux/crypto* F: lib/crypto/ =20 +CRYPTO SPEED TEST COMPARE +M: Wang Jinchao +L: linux-crypto@vger.kernel.org +S: Maintained +F: tools/crypto/tcrypt/tcrypt_speed_compare.py + CRYPTOGRAPHIC RANDOM NUMBER GENERATOR M: Neil Horman L: linux-crypto@vger.kernel.org diff --git a/tools/crypto/tcrypt/tcrypt_speed_compare.py b/tools/crypto/tcr= ypt/tcrypt_speed_compare.py new file mode 100755 index 000000000000..f3f5783cdc06 --- /dev/null +++ b/tools/crypto/tcrypt/tcrypt_speed_compare.py @@ -0,0 +1,190 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) xFusion Digital Technologies Co., Ltd., 2023 +# +# Author: Wang Jinchao +# +""" +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=3D0 + +# When sec=3D0, it will perform cycle tests; +# otherwise, it indicates the duration of a single test +sec=3D0 +num_mb=3D8 +mode=3D211 + +# base speed test +lsmod | grep pcrypt && modprobe -r pcrypt +dmesg -C +modprobe tcrypt alg=3D"pcrypt(rfc4106(gcm(aes)))" type=3D3 +modprobe tcrypt mode=3D${mode} sec=3D${sec} num_mb=3D${num_mb} +dmesg > ${seq_num}_base_dmesg.log + +# new speed test +lsmod | grep pcrypt && modprobe -r pcrypt +dmesg -C +modprobe tcrypt alg=3D"pcrypt(rfc4106(gcm(aes)))" type=3D3 +modprobe tcrypt mode=3D${mode} sec=3D${sec} num_mb=3D${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=3D"" ${seq_num}_compare.log +``` +""" + +import sys +import re + + +def parse_title(line): + pattern =3D r'tcrypt: testing speed of (.*?) (encryption|decryption)' + match =3D re.search(pattern, line) + if match: + alg =3D match.group(1) + op =3D match.group(2) + return alg, op + else: + return "", "" + + +def parse_item(line): + pattern_operations =3D r'\((\d+) bit key, (\d+) byte blocks\): (\d+) o= perations' + pattern_cycles =3D r'\((\d+) bit key, (\d+) byte blocks\): 1 operation= in (\d+) cycles' + match =3D re.search(pattern_operations, line) + if match: + res =3D { + "bit_key": int(match.group(1)), + "byte_blocks": int(match.group(2)), + "operations": int(match.group(3)), + } + return res + + match =3D re.search(pattern_cycles, line) + if match: + res =3D { + "bit_key": int(match.group(1)), + "byte_blocks": int(match.group(2)), + "cycles": int(match.group(3)), + } + return res + + return None + + +def parse(filepath): + result =3D {} + alg, op =3D "", "" + with open(filepath, 'r') as file: + for line in file: + if not line: + continue + _alg, _op =3D parse_title(line) + if _alg: + alg, op =3D _alg, _op + if alg not in result: + result[alg] =3D {} + if op not in result[alg]: + result[alg][op] =3D [] + continue + parsed_result =3D parse_item(line) + if parsed_result: + result[alg][op].append(parsed_result) + return result + + +def merge(base, new): + merged =3D {} + for alg in base.keys(): + merged[alg] =3D {} + for op in base[alg].keys(): + if op not in merged[alg]: + merged[alg][op] =3D [] + for index in range(len(base[alg][op])): + merged_item =3D { + "bit_key": base[alg][op][index]["bit_key"], + "byte_blocks": base[alg][op][index]["byte_blocks"], + } + if "operations" in base[alg][op][index].keys(): + merged_item["base_ops"] =3D base[alg][op][index]["oper= ations"] + merged_item["new_ops"] =3D new[alg][op][index]["operat= ions"] + else: + merged_item["base_cycles"] =3D base[alg][op][index]["c= ycles"] + merged_item["new_cycles"] =3D new[alg][op][index]["cyc= les"] + + merged[alg][op].append(merged_item) + return merged + + +def format(merged): + for alg in merged.keys(): + for op in merged[alg].keys(): + base_sum =3D 0 + new_sum =3D 0 + differ_sum =3D 0 + differ_cnt =3D 0 + print() + hlen =3D 80 + print("=3D"*hlen) + print(f"{alg}") + print(f"{' '*(len(alg)//3) + op}") + print("-"*hlen) + key =3D "" + if "base_ops" in merged[alg][op][0]: + key =3D "ops" + print(f"bit key | byte blocks | base ops | new ops = | differ(%)") + else: + key =3D "cycles" + print(f"bit key | byte blocks | base cycles | new cycles = | differ(%)") + for index in range(len(merged[alg][op])): + item =3D merged[alg][op][index] + base_cnt =3D item[f"base_{key}"] + new_cnt =3D item[f"new_{key}"] + base_sum +=3D base_cnt + new_sum +=3D new_cnt + differ =3D round((new_cnt - base_cnt)*100/base_cnt, 2) + differ_sum +=3D differ + differ_cnt +=3D 1 + bit_key =3D item["bit_key"] + byte_blocks =3D item["byte_blocks"] + print( + f"{bit_key:<7} | {byte_blocks:<11} | {base_cnt:<11} | = {new_cnt:<11} | {differ:<8}") + average_speed_up =3D "{:.2f}".format(differ_sum/differ_cnt) + ops_total_speed_up =3D "{:.2f}".format( + (base_sum - new_sum) * 100 / base_sum) + print('-'*hlen) + print(f"average differ(%s) | total_differ(%)") + print('-'*hlen) + print(f"{average_speed_up:<21} | {ops_total_speed_up:<10}") + print('=3D'*hlen) + + +def main(base_log, new_log): + base =3D parse(base_log) + new =3D parse(new_log) + merged =3D merge(base, new) + format(merged) + + +if __name__ =3D=3D "__main__": + if len(sys.argv) !=3D 3: + print(f"usage: {sys.argv[0]} base_log new_log") + exit(-1) + main(sys.argv[1], sys.argv[2]) --=20 2.40.0