diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-05-27 15:39:03 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-05-27 15:39:03 +0000 |
commit | 641abe4368fb6b8660a965e8889f58d267fc8e50 (patch) | |
tree | 430d1ab209d9286b7c6b306c4ad566e57fd35d82 | |
parent | 547cc56fa3676c125430b317be820a4f82b0842d (diff) | |
download | gnunet-641abe4368fb6b8660a965e8889f58d267fc8e50.tar.gz gnunet-641abe4368fb6b8660a965e8889f58d267fc8e50.zip |
scheduling
3 files changed, 122 insertions, 45 deletions
diff --git a/src/experimentation/gnunet-daemon-experimentation.h b/src/experimentation/gnunet-daemon-experimentation.h index d61b61251..4a7e62028 100644 --- a/src/experimentation/gnunet-daemon-experimentation.h +++ b/src/experimentation/gnunet-daemon-experimentation.h | |||
@@ -34,12 +34,12 @@ | |||
34 | /** | 34 | /** |
35 | * Timeout between request and expected response | 35 | * Timeout between request and expected response |
36 | */ | 36 | */ |
37 | #define EXP_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 37 | #define EXP_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Default experiment frequency | 40 | * Default experiment frequency |
41 | */ | 41 | */ |
42 | #define EXP_DEFAULT_EXP_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 42 | #define EXP_DEFAULT_EXP_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 6) |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Default experiment duration | 45 | * Default experiment duration |
@@ -84,6 +84,50 @@ enum GNUNET_EXPERIMENTATION_capabilities | |||
84 | 84 | ||
85 | 85 | ||
86 | /** | 86 | /** |
87 | * Struct to store information about a specific experiment | ||
88 | */ | ||
89 | struct Experiment | ||
90 | { | ||
91 | /* Header */ | ||
92 | /* ----------------- */ | ||
93 | char *name; | ||
94 | |||
95 | /* Experiment issuer */ | ||
96 | struct GNUNET_PeerIdentity issuer; | ||
97 | |||
98 | /* Experiment version as timestamp of creation */ | ||
99 | struct GNUNET_TIME_Absolute version; | ||
100 | |||
101 | /* Description */ | ||
102 | char *description; | ||
103 | |||
104 | /* Required capabilities */ | ||
105 | uint32_t required_capabilities; | ||
106 | |||
107 | /* Experiment timing */ | ||
108 | /* ----------------- */ | ||
109 | |||
110 | /* When to start experiment */ | ||
111 | struct GNUNET_TIME_Absolute start; | ||
112 | |||
113 | /* When to end experiment */ | ||
114 | struct GNUNET_TIME_Absolute stop; | ||
115 | |||
116 | /* How often to run experiment */ | ||
117 | struct GNUNET_TIME_Relative frequency; | ||
118 | |||
119 | /* How long to run each execution */ | ||
120 | struct GNUNET_TIME_Relative duration; | ||
121 | |||
122 | |||
123 | /* Experiment itself */ | ||
124 | /* ----------------- */ | ||
125 | |||
126 | /* TBD */ | ||
127 | }; | ||
128 | |||
129 | |||
130 | /** | ||
87 | * A experimentation node | 131 | * A experimentation node |
88 | */ | 132 | */ |
89 | struct Node | 133 | struct Node |
@@ -207,6 +251,12 @@ GNUNET_EXPERIMENTATION_experiments_stop (); | |||
207 | * Start the scheduler component | 251 | * Start the scheduler component |
208 | */ | 252 | */ |
209 | void | 253 | void |
254 | GNUNET_EXPERIMENTATION_scheduler_add (struct Experiment *e); | ||
255 | |||
256 | /** | ||
257 | * Start the scheduler component | ||
258 | */ | ||
259 | void | ||
210 | GNUNET_EXPERIMENTATION_scheduler_start (); | 260 | GNUNET_EXPERIMENTATION_scheduler_start (); |
211 | 261 | ||
212 | 262 | ||
diff --git a/src/experimentation/gnunet-daemon-experimentation_experiments.c b/src/experimentation/gnunet-daemon-experimentation_experiments.c index 300b37d28..26157666a 100644 --- a/src/experimentation/gnunet-daemon-experimentation_experiments.c +++ b/src/experimentation/gnunet-daemon-experimentation_experiments.c | |||
@@ -32,49 +32,6 @@ | |||
32 | #include "gnunet-daemon-experimentation.h" | 32 | #include "gnunet-daemon-experimentation.h" |
33 | 33 | ||
34 | 34 | ||
35 | /** | ||
36 | * Struct to store information about a specific experiment | ||
37 | */ | ||
38 | struct Experiment | ||
39 | { | ||
40 | /* Header */ | ||
41 | /* ----------------- */ | ||
42 | char *name; | ||
43 | |||
44 | /* Experiment issuer */ | ||
45 | struct GNUNET_PeerIdentity issuer; | ||
46 | |||
47 | /* Experiment version as timestamp of creation */ | ||
48 | struct GNUNET_TIME_Absolute version; | ||
49 | |||
50 | /* Description */ | ||
51 | char *description; | ||
52 | |||
53 | /* Required capabilities */ | ||
54 | uint32_t required_capabilities; | ||
55 | |||
56 | /* Experiment timing */ | ||
57 | /* ----------------- */ | ||
58 | |||
59 | /* When to start experiment */ | ||
60 | struct GNUNET_TIME_Absolute start; | ||
61 | |||
62 | /* When to end experiment */ | ||
63 | struct GNUNET_TIME_Absolute stop; | ||
64 | |||
65 | /* How often to run experiment */ | ||
66 | struct GNUNET_TIME_Relative frequency; | ||
67 | |||
68 | /* How long to run each execution */ | ||
69 | struct GNUNET_TIME_Relative duration; | ||
70 | |||
71 | |||
72 | /* Experiment itself */ | ||
73 | /* ----------------- */ | ||
74 | |||
75 | /* TBD */ | ||
76 | }; | ||
77 | |||
78 | 35 | ||
79 | /** | 36 | /** |
80 | * Struct to store information about an experiment issuer | 37 | * Struct to store information about an experiment issuer |
@@ -210,6 +167,8 @@ int GNUNET_EXPERIMENTATION_experiments_add (struct Issuer *i, | |||
210 | GNUNET_CONTAINER_multihashmap_put (experiments, &e->issuer.hashPubKey, e, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 167 | GNUNET_CONTAINER_multihashmap_put (experiments, &e->issuer.hashPubKey, e, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
211 | GNUNET_STATISTICS_set (GSE_stats, "# experiments", GNUNET_CONTAINER_multihashmap_size (experiments), GNUNET_NO); | 168 | GNUNET_STATISTICS_set (GSE_stats, "# experiments", GNUNET_CONTAINER_multihashmap_size (experiments), GNUNET_NO); |
212 | 169 | ||
170 | GNUNET_EXPERIMENTATION_scheduler_add (e); | ||
171 | |||
213 | return GNUNET_OK; | 172 | return GNUNET_OK; |
214 | } | 173 | } |
215 | 174 | ||
diff --git a/src/experimentation/gnunet-daemon-experimentation_scheduler.c b/src/experimentation/gnunet-daemon-experimentation_scheduler.c index 478813cf7..39b541574 100644 --- a/src/experimentation/gnunet-daemon-experimentation_scheduler.c +++ b/src/experimentation/gnunet-daemon-experimentation_scheduler.c | |||
@@ -31,6 +31,60 @@ | |||
31 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
32 | #include "gnunet-daemon-experimentation.h" | 32 | #include "gnunet-daemon-experimentation.h" |
33 | 33 | ||
34 | struct ScheduledExperiment { | ||
35 | struct ScheduledExperiment *next; | ||
36 | struct ScheduledExperiment *prev; | ||
37 | |||
38 | struct Experiment *e; | ||
39 | GNUNET_SCHEDULER_TaskIdentifier task; | ||
40 | }; | ||
41 | |||
42 | struct ScheduledExperiment *list_head; | ||
43 | struct ScheduledExperiment *list_tail; | ||
44 | |||
45 | |||
46 | static void run (void *cls,const struct GNUNET_SCHEDULER_TaskContext* tc) | ||
47 | { | ||
48 | struct ScheduledExperiment *se = cls; | ||
49 | //struct GNUNET_TIME_Relative end; | ||
50 | se->task = GNUNET_SCHEDULER_NO_TASK; | ||
51 | |||
52 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running `%s'\n", se->e->name); | ||
53 | |||
54 | // end = GNUNET_TIME_absolute_get_remaining(se->e->stop); | ||
55 | // if (0 < end.rel_value) | ||
56 | // return; /* End of experiment is reached */ | ||
57 | |||
58 | //GNUNET_break (0); | ||
59 | se->task = GNUNET_SCHEDULER_add_delayed (se->e->frequency, &run, se); | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Start the scheduler component | ||
64 | */ | ||
65 | void | ||
66 | GNUNET_EXPERIMENTATION_scheduler_add (struct Experiment *e) | ||
67 | { | ||
68 | struct ScheduledExperiment *se; | ||
69 | struct GNUNET_TIME_Relative start; | ||
70 | struct GNUNET_TIME_Relative end; | ||
71 | |||
72 | start = GNUNET_TIME_absolute_get_remaining(e->start); | ||
73 | end = GNUNET_TIME_absolute_get_remaining(e->stop); | ||
74 | |||
75 | if (0 == end.rel_value) | ||
76 | return; /* End of experiment is reached */ | ||
77 | |||
78 | se = GNUNET_malloc (sizeof (struct ScheduledExperiment)); | ||
79 | se->e = e; | ||
80 | if (0 == start.rel_value) | ||
81 | se->task = GNUNET_SCHEDULER_add_now (&run, se); | ||
82 | else | ||
83 | se->task = GNUNET_SCHEDULER_add_delayed (start, &run, se); | ||
84 | |||
85 | GNUNET_CONTAINER_DLL_insert (list_head, list_tail, se); | ||
86 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scheduled `%s'\n", e->name); | ||
87 | } | ||
34 | 88 | ||
35 | /** | 89 | /** |
36 | * Start the scheduler component | 90 | * Start the scheduler component |
@@ -48,7 +102,21 @@ GNUNET_EXPERIMENTATION_scheduler_start () | |||
48 | void | 102 | void |
49 | GNUNET_EXPERIMENTATION_scheduler_stop () | 103 | GNUNET_EXPERIMENTATION_scheduler_stop () |
50 | { | 104 | { |
105 | struct ScheduledExperiment *cur; | ||
106 | struct ScheduledExperiment *next; | ||
51 | 107 | ||
108 | next = list_head; | ||
109 | while (NULL != (cur = next)) | ||
110 | { | ||
111 | next = cur->next; | ||
112 | GNUNET_CONTAINER_DLL_remove (list_head, list_tail, cur); | ||
113 | if (GNUNET_SCHEDULER_NO_TASK != cur->task) | ||
114 | { | ||
115 | GNUNET_SCHEDULER_cancel (cur->task); | ||
116 | cur->task = GNUNET_SCHEDULER_NO_TASK; | ||
117 | } | ||
118 | GNUNET_free (cur); | ||
119 | } | ||
52 | } | 120 | } |
53 | 121 | ||
54 | /* end of gnunet-daemon-experimentation_scheduler.c */ | 122 | /* end of gnunet-daemon-experimentation_scheduler.c */ |