forked from CyanogenMod/android_external_netperf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnettest_sdp.c
More file actions
3553 lines (2987 loc) · 110 KB
/
nettest_sdp.c
File metadata and controls
3553 lines (2987 loc) · 110 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
#ifndef lint
char nettest_sdp[]="\
@(#)nettest_sdp.c (c) Copyright 2007 Hewlett-Packard Co. Version 2.4.4";
#else
#define DIRTY
#define WANT_HISTOGRAM
#define WANT_INTERVALS
#endif /* lint */
/****************************************************************/
/* */
/* nettest_sdp.c */
/* */
/* */
/* scan_sdp_args() get the sdp command line args */
/* */
/* the actual test routines... */
/* */
/* send_sdp_stream() perform a sdp stream test */
/* recv_sdp_stream() */
/* send_sdp_rr() perform a sdp request/response */
/* recv_sdp_rr() */
/* */
/* relies on create_data_socket in nettest_bsd.c */
/****************************************************************/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#if defined(WANT_SDP)
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#ifdef NOSTDLIBH
#include <malloc.h>
#else /* NOSTDLIBH */
#include <stdlib.h>
#endif /* NOSTDLIBH */
#if !defined(__VMS)
#include <sys/ipc.h>
#endif /* !defined(__VMS) */
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
/* would seem that not all sdp.h files define a MSG_EOF, but that
MSG_EOF can be the same as MSG_FIN so lets work with that
assumption. initial find by Jon Pedersen. raj 2006-02-01 */
#ifndef MSG_EOF
#ifdef MSG_FIN
#define MSG_EOF MSG_FIN
#else
#error Must have either MSG_EOF or MSG_FIN defined
#endif
#endif
#include "netlib.h"
#include "netsh.h"
/* get some of the functions from nettest_bsd.c */
#include "nettest_bsd.h"
#include "nettest_sdp.h"
#ifdef WANT_HISTOGRAM
#ifdef __sgi
#include <sys/time.h>
#endif /* __sgi */
#include "hist.h"
#endif /* WANT_HISTOGRAM */
#ifdef WANT_FIRST_BURST
extern int first_burst_size;
#endif /* WANT_FIRST_BURST */
/* these variables are specific to SDP tests. declare */
/* them static to make them global only to this file. */
static int
msg_count = 0, /* number of messages to transmit on association */
non_block = 0, /* default to blocking sockets */
num_associations = 1; /* number of associations on the endpoint */
static int confidence_iteration;
static char local_cpu_method;
static char remote_cpu_method;
#ifdef WANT_HISTOGRAM
static struct timeval time_one;
static struct timeval time_two;
static HIST time_hist;
#endif /* WANT_HISTOGRAM */
char sdp_usage[] = "\n\
Usage: netperf [global options] -- [test options] \n\
\n\
SDP Sockets Test Options:\n\
-b number Send number requests at the start of _RR tests\n\
-D [L][,R] Set SDP_NODELAY locally and/or remotely\n\
-h Display this text\n\
-H name,fam Use name (or IP) and family as target of data connection\n\
-L name,fam Use name (or IP) and family as source of data connextion\n\
-m bytes Set the size of each sent message\n\
-M bytes Set the size of each received messages\n\
-P local[,remote] Set the local/remote port for the data socket\n\
-r req,[rsp] Set request/response sizes (_RR tests)\n\
-s send[,recv] Set local socket send/recv buffer sizes\n\
-S send[,recv] Set remote socket send/recv buffer sizes\n\
-V Enable copy avoidance if supported\n\
-4 Use AF_INET (eg IPv4) on both ends of the data conn\n\
-6 Use AF_INET6 (eg IPv6) on both ends of the data conn\n\
\n\
For those options taking two parms, at least one must be specified;\n\
specifying one value without a comma will set both parms to that\n\
value, specifying a value with a leading comma will set just the second\n\
parm, a value with a trailing comma will set just the first. To set\n\
each parm to unique values, specify both and separate them with a\n\
comma.\n";
/* This routine is intended to retrieve interesting aspects of sdp */
/* for the data connection. at first, it attempts to retrieve the */
/* maximum segment size. later, it might be modified to retrieve */
/* other information, but it must be information that can be */
/* retrieved quickly as it is called during the timing of the test. */
/* for that reason, a second routine may be created that can be */
/* called outside of the timing loop */
static
void
get_sdp_info(int socket, int * mss)
{
#ifdef TCP_MAXSEG
netperf_socklen_t sock_opt_len;
sock_opt_len = sizeof(netperf_socklen_t);
if (getsockopt(socket,
getprotobyname("tcp")->p_proto,
TCP_MAXSEG,
(char *)mss,
&sock_opt_len) == SOCKET_ERROR) {
fprintf(where,
"netperf: get_sdp_info: getsockopt TCP_MAXSEG: errno %d\n",
errno);
fflush(where);
*mss = -1;
}
#else
*mss = -1;
#endif /* TCP_MAXSEG */
}
void
send_sdp_stream(char remote_host[])
{
char *tput_title = "\
Recv Send Send \n\
Socket Socket Message Elapsed \n\
Size Size Size Time Throughput \n\
bytes bytes bytes secs. %s/sec \n\n";
char *tput_fmt_0 =
"%7.2f %s\n";
char *tput_fmt_1 =
"%6d %6d %6d %-6.2f %7.2f %s\n";
char *cpu_title = "\
Recv Send Send Utilization Service Demand\n\
Socket Socket Message Elapsed Send Recv Send Recv\n\
Size Size Size Time Throughput local remote local remote\n\
bytes bytes bytes secs. %-8.8s/s %% %c %% %c us/KB us/KB\n\n";
char *cpu_fmt_0 =
"%6.3f %c %s\n";
char *cpu_fmt_1 =
"%6d %6d %6d %-6.2f %7.2f %-6.2f %-6.2f %-6.3f %-6.3f %s\n";
char *ksink_fmt = "\n\
Alignment Offset %-8.8s %-8.8s Sends %-8.8s Recvs\n\
Local Remote Local Remote Xfered Per Per\n\
Send Recv Send Recv Send (avg) Recv (avg)\n\
%5d %5d %5d %5d %6.4g %6.2f %6d %6.2f %6d\n";
char *ksink_fmt2 = "\n\
Maximum\n\
Segment\n\
Size (bytes)\n\
%6d\n";
float elapsed_time;
/* what we want is to have a buffer space that is at least one */
/* send-size greater than our send window. this will insure that we */
/* are never trying to re-use a buffer that may still be in the hands */
/* of the transport. This buffer will be malloc'd after we have found */
/* the size of the local senc socket buffer. We will want to deal */
/* with alignment and offset concerns as well. */
struct ring_elt *send_ring;
int len;
unsigned int nummessages = 0;
SOCKET send_socket;
int bytes_remaining;
int sdp_mss = -1; /* possibly uninitialized on printf far below */
/* with links like fddi, one can send > 32 bits worth of bytes */
/* during a test... ;-) at some point, this should probably become a */
/* 64bit integral type, but those are not entirely common yet */
unsigned long long local_bytes_sent = 0;
double bytes_sent = 0.0;
float local_cpu_utilization;
float local_service_demand;
float remote_cpu_utilization;
float remote_service_demand;
double thruput;
struct addrinfo *remote_res;
struct addrinfo *local_res;
struct sdp_stream_request_struct *sdp_stream_request;
struct sdp_stream_response_struct *sdp_stream_response;
struct sdp_stream_results_struct *sdp_stream_result;
sdp_stream_request =
(struct sdp_stream_request_struct *)netperf_request.content.test_specific_data;
sdp_stream_response =
(struct sdp_stream_response_struct *)netperf_response.content.test_specific_data;
sdp_stream_result =
(struct sdp_stream_results_struct *)netperf_response.content.test_specific_data;
#ifdef WANT_HISTOGRAM
if (verbosity > 1) {
time_hist = HIST_new();
}
#endif /* WANT_HISTOGRAM */
/* since we are now disconnected from the code that established the */
/* control socket, and since we want to be able to use different */
/* protocols and such, we are passed the name of the remote host and */
/* must turn that into the test specific addressing information. */
/* complete_addrinfos will either succede or exit the process */
complete_addrinfos(&remote_res,
&local_res,
remote_host,
SOCK_STREAM,
IPPROTO_TCP,
0);
if ( print_headers ) {
print_top_test_header("SDP STREAM TEST",local_res,remote_res);
}
send_ring = NULL;
confidence_iteration = 1;
init_stat();
/* we have a great-big while loop which controls the number of times */
/* we run a particular test. this is for the calculation of a */
/* confidence interval (I really should have stayed awake during */
/* probstats :). If the user did not request confidence measurement */
/* (no confidence is the default) then we will only go though the */
/* loop once. the confidence stuff originates from the folks at IBM */
while (((confidence < 0) && (confidence_iteration < iteration_max)) ||
(confidence_iteration <= iteration_min)) {
/* initialize a few counters. we have to remember that we might be */
/* going through the loop more than once. */
nummessages = 0;
bytes_sent = 0.0;
times_up = 0;
/*set up the data socket */
/* fake things out by changing local_res->ai_family to AF_INET_SDP */
local_res->ai_family = AF_INET_SDP;
local_res->ai_protocol = 0;
send_socket = create_data_socket(local_res);
if (send_socket == INVALID_SOCKET){
perror("netperf: send_sdp_stream: sdp stream data socket");
exit(1);
}
if (debug) {
fprintf(where,"send_sdp_stream: send_socket obtained...\n");
}
/* at this point, we have either retrieved the socket buffer sizes, */
/* or have tried to set them, so now, we may want to set the send */
/* size based on that (because the user either did not use a -m */
/* option, or used one with an argument of 0). If the socket buffer */
/* size is not available, we will set the send size to 4KB - no */
/* particular reason, just arbitrary... */
if (send_size == 0) {
if (lss_size > 0) {
send_size = lss_size;
}
else {
send_size = 4096;
}
}
/* set-up the data buffer ring with the requested alignment and offset. */
/* note also that we have allocated a quantity */
/* of memory that is at least one send-size greater than our socket */
/* buffer size. We want to be sure that there are at least two */
/* buffers allocated - this can be a bit of a problem when the */
/* send_size is bigger than the socket size, so we must check... the */
/* user may have wanted to explicitly set the "width" of our send */
/* buffers, we should respect that wish... */
if (send_width == 0) {
send_width = (lss_size/send_size) + 1;
if (send_width == 1) send_width++;
}
if (send_ring == NULL) {
/* only allocate the send ring once. this is a networking test, */
/* not a memory allocation test. this way, we do not need a */
/* deallocate_buffer_ring() routine, and I don't feel like */
/* writing one anyway :) raj 11/94 */
send_ring = allocate_buffer_ring(send_width,
send_size,
local_send_align,
local_send_offset);
}
/* If the user has requested cpu utilization measurements, we must */
/* calibrate the cpu(s). We will perform this task within the tests */
/* themselves. If the user has specified the cpu rate, then */
/* calibrate_local_cpu will return rather quickly as it will have */
/* nothing to do. If local_cpu_rate is zero, then we will go through */
/* all the "normal" calibration stuff and return the rate back. */
if (local_cpu_usage) {
local_cpu_rate = calibrate_local_cpu(local_cpu_rate);
}
if (!no_control) {
/* Tell the remote end to do a listen. The server alters the
socket paramters on the other side at this point, hence the
reason for all the values being passed in the setup
message. If the user did not specify any of the parameters,
they will be passed as 0, which will indicate to the remote
that no changes beyond the system's default should be
used. Alignment is the exception, it will default to 1, which
will be no alignment alterations. */
netperf_request.content.request_type = DO_SDP_STREAM;
sdp_stream_request->send_buf_size = rss_size_req;
sdp_stream_request->recv_buf_size = rsr_size_req;
sdp_stream_request->receive_size = recv_size;
sdp_stream_request->no_delay = rem_nodelay;
sdp_stream_request->recv_alignment = remote_recv_align;
sdp_stream_request->recv_offset = remote_recv_offset;
sdp_stream_request->measure_cpu = remote_cpu_usage;
sdp_stream_request->cpu_rate = remote_cpu_rate;
if (test_time) {
sdp_stream_request->test_length = test_time;
}
else {
sdp_stream_request->test_length = test_bytes;
}
sdp_stream_request->so_rcvavoid = rem_rcvavoid;
sdp_stream_request->so_sndavoid = rem_sndavoid;
#ifdef DIRTY
sdp_stream_request->dirty_count = rem_dirty_count;
sdp_stream_request->clean_count = rem_clean_count;
#endif /* DIRTY */
sdp_stream_request->port = atoi(remote_data_port);
sdp_stream_request->ipfamily = af_to_nf(remote_res->ai_family);
if (debug > 1) {
fprintf(where,
"netperf: send_sdp_stream: requesting SDP stream test\n");
}
send_request();
/* The response from the remote will contain all of the relevant
socket parameters for this test type. We will put them back
into the variables here so they can be displayed if desired.
The remote will have calibrated CPU if necessary, and will
have done all the needed set-up we will have calibrated the
cpu locally before sending the request, and will grab the
counter value right after the connect returns. The remote
will grab the counter right after the accept call. This saves
the hassle of extra messages being sent for the SDP
tests. */
recv_response();
if (!netperf_response.content.serv_errno) {
if (debug)
fprintf(where,"remote listen done.\n");
rsr_size = sdp_stream_response->recv_buf_size;
rss_size = sdp_stream_response->send_buf_size;
rem_nodelay = sdp_stream_response->no_delay;
remote_cpu_usage= sdp_stream_response->measure_cpu;
remote_cpu_rate = sdp_stream_response->cpu_rate;
/* we have to make sure that the server port number is in
network order */
set_port_number(remote_res,
(short)sdp_stream_response->data_port_number);
rem_rcvavoid = sdp_stream_response->so_rcvavoid;
rem_sndavoid = sdp_stream_response->so_sndavoid;
}
else {
Set_errno(netperf_response.content.serv_errno);
fprintf(where,
"netperf: remote error %d",
netperf_response.content.serv_errno);
perror("");
fflush(where);
exit(1);
}
}
#ifdef WANT_DEMO
DEMO_STREAM_SETUP(lss_size,rsr_size)
#endif
/*Connect up to the remote port on the data socket */
if (connect(send_socket,
remote_res->ai_addr,
remote_res->ai_addrlen) == INVALID_SOCKET){
perror("netperf: send_sdp_stream: data socket connect failed");
exit(1);
}
/* Data Socket set-up is finished. If there were problems, either */
/* the connect would have failed, or the previous response would */
/* have indicated a problem. I failed to see the value of the */
/* extra message after the accept on the remote. If it failed, */
/* we'll see it here. If it didn't, we might as well start pumping */
/* data. */
/* Set-up the test end conditions. For a stream test, they can be */
/* either time or byte-count based. */
if (test_time) {
/* The user wanted to end the test after a period of time. */
times_up = 0;
bytes_remaining = 0;
/* in previous revisions, we had the same code repeated throught */
/* all the test suites. this was unnecessary, and meant more */
/* work for me when I wanted to switch to POSIX signals, so I */
/* have abstracted this out into a routine in netlib.c. if you */
/* are experiencing signal problems, you might want to look */
/* there. raj 11/94 */
start_timer(test_time);
}
else {
/* The tester wanted to send a number of bytes. */
bytes_remaining = test_bytes;
times_up = 1;
}
/* The cpu_start routine will grab the current time and possibly */
/* value of the idle counter for later use in measuring cpu */
/* utilization and/or service demand and thruput. */
cpu_start(local_cpu_usage);
/* we only start the interval timer if we are using the
timer-timed intervals rather than the sit and spin ones. raj
2006-02-06 */
#if defined(WANT_INTERVALS)
INTERVALS_INIT();
#endif /* WANT_INTERVALS */
/* before we start, initialize a few variables */
#ifdef WANT_DEMO
if (demo_mode) {
HIST_timestamp(demo_one_ptr);
}
#endif
/* We use an "OR" to control test execution. When the test is */
/* controlled by time, the byte count check will always return false. */
/* When the test is controlled by byte count, the time test will */
/* always return false. When the test is finished, the whole */
/* expression will go false and we will stop sending data. */
while ((!times_up) || (bytes_remaining > 0)) {
#ifdef DIRTY
access_buffer(send_ring->buffer_ptr,
send_size,
loc_dirty_count,
loc_clean_count);
#endif /* DIRTY */
#ifdef WANT_HISTOGRAM
if (verbosity > 1) {
/* timestamp just before we go into send and then again just
after we come out raj 8/94 */
/* but lets only do this if there is going to be a histogram
displayed */
HIST_timestamp(&time_one);
}
#endif /* WANT_HISTOGRAM */
if((len=send(send_socket,
send_ring->buffer_ptr,
send_size,
0)) != send_size) {
if ((len >=0) || SOCKET_EINTR(len)) {
/* the test was interrupted, must be the end of test */
break;
}
perror("netperf: data send error");
printf("len was %d\n",len);
exit(1);
}
local_bytes_sent += send_size;
#ifdef WANT_HISTOGRAM
if (verbosity > 1) {
/* timestamp the exit from the send call and update the histogram */
HIST_timestamp(&time_two);
HIST_add(time_hist,delta_micro(&time_one,&time_two));
}
#endif /* WANT_HISTOGRAM */
#ifdef WANT_DEMO
DEMO_STREAM_INTERVAL(send_size)
#endif
#if defined(WANT_INTERVALS)
INTERVALS_WAIT();
#endif /* WANT_INTERVALS */
/* now we want to move our pointer to the next position in the */
/* data buffer...we may also want to wrap back to the "beginning" */
/* of the bufferspace, so we will mod the number of messages sent */
/* by the send width, and use that to calculate the offset to add */
/* to the base pointer. */
nummessages++;
send_ring = send_ring->next;
if (bytes_remaining) {
bytes_remaining -= send_size;
}
}
/* The test is over. Flush the buffers to the remote end. We do a */
/* graceful release to insure that all data has been taken by the */
/* remote. */
/* but first, if the verbosity is greater than 1, find-out what */
/* the SDP maximum segment_size was (if possible) */
if (verbosity > 1) {
sdp_mss = -1;
get_sdp_info(send_socket,&sdp_mss);
}
if (shutdown(send_socket,SHUT_WR) == SOCKET_ERROR) {
perror("netperf: cannot shutdown sdp stream socket");
exit(1);
}
/* hang a recv() off the socket to block until the remote has */
/* brought all the data up into the application. it will do a */
/* shutdown to cause a FIN to be sent our way. We will assume that */
/* any exit from the recv() call is good... raj 4/93 */
recv(send_socket, send_ring->buffer_ptr, send_size, 0);
/* this call will always give us the elapsed time for the test, and */
/* will also store-away the necessaries for cpu utilization */
cpu_stop(local_cpu_usage,&elapsed_time); /* was cpu being */
/* measured and how */
/* long did we really */
/* run? */
/* we are finished with the socket, so close it to prevent hitting */
/* the limit on maximum open files. */
close(send_socket);
if (!no_control) {
/* Get the statistics from the remote end. The remote will have
calculated service demand and all those interesting
things. If it wasn't supposed to care, it will return obvious
values. */
recv_response();
if (!netperf_response.content.serv_errno) {
if (debug)
fprintf(where,"remote results obtained\n");
}
else {
Set_errno(netperf_response.content.serv_errno);
fprintf(where,
"netperf: remote error %d",
netperf_response.content.serv_errno);
perror("");
fflush(where);
exit(1);
}
/* We now calculate what our thruput was for the test. In the
future, we may want to include a calculation of the thruput
measured by the remote, but it should be the case that for a
SDP stream test, that the two numbers should be *very*
close... We calculate bytes_sent regardless of the way the
test length was controlled. If it was time, we needed to,
and if it was by bytes, the user may have specified a number
of bytes that wasn't a multiple of the send_size, so we
really didn't send what he asked for ;-) */
bytes_sent = ntohd(sdp_stream_result->bytes_received);
}
else {
bytes_sent = (double)local_bytes_sent;
}
thruput = calc_thruput(bytes_sent);
if (local_cpu_usage || remote_cpu_usage) {
/* We must now do a little math for service demand and cpu */
/* utilization for the system(s) */
/* Of course, some of the information might be bogus because */
/* there was no idle counter in the kernel(s). We need to make */
/* a note of this for the user's benefit...*/
if (local_cpu_usage) {
local_cpu_utilization = calc_cpu_util(0.0);
local_service_demand = calc_service_demand(bytes_sent,
0.0,
0.0,
0);
}
else {
local_cpu_utilization = (float) -1.0;
local_service_demand = (float) -1.0;
}
if (remote_cpu_usage) {
remote_cpu_utilization = sdp_stream_result->cpu_util;
remote_service_demand = calc_service_demand(bytes_sent,
0.0,
remote_cpu_utilization,
sdp_stream_result->num_cpus);
}
else {
remote_cpu_utilization = (float) -1.0;
remote_service_demand = (float) -1.0;
}
}
else {
/* we were not measuring cpu, for the confidence stuff, we */
/* should make it -1.0 */
local_cpu_utilization = (float) -1.0;
local_service_demand = (float) -1.0;
remote_cpu_utilization = (float) -1.0;
remote_service_demand = (float) -1.0;
}
/* at this point, we want to calculate the confidence information. */
/* if debugging is on, calculate_confidence will print-out the */
/* parameters we pass it */
calculate_confidence(confidence_iteration,
elapsed_time,
thruput,
local_cpu_utilization,
remote_cpu_utilization,
local_service_demand,
remote_service_demand);
confidence_iteration++;
}
/* at this point, we have finished making all the runs that we */
/* will be making. so, we should extract what the calcuated values */
/* are for all the confidence stuff. we could make the values */
/* global, but that seemed a little messy, and it did not seem worth */
/* all the mucking with header files. so, we create a routine much */
/* like calcualte_confidence, which just returns the mean values. */
/* raj 11/94 */
retrieve_confident_values(&elapsed_time,
&thruput,
&local_cpu_utilization,
&remote_cpu_utilization,
&local_service_demand,
&remote_service_demand);
/* We are now ready to print all the information. If the user */
/* has specified zero-level verbosity, we will just print the */
/* local service demand, or the remote service demand. If the */
/* user has requested verbosity level 1, he will get the basic */
/* "streamperf" numbers. If the user has specified a verbosity */
/* of greater than 1, we will display a veritable plethora of */
/* background information from outside of this block as it it */
/* not cpu_measurement specific... */
if (confidence < 0) {
/* we did not hit confidence, but were we asked to look for it? */
if (iteration_max > 1) {
display_confidence();
}
}
if (local_cpu_usage || remote_cpu_usage) {
local_cpu_method = format_cpu_method(cpu_method);
remote_cpu_method = format_cpu_method(sdp_stream_result->cpu_method);
switch (verbosity) {
case 0:
if (local_cpu_usage) {
fprintf(where,
cpu_fmt_0,
local_service_demand,
local_cpu_method,
((print_headers) ||
(result_brand == NULL)) ? "" : result_brand);
}
else {
fprintf(where,
cpu_fmt_0,
remote_service_demand,
remote_cpu_method,
((print_headers) ||
(result_brand == NULL)) ? "" : result_brand);
}
break;
case 1:
case 2:
if (print_headers) {
fprintf(where,
cpu_title,
format_units(),
local_cpu_method,
remote_cpu_method);
}
fprintf(where,
cpu_fmt_1, /* the format string */
rsr_size, /* remote recvbuf size */
lss_size, /* local sendbuf size */
send_size, /* how large were the sends */
elapsed_time, /* how long was the test */
thruput, /* what was the xfer rate */
local_cpu_utilization, /* local cpu */
remote_cpu_utilization, /* remote cpu */
local_service_demand, /* local service demand */
remote_service_demand, /* remote service demand */
((print_headers) ||
(result_brand == NULL)) ? "" : result_brand);
break;
}
}
else {
/* The tester did not wish to measure service demand. */
switch (verbosity) {
case 0:
fprintf(where,
tput_fmt_0,
thruput,
((print_headers) ||
(result_brand == NULL)) ? "" : result_brand);
break;
case 1:
case 2:
if (print_headers) {
fprintf(where,tput_title,format_units());
}
fprintf(where,
tput_fmt_1, /* the format string */
rsr_size, /* remote recvbuf size */
lss_size, /* local sendbuf size */
send_size, /* how large were the sends */
elapsed_time, /* how long did it take */
thruput, /* how fast did it go */
((print_headers) ||
(result_brand == NULL)) ? "" : result_brand);
break;
}
}
/* it would be a good thing to include information about some of the */
/* other parameters that may have been set for this test, but at the */
/* moment, I do not wish to figure-out all the formatting, so I will */
/* just put this comment here to help remind me that it is something */
/* that should be done at a later time. */
if (verbosity > 1) {
/* The user wanted to know it all, so we will give it to him. */
/* This information will include as much as we can find about */
/* SDP statistics, the alignments of the sends and receives */
/* and all that sort of rot... */
/* this stuff needs to be worked-out in the presence of confidence */
/* intervals and multiple iterations of the test... raj 11/94 */
fprintf(where,
ksink_fmt,
"Bytes",
"Bytes",
"Bytes",
local_send_align,
remote_recv_align,
local_send_offset,
remote_recv_offset,
bytes_sent,
bytes_sent / (double)nummessages,
nummessages,
bytes_sent / (double)sdp_stream_result->recv_calls,
sdp_stream_result->recv_calls);
fprintf(where,
ksink_fmt2,
sdp_mss);
fflush(where);
#ifdef WANT_HISTOGRAM
fprintf(where,"\n\nHistogram of time spent in send() call.\n");
fflush(where);
HIST_report(time_hist);
#endif /* WANT_HISTOGRAM */
}
}
/* This routine implements the netperf-side SDP unidirectional data
transfer test (a.k.a. stream) for the sockets interface where the
data flow is from the netserver to the netperf. It receives its
parameters via global variables from the shell and writes its
output to the standard output. */
void
send_sdp_maerts(char remote_host[])
{
char *tput_title = "\
Recv Send Send \n\
Socket Socket Message Elapsed \n\
Size Size Size Time Throughput \n\
bytes bytes bytes secs. %s/sec \n\n";
char *tput_fmt_0 =
"%7.2f %s\n";
char *tput_fmt_1 =
"%6d %6d %6d %-6.2f %7.2f \n %s";
char *cpu_title = "\
Recv Send Send Utilization Service Demand\n\
Socket Socket Message Elapsed Send Recv Send Recv\n\
Size Size Size Time Throughput local remote local remote\n\
bytes bytes bytes secs. %-8.8s/s %% %c %% %c us/KB us/KB\n\n";
char *cpu_fmt_0 =
"%6.3f %c %s\n";
char *cpu_fmt_1 =
"%6d %6d %6d %-6.2f %7.2f %-6.2f %-6.2f %-6.3f %-6.3f %s\n";
char *ksink_fmt = "\n\
Alignment Offset %-8.8s %-8.8s Recvs %-8.8s Sends\n\
Local Remote Local Remote Xfered Per Per\n\
Recv Send Recv Send Recv (avg) Send (avg)\n\
%5d %5d %5d %5d %6.4g %6.2f %6d %6.2f %6d\n";
char *ksink_fmt2 = "\n\
Maximum\n\
Segment\n\
Size (bytes)\n\
%6d\n";
float elapsed_time;
/* what we want is to have a buffer space that is at least one */
/* recv-size greater than our recv window. this will insure that we */
/* are never trying to re-use a buffer that may still be in the hands */
/* of the transport. This buffer will be malloc'd after we have found */
/* the size of the local senc socket buffer. We will want to deal */
/* with alignment and offset concerns as well. */
struct ring_elt *recv_ring;
int len;
unsigned int nummessages = 0;
SOCKET recv_socket;
int bytes_remaining;
int sdp_mss = -1; /* possibly uninitialized on printf far below */
/* with links like fddi, one can recv > 32 bits worth of bytes */
/* during a test... ;-) at some point, this should probably become a */
/* 64bit integral type, but those are not entirely common yet */
double bytes_sent = 0.0;
unsigned long long local_bytes_recvd = 0;
float local_cpu_utilization;
float local_service_demand;
float remote_cpu_utilization;
float remote_service_demand;
double thruput;
struct addrinfo *remote_res;
struct addrinfo *local_res;
struct sdp_maerts_request_struct *sdp_maerts_request;
struct sdp_maerts_response_struct *sdp_maerts_response;
struct sdp_maerts_results_struct *sdp_maerts_result;
sdp_maerts_request =
(struct sdp_maerts_request_struct *)netperf_request.content.test_specific_data;
sdp_maerts_response =
(struct sdp_maerts_response_struct *)netperf_response.content.test_specific_data;
sdp_maerts_result =
(struct sdp_maerts_results_struct *)netperf_response.content.test_specific_data;
#ifdef WANT_HISTOGRAM
if (verbosity > 1) {
time_hist = HIST_new();
}
#endif /* WANT_HISTOGRAM */
/* since we are now disconnected from the code that established the */
/* control socket, and since we want to be able to use different */
/* protocols and such, we are passed the name of the remote host and */
/* must turn that into the test specific addressing information. */
complete_addrinfos(&remote_res,
&local_res,
remote_host,
SOCK_STREAM,
IPPROTO_TCP,
0);
if ( print_headers ) {
print_top_test_header("SDP MAERTS TEST",local_res,remote_res);
}
recv_ring = NULL;
confidence_iteration = 1;
init_stat();
/* we have a great-big while loop which controls the number of times */
/* we run a particular test. this is for the calculation of a */
/* confidence interval (I really should have stayed awake during */
/* probstats :). If the user did not request confidence measurement */
/* (no confidence is the default) then we will only go though the */
/* loop once. the confidence stuff originates from the folks at IBM */
while (((confidence < 0) && (confidence_iteration < iteration_max)) ||
(confidence_iteration <= iteration_min)) {
/* initialize a few counters. we have to remember that we might be */
/* going through the loop more than once. */
nummessages = 0;
bytes_sent = 0.0;
times_up = 0;
/*set up the data socket */
/* fake things out by changing local_res->ai_family to AF_INET_SDP */
local_res->ai_family = AF_INET_SDP;
local_res->ai_protocol = 0;
recv_socket = create_data_socket(local_res);
if (recv_socket == INVALID_SOCKET){
perror("netperf: send_sdp_maerts: sdp stream data socket");
exit(1);