Skip to content

Commit 6ef81f3

Browse files
committed
This change hopes to provide a better alignement of pkeyread with other
performance tools we have. The pkeyread enables as to evaluate speed of reading various keys in der/pem formats. This requires user to specifi desired key and format on command line. This makes pkeyread different to other tools which seem to have a common set of options: ./tool_name --terse 2 command line above executes tool tool_name running test using 2 threads with terse output. The idea of this change is to provide implicit mode for pkeyread where key and format is determined from command name. For example to run evaulation for rsa key in pem format using 2 threads one runs tool: ./rsa.pem 2 The tool for rsa essentially becames a symlink to pkeyread binary. This should help us to create us more simple shell scripts to run performacne test. For example to run all tests for pem keys we can do something like this in shell for perf_tool in *.pem ; do ./$perf_tool --terse 2 ; done
1 parent 7c6bdb6 commit 6ef81f3

File tree

2 files changed

+115
-3
lines changed

2 files changed

+115
-3
lines changed

perf/Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
all: randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall rwlocks pkeyread evp_fetch
1+
PKEYREAD_SYMLINKS=pkeyread-dh-pem pkeyread-dhx-pem pkeyread-dsa-pem pkeyread-ec-pem pkeyread-rsa-pem pkeyread-x25519-pem \
2+
pkeyread-dh-der pkeyread-dhx-der pkeyread-dsa-der pkeyread-ec-der pkeyread-rsa-der pkeyread-x25519-der
3+
all: randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall rwlocks pkeyread evp_fetch \
4+
$(PKEYREAD_SYMLINKS)
5+
26
# Build target for OpenSSL 1.1.1 builds
3-
all111: randbytes handshake sslnew newrawkey rsasign x509storeissuer rwlocks pkeyread
7+
all111: randbytes handshake sslnew newrawkey rsasign x509storeissuer rwlocks pkeyread \
8+
$(PKEYREAD_SYMLINKS)
49

510
clean:
6-
rm -f libperf.a *.o randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall rwlocks pkeyread evp_fetch
11+
rm -f libperf.a *.o randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall rwlocks pkeyread evp_fetch \
12+
$(PKEYREAD_SYMLINKS)
713

814
CPPFLAGS += -I$(TARGET_OSSL_INCLUDE_PATH) -I.
915
# For second include path, i.e. out of tree build of OpenSSL uncomment this:
@@ -13,6 +19,8 @@ LDFLAGS += -L$(TARGET_OSSL_LIBRARY_PATH) -L.
1319
# For setting RUNPATH on built executables uncomment this:
1420
# LDFLAGS += -Wl,-rpath,$(TARGET_OSSL_LIBRARY_PATH)
1521

22+
LN=/bin/ln
23+
1624
libperf.a: perflib/*.c perflib/*.h
1725
$(CC) $(CPPFLAGS) $(CFLAGS) -c perflib/*.c
1826
ar rcs libperf.a *.o
@@ -49,3 +57,6 @@ regen_key_samples:
4957

5058
pkeyread: pkeyread.c keys.h libperf.a
5159
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o pkeyread pkeyread.c -lperf -lcrypto
60+
61+
$(PKEYREAD_SYMLINKS) pkeyread-%: pkeyread
62+
$(LN) -s pkeyread $@

perf/pkeyread.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <stdio.h>
1212
#include <string.h>
1313
#include <unistd.h>
14+
#include <libgen.h>
1415
#include <openssl/pem.h>
1516
#include <openssl/evp.h>
1617
#include <openssl/x509.h>
@@ -217,6 +218,103 @@ static void usage(char * const argv[])
217218
} while (*format_name != NULL);
218219
}
219220

221+
static void implicit_report_result(char *const argv[], int terse)
222+
{
223+
if (terse)
224+
printf("%lf\n", get_avcalltime());
225+
else
226+
printf("%s average time per call: %lfus\n", basename(argv[0]),
227+
get_avcalltime());
228+
}
229+
230+
static int implicit_main(int argc, char *const argv[])
231+
{
232+
OSSL_TIME duration;
233+
char progname[80];
234+
char *key, *format;
235+
int format_id, ch, terse;
236+
void (*do_f[2])(size_t) = {
237+
do_pemread,
238+
do_derread
239+
};
240+
241+
strncpy(progname, basename(argv[0]), sizeof(progname));
242+
progname[79] = '\0';
243+
244+
/* chop off pkeyread */
245+
key = strchr(progname, '-');
246+
if (key == NULL) {
247+
fprintf(stderr, "Unexpected command %s\n", argv[0]);
248+
return EXIT_FAILURE;
249+
}
250+
key++;
251+
252+
format = strchr(key, '-');
253+
if (format == NULL) {
254+
fprintf(stderr, "Unexpected command %s\n", argv[0]);
255+
return EXIT_FAILURE;
256+
}
257+
*format = '\0';
258+
format++;
259+
260+
format_id = format_name_to_id(format);
261+
if (format_id == FORMAT_INVALID || format_id == FORMAT_ALL) {
262+
fprintf(stderr, "%s - unexpected command .%s\n", argv[0], format);
263+
return EXIT_FAILURE;
264+
}
265+
266+
sample_id = sample_name_to_id(key);
267+
if (sample_id == SAMPLE_INVALID || sample_id == SAMPLE_ALL) {
268+
fprintf(stderr, "%s - unexpected command %s.\n", argv[0], key);
269+
return EXIT_FAILURE;
270+
}
271+
272+
terse = 0;
273+
while ((ch = getopt(argc, argv, "t")) != -1) {
274+
switch (ch) {
275+
case 't':
276+
terse = 1;
277+
break;
278+
default:
279+
fprintf(stderr, "invalid option!\n%s [-t]\n"
280+
"\t-t enables minimal output", basename(argv[0]));
281+
return EXIT_FAILURE;
282+
}
283+
}
284+
285+
if (argv[optind] == NULL) {
286+
fprintf(stderr, "%s Missing threadcount argument\n", argv[0]);
287+
return EXIT_FAILURE;
288+
}
289+
290+
threadcount = atoi(argv[optind]);
291+
if (threadcount < 1) {
292+
fprintf(stderr, "%s threadcount must be > 0\n", argv[0]);
293+
return EXIT_FAILURE;
294+
}
295+
296+
times = OPENSSL_malloc(sizeof(OSSL_TIME) * threadcount);
297+
if (times == NULL) {
298+
printf("%s Failed to create times array\n", argv[0]);
299+
return EXIT_FAILURE;
300+
}
301+
302+
num_calls = NUM_CALLS_PER_TEST;
303+
if (NUM_CALLS_PER_TEST % threadcount > 0) /* round up */
304+
num_calls += threadcount - NUM_CALLS_PER_TEST % threadcount;
305+
306+
if (!perflib_run_multi_thread_test(do_f[format_id], threadcount,
307+
&duration)) {
308+
fprintf(stderr, "%s Failed to run the test %s in %s format]\n",
309+
argv[0], key, format);
310+
return EXIT_FAILURE;
311+
}
312+
313+
implicit_report_result(argv, terse);
314+
315+
return EXIT_SUCCESS;
316+
}
317+
220318
int main(int argc, char * const argv[])
221319
{
222320
OSSL_TIME duration;
@@ -236,6 +334,9 @@ int main(int argc, char * const argv[])
236334
"X509_PUBKEY_get0_param"
237335
};
238336

337+
if (strcmp(basename(argv[0]), "pkeyread") != 0)
338+
return implicit_main(argc, argv);
339+
239340
key_id = SAMPLE_INVALID;
240341
format_id = FORMAT_INVALID;
241342

0 commit comments

Comments
 (0)