aboutsummaryrefslogtreecommitdiff
path: root/src/util/scheduler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/scheduler.c')
-rw-r--r--src/util/scheduler.c110
1 files changed, 47 insertions, 63 deletions
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index b7860650e..d40853963 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -34,6 +34,10 @@
34#include "execinfo.h" 34#include "execinfo.h"
35 35
36 36
37#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
38
39#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall)
40
37/** 41/**
38 * Use lsof to generate file descriptor reports on select error? 42 * Use lsof to generate file descriptor reports on select error?
39 * (turn off for stable releases). 43 * (turn off for stable releases).
@@ -523,10 +527,9 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs,
523 while (pos != NULL) 527 while (pos != NULL)
524 { 528 {
525#if DEBUG_TASKS 529#if DEBUG_TASKS
526 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 530 LOG (GNUNET_ERROR_TYPE_DEBUG,
527 "util", 531 "Checking readiness of task: %llu / %p\n", pos->id,
528 "Checking readiness of task: %llu / %p\n", pos->id, 532 pos->callback_cls);
529 pos->callback_cls);
530#endif 533#endif
531 next = pos->next; 534 next = pos->next;
532 if (GNUNET_YES == is_ready (pos, now, rs, ws)) 535 if (GNUNET_YES == is_ready (pos, now, rs, ws))
@@ -656,12 +659,10 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws)
656 if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value > 659 if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value >
657 DELAY_THRESHOLD.rel_value) 660 DELAY_THRESHOLD.rel_value)
658 { 661 {
659 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 662 LOG (GNUNET_ERROR_TYPE_ERROR,
660 "util", 663 "Task %llu took %llums to be scheduled\n", pos->id,
661 "Task %llu took %llums to be scheduled\n", pos->id, 664 (unsigned long long)
662 (unsigned long long) 665 GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value);
663 GNUNET_TIME_absolute_get_duration
664 (pos->start_time).rel_value);
665 } 666 }
666#endif 667#endif
667 tc.reason = pos->reason; 668 tc.reason = pos->reason;
@@ -678,20 +679,17 @@ run_ready (struct GNUNET_NETWORK_FDSet *rs, struct GNUNET_NETWORK_FDSet *ws)
678 (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd))) 679 (!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd)))
679 abort (); // added to ready in previous select loop! 680 abort (); // added to ready in previous select loop!
680#if DEBUG_TASKS 681#if DEBUG_TASKS
681 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 682 LOG (GNUNET_ERROR_TYPE_DEBUG,
682 "util", 683 "Running task: %llu / %p\n", pos->id, pos->callback_cls);
683 "Running task: %llu / %p\n", pos->id,
684 pos->callback_cls);
685#endif 684#endif
686 pos->callback (pos->callback_cls, &tc); 685 pos->callback (pos->callback_cls, &tc);
687#if EXECINFO 686#if EXECINFO
688 int i; 687 int i;
689 688
690 for (i = 0; i < pos->num_backtrace_strings; i++) 689 for (i = 0; i < pos->num_backtrace_strings; i++)
691 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 690 LOG (GNUNET_ERROR_TYPE_ERROR,
692 "util", 691 "Task %llu trace %d: %s\n", pos->id,
693 "Task %llu trace %d: %s\n", pos->id, 692 i, pos->backtrace_strings[i]);
694 i, pos->backtrace_strings[i]);
695#endif 693#endif
696 active_task = NULL; 694 active_task = NULL;
697 destroy_task (pos); 695 destroy_task (pos);
@@ -844,8 +842,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
844 if (errno == EINTR) 842 if (errno == EINTR)
845 continue; 843 continue;
846 844
847 GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_ERROR, "util", 845 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "select");
848 "select");
849#ifndef MINGW 846#ifndef MINGW
850#if USE_LSOF 847#if USE_LSOF
851 char lsof[512]; 848 char lsof[512];
@@ -854,8 +851,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
854 (void) close (1); 851 (void) close (1);
855 (void) dup2 (2, 1); 852 (void) dup2 (2, 1);
856 if (0 != system (lsof)) 853 if (0 != system (lsof))
857 GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "util", 854 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "system");
858 "system");
859#endif 855#endif
860#endif 856#endif
861 abort (); 857 abort ();
@@ -863,8 +859,8 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls)
863 } 859 }
864 if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16)) 860 if ((ret == 0) && (timeout.rel_value == 0) && (busy_wait_warning > 16))
865 { 861 {
866 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 862 LOG (GNUNET_ERROR_TYPE_WARNING,
867 "util", _("Looks like we're busy waiting...\n")); 863 _("Looks like we're busy waiting...\n"));
868 sleep (1); /* mitigate */ 864 sleep (1); /* mitigate */
869 } 865 }
870 check_ready (rs, ws); 866 check_ready (rs, ws);
@@ -994,10 +990,9 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task)
994 p++; 990 p++;
995 if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT) 991 if (p >= GNUNET_SCHEDULER_PRIORITY_COUNT)
996 { 992 {
997 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 993 LOG (GNUNET_ERROR_TYPE_ERROR,
998 "util", 994 _("Attempt to cancel dead task %llu!\n"),
999 _("Attempt to cancel dead task %llu!\n"), 995 (unsigned long long) task);
1000 (unsigned long long) task);
1001 GNUNET_assert (0); 996 GNUNET_assert (0);
1002 } 997 }
1003 prev = NULL; 998 prev = NULL;
@@ -1037,9 +1032,8 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task)
1037 } 1032 }
1038 ret = t->callback_cls; 1033 ret = t->callback_cls;
1039#if DEBUG_TASKS 1034#if DEBUG_TASKS
1040 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1035 LOG (GNUNET_ERROR_TYPE_DEBUG,
1041 "util", 1036 "Canceling task: %llu / %p\n", task, t->callback_cls);
1042 "Canceling task: %llu / %p\n", task, t->callback_cls);
1043#endif 1037#endif
1044 destroy_task (t); 1038 destroy_task (t);
1045 return ret; 1039 return ret;
@@ -1086,10 +1080,8 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1086 t->priority = current_priority; 1080 t->priority = current_priority;
1087 t->lifeness = current_lifeness; 1081 t->lifeness = current_lifeness;
1088#if DEBUG_TASKS 1082#if DEBUG_TASKS
1089 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1083 LOG (GNUNET_ERROR_TYPE_DEBUG,
1090 "util", 1084 "Adding continuation task: %llu / %p\n", t->id, t->callback_cls);
1091 "Adding continuation task: %llu / %p\n",
1092 t->id, t->callback_cls);
1093#endif 1085#endif
1094 queue_ready_task (t); 1086 queue_ready_task (t);
1095} 1087}
@@ -1220,18 +1212,15 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1220 pending_timeout_last = t; 1212 pending_timeout_last = t;
1221 1213
1222#if DEBUG_TASKS 1214#if DEBUG_TASKS
1223 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1215 LOG (GNUNET_ERROR_TYPE_DEBUG,
1224 "util", 1216 "Adding task: %llu / %p\n", t->id, t->callback_cls);
1225 "Adding task: %llu / %p\n", t->id, t->callback_cls);
1226#endif 1217#endif
1227#if EXECINFO 1218#if EXECINFO
1228 int i; 1219 int i;
1229 1220
1230 for (i = 0; i < t->num_backtrace_strings; i++) 1221 for (i = 0; i < t->num_backtrace_strings; i++)
1231 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1222 LOG (GNUNET_ERROR_TYPE_DEBUG,
1232 "util", 1223 "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]);
1233 "Task %llu trace %d: %s\n", t->id, i,
1234 t->backtrace_strings[i]);
1235#endif 1224#endif
1236 return t->id; 1225 return t->id;
1237 1226
@@ -1352,14 +1341,14 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
1352 1341
1353 if ((flags == -1) && (errno == EBADF)) 1342 if ((flags == -1) && (errno == EBADF))
1354 { 1343 {
1355 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1344 LOG (GNUNET_ERROR_TYPE_ERROR,
1356 "util", "Got invalid file descriptor %d!\n", rfd); 1345 "Got invalid file descriptor %d!\n", rfd);
1357#if EXECINFO 1346#if EXECINFO
1358 int i; 1347 int i;
1359 1348
1360 for (i = 0; i < t->num_backtrace_strings; i++) 1349 for (i = 0; i < t->num_backtrace_strings; i++)
1361 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1350 LOG (GNUNET_ERROR_TYPE_DEBUG,
1362 "util", "Trace: %s\n", t->backtrace_strings[i]); 1351 "Trace: %s\n", t->backtrace_strings[i]);
1363#endif 1352#endif
1364 GNUNET_assert (0); 1353 GNUNET_assert (0);
1365 } 1354 }
@@ -1370,14 +1359,14 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
1370 1359
1371 if (flags == -1 && errno == EBADF) 1360 if (flags == -1 && errno == EBADF)
1372 { 1361 {
1373 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1362 LOG (GNUNET_ERROR_TYPE_ERROR,
1374 "util", "Got invalid file descriptor %d!\n", wfd); 1363 "Got invalid file descriptor %d!\n", wfd);
1375#if EXECINFO 1364#if EXECINFO
1376 int i; 1365 int i;
1377 1366
1378 for (i = 0; i < t->num_backtrace_strings; i++) 1367 for (i = 0; i < t->num_backtrace_strings; i++)
1379 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1368 LOG (GNUNET_ERROR_TYPE_DEBUG,
1380 "util", "Trace: %s\n", t->backtrace_strings[i]); 1369 "Trace: %s\n", t->backtrace_strings[i]);
1381#endif 1370#endif
1382 GNUNET_assert (0); 1371 GNUNET_assert (0);
1383 } 1372 }
@@ -1398,17 +1387,15 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
1398 pending = t; 1387 pending = t;
1399 max_priority_added = GNUNET_MAX (max_priority_added, t->priority); 1388 max_priority_added = GNUNET_MAX (max_priority_added, t->priority);
1400#if DEBUG_TASKS 1389#if DEBUG_TASKS
1401 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1390 LOG (GNUNET_ERROR_TYPE_DEBUG,
1402 "util", 1391 "Adding task: %llu / %p\n", t->id, t->callback_cls);
1403 "Adding task: %llu / %p\n", t->id, t->callback_cls);
1404#endif 1392#endif
1405#if EXECINFO 1393#if EXECINFO
1406 int i; 1394 int i;
1407 1395
1408 for (i = 0; i < t->num_backtrace_strings; i++) 1396 for (i = 0; i < t->num_backtrace_strings; i++)
1409 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "util", 1397 LOG (GNUNET_ERROR_TYPE_DEBUG,
1410 "Task %llu trace %d: %s\n", t->id, i, 1398 "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]);
1411 t->backtrace_strings[i]);
1412#endif 1399#endif
1413 return t->id; 1400 return t->id;
1414} 1401}
@@ -1673,18 +1660,15 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio,
1673 pending = t; 1660 pending = t;
1674 max_priority_added = GNUNET_MAX (max_priority_added, t->priority); 1661 max_priority_added = GNUNET_MAX (max_priority_added, t->priority);
1675#if DEBUG_TASKS 1662#if DEBUG_TASKS
1676 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1663 LOG (GNUNET_ERROR_TYPE_DEBUG,
1677 "util", 1664 "Adding task: %llu / %p\n", t->id, t->callback_cls);
1678 "Adding task: %llu / %p\n", t->id, t->callback_cls);
1679#endif 1665#endif
1680#if EXECINFO 1666#if EXECINFO
1681 int i; 1667 int i;
1682 1668
1683 for (i = 0; i < t->num_backtrace_strings; i++) 1669 for (i = 0; i < t->num_backtrace_strings; i++)
1684 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1670 LOG (GNUNET_ERROR_TYPE_DEBUG,
1685 "util", 1671 "Task %llu trace %d: %s\n", t->id, i, t->backtrace_strings[i]);
1686 "Task %llu trace %d: %s\n", t->id, i,
1687 t->backtrace_strings[i]);
1688#endif 1672#endif
1689 return t->id; 1673 return t->id;
1690} 1674}