3 #include <sys/socket.h>
4 #include <netinet/in.h>
19 #include <semaphore.h>
20 #include <sys/ioctl.h>
24 #include <fwp_confdefs.h>
29 #define MAX_STREAMS 10
30 #define MIN_GRANULARITY 100
32 unsigned opt_packet_size = 800;
33 int opt_send_buf_size = -1;
34 unsigned opt_period_usec = 10*MSEC_TO_USEC;
36 unsigned opt_jitter = 0;
37 char *opt_output = "delay_stats";
38 unsigned opt_count_sec = 0;
39 unsigned opt_def_bandwidth = 200;
40 unsigned opt_def_period_msec = 0;
41 int opt_granularity_usec = MIN_GRANULARITY;
42 bool opt_wait_for_queue_is_full; /* Don't gather any statistics until any queue is full */
43 char *opt_comment = NULL;
45 bool some_queue_is_full = false;
46 struct timespec reset_timestamp;
48 /* Locked when some queue is full to prevent multiple resets of
50 pthread_mutex_t queue_full_mutex = PTHREAD_MUTEX_INITIALIZER;
52 int ac_sockfd[AC_NUM];
56 unsigned received, last_received;
63 /* maximal traffic delay in ms - 10 s*/
64 #define MAX_DELAY_US 10000000
67 unsigned csc; /* Client-server-client delay divided by 2 */
68 unsigned cs; /* Client-server delay */
69 unsigned sc; /* Server-client delay */
72 struct delay_stat delay_stats[AC_NUM][MAX_DELAY_US/MIN_GRANULARITY];
73 pthread_mutex_t delay_stats_mutex = PTHREAD_MUTEX_INITIALIZER;
75 /*struct ac_stats[AC_NUM] {
76 unsigned long int min_trans_time;
77 unsigned long int sum_trans_time;
78 struct timespec recv_timestamp;
79 struct timespec send_timestamp;
83 /* Input parameters */
85 int bandwidth_bps; /* bits per second */
86 int jitter; /* percent */
87 /* Mulualy exclusive input parameters */
89 long period_usec; /* all time units are in microseconds */
93 struct sockaddr_in rem_addr;
95 fwp_endpoint_d_t endpoint;
100 pthread_mutex_t mutex;
101 unsigned long long sent, really_sent, received;
104 static struct cmsg_ipi {
106 struct in_pktinfo ipi;
107 } cmsg = { {sizeof(struct cmsg_ipi), SOL_IP, IP_PKTINFO},
112 struct send_endpoint sepoint[] = {
113 { .ac = AC_VO, .period_usec=200*MSEC_TO_USEC, .bandwidth_bps = 34*Kbit },
114 { .ac = AC_VI, .period_usec=25*MSEC_TO_USEC, .bandwidth_bps = 480*Kbit },
115 { .ac = AC_BE, .period_usec=40*MSEC_TO_USEC, .bandwidth_bps = 300*Kbit },
116 { .ac = AC_BK, .period_usec=40*MSEC_TO_USEC, .bandwidth_bps = 300*Kbit },
117 // { .ac = AC_VI, .period_usec=17*MSEC_TO_USEC, .bandwidth_bps = 675*Kbit },
121 struct stream streams[MAX_STREAMS];
123 unsigned int nr_streams = 0;
125 sem_t sem_thread_finished;
127 bool exit_flag = false;
130 #define negotiate_contract_for_stream(s) negotiate_contract_for_stream_fwp(s)
131 #define create_stream_endpoint(s) create_stream_endpoint_fwp(s)
132 #define send_packet(s, b) send_packet_fwp(s, b)
134 #define negotiate_contract_for_stream(s) 0
135 #define create_stream_endpoint(s) create_stream_endpoint_native(s)
136 #define send_packet(s, b) send_packet_native(s, b)
144 /* Interrupt all receivers */
145 for (i=0; i < AC_NUM; i++) {
146 pthread_kill(receivers[i].thread, SIGUSR1);
150 void stream_to_text(char *stream_desc, size_t n, struct stream *stream, long long useconds)
156 snprintf(real, sizeof(real), "; real: %s sent %lld (%lld/s), received %lld (%lld/s)",
157 bandwidth_to_text(buf[0], (long long)stream->really_sent*stream->packet_size*8*SEC_TO_USEC/useconds),
158 stream->sent, stream->sent*SEC_TO_USEC/useconds,
159 stream->received, stream->received*SEC_TO_USEC/useconds);
164 snprintf(stream_desc, n, "%d: %s %s (%d bytes per %s +-%s, %d packets/s)%s",
165 stream-streams, ac_to_text[stream->ac], bandwidth_to_text(buf[0], stream->bandwidth_bps),
166 stream->packet_size, usec_to_text(buf[1], stream->period_usec),
167 usec_to_text(buf[2], stream->jitter*stream->period_usec/100),
168 (int)(SEC_TO_USEC/stream->period_usec), real);
171 void save_results(int argc, char *argv[], int useconds)
174 const int mini = 3000/opt_granularity_usec;
176 unsigned send_count[AC_NUM];
178 fprintf(stderr, "Writing data to %s... ", logfname);
181 fprintf(logfd, "# Invoked as: ");
182 for (i=0; i<argc; i++) fprintf(logfd, "%s ", argv[i]);
184 fprintf(logfd, "(%s)", opt_comment);
186 fprintf(logfd, "\n");
188 if (useconds/SEC_TO_USEC != opt_count_sec) {
190 usec_to_text(buf, useconds);
191 fprintf(logfd, "# Data gathered for %s.\n", buf);
194 for (i = 0; i < nr_streams; i++) {
195 char stream_desc[200];
196 stream_to_text(stream_desc, sizeof(stream_desc), &streams[i], useconds);
197 fprintf(logfd, "# Stream %s\n", stream_desc);
200 /* Find maximal delay */
202 for (maxi = MAX_DELAY_US/opt_granularity_usec - 1; maxi >= 0; maxi--) {
203 for (ac = 0; ac < AC_NUM; ac++) {
204 if ((delay_stats[ac][maxi].csc != 0) ||
205 (delay_stats[ac][maxi].cs != 0) ||
206 (delay_stats[ac][maxi].sc != 0))
209 if (!allzeros) break;
212 if (maxi < mini) maxi = mini;
214 /* Calculate total number of sent packets per AC */
215 memset(send_count, 0, sizeof(send_count));
216 for (i = 0; i < nr_streams; i++) {
218 send_count[ac] += streams[i].sent;
223 for ( i = 0 ; i < maxi; i++) {
224 fprintf(logfd,"\n%f", i*opt_granularity_usec/1000.0);
225 for (ac = 0; ac < AC_NUM; ac++) {
227 val = (double)delay_stats[ac][i]*100.0 / sum[ac];
228 else val = -1; /* Don't display this ac */
229 fprintf(logfd," %lf", val);
233 fprintf(logfd,"\n\n");
236 fprintf(logfd,"## Format: msec csc%% cs%% sc%%\n");
239 for (ac = 0; ac < AC_NUM; ac++) {
240 struct delay_stat integral = {0,0,0}, last = {-1,-1,-1};
242 fprintf(logfd,"%f %f %f %f\n", 0.0, 0.0, 0.0, 0.0);
244 if (send_count[ac] != 0) {
246 while ((delay_stats[ac][i].csc == 0) &&
247 (delay_stats[ac][i].cs == 0) &&
248 (delay_stats[ac][i].sc == 0)) i++;
250 for (i++; i < maxi+1; i++) {
251 if (memcmp(&last, &integral, sizeof(last))) {
253 snprintf(buf[0], sizeof(buf[0]), "%f", (double)integral.csc*100.0 / send_count[ac]);
254 snprintf(buf[1], sizeof(buf[1]), "%f", (double)integral.cs *100.0 / send_count[ac]);
255 snprintf(buf[2], sizeof(buf[2]), "%f", (double)integral.sc *100.0 / send_count[ac]);
257 fprintf(logfd,"%f %s %s %s\n", i*opt_granularity_usec/1000.0,
258 integral.csc != last.csc ? buf[0] : "-",
259 integral.cs != last.cs ? buf[1] : "-",
260 integral.sc != last.sc ? buf[2] : "-"
265 integral.csc += delay_stats[ac][i-1].csc;
266 integral.sc += delay_stats[ac][i-1].sc;
267 integral.cs += delay_stats[ac][i-1].cs;
271 fprintf(logfd,"\n\n");
274 fprintf(stderr, "finished.\n");
280 int create_ac_socket(unsigned int ac)
283 unsigned int yes=1, tos;
286 if ((sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
288 perror("Unable to open socket");
291 if (fcntl(sockfd, F_SETFL, O_NONBLOCK) != 0) {
292 perror("set non-blocking socket");
295 if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) {
296 perror("Unable to set socket");
300 if (opt_send_buf_size >= 0) {
301 if (setsockopt(sockfd,SOL_SOCKET,SO_SNDBUF,&opt_send_buf_size,sizeof(opt_send_buf_size)) == -1) {
302 perror("Unable to set socket buffer size");
308 //tos = ((AC_NUM - ac) *2 - 1)*32;
310 if (setsockopt(sockfd, SOL_IP, IP_TOS, &tos, sizeof(tos))) {
311 perror("Unable to set TOS");
323 void reset_statistics()
326 for (i = 0; i < nr_streams; i++) {
327 pthread_mutex_lock(&streams[i].mutex);
329 streams[i].really_sent = 0;
330 streams[i].received = 0;
331 pthread_mutex_unlock(&streams[i].mutex);
333 pthread_mutex_lock(&delay_stats_mutex);
334 clock_gettime(CLOCK_REALTIME, &reset_timestamp);
335 memset(delay_stats, 0, sizeof(delay_stats));
336 pthread_mutex_unlock(&delay_stats_mutex);
339 void* receiver(void* queue)
342 struct sockaddr_in rem_addr;
344 unsigned int ac, rem_addr_length;
345 long long int trans_time_usec, client_to_server_usec, server_to_client_usec;
346 long long int min_trans_time;
347 struct timespec send_timestamp, server_timestamp, recv_timestamp;
356 rem_addr_length = sizeof(rem_addr);
359 FD_SET(ac_sockfd[ac], &fdset);
360 ret = select(ac_sockfd[ac]+1, &fdset, NULL, NULL, NULL);
362 if (errno == EINTR) continue;
363 perror("receiver select");
366 mlen = recvfrom(ac_sockfd[ac], &msg, sizeof(msg), 0,
367 (struct sockaddr*)&rem_addr, &rem_addr_length);
369 perror("Chyba pri prijimani pozadavku");
372 clock_gettime(CLOCK_REALTIME,&recv_timestamp);
373 send_timestamp = msg.send_timestamp;
374 server_timestamp = msg.sendback_timestamp;
376 /* Check whether this message was sent after reset_statistics() */
378 if ((ret = timespec_sub_usec(&send_timestamp, &reset_timestamp)) < 0) {
379 continue; /* If so, don't count it */
382 trans_time_usec = timespec_sub_usec(&recv_timestamp ,&send_timestamp) / 2;
383 client_to_server_usec = timespec_sub_usec(&server_timestamp, &send_timestamp);
384 server_to_client_usec = timespec_sub_usec(&recv_timestamp, &server_timestamp);
386 pthread_mutex_lock(&delay_stats_mutex);
387 if (trans_time_usec < MAX_DELAY_US && trans_time_usec >= 0) {
388 delay_stats[ac][trans_time_usec/opt_granularity_usec].csc++;
390 if (client_to_server_usec < MAX_DELAY_US && client_to_server_usec >= 0) {
391 delay_stats[ac][client_to_server_usec/opt_granularity_usec].cs++;
393 if (server_to_client_usec < MAX_DELAY_US && server_to_client_usec >= 0) {
394 delay_stats[ac][server_to_client_usec/opt_granularity_usec].sc++;
396 pthread_mutex_unlock(&delay_stats_mutex);
398 receivers[ac].received++;
400 pthread_mutex_lock(&streams[msg.stream].mutex);
401 streams[msg.stream].received++;
402 pthread_mutex_unlock(&streams[msg.stream].mutex);
404 /*if (trans_time_nsec < min_trans_time)
405 min_trans_time = trans_time_nsec;*/
406 /*printf("seqn= %lu tos= %d start= %lu(s).%lu(ns)"\
407 "stop= %lu(s).%lu(ns)\n trans_time = %lums\n",\
408 msg.seqn, msg.tos, send_timestamp.tv_sec,\
409 send_timestamp.tv_nsec,recv_timestamp.tv_sec,\
410 recv_timestamp.tv_nsec, trans_time_msec); */
413 sem_post(&sem_thread_finished);
420 * @return -1 in case of error, 1 in case of sucessfull send and 0
421 * when all buffers are full.
425 send_packet_native(struct stream* stream, union msg_buff* buff)
431 iov.iov_len = stream->packet_size;
432 msg.msg_name = (void*)&stream->rem_addr;
433 msg.msg_namelen = sizeof(stream->rem_addr);
437 msg.msg_control = &cmsg;
438 msg.msg_controllen = cmsg_len;
442 while (sendmsg(ac_sockfd[stream->ac], &msg, 0) < 0) {
443 if (errno == EINTR) continue;
444 if (errno == EAGAIN) {
445 if (opt_wait_for_queue_is_full &&
446 !some_queue_is_full &&
447 /* We use mutex as atomic test and set */
448 (pthread_mutex_trylock(&queue_full_mutex) != EBUSY)) {
449 some_queue_is_full = true;
455 perror("Error while sending");
464 send_packet_fwp(struct stream* stream, union msg_buff* buff)
468 ret = fwp_send(stream->endpoint, buff, stream->packet_size, 0);
475 wait_for_next_send(struct stream* stream, struct timespec *last_send_time)
477 struct timespec time_to_wait, current_time, period, interval;
478 unsigned period_usec = stream->period_usec;
480 /* |~~~+~~~| jitter interval (width = 2*stream->jitter percentage from period)*/
481 /* |-------------| nominal period*/
482 if (stream->jitter) {
483 period.tv_nsec = USEC_TO_NSEC*(period_usec*(100-stream->jitter)/100
484 + rand() % (2*period_usec*stream->jitter/100));
486 period.tv_nsec = USEC_TO_NSEC*(period_usec);
490 timespec_add(&time_to_wait, last_send_time, &period);
491 clock_gettime(CLOCK_REALTIME,¤t_time);
492 timespec_sub(&interval,&time_to_wait,¤t_time);
493 nanosleep(&interval,NULL);
497 void* sender(void* arg)
500 unsigned long int seqn;
501 struct stream* stream = (struct stream*) arg;
502 char stream_desc[100];
505 stream_to_text(stream_desc, sizeof(stream_desc), stream, 0);
506 printf("%s\n", stream_desc);
508 if (stream->bandwidth_bps == 0)
514 set_rt_prio(90-stream->ac);
518 /* buff.msg.seqn = seqn++; */
519 /* buff.msg.tos = ac_to_tos[stream->ac]; */
520 buff.msg.stream = stream-streams;
522 clock_gettime(CLOCK_REALTIME,&buff.msg.send_timestamp);
524 ret = send_packet(stream, &buff);
529 pthread_mutex_lock(&stream->mutex);
532 stream->really_sent++;
533 pthread_mutex_unlock(&stream->mutex);
536 printf("%d", stream->ac);
540 wait_for_next_send(stream, &buff.msg.send_timestamp);
543 sem_post(&sem_thread_finished);
548 static int negotiate_contract_for_stream_fwp(struct stream *stream)
550 fwp_contract_t contract;
551 fwp_contract_d_t contract_d;
555 /* Contract for client->server stream */
556 contract.budget = stream->packet_size;
557 contract.period_usec = stream->period_usec;
559 contract_d = fwp_contract_create(&contract);
560 ret = fwp_contract_negotiate(contract_d, &stream->vres);
562 /* Contract for server->client stream */
563 contract.budget = stream->packet_size;
564 contract.period_usec = stream->period_usec;
566 contract_d = fwp_contract_create(&contract);
567 ret = fwp_contract_negotiate(contract_d, &vres2);
569 /* We don't use the vres at server, since the server doesn't
570 * know the parameters. Instread, server uses plain
578 static void create_stream_endpoint_fwp(struct stream *stream)
580 /* fwp_endpoint_attr_t attr; */
584 /* fwp_endpoint_attr_init(&attr); */
585 /* fwp_endpoint_attr_setreliability(&attr, FWP_EPOINT_BESTEFFORT); */
587 ph = gethostbyname(server_addr);
588 if (ph && ph->h_addr_list[0]) {
589 struct in_addr *a = (struct in_addr *)(ph->h_addr_list[0]);
590 ret = fwp_send_endpoint_create(a->s_addr, BASE_PORT + fwp_vres_get_ac(stream->vres),
591 NULL, &stream->endpoint);
592 /* stream->rem_addr.sin_port = htons(BASE_PORT + stream->ac); */
594 perror("fwp_send_endpoint_create");
597 ret = fwp_send_endpoint_bind(stream->endpoint, stream->vres);
599 perror("fwp_send_endpoint_bind");
607 snprintf(str, sizeof(str), "gethostbyname(%s)", server_addr);
614 static void create_stream_endpoint_native(struct stream *stream)
618 memset(&stream->rem_addr,0, sizeof(stream->rem_addr));
620 stream->rem_addr.sin_family = AF_INET;
621 ph = gethostbyname(server_addr);
623 stream->rem_addr.sin_addr = *((struct in_addr *)ph->h_addr);
626 snprintf(str, sizeof(str), "gethostbyname(%s)", server_addr);
630 stream->rem_addr.sin_port = htons(BASE_PORT + stream->ac);
635 calc_stream_params(struct stream *stream)
638 unsigned period_usec;
642 /* If some parameters are not set explicitely, use default values. */
643 if (stream->bandwidth_bps < 0) stream->bandwidth_bps = opt_def_bandwidth * Kbit;
644 if (stream->packet_size < 0) stream->packet_size = opt_packet_size;
645 if (stream->period_usec < 0) stream->period_usec = opt_def_period_msec * MSEC_TO_USEC;
647 bandwidth = stream->bandwidth_bps;
649 /* Avoid arithmetic exception. Server thread will exit if
650 stream->bandwidth_bps == 0. */
651 if (bandwidth == 0) bandwidth = 1;
653 if (stream->packet_size) {
654 packet_size = stream->packet_size;
655 period_usec = SEC_TO_USEC*packet_size*8/bandwidth;
656 if (period_usec == 0) period_usec = 1;
657 } else if (stream->period_usec) {
658 period_usec = stream->period_usec;
659 packet_size = (long long)bandwidth/8 * period_usec/SEC_TO_USEC;
662 stream_to_text(buf, sizeof(buf), stream, 0);
663 fprintf(stderr, "Neither packet size nor period was specified for a stream %s\n", buf);
667 if (packet_size < sizeof(struct msg_t)) {
668 fprintf(stderr, "Packet size too small (min %d)\n", sizeof(struct msg_t));
672 stream->packet_size = packet_size;
673 stream->period_usec = period_usec;
674 stream->jitter = opt_jitter;
676 ret = negotiate_contract_for_stream(stream);
678 create_stream_endpoint(stream);
681 stream_to_text(buf, sizeof(buf), stream, 0);
682 fprintf(stderr, "Contract hasn't been accepted: %s\n", buf);
683 stream->bandwidth_bps = 0;
688 * Parse -b parameter.
690 * @param params String to parse
692 * @return NULL in case of success, pointer to a problematic character
695 char* parse_bandwidths(char *params)
697 struct stream *sp = &streams[nr_streams];
699 while (*params && nr_streams < MAX_STREAMS) {
700 char *ac_ids[AC_NUM] = { [AC_VO]="VO", [AC_VI]="VI", [AC_BE]="BE", [AC_BK]="BK" };
704 if (strlen(params) < 2)
706 for (i=0; i<AC_NUM; i++) {
707 if (strncmp(params, ac_ids[i], 2) == 0) {
709 params+=strlen(ac_ids[i]);
717 if (*params == ':') {
720 bw = strtol(params, &next_char, 10);
721 if (next_char == params)
727 sp->bandwidth_bps = bw*Kbit;
730 long packet_size = 0;
731 if (*params == '@') {
733 period = strtol(params, &next_char, 10);
739 if (*params == '/') {
741 packet_size = strtol(params, &next_char, 10);
742 if (packet_size == 0)
750 sp->period_usec = period*MSEC_TO_USEC;
751 sp->packet_size = packet_size;
755 if (*params != '\0' && *params != ',')
765 int main(int argc, char *argv[])
767 int ac, i, rc, seconds;
773 while ((opt = getopt(argc, argv, "B:b:C:c:g:I:j:o:qQ:s:T:")) != -1) {
776 opt_def_bandwidth = atoi(optarg);
780 error = parse_bandwidths(optarg);
783 fprintf(stderr, "Bandwidth parse error - string to short\n");
785 fprintf(stderr, "Bandwidth parse error at '%s'\n", error);
791 opt_comment = optarg;
794 opt_count_sec = atoi(optarg);
797 opt_granularity_usec = atoi(optarg);
798 if (opt_granularity_usec < MIN_GRANULARITY) {
799 fprintf(stderr, "Granulatiry too small (min %d)!\n", MIN_GRANULARITY);
804 opt_interface = optarg;
808 fprintf(stderr, "-j is not allowd when compiled with FWP\n");
811 opt_jitter = atoi(optarg);
818 opt_send_buf_size = atoi(optarg);
821 opt_wait_for_queue_is_full = true;
824 opt_packet_size = atoi(optarg);
827 opt_def_period_msec = atoi(optarg);
830 fprintf(stderr, "Usage: %s [ options ] server_addr\n\n", argv[0]);
831 fprintf(stderr, "Options:\n");
832 fprintf(stderr, " -B default bandwidth for -b option [kbit]\n");
833 fprintf(stderr, " -b bandwidth of streams (VO|VI|BE|BK)[:<kbit>][@<msec> or /<bytes>][,...]\n");
834 fprintf(stderr, " -C comment (added to header)\n");
835 fprintf(stderr, " -c count (number of seconds to run)\n");
836 fprintf(stderr, " -g histogram granularity [usec]\n");
837 fprintf(stderr, " -I <interface> send packets from this interface");
838 fprintf(stderr, " -j send jitter (0-100) [%%]\n");
839 fprintf(stderr, " -o output filename (.dat will be appended)\n");
840 fprintf(stderr, " -q gather statistics only after some queue becomes full\n");
841 fprintf(stderr, " -Q <bytes> set size for socket send buffers\n");
842 fprintf(stderr, " -s size of data payload in packets [bytes] (default: %d)\n", opt_packet_size);
843 fprintf(stderr, " -T default period for -b option [msec]\n");
847 if (opt_packet_size && opt_def_period_msec) {
848 fprintf(stderr, "Error: Nonzero -T and -s can't be used together!.\n");
853 server_addr = argv[optind];
855 fprintf(stderr, "Expected server address argument\n");
860 parse_bandwidths("BE");
862 pthread_attr_init(&attr);
864 snprintf(logfname, sizeof(logfname), "%s.dat", opt_output);
866 if ((logfd = fopen(logfname,"w+")) == NULL) {
867 fprintf(stderr,"Can not open %s\n", logfname);
870 if (signal(SIGTERM, stopper) == SIG_ERR) {
871 perror("Error in signal registration");
875 if (signal(SIGINT, stopper) == SIG_ERR) {
876 perror("Signal handler registration error");
881 sa.sa_handler = empty_handler;
882 sa.sa_flags = 0; /* don't restart syscalls */
884 if (sigaction(SIGUSR1, &sa, NULL) < 0) {
885 perror("sigaction error");
889 sem_init(&sem_thread_finished, 0, 0);
897 /* create four receivers each per AC */
898 for (ac = AC_NUM - 1; ac >= 0; ac--) {
899 ac_sockfd[ac] = create_ac_socket(ac);
900 if (ac_sockfd[ac] < 0) {
903 rc = pthread_create(&receivers[ac].thread, &attr, receiver, (void*) ac);
905 fprintf(stderr, "Error while creating receiver %d\n",rc);
913 memset(&ifr, 0, sizeof(ifr));
914 strncpy(ifr.ifr_name, opt_interface, IFNAMSIZ-1);
915 if (ioctl(ac_sockfd[AC_VO], SIOCGIFINDEX, &ifr) < 0) {
916 fprintf(stderr, "unknown iface %s\n", opt_interface);
919 cmsg.ipi.ipi_ifindex = ifr.ifr_ifindex;
920 cmsg_len = sizeof(cmsg);
922 /* create sendpoints */
923 for (i = 0; i < nr_streams; i++) {
924 struct stream *s = &streams[i];
925 pthread_mutex_init(&s->mutex, NULL);
926 calc_stream_params(s);
927 rc = pthread_create(&thread, &attr, sender, (void*) s);
929 fprintf(stderr, "Error while creating sender %d\n",rc);
938 fprintf(stderr, "\r%3ds", seconds);
939 for (ac = 0; ac < AC_NUM; ac++) {
940 int delta = receivers[ac].received - receivers[ac].last_received;
941 receivers[ac].last_received = receivers[ac].received;
942 fprintf(stderr, " %s %5d %4d/s", ac_to_text[ac], receivers[ac].received, delta);
945 if (seconds == opt_count_sec)
949 fprintf(stderr, "\nWaiting for threads to finish\n");
950 /* Wait for all threads to finish */
951 for (i=0; i < nr_streams + AC_NUM; i++) {
952 sem_wait(&sem_thread_finished);
954 struct timespec end_timestamp, measure_length;
955 clock_gettime(CLOCK_REALTIME,&end_timestamp);
956 timespec_sub(&measure_length, &end_timestamp, &reset_timestamp);
958 save_results(argc, argv, timespec2usec(&measure_length));