Skip to content

Commit

Permalink
This change adds rwlocks.rlock and rwlocks.wlock symlinks rwlocks bin…
Browse files Browse the repository at this point in the history
…ary.

We need it so we can pass 'implicit' option so we can chose which
statistics want to collect. This helps us with our current simple
tooling we have to collect stats. The script we currently work on
expects tool prints a single number as its output.
  • Loading branch information
Sashan committed Jun 19, 2024
1 parent 54ed7d1 commit 16546f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
17 changes: 14 additions & 3 deletions perf/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
all: randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall rwlocks pkeyread evp_fetch
all: randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall rwlocks pkeyread evp_fetch \
rwlocks.rlock rwlocks.wlock
# Build target for OpenSSL 1.1.1 builds
all111: randbytes handshake sslnew newrawkey rsasign x509storeissuer rwlocks pkeyread
all111: randbytes handshake sslnew newrawkey rsasign x509storeissuer rwlocks pkeyread rwlocks.rlock \
rwlocks.wlock

clean:
rm -f libperf.a *.o randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall rwlocks pkeyread evp_fetch
rm -f libperf.a *.o randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall rwlocks pkeyread evp_fetch \
rwlocks.rlock rwlocks.wlock

LN=/bin/ln

CPPFLAGS += -I$(TARGET_OSSL_INCLUDE_PATH) -I.
# For second include path, i.e. out of tree build of OpenSSL uncomment this:
Expand Down Expand Up @@ -44,6 +49,12 @@ providerdoall: providerdoall.c libperf.a
rwlocks: rwlocks.c libperf.a
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o rwlocks rwlocks.c -lperf -lcrypto

rwlocks.rlock: rwlocks
$(LN) -s rwlocks rwlocks.rlock

rwlocks.wlock: rwlocks
$(LN) -s rwlocks rwlocks.wlock

regen_key_samples:
./genkeys.sh > keys.h

Expand Down
27 changes: 23 additions & 4 deletions perf/rwlocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <libgen.h>
#include <openssl/pem.h>
#include <openssl/evp.h>
#include <openssl/crypto.h>
Expand Down Expand Up @@ -102,6 +103,7 @@ int main(int argc, char *argv[])
int terse = 0;
int argnext;
char *writeenv;
int show_rlock_stats, show_wlock_stats;;

if ((argc != 2 && argc != 3)
|| (argc == 3 && strcmp("--terse", argv[1]) != 0)) {
Expand All @@ -116,6 +118,17 @@ int main(int argc, char *argv[])
argnext = 1;
}

if (strcmp(basename(argv[0]), "rwlocks.rlock") == 0) {
show_rlock_stats = 1;
show_wlock_stats = 0;
} else if (strcmp(basename(argv[0]), "rwlocks.wlock") == 0) {
show_rlock_stats = 0;
show_wlock_stats = 1;
} else {
show_rlock_stats = 1;
show_wlock_stats = 1;
}

threadcount = atoi(argv[argnext]);
if (threadcount < 1) {
printf("threadcount must be > 0\n");
Expand Down Expand Up @@ -169,12 +182,18 @@ int main(int argc, char *argv[])
read_lock_calls, (double)us);

if (terse) {
printf("%lf %lf\n", avwcalltime, avrcalltime);
if (show_rlock_stats)
printf("%lf", avrcalltime);
if (show_wlock_stats)
printf("%lf", avwcalltime);
printf("\n");
} else {
printf("Average time per write_lock/unlock call pair: %lfus\n",
avwcalltime);
printf("Average time per read_lock/unlock call pair: %lfus\n",
if (show_rlock_stats)
printf("Average time per read_lock/unlock call pair: %lfus\n",
avrcalltime);
if (show_wlock_stats)
printf("Average time per write_lock/unlock call pair: %lfus\n",
avwcalltime);
}

CRYPTO_THREAD_lock_free(lock);
Expand Down

0 comments on commit 16546f3

Please sign in to comment.