gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r30484 - gnunet/src/ats


From: gnunet
Subject: [GNUnet-SVN] r30484 - gnunet/src/ats
Date: Wed, 30 Oct 2013 17:54:08 +0100

Author: oehlmann
Date: 2013-10-30 17:54:08 +0100 (Wed, 30 Oct 2013)
New Revision: 30484

Modified:
   gnunet/src/ats/libgnunet_plugin_ats_ril.c
Log:
- bulk lock
- epoch triggered after changes of environment

Modified: gnunet/src/ats/libgnunet_plugin_ats_ril.c
===================================================================
--- gnunet/src/ats/libgnunet_plugin_ats_ril.c   2013-10-30 16:35:50 UTC (rev 
30483)
+++ gnunet/src/ats/libgnunet_plugin_ats_ril.c   2013-10-30 16:54:08 UTC (rev 
30484)
@@ -258,8 +258,13 @@
   struct GNUNET_STATISTICS_Handle *stats;
 
   /**
-   * Number of performed time-steps
+   * Number of performed epochs
    */
+  unsigned long long epoch_count;
+
+  /**
+   * Number of performed steps
+   */
   unsigned long long step_count;
 
   /**
@@ -273,6 +278,16 @@
   GNUNET_SCHEDULER_TaskIdentifier next_step;
 
   /**
+   * Lock for bulk operations
+   */
+  int bulk_lock;
+
+  /**
+   * Number of changes during a lock
+   */
+  int bulk_changes;
+
+  /**
    * Learning parameters
    */
   struct RIL_Learning_Parameters parameters;
@@ -500,6 +515,13 @@
   }
 }
 
+static void ril_inform (struct GAS_RIL_Handle *solver,
+    enum GAS_Solver_Operation op, enum GAS_Solver_Status stat)
+{
+  if (NULL != solver->plugin_envi->info_cb)
+    solver->plugin_envi->info_cb (solver->plugin_envi->info_cb_cls, op, stat);
+}
+
 /**
  * Changes the active assignment suggestion of the handler and invokes the 
bw_changed callback to
  * notify ATS of its new decision
@@ -713,6 +735,8 @@
 static double
 envi_reward_local (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
 {
+  //TODO! add utilization
+
   const double *preferences;
   const double *properties;
   int prop_index;
@@ -1044,19 +1068,22 @@
 }
 
 /**
- * Cycles through all agents and lets the active ones do a step. Schedules the 
next step.
- *
- * @param cls the solver handle
- * @param tc the task context for the scheduler
+ * Triggers one epoch of agent decisions
+ * @param solver
  */
-static void
-ril_periodic_step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+static int
+ril_epoch (struct GAS_RIL_Handle *solver)
 {
-  struct GAS_RIL_Handle *solver = cls;
+  //TODO! add multiple steps per epoch
   struct RIL_Peer_Agent *cur;
 
-  LOG(GNUNET_ERROR_TYPE_DEBUG, "RIL step number %d\n", solver->step_count);
+  if (GNUNET_YES == solver->bulk_lock)
+  {
+    solver->bulk_changes ++;
+    return GNUNET_NO;
+  }
 
+  ril_inform(solver, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS);
   for (cur = solver->agents_head; NULL != cur; cur = cur->next)
   {
     if (cur->is_active && cur->address_inuse)
@@ -1064,8 +1091,27 @@
       agent_step (cur);
     }
   }
+  ril_inform(solver, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS);
 
-  solver->step_count += 1;
+  return GNUNET_YES;
+}
+
+/**
+ * Cycles through all agents and lets the active ones do a step. Schedules the 
next step.
+ *
+ * @param cls the solver handle
+ * @param tc the task context for the scheduler
+ */
+static void
+ril_periodic_step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GAS_RIL_Handle *solver = cls;
+
+  LOG(GNUNET_ERROR_TYPE_DEBUG, "RIL step number %d\n", solver->step_count);
+
+  ril_epoch(solver);
+
+  solver->epoch_count += 1;
   solver->next_step = GNUNET_SCHEDULER_add_delayed (solver->step_time, 
&ril_periodic_step, solver);
 }
 
@@ -1268,9 +1314,8 @@
   LOG(GNUNET_ERROR_TYPE_DEBUG,
       "API_address_change_preference() Preference '%s' for peer '%s' changed 
to %.2f \n",
       GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer), pref_rel);
-  /*
-   * Nothing to do here. Preferences are considered during reward calculation.
-   */
+
+  ril_epoch(solver);
 }
 
 /**
@@ -1480,6 +1525,8 @@
     envi_set_active_suggestion (s, agent, address, min_bw, min_bw, GNUNET_NO);
   }
 
+  ril_epoch(s);
+
   LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %p for 
peer '%s'\n",
       address->active ? "active" : "inactive", address->plugin, address->addr,
       GNUNET_i2s (&address->peer));
@@ -1596,6 +1643,8 @@
     }
   }
 
+  ril_epoch(solver);
+
   LOG(GNUNET_ERROR_TYPE_DEBUG, "Address deleted\n");
 }
 
@@ -1619,9 +1668,8 @@
       "API_address_property_changed() Property '%s' for peer '%s' address %p 
changed "
           "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s 
(&address->peer),
       address->addr, rel_value);
-  /*
-   * Nothing to do here, properties are considered in every reward calculation
-   */
+
+  ril_epoch(solver);
 }
 
 /**
@@ -1745,29 +1793,45 @@
 /**
  * Start a bulk operation
  *
- * Since new calculations of the assignment are not triggered by a change of 
preferences, as it
- * happens in the proportional and the mlp solver, there is no need to block 
this solver.
- *
  * @param solver the solver
  */
 void
 GAS_ril_bulk_start (void *solver)
 {
-  /* nop */
+  struct GAS_RIL_Handle *s = solver;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start() Locking solver for bulk 
operation ...\n");
+
+  s->bulk_lock++;
 }
 
 /**
  * Bulk operation done
  *
- * Since new calculations of the assignment are not triggered by a change of 
preferences, as it
- * happens in the proportional and the mlp solver, there is no need to block 
this solver.
- *
  * @param solver the solver handle
  */
 void
 GAS_ril_bulk_stop (void *solver)
 {
-  /* nop */
+  /* TODO! trigger "recalculation" after bulk / trigger "recalculation" after 
changes (address or preference)
+   * that has to be properly thought through, not when your mind is blocked 
completely
+   */
+  struct GAS_RIL_Handle *s = solver;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop() Releasing solver from bulk 
operation ...\n");
+
+  if (s->bulk_lock < 1)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  s->bulk_lock--;
+
+  if (0 < s->bulk_changes)
+  {
+    ril_epoch (solver);
+    s->bulk_changes = 0;
+  }
 }
 
 /**
@@ -1816,6 +1880,8 @@
         GNUNET_i2s (peer));
   }
 
+  ril_epoch(s);
+
   return agent->address_inuse;
 }
 
@@ -1858,6 +1924,8 @@
   envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in, 
agent->bw_out,
       GNUNET_YES);
 
+  ril_epoch(s);
+
   LOG(GNUNET_ERROR_TYPE_DEBUG,
       "API_stop_get_preferred_address() Paused agent for peer '%s' with %s 
address\n",
       GNUNET_i2s (peer), agent->address_inuse->plugin);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]