-
Notifications
You must be signed in to change notification settings - Fork 305
/
Copy pathperftest_resources.c
executable file
·5570 lines (4792 loc) · 165 KB
/
perftest_resources.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#if !defined(__FreeBSD__)
#include <malloc.h>
#endif
#include <getopt.h>
#include <limits.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <ctype.h>
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <pthread.h>
#if defined(__FreeBSD__)
#include <sys/stat.h>
#endif
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_SRD
#include <infiniband/efadv.h>
#endif
#include "perftest_resources.h"
#include "raw_ethernet_resources.h"
static enum ibv_wr_opcode opcode_verbs_array[] = {IBV_WR_SEND,IBV_WR_RDMA_WRITE,IBV_WR_RDMA_WRITE_WITH_IMM,IBV_WR_RDMA_READ};
static enum ibv_wr_opcode opcode_atomic_array[] = {IBV_WR_ATOMIC_CMP_AND_SWP,IBV_WR_ATOMIC_FETCH_AND_ADD};
#define CPU_UTILITY "/proc/stat"
#define DC_KEY 0xffeeddcc
struct perftest_parameters* duration_param;
struct check_alive_data check_alive_data;
/******************************************************************************
* Beginning
******************************************************************************/
#ifdef HAVE_AES_XTS
int set_valid_dek(char *dst, struct perftest_parameters *user_param)
{
char * line = NULL;
size_t len = 0;
ssize_t read;
int index = 0;
char* eptr;
char* execute = NULL;
int i;
int size;
const char file_name_letters[] = "abcdefghijklmnopqrstuvwxyz1234567890";
char file_path[AES_XTS_DEK_FILE_NAME_SIZE];
int file_letters_size = sizeof(file_name_letters)-1;
FILE* dek_file = NULL;
srand (time (NULL));
sprintf(file_path, "/tmp/");
/* + 5 because we begin to randomize after folder path /tmp/ */
for(i = 5; i < AES_XTS_DEK_FILE_NAME_SIZE - 1; i++) {
file_path[i] = file_name_letters[rand() % file_letters_size];
}
/* + 1 for the '\0' at the end of the char array*/
size = strlen(user_param->data_enc_key_app_path) + 1
+ strlen(user_param->kek_path) + 1 + strlen(file_path) + 1;
ALLOCATE(execute, char, size);
strcpy(execute, user_param->data_enc_key_app_path);
strcat(execute, " ");
strcat(execute, user_param->kek_path);
strcat(execute, " ");
strcat(execute, file_path);
if(system(execute)) {
fprintf(stderr, "Execution of %s has failed\n", execute);
free(execute);
return FAILURE;
}
free(execute);
dek_file = fopen(file_path, "r");
if(dek_file == NULL) {
fprintf(stderr, "Can not open the data_encryption_key file\n");
return FAILURE;
}
while((read = getline(&line, &len, dek_file)) != -1) {
if(index >= AES_XTS_DEK_SIZE) {
fprintf(stderr, "Invalid data_encryption_key file\n");
fclose(dek_file);
return FAILURE;
}
dst[index] = strtol(line, &eptr, 16);
index++;
}
fclose(dek_file);
remove(file_path);
return 0;
}
int set_valid_cred(char *dst, struct perftest_parameters *user_param)
{
char valid_credential[48];
char * line = NULL;
size_t len = 0;
ssize_t read;
char* eptr;
int index = 0;
FILE* cred = NULL;
cred = fopen(user_param->credentials_path, "r");
if(cred == NULL) {
fprintf(stderr, "Can not open the credentials file\n");
return FAILURE;
}
while((read = getline(&line, &len, cred)) != -1) {
if(index >= AES_XTS_CREDENTIALS_SIZE) {
fprintf(stderr, "Invalid credentials file\n");
fclose(cred);
return FAILURE;
}
valid_credential[index] = strtol(line, &eptr, 16);
index++;
}
fclose(cred);
//coverity[uninit_use_in_call]
memcpy(dst, valid_credential, sizeof(valid_credential));
return 0;
}
#endif
// cppcheck-suppress constParameter
static int next_word_string(char* input, char* output, int from_index)
{
int i = from_index;
int j = 0;
while (input[i] != ' ') {
output[j] = input[i];
j++; i++;
}
output[j]=0;
return i+1;
}
static int get_n_word_string(char *input, char *output,int from_index, int iters)
{
for (;iters > 0; iters--) {
from_index = next_word_string(input,output,from_index);
}
return from_index;
}
static void compress_spaces(char *str, char *dst)
{
for (; *str; ++str) {
*dst++ = *str;
if (isspace(*str)) {
do ++str;
while (isspace(*str));
--str;
}
}
*dst = 0;
}
static void get_cpu_stats(struct perftest_parameters *duration_param,int stat_index)
{
char* file_name = CPU_UTILITY;
FILE *fp;
fp = fopen(file_name, "r");
if (fp != NULL) {
char line[100];
if (fgets(line,100,fp) != NULL) {
char tmp[100];
int index=0;
compress_spaces(line,line);
index=get_n_word_string(line,tmp,index,2); /* skip first word */
duration_param->cpu_util_data.ustat[stat_index-1] = atoll(tmp);
get_n_word_string(line,tmp,index,3); /* skip 2 stats */
duration_param->cpu_util_data.idle[stat_index-1] = atoll(tmp);
}
fclose(fp);
}
}
/* _new_post_send.
*
* Description :
*
* Does efficient posting of work to a send
* queue using function calls instead of the struct based *ibv_post_send()*
* scheme. Inline is used to make sure that switch would be decided on
* compile time.
*
* Parameters :
*
* ctx - Test Context.
* user_param - user_parameters struct for this test.
* inl - use inline or not.
* index - qp index.
* qpt - qp type.
* op - RDMA operation code.
* connection_type - Type of the connection.
* enc - use encryption/decryption or not.
*
* Return Value : int.
*
*/
#ifdef HAVE_IBV_WR_API
static inline int _new_post_send(struct pingpong_context *ctx,
struct perftest_parameters *user_param, int inl, int index,
enum ibv_qp_type qpt, enum ibv_wr_opcode op, int connection_type, int enc)
__attribute__((always_inline));
static inline int _new_post_send(struct pingpong_context *ctx,
struct perftest_parameters *user_param, int inl, int index,
enum ibv_qp_type qpt, enum ibv_wr_opcode op, int connection_type, int enc)
{
int rc;
int wr_index = index * user_param->post_list;
struct ibv_send_wr *wr = &ctx->wr[wr_index];
#ifdef HAVE_AES_XTS
if(enc) {
int i;
struct ibv_sge sgl;
struct mlx5dv_mkey_conf_attr mkey_attr = {};
struct mlx5dv_crypto_attr crypto_attr = {};
ibv_wr_start(ctx->qpx[index]);
ctx->qpx[index]->wr_flags = IBV_SEND_INLINE;
crypto_attr.crypto_standard = MLX5DV_CRYPTO_STANDARD_AES_XTS;
sgl.addr = (uintptr_t)ctx->mr[index]->addr;
sgl.lkey = ctx->mr[index]->lkey;
sgl.length = user_param->buff_size;
mlx5dv_wr_mkey_configure(ctx->dv_qp[index], ctx->mkey[index], 3, &mkey_attr);
mlx5dv_wr_set_mkey_access_flags(ctx->dv_qp[index], IBV_ACCESS_REMOTE_READ |
IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_LOCAL_WRITE);
mlx5dv_wr_set_mkey_layout_list(ctx->dv_qp[index], 1, &sgl);
if(user_param->sig_before) {
crypto_attr.signature_crypto_order = MLX5DV_SIGNATURE_CRYPTO_ORDER_SIGNATURE_BEFORE_CRYPTO_ON_TX;
}
else {
crypto_attr.signature_crypto_order = MLX5DV_SIGNATURE_CRYPTO_ORDER_SIGNATURE_AFTER_CRYPTO_ON_TX;
}
if(user_param->encrypt_on_tx) {
crypto_attr.encrypt_on_tx = true;
}
else {
crypto_attr.encrypt_on_tx = false;
}
for(i=0; i < AES_XTS_TWEAK_SIZE; i++) {
crypto_attr.initial_tweak[i] = i;
}
for(i=0; i < AES_XTS_KEYTAG_SIZE; i++) {
crypto_attr.keytag[i] = 0;
}
crypto_attr.data_unit_size = user_param->aes_block_size;
crypto_attr.dek = ctx->dek[(ctx->dek_number%user_param->data_enc_keys_number)];
ctx->dek_number++;
mlx5dv_wr_set_mkey_crypto(ctx->dv_qp[index], &crypto_attr);
ibv_wr_complete(ctx->qpx[index]);
}
#endif
ibv_wr_start(ctx->qpx[index]);
while (wr)
{
ctx->qpx[index]->wr_id = wr->wr_id;
ctx->qpx[index]->wr_flags = wr->send_flags;
switch (op)
{
case IBV_WR_SEND:
ibv_wr_send(ctx->qpx[index]);
break;
case IBV_WR_RDMA_WRITE:
ibv_wr_rdma_write(
ctx->qpx[index],
wr->wr.rdma.rkey,
wr->wr.rdma.remote_addr);
break;
case IBV_WR_RDMA_WRITE_WITH_IMM:
ibv_wr_rdma_write_imm(
ctx->qpx[index],
wr->wr.rdma.rkey,
wr->wr.rdma.remote_addr, 0);
break;
case IBV_WR_RDMA_READ:
ibv_wr_rdma_read(
ctx->qpx[index],
wr->wr.rdma.rkey,
wr->wr.rdma.remote_addr);
break;
case IBV_WR_ATOMIC_FETCH_AND_ADD:
ibv_wr_atomic_fetch_add(
ctx->qpx[index],
wr->wr.atomic.rkey,
wr->wr.atomic.remote_addr,
wr->wr.atomic.compare_add);
break;
case IBV_WR_ATOMIC_CMP_AND_SWP:
ibv_wr_atomic_cmp_swp(
ctx->qpx[index],
wr->wr.atomic.rkey,
wr->wr.atomic.remote_addr,
wr->wr.atomic.compare_add,
wr->wr.atomic.swap);
break;
default:
fprintf(stderr, "Post send failed: unknown operation code.\n");
}
#ifdef HAVE_MLX5DV
if (qpt == IBV_QPT_DRIVER && connection_type == DC)
{
#ifdef HAVE_DCS
mlx5dv_wr_set_dc_addr_stream(
ctx->dv_qp[index],
ctx->ah[index],
ctx->r_dctn[index],
DC_KEY,
ctx->dci_stream_id[index]);
ctx->dci_stream_id[index] = (ctx->dci_stream_id[index] + 1) & (0xffffffff >> (32 - (user_param->log_active_dci_streams)));
#else
mlx5dv_wr_set_dc_addr(
ctx->dv_qp[index],
ctx->ah[index],
ctx->r_dctn[index],
DC_KEY);
#endif
}
else
#endif
if (qpt == IBV_QPT_UD) {
ibv_wr_set_ud_addr(
ctx->qpx[index],
wr->wr.ud.ah,
wr->wr.ud.remote_qpn,
wr->wr.ud.remote_qkey);
} else if (qpt == IBV_QPT_DRIVER && connection_type == SRD) {
ibv_wr_set_ud_addr(
ctx->qpx[index],
ctx->ah[index],
ctx->rem_qpn[index],
DEF_QKEY);
}
#ifdef HAVE_XRCD
else if (qpt == IBV_QPT_XRC_SEND)
{
ibv_wr_set_xrc_srqn(
ctx->qpx[index],
wr->qp_type.xrc.remote_srqn);
}
#endif
if (inl)
{
ibv_wr_set_inline_data(
ctx->qpx[index],
(void*) wr->sg_list->addr,
user_param->size);
}
else
{
#ifdef HAVE_AES_XTS
if(enc) {
ctx->qpx[index]->wr_flags = ctx->qpx[index]->wr_flags | IBV_SEND_SIGNALED;
ibv_wr_set_sge(ctx->qpx[index],
ctx->mkey[index]->lkey,
(uintptr_t)0,
user_param->size);
}
else
#endif
ibv_wr_set_sge(
ctx->qpx[index],
wr->sg_list->lkey,
wr->sg_list->addr,
user_param->size);
}
wr = wr->next;
}
rc = ibv_wr_complete(ctx->qpx[index]);
return rc;
}
/* new_post_send_*.
*
* Description :
*
* Calls _new_post_send to do posting of work to a send
* queue using function calls instead of the struct based *ibv_post_send()*
* scheme. We need a lot of functions for each combination to make sure the
* condition in _new_post_send is decided in compile-time.
*
* Parameters :
*
* ctx - Test Context.
* index - qp index.
* user_param - user_parameters struct for this test.
*
* Return Value : int.
*
*/
static int new_post_write_sge_dc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_DRIVER, opcode_verbs_array[user_param->verb], DC, 0);
}
static int new_post_write_inl_dc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 1, index, IBV_QPT_DRIVER, opcode_verbs_array[user_param->verb], DC, 0);
}
static int new_post_read_sge_dc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_DRIVER, IBV_WR_RDMA_READ, DC, 0);
}
static int new_post_send_sge_dc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_DRIVER, IBV_WR_SEND, DC, 0);
}
static int new_post_send_inl_dc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 1, index, IBV_QPT_DRIVER, IBV_WR_SEND, DC, 0);
}
static int new_post_atomic_fa_sge_dc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_DRIVER, IBV_WR_ATOMIC_FETCH_AND_ADD, DC, 0);
}
static int new_post_atomic_cs_sge_dc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_DRIVER, IBV_WR_ATOMIC_CMP_AND_SWP, DC, 0);
}
static int new_post_send_sge_rc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_RC, IBV_WR_SEND, RC, 0);
}
static int new_post_send_sge_enc_rc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_RC, IBV_WR_SEND, RC, 1);
}
static int new_post_send_inl_rc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 1, index, IBV_QPT_RC, IBV_WR_SEND, RC, 0);
}
static int new_post_write_sge_rc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_RC, opcode_verbs_array[user_param->verb], RC, 0);
}
static int new_post_write_sge_enc_rc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_RC, opcode_verbs_array[user_param->verb], RC, 1);
}
static int new_post_write_inl_rc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 1, index, IBV_QPT_RC, opcode_verbs_array[user_param->verb], RC, 0);
}
static int new_post_read_sge_rc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_RC, IBV_WR_RDMA_READ, RC, 0);
}
static int new_post_read_sge_enc_rc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_RC, IBV_WR_RDMA_READ, RC, 1);
}
static int new_post_atomic_fa_sge_rc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_RC, IBV_WR_ATOMIC_FETCH_AND_ADD, RC, 0);
}
static int new_post_atomic_cs_sge_rc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_RC, IBV_WR_ATOMIC_CMP_AND_SWP, RC, 0);
}
static int new_post_send_sge_ud(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_UD, IBV_WR_SEND, UD, 0);
}
static int new_post_send_inl_ud(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 1, index, IBV_QPT_UD, IBV_WR_SEND, UD, 0);
}
static int new_post_send_sge_uc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_UC, IBV_WR_SEND, UC, 0);
}
static int new_post_send_inl_uc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 1, index, IBV_QPT_UC, IBV_WR_SEND, UC, 0);
}
static int new_post_write_sge_uc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_UC, opcode_verbs_array[user_param->verb], UC, 0);
}
static int new_post_write_inl_uc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 1, index, IBV_QPT_UC, opcode_verbs_array[user_param->verb], UC, 0);
}
static int new_post_send_sge_srd(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_DRIVER, IBV_WR_SEND, SRD, 0);
}
static int new_post_send_inl_srd(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 1, index, IBV_QPT_DRIVER, IBV_WR_SEND, SRD, 0);
}
static int new_post_read_sge_srd(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_DRIVER, IBV_WR_RDMA_READ, SRD, 0);
}
static int new_post_write_sge_srd(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_DRIVER, opcode_verbs_array[user_param->verb], SRD, 0);
}
static int new_post_write_inl_srd(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 1, index, IBV_QPT_DRIVER, opcode_verbs_array[user_param->verb], SRD, 0);
}
#ifdef HAVE_XRCD
static int new_post_send_sge_xrc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_XRC_SEND, IBV_WR_SEND, XRC, 0);
}
static int new_post_send_inl_xrc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 1, index, IBV_QPT_XRC_SEND, IBV_WR_SEND, XRC, 0);
}
static int new_post_write_sge_xrc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_XRC_SEND, opcode_verbs_array[user_param->verb], XRC, 0);
}
static int new_post_write_inl_xrc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 1, index, IBV_QPT_XRC_SEND, opcode_verbs_array[user_param->verb], XRC, 0);
}
static int new_post_read_sge_xrc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_XRC_SEND, IBV_WR_RDMA_READ, XRC, 0);
}
static int new_post_atomic_fa_sge_xrc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_XRC_SEND, IBV_WR_ATOMIC_FETCH_AND_ADD, XRC, 0);
}
static int new_post_atomic_cs_sge_xrc(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
return _new_post_send(ctx, user_param, 0, index, IBV_QPT_XRC_SEND, IBV_WR_ATOMIC_CMP_AND_SWP, XRC, 0);
}
#endif
#endif
/* post_send_method.
*
* Description :
*
* Does posting of work to a send queue.
*
* Parameters :
*
* ctx - Test Context.
* index - qp index.
* user_param - user_parameters struct for this test.
*
* Return Value : int.
*
*/
static inline int post_send_method(struct pingpong_context *ctx, int index,
struct perftest_parameters *user_param)
{
#ifdef HAVE_IBV_WR_API
if (!user_param->use_old_post_send)
return (*ctx->new_post_send_work_request_func_pointer)(ctx, index, user_param);
#endif
struct ibv_send_wr *bad_wr = NULL;
return ibv_post_send(ctx->qp[index], &ctx->wr[index*user_param->post_list], &bad_wr);
}
#ifdef HAVE_XRCD
/******************************************************************************
*
******************************************************************************/
static int ctx_xrcd_create(struct pingpong_context *ctx,struct perftest_parameters *user_param)
{
char *tmp_file_name;
struct ibv_xrcd_init_attr xrcd_init_attr;
memset(&xrcd_init_attr , 0 , sizeof xrcd_init_attr);
tmp_file_name = (user_param->machine == SERVER) ? SERVER_FD : CLIENT_FD;
ctx->fd = open(tmp_file_name, O_RDONLY | O_CREAT, S_IRUSR | S_IRGRP);
if (ctx->fd < 0) {
fprintf(stderr,"Error opening file %s errno: %s\n", tmp_file_name,strerror(errno));
return FAILURE;
}
xrcd_init_attr.comp_mask = IBV_XRCD_INIT_ATTR_FD | IBV_XRCD_INIT_ATTR_OFLAGS;
xrcd_init_attr.fd = ctx->fd;
xrcd_init_attr.oflags = O_CREAT ;
ctx->xrc_domain = ibv_open_xrcd(ctx->context,&xrcd_init_attr);
if (ctx->xrc_domain == NULL) {
fprintf(stderr,"Error opening XRC domain\n");
return FAILURE;
}
return 0;
}
/******************************************************************************
*
******************************************************************************/
static int ctx_xrc_srq_create(struct pingpong_context *ctx,
struct perftest_parameters *user_param)
{
struct ibv_srq_init_attr_ex srq_init_attr;
memset(&srq_init_attr, 0, sizeof(srq_init_attr));
srq_init_attr.attr.max_wr = user_param->rx_depth;
srq_init_attr.attr.max_sge = 1;
srq_init_attr.comp_mask = IBV_SRQ_INIT_ATTR_TYPE | IBV_SRQ_INIT_ATTR_XRCD | IBV_SRQ_INIT_ATTR_CQ | IBV_SRQ_INIT_ATTR_PD;
srq_init_attr.srq_type = IBV_SRQT_XRC;
srq_init_attr.xrcd = ctx->xrc_domain;
if(user_param->verb == SEND || user_param->verb == WRITE_IMM)
srq_init_attr.cq = ctx->recv_cq;
else
srq_init_attr.cq = ctx->send_cq;
srq_init_attr.pd = ctx->pd;
ctx->srq = ibv_create_srq_ex(ctx->context, &srq_init_attr);
if (ctx->srq == NULL) {
fprintf(stderr, "Couldn't open XRC SRQ\n");
return FAILURE;
}
return 0;
}
/******************************************************************************
*
******************************************************************************/
static struct ibv_qp *ctx_xrc_qp_create(struct pingpong_context *ctx,
struct perftest_parameters *user_param,
int qp_index)
{
struct ibv_qp* qp = NULL;
int num_of_qps = user_param->num_of_qps / 2;
#ifdef HAVE_IBV_WR_API
enum ibv_wr_opcode opcode;
#endif
struct ibv_qp_init_attr_ex qp_init_attr;
memset(&qp_init_attr, 0, sizeof(qp_init_attr));
if ( (!(user_param->duplex || user_param->tst == LAT) && (user_param->machine == SERVER) )
|| ((user_param->duplex || user_param->tst == LAT) && (qp_index >= num_of_qps))) {
qp_init_attr.qp_type = IBV_QPT_XRC_RECV;
qp_init_attr.comp_mask = IBV_QP_INIT_ATTR_XRCD;
qp_init_attr.xrcd = ctx->xrc_domain;
qp_init_attr.cap.max_recv_wr = user_param->rx_depth;
qp_init_attr.cap.max_recv_sge = 1;
qp_init_attr.cap.max_inline_data = user_param->inline_size;
} else {
qp_init_attr.qp_type = IBV_QPT_XRC_SEND;
qp_init_attr.send_cq = ctx->send_cq;
qp_init_attr.cap.max_send_wr = user_param->tx_depth;
qp_init_attr.cap.max_send_sge = 1;
qp_init_attr.comp_mask = IBV_QP_INIT_ATTR_PD;
qp_init_attr.pd = ctx->pd;
#ifdef HAVE_IBV_WR_API
if (!user_param->use_old_post_send)
qp_init_attr.comp_mask |= IBV_QP_INIT_ATTR_SEND_OPS_FLAGS;
#endif
qp_init_attr.cap.max_inline_data = user_param->inline_size;
}
#ifdef HAVE_IBV_WR_API
if (!user_param->use_old_post_send)
{
if (user_param->verb == ATOMIC)
{
opcode = opcode_atomic_array[user_param->atomicType];
if (opcode == IBV_WR_ATOMIC_FETCH_AND_ADD)
qp_init_attr.send_ops_flags |= IBV_QP_EX_WITH_ATOMIC_FETCH_AND_ADD;
else if (opcode == IBV_WR_ATOMIC_CMP_AND_SWP)
qp_init_attr.send_ops_flags |= IBV_QP_EX_WITH_ATOMIC_CMP_AND_SWP;
}
else
{
opcode = opcode_verbs_array[user_param->verb];
if (opcode == IBV_WR_SEND)
qp_init_attr.send_ops_flags |= IBV_QP_EX_WITH_SEND;
else if (opcode == IBV_WR_RDMA_WRITE)
qp_init_attr.send_ops_flags |= IBV_QP_EX_WITH_RDMA_WRITE;
else if (opcode == IBV_WR_RDMA_WRITE_WITH_IMM)
qp_init_attr.send_ops_flags |= IBV_QP_EX_WITH_RDMA_WRITE_WITH_IMM;
else if (opcode == IBV_WR_RDMA_READ)
qp_init_attr.send_ops_flags |= IBV_QP_EX_WITH_RDMA_READ;
}
}
#endif
qp = ibv_create_qp_ex(ctx->context, &qp_init_attr);
return qp;
}
#endif
/******************************************************************************
*
******************************************************************************/
int check_add_port(char **service,int port,
const char *servername,
struct addrinfo *hints,
struct addrinfo **res)
{
int number;
if (asprintf(service,"%d", port) < 0) {
return FAILURE;
}
number = getaddrinfo(servername,*service,hints,res);
free(*service);
if (number < 0) {
fprintf(stderr, "%s for ai_family: %x service: %s port: %d\n",
gai_strerror(number), hints->ai_family, servername, port);
return FAILURE;
}
return SUCCESS;
}
/******************************************************************************
*
******************************************************************************/
int sockaddr_set_port(struct sockaddr *sin,int port)
{
switch (sin->sa_family) {
case AF_INET: ((struct sockaddr_in*) sin)->sin_port = htons(port);
break;
case AF_INET6: ((struct sockaddr_in6*) sin)->sin6_port = htons(port);
break;
default:
fprintf(stderr, "ai_family: %x is not yet supported\n", sin->sa_family);
return FAILURE;
}
return SUCCESS;
}
/******************************************************************************
*
******************************************************************************/
int create_rdma_resources(struct pingpong_context *ctx,
struct perftest_parameters *user_param)
{
int is_udp_ps = user_param->connection_type == UD || user_param->connection_type == RawEth;
enum rdma_port_space port_space = (is_udp_ps) ? RDMA_PS_UDP : RDMA_PS_TCP;
struct rdma_cm_id **cm_id = (user_param->machine == CLIENT) ? &ctx->cm_id : &ctx->cm_id_control;
ctx->cm_channel = rdma_create_event_channel();
if (ctx->cm_channel == NULL) {
fprintf(stderr, " rdma_create_event_channel failed\n");
return FAILURE;
}
if (rdma_create_id(ctx->cm_channel,cm_id,NULL,port_space)) {
fprintf(stderr,"rdma_create_id failed\n");
goto destroy_event_channel;
}
return SUCCESS;
destroy_event_channel:
rdma_destroy_event_channel(ctx->cm_channel);
return FAILURE;
}
/******************************************************************************
*
******************************************************************************/
int destroy_rdma_resources(struct pingpong_context *ctx,
struct perftest_parameters *user_param)
{
int ret;
if (user_param->machine == CLIENT) {
ret = rdma_destroy_id(ctx->cm_id);
} else {
ret = rdma_destroy_id(ctx->cm_id_control);
}
rdma_destroy_event_channel(ctx->cm_channel);
return ret;
}
/******************************************************************************
+ *
+ ******************************************************************************/
struct ibv_device* ctx_find_dev(char **ib_devname)
{
int num_of_device;
struct ibv_device **dev_list;
struct ibv_device *ib_dev = NULL;
dev_list = ibv_get_device_list(&num_of_device);
//coverity[uninit_use]
if (num_of_device <= 0) {
fprintf(stderr," Did not detect devices \n");
fprintf(stderr," If device exists, check if driver is up\n");
return NULL;
}
if (!ib_devname) {
fprintf(stderr," Internal error, existing.\n");
return NULL;
}
if (!*ib_devname) {
ib_dev = dev_list[0];
if (!ib_dev) {
fprintf(stderr, "No IB devices found\n");
exit (1);
}
} else {
for (; (ib_dev = *dev_list); ++dev_list)
if (!strcmp(ibv_get_device_name(ib_dev), *ib_devname))
break;
if (!ib_dev) {
fprintf(stderr, "IB device %s not found\n", *ib_devname);
return NULL;
}
}
GET_STRING(*ib_devname, ibv_get_device_name(ib_dev));
return ib_dev;
}
/******************************************************************************
*
******************************************************************************/
struct ibv_context* ctx_open_device(struct ibv_device *ib_dev, struct perftest_parameters *user_param)
{
struct ibv_context *context;
#ifdef HAVE_AES_XTS
if(user_param->aes_xts){
struct mlx5dv_crypto_login_attr login_attr = {};
struct mlx5dv_context_attr attr = {};
attr.flags = MLX5DV_CONTEXT_FLAGS_DEVX;
if(set_valid_cred(login_attr.credential, user_param)){
fprintf(stderr, "Couldn't set credentials\n");
return NULL;
}
context = mlx5dv_open_device(ib_dev, &attr);
if(!context){
fprintf(stderr, "Couldn't get context for the device\n");
return NULL;
}
int ret = mlx5dv_crypto_login(context, &login_attr);
if (ret) {
fprintf(stderr,"Couldn't login. err=%d.\n", ret);
return NULL;
}
return context;
}
#endif
context = ibv_open_device(ib_dev);
if (!context) {
fprintf(stderr, " Couldn't get context for the device\n");
return NULL;
}
return context;
}
/******************************************************************************
*