qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio
at master 114 lines 3.1 kB view raw
1/* 2 * QEMU Crypto hash speed benchmark 3 * 4 * Copyright (c) 2017 HUAWEI TECHNOLOGIES CO., LTD. 5 * 6 * Authors: 7 * Longpeng(Mike) <longpeng2@huawei.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2 or 10 * (at your option) any later version. See the COPYING file in the 11 * top-level directory. 12 */ 13#include "qemu/osdep.h" 14#include "qemu/units.h" 15#include "crypto/init.h" 16#include "crypto/hash.h" 17 18typedef struct QCryptoHashOpts { 19 size_t chunk_size; 20 QCryptoHashAlgorithm alg; 21} QCryptoHashOpts; 22 23static void test_hash_speed(const void *opaque) 24{ 25 const QCryptoHashOpts *opts = opaque; 26 uint8_t *in = NULL, *out = NULL; 27 size_t out_len = 0; 28 const size_t total = 2 * GiB; 29 size_t remain; 30 struct iovec iov; 31 int ret; 32 33 in = g_new0(uint8_t, opts->chunk_size); 34 memset(in, g_test_rand_int(), opts->chunk_size); 35 36 iov.iov_base = (char *)in; 37 iov.iov_len = opts->chunk_size; 38 39 g_test_timer_start(); 40 remain = total; 41 while (remain) { 42 ret = qcrypto_hash_bytesv(opts->alg, 43 &iov, 1, &out, &out_len, 44 NULL); 45 g_assert(ret == 0); 46 47 remain -= opts->chunk_size; 48 } 49 g_test_timer_elapsed(); 50 51 g_print("%.2f MB/sec ", (double)total / MiB / g_test_timer_last()); 52 53 g_free(out); 54 g_free(in); 55} 56 57int main(int argc, char **argv) 58{ 59 char name[64]; 60 61 g_test_init(&argc, &argv, NULL); 62 g_assert(qcrypto_init(NULL) == 0); 63 64#define TEST_ONE(a, c) \ 65 QCryptoHashOpts opts ## a ## c = { \ 66 .alg = QCRYPTO_HASH_ALG_ ## a, .chunk_size = c, \ 67 }; \ 68 memset(name, 0 , sizeof(name)); \ 69 snprintf(name, sizeof(name), \ 70 "/crypto/benchmark/hash/%s/bufsize-%d", \ 71 QCryptoHashAlgorithm_str(QCRYPTO_HASH_ALG_ ## a), \ 72 c); \ 73 if (qcrypto_hash_supports(QCRYPTO_HASH_ALG_ ## a)) \ 74 g_test_add_data_func(name, \ 75 &opts ## a ## c, \ 76 test_hash_speed); 77 78 TEST_ONE(MD5, 512); 79 TEST_ONE(MD5, 1024); 80 TEST_ONE(MD5, 4096); 81 TEST_ONE(MD5, 16384); 82 83 TEST_ONE(SHA1, 512); 84 TEST_ONE(SHA1, 1024); 85 TEST_ONE(SHA1, 4096); 86 TEST_ONE(SHA1, 16384); 87 88 TEST_ONE(SHA224, 512); 89 TEST_ONE(SHA224, 1024); 90 TEST_ONE(SHA224, 4096); 91 TEST_ONE(SHA224, 16384); 92 93 TEST_ONE(SHA384, 512); 94 TEST_ONE(SHA384, 1024); 95 TEST_ONE(SHA384, 4096); 96 TEST_ONE(SHA384, 16384); 97 98 TEST_ONE(SHA256, 512); 99 TEST_ONE(SHA256, 1024); 100 TEST_ONE(SHA256, 4096); 101 TEST_ONE(SHA256, 16384); 102 103 TEST_ONE(SHA512, 512); 104 TEST_ONE(SHA512, 1024); 105 TEST_ONE(SHA512, 4096); 106 TEST_ONE(SHA512, 16384); 107 108 TEST_ONE(RIPEMD160, 512); 109 TEST_ONE(RIPEMD160, 1024); 110 TEST_ONE(RIPEMD160, 4096); 111 TEST_ONE(RIPEMD160, 16384); 112 113 return g_test_run(); 114}