aboutsummaryrefslogtreecommitdiff
path: root/src/util/speedup.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-05-30 14:47:45 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-05-30 14:47:45 +0000
commit8f654f30c3c4987c9ca1b564d6e6f2d75ae24862 (patch)
tree5930e87f3e34c36610bc707e04a594f9b47432c2 /src/util/speedup.c
parentf3285213446b9d75720621711de099e26ea83506 (diff)
downloadgnunet-8f654f30c3c4987c9ca1b564d6e6f2d75ae24862.tar.gz
gnunet-8f654f30c3c4987c9ca1b564d6e6f2d75ae24862.zip
speedup mechanism to manipulate gnunet time
Diffstat (limited to 'src/util/speedup.c')
-rw-r--r--src/util/speedup.c94
1 files changed, 94 insertions, 0 deletions
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
32static long long current_offset;
33static struct GNUNET_TIME_Relative interval;
34static struct GNUNET_TIME_Relative delta;
35
36static GNUNET_SCHEDULER_TaskIdentifier speedup_task;
37
38static void
39do_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
55int
56GNUNET_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
78void
79GNUNET_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 */