diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-04-30 08:17:37 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-04-30 08:17:37 +0000 |
commit | 95f9076a2139f5fb042b944a0658b6cda2fa35db (patch) | |
tree | b0826a2a1dcf812e6b4450fe6b05d47cd53ae49d /src/nse/gnunet-nse-profiler.c | |
parent | 7746f68db77b9ca3c4aaca24ab2ce5253461240b (diff) | |
download | gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.tar.gz gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.zip |
implementing new scheduler shutdown semantics
Diffstat (limited to 'src/nse/gnunet-nse-profiler.c')
-rw-r--r-- | src/nse/gnunet-nse-profiler.c | 93 |
1 files changed, 38 insertions, 55 deletions
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c index 5b893ae47..48afd9298 100644 --- a/src/nse/gnunet-nse-profiler.c +++ b/src/nse/gnunet-nse-profiler.c | |||
@@ -177,11 +177,6 @@ static struct GNUNET_TESTBED_Peer **daemons; | |||
177 | static struct GNUNET_CONFIGURATION_Handle *testing_cfg; | 177 | static struct GNUNET_CONFIGURATION_Handle *testing_cfg; |
178 | 178 | ||
179 | /** | 179 | /** |
180 | * The shutdown task | ||
181 | */ | ||
182 | static struct GNUNET_SCHEDULER_Task * shutdown_task_id; | ||
183 | |||
184 | /** | ||
185 | * Maximum number of connections to NSE services. | 180 | * Maximum number of connections to NSE services. |
186 | */ | 181 | */ |
187 | static unsigned int connection_limit; | 182 | static unsigned int connection_limit; |
@@ -228,9 +223,9 @@ static struct OpListEntry *oplist_head; | |||
228 | static struct OpListEntry *oplist_tail; | 223 | static struct OpListEntry *oplist_tail; |
229 | 224 | ||
230 | /** | 225 | /** |
231 | * Are we shutting down | 226 | * Task running each round of the experiment. |
232 | */ | 227 | */ |
233 | static int shutting_down; | 228 | static struct GNUNET_SCHEDULER_Task *round_task; |
234 | 229 | ||
235 | 230 | ||
236 | /** | 231 | /** |
@@ -269,12 +264,13 @@ close_monitor_connections () | |||
269 | static void | 264 | static void |
270 | shutdown_task (void *cls) | 265 | shutdown_task (void *cls) |
271 | { | 266 | { |
272 | shutdown_task_id = NULL; | ||
273 | if (GNUNET_YES == shutting_down) | ||
274 | return; | ||
275 | shutting_down = GNUNET_YES; | ||
276 | LOG_DEBUG ("Ending test.\n"); | 267 | LOG_DEBUG ("Ending test.\n"); |
277 | close_monitor_connections (); | 268 | close_monitor_connections (); |
269 | if (NULL != round_task) | ||
270 | { | ||
271 | GNUNET_SCHEDULER_cancel (round_task); | ||
272 | round_task = NULL; | ||
273 | } | ||
278 | if (NULL != data_file) | 274 | if (NULL != data_file) |
279 | { | 275 | { |
280 | GNUNET_DISK_file_close (data_file); | 276 | GNUNET_DISK_file_close (data_file); |
@@ -286,20 +282,10 @@ shutdown_task (void *cls) | |||
286 | output_file = NULL; | 282 | output_file = NULL; |
287 | } | 283 | } |
288 | if (NULL != testing_cfg) | 284 | if (NULL != testing_cfg) |
285 | { | ||
289 | GNUNET_CONFIGURATION_destroy (testing_cfg); | 286 | GNUNET_CONFIGURATION_destroy (testing_cfg); |
290 | testing_cfg = NULL; | 287 | testing_cfg = NULL; |
291 | } | 288 | } |
292 | |||
293 | |||
294 | /** | ||
295 | * Schedules shutdown task to be run now | ||
296 | */ | ||
297 | static void | ||
298 | shutdown_now () | ||
299 | { | ||
300 | if (NULL != shutdown_task_id) | ||
301 | GNUNET_SCHEDULER_cancel (shutdown_task_id); | ||
302 | shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
303 | } | 289 | } |
304 | 290 | ||
305 | 291 | ||
@@ -556,14 +542,11 @@ next_round (void *cls); | |||
556 | static void | 542 | static void |
557 | finish_round (void *cls) | 543 | finish_round (void *cls) |
558 | { | 544 | { |
559 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 545 | LOG (GNUNET_ERROR_TYPE_INFO, |
560 | 546 | "Have %u connections\n", | |
561 | tc = GNUNET_SCHEDULER_get_task_context (); | 547 | total_connections); |
562 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | ||
563 | return; | ||
564 | LOG (GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections); | ||
565 | close_monitor_connections (); | 548 | close_monitor_connections (); |
566 | GNUNET_SCHEDULER_add_now (&next_round, NULL); | 549 | round_task = GNUNET_SCHEDULER_add_now (&next_round, NULL); |
567 | } | 550 | } |
568 | 551 | ||
569 | 552 | ||
@@ -575,7 +558,8 @@ finish_round (void *cls) | |||
575 | static void | 558 | static void |
576 | run_round () | 559 | run_round () |
577 | { | 560 | { |
578 | LOG_DEBUG ("Running round %u\n", current_round); | 561 | LOG_DEBUG ("Running round %u\n", |
562 | current_round); | ||
579 | connect_nse_service (); | 563 | connect_nse_service (); |
580 | GNUNET_SCHEDULER_add_delayed (wait_time, | 564 | GNUNET_SCHEDULER_add_delayed (wait_time, |
581 | &finish_round, | 565 | &finish_round, |
@@ -592,7 +576,9 @@ make_oplist_entry () | |||
592 | struct OpListEntry *entry; | 576 | struct OpListEntry *entry; |
593 | 577 | ||
594 | entry = GNUNET_new (struct OpListEntry); | 578 | entry = GNUNET_new (struct OpListEntry); |
595 | GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); | 579 | GNUNET_CONTAINER_DLL_insert_tail (oplist_head, |
580 | oplist_tail, | ||
581 | entry); | ||
596 | return entry; | 582 | return entry; |
597 | } | 583 | } |
598 | 584 | ||
@@ -605,7 +591,8 @@ make_oplist_entry () | |||
605 | * @param emsg NULL on success; otherwise an error description | 591 | * @param emsg NULL on success; otherwise an error description |
606 | */ | 592 | */ |
607 | static void | 593 | static void |
608 | manage_service_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | 594 | manage_service_cb (void *cls, |
595 | struct GNUNET_TESTBED_Operation *op, | ||
609 | const char *emsg) | 596 | const char *emsg) |
610 | { | 597 | { |
611 | struct OpListEntry *entry = cls; | 598 | struct OpListEntry *entry = cls; |
@@ -619,7 +606,9 @@ manage_service_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
619 | } | 606 | } |
620 | GNUNET_assert (0 != entry->delta); | 607 | GNUNET_assert (0 != entry->delta); |
621 | peers_running += entry->delta; | 608 | peers_running += entry->delta; |
622 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | 609 | GNUNET_CONTAINER_DLL_remove (oplist_head, |
610 | oplist_tail, | ||
611 | entry); | ||
623 | GNUNET_free (entry); | 612 | GNUNET_free (entry); |
624 | if (num_peers_in_round[current_round] == peers_running) | 613 | if (num_peers_in_round[current_round] == peers_running) |
625 | run_round (); | 614 | run_round (); |
@@ -672,26 +661,22 @@ adjust_running_peers () | |||
672 | static void | 661 | static void |
673 | next_round (void *cls) | 662 | next_round (void *cls) |
674 | { | 663 | { |
675 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 664 | round_task = NULL; |
676 | |||
677 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
678 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | ||
679 | return; | ||
680 | LOG_DEBUG ("Disconnecting nse service of peers\n"); | 665 | LOG_DEBUG ("Disconnecting nse service of peers\n"); |
681 | current_round++; | 666 | current_round++; |
682 | if (current_round == num_rounds) | 667 | if (current_round == num_rounds) |
683 | { | 668 | { |
684 | /* this was the last round, terminate */ | 669 | /* this was the last round, terminate */ |
685 | ok = 0; | 670 | ok = 0; |
686 | GNUNET_SCHEDULER_shutdown (); | 671 | GNUNET_SCHEDULER_shutdown (); |
687 | return; | 672 | return; |
688 | } | 673 | } |
689 | if (num_peers_in_round[current_round] == peers_running) | 674 | if (num_peers_in_round[current_round] == peers_running) |
690 | { | 675 | { |
691 | /* no need to churn, just run next round */ | 676 | /* no need to churn, just run next round */ |
692 | run_round (); | 677 | run_round (); |
693 | return; | 678 | return; |
694 | } | 679 | } |
695 | adjust_running_peers (); | 680 | adjust_running_peers (); |
696 | } | 681 | } |
697 | 682 | ||
@@ -744,7 +729,7 @@ test_master (void *cls, | |||
744 | { | 729 | { |
745 | if (NULL == peers) | 730 | if (NULL == peers) |
746 | { | 731 | { |
747 | shutdown_now (); | 732 | GNUNET_SCHEDULER_shutdown (); |
748 | return; | 733 | return; |
749 | } | 734 | } |
750 | daemons = peers; | 735 | daemons = peers; |
@@ -838,9 +823,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
838 | NULL, /* master_controller_cb cls */ | 823 | NULL, /* master_controller_cb cls */ |
839 | &test_master, | 824 | &test_master, |
840 | NULL); /* test_master cls */ | 825 | NULL); /* test_master cls */ |
841 | shutdown_task_id = | 826 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
842 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
843 | &shutdown_task, NULL); | ||
844 | } | 827 | } |
845 | 828 | ||
846 | 829 | ||