From 641abe4368fb6b8660a965e8889f58d267fc8e50 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Mon, 27 May 2013 15:39:03 +0000 Subject: [PATCH] scheduling --- .../gnunet-daemon-experimentation.h | 54 ++++++++++++++- ...nunet-daemon-experimentation_experiments.c | 45 +----------- .../gnunet-daemon-experimentation_scheduler.c | 68 +++++++++++++++++++ 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 @@ /** * Timeout between request and expected response */ -#define EXP_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) +#define EXP_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) /** * Default experiment frequency */ -#define EXP_DEFAULT_EXP_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) +#define EXP_DEFAULT_EXP_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 6) /** * Default experiment duration @@ -83,6 +83,50 @@ enum GNUNET_EXPERIMENTATION_capabilities }; +/** + * Struct to store information about a specific experiment + */ +struct Experiment +{ + /* Header */ + /* ----------------- */ + char *name; + + /* Experiment issuer */ + struct GNUNET_PeerIdentity issuer; + + /* Experiment version as timestamp of creation */ + struct GNUNET_TIME_Absolute version; + + /* Description */ + char *description; + + /* Required capabilities */ + uint32_t required_capabilities; + + /* Experiment timing */ + /* ----------------- */ + + /* When to start experiment */ + struct GNUNET_TIME_Absolute start; + + /* When to end experiment */ + struct GNUNET_TIME_Absolute stop; + + /* How often to run experiment */ + struct GNUNET_TIME_Relative frequency; + + /* How long to run each execution */ + struct GNUNET_TIME_Relative duration; + + + /* Experiment itself */ + /* ----------------- */ + + /* TBD */ +}; + + /** * A experimentation node */ @@ -203,6 +247,12 @@ void GNUNET_EXPERIMENTATION_experiments_stop (); +/** + * Start the scheduler component + */ +void +GNUNET_EXPERIMENTATION_scheduler_add (struct Experiment *e); + /** * Start the scheduler component */ 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 @@ #include "gnunet-daemon-experimentation.h" -/** - * Struct to store information about a specific experiment - */ -struct Experiment -{ - /* Header */ - /* ----------------- */ - char *name; - - /* Experiment issuer */ - struct GNUNET_PeerIdentity issuer; - - /* Experiment version as timestamp of creation */ - struct GNUNET_TIME_Absolute version; - - /* Description */ - char *description; - - /* Required capabilities */ - uint32_t required_capabilities; - - /* Experiment timing */ - /* ----------------- */ - - /* When to start experiment */ - struct GNUNET_TIME_Absolute start; - - /* When to end experiment */ - struct GNUNET_TIME_Absolute stop; - - /* How often to run experiment */ - struct GNUNET_TIME_Relative frequency; - - /* How long to run each execution */ - struct GNUNET_TIME_Relative duration; - - - /* Experiment itself */ - /* ----------------- */ - - /* TBD */ -}; - /** * Struct to store information about an experiment issuer @@ -210,6 +167,8 @@ int GNUNET_EXPERIMENTATION_experiments_add (struct Issuer *i, GNUNET_CONTAINER_multihashmap_put (experiments, &e->issuer.hashPubKey, e, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); GNUNET_STATISTICS_set (GSE_stats, "# experiments", GNUNET_CONTAINER_multihashmap_size (experiments), GNUNET_NO); + GNUNET_EXPERIMENTATION_scheduler_add (e); + return GNUNET_OK; } 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 @@ #include "gnunet_statistics_service.h" #include "gnunet-daemon-experimentation.h" +struct ScheduledExperiment { + struct ScheduledExperiment *next; + struct ScheduledExperiment *prev; + + struct Experiment *e; + GNUNET_SCHEDULER_TaskIdentifier task; +}; + +struct ScheduledExperiment *list_head; +struct ScheduledExperiment *list_tail; + + +static void run (void *cls,const struct GNUNET_SCHEDULER_TaskContext* tc) +{ + struct ScheduledExperiment *se = cls; + //struct GNUNET_TIME_Relative end; + se->task = GNUNET_SCHEDULER_NO_TASK; + + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running `%s'\n", se->e->name); + +// end = GNUNET_TIME_absolute_get_remaining(se->e->stop); +// if (0 < end.rel_value) +// return; /* End of experiment is reached */ + +//GNUNET_break (0); + se->task = GNUNET_SCHEDULER_add_delayed (se->e->frequency, &run, se); +} + +/** + * Start the scheduler component + */ +void +GNUNET_EXPERIMENTATION_scheduler_add (struct Experiment *e) +{ + struct ScheduledExperiment *se; + struct GNUNET_TIME_Relative start; + struct GNUNET_TIME_Relative end; + + start = GNUNET_TIME_absolute_get_remaining(e->start); + end = GNUNET_TIME_absolute_get_remaining(e->stop); + + if (0 == end.rel_value) + return; /* End of experiment is reached */ + + se = GNUNET_malloc (sizeof (struct ScheduledExperiment)); + se->e = e; + if (0 == start.rel_value) + se->task = GNUNET_SCHEDULER_add_now (&run, se); + else + se->task = GNUNET_SCHEDULER_add_delayed (start, &run, se); + + GNUNET_CONTAINER_DLL_insert (list_head, list_tail, se); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scheduled `%s'\n", e->name); +} /** * Start the scheduler component @@ -48,7 +102,21 @@ GNUNET_EXPERIMENTATION_scheduler_start () void GNUNET_EXPERIMENTATION_scheduler_stop () { + struct ScheduledExperiment *cur; + struct ScheduledExperiment *next; + next = list_head; + while (NULL != (cur = next)) + { + next = cur->next; + GNUNET_CONTAINER_DLL_remove (list_head, list_tail, cur); + if (GNUNET_SCHEDULER_NO_TASK != cur->task) + { + GNUNET_SCHEDULER_cancel (cur->task); + cur->task = GNUNET_SCHEDULER_NO_TASK; + } + GNUNET_free (cur); + } } /* end of gnunet-daemon-experimentation_scheduler.c */ -- 2.25.1