mirror of https://github.com/openssl/tools
Compare commits
12 Commits
ce5718a68c
...
f584b9ec68
Author | SHA1 | Date |
---|---|---|
Neil Horman | f584b9ec68 | |
Neil Horman | cdd4959a97 | |
Neil Horman | 13fe31415f | |
Neil Horman | 4ca43da682 | |
Neil Horman | a4ccf92b25 | |
Neil Horman | 18ada4f639 | |
Neil Horman | 7b5e2edc8b | |
Neil Horman | 8a3e7cae16 | |
Neil Horman | 352d322c2c | |
Neil Horman | 291a580209 | |
Neil Horman | 3079057789 | |
Neil Horman | f6a78a269c |
|
@ -1,7 +1,7 @@
|
|||
all: randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall pemread
|
||||
all: randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall pemread rwlocks
|
||||
|
||||
clean:
|
||||
rm libperf.a *.o randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall pemread
|
||||
rm libperf.a *.o randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall pemread rwlocks
|
||||
|
||||
#-Wl,-rpath,$(TARGET_OSSL_LIBRARY_PATH)
|
||||
|
||||
|
@ -36,3 +36,6 @@ providerdoall: providerdoall.c libperf.a
|
|||
|
||||
pemread: pemread.c libperf.a
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o pemread pemread.c -lperf -lcrypto
|
||||
|
||||
rwlocks: rwlocks.c libperf.a
|
||||
gcc $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o rwlocks rwlocks.c -lperf -lcrypto
|
||||
|
|
|
@ -118,3 +118,11 @@ a memory BIO with a private RSA key. It does 100000 repetitions divided evenly
|
|||
among each thread. The number of threads to use is provided as an argument and
|
||||
the test reports the average time take to execute a block of 1000
|
||||
PEM_read_bio_PrivateKey() calls.
|
||||
|
||||
rwlocks
|
||||
-------------
|
||||
the rwlocks test creates the command line specified number of threads, splitting
|
||||
them evenly between read and write functions (though this is adjustable via the
|
||||
LOCK_WRITERS environment variable). Threads then iteratively acquire a shared
|
||||
rwlock to read or update some shared data. The number of read and write
|
||||
lock/unlock pairs are reported as a performance measurement
|
||||
|
|
|
@ -13,10 +13,9 @@
|
|||
#include <openssl/evp.h>
|
||||
#include "perflib/perflib.h"
|
||||
|
||||
#define NUM_CALLS_PER_BLOCK 1000
|
||||
#define NUM_CALL_BLOCKS_PER_RUN 100
|
||||
#define NUM_CALLS_PER_RUN (NUM_CALLS_PER_BLOCK * NUM_CALL_BLOCKS_PER_RUN)
|
||||
#define NUM_CALLS_PER_TEST 100000
|
||||
|
||||
OSSL_TIME *times;
|
||||
|
||||
int err = 0;
|
||||
|
||||
|
@ -32,8 +31,11 @@ void do_newrawkey(size_t num)
|
|||
{
|
||||
int i;
|
||||
EVP_PKEY *pkey;
|
||||
OSSL_TIME start, end;
|
||||
|
||||
for (i = 0; i < NUM_CALLS_PER_RUN / threadcount; i++) {
|
||||
start = ossl_time_now();
|
||||
|
||||
for (i = 0; i < NUM_CALLS_PER_TEST / threadcount; i++) {
|
||||
pkey = EVP_PKEY_new_raw_public_key_ex(NULL, "X25519", NULL, buf,
|
||||
sizeof(buf));
|
||||
if (pkey == NULL)
|
||||
|
@ -41,15 +43,20 @@ void do_newrawkey(size_t num)
|
|||
else
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
|
||||
end = ossl_time_now();
|
||||
times[num] = ossl_time_subtract(end, start);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
OSSL_TIME duration;
|
||||
uint64_t us;
|
||||
double avcalltime;
|
||||
OSSL_TIME us;
|
||||
double av;
|
||||
int terse = 0;
|
||||
int argnext;
|
||||
size_t i;
|
||||
int rc = EXIT_FAILURE;
|
||||
|
||||
if ((argc != 2 && argc != 3)
|
||||
|| (argc == 3 && strcmp("--terse", argv[1]) != 0)) {
|
||||
|
@ -70,25 +77,45 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
times = OPENSSL_malloc(sizeof(OSSL_TIME) * threadcount);
|
||||
if (times == NULL) {
|
||||
printf("Failed to create times array\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!perflib_run_multi_thread_test(do_newrawkey, threadcount, &duration)) {
|
||||
printf("Failed to run the test\n");
|
||||
return EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
printf("Error during test\n");
|
||||
return EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
us = ossl_time2us(duration);
|
||||
us = times[0];
|
||||
for (i = 1; i < threadcount; i++)
|
||||
us = ossl_time_add(us, times[i]);
|
||||
us = ossl_time_divide(us, NUM_CALLS_PER_TEST);
|
||||
|
||||
avcalltime = (double)us / NUM_CALL_BLOCKS_PER_RUN;
|
||||
/*
|
||||
* EVP_PKEY_new_raw_public_key is pretty fast, running in
|
||||
* only a few us. But ossl_time2us does integer division
|
||||
* and so because the average us computed above is less than
|
||||
* the value of OSSL_TIME_US, we wind up with truncation to
|
||||
* zero in the math. Instead, manually do the division, casting
|
||||
* our values as doubles so that we comput the proper time
|
||||
*/
|
||||
av = (double)ossl_time2ticks(us)/(double)OSSL_TIME_US;
|
||||
|
||||
if (terse)
|
||||
printf("%lf\n", avcalltime);
|
||||
printf("%lf\n", av);
|
||||
else
|
||||
printf("Average time per %d EVP_PKEY_new_raw_public_key_ex() calls: %lfus\n",
|
||||
NUM_CALLS_PER_BLOCK, avcalltime);
|
||||
printf("Average time per EVP_PKEY_new_raw_public_key_ex() call: %lfus\n",
|
||||
av);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
rc = EXIT_SUCCESS;
|
||||
out:
|
||||
OPENSSL_free(times);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -15,10 +15,9 @@
|
|||
#include <openssl/crypto.h>
|
||||
#include "perflib/perflib.h"
|
||||
|
||||
#define NUM_CALLS_PER_BLOCK 1000
|
||||
#define NUM_CALL_BLOCKS_PER_RUN 100
|
||||
#define NUM_CALLS_PER_RUN (NUM_CALLS_PER_BLOCK * NUM_CALL_BLOCKS_PER_RUN)
|
||||
#define NUM_CALLS_PER_TEST 100000
|
||||
|
||||
static OSSL_TIME *times = NULL;
|
||||
|
||||
int err = 0;
|
||||
|
||||
|
@ -44,6 +43,7 @@ void do_pemread(size_t num)
|
|||
int i;
|
||||
char *pemdata;
|
||||
size_t len;
|
||||
OSSL_TIME start, end;
|
||||
|
||||
pemdata = perflib_glue_strings(pemdataraw, &len);
|
||||
if (pemdata == NULL) {
|
||||
|
@ -59,11 +59,13 @@ void do_pemread(size_t num)
|
|||
return;
|
||||
}
|
||||
|
||||
start = ossl_time_now();
|
||||
|
||||
/*
|
||||
* Technically this includes the EVP_PKEY_free() in the timing - but I
|
||||
* think we can live with that
|
||||
*/
|
||||
for (i = 0; i < NUM_CALLS_PER_RUN / threadcount; i++) {
|
||||
for (i = 0; i < NUM_CALLS_PER_TEST / threadcount; i++) {
|
||||
key = PEM_read_bio_PrivateKey(pem, NULL, NULL, NULL);
|
||||
if (key == NULL) {
|
||||
printf("Failed to create key: %d\n", i);
|
||||
|
@ -75,16 +77,21 @@ void do_pemread(size_t num)
|
|||
BIO_reset(pem);
|
||||
}
|
||||
|
||||
end = ossl_time_now();
|
||||
times[num] = ossl_time_subtract(end, start);
|
||||
|
||||
BIO_free(pem);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
OSSL_TIME duration;
|
||||
uint64_t us;
|
||||
OSSL_TIME us;
|
||||
double avcalltime;
|
||||
int terse = 0;
|
||||
int argnext;
|
||||
int rc = EXIT_FAILURE;
|
||||
size_t i;
|
||||
|
||||
if ((argc != 2 && argc != 3)
|
||||
|| (argc == 3 && strcmp("--terse", argv[1]) != 0)) {
|
||||
|
@ -105,25 +112,37 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
times = OPENSSL_malloc(sizeof(OSSL_TIME) * threadcount);
|
||||
if (times == NULL) {
|
||||
printf("Failed to create times array\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!perflib_run_multi_thread_test(do_pemread, threadcount, &duration)) {
|
||||
printf("Failed to run the test\n");
|
||||
return EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
printf("Error during test\n");
|
||||
return EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
us = ossl_time2us(duration);
|
||||
us = times[0];
|
||||
for (i = 1; i < threadcount; i++)
|
||||
us = ossl_time_add(us, times[i]);
|
||||
us = ossl_time_divide(us, NUM_CALLS_PER_TEST);
|
||||
|
||||
avcalltime = (double)us / NUM_CALL_BLOCKS_PER_RUN;
|
||||
avcalltime = (double)ossl_time2ticks(us) / (double)OSSL_TIME_US;
|
||||
|
||||
if (terse)
|
||||
printf("%lf\n", avcalltime);
|
||||
else
|
||||
printf("Average time per %d PEM_read_bio_PrivateKey() calls: %lfus\n",
|
||||
NUM_CALLS_PER_BLOCK, avcalltime);
|
||||
printf("Average time per PEM_read_bio_PrivateKey() call: %lfus\n",
|
||||
avcalltime);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
rc = EXIT_SUCCESS;
|
||||
out:
|
||||
OPENSSL_free(times);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -15,9 +15,7 @@
|
|||
#include <openssl/provider.h>
|
||||
#include "perflib/perflib.h"
|
||||
|
||||
#define NUM_CALLS_PER_BLOCK 1000
|
||||
#define NUM_CALL_BLOCKS_PER_RUN 100
|
||||
#define NUM_CALLS_PER_RUN (NUM_CALLS_PER_BLOCK * NUM_CALL_BLOCKS_PER_RUN)
|
||||
#define NUM_CALLS_PER_TEST 100000
|
||||
|
||||
static int err = 0;
|
||||
OSSL_TIME *times;
|
||||
|
@ -41,7 +39,7 @@ static void do_providerdoall(size_t num)
|
|||
|
||||
start = ossl_time_now();
|
||||
|
||||
for (i = 0; i < NUM_CALLS_PER_RUN / threadcount; i++) {
|
||||
for (i = 0; i < NUM_CALLS_PER_TEST / threadcount; i++) {
|
||||
count = 0;
|
||||
if (!OSSL_PROVIDER_do_all(NULL, doit, &count) || count != 1) {
|
||||
err = 1;
|
||||
|
@ -50,15 +48,14 @@ static void do_providerdoall(size_t num)
|
|||
}
|
||||
|
||||
end = ossl_time_now();
|
||||
|
||||
times[num] = ossl_time_divide(ossl_time_subtract(end, start),
|
||||
NUM_CALL_BLOCKS_PER_RUN);
|
||||
times[num] = ossl_time_subtract(end, start);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
OSSL_TIME duration, av;
|
||||
OSSL_TIME duration, us;
|
||||
double av;
|
||||
int terse = 0;
|
||||
int argnext;
|
||||
int ret = EXIT_FAILURE;
|
||||
|
@ -98,15 +95,18 @@ int main(int argc, char *argv[])
|
|||
goto err;
|
||||
}
|
||||
|
||||
av = times[0];
|
||||
us = times[0];
|
||||
for (i = 1; i < threadcount; i++)
|
||||
av = ossl_time_add(av, times[i]);
|
||||
us = ossl_time_add(us, times[i]);
|
||||
us = ossl_time_divide(us, NUM_CALLS_PER_TEST);
|
||||
|
||||
av = (double)ossl_time2ticks(us) / (double)OSSL_TIME_US;
|
||||
|
||||
if (terse)
|
||||
printf("%ld\n", ossl_time2us(av));
|
||||
printf("%lf\n", av);
|
||||
else
|
||||
printf("Average time per %d OSSL_PROVIDER_do_all() calls: %ldus\n",
|
||||
NUM_CALLS_PER_BLOCK, ossl_time2us(av));
|
||||
printf("Average time per OSSL_PROVIDER_do_all() call: %lfus\n",
|
||||
av);
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
err:
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
#include <openssl/crypto.h>
|
||||
#include "perflib/perflib.h"
|
||||
|
||||
#define NUM_CALLS_PER_BLOCK 1000
|
||||
#define NUM_CALL_BLOCKS_PER_RUN 100
|
||||
#define NUM_CALLS_PER_RUN (NUM_CALLS_PER_BLOCK * NUM_CALL_BLOCKS_PER_RUN)
|
||||
#define NUM_CALLS_PER_TEST 100000
|
||||
|
||||
OSSL_TIME *times = NULL;
|
||||
|
||||
int err = 0;
|
||||
|
||||
|
@ -26,19 +26,27 @@ void do_randbytes(size_t num)
|
|||
{
|
||||
int i;
|
||||
unsigned char buf[32];
|
||||
OSSL_TIME start, end;
|
||||
|
||||
for (i = 0; i < NUM_CALLS_PER_RUN / threadcount; i++)
|
||||
start = ossl_time_now();
|
||||
|
||||
for (i = 0; i < NUM_CALLS_PER_TEST / threadcount; i++)
|
||||
if (!RAND_bytes(buf, sizeof(buf)))
|
||||
err = 1;
|
||||
|
||||
end = ossl_time_now();
|
||||
times[num] = ossl_time_subtract(end, start);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
OSSL_TIME duration;
|
||||
uint64_t us;
|
||||
OSSL_TIME us;
|
||||
double avcalltime;
|
||||
int terse = 0;
|
||||
int argnext;
|
||||
int rc = EXIT_FAILURE;
|
||||
size_t i;
|
||||
|
||||
if ((argc != 2 && argc != 3)
|
||||
|| (argc == 3 && strcmp("--terse", argv[1]) != 0)) {
|
||||
|
@ -59,25 +67,37 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
times = OPENSSL_malloc(sizeof(OSSL_TIME) * threadcount);
|
||||
if (times == NULL) {
|
||||
printf("Failed to create times array\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!perflib_run_multi_thread_test(do_randbytes, threadcount, &duration)) {
|
||||
printf("Failed to run the test\n");
|
||||
return EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
printf("Error during test\n");
|
||||
return EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
us = ossl_time2us(duration);
|
||||
us = times[0];
|
||||
for (i = 1; i < threadcount; i++)
|
||||
us = ossl_time_add(us, times[i]);
|
||||
us = ossl_time_divide(us, NUM_CALLS_PER_TEST);
|
||||
|
||||
avcalltime = (double)us / NUM_CALL_BLOCKS_PER_RUN;
|
||||
avcalltime = (double)ossl_time2ticks(us) / (double)OSSL_TIME_US;
|
||||
|
||||
if (terse)
|
||||
printf("%lf\n", avcalltime);
|
||||
else
|
||||
printf("Average time per %d RAND_bytes() calls: %lfus\n",
|
||||
NUM_CALLS_PER_BLOCK, avcalltime);
|
||||
printf("Average time per RAND_bytes() call: %lfus\n",
|
||||
avcalltime);
|
||||
|
||||
rc = EXIT_SUCCESS;
|
||||
out:
|
||||
OPENSSL_free(times);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -16,9 +16,7 @@
|
|||
#include <openssl/crypto.h>
|
||||
#include "perflib/perflib.h"
|
||||
|
||||
#define NUM_CALLS_PER_BLOCK 1000
|
||||
#define NUM_CALL_BLOCKS_PER_RUN 100
|
||||
#define NUM_CALLS_PER_RUN (NUM_CALLS_PER_BLOCK * NUM_CALL_BLOCKS_PER_RUN)
|
||||
#define NUM_CALLS_PER_TEST 100000
|
||||
|
||||
int err = 0;
|
||||
EVP_PKEY *rsakey = NULL;
|
||||
|
@ -39,6 +37,8 @@ static const char *tbs = "0123456789abcdefghij"; /* Length of SHA1 digest */
|
|||
|
||||
static int threadcount;
|
||||
|
||||
static OSSL_TIME *times = NULL;
|
||||
|
||||
void do_rsasign(size_t num)
|
||||
{
|
||||
int i;
|
||||
|
@ -46,25 +46,34 @@ void do_rsasign(size_t num)
|
|||
unsigned char sig[64];
|
||||
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(rsakey, NULL);
|
||||
size_t siglen = sizeof(sig);
|
||||
OSSL_TIME start, end;
|
||||
|
||||
for (i = 0; i < NUM_CALLS_PER_RUN; i++) {
|
||||
start = ossl_time_now();
|
||||
|
||||
for (i = 0; i < NUM_CALLS_PER_TEST / threadcount; i++) {
|
||||
if (EVP_PKEY_sign_init(ctx) <= 0
|
||||
|| EVP_PKEY_sign(ctx, sig, &siglen, tbs, SHA_DIGEST_LENGTH) <= 0) {
|
||||
err = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
end = ossl_time_now();
|
||||
times[num] = ossl_time_subtract(end, start);
|
||||
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
OSSL_TIME duration;
|
||||
uint64_t us;
|
||||
OSSL_TIME us;
|
||||
double avcalltime;
|
||||
int terse = 0;
|
||||
int argnext;
|
||||
BIO *membio = NULL;
|
||||
int rc = EXIT_FAILURE;
|
||||
size_t i;
|
||||
|
||||
if ((argc != 2 && argc != 3)
|
||||
|| (argc == 3 && strcmp("--terse", argv[1]) != 0)) {
|
||||
|
@ -95,30 +104,42 @@ int main(int argc, char *argv[])
|
|||
BIO_free(membio);
|
||||
if (rsakey == NULL) {
|
||||
printf("Failed to load the RSA key\n");
|
||||
return EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
times = OPENSSL_malloc(sizeof(OSSL_TIME) * threadcount);
|
||||
if (times == NULL) {
|
||||
printf("Failed to create times array\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!perflib_run_multi_thread_test(do_rsasign, threadcount, &duration)) {
|
||||
printf("Failed to run the test\n");
|
||||
EVP_PKEY_free(rsakey);
|
||||
return EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
EVP_PKEY_free(rsakey);
|
||||
|
||||
if (err) {
|
||||
printf("Error during test\n");
|
||||
return EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
us = ossl_time2us(duration);
|
||||
us = times[0];
|
||||
for (i = 1; i < threadcount; i++)
|
||||
us = ossl_time_add(us, times[i]);
|
||||
us = ossl_time_divide(us, NUM_CALLS_PER_TEST);
|
||||
|
||||
avcalltime = (double)us / NUM_CALL_BLOCKS_PER_RUN;
|
||||
avcalltime = (double)ossl_time2ticks(us) / (double)OSSL_TIME_US;
|
||||
|
||||
if (terse)
|
||||
printf("%lf\n", avcalltime);
|
||||
else
|
||||
printf("Average time per %d RSA signature operations: %lfus\n",
|
||||
NUM_CALLS_PER_BLOCK, avcalltime);
|
||||
printf("Average time per RSA signature operation: %lfus\n",
|
||||
avcalltime);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
rc = EXIT_SUCCESS;
|
||||
|
||||
out:
|
||||
EVP_PKEY_free(rsakey);
|
||||
OPENSSL_free(times);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
* Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include "perflib/perflib.h"
|
||||
|
||||
#define NUM_CALLS_PER_RUN 1000000
|
||||
|
||||
int threadcount = 0;
|
||||
int err = 0;
|
||||
unsigned long *dataval = NULL;
|
||||
int writers = 0;
|
||||
int readers = 0;
|
||||
int write_lock_calls = 0;
|
||||
int read_lock_calls = 0;
|
||||
OSSL_TIME reader_end = { 0 };
|
||||
OSSL_TIME writer_end = { 0 };
|
||||
|
||||
CRYPTO_RWLOCK *lock = NULL;
|
||||
|
||||
void do_rw_wlock(size_t num)
|
||||
{
|
||||
int i;
|
||||
unsigned long *newval, *oldval;
|
||||
int local_write_lock_calls = 0;
|
||||
|
||||
for (i = 0; i < NUM_CALLS_PER_RUN / threadcount; i++) {
|
||||
newval = OPENSSL_malloc(sizeof(int));
|
||||
CRYPTO_THREAD_write_lock(lock);
|
||||
if (dataval == NULL)
|
||||
*newval = 1;
|
||||
else
|
||||
*newval = ((*dataval) + 1);
|
||||
oldval = dataval;
|
||||
dataval = newval;
|
||||
CRYPTO_THREAD_unlock(lock);
|
||||
local_write_lock_calls += 2; /* lock and unlock */
|
||||
OPENSSL_free(oldval);
|
||||
}
|
||||
|
||||
CRYPTO_THREAD_write_lock(lock);
|
||||
write_lock_calls += local_write_lock_calls;
|
||||
writers--;
|
||||
if (writers == 0) {
|
||||
writer_end = ossl_time_now();
|
||||
OPENSSL_free(dataval); /* free last allocation */
|
||||
}
|
||||
CRYPTO_THREAD_unlock(lock);
|
||||
}
|
||||
|
||||
void do_rw_rlock(size_t num)
|
||||
{
|
||||
int i;
|
||||
unsigned long last_val = 0;
|
||||
int local_read_lock_calls = 0;
|
||||
|
||||
for (i = 0; i < NUM_CALLS_PER_RUN / threadcount; i++) {
|
||||
CRYPTO_THREAD_read_lock(lock);
|
||||
if (dataval != NULL) {
|
||||
if (last_val != 0 && last_val > *dataval)
|
||||
printf("dataval went backwards! %lu:%lu\n", last_val, *dataval);
|
||||
last_val = *dataval;
|
||||
}
|
||||
CRYPTO_THREAD_unlock(lock);
|
||||
local_read_lock_calls += 2; /* lock and unlock */
|
||||
}
|
||||
|
||||
CRYPTO_THREAD_write_lock(lock);
|
||||
read_lock_calls += local_read_lock_calls;
|
||||
readers--;
|
||||
if (readers == 0)
|
||||
reader_end = ossl_time_now();
|
||||
CRYPTO_THREAD_unlock(lock);
|
||||
}
|
||||
|
||||
void do_rwlocks(size_t num)
|
||||
{
|
||||
if (num >= threadcount - writers)
|
||||
do_rw_wlock(num);
|
||||
else
|
||||
do_rw_rlock(num);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
OSSL_TIME duration;
|
||||
OSSL_TIME start;
|
||||
uint64_t us;
|
||||
double avwcalltime;
|
||||
double avrcalltime;
|
||||
int terse = 0;
|
||||
int argnext;
|
||||
char *writeenv;
|
||||
|
||||
if ((argc != 2 && argc != 3)
|
||||
|| (argc == 3 && strcmp("--terse", argv[1]) != 0)) {
|
||||
printf("Usage: rwlocks [--terse] threadcount\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (argc == 3) {
|
||||
terse = 1;
|
||||
argnext = 2;
|
||||
} else {
|
||||
argnext = 1;
|
||||
}
|
||||
|
||||
threadcount = atoi(argv[argnext]);
|
||||
if (threadcount < 1) {
|
||||
printf("threadcount must be > 0\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
writeenv = getenv("LOCK_WRITERS");
|
||||
if (writeenv == NULL) {
|
||||
writers = threadcount / 2;
|
||||
} else {
|
||||
writers = atoi(writeenv);
|
||||
if (writers == 0)
|
||||
writers = threadcount / 2;
|
||||
}
|
||||
|
||||
lock = CRYPTO_THREAD_lock_new();
|
||||
if (lock == NULL) {
|
||||
printf("unable to allocate lock\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
readers = threadcount - writers;
|
||||
|
||||
if (!terse)
|
||||
printf("Running rwlock test with %d writers and %d readers\n",
|
||||
writers, readers);
|
||||
|
||||
start = ossl_time_now();
|
||||
|
||||
if (!perflib_run_multi_thread_test(do_rwlocks, threadcount, &duration)) {
|
||||
printf("Failed to run the test\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
printf("Error during test\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
us = ossl_time2us(ossl_time_subtract(writer_end, start));
|
||||
avwcalltime = (double)us / (double)write_lock_calls;
|
||||
|
||||
if (!terse)
|
||||
printf("total write lock/unlock calls %d in %lf us\n",
|
||||
write_lock_calls, (double)us);
|
||||
|
||||
us = ossl_time2us(ossl_time_subtract(reader_end, start));
|
||||
avrcalltime = (double)us / (double)read_lock_calls;
|
||||
if (!terse)
|
||||
printf("total read lock/unlock calls %d %lf us\n",
|
||||
read_lock_calls, (double)us);
|
||||
|
||||
if (terse) {
|
||||
printf("%lf %lf\n", avwcalltime, avrcalltime);
|
||||
} else {
|
||||
printf("Average time per write_lock/unlock call pair: %lfus\n",
|
||||
avwcalltime);
|
||||
printf("Average time per read_lock/unlock call pair: %lfus\n",
|
||||
avrcalltime);
|
||||
}
|
||||
|
||||
CRYPTO_THREAD_lock_free(lock);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -14,22 +14,24 @@
|
|||
#include <openssl/crypto.h>
|
||||
#include "perflib/perflib.h"
|
||||
|
||||
#define NUM_CALLS_PER_BLOCK 1000
|
||||
#define NUM_CALL_BLOCKS_PER_RUN 100
|
||||
#define NUM_CALLS_PER_RUN (NUM_CALLS_PER_BLOCK * NUM_CALL_BLOCKS_PER_RUN)
|
||||
#define NUM_CALLS_PER_TEST 100000
|
||||
|
||||
int err = 0;
|
||||
static SSL_CTX *ctx;
|
||||
|
||||
static int threadcount;
|
||||
static OSSL_TIME *times = NULL;
|
||||
|
||||
void do_sslnew(size_t num)
|
||||
{
|
||||
int i;
|
||||
SSL *s;
|
||||
BIO *rbio, *wbio;
|
||||
OSSL_TIME start, end;
|
||||
|
||||
for (i = 0; i < NUM_CALLS_PER_RUN / threadcount; i++) {
|
||||
start = ossl_time_now();
|
||||
|
||||
for (i = 0; i < NUM_CALLS_PER_TEST / threadcount; i++) {
|
||||
s = SSL_new(ctx);
|
||||
rbio = BIO_new(BIO_s_mem());
|
||||
wbio = BIO_new(BIO_s_mem());
|
||||
|
@ -45,15 +47,20 @@ void do_sslnew(size_t num)
|
|||
|
||||
SSL_free(s);
|
||||
}
|
||||
|
||||
end = ossl_time_now();
|
||||
times[num] = ossl_time_subtract(end, start);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
OSSL_TIME duration;
|
||||
uint64_t us;
|
||||
OSSL_TIME us;
|
||||
double avcalltime;
|
||||
int terse = 0;
|
||||
int argnext;
|
||||
int rc = EXIT_FAILURE;
|
||||
size_t i;
|
||||
|
||||
if ((argc != 2 && argc != 3)
|
||||
|| (argc == 3 && strcmp("--terse", argv[1]) != 0)) {
|
||||
|
@ -74,34 +81,42 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
times = OPENSSL_malloc(sizeof(OSSL_TIME) * threadcount);
|
||||
if (times == NULL) {
|
||||
printf("Failed to create times array\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ctx = SSL_CTX_new(TLS_server_method());
|
||||
if (ctx == NULL) {
|
||||
printf("Failure to create SSL_CTX\n");
|
||||
return EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!perflib_run_multi_thread_test(do_sslnew, threadcount, &duration)) {
|
||||
SSL_CTX_free(ctx);
|
||||
printf("Failed to run the test\n");
|
||||
return EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
SSL_CTX_free(ctx);
|
||||
|
||||
if (err) {
|
||||
printf("Error during test\n");
|
||||
return EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
us = ossl_time2us(duration);
|
||||
us = times[0];
|
||||
for (i = 1; i < threadcount; i++)
|
||||
us = ossl_time_add(us, times[i]);
|
||||
us = ossl_time_divide(us, NUM_CALLS_PER_TEST);
|
||||
|
||||
avcalltime = (double)us / NUM_CALL_BLOCKS_PER_RUN;
|
||||
avcalltime = (double)ossl_time2ticks(us) / (double)OSSL_TIME_US;
|
||||
|
||||
if (terse)
|
||||
printf("%lf\n", avcalltime);
|
||||
else
|
||||
printf("Average time per %d SSL/BIO creation calls: %lfus\n",
|
||||
NUM_CALLS_PER_BLOCK, avcalltime);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
printf("Average time per SSL/BIO creation call: %lfus\n",
|
||||
avcalltime);
|
||||
out:
|
||||
SSL_CTX_free(ctx);
|
||||
OPENSSL_free(times);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -14,9 +14,7 @@
|
|||
#include <openssl/x509.h>
|
||||
#include "perflib/perflib.h"
|
||||
|
||||
#define NUM_CALLS_PER_BLOCK 1000
|
||||
#define NUM_CALL_BLOCKS_PER_RUN 100
|
||||
#define NUM_CALLS_PER_RUN (NUM_CALLS_PER_BLOCK * NUM_CALL_BLOCKS_PER_RUN)
|
||||
#define NUM_CALLS_PER_TEST 100000
|
||||
|
||||
static int err = 0;
|
||||
static X509_STORE *store = NULL;
|
||||
|
@ -40,7 +38,7 @@ static void do_x509storeissuer(size_t num)
|
|||
|
||||
start = ossl_time_now();
|
||||
|
||||
for (i = 0; i < NUM_CALLS_PER_RUN / threadcount; i++) {
|
||||
for (i = 0; i < NUM_CALLS_PER_TEST / threadcount; i++) {
|
||||
/*
|
||||
* We actually expect this to fail. We've not configured any
|
||||
* certificates inside our store. We're just testing calling this
|
||||
|
@ -56,8 +54,7 @@ static void do_x509storeissuer(size_t num)
|
|||
}
|
||||
|
||||
end = ossl_time_now();
|
||||
times[num] = ossl_time_divide(ossl_time_subtract(end, start),
|
||||
NUM_CALL_BLOCKS_PER_RUN);
|
||||
times[num] = ossl_time_subtract(end, start);
|
||||
|
||||
err:
|
||||
X509_STORE_CTX_free(ctx);
|
||||
|
@ -65,9 +62,8 @@ static void do_x509storeissuer(size_t num)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int threadcount, i;
|
||||
OSSL_TIME duration, av;
|
||||
uint64_t us;
|
||||
int i;
|
||||
OSSL_TIME duration, ttime;
|
||||
double avcalltime;
|
||||
int terse = 0;
|
||||
int argnext;
|
||||
|
@ -135,17 +131,20 @@ int main(int argc, char *argv[])
|
|||
goto err;
|
||||
}
|
||||
|
||||
av = times[0];
|
||||
ttime = times[0];
|
||||
for (i = 1; i < threadcount; i++)
|
||||
av = ossl_time_add(av, times[i]);
|
||||
ttime = ossl_time_add(ttime, times[i]);
|
||||
|
||||
avcalltime = ((double)ossl_time2ticks(ttime) / (double)NUM_CALLS_PER_TEST) /(double)OSSL_TIME_US;
|
||||
|
||||
if (terse)
|
||||
printf("%ld\n", ossl_time2us(av));
|
||||
printf("%lf\n", avcalltime);
|
||||
else
|
||||
printf("Average time per %d X509_STORE_CTX_get1_issuer() calls: %ldus\n",
|
||||
NUM_CALLS_PER_BLOCK, ossl_time2us(av));
|
||||
printf("Average time per X509_STORE_CTX_get1_issuer() call: %lfus\n",
|
||||
avcalltime);
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
|
||||
err:
|
||||
X509_STORE_free(store);
|
||||
X509_free(x509);
|
||||
|
|
Loading…
Reference in New Issue