-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathqperf.c
More file actions
2868 lines (2540 loc) · 80.5 KB
/
qperf.c
File metadata and controls
2868 lines (2540 loc) · 80.5 KB
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
/*
* qperf - main.
* Measure socket and RDMA performance.
*
* Copyright (c) 2002-2009 Johann George. All rights reserved.
* Copyright (c) 2006-2009 QLogic Corporation. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* 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.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#define _GNU_SOURCE
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <sched.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <sys/times.h>
#include <sys/select.h>
#include <sys/utsname.h>
#include "qperf.h"
/*
* Configurable parameters. If your change makes this version of qperf
* incompatible with previous versions (usually a change to the Req structure),
* increment VER_MIN and set VER_INC to 0. Otherwise, just increment VER_INC.
* VER_MAJ is reserved for major changes.
*/
#define VER_MAJ 0 /* Major version */
#define VER_MIN 4 /* Minor version */
#define VER_INC 11 /* Incremental version */
#define LISTENQ 5 /* Size of listen queue */
#define BUFSIZE 1024 /* Size of buffers */
/*
* Default parameter values.
*/
#define DEF_TIME 2 /* Test duration */
#define DEF_TIMEOUT 5 /* Timeout */
#define DEF_PRECISION 3 /* Precision displayed */
#define DEF_LISTEN_PORT 19765 /* Listen port */
/*
* Option list.
*/
typedef struct OPTION {
char *name; /* Name of option */
char *type; /* Type */
int arg1; /* First argument */
int arg2; /* Second argument */
} OPTION;
/*
* Used to loop through a range of values.
*/
typedef struct LOOP {
struct LOOP *next; /* Pointer to next loop */
OPTION *option; /* Loop variable */
long init; /* Initial value */
long last; /* Last value */
long incr; /* Increment */
int mult; /* If set, multiply, otherwise add */
} LOOP;
/*
* Parameter information.
*/
typedef struct PAR_INFO {
PAR_INDEX index; /* Index into parameter table */
int type; /* Type */
void *ptr; /* Pointer to value */
char *name; /* Option name */
int set; /* Parameter has been set */
int used; /* Parameter has been used */
int inuse; /* Parameter is in use */
} PAR_INFO;
/*
* Parameter name association.
*/
typedef struct PAR_NAME {
char *name; /* Name */
PAR_INDEX loc_i; /* Local index */
PAR_INDEX rem_i; /* Remote index */
} PAR_NAME;
/*
* A simple mapping between two strings.
*/
typedef struct DICT {
char *str1; /* String 1 */
char *str2; /* String 2 */
} DICT;
/*
* Test prototype.
*/
typedef struct TEST {
char *name; /* Test name */
void (*client)(void); /* Client function */
void (*server)(void); /* Server function */
} TEST;
/*
* Used to save output data for formatting.
*/
typedef struct SHOW {
char *pref; /* Name prefix */
char *name; /* Name */
char *data; /* Data */
char *unit; /* Unit */
char *altn; /* Alternative value */
} SHOW;
/*
* Configuration information.
*/
typedef struct CONF {
char node[STRSIZE]; /* Node */
char cpu[STRSIZE]; /* CPU */
char os[STRSIZE]; /* Operating System */
char qperf[STRSIZE]; /* Qperf version */
} CONF;
/*
* Function prototypes.
*/
static void add_ustat(USTAT *l, USTAT *r);
static long arg_long(char ***argvp);
static long arg_size(char ***argvp);
static char *arg_strn(char ***argvp);
static long arg_time(char ***argvp);
static void calc_node(RESN *resn, STAT *stat);
static void calc_results(void);
static void client(TEST *test);
static int cmpsub(char *s2, char *s1);
static char *commify(char *data);
static void dec_req_data(REQ *host);
static void dec_req_version(REQ *host);
static void dec_stat(STAT *host);
static void dec_ustat(USTAT *host);
static void do_args(char *args[]);
static void do_loop(LOOP *loop, TEST *test);
static void do_option(OPTION *option, char ***argvp);
static void enc_req(REQ *host);
static void enc_stat(STAT *host);
static void enc_ustat(USTAT *host);
static TEST *find_test(char *name);
static OPTION *find_option(char *name);
static void get_conf(CONF *conf);
static void get_cpu(CONF *conf);
static void get_times(CLOCK timex[T_N]);
static void initialize(void);
static void init_lstat(void);
static char *loop_arg(char **pp);
static int nice_1024(char *pref, char *name, long long value);
static PAR_INFO *par_info(PAR_INDEX index);
static PAR_INFO *par_set(char *name, PAR_INDEX index);
static int par_isset(PAR_INDEX index);
static void parse_loop(char ***argvp);
static void place_any(char *pref, char *name, char *unit, char *data,
char *altn);
static void place_show(void);
static void place_val(char *pref, char *name, char *unit, double value);
static void remotefd_close(void);
static void remotefd_setup(void);
static void run_client_conf(void);
static void run_client_quit(void);
static void run_server_conf(void);
static void run_server_quit(void);
static void server(void);
static void server_listen(void);
static int server_recv_request(void);
static void set_affinity(void);
static void set_signals(void);
static void show_debug(void);
static void show_info(MEASURE measure);
static void show_rest(void);
static void show_used(void);
static void sig_alrm(int signo, siginfo_t *siginfo, void *ucontext);
static void sig_quit(int signo, siginfo_t *siginfo, void *ucontext);
static void sig_urg(int signo, siginfo_t *siginfo, void *ucontext);
static char *skip_colon(char *s);
static void start_test_timer(int seconds);
static long str_size(char *arg, char *str);
static void strncopy(char *d, char *s, int n);
static char *two_args(char ***argvp);
static int verbose(int type, double value);
static void version_error(void);
static void view_band(int type, char *pref, char *name, double value);
static void view_cost(int type, char *pref, char *name, double value);
static void view_cpus(int type, char *pref, char *name, double value);
static void view_rate(int type, char *pref, char *name, double value);
static void view_long(int type, char *pref, char *name, long long value);
static void view_size(int type, char *pref, char *name, long long value);
static void view_strn(int type, char *pref, char *name, char *value);
static void view_time(int type, char *pref, char *name, double value);
/*
* Configurable variables.
*/
static int ListenPort = DEF_LISTEN_PORT;
static int Precision = DEF_PRECISION;
static int ServerWait = DEF_TIMEOUT;
static int UseBitsPerSec = 0;
/*
* Static variables.
*/
static REQ RReq;
static STAT IStat;
static int ListenFD;
static LOOP *Loops;
static int ProcStatFD;
static STAT RStat;
static int ShowIndex;
static SHOW ShowTable[256];
static int UnifyUnits;
static int UnifyNodes;
static int VerboseConf;
static int VerboseStat;
static int VerboseTime;
static int VerboseUsed;
/*
* Global variables.
*/
RES Res;
REQ Req;
STAT LStat;
char *TestName;
char *ServerName;
SS ServerAddr;
int ServerAddrLen;
int RemoteFD;
int Debug;
volatile int Finished;
/*
* Parameter names. This is used to print out the names of the parameters that
* have been set.
*/
PAR_NAME ParName[] ={
{ "access_recv", L_ACCESS_RECV, R_ACCESS_RECV },
{ "affinity", L_AFFINITY, R_AFFINITY },
{ "alt_port", L_ALT_PORT, R_ALT_PORT },
{ "flip", L_FLIP, R_FLIP },
{ "id", L_ID, R_ID },
{ "msg_size", L_MSG_SIZE, R_MSG_SIZE },
{ "mtu_size", L_MTU_SIZE, R_MTU_SIZE },
{ "no_msgs", L_NO_MSGS, R_NO_MSGS },
{ "poll_mode", L_POLL_MODE, R_POLL_MODE },
{ "port", L_PORT, R_PORT },
{ "rd_atomic", L_RD_ATOMIC, R_RD_ATOMIC },
{ "service_level", L_SL, R_SL },
{ "sock_buf_size", L_SOCK_BUF_SIZE, R_SOCK_BUF_SIZE },
{ "src_path_bits", L_SRC_PATH_BITS, R_SRC_PATH_BITS },
{ "time", L_TIME, R_TIME },
{ "timeout", L_TIMEOUT, R_TIMEOUT },
{ "use_cm", L_USE_CM, R_USE_CM },
};
/*
* Parameters. These must be listed in the same order as the indices are
* defined.
*/
PAR_INFO ParInfo[P_N] ={
{ P_NULL, },
{ L_ACCESS_RECV, 'l', &Req.access_recv },
{ R_ACCESS_RECV, 'l', &RReq.access_recv },
{ L_AFFINITY, 'l', &Req.affinity },
{ R_AFFINITY, 'l', &RReq.affinity },
{ L_ALT_PORT, 'l', &Req.alt_port },
{ R_ALT_PORT, 'l', &RReq.alt_port },
{ L_FLIP, 'l', &Req.flip },
{ R_FLIP, 'l', &RReq.flip },
{ L_ID, 'p', &Req.id },
{ R_ID, 'p', &RReq.id },
{ L_MSG_SIZE, 's', &Req.msg_size },
{ R_MSG_SIZE, 's', &RReq.msg_size },
{ L_MTU_SIZE, 's', &Req.mtu_size },
{ R_MTU_SIZE, 's', &RReq.mtu_size },
{ L_NO_MSGS, 'l', &Req.no_msgs },
{ R_NO_MSGS, 'l', &RReq.no_msgs },
{ L_POLL_MODE, 'l', &Req.poll_mode },
{ R_POLL_MODE, 'l', &RReq.poll_mode },
{ L_PORT, 'l', &Req.port },
{ R_PORT, 'l', &RReq.port },
{ L_RD_ATOMIC, 'l', &Req.rd_atomic },
{ R_RD_ATOMIC, 'l', &RReq.rd_atomic },
{ L_SL, 'l', &Req.sl },
{ R_SL, 'l', &RReq.sl },
{ L_SOCK_BUF_SIZE, 's', &Req.sock_buf_size },
{ R_SOCK_BUF_SIZE, 's', &RReq.sock_buf_size },
{ L_SRC_PATH_BITS, 's', &Req.src_path_bits },
{ R_SRC_PATH_BITS, 's', &RReq.src_path_bits },
{ L_STATIC_RATE, 'p', &Req.static_rate },
{ R_STATIC_RATE, 'p', &RReq.static_rate },
{ L_TIME, 't', &Req.time },
{ R_TIME, 't', &RReq.time },
{ L_TIMEOUT, 't', &Req.timeout },
{ R_TIMEOUT, 't', &RReq.timeout },
{ L_USE_CM, 'l', &Req.use_cm },
{ R_USE_CM, 'l', &RReq.use_cm },
};
/*
* Renamed options. First is old, second is new.
*/
DICT Renamed[] = {
/* -a becomes -ca (--cpu_affinity) */
{ "--affinity", "--cpu_affinity" },
{ "-a", "-ca" },
{ "--loc_affinity", "--loc_cpu_affinity" },
{ "-la", "-lca" },
{ "--rem_affinity", "--rem_cpu_affinity" },
{ "-ra", "-rca" },
/* -r becomes -sr (--static_rate) */
{ "--rate", "--static_rate" },
{ "-r", "-sr" },
{ "--loc_rate", "--loc_static_rate" },
{ "-lr", "-lsr" },
{ "--rem_rate", "--rem_static_rate" },
{ "-rr", "-rsr" },
/* -p becomes -ip (--ip_port) */
{ "--port", "--ip_port" },
{ "-p", "-ip" },
/* -P becomes -cp (--cq_poll) */
{ "--poll", "--cq_poll" },
{ "-P", "-cp" },
{ "--loc_poll", "--loc_cq_poll" },
{ "-lP", "-lcp" },
{ "--rem_poll", "--rem_cq_poll" },
{ "-rP", "-rcp" },
/* -R becomes -nr (--rd_atomic) */
{ "-R", "-nr" },
{ "-lR", "-lnr" },
{ "-rR", "-rnr" },
/* -T becomes -to (--timeout) */
{ "-T", "-to" },
{ "-lT", "-lto" },
{ "-rT", "-rto" },
/* -S becomes -sb (--sock_buf_size) */
{ "-S", "-sb" },
{ "-lS", "-lsb" },
{ "-rS", "-rsb" },
/* -W becomes -ws (--wait_server) */
{ "--wait", "--wait_server" },
{ "-W", "-ws" },
/* verbose options */
{ "-vC", "-vvc", },
{ "-vS", "-vvs", },
{ "-vT", "-vvt", },
{ "-vU", "-vvu", },
/* options that are on */
{ "-aro", "-ar1" },
{ "-cmo", "-cm1" },
{ "-fo", "-f1" },
{ "-cpo", "-cp1" },
{ "-lcpo", "-lcp1" },
{ "-rcpo", "-rcp1" },
/* miscellaneous */
{ "-Ar", "-ar" },
{ "-M", "-mt" },
{ "-u", "-uu", },
};
/*
* Options. The type field (2nd column) is used by do_option. If it begins
* with a S, it is a valid server option. If it begins with a X, it is
* obsolete and will eventually go away.
*/
OPTION Options[] ={
{ "--access_recv", "int", L_ACCESS_RECV, R_ACCESS_RECV },
{ "-ar", "int", L_ACCESS_RECV, R_ACCESS_RECV },
{ "-ar1", "set1", L_ACCESS_RECV, R_ACCESS_RECV },
{ "--alt_port", "int", L_ALT_PORT, R_ALT_PORT },
{ "-ap", "int", L_ALT_PORT, R_ALT_PORT },
{ "--loc_alt_port", "int", L_ALT_PORT, },
{ "-lap", "int", L_ALT_PORT, },
{ "--rem_alt_port", "int", R_ALT_PORT },
{ "-rap", "int", R_ALT_PORT },
{ "--cpu_affinity", "int", L_AFFINITY, R_AFFINITY },
{ "-ca", "int", L_AFFINITY, R_AFFINITY },
{ "--loc_cpu_affinity", "int", L_AFFINITY, },
{ "-lca", "int", L_AFFINITY, },
{ "--rem_cpu_affinity", "int", R_AFFINITY },
{ "-rca", "int", R_AFFINITY },
{ "--debug", "Sdebug", },
{ "-D", "Sdebug", },
{ "--flip", "int", L_FLIP, R_FLIP },
{ "-f", "int", L_FLIP, R_FLIP },
{ "-f1", "set1", L_FLIP, R_FLIP },
{ "--help", "help" },
{ "-h", "help" },
{ "--host", "host", },
{ "-H", "host", },
{ "--id", "str", L_ID, R_ID },
{ "-i", "str", L_ID, R_ID },
{ "--loc_id", "str", L_ID, },
{ "-li", "str", L_ID, },
{ "--rem_id", "str", R_ID },
{ "-ri", "str", R_ID },
{ "--listen_port", "Slp", },
{ "-lp", "Slp", },
{ "--loop", "loop", },
{ "-oo", "loop", },
{ "--msg_size", "size", L_MSG_SIZE, R_MSG_SIZE },
{ "-m", "size", L_MSG_SIZE, R_MSG_SIZE },
{ "--mtu_size", "size", L_MTU_SIZE, R_MTU_SIZE },
{ "-mt", "size", L_MTU_SIZE, R_MTU_SIZE },
{ "--no_msgs", "int", L_NO_MSGS, R_NO_MSGS },
{ "-n", "int", L_NO_MSGS, R_NO_MSGS },
{ "--cq_poll", "int", L_POLL_MODE, R_POLL_MODE },
{ "-cp", "int", L_POLL_MODE, R_POLL_MODE },
{ "-cp1", "set1", L_POLL_MODE, R_POLL_MODE },
{ "--loc_cq_poll", "int", L_POLL_MODE, },
{ "-lcp", "int", L_POLL_MODE, },
{ "-lcp1", "set1", L_POLL_MODE },
{ "--rem_cq_poll", "int", R_POLL_MODE },
{ "-rcp", "int", R_POLL_MODE },
{ "-rcp1", "set1", R_POLL_MODE },
{ "--ip_port", "int", L_PORT, R_PORT },
{ "-ip", "int", L_PORT, R_PORT },
{ "--precision", "precision", },
{ "-e", "precision", },
{ "--rd_atomic", "int", L_RD_ATOMIC, R_RD_ATOMIC },
{ "-nr", "int", L_RD_ATOMIC, R_RD_ATOMIC },
{ "--loc_rd_atomic", "int", L_RD_ATOMIC, },
{ "-lnr", "int", L_RD_ATOMIC, },
{ "--rem_rd_atomic", "int", R_RD_ATOMIC },
{ "-rnr", "int", R_RD_ATOMIC },
{ "--service_level", "sl", L_SL, R_SL },
{ "-sl", "sl", L_SL, R_SL },
{ "--loc_service_level", "sl", L_SL },
{ "-lsl", "sl", L_SL },
{ "--rem_service_level", "sl", R_SL },
{ "-rsl", "sl", R_SL },
{ "--sock_buf_size", "size", L_SOCK_BUF_SIZE, R_SOCK_BUF_SIZE },
{ "-sb", "size", L_SOCK_BUF_SIZE, R_SOCK_BUF_SIZE },
{ "--loc_sock_buf_size", "size", L_SOCK_BUF_SIZE },
{ "-lsb", "size", L_SOCK_BUF_SIZE },
{ "--rem_sock_buf_size", "size", R_SOCK_BUF_SIZE },
{ "-rsb", "size", R_SOCK_BUF_SIZE },
{ "--src_path_bits", "size", L_SRC_PATH_BITS, R_SRC_PATH_BITS },
{ "-sp", "size", L_SRC_PATH_BITS, R_SRC_PATH_BITS },
{ "--loc_src_path_bits", "size", L_SRC_PATH_BITS },
{ "-lsp", "size", L_SRC_PATH_BITS },
{ "--rem_src_path_bits", "size", R_SRC_PATH_BITS },
{ "-rsp", "size", R_SRC_PATH_BITS },
{ "--static_rate", "str", L_STATIC_RATE, R_STATIC_RATE },
{ "-sr", "str", L_STATIC_RATE, R_STATIC_RATE },
{ "--loc_static_rate", "str", L_STATIC_RATE },
{ "-lsr", "str", L_STATIC_RATE },
{ "--rem_static_rate", "str", R_STATIC_RATE },
{ "-rsr", "str", R_STATIC_RATE },
{ "--time", "time", L_TIME, R_TIME },
{ "-t", "time", L_TIME, R_TIME },
{ "--timeout", "time", L_TIMEOUT, R_TIMEOUT },
{ "-to", "time", L_TIMEOUT, R_TIMEOUT },
{ "--loc_timeout", "Stime", L_TIMEOUT },
{ "-lto", "Stime", L_TIMEOUT },
{ "--rem_timeout", "time", R_TIMEOUT },
{ "-rto", "time", R_TIMEOUT },
{ "--unify_nodes", "un", },
{ "-un", "un", },
{ "--unify_units", "uu", },
{ "-uu", "uu", },
{ "--use_bits_per_sec", "ub", },
{ "-ub", "ub", },
{ "--use_cm", "int", L_USE_CM, R_USE_CM },
{ "-cm", "int", L_USE_CM, R_USE_CM },
{ "-cm1", "set1", L_USE_CM, R_USE_CM },
{ "--verbose", "v", },
{ "-v", "v", },
{ "--verbose_conf", "vc", },
{ "-vc", "vc", },
{ "--verbose_stat", "vs", },
{ "-vs", "vs", },
{ "--verbose_time", "vt", },
{ "-vt", "vt", },
{ "--verbose_used", "vu", },
{ "-vu", "vu", },
{ "--verbose_more", "vv", },
{ "-vv", "vv", },
{ "--verbose_more_conf", "vvc", },
{ "-vvc", "vvc", },
{ "--verbose_more_stat", "vvs", },
{ "-vvs", "vvs", },
{ "--verbose_more_time", "vvt", },
{ "-vvt", "vvt", },
{ "--verbose_more_used", "vvu", },
{ "-vvu", "vvu", },
{ "--version", "version", },
{ "-V", "version", },
{ "--wait_server", "wait", },
{ "-ws", "wait", },
};
/*
* Tests.
*/
#define test(n) { #n, run_client_##n, run_server_##n }
TEST Tests[] ={
test(conf),
test(quit),
test(rds_bw),
test(rds_lat),
test(sctp_bw),
test(sctp_lat),
test(sdp_bw),
test(sdp_lat),
test(tcp_bw),
test(tcp_lat),
test(udp_bw),
test(udp_lat),
#ifdef RDMA
test(rc_bi_bw),
test(rc_bw),
test(rc_compare_swap_mr),
test(rc_fetch_add_mr),
test(rc_lat),
test(rc_rdma_read_bw),
test(rc_rdma_read_lat),
test(rc_rdma_write_bw),
test(rc_rdma_write_lat),
test(rc_rdma_write_poll_lat),
test(uc_bi_bw),
test(uc_bw),
test(uc_lat),
test(uc_rdma_write_bw),
test(uc_rdma_write_lat),
test(uc_rdma_write_poll_lat),
test(ud_bi_bw),
test(ud_bw),
test(ud_lat),
test(ver_rc_compare_swap),
test(ver_rc_fetch_add),
#ifdef HAS_XRC
test(xrc_bi_bw),
test(xrc_bw),
test(xrc_lat),
#endif /* HAS_XRC */
#endif
};
int
main(int argc, char *argv[])
{
initialize();
set_signals();
do_args(&argv[1]);
return 0;
}
/*
* Initialize variables.
*/
static void
initialize(void)
{
int i;
RemoteFD = -1;
for (i = 0; i < P_N; ++i)
if (ParInfo[i].index != i)
error(BUG, "initialize: ParInfo: out of order: %d", i);
ProcStatFD = open("/proc/stat", 0);
if (ProcStatFD < 0)
error(SYS, "cannot open /proc/stat");
IStat.no_cpus = sysconf(_SC_NPROCESSORS_ONLN);
IStat.no_ticks = sysconf(_SC_CLK_TCK);
}
/*
* Look for a colon and skip past it and any spaces.
*/
static char *
skip_colon(char *s)
{
for (;;) {
int c = *s++;
if (c == ':')
break;
if (c == '\0')
return 0;
}
while (*s == ' ')
s++;
return s;
}
/*
* A case insensitive string compare. s2 must at least contain all of s1 but
* can be longer.
*/
static int
cmpsub(char *s2, char *s1)
{
for (;;) {
int c1 = *s1++;
int c2 = *s2++;
if (c1 == '\0')
return 1;
if (c2 == '\0')
return 0;
if (tolower(c1) != tolower(c2))
return 0;
}
}
/*
* Set up signal handlers.
*/
static void
set_signals(void)
{
struct sigaction act ={
.sa_flags = SA_SIGINFO
};
act.sa_sigaction = sig_alrm;
sigaction(SIGALRM, &act, 0);
sigaction(SIGPIPE, &act, 0);
act.sa_sigaction = sig_quit;
sigaction(SIGQUIT, &act, 0);
act.sa_sigaction = sig_urg;
sigaction(SIGURG, &act, 0);
}
/*
* Note that time is up.
*/
static void
sig_alrm(int signo, siginfo_t *siginfo, void *ucontext)
{
set_finished();
}
/*
* Our child sends us a quit when it wishes us to exit.
*/
static void
sig_quit(int signo, siginfo_t *siginfo, void *ucontext)
{
exit(0);
}
/*
* Called when a TCP/IP out-of-band message is received.
*/
static void
sig_urg(int signo, siginfo_t *siginfo, void *ucontext)
{
urgent();
}
/*
* Parse arguments.
*/
static void
do_args(char *args[])
{
int isClient = 0;
int testSpecified = 0;
while (*args) {
char *arg = *args;
if (arg[0] == '-') {
OPTION *option = find_option(arg);
if (!option)
error(0, "%s: bad option; try: qperf --help options", arg);
if (option->type[0] != 'S')
isClient = 1;
do_option(option, &args);
} else {
isClient = 1;
if (!ServerName)
ServerName = arg;
else {
TEST *test = find_test(arg);
if (!test)
error(0, "%s: bad test; try: qperf --help tests", arg);
do_loop(Loops, test);
testSpecified = 1;
}
++args;
}
}
if (!isClient)
server();
else if (!testSpecified) {
if (!ServerName)
error(0, "you used a client-only option but did not specify the "
"server name.\nDo you want to be a client or server?");
if (find_test(ServerName))
error(0, "must specify host name first; try: qperf --help");
error(0, "must specify a test type; try: qperf --help");
}
}
/*
* Loop through a series of tests.
*/
static void
do_loop(LOOP *loop, TEST *test)
{
if (!loop)
client(test);
else {
long l = loop->init;
while (l <= loop->last) {
char buf[64];
char *args[2] = {loop->option->name, buf};
char **argv = args;
snprintf(buf, sizeof(buf), "%ld", l);
do_option(loop->option, &argv);
do_loop(loop->next, test);
if (loop->mult)
l *= loop->incr;
else
l += loop->incr;
}
}
}
/*
* Given the name of an option, find it.
*/
static OPTION *
find_option(char *name)
{
int n;
DICT *d;
OPTION *p;
n = cardof(Renamed);
d = Renamed;
for (; n--; ++d) {
if (streq(name, d->str1)) {
char *msg = "warning: obsolete option: %s; use %s instead";
error(RET, msg, name, d->str2);
name = d->str2;
break;
}
}
n = cardof(Options);
p = Options;
for (; n--; ++p)
if (streq(name, p->name))
return p;
return 0;
}
/*
* Given the name of a test, find it.
*/
static TEST *
find_test(char *name)
{
int n = cardof(Tests);
TEST *p = Tests;
for (; n--; ++p)
if (streq(name, p->name))
return p;
return 0;
}
/*
* Handle options.
*/
static void
do_option(OPTION *option, char ***argvp)
{
char *t = option->type;
if (*t == 'S')
++t;
if (streq(t, "debug")) {
Debug = 1;
*argvp += 1;
} else if (streq(t, "help")) {
/* Help */
char **usage;
char *category = (*argvp)[1];
if (!category)
category = "main";
for (usage = Usage; *usage; usage += 2)
if (streq(*usage, category))
break;
if (!*usage) {
error(0,
"cannot find help category %s; try: qperf --help categories",
category);
}
printf("%s", usage[1]);
exit(0);
} else if (streq(t, "host")) {
ServerName = arg_strn(argvp);
} else if (streq(t, "int")) {
long v = arg_long(argvp);
setp_u32(option->name, option->arg1, v);
setp_u32(option->name, option->arg2, v);
} else if (streq(t, "loop")) {
parse_loop(argvp);
} else if (streq(t, "lp")) {
ListenPort = arg_long(argvp);
} else if (streq(t, "precision")) {
Precision = arg_long(argvp);
} else if (streq(t, "set1")) {
setp_u32(option->name, option->arg1, 1);
setp_u32(option->name, option->arg2, 1);
*argvp += 1;
} else if (streq(t, "size")) {
long v = arg_size(argvp);
setp_u32(option->name, option->arg1, v);
setp_u32(option->name, option->arg2, v);
} else if (streq(t, "sl")) {
long v = arg_long(argvp);
if (v < 0 || v > 15)
error(0, "service level must be between 0 and 15: %d given", v);
setp_u32(option->name, option->arg1, v);
setp_u32(option->name, option->arg2, v);
} else if (streq(t, "str")) {
char *s = arg_strn(argvp);
setp_str(option->name, option->arg1, s);
setp_str(option->name, option->arg2, s);
} else if (streq(t, "time")) {
long v = arg_time(argvp);
setp_u32(option->name, option->arg1, v);
setp_u32(option->name, option->arg2, v);
} else if (streq(t, "ub")) {
UseBitsPerSec = 1;
*argvp += 1;
} else if (streq(t, "un")) {
UnifyNodes = 1;
*argvp += 1;
} else if (streq(t, "uu")) {
UnifyUnits = 1;
*argvp += 1;
} else if (streq(t, "v")) {
if (VerboseConf < 1)
VerboseConf = 1;
if (VerboseStat < 1)
VerboseStat = 1;
if (VerboseTime < 1)
VerboseTime = 1;
if (VerboseUsed < 1)
VerboseUsed = 1;
*argvp += 1;
} else if (streq(t, "vc")) {
VerboseConf = 1;
*argvp += 1;
} else if (streq(t, "version")) {
printf("qperf %d.%d.%d\n", VER_MAJ, VER_MIN, VER_INC);
exit(0);
} else if (streq(t, "vs")) {
VerboseStat = 1;
*argvp += 1;
} else if (streq(t, "vt")) {
VerboseTime = 1;
*argvp += 1;
} else if (streq(t, "vu")) {
VerboseUsed = 1;
*argvp += 1;
} else if (streq(t, "vv")) {
VerboseConf = 2;
VerboseStat = 2;
VerboseTime = 2;
VerboseUsed = 2;
*argvp += 1;
} else if (streq(t, "vvc")) {
VerboseConf = 2;
*argvp += 1;
} else if (streq(t, "vvs")) {
VerboseStat = 2;
*argvp += 1;
} else if (streq(t, "vvt")) {
VerboseTime = 2;
*argvp += 1;
} else if (streq(t, "vvu")) {
VerboseUsed = 2;
*argvp += 1;
} else if (streq(t, "wait")) {
ServerWait = arg_time(argvp);
} else
error(BUG, "do_option: unknown type: %s", t);
}
/*
* Parse a loop option.
*/
static void
parse_loop(char ***argvp)
{
char *opt = **argvp;
char *s = two_args(argvp);
char *name = loop_arg(&s);
char *init = loop_arg(&s);
char *last = loop_arg(&s);
char *incr = loop_arg(&s);
LOOP *loop = qmalloc(sizeof(LOOP));
memset(loop, 0, sizeof(*loop));
/* Parse variable name */
{
int n = cardof(Options);
OPTION *p = Options;
if (!name)
name = "msg_size";
for (;;) {
char *s = p->name;
if (n-- == 0)
error(0, "%s: %s: no such variable", opt, name);
if (*s++ != '-')
continue;
if (*s == '-')
s++;
if (streq(name, s))