diff options
-rw-r--r-- | src/util/Makefile.am | 12 | ||||
-rw-r--r-- | src/util/program.c | 7 | ||||
-rw-r--r-- | src/util/service.c | 10 | ||||
-rw-r--r-- | src/util/speedup.c | 94 | ||||
-rw-r--r-- | src/util/test_speedup.c | 101 | ||||
-rw-r--r-- | src/util/test_speedup_data.conf | 3 | ||||
-rw-r--r-- | src/util/util.conf | 2 |
7 files changed, 226 insertions, 3 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 9e670d950..ad918baef 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -99,7 +99,8 @@ libgnunetutil_la_SOURCES = \ | |||
99 | service.c \ | 99 | service.c \ |
100 | signal.c \ | 100 | signal.c \ |
101 | strings.c \ | 101 | strings.c \ |
102 | time.c | 102 | time.c \ |
103 | speedup.c | ||
103 | 104 | ||
104 | 105 | ||
105 | libgnunetutil_la_LIBADD = \ | 106 | libgnunetutil_la_LIBADD = \ |
@@ -203,6 +204,7 @@ check_PROGRAMS = \ | |||
203 | test_service \ | 204 | test_service \ |
204 | test_strings \ | 205 | test_strings \ |
205 | test_time \ | 206 | test_time \ |
207 | test_speedup \ | ||
206 | $(BENCHMARKS) \ | 208 | $(BENCHMARKS) \ |
207 | test_os_start_process \ | 209 | test_os_start_process \ |
208 | test_common_logging_runtime_loglevels | 210 | test_common_logging_runtime_loglevels |
@@ -444,6 +446,11 @@ test_time_SOURCES = \ | |||
444 | test_time_LDADD = \ | 446 | test_time_LDADD = \ |
445 | $(top_builddir)/src/util/libgnunetutil.la | 447 | $(top_builddir)/src/util/libgnunetutil.la |
446 | 448 | ||
449 | test_speedup_SOURCES = \ | ||
450 | test_speedup.c | ||
451 | test_speedup_LDADD = \ | ||
452 | $(top_builddir)/src/util/libgnunetutil.la | ||
453 | |||
447 | perf_crypto_hash_SOURCES = \ | 454 | perf_crypto_hash_SOURCES = \ |
448 | perf_crypto_hash.c | 455 | perf_crypto_hash.c |
449 | perf_crypto_hash_LDADD = \ | 456 | perf_crypto_hash_LDADD = \ |
@@ -455,4 +462,5 @@ EXTRA_DIST = \ | |||
455 | test_program_data.conf \ | 462 | test_program_data.conf \ |
456 | test_pseudonym_data.conf \ | 463 | test_pseudonym_data.conf \ |
457 | test_resolver_api_data.conf \ | 464 | test_resolver_api_data.conf \ |
458 | test_service_data.conf | 465 | test_service_data.conf \ |
466 | test_speedup_data.conf | ||
diff --git a/src/util/program.c b/src/util/program.c index b6d0c78c6..9e1a83d0b 100644 --- a/src/util/program.c +++ b/src/util/program.c | |||
@@ -72,6 +72,11 @@ struct CommandContext | |||
72 | 72 | ||
73 | }; | 73 | }; |
74 | 74 | ||
75 | int | ||
76 | GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
77 | |||
78 | int | ||
79 | GNUNET_SPEEDUP_stop_ (void); | ||
75 | 80 | ||
76 | /** | 81 | /** |
77 | * Initial task called by the scheduler for each | 82 | * Initial task called by the scheduler for each |
@@ -81,6 +86,7 @@ static void | |||
81 | program_main (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 86 | program_main (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
82 | { | 87 | { |
83 | struct CommandContext *cc = cls; | 88 | struct CommandContext *cc = cls; |
89 | GNUNET_SPEEDUP_start_(cc->cfg); | ||
84 | 90 | ||
85 | GNUNET_RESOLVER_connect (cc->cfg); | 91 | GNUNET_RESOLVER_connect (cc->cfg); |
86 | cc->task (cc->task_cls, cc->args, cc->cfgfile, cc->cfg); | 92 | cc->task (cc->task_cls, cc->args, cc->cfgfile, cc->cfg); |
@@ -260,6 +266,7 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
260 | cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg); | 266 | cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg); |
261 | } | 267 | } |
262 | /* clean up */ | 268 | /* clean up */ |
269 | GNUNET_SPEEDUP_stop_ (); | ||
263 | GNUNET_CONFIGURATION_destroy (cfg); | 270 | GNUNET_CONFIGURATION_destroy (cfg); |
264 | GNUNET_free_non_null (cc.cfgfile); | 271 | GNUNET_free_non_null (cc.cfgfile); |
265 | GNUNET_free_non_null (loglev); | 272 | GNUNET_free_non_null (loglev); |
diff --git a/src/util/service.c b/src/util/service.c index 92c125df1..6a6fb6cc9 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -78,6 +78,13 @@ struct IPv6NetworkSet | |||
78 | }; | 78 | }; |
79 | 79 | ||
80 | 80 | ||
81 | int | ||
82 | GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
83 | |||
84 | int | ||
85 | GNUNET_SPEEDUP_stop_ (void); | ||
86 | |||
87 | |||
81 | /** | 88 | /** |
82 | * Parse a network specification. The argument specifies | 89 | * Parse a network specification. The argument specifies |
83 | * a list of networks. The format is | 90 | * a list of networks. The format is |
@@ -1771,7 +1778,7 @@ GNUNET_SERVICE_run (int argc, char *const *argv, const char *service_name, | |||
1771 | /* actually run service */ | 1778 | /* actually run service */ |
1772 | err = 0; | 1779 | err = 0; |
1773 | GNUNET_SCHEDULER_run (&service_task, &sctx); | 1780 | GNUNET_SCHEDULER_run (&service_task, &sctx); |
1774 | 1781 | GNUNET_SPEEDUP_start_ (cfg); | |
1775 | /* shutdown */ | 1782 | /* shutdown */ |
1776 | if ((1 == do_daemonize) && (NULL != sctx.server)) | 1783 | if ((1 == do_daemonize) && (NULL != sctx.server)) |
1777 | pid_file_delete (&sctx); | 1784 | pid_file_delete (&sctx); |
@@ -1785,6 +1792,7 @@ shutdown: | |||
1785 | GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd)); | 1792 | GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd)); |
1786 | } | 1793 | } |
1787 | 1794 | ||
1795 | GNUNET_SPEEDUP_stop_ (); | ||
1788 | GNUNET_CONFIGURATION_destroy (cfg); | 1796 | GNUNET_CONFIGURATION_destroy (cfg); |
1789 | i = 0; | 1797 | i = 0; |
1790 | if (NULL != sctx.addrs) | 1798 | if (NULL != sctx.addrs) |
diff --git a/src/util/speedup.c b/src/util/speedup.c new file mode 100644 index 000000000..6a17f3132 --- /dev/null +++ b/src/util/speedup.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2006, 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file util/speedup.c | ||
23 | * @author Matthias Wachs | ||
24 | * @brief functions to speedup peer execution by manipulation system time | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_time_lib.h" | ||
28 | #include "gnunet_scheduler_lib.h" | ||
29 | |||
30 | #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) | ||
31 | |||
32 | static long long current_offset; | ||
33 | static struct GNUNET_TIME_Relative interval; | ||
34 | static struct GNUNET_TIME_Relative delta; | ||
35 | |||
36 | static GNUNET_SCHEDULER_TaskIdentifier speedup_task; | ||
37 | |||
38 | static void | ||
39 | do_speedup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
40 | { | ||
41 | speedup_task = GNUNET_SCHEDULER_NO_TASK; | ||
42 | |||
43 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | ||
44 | return; | ||
45 | |||
46 | current_offset += delta.rel_value; | ||
47 | GNUNET_TIME_set_offset (current_offset); | ||
48 | |||
49 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Speed up execution time by %llu ms\n", delta.rel_value); | ||
50 | |||
51 | speedup_task = GNUNET_SCHEDULER_add_delayed (interval, &do_speedup, NULL); | ||
52 | } | ||
53 | |||
54 | |||
55 | int | ||
56 | GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
57 | { | ||
58 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "testing", "SPEEDUP_INTERVAL", &interval)) | ||
59 | return GNUNET_SYSERR; | ||
60 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "testing", "SPEEDUP_DELTA", &delta)) | ||
61 | return GNUNET_SYSERR; | ||
62 | |||
63 | if ((interval.rel_value == 0) || (delta.rel_value == 0)) | ||
64 | { | ||
65 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
66 | "Speed up disabled\n"); | ||
67 | return GNUNET_OK; | ||
68 | } | ||
69 | |||
70 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
71 | "Speed up execution time %llu ms every %llu ms\n", | ||
72 | delta.rel_value, interval.rel_value); | ||
73 | |||
74 | speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, &do_speedup, NULL); | ||
75 | return GNUNET_OK; | ||
76 | } | ||
77 | |||
78 | void | ||
79 | GNUNET_SPEEDUP_stop_ ( ) | ||
80 | { | ||
81 | if (GNUNET_SCHEDULER_NO_TASK != speedup_task) | ||
82 | { | ||
83 | GNUNET_SCHEDULER_cancel (speedup_task); | ||
84 | speedup_task = GNUNET_SCHEDULER_NO_TASK; | ||
85 | |||
86 | } | ||
87 | |||
88 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
89 | "Stopped execution speed up\n"); | ||
90 | } | ||
91 | |||
92 | |||
93 | |||
94 | /* end of speedup.c */ | ||
diff --git a/src/util/test_speedup.c b/src/util/test_speedup.c new file mode 100644 index 000000000..849505c24 --- /dev/null +++ b/src/util/test_speedup.c | |||
@@ -0,0 +1,101 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2006, 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_speedup.c | ||
22 | * @brief testcase for speedup.c | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_common.h" | ||
26 | #include "gnunet_program_lib.h" | ||
27 | #include "gnunet_time_lib.h" | ||
28 | #include "gnunet_strings_lib.h" | ||
29 | |||
30 | |||
31 | #define VERBOSE GNUNET_NO | ||
32 | |||
33 | static struct GNUNET_TIME_Absolute start; | ||
34 | static struct GNUNET_TIME_Absolute end; | ||
35 | static int cycles; | ||
36 | |||
37 | static void | ||
38 | run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
39 | { | ||
40 | |||
41 | cycles ++; | ||
42 | printf ("..%u", cycles); | ||
43 | fflush(stdout); | ||
44 | if (cycles <= 5) | ||
45 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &run, NULL); | ||
46 | else | ||
47 | { | ||
48 | end = GNUNET_TIME_absolute_get(); | ||
49 | printf ("\n"); | ||
50 | fflush(stdout); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | void check (void *cls, char *const *args, | ||
55 | const char *cfgfile, | ||
56 | const struct GNUNET_CONFIGURATION_Handle * | ||
57 | cfg) | ||
58 | { | ||
59 | printf ("0"); | ||
60 | fflush(stdout); | ||
61 | GNUNET_SCHEDULER_add_now(&run, NULL); | ||
62 | } | ||
63 | |||
64 | |||
65 | int | ||
66 | main (int argc, char *argv[]) | ||
67 | { | ||
68 | time_t start_real; | ||
69 | time_t end_real; | ||
70 | struct GNUNET_TIME_Relative delta; | ||
71 | |||
72 | static char *const argvn[] = { "test-speedup", | ||
73 | "-c", | ||
74 | "test_speedup_data.conf", | ||
75 | #if VERBOSE | ||
76 | "-L", "DEBUG", | ||
77 | #endif | ||
78 | NULL | ||
79 | }; | ||
80 | start_real = time (NULL); | ||
81 | start = GNUNET_TIME_absolute_get(); | ||
82 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
83 | GNUNET_GETOPT_OPTION_END | ||
84 | }; | ||
85 | |||
86 | GNUNET_PROGRAM_run ((sizeof (argvn) / sizeof (char *)) - 1, argvn, "test-speedup", | ||
87 | "nohelp", options, &check, NULL); | ||
88 | |||
89 | end_real = time (NULL); | ||
90 | delta = GNUNET_TIME_absolute_get_difference(start, end); | ||
91 | |||
92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution time in GNUnet time: %llu ms\n", delta.rel_value); | ||
93 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution time in system time: %llu ms\n", (end_real - start_real) * 1000); | ||
94 | |||
95 | if (delta.rel_value > ((end_real - start_real) * 1500)) | ||
96 | return 0; | ||
97 | else | ||
98 | return 1; | ||
99 | } | ||
100 | |||
101 | /* end of test_speedup.c */ | ||
diff --git a/src/util/test_speedup_data.conf b/src/util/test_speedup_data.conf new file mode 100644 index 000000000..262b2f01e --- /dev/null +++ b/src/util/test_speedup_data.conf | |||
@@ -0,0 +1,3 @@ | |||
1 | [testing] | ||
2 | SPEEDUP_INTERVAL = 1 ms | ||
3 | SPEEDUP_DELTA = 1 ms | ||
diff --git a/src/util/util.conf b/src/util/util.conf index ba9dfec70..f3d301e48 100644 --- a/src/util/util.conf +++ b/src/util/util.conf | |||
@@ -14,3 +14,5 @@ HOME = $SERVICEHOME | |||
14 | 14 | ||
15 | [TESTING] | 15 | [TESTING] |
16 | WEAKRANDOM = NO | 16 | WEAKRANDOM = NO |
17 | SPEEDUP_INTERVAL = 0 ms | ||
18 | SPEEDUP_DELTA = 0 ms | ||