1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588
|
/* ====================================================================
*
*
* BSD LICENSE
*
* Copyright(c) 2021-2025 Intel Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* ====================================================================
*/
/* macros defined to allow use of the cpu get and set affinity functions */
#define _GNU_SOURCE
#define __USE_GNU
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#ifndef __FreeBSD__
# include <sched.h>
# else
# include <pthread_np.h>
# include <sys/types.h>
# include <sys/sysctl.h>
# include <unistd.h>
# include <errno.h>
#endif
#include <sys/time.h>
#include <unistd.h>
#include <openssl/engine.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/async.h>
#include "tests.h"
#include "../qat_utils.h"
#define DEFAULT_KEY_SIZE 2048
#ifndef __FreeBSD__
typedef cpu_set_t qat_cpuset;
#else
typedef cpuset_t qat_cpuset;
#endif
FILE *qatDebugLogFile = NULL;
static pthread_cond_t ready_cond;
static pthread_cond_t start_cond;
static pthread_cond_t stop_cond;
static pthread_mutex_t mutex;
static int cleared_to_start;
static int active_thread_count;
static int ready_thread_count;
/* thread_count - control number of threads created */
static int thread_count = 1;
/* define the initial test values */
static int core_count = 1;
static int enable_engine = 0;
static int enable_provider = 0;
char *prov_id;
#ifdef QAT_OPENSSL_PROVIDER
static OSSL_PROVIDER *provider = NULL;
#endif
/* test_count - specify the number of operations that each thread does */
static int test_count = 1;
static int test_size = DEFAULT_KEY_SIZE;
static int cpu_affinity = 0;
static int test_alg = 0;
static int enable_perf = 0;
static int enable_async = 0;
#ifdef QAT_OPENSSL_3
static int use_callback_mode = 0;
#endif
static int enable_external_polling = 0;
static int enable_event_driven_polling = 0;
static int enable_negative = 0;
static int print_output = 0;
static int verify = 0;
static int curve = P_CURVE_256; /* default curve is NIST Prime-Curve P-256 */
static int kdf = 1;
static int zero_copy = 0;
static int cpu_core_info = 0;
static int qatPerformOpRetries;
static char *engine_id;
static ENGINE *engine = NULL;
static char *default_tls_string = "TLSv1_2";
static char *default_digest_string = "SHA256";
static char *tls_version = NULL;
static char *digest_kdf = NULL;
static int prf_op = -1;
static int hkdf_op = -1;
static int explicit_engine = 0;
static int async_jobs = 1;
static int sw_fallback = 0;
static int sign_only = 0;
static int verify_only = 0;
static int encrypt_only = 0;
static int decrypt_only = 0;
extern char *sw_algo_bitmap;
extern char *hw_algo_bitmap;
/* Thread_info structure declaration */
typedef struct {
pthread_t th;
int id;
int count;
TEST_PARAMS *test_params;
}
THREAD_INFO;
#define MAX_STAT 10
#ifdef __FreeBSD__
# define MAX_CORE 88
#else
# define MAX_CORE 48
#endif
typedef union {
struct {
int user;
int nice;
int sys;
int idle;
int io;
#ifndef __FreeBSD__
int irq;
int softirq;
#else
/* interrupt */
int intr;
#endif
int context;
};
int d[MAX_STAT];
}
cpu_time_t;
static cpu_time_t cpu_time[MAX_CORE];
static cpu_time_t cpu_time_total;
#ifndef __FreeBSD__
static cpu_time_t cpu_context;
#endif
#define MAX_THREAD 1024
THREAD_INFO tinfo[MAX_THREAD];
#ifdef __FreeBSD__
# define CPU_STATES 5
# define CP_USER 0
# define CP_NICE 1
# define CP_SYS 2
# define CP_INTR 3
# define CP_IDLE 4
# define CP_STAT_SIZE (MAX_CORE * CPU_STATES)
#endif
typedef struct options_data {
const char *name;
int test_size;
int test_alg;
int curve_name;
int op;
} option_data;
static const option_data rsa_choices[] = {
{"rsa1024", 1024, TEST_RSA, 0, 0},
{"rsa2048", 2048, TEST_RSA, 0, 0},
{"rsa3072", 3072, TEST_RSA, 0, 0},
{"rsa4096", 4096, TEST_RSA, 0, 0},
{"rsa8192", 8192, TEST_RSA, 0, 0},
};
static const option_data dsa_choices[] = {
{"dsa1024", 1024, TEST_DSA, 0, 0},
{"dsa2048", 2048, TEST_DSA, 0, 0},
{"dsa3072", 3072, TEST_DSA, 0, 0},
{"dsa4096", 4096, TEST_DSA, 0, 0},
};
static const option_data dh_choices[] = {
{"dh512", 512, TEST_DH, 0, 0},
{"dh1024", 1024, TEST_DH, 0, 0},
{"dh2048", 2048, TEST_DH, 0, 0},
{"dh3072", 3072, TEST_DH, 0, 0},
{"dh4096", 4096, TEST_DH, 0, 0},
{"dh8192", 8192, TEST_DH, 0, 0},
};
static const option_data ecdh_choices[] = {
{"ecdhp192", 0, TEST_ECDH, P_CURVE_192, 0},
{"ecdhp224", 0, TEST_ECDH, P_CURVE_224, 0},
{"ecdhp256", 0, TEST_ECDH, P_CURVE_256, 0},
{"ecdhp384", 0, TEST_ECDH, P_CURVE_384, 0},
{"ecdhp521", 0, TEST_ECDH, P_CURVE_521, 0},
{"ecdhk163", 0, TEST_ECDH, K_CURVE_163, 0},
{"ecdhk233", 0, TEST_ECDH, K_CURVE_233, 0},
{"ecdhk283", 0, TEST_ECDH, K_CURVE_283, 0},
{"ecdhk409", 0, TEST_ECDH, K_CURVE_409, 0},
{"ecdhk571", 0, TEST_ECDH, K_CURVE_571, 0},
{"ecdhb163", 0, TEST_ECDH, B_CURVE_163, 0},
{"ecdhb233", 0, TEST_ECDH, B_CURVE_233, 0},
{"ecdhb283", 0, TEST_ECDH, B_CURVE_283, 0},
{"ecdhb409", 0, TEST_ECDH, B_CURVE_409, 0},
{"ecdhb571", 0, TEST_ECDH, B_CURVE_571, 0},
{"ecdhx25519", 0, TEST_ECX, X_CURVE_25519, 0},
{"ecdhx448", 0, TEST_ECX, X_CURVE_448, 0},
{"ecdhsm2", 0, TEST_ECDH, P_CURVE_SM2, 0},
};
static const option_data ecdsa_choices[] = {
{"ecdsap192", 0, TEST_ECDSA, P_CURVE_192, 0},
{"ecdsap224", 0, TEST_ECDSA, P_CURVE_224, 0},
{"ecdsap256", 0, TEST_ECDSA, P_CURVE_256, 0},
{"ecdsap384", 0, TEST_ECDSA, P_CURVE_384, 0},
{"ecdsap521", 0, TEST_ECDSA, P_CURVE_521, 0},
{"ecdsak163", 0, TEST_ECDSA, K_CURVE_163, 0},
{"ecdsak233", 0, TEST_ECDSA, K_CURVE_233, 0},
{"ecdsak283", 0, TEST_ECDSA, K_CURVE_283, 0},
{"ecdsak409", 0, TEST_ECDSA, K_CURVE_409, 0},
{"ecdsak571", 0, TEST_ECDSA, K_CURVE_571, 0},
{"ecdsab163", 0, TEST_ECDSA, B_CURVE_163, 0},
{"ecdsab233", 0, TEST_ECDSA, B_CURVE_233, 0},
{"ecdsab283", 0, TEST_ECDSA, B_CURVE_283, 0},
{"ecdsab409", 0, TEST_ECDSA, B_CURVE_409, 0},
{"ecdsab571", 0, TEST_ECDSA, B_CURVE_571, 0},
};
static const option_data aes_choices[] = {
{"aes128_cbc_hmac_sha1", 0, TEST_AES128_CBC_HMAC_SHA1, 0, 0},
{"aes256_cbc_hmac_sha1", 0, TEST_AES256_CBC_HMAC_SHA1, 0, 0},
{"aes128_cbc_hmac_sha256", 0, TEST_AES128_CBC_HMAC_SHA256, 0, 0},
{"aes256_cbc_hmac_sha256", 0, TEST_AES256_CBC_HMAC_SHA256, 0, 0},
{"aes128gcm", 0, TEST_AES128_GCM, 0, 0},
{"aes256gcm", 0, TEST_AES256_GCM, 0, 0},
{"aes128ccm", 0, TEST_AES128_CCM, 0, 0},
{"aes192ccm", 0, TEST_AES192_CCM, 0, 0},
{"aes256ccm", 0, TEST_AES256_CCM, 0, 0},
};
static const option_data sha3_choices[] = {
{"sha3-224", 0, TEST_SHA3_224, 0, 0},
{"sha3-256", 0, TEST_SHA3_256, 0, 0},
{"sha3-384", 0, TEST_SHA3_384, 0, 0},
{"sha3-512", 0, TEST_SHA3_512, 0, 0},
};
static const option_data sha2_choices[] = {
{"sha2-224", 0, TEST_SHA2_224, 0, 0},
{"sha2-256", 0, TEST_SHA2_256, 0, 0},
{"sha2-384", 0, TEST_SHA2_384, 0, 0},
{"sha2-512", 0, TEST_SHA2_512, 0, 0},
};
/******************************************************************************
* function:
* cpu_time_add (cpu_time_t *t1, cpu_time_t *t2, int subtract)
*
* @param t1 [IN] - cpu time
* @param t2 [IN] - cpu time
* @param subtract [IN] - subtract flag
*
* description:
* CPU timing calculation functions.
******************************************************************************/
static void cpu_time_add (cpu_time_t *t1, cpu_time_t *t2, int subtract)
{
int i;
for (i = 0; i < MAX_STAT; i++) {
if (subtract)
t1->d[i] -= t2->d[i];
else
t1->d[i] += t2->d[i];
}
}
#ifndef __FreeBSD__
/******************************************************************************
* function:
* read_stat (int init)
*
* @param init [IN] - op flag
*
* description:
* read in CPU status from proc/stat file
******************************************************************************/
static void read_stat (int init)
{
char line[1024];
char tag[10];
FILE *fp;
int index = 0;
int i;
cpu_time_t tmp;
if ((fp = fopen("/proc/stat", "r")) == NULL) {
WARN("# FAIL: Can't open proc stat\n");
exit(1);
}
while (!feof(fp)) {
if (fgets(line, sizeof(line) - 1, fp) == NULL)
break;
if (!strncmp(line, "ctxt", 4)) {
if (sscanf(line, "%*s %d", &tmp.context) < 1)
goto parse_fail;
cpu_time_add(&cpu_context, &tmp, init);
continue;
}
if (strncmp(line, "cpu", 3))
continue;
if (sscanf(line, "%s %d %d %d %d %d %d %d",
tag,
&tmp.user,
&tmp.nice,
&tmp.sys,
&tmp.idle,
&tmp.io,
&tmp.irq,
&tmp.softirq) < 8)
goto parse_fail;
if (!strcmp(tag, "cpu"))
cpu_time_add(&cpu_time_total, &tmp, init);
else if (!strncmp(tag, "cpu", 3)) {
index = atoi(&tag[3]);
if ((index >= 0) && (index < MAX_CORE))
cpu_time_add(&cpu_time[index], &tmp, init);
}
}
if (!init && cpu_core_info) {
printf(" %10s %10s %10s %10s %10s %10s %10s\n",
"user", "nice", "sys", "idle", "io", "irq", "sirq");
for (i = 0; i < MAX_CORE + 1; i++) {
cpu_time_t *t;
if (i == MAX_CORE) {
printf("total ");
t = &cpu_time_total;
}
else {
printf("cpu%d ", i);
t = &cpu_time[i];
}
printf(" %10d %10d %10d %10d %10d %10d %10d\n",
t->user,
t->nice,
t->sys,
t->idle,
t->io,
t->irq,
t->softirq);
}
printf("Context switches: %d\n", cpu_context.context);
}
fclose(fp);
return;
parse_fail:
WARN("# FAIL: Failed to parse %s\n", line);
exit(1);
}
#else
/******************************************************************************
* function:
* read_stat_systemctl (int init)
*
* @param init [IN] - op flag
*
* description:
* read in CPU status from systemctl system call using kern.cp_time and
kern.cp_times
******************************************************************************/
static void read_stat_systemctl (int init)
{
int index = 0;
int i;
int core;
cpu_time_t tmp;
long cputotal[CPU_STATES];
long pcpustat[CP_STAT_SIZE];
size_t cputotal_size;
size_t pcpustat_size;
cputotal_size = sizeof(cputotal);
pcpustat_size = sizeof(pcpustat);
if (sysctlbyname("kern.cp_time", &cputotal, &cputotal_size, NULL, 0) < 0) {
WARN("#FAIL: Error reading kern.cp_time sysctl : %s\n",
strerror(errno));
exit(1);
}
tmp.user = (int) cputotal[CP_USER];
tmp.nice = (int) cputotal[CP_NICE];
tmp.sys = (int) cputotal[CP_SYS];
tmp.intr = (int) cputotal[CP_INTR];
tmp.idle = (int) cputotal[CP_IDLE];
cpu_time_add(&cpu_time_total, &tmp, init);
if (sysctlbyname("kern.cp_times", &pcpustat, &pcpustat_size, NULL, 0) < 0) {
WARN("#FAIL: Error reading kern.cp_times sysctl : %s\n",
strerror(errno));
exit(1);
}
core = 0;
for (index = 0; index < CP_STAT_SIZE; index += CPU_STATES) {
tmp.user = (int) pcpustat[index + CP_USER];
tmp.nice = (int) pcpustat[index + CP_NICE];
tmp.sys = (int) pcpustat[index + CP_SYS];
tmp.intr = (int) pcpustat[index + CP_INTR];
tmp.idle = (int) pcpustat[index + CP_IDLE];
if(core < MAX_CORE + 1)
cpu_time_add(&cpu_time[core], &tmp, init);
core = core + 1;
}
if (!init && cpu_core_info) {
printf(" %10s %10s %10s %10s %10s\n", "user", "nice", "sys",
"intr", "idle");
for (i = 0; i < MAX_CORE + 1; i++) {
cpu_time_t *t;
if (i == MAX_CORE) {
printf("total ");
t = &cpu_time_total;
}
else {
printf("cpu%d ", i);
t = &cpu_time[i];
}
printf(" %10d %10d %10d %10d %10d\n", t->user, t->nice,
t->sys, t->intr, t->idle);
}
}
return;
}
#endif
/******************************************************************************
* function:
* rdtsc (void)
* description:
* Timestamp Counter for measuring clock cycles in performance testing.
******************************************************************************/
static __inline__ unsigned long long rdtsc(void)
{
unsigned long a, d;
asm volatile ("rdtsc":"=a" (a), "=d"(d));
return (((unsigned long long)a) | (((unsigned long long)d) << 32));
}
/******************************************************************************
* function:
* *test_name(int test)
*
* @param test [IN] - test case
*
* description:
* test_name selection list
******************************************************************************/
char *test_name(int test)
{
switch (test) {
case TEST_RSA:
return "RSA";
case TEST_ECDH:
return "ECDH";
case TEST_ECDSA:
return "ECDSA";
case TEST_ECX:
return "ECX";
case TEST_AES128_GCM:
return "AES128 GCM";
case TEST_AES256_GCM:
return "AES256 GCM";
case TEST_AES128_CCM:
return "AES128 CCM";
case TEST_AES192_CCM:
return "AES192 CCM";
case TEST_AES256_CCM:
return "AES256 CCM";
case TEST_SM3:
return "SM3";
case TEST_DSA:
return "DSA";
case TEST_DH:
return "DH";
case TEST_PRF:
return "PRF";
case TEST_HKDF:
return "HKDF";
case TEST_AES128_CBC_HMAC_SHA1:
return "AES128 CBC HMAC SHA1";
case TEST_AES256_CBC_HMAC_SHA1:
return "AES256 CBC HMAC SHA1";
case TEST_AES128_CBC_HMAC_SHA256:
return "AES128 CBC HMAC SHA256";
case TEST_AES256_CBC_HMAC_SHA256:
return "AES256 CBC HMAC SHA256";
case TEST_SHA3_224:
return "SHA3-224";
case TEST_SHA3_256:
return "SHA3-256";
case TEST_SHA3_384:
return "SHA3-384";
case TEST_SHA3_512:
return "SHA3-512";
case TEST_CHACHA20_POLY1305:
return "CHACHA20-POLY1305";
case TEST_SM4_CBC:
return "SM4-CBC";
case TEST_SM4_GCM:
return "SM4-GCM";
case TEST_SM4_CCM:
return "SM4-CCM";
case TEST_SM2:
return "SM2";
case TEST_SHA2_224:
return "SHA2-224";
case TEST_SHA2_256:
return "SHA2-256";
case TEST_SHA2_384:
return "SHA2-384";
case TEST_SHA2_512:
return "SHA2-512";
case 0:
return "all tests";
default:
return "*unknown or not supported on this platform*";
}
}
/******************************************************************************
* function:
* *ecdh_curve__name(int type)
*
* @param test [IN] - curve type
*
* description:
* ecdh curve name selection list
******************************************************************************/
char *ecdh_curve_name(int type)
{
switch (type) {
case P_CURVE_192:
return "NIST Prime-Curve P-192";
case P_CURVE_224:
return "NIST Prime-Curve P-224";
case P_CURVE_256:
return "NIST Prime-Curve P-256";
case P_CURVE_384:
return "NIST Prime-Curve P-384";
case P_CURVE_521:
return "NIST Prime-Curve P-521";
case K_CURVE_163:
return "NIST Binary-Curve K-163";
case K_CURVE_233:
return "NIST Binary-Curve K-233";
case K_CURVE_283:
return "NIST Binary-Curve K-283";
case K_CURVE_409:
return "NIST Binary-Curve K-409";
case K_CURVE_571:
return "NIST Binary-Curve K-571";
case B_CURVE_163:
return "NIST Binary-Curve B-163";
case B_CURVE_233:
return "NIST Binary-Curve B-233";
case B_CURVE_283:
return "NIST Binary-Curve B-283";
case B_CURVE_409:
return "NIST Binary-Curve B-409";
case B_CURVE_571:
return "NIST Binary-Curve B-571";
case P_CURVE_SM2:
return "SM2 Curve";
case 0:
return "all curves";
default:
return "*unknown*";
}
}
char *size(int type)
{
switch (type) {
case KEY_2048_224:
return "DSA key 2048-224";
case KEY_2048_256:
return "DSA key 2048-256";
case 0:
return "all curves";
default:
return "*unknown*";
}
}
/******************************************************************************
* function:
* usage(char *program)
*
*
* @param program [IN] - input argument
*
* description:
* test application usage help
******************************************************************************/
static void usage(char *program)
{
printf("\nUsage:\n");
printf("\t%s [-c <count>] ", program);
printf("[-n <count>] [-nc <count>] [-af] [-p] [-v] ");
#ifdef QAT_OPENSSL_3
printf("[-callback] ");
#endif
printf("[-u] [-perf] [-x] [-z] [-epoll] [-poll] [-f] [-engine <string>] ");
printf("[-ne] [-tls_version <tls>] [-di <digest>] ");
printf("[-async_jobs <count>] [-prf_op <op>] ");
printf("[-hkdf_op <op>]");
printf("[-sw_fallback] ");
printf("[-sign] [-verify] [-encrypt] [-decrypt] [-h] [<test>] \n");
printf("Where:\n");
printf("\t-c specifies the test iteration count\n");
printf("\t-n specifies the number of threads to run\n");
printf("\t-nc specifies the number of CPU cores\n");
printf("\t-af enables core affinity\n");
printf("\t-p print the test output\n");
printf("\t-v verify the output\n");
#ifdef QAT_OPENSSL_3
printf("\t-callback enable callback mode in asynchronous processing\n");
#endif
printf("\t-u display cpu usage per core\n");
printf("\t-perf run performance measurement\n");
printf("\t-x force EVP layer calls to use an explicit engine.\n");
printf("\t Note: This will cause any calls that are not implemented\n");
printf("\t by the engine under test to fail.\n");
printf("\t-z enable zero copy mode\n");
printf("\t-epoll enable event driven polling\n");
printf("\t-poll enable external polling of the engine (qat engine only)\n");
printf("\t-f specifies whether to enable(1) or disable(0) KDF for ECDH \n");
printf("\t-engine specify the engine to use, eg -engine qatengine (default is software)\n");
printf("\t-hw_algo specify the hw algorithm enabling bitmap\n");
printf("\t-sw_algo specify the sw algorithm enabling bitmap\n");
printf("\t-provider specify the provider to use, eg -provider qat (default is software)\n");
printf("\t-ne enables negative scenario test cases \n");
printf("\t-tls_version specifies tls_version TLSv1,TLSv1_1, TLSv1_2 \n");
printf("\t-di specifies digest for prf and hkdf (OpenSSL_1.1.1 & higher), MD5, SHA256, SHA384, SHA512 \n");
printf("\t-async_jobs enable asynchronous processing and specifies the number of asynchronous jobs per thread\n");
printf("\t-prf_op specifies the PRF operation required (default is to run them all)\n");
printf("\t-hkdf_op specifies the HKDF operation (0-Extract&Expand 1-Extract 2-Expand (default is to run them all))\n");
printf("\t-sw_fallback enables the sw fallback feature (qat engine only)\n");
printf("\t-sign sign only\n");
printf("\t-verify verify only\n");
printf("\t-encrypt encrypt only\n");
printf("\t-decrypt decrypt only\n");
printf("\t-h print this usage\n");
printf("\nTests:\n");
printf("\trsa1024 RSA 1024 test\n");
printf("\trsa2048 RSA 2048 test\n");
printf("\trsa3072 RSA 3072 test\n");
printf("\trsa4096 RSA 4096 test\n");
printf("\trsa8192 RSA 8192 test\n");
printf("\tdsa1024 DSA 1024 test\n");
printf("\tdsa2048 DSA 2048 test\n");
printf("\tdsa3072 DSA 3072 test\n");
printf("\tdsa4096 DSA 4096 test\n");
printf("\tdh512 DH 1024 test\n");
printf("\tdh1024 DH 1024 test\n");
printf("\tdh2048 DH 2048 test\n");
printf("\tdh3072 DH 3072 test\n");
printf("\tdh4096 DH 4096 test\n");
printf("\tdh8192 DH 8192 test\n");
printf("\taes128_cbc_hmac_sha1 AES128 CBC HMAC SHA1 test\n");
printf("\taes256_cbc_hmac_sha1 AES256 CBC HMAC SHA1 test\n");
printf("\taes128_cbc_hmac_sha256 AES128 CBC HMAC SHA256 test\n");
printf("\taes256_cbc_hmac_sha256 AES256 CBC HMAC SHA256 test\n");
/* ECDH options */
printf("\tecdhp192 ECDH P192 test\n");
printf("\tecdhp224 ECDH P224 test\n");
printf("\tecdhp256 ECDH P256 test\n");
printf("\tecdhp384 ECDH P384 test\n");
printf("\tecdhp521 ECDH P521 test\n");
printf("\tecdhk163 ECDH K163 test\n");
printf("\tecdhk233 ECDH K233 test\n");
printf("\tecdhk283 ECDH K283 test\n");
printf("\tecdhk409 ECDH K409 test\n");
printf("\tecdhk571 ECDH K571 test\n");
printf("\tecdhb163 ECDH B163 test\n");
printf("\tecdhb233 ECDH B233 test\n");
printf("\tecdhb283 ECDH B283 test\n");
printf("\tecdhb409 ECDH B409 test\n");
printf("\tecdhb571 ECDH B571 test\n");
printf("\tecdhsm2 ECDH SM2 test\n");
/* ECX options */
printf("\tecdhx25519 ECX25519 test\n");
printf("\tecdhx448 ECX448 test\n");
/* ECDSA options */
printf("\tecdsap192 ECDSA P192 test\n");
printf("\tecdsap224 ECDSA P224 test\n");
printf("\tecdsap256 ECDSA P256 test\n");
printf("\tecdsap384 ECDSA P384 test\n");
printf("\tecdsap521 ECDSA P521 test\n");
printf("\tecdsak163 ECDSA K163 test\n");
printf("\tecdsak233 ECDSA K233 test\n");
printf("\tecdsak283 ECDSA K283 test\n");
printf("\tecdsak409 ECDSA K409 test\n");
printf("\tecdsak571 ECDSA K571 test\n");
printf("\tecdsab163 ECDSA B163 test\n");
printf("\tecdsab233 ECDSA B233 test\n");
printf("\tecdsab283 ECDSA B283 test\n");
printf("\tecdsab409 ECDSA B409 test\n");
printf("\tecdsab571 ECDSA B571 test\n");
printf("\tprf PRF test\n");
printf("\thkdf HKDF test\n");
printf("\taes128gcm AES128 GCM test\n");
printf("\taes256gcm AES256 GCM test\n");
printf("\taes128ccm AES128 CCM test\n");
printf("\taes192ccm AES192 CCM test\n");
printf("\taes256ccm AES256 CCM test\n");
printf("\tsha3-224 SHA3 224 test\n");
printf("\tsha3-256 SHA3 256 test\n");
printf("\tsha3-384 SHA3 384 test\n");
printf("\tsha3-512 SHA3 512 test\n");
printf("\tsm3 SM3 test\n");
printf("\tsm4-cbc SM4 CBC test\n");
printf("\tsm4-gcm SM4 GCM test\n");
printf("\tsm4-ccm SM4 CCM test\n");
printf("\tchachapoly CHACHAPOLY test\n\n");
printf("\tsha2-224 SHA2 224 test\n");
printf("\tsha2-256 SHA2 256 test\n");
printf("\tsha2-384 SHA2 384 test\n");
printf("\tsha2-512 SHA2 512 test\n");
printf("\tsm2 SM2 test\n\n");
printf("\nIf test algo is not specified, default tests"
"(RSA, ECDH, ECDSA) will be executed.\n");
/* In order to measure the maximum throughput from QAT, the iteration
* test will repeat actual operation to keep QAT busy without reset
* input variables such as initial vector. Thus, the iteration count should
* limited to one for verification propose.
*/
printf("The test iteration count will set to 1 if the verify flag raised.\n\n");
exit(EXIT_SUCCESS);
}
/******************************************************************************
* function:
* parse_option(int *index,
* int argc,
* char *argv[],
* int *value)
*
* @param index [IN] - index pointer
* @param argc [IN] - input argument count
* @param argv [IN] - argument buffer
* @param value [IN] - input value pointer
*
* description:
* user input arguments check
******************************************************************************/
static void parse_option(int *index, int argc, char *argv[], int *value)
{
if (*index + 1 >= argc) {
printf("\n# FAIL: Parameter expected\n");
usage(argv[0]);
exit(EXIT_FAILURE);
}
(*index)++;
*value = atoi(argv[*index]);
}
/******************************************************************************
* function:
* parse_option_string(int *index,
* int argc,
* char *argv[],
* char *str
*
* @param index [IN] - index pointer
* @param argc [IN] - input argument count
* @param argv [IN] - argument buffer
* @param str [IN] - char * pointer to store the string
*
* description:
* user input arguments check
******************************************************************************/
static void parse_option_string(int *index, int argc, char *argv[], char **str)
{
if (*index + 1 >= argc) {
printf("\n# FAIL: Parameter expected\n");
usage(argv[0]);
exit(EXIT_FAILURE);
}
(*index)++;
*str = argv[*index];
}
/******************************************************************************
* function:
* handle_option(int argc,
* char *argv[],
* int *index)
*
* @param argc [IN] - input argument count
* @param argv [IN] - argument buffer
* @param index [IN] - index pointer
*
* description:
* input operation handler
******************************************************************************/
static void handle_option(int argc, char *argv[], int *index)
{
char *option = argv[*index];
int i, size;
if (!strcmp(option, "-n"))
parse_option(index, argc, argv, &thread_count);
else if (!strcmp(option, "-perf"))
enable_perf = 1;
#ifdef QAT_OPENSSL_3
else if (!strcmp(option, "-callback"))
use_callback_mode = 1;
#endif
else if (!strcmp(option, "-epoll"))
enable_event_driven_polling = 1;
else if (!strcmp(option, "-poll"))
enable_external_polling = 1;
else if (!strcmp(option, "-c"))
parse_option(index, argc, argv, &test_count);
else if (!strcmp(option, "-af"))
cpu_affinity = 1;
else if (!strcmp(option, "-nc"))
parse_option(index, argc, argv, &core_count);
else if (!strcmp(option, "-engine")) {
parse_option_string(index, argc, argv, &engine_id);
enable_engine = 1;
printf("[%s] engine enabled ! \n", engine_id);
} else if (!strcmp(option, "-provider")) {
parse_option_string(index, argc, argv, &prov_id);
enable_provider = 1;
printf("[%s] provider enabled ! \n", prov_id);
} else if (!strcmp(option, "-p"))
print_output = 1;
else if (!strcmp(option, "-v"))
verify = 1;
else if (!strcmp(option, "-sign"))
sign_only = 1;
else if (!strcmp(option, "-verify"))
verify_only = 1;
else if (!strcmp(option, "-encrypt"))
encrypt_only = 1;
else if (!strcmp(option, "-decrypt"))
decrypt_only = 1;
else if (!strcmp(option, "dh"))
test_alg = TEST_DH;
else if (!strcmp(option, "prf"))
test_alg = TEST_PRF;
else if (!strcmp(option, "sm3"))
test_alg = TEST_SM3;
else if (!strcmp(option, "sm4-cbc"))
test_alg = TEST_SM4_CBC;
else if (!strcmp(option, "sm4-gcm"))
test_alg = TEST_SM4_GCM;
else if (!strcmp(option, "sm4-ccm"))
test_alg = TEST_SM4_CCM;
else if (!strcmp(option, "hkdf"))
test_alg = TEST_HKDF;
else if (!strcmp(option, "chachapoly")) {
test_alg = TEST_CHACHA20_POLY1305;
test_size = 4096;
} else if (!strcmp(option, "sm2")){
test_alg = TEST_SM2;
curve = P_CURVE_SM2;
} else if (!strncmp(option, "rsa", strlen("rsa"))) {
size = sizeof(rsa_choices) / sizeof(option_data);
for (i = 0; i < size; i++)
if (!strcmp(option, rsa_choices[i].name)) {
test_size = rsa_choices[i].test_size;
test_alg = rsa_choices[i].test_alg;
break;
}
} else if (!strncmp(option, "dsa", strlen("dsa"))) {
size = sizeof(dsa_choices) / sizeof(option_data);
for (i = 0; i < size; i++)
if (!strcmp(option, dsa_choices[i].name)) {
test_size = dsa_choices[i].test_size;
test_alg = dsa_choices[i].test_alg;
break;
}
} else if (!strncmp(option, "dh", strlen("dh"))) {
size = sizeof(dh_choices) / sizeof(option_data);
for (i = 0; i < size; i++)
if (!strcmp(option, dh_choices[i].name)) {
test_size = dh_choices[i].test_size;
test_alg = dh_choices[i].test_alg;
break;
}
} else if (!strncmp(option, "ecdh", strlen("ecdh"))) {
size = sizeof(ecdh_choices) / sizeof(option_data);
for (i = 0; i < size; i++)
if (!strcmp(option, ecdh_choices[i].name)) {
printf ("name %s\n", ecdh_choices[i].name);
curve = ecdh_choices[i].curve_name;
test_alg = ecdh_choices[i].test_alg;
break;
}
} else if (!strncmp(option, "ecdsa", strlen("ecdsa"))) {
size = sizeof(ecdsa_choices) / sizeof(option_data);
for (i = 0; i < size; i++)
if (!strcmp(option, ecdsa_choices[i].name)) {
curve = ecdsa_choices[i].curve_name;
test_alg = ecdsa_choices[i].test_alg;
break;
}
} else if (!strncmp(option, "aes", strlen("aes"))) {
size = sizeof(aes_choices) / sizeof(option_data);
for (i = 0; i < size; i++)
if (!strcmp(option, aes_choices[i].name)) {
test_alg = aes_choices[i].test_alg;
break;
}
} else if (!strncmp(option, "sha3", strlen("sha3"))) {
size = sizeof(sha3_choices) / sizeof(option_data);
for (i = 0; i < size; i++)
if (!strcmp(option, sha3_choices[i].name)) {
test_alg = sha3_choices[i].test_alg;
test_size = 4096;
break;
}
} else if (!strncmp(option, "sha2", strlen("sha2"))) {
size = sizeof(sha2_choices) / sizeof(option_data);
for (i = 0; i < size; i++)
if (!strcmp(option, sha2_choices[i].name)) {
test_alg = sha2_choices[i].test_alg;
test_size = 4096;
break;
}
} else if (!strcmp(option, "-f"))
parse_option(index, argc, argv, &kdf);
else if (!strcmp(option, "-x"))
explicit_engine = 1;
else if (!strcmp(option, "-z"))
zero_copy = 1;
else if (!strcmp(option, "-u"))
cpu_core_info = 1;
else if (!strcmp(option, "-tls_version"))
parse_option_string(index, argc, argv, &tls_version);
else if(!strcmp(option, "-ne"))
enable_negative = 1;
else if (!strcmp(option, "-di"))
parse_option_string(index, argc, argv, &digest_kdf);
else if (!strcmp(option, "-async_jobs")) {
parse_option(index, argc, argv, &async_jobs);
if (async_jobs <= 0) {
printf("\n# FAIL: Invalid number of async_jobs.\n");
usage(argv[0]);
exit(EXIT_FAILURE);
}
enable_async = 1;
}
else if (!strcmp(option, "-prf_op")) {
parse_option(index, argc, argv, &prf_op);
if (prf_op < 0 || prf_op > 4) {
printf("\n# FAIL: Invalid prf_op number.\n");
usage(argv[0]);
exit(EXIT_FAILURE);
}
}
else if (!strcmp(option, "-hkdf_op")) {
parse_option(index, argc, argv, &hkdf_op);
if (hkdf_op < 0 || hkdf_op > 2) {
printf("\n# FAIL: Invalid hkdf_op number.\n");
usage(argv[0]);
exit(EXIT_FAILURE);
}
}
else if (!strcmp(option, "-sw_fallback"))
sw_fallback = 1;
else if (!strcmp(option, "-h"))
usage(argv[0]);
else if (!strcmp(option, "-sw_algo")) {
parse_option_string(index, argc, argv, &sw_algo_bitmap);
}
else if (!strcmp(option, "-hw_algo")) {
parse_option_string(index, argc, argv, &hw_algo_bitmap);
}
else {
printf("\n# FAIL: Invalid option '%s'\n", option);
usage(argv[0]);
exit(EXIT_FAILURE);
}
if (verify) {
test_count = 1;
core_count = 1;
thread_count = 1;
}
}
/******************************************************************************
* function:
* *thread_worker(void *arg)
*
* @param arg [IN] - thread structure info
*
* description:
* thread worker setups. the threads will launch at the same time after
* all of them in ready condition.
******************************************************************************/
static void *thread_worker(void *arg)
{
THREAD_INFO *info = (THREAD_INFO *) arg;
if (enable_engine && !enable_external_polling){
ENGINE_ctrl_cmd(engine,"SET_INSTANCE_FOR_THREAD",info->id,NULL,NULL,0);
}
/* mutex lock for thread count */
pthread_mutex_lock(&mutex);
ready_thread_count++;
pthread_cond_broadcast(&ready_cond);
pthread_mutex_unlock(&mutex);
/* waiting for thread clearance */
pthread_mutex_lock(&mutex);
while (!cleared_to_start)
pthread_cond_wait(&start_cond, &mutex);
pthread_mutex_unlock(&mutex);
tests_run(info->test_params, info->id);
/* update active threads */
pthread_mutex_lock(&mutex);
active_thread_count--;
pthread_cond_broadcast(&stop_cond);
pthread_mutex_unlock(&mutex);
return NULL;
}
/******************************************************************************
* function:
* performance_test(void)
*
* description:
* performers test application running on user definition .
******************************************************************************/
static void performance_test(void)
{
int i, j;
int coreID = 0;
int sts = 1;
qat_cpuset cpuset;
struct timeval start_time;
struct timeval stop_time;
int elapsed = 0;
unsigned long long rdtsc_start = 0;
unsigned long long rdtsc_end = 0;
int bytes_to_bits = 8;
int crypto_ops_per_test = 1;
float throughput = 0.0;
char name[20];
THREAD_INFO *info = NULL;
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&ready_cond, NULL);
pthread_cond_init(&start_cond, NULL);
pthread_cond_init(&stop_cond, NULL);
for (i = 0; i < thread_count; i++) {
info = &tinfo[i];
info->id = i;
info->count = (test_count / thread_count) / async_jobs;
info->test_params = OPENSSL_malloc(sizeof(TEST_PARAMS));
if (info->test_params == NULL) {
WARN("# FAIL: Unable to allocate info->test_params\n");
exit(EXIT_FAILURE);
}
memset(info->test_params, 0, sizeof(TEST_PARAMS));
info->test_params->engine_id = engine_id;
info->test_params->count = &info->count;
info->test_params->type = test_alg;
info->test_params->size = test_size;
info->test_params->e = engine;
info->test_params->print_output = print_output;
info->test_params->verify = verify;
info->test_params->performance = enable_perf;
info->test_params->enable_external_polling = enable_external_polling;
info->test_params->enable_event_driven_polling =
enable_event_driven_polling;
info->test_params->enable_async = enable_async;
#ifdef QAT_OPENSSL_3
info->test_params->use_callback_mode = use_callback_mode;
#endif
info->test_params->enable_negative = enable_negative;
info->test_params->curve = curve;
info->test_params->kdf = kdf;
info->test_params->tls_version = tls_version;
info->test_params->digest_kdf = digest_kdf;
info->test_params->explicit_engine = explicit_engine;
info->test_params->sign_only = sign_only;
info->test_params->verify_only = verify_only;
info->test_params->encrypt_only = encrypt_only;
info->test_params->decrypt_only = decrypt_only;
info->test_params->async_jobs = async_jobs;
info->test_params->prf_op = prf_op;
info->test_params->hkdf_op = hkdf_op;
info->test_params->jobs = OPENSSL_malloc(sizeof(ASYNC_JOB*)*async_jobs);
if (info->test_params->jobs == NULL) {
WARN("# FAIL: Unable to allocate info->test_params->jobs\n");
exit(EXIT_FAILURE);
}
info->test_params->awcs = OPENSSL_malloc(
sizeof(ASYNC_WAIT_CTX*)*async_jobs);
if (info->test_params->awcs == NULL) {
WARN("# FAIL: Unable to allocate info->test_params->awcs\n");
exit(EXIT_FAILURE);
}
memset(info->test_params->jobs, 0, sizeof(ASYNC_JOB*)*async_jobs);
memset(info->test_params->awcs, 0, sizeof(ASYNC_WAIT_CTX*)*async_jobs);
for (j =0; j < async_jobs; j++) {
info->test_params->awcs[j] = ASYNC_WAIT_CTX_new();
if (info->test_params->awcs[j] == NULL) {
WARN("# FAIL: Unable to allocate info->test_params->awcs[%d]\n",
j);
exit(EXIT_FAILURE);
}
}
pthread_create(&tinfo[i].th, NULL, thread_worker, (void *)&tinfo[i]);
sprintf(name, "worker-%d", i);
/* cpu affinity setup */
if (cpu_affinity == 1) {
CPU_ZERO(&cpuset);
/* assigning thread to different cores */
coreID = (i % core_count);
CPU_SET(coreID, &cpuset);
sts = pthread_setaffinity_np(info->th, sizeof(qat_cpuset), &cpuset);
if (sts != 0) {
WARN("# FAIL: pthread_setaffinity_np error, status = %d \n",
sts);
exit(EXIT_FAILURE);
}
sts = pthread_getaffinity_np(info->th, sizeof(qat_cpuset), &cpuset);
if (sts != 0) {
WARN("# FAIL: pthread_getaffinity_np error, status = %d \n",
sts);
exit(EXIT_FAILURE);
}
if (CPU_ISSET(coreID, &cpuset))
printf("Thread %d assigned on CPU core %d\n", i, coreID);
}
}
/* set all threads to ready condition */
pthread_mutex_lock(&mutex);
while (ready_thread_count < thread_count)
pthread_cond_wait(&ready_cond, &mutex);
pthread_mutex_unlock(&mutex);
printf("Beginning test ....\n");
/* all threads start at the same time */
#ifdef __FreeBSD__
read_stat_systemctl(1);
#else
read_stat(1);
#endif
gettimeofday(&start_time, NULL);
rdtsc_start = rdtsc();
pthread_mutex_lock(&mutex);
cleared_to_start = 1;
pthread_cond_broadcast(&start_cond);
pthread_mutex_unlock(&mutex);
/* wait for other threads stop */
pthread_mutex_lock(&mutex);
while (active_thread_count > 0)
pthread_cond_wait(&stop_cond, &mutex);
pthread_mutex_unlock(&mutex);
for (i = 0; i < thread_count; i++) {
if (pthread_join(tinfo[i].th, NULL))
printf("Could not join thread id - %d !\n", i);
}
rdtsc_end = rdtsc();
gettimeofday(&stop_time, NULL);
#ifdef __FreeBSD__
read_stat_systemctl(0);
#else
read_stat(0);
#endif
printf("All threads complete\n\n");
/* generate report */
elapsed = (stop_time.tv_sec - start_time.tv_sec) * 1000000 +
(stop_time.tv_usec - start_time.tv_usec);
/* Cipher tests contain 2 performOp calls. */
crypto_ops_per_test = 2;
/* Cast test_size * test_count to avoid int overflow */
throughput = ((float)test_size * (float)test_count *
(bytes_to_bits * crypto_ops_per_test) / (float)elapsed);
printf("Elapsed time = %.3f msec\n", (float)elapsed / 1000);
printf("Operations = %d\n", test_count);
printf("Time per op = %.3f usec (%d ops/sec)\n",
(float)elapsed / test_count,
(int)((float)test_count * 1000000.0 / (float)elapsed));
printf("Elapsed cycles = %llu\n", rdtsc_end - rdtsc_start);
printf("Throughput = %.2f (Mbps)\n", throughput);
if (enable_engine){
ENGINE_ctrl_cmd(engine, "GET_NUM_OP_RETRIES", 0,
&qatPerformOpRetries,NULL,0);
printf("Retries = %d\n", qatPerformOpRetries);
}
printf("\nCSV summary:\n");
printf("Algorithm,"
"Test_type,"
"Using_engine,"
"Core_affinity,"
"Elapsed_usec,"
"Cores,"
"Threads,"
"Count,"
"Data_size,"
"Mbps,"
"CPU_time,"
"User_time,"
"Kernel_time\n");
int cpu_time = 0;
int cpu_user = 0;
int cpu_kernel = 0;
#ifdef __FreeBSD__
cpu_time = (cpu_time_total.user +
cpu_time_total.nice +
cpu_time_total.sys +
cpu_time_total.intr) * 10000 / core_count;
#else
cpu_time = (cpu_time_total.user +
cpu_time_total.nice +
cpu_time_total.sys +
cpu_time_total.io +
cpu_time_total.irq +
cpu_time_total.softirq) * 10000 / core_count;
#endif
cpu_user = cpu_time_total.user * 10000 / core_count;
cpu_kernel = cpu_time_total.sys * 10000 / core_count;
printf("csv,%s,%d,%s,%s,%d,%d,%d,%d,%d,%.2f,%d,%d,%d\n",
test_name(test_alg),
test_alg,
(enable_engine) ? "Yes" : "No",
cpu_affinity ? "Yes" : "No",
elapsed,
core_count, thread_count, test_count, test_size, throughput,
cpu_time * 100 / elapsed,
cpu_user * 100 / elapsed,
cpu_kernel * 100 / elapsed);
for (i = 0; i < thread_count; i++) {
info = &tinfo[i];
for (j =0; j < async_jobs; j++)
ASYNC_WAIT_CTX_free(info->test_params->awcs[j]);
if (info->test_params->awcs)
OPENSSL_free(info->test_params->awcs);
if (info->test_params->jobs)
OPENSSL_free(info->test_params->jobs);
if (info->test_params)
OPENSSL_free(info->test_params);
}
}
/******************************************************************************
* function:
* functional_test(void)
*
* description:
* Default testing application, a single thread test running through all the
* test cases with testing function definition values
******************************************************************************/
static void functional_test(void)
{
int i;
int count = 1;
TEST_PARAMS args;
args.engine_id = engine_id;
args.count = &test_count;
args.type = test_alg;
args.size = test_size;
args.e = engine;
args.print_output = print_output;
args.verify = verify;
args.performance = enable_perf;
args.enable_external_polling = enable_external_polling;
args.enable_event_driven_polling = enable_event_driven_polling;
args.enable_async = enable_async;
#ifdef QAT_OPENSSL_3
args.use_callback_mode = use_callback_mode;
#endif
args.enable_negative = enable_negative;
args.curve = curve;
args.kdf = kdf;
args.tls_version = tls_version;
args.digest_kdf = digest_kdf;
args.explicit_engine = explicit_engine;
args.sign_only = sign_only;
args.verify_only = verify_only;
args.encrypt_only = encrypt_only;
args.decrypt_only = decrypt_only;
args.async_jobs = async_jobs;
args.prf_op = prf_op;
args.hkdf_op = hkdf_op;
args.sw_fallback = sw_fallback;
args.jobs = OPENSSL_malloc(sizeof(ASYNC_JOB*)*async_jobs);
if (args.jobs == NULL) {
WARN("# FAIL: Unable to allocate args.jobs\n");
exit(EXIT_FAILURE);
}
args.awcs = OPENSSL_malloc(sizeof(ASYNC_WAIT_CTX*)*async_jobs);
if (args.awcs == NULL) {
WARN("# FAIL: Unable to allocate args.awcs\n");
exit(EXIT_FAILURE);
}
memset(args.jobs, 0, sizeof(ASYNC_JOB*)*async_jobs);
memset(args.awcs, 0, sizeof(ASYNC_WAIT_CTX*)*async_jobs);
for (i =0; i < async_jobs; i++) {
args.awcs[i] = ASYNC_WAIT_CTX_new();
if (args.awcs[i] == NULL) {
WARN("# FAIL: Unable to allocate args.awcs[%d]\n", i);
exit(EXIT_FAILURE);
}
}
if (test_alg == 0) {
args.size = DEFAULT_KEY_SIZE;
args.verify = 1;
args.count = &count;
args.enable_negative = enable_negative;
args.curve = P_CURVE_256;
args.kdf = kdf;
args.explicit_engine = explicit_engine;
args.sign_only = 1;
printf("\nResults for functional test cases: force variables:- \nverify = %d, count = %d, size = %d\n",
args.verify, *(args.count), args.size);
/* Default case, only run tests supported by both QAT_HW and QAT_SW */
for (i = 1; i <= TEST_ECX; i++) {
args.type = i;
tests_run(&args, 0);
}
} else if (test_alg == TEST_TYPE_MAX - 1) {
args.count = &test_count;
tests_run(&args, 0);
} else {
tests_run(&args, 0);
}
for (i =0; i < async_jobs; i++)
ASYNC_WAIT_CTX_free(args.awcs[i]);
OPENSSL_free(args.awcs);
OPENSSL_free(args.jobs);
}
/******************************************************************************
* function:
* main(int argc,
* char *argv[])
*
* @param argc [IN] - input argument count
* @param argv [IN] - argument buffer
*
* description:
* main function is used to setups QAT engine setups and define the testing
* type.
******************************************************************************/
int main(int argc, char *argv[])
{
int i = 0;
tls_version = default_tls_string;
digest_kdf = default_digest_string;
QAT_DEBUG_LOG_INIT();
for (i = 1; i < argc; i++) {
/*
* allow rsa, dsa, dh, aes, prf, hkdf, sha-3 , chachapoly & ecx options
* without '-' prefix
*/
if ((argv[i][0] != '-') &&
(argv[i][0] != 'r') &&
(argv[i][0] != 'd') &&
(argv[i][0] != 'a') &&
(argv[i][0] != 'e') &&
(argv[i][0] != 'p') &&
(argv[i][0] != 'h') &&
(argv[i][0] != 's') &&
(argv[i][0] != 'c'))
break;
handle_option(argc, argv, &i);
}
/* The thread count should not be great than the test count */
if (thread_count > test_count ) {
thread_count = test_count;
printf("\nWARNING - Thread Count cannot exceed the Test Count");
printf("\nThread Count adjusted to: %d\n\n", thread_count);
}
if (i < argc) {
printf("# FAIL: This program does not take arguments, please use -h for usage.\n");
exit(EXIT_FAILURE);
}
active_thread_count = thread_count;
ready_thread_count = 0;
/* Zero Copy Mode is currently disabled */
if (zero_copy) {
printf("Zero copy mode is currently disabled! Running in standard mode\n");
zero_copy = 0;
}
/* Load engine for workers */
if (enable_engine) {
ENGINE_load_builtin_engines();
engine = tests_initialise_engine(engine_id, enable_external_polling,
enable_event_driven_polling,
enable_async, zero_copy, sw_fallback);
if (!engine) {
printf("# FAIL: ENGINE load error, exit! \n");
exit(EXIT_FAILURE);
}
}
#ifdef QAT_OPENSSL_PROVIDER
else if(enable_provider) {
provider = tests_initialise_provider(prov_id);
if (!provider) {
fprintf(stderr, "# FAIL: Provider load error, exit! \n");
exit(EXIT_FAILURE);
}
}
#endif
else
printf("Engine disabled! using software implementation\n");
printf("\nQAT Engine Test Application\n");
printf("\n\tCopyright (C) 2021-2025 Intel Corporation\n");
printf("\nTest Parameters:\n\n");
printf("\tTest Type: %s\n",
enable_perf ? "Performance" : "Functional");
printf("\tTest Alg: %d (%s", test_alg, test_name(test_alg));
if (sign_only) printf(" sign");
if (verify_only) printf(" verify");
if (encrypt_only) printf(" encrypt");
if (decrypt_only) printf(" decrypt");
printf(")\n");
printf("\tTest Count: %d\n", test_count);
printf("\tThread Count: %d\n", thread_count);
printf("\tMessage Size: %d\n", test_size);
printf("\tPrint Output: %s\n", print_output ? "Yes" : "No");
printf("\tCPU Core Affinity: %s\n", cpu_affinity ? "Yes" : "No");
printf("\tNumber of Cores: %d\n", core_count);
printf("\tAsynchronous: %s\n", enable_async ? "Yes" : "No");
#ifdef QAT_OPENSSL_3
printf("\tUse asynch callback: %s\n", use_callback_mode ? "Yes" : "No");
#endif
printf("\tExternal Polling: %s\n",
enable_external_polling ? "Yes" : "No");
printf("\tEvent Driven Polling: %s\n",
enable_event_driven_polling ? "Yes" : "No");
printf("\tEngine Enabled: %s\n", enable_engine ? "Yes" : "No");
printf("\tProvider Enabled: %s\n", enable_provider ? "Yes" : "No");
printf("\tForce Explicit Engine:%s\n", explicit_engine ? "Yes" : "No");
printf("\tNegative Scenario: %s\n", enable_negative ? "Yes" : "No");
printf("\tPRF TLS Version: %s\n", tls_version);
if (strcmp(tls_version, "TLSv1_2") == 0)
printf("\tKDF Digest: %s\n", digest_kdf);
if (prf_op != -1)
printf("\tPRF Operation: %d\n", prf_op);
if (hkdf_op != -1)
printf("\tHKDF Operation: %d\n", hkdf_op);
printf("\tSW Fallback: %s\n", sw_fallback ? "Yes" : "No");
printf("\n");
if (!enable_perf)
functional_test();
else
performance_test();
if (engine)
tests_cleanup_engine(engine, engine_id, enable_async,
enable_external_polling,
enable_event_driven_polling, sw_fallback);
#ifdef QAT_OPENSSL_PROVIDER
if (provider)
tests_cleanup_provider(provider);
#endif
return 0;
}
|