Skip to content

Commit bdad61c

Browse files
committed
pkeyread: add an option to bind threads to cores
Signed-off-by: Eugene Syromiatnikov <[email protected]>
1 parent 4175dc9 commit bdad61c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ option is specified, only the number is printed, without key type and format.
136136
If `-v` ("verbose") option is specified, additional information is printed
137137
for each run: median, minimum, maximum time among threads, as well as standard
138138
deviation.
139+
If `-b` ("bind") option is provided, thread affinity is set to the threads
140+
so the available cores are assigned in a round robin manner.
139141
The mandatory option `-k` selects the key type for benchmark. The list of keys
140142
for testing is as follows: dh, dhx, dsa, ec, rsa, x25519. To run benchmark
141143
for all keys and formats using 4 threads, run `pkeyread` as follows:

source/pkeyread.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ static void usage(char * const argv[])
275275
fprintf(stderr, "%s -k key_name -f format_name [-t] [-v] [-T time] threadcount\n"
276276
"\t-t terse output\n"
277277
"\t-v verbose output, includes min, max, stddev, and median times\n"
278-
"\t-T timeout for each test run in seconds, can be fractional"
278+
"\t-T timeout for each test run in seconds, can be fractional\n"
279+
"\t-b Set CPU affinity for the threads (in round robin fashion)\n"
279280
"\twhere key_name is one of these: ", argv[0]);
280281
fprintf(stderr, "%s", *key_name);
281282
do {
@@ -303,6 +304,7 @@ int main(int argc, char * const argv[])
303304
int key_id, key_id_min, key_id_max, k;
304305
int format_id, format_id_min, format_id_max, f;
305306
int verbosity = VERBOSITY_DEFAULT;
307+
int bind_threads = 0;
306308
char *key = NULL;
307309
char *key_format = NULL;
308310
void (*do_f[2])(size_t) = {
@@ -313,7 +315,7 @@ int main(int argc, char * const argv[])
313315
key_id = SAMPLE_INVALID;
314316
format_id = FORMAT_INVALID;
315317

316-
while ((ch = getopt(argc, argv, "T:k:f:tv")) != -1) {
318+
while ((ch = getopt(argc, argv, "T:k:f:tvb")) != -1) {
317319
switch (ch) {
318320
case 'T': {
319321
double timeout_s;
@@ -342,6 +344,9 @@ int main(int argc, char * const argv[])
342344
case 'v':
343345
verbosity = VERBOSITY_VERBOSE;
344346
break;
347+
case 'b':
348+
bind_threads = 1;
349+
break;
345350
}
346351
}
347352

@@ -419,7 +424,9 @@ int main(int argc, char * const argv[])
419424
for (f = format_id_min; f < format_id_max; f++) {
420425
sample_id = k;
421426
max_time = ossl_time_add(ossl_time_now(), ossl_us2time(timeout_us));
422-
if (!perflib_run_multi_thread_test(do_f[f], threadcount, &duration)) {
427+
if (!perflib_run_multi_thread_test_ex(do_f[f], threadcount,
428+
&duration, bind_threads ? perflib_roundrobin_affinity : NULL,
429+
NULL)) {
423430
fprintf(stderr, "Failed to run the test %s in %s format\n",
424431
sample_names[k], format_names[f]);
425432
OPENSSL_free(counts);

0 commit comments

Comments
 (0)