2 # SPDX-License-Identifier: GPL-2.0
4 # Copyright (C) xFusion Digital Technologies Co., Ltd., 2023
6 # Author: Wang Jinchao <wangjinchao@xfusion.com>
9 A tool for comparing tcrypt speed test logs.
11 Please note that for such a comparison, stability depends
12 on whether we allow frequency to float or pin the frequency.
14 Both support tests for operations within one second and
16 For example, use it in the bash script below.
24 # When sec=0, it will perform cycle tests;
25 # otherwise, it indicates the duration of a single test
31 lsmod | grep pcrypt && modprobe -r pcrypt
33 modprobe tcrypt alg="pcrypt(rfc4106(gcm(aes)))" type=3
34 modprobe tcrypt mode=${mode} sec=${sec} num_mb=${num_mb}
35 dmesg > ${seq_num}_base_dmesg.log
38 lsmod | grep pcrypt && modprobe -r pcrypt
40 modprobe tcrypt alg="pcrypt(rfc4106(gcm(aes)))" type=3
41 modprobe tcrypt mode=${mode} sec=${sec} num_mb=${num_mb}
42 dmesg > ${seq_num}_new_dmesg.log
43 lsmod | grep pcrypt && modprobe -r pcrypt
45 tools/crypto/tcrypt/tcrypt_speed_compare.py \
46 ${seq_num}_base_dmesg.log \
47 ${seq_num}_new_dmesg.log \
48 >${seq_num}_compare.log
49 grep 'average' -A2 -B0 --group-separator="" ${seq_num}_compare.log
57 def parse_title(line
):
58 pattern
= r
'tcrypt: testing speed of (.*?) (encryption|decryption)'
59 match
= re
.search(pattern
, line
)
69 pattern_operations
= r
'\((\d+) bit key, (\d+) byte blocks\): (\d+) operations'
70 pattern_cycles
= r
'\((\d+) bit key, (\d+) byte blocks\): 1 operation in (\d+) cycles'
71 match
= re
.search(pattern_operations
, line
)
74 "bit_key": int(match
.group(1)),
75 "byte_blocks": int(match
.group(2)),
76 "operations": int(match
.group(3)),
80 match
= re
.search(pattern_cycles
, line
)
83 "bit_key": int(match
.group(1)),
84 "byte_blocks": int(match
.group(2)),
85 "cycles": int(match
.group(3)),
95 with
open(filepath
, 'r') as file:
99 _alg
, _op
= parse_title(line
)
102 if alg
not in result
:
104 if op
not in result
[alg
]:
107 parsed_result
= parse_item(line
)
109 result
[alg
][op
].append(parsed_result
)
113 def merge(base
, new
):
115 for alg
in base
.keys():
117 for op
in base
[alg
].keys():
118 if op
not in merged
[alg
]:
120 for index
in range(len(base
[alg
][op
])):
122 "bit_key": base
[alg
][op
][index
]["bit_key"],
123 "byte_blocks": base
[alg
][op
][index
]["byte_blocks"],
125 if "operations" in base
[alg
][op
][index
].keys():
126 merged_item
["base_ops"] = base
[alg
][op
][index
]["operations"]
127 merged_item
["new_ops"] = new
[alg
][op
][index
]["operations"]
129 merged_item
["base_cycles"] = base
[alg
][op
][index
]["cycles"]
130 merged_item
["new_cycles"] = new
[alg
][op
][index
]["cycles"]
132 merged
[alg
][op
].append(merged_item
)
137 for alg
in merged
.keys():
138 for op
in merged
[alg
].keys():
147 print(f
"{' '*(len(alg)//3) + op}")
150 if "base_ops" in merged
[alg
][op
][0]:
152 print(f
"bit key | byte blocks | base ops | new ops | differ(%)")
155 print(f
"bit key | byte blocks | base cycles | new cycles | differ(%)")
156 for index
in range(len(merged
[alg
][op
])):
157 item
= merged
[alg
][op
][index
]
158 base_cnt
= item
[f
"base_{key}"]
159 new_cnt
= item
[f
"new_{key}"]
162 differ
= round((new_cnt
- base_cnt
)*100/base_cnt
, 2)
165 bit_key
= item
["bit_key"]
166 byte_blocks
= item
["byte_blocks"]
168 f
"{bit_key:<7} | {byte_blocks:<11} | {base_cnt:<11} | {new_cnt:<11} | {differ:<8}")
169 average_speed_up
= "{:.2f}".format(differ_sum
/differ_cnt
)
170 ops_total_speed_up
= "{:.2f}".format(
171 (base_sum
- new_sum
) * 100 / base_sum
)
173 print(f
"average differ(%s) | total_differ(%)")
175 print(f
"{average_speed_up:<21} | {ops_total_speed_up:<10}")
179 def main(base_log
, new_log
):
180 base
= parse(base_log
)
182 merged
= merge(base
, new
)
186 if __name__
== "__main__":
187 if len(sys
.argv
) != 3:
188 print(f
"usage: {sys.argv[0]} base_log new_log")
190 main(sys
.argv
[1], sys
.argv
[2])