aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-cadet-profiler.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
committerChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
commit95f9076a2139f5fb042b944a0658b6cda2fa35db (patch)
treeb0826a2a1dcf812e6b4450fe6b05d47cd53ae49d /src/cadet/gnunet-cadet-profiler.c
parent7746f68db77b9ca3c4aaca24ab2ce5253461240b (diff)
downloadgnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.tar.gz
gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.zip
implementing new scheduler shutdown semantics
Diffstat (limited to 'src/cadet/gnunet-cadet-profiler.c')
-rw-r--r--src/cadet/gnunet-cadet-profiler.c224
1 files changed, 128 insertions, 96 deletions
diff --git a/src/cadet/gnunet-cadet-profiler.c b/src/cadet/gnunet-cadet-profiler.c
index ffa993f8e..b2a07cb0c 100644
--- a/src/cadet/gnunet-cadet-profiler.c
+++ b/src/cadet/gnunet-cadet-profiler.c
@@ -147,7 +147,12 @@ struct CadetPeer
147 /** 147 /**
148 * Task to do the next ping. 148 * Task to do the next ping.
149 */ 149 */
150 struct GNUNET_SCHEDULER_Task * ping_task; 150 struct GNUNET_SCHEDULER_Task *ping_task;
151
152 /**
153 * NTR operation for the next ping.
154 */
155 struct GNUNET_CADET_TransmitHandle *ping_ntr;
151 156
152 float mean[number_rounds]; 157 float mean[number_rounds];
153 float var[number_rounds]; 158 float var[number_rounds];
@@ -179,7 +184,7 @@ static struct GNUNET_TESTBED_Operation *stats_op;
179/** 184/**
180 * Operation to get peer ids. 185 * Operation to get peer ids.
181 */ 186 */
182struct CadetPeer *peers; 187static struct CadetPeer *peers;
183 188
184/** 189/**
185 * Peer ids counter. 190 * Peer ids counter.
@@ -207,19 +212,14 @@ static unsigned long long peers_pinging;
207static struct GNUNET_CADET_TEST_Context *test_ctx; 212static struct GNUNET_CADET_TEST_Context *test_ctx;
208 213
209/** 214/**
210 * Task called to shutdown test.
211 */
212static struct GNUNET_SCHEDULER_Task * shutdown_handle;
213
214/**
215 * Task called to disconnect peers, before shutdown. 215 * Task called to disconnect peers, before shutdown.
216 */ 216 */
217static struct GNUNET_SCHEDULER_Task * disconnect_task; 217static struct GNUNET_SCHEDULER_Task *disconnect_task;
218 218
219/** 219/**
220 * Task to perform tests 220 * Task to perform tests
221 */ 221 */
222static struct GNUNET_SCHEDULER_Task * test_task; 222static struct GNUNET_SCHEDULER_Task *test_task;
223 223
224/** 224/**
225 * Round number. 225 * Round number.
@@ -241,6 +241,11 @@ static unsigned int peers_warmup;
241 */ 241 */
242static int test_finished; 242static int test_finished;
243 243
244/**
245 * Task running each round of the benchmark.
246 */
247static struct GNUNET_SCHEDULER_Task *round_task;
248
244 249
245/** 250/**
246 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES. 251 * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
@@ -310,19 +315,6 @@ show_end_data (void)
310 315
311 316
312/** 317/**
313 * Shut down peergroup, clean up.
314 *
315 * @param cls Closure (unused).
316 */
317static void
318shutdown_task (void *cls)
319{
320 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Ending test.\n");
321 shutdown_handle = NULL;
322}
323
324
325/**
326 * Disconnect from cadet services af all peers, call shutdown. 318 * Disconnect from cadet services af all peers, call shutdown.
327 * 319 *
328 * @param cls Closure (unused). 320 * @param cls Closure (unused).
@@ -334,7 +326,8 @@ disconnect_cadet_peers (void *cls)
334 unsigned int i; 326 unsigned int i;
335 327
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
337 "disconnecting cadet service, called from line %ld\n", line); 329 "disconnecting cadet service, called from line %ld\n",
330 line);
338 disconnect_task = NULL; 331 disconnect_task = NULL;
339 for (i = 0; i < peers_total; i++) 332 for (i = 0; i < peers_total; i++)
340 { 333 {
@@ -346,28 +339,56 @@ disconnect_cadet_peers (void *cls)
346 339
347 if (NULL != peers[i].ch) 340 if (NULL != peers[i].ch)
348 { 341 {
349 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: channel %p\n", i, peers[i].ch); 342 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
343 "%u: channel %p\n", i, peers[i].ch);
350 GNUNET_CADET_channel_destroy (peers[i].ch); 344 GNUNET_CADET_channel_destroy (peers[i].ch);
351 } 345 }
352 if (NULL != peers[i].warmup_ch) 346 if (NULL != peers[i].warmup_ch)
353 { 347 {
354 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: warmup channel %p\n", 348 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
349 "%u: warmup channel %p\n",
355 i, peers[i].warmup_ch); 350 i, peers[i].warmup_ch);
356 GNUNET_CADET_channel_destroy (peers[i].warmup_ch); 351 GNUNET_CADET_channel_destroy (peers[i].warmup_ch);
357 } 352 }
358 if (NULL != peers[i].incoming_ch) 353 if (NULL != peers[i].incoming_ch)
359 { 354 {
360 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: incoming channel %p\n", 355 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
356 "%u: incoming channel %p\n",
361 i, peers[i].incoming_ch); 357 i, peers[i].incoming_ch);
362 GNUNET_CADET_channel_destroy (peers[i].incoming_ch); 358 GNUNET_CADET_channel_destroy (peers[i].incoming_ch);
363 } 359 }
364 } 360 }
365 GNUNET_CADET_TEST_cleanup (test_ctx); 361 GNUNET_CADET_TEST_cleanup (test_ctx);
366 if (NULL != shutdown_handle) 362 GNUNET_SCHEDULER_shutdown ();
363}
364
365
366/**
367 * Shut down peergroup, clean up.
368 *
369 * @param cls Closure (unused).
370 */
371static void
372shutdown_task (void *cls)
373{
374 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
375 "Ending test.\n");
376 if (NULL != disconnect_task)
367 { 377 {
368 GNUNET_SCHEDULER_cancel (shutdown_handle); 378 GNUNET_SCHEDULER_cancel (disconnect_task);
379 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
380 (void *) __LINE__);
381 }
382 if (NULL != round_task)
383 {
384 GNUNET_SCHEDULER_cancel (round_task);
385 round_task = NULL;
386 }
387 if (NULL != test_task)
388 {
389 GNUNET_SCHEDULER_cancel (test_task);
390 test_task = NULL;
369 } 391 }
370 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
371} 392}
372 393
373 394
@@ -418,13 +439,16 @@ stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
418 * @param subsystem name of subsystem that created the statistic 439 * @param subsystem name of subsystem that created the statistic
419 * @param name the name of the datum 440 * @param name the name of the datum
420 * @param value the current value 441 * @param value the current value
421 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not 442 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
422 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 443 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
423 */ 444 */
424static int 445static int
425stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer, 446stats_iterator (void *cls,
426 const char *subsystem, const char *name, 447 const struct GNUNET_TESTBED_Peer *peer,
427 uint64_t value, int is_persistent) 448 const char *subsystem,
449 const char *name,
450 uint64_t value,
451 int is_persistent)
428{ 452{
429 uint32_t i; 453 uint32_t i;
430 454
@@ -444,16 +468,13 @@ stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
444static void 468static void
445collect_stats (void *cls) 469collect_stats (void *cls)
446{ 470{
447 const struct GNUNET_SCHEDULER_TaskContext *tc; 471 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
448 472 "Start collecting statistics...\n");
449 tc = GNUNET_SCHEDULER_get_task_context (); 473 stats_op = GNUNET_TESTBED_get_statistics (peers_total,
450 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0) 474 testbed_handles,
451 return;
452
453 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
454 stats_op = GNUNET_TESTBED_get_statistics (peers_total, testbed_handles,
455 NULL, NULL, 475 NULL, NULL,
456 stats_iterator, stats_cont, NULL); 476 &stats_iterator,
477 &stats_cont, NULL);
457} 478}
458 479
459 480
@@ -465,17 +486,12 @@ collect_stats (void *cls)
465static void 486static void
466finish_profiler (void *cls) 487finish_profiler (void *cls)
467{ 488{
468 const struct GNUNET_SCHEDULER_TaskContext *tc;
469
470 tc = GNUNET_SCHEDULER_get_task_context ();
471 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
472 return;
473
474 test_finished = GNUNET_YES; 489 test_finished = GNUNET_YES;
475 show_end_data(); 490 show_end_data ();
476 GNUNET_SCHEDULER_add_now (&collect_stats, NULL); 491 GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
477} 492}
478 493
494
479/** 495/**
480 * Set the total number of running peers. 496 * Set the total number of running peers.
481 * 497 *
@@ -515,9 +531,15 @@ adjust_running_peers (unsigned int target)
515 run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id)); 531 run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
516 532
517 if (NULL != peers[r].ping_task) 533 if (NULL != peers[r].ping_task)
534 {
518 GNUNET_SCHEDULER_cancel (peers[r].ping_task); 535 GNUNET_SCHEDULER_cancel (peers[r].ping_task);
519 peers[r].ping_task = NULL; 536 peers[r].ping_task = NULL;
520 537 }
538 if (NULL != peers[r].ping_ntr)
539 {
540 GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr);
541 peers[r].ping_ntr = NULL;
542 }
521 peers[r].up = run; 543 peers[r].up = run;
522 544
523 if (NULL != peers[r].ch) 545 if (NULL != peers[r].ch)
@@ -547,12 +569,6 @@ adjust_running_peers (unsigned int target)
547static void 569static void
548next_rnd (void *cls) 570next_rnd (void *cls)
549{ 571{
550 const struct GNUNET_SCHEDULER_TaskContext *tc;
551
552 tc = GNUNET_SCHEDULER_get_task_context ();
553 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
554 return;
555
556 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ROUND %ld\n", current_round); 572 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ROUND %ld\n", current_round);
557 if (0.0 == rounds[current_round]) 573 if (0.0 == rounds[current_round])
558 { 574 {
@@ -563,7 +579,9 @@ next_rnd (void *cls)
563 adjust_running_peers (rounds[current_round] * peers_total); 579 adjust_running_peers (rounds[current_round] * peers_total);
564 current_round++; 580 current_round++;
565 581
566 GNUNET_SCHEDULER_add_delayed (round_time, &next_rnd, NULL); 582 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
583 &next_rnd,
584 NULL);
567} 585}
568 586
569 587
@@ -616,21 +634,19 @@ static void
616ping (void *cls) 634ping (void *cls)
617{ 635{
618 struct CadetPeer *peer = cls; 636 struct CadetPeer *peer = cls;
619 const struct GNUNET_SCHEDULER_TaskContext *tc;
620 637
621 peer->ping_task = NULL; 638 peer->ping_task = NULL;
622 tc = GNUNET_SCHEDULER_get_task_context (); 639 if (GNUNET_YES == test_finished)
623 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)
624 || GNUNET_YES == test_finished)
625 return; 640 return;
626 641 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
627 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u -> %u (%u)\n", 642 "%u -> %u (%u)\n",
628 get_index (peer), get_index (peer->dest), peer->data_sent); 643 get_index (peer),
629 644 get_index (peer->dest),
630 GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO, 645 peer->data_sent);
631 GNUNET_TIME_UNIT_FOREVER_REL, 646 peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
632 sizeof (struct CadetPingMessage), 647 GNUNET_TIME_UNIT_FOREVER_REL,
633 &tmt_rdy_ping, peer); 648 sizeof (struct CadetPingMessage),
649 &tmt_rdy_ping, peer);
634} 650}
635 651
636/** 652/**
@@ -640,12 +656,13 @@ ping (void *cls)
640 * @param tc Task context. 656 * @param tc Task context.
641 */ 657 */
642static void 658static void
643pong (struct GNUNET_CADET_Channel *channel, const struct CadetPingMessage *ping) 659pong (struct GNUNET_CADET_Channel *channel,
660 const struct CadetPingMessage *ping)
644{ 661{
645 struct CadetPingMessage *copy; 662 struct CadetPingMessage *copy;
646 663
647 copy = GNUNET_new (struct CadetPingMessage); 664 copy = GNUNET_new (struct CadetPingMessage);
648 memcpy (copy, ping, sizeof (*ping)); 665 *copy = *ping;
649 GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO, 666 GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
650 GNUNET_TIME_UNIT_FOREVER_REL, 667 GNUNET_TIME_UNIT_FOREVER_REL,
651 sizeof (struct CadetPingMessage), 668 sizeof (struct CadetPingMessage),
@@ -666,7 +683,9 @@ tmt_rdy_ping (void *cls, size_t size, void *buf)
666 struct CadetPeer *peer = (struct CadetPeer *) cls; 683 struct CadetPeer *peer = (struct CadetPeer *) cls;
667 struct CadetPingMessage *msg = buf; 684 struct CadetPingMessage *msg = buf;
668 685
669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n"); 686 peer->ping_ntr = NULL;
687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
688 "tmt_rdy called, filling buffer\n");
670 if (size < sizeof (struct CadetPingMessage) || NULL == buf) 689 if (size < sizeof (struct CadetPingMessage) || NULL == buf)
671 { 690 {
672 GNUNET_break (GNUNET_YES == test_finished); 691 GNUNET_break (GNUNET_YES == test_finished);
@@ -827,7 +846,8 @@ incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
827 * with the channel is stored 846 * with the channel is stored
828 */ 847 */
829static void 848static void
830channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel, 849channel_cleaner (void *cls,
850 const struct GNUNET_CADET_Channel *channel,
831 void *channel_ctx) 851 void *channel_ctx)
832{ 852{
833 long n = (long) cls; 853 long n = (long) cls;
@@ -874,13 +894,8 @@ start_test (void *cls)
874{ 894{
875 enum GNUNET_CADET_ChannelOption flags; 895 enum GNUNET_CADET_ChannelOption flags;
876 unsigned long i; 896 unsigned long i;
877 const struct GNUNET_SCHEDULER_TaskContext *tc;
878 897
879 test_task = NULL; 898 test_task = NULL;
880 tc = GNUNET_SCHEDULER_get_task_context ();
881 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
882 return;
883
884 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n"); 899 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
885 900
886 flags = GNUNET_CADET_OPTION_DEFAULT; 901 flags = GNUNET_CADET_OPTION_DEFAULT;
@@ -909,7 +924,9 @@ start_test (void *cls)
909 number_rounds + 1), 924 number_rounds + 1),
910 &disconnect_cadet_peers, 925 &disconnect_cadet_peers,
911 (void *) __LINE__); 926 (void *) __LINE__);
912 GNUNET_SCHEDULER_add_delayed (round_time, &next_rnd, NULL); 927 round_task = GNUNET_SCHEDULER_add_delayed (round_time,
928 &next_rnd,
929 NULL);
913} 930}
914 931
915 932
@@ -939,6 +956,7 @@ warmup (void)
939 } 956 }
940} 957}
941 958
959
942/** 960/**
943 * Callback to be called when the requested peer information is available 961 * Callback to be called when the requested peer information is available
944 * 962 *
@@ -950,9 +968,9 @@ warmup (void)
950 */ 968 */
951static void 969static void
952peer_id_cb (void *cls, 970peer_id_cb (void *cls,
953 struct GNUNET_TESTBED_Operation *op, 971 struct GNUNET_TESTBED_Operation *op,
954 const struct GNUNET_TESTBED_PeerInformation *pinfo, 972 const struct GNUNET_TESTBED_PeerInformation *pinfo,
955 const char *emsg) 973 const char *emsg)
956{ 974{
957 long n = (long) cls; 975 long n = (long) cls;
958 976
@@ -991,6 +1009,7 @@ peer_id_cb (void *cls,
991 &start_test, NULL); 1009 &start_test, NULL);
992} 1010}
993 1011
1012
994/** 1013/**
995 * test main: start test when all peers are connected 1014 * test main: start test when all peers are connected
996 * 1015 *
@@ -1009,7 +1028,8 @@ tmain (void *cls,
1009{ 1028{
1010 unsigned long i; 1029 unsigned long i;
1011 1030
1012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n"); 1031 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1032 "test main\n");
1013 test_ctx = ctx; 1033 test_ctx = ctx;
1014 GNUNET_assert (peers_total == num_peers); 1034 GNUNET_assert (peers_total == num_peers);
1015 peers_running = num_peers; 1035 peers_running = num_peers;
@@ -1017,11 +1037,12 @@ tmain (void *cls,
1017 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, 1037 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
1018 &disconnect_cadet_peers, 1038 &disconnect_cadet_peers,
1019 (void *) __LINE__); 1039 (void *) __LINE__);
1020 shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1040 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1021 &shutdown_task, NULL);
1022 for (i = 0; i < peers_total; i++) 1041 for (i = 0; i < peers_total; i++)
1023 { 1042 {
1024 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requesting id %ld\n", i); 1043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1044 "requesting id %ld\n",
1045 i);
1025 peers[i].up = GNUNET_YES; 1046 peers[i].up = GNUNET_YES;
1026 peers[i].cadet = cadetes[i]; 1047 peers[i].cadet = cadetes[i];
1027 peers[i].op = 1048 peers[i].op =
@@ -1047,25 +1068,35 @@ main (int argc, char *argv[])
1047 1068
1048 if (4 > argc) 1069 if (4 > argc)
1049 { 1070 {
1050 fprintf (stderr, "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n", argv[0]); 1071 fprintf (stderr,
1051 fprintf (stderr, "example: %s 30s 16 1 Y\n", argv[0]); 1072 "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
1073 argv[0]);
1074 fprintf (stderr,
1075 "example: %s 30s 16 1 Y\n",
1076 argv[0]);
1052 return 1; 1077 return 1;
1053 } 1078 }
1054 1079
1055 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[1], &round_time)) 1080 if (GNUNET_OK !=
1081 GNUNET_STRINGS_fancy_time_to_relative (argv[1],
1082 &round_time))
1056 { 1083 {
1057 fprintf (stderr, "%s is not a valid time\n", argv[1]); 1084 fprintf (stderr,
1085 "%s is not a valid time\n",
1086 argv[1]);
1058 return 1; 1087 return 1;
1059 } 1088 }
1060 1089
1061 peers_total = atoll (argv[2]); 1090 peers_total = atoll (argv[2]);
1062 if (2 > peers_total) 1091 if (2 > peers_total)
1063 { 1092 {
1064 fprintf (stderr, "%s peers is not valid (> 2)\n", argv[1]); 1093 fprintf (stderr,
1094 "%s peers is not valid (> 2)\n",
1095 argv[1]);
1065 return 1; 1096 return 1;
1066 } 1097 }
1067 peers = GNUNET_malloc (sizeof (struct CadetPeer) * peers_total); 1098 peers = GNUNET_new_array (peers_total,
1068 1099 struct CadetPeer);
1069 peers_pinging = atoll (argv[3]); 1100 peers_pinging = atoll (argv[3]);
1070 1101
1071 if (peers_total < 2 * peers_pinging) 1102 if (peers_total < 2 * peers_pinging)
@@ -1077,7 +1108,8 @@ main (int argc, char *argv[])
1077 1108
1078 do_warmup = (5 > argc || argv[4][0] != 'N'); 1109 do_warmup = (5 > argc || argv[4][0] != 'N');
1079 1110
1080 ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total, GNUNET_YES); 1111 ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total,
1112 GNUNET_YES);
1081 GNUNET_assert (NULL != ids); 1113 GNUNET_assert (NULL != ids);
1082 p_ids = 0; 1114 p_ids = 0;
1083 test_finished = GNUNET_NO; 1115 test_finished = GNUNET_NO;