diff options
author | Fabian Oehlmann <oehlmann@in.tum.de> | 2013-10-30 16:54:08 +0000 |
---|---|---|
committer | Fabian Oehlmann <oehlmann@in.tum.de> | 2013-10-30 16:54:08 +0000 |
commit | df64ed90529f6370a15bdb548f16b1948420c828 (patch) | |
tree | a1300c15b3b0c900abaed0bfe4ec97257d572625 /src | |
parent | 65e76227902ef9db39f94b1af8765566b31a1b2a (diff) | |
download | gnunet-df64ed90529f6370a15bdb548f16b1948420c828.tar.gz gnunet-df64ed90529f6370a15bdb548f16b1948420c828.zip |
- bulk lock
- epoch triggered after changes of environment
Diffstat (limited to 'src')
-rwxr-xr-x | src/ats/libgnunet_plugin_ats_ril.c | 116 |
1 files changed, 92 insertions, 24 deletions
diff --git a/src/ats/libgnunet_plugin_ats_ril.c b/src/ats/libgnunet_plugin_ats_ril.c index 62292ba0d..e7ba42d6b 100755 --- a/src/ats/libgnunet_plugin_ats_ril.c +++ b/src/ats/libgnunet_plugin_ats_ril.c | |||
@@ -258,7 +258,12 @@ struct GAS_RIL_Handle | |||
258 | struct GNUNET_STATISTICS_Handle *stats; | 258 | struct GNUNET_STATISTICS_Handle *stats; |
259 | 259 | ||
260 | /** | 260 | /** |
261 | * Number of performed time-steps | 261 | * Number of performed epochs |
262 | */ | ||
263 | unsigned long long epoch_count; | ||
264 | |||
265 | /** | ||
266 | * Number of performed steps | ||
262 | */ | 267 | */ |
263 | unsigned long long step_count; | 268 | unsigned long long step_count; |
264 | 269 | ||
@@ -273,6 +278,16 @@ struct GAS_RIL_Handle | |||
273 | GNUNET_SCHEDULER_TaskIdentifier next_step; | 278 | GNUNET_SCHEDULER_TaskIdentifier next_step; |
274 | 279 | ||
275 | /** | 280 | /** |
281 | * Lock for bulk operations | ||
282 | */ | ||
283 | int bulk_lock; | ||
284 | |||
285 | /** | ||
286 | * Number of changes during a lock | ||
287 | */ | ||
288 | int bulk_changes; | ||
289 | |||
290 | /** | ||
276 | * Learning parameters | 291 | * Learning parameters |
277 | */ | 292 | */ |
278 | struct RIL_Learning_Parameters parameters; | 293 | struct RIL_Learning_Parameters parameters; |
@@ -500,6 +515,13 @@ agent_modify_eligibility (struct RIL_Peer_Agent *agent, enum RIL_E_Modification | |||
500 | } | 515 | } |
501 | } | 516 | } |
502 | 517 | ||
518 | static void ril_inform (struct GAS_RIL_Handle *solver, | ||
519 | enum GAS_Solver_Operation op, enum GAS_Solver_Status stat) | ||
520 | { | ||
521 | if (NULL != solver->plugin_envi->info_cb) | ||
522 | solver->plugin_envi->info_cb (solver->plugin_envi->info_cb_cls, op, stat); | ||
523 | } | ||
524 | |||
503 | /** | 525 | /** |
504 | * Changes the active assignment suggestion of the handler and invokes the bw_changed callback to | 526 | * Changes the active assignment suggestion of the handler and invokes the bw_changed callback to |
505 | * notify ATS of its new decision | 527 | * notify ATS of its new decision |
@@ -713,6 +735,8 @@ envi_reward_global (struct GAS_RIL_Handle *solver) | |||
713 | static double | 735 | static double |
714 | envi_reward_local (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | 736 | envi_reward_local (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) |
715 | { | 737 | { |
738 | //TODO! add utilization | ||
739 | |||
716 | const double *preferences; | 740 | const double *preferences; |
717 | const double *properties; | 741 | const double *properties; |
718 | int prop_index; | 742 | int prop_index; |
@@ -1044,19 +1068,22 @@ agent_step (struct RIL_Peer_Agent *agent) | |||
1044 | } | 1068 | } |
1045 | 1069 | ||
1046 | /** | 1070 | /** |
1047 | * Cycles through all agents and lets the active ones do a step. Schedules the next step. | 1071 | * Triggers one epoch of agent decisions |
1048 | * | 1072 | * @param solver |
1049 | * @param cls the solver handle | ||
1050 | * @param tc the task context for the scheduler | ||
1051 | */ | 1073 | */ |
1052 | static void | 1074 | static int |
1053 | ril_periodic_step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1075 | ril_epoch (struct GAS_RIL_Handle *solver) |
1054 | { | 1076 | { |
1055 | struct GAS_RIL_Handle *solver = cls; | 1077 | //TODO! add multiple steps per epoch |
1056 | struct RIL_Peer_Agent *cur; | 1078 | struct RIL_Peer_Agent *cur; |
1057 | 1079 | ||
1058 | LOG(GNUNET_ERROR_TYPE_DEBUG, "RIL step number %d\n", solver->step_count); | 1080 | if (GNUNET_YES == solver->bulk_lock) |
1081 | { | ||
1082 | solver->bulk_changes ++; | ||
1083 | return GNUNET_NO; | ||
1084 | } | ||
1059 | 1085 | ||
1086 | ril_inform(solver, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS); | ||
1060 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 1087 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
1061 | { | 1088 | { |
1062 | if (cur->is_active && cur->address_inuse) | 1089 | if (cur->is_active && cur->address_inuse) |
@@ -1064,8 +1091,27 @@ ril_periodic_step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1064 | agent_step (cur); | 1091 | agent_step (cur); |
1065 | } | 1092 | } |
1066 | } | 1093 | } |
1094 | ril_inform(solver, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS); | ||
1095 | |||
1096 | return GNUNET_YES; | ||
1097 | } | ||
1098 | |||
1099 | /** | ||
1100 | * Cycles through all agents and lets the active ones do a step. Schedules the next step. | ||
1101 | * | ||
1102 | * @param cls the solver handle | ||
1103 | * @param tc the task context for the scheduler | ||
1104 | */ | ||
1105 | static void | ||
1106 | ril_periodic_step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1107 | { | ||
1108 | struct GAS_RIL_Handle *solver = cls; | ||
1109 | |||
1110 | LOG(GNUNET_ERROR_TYPE_DEBUG, "RIL step number %d\n", solver->step_count); | ||
1111 | |||
1112 | ril_epoch(solver); | ||
1067 | 1113 | ||
1068 | solver->step_count += 1; | 1114 | solver->epoch_count += 1; |
1069 | solver->next_step = GNUNET_SCHEDULER_add_delayed (solver->step_time, &ril_periodic_step, solver); | 1115 | solver->next_step = GNUNET_SCHEDULER_add_delayed (solver->step_time, &ril_periodic_step, solver); |
1070 | } | 1116 | } |
1071 | 1117 | ||
@@ -1268,9 +1314,8 @@ GAS_ril_address_change_preference (void *solver, | |||
1268 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1314 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1269 | "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n", | 1315 | "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n", |
1270 | GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer), pref_rel); | 1316 | GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer), pref_rel); |
1271 | /* | 1317 | |
1272 | * Nothing to do here. Preferences are considered during reward calculation. | 1318 | ril_epoch(solver); |
1273 | */ | ||
1274 | } | 1319 | } |
1275 | 1320 | ||
1276 | /** | 1321 | /** |
@@ -1480,6 +1525,8 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network | |||
1480 | envi_set_active_suggestion (s, agent, address, min_bw, min_bw, GNUNET_NO); | 1525 | envi_set_active_suggestion (s, agent, address, min_bw, min_bw, GNUNET_NO); |
1481 | } | 1526 | } |
1482 | 1527 | ||
1528 | ril_epoch(s); | ||
1529 | |||
1483 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %p for peer '%s'\n", | 1530 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %p for peer '%s'\n", |
1484 | address->active ? "active" : "inactive", address->plugin, address->addr, | 1531 | address->active ? "active" : "inactive", address->plugin, address->addr, |
1485 | GNUNET_i2s (&address->peer)); | 1532 | GNUNET_i2s (&address->peer)); |
@@ -1596,6 +1643,8 @@ GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_o | |||
1596 | } | 1643 | } |
1597 | } | 1644 | } |
1598 | 1645 | ||
1646 | ril_epoch(solver); | ||
1647 | |||
1599 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Address deleted\n"); | 1648 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Address deleted\n"); |
1600 | } | 1649 | } |
1601 | 1650 | ||
@@ -1619,9 +1668,8 @@ GAS_ril_address_property_changed (void *solver, | |||
1619 | "API_address_property_changed() Property '%s' for peer '%s' address %p changed " | 1668 | "API_address_property_changed() Property '%s' for peer '%s' address %p changed " |
1620 | "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer), | 1669 | "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer), |
1621 | address->addr, rel_value); | 1670 | address->addr, rel_value); |
1622 | /* | 1671 | |
1623 | * Nothing to do here, properties are considered in every reward calculation | 1672 | ril_epoch(solver); |
1624 | */ | ||
1625 | } | 1673 | } |
1626 | 1674 | ||
1627 | /** | 1675 | /** |
@@ -1745,29 +1793,45 @@ GAS_ril_address_preference_feedback (void *solver, | |||
1745 | /** | 1793 | /** |
1746 | * Start a bulk operation | 1794 | * Start a bulk operation |
1747 | * | 1795 | * |
1748 | * Since new calculations of the assignment are not triggered by a change of preferences, as it | ||
1749 | * happens in the proportional and the mlp solver, there is no need to block this solver. | ||
1750 | * | ||
1751 | * @param solver the solver | 1796 | * @param solver the solver |
1752 | */ | 1797 | */ |
1753 | void | 1798 | void |
1754 | GAS_ril_bulk_start (void *solver) | 1799 | GAS_ril_bulk_start (void *solver) |
1755 | { | 1800 | { |
1756 | /* nop */ | 1801 | struct GAS_RIL_Handle *s = solver; |
1802 | |||
1803 | LOG (GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start() Locking solver for bulk operation ...\n"); | ||
1804 | |||
1805 | s->bulk_lock++; | ||
1757 | } | 1806 | } |
1758 | 1807 | ||
1759 | /** | 1808 | /** |
1760 | * Bulk operation done | 1809 | * Bulk operation done |
1761 | * | 1810 | * |
1762 | * Since new calculations of the assignment are not triggered by a change of preferences, as it | ||
1763 | * happens in the proportional and the mlp solver, there is no need to block this solver. | ||
1764 | * | ||
1765 | * @param solver the solver handle | 1811 | * @param solver the solver handle |
1766 | */ | 1812 | */ |
1767 | void | 1813 | void |
1768 | GAS_ril_bulk_stop (void *solver) | 1814 | GAS_ril_bulk_stop (void *solver) |
1769 | { | 1815 | { |
1770 | /* nop */ | 1816 | /* TODO! trigger "recalculation" after bulk / trigger "recalculation" after changes (address or preference) |
1817 | * that has to be properly thought through, not when your mind is blocked completely | ||
1818 | */ | ||
1819 | struct GAS_RIL_Handle *s = solver; | ||
1820 | |||
1821 | LOG (GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop() Releasing solver from bulk operation ...\n"); | ||
1822 | |||
1823 | if (s->bulk_lock < 1) | ||
1824 | { | ||
1825 | GNUNET_break (0); | ||
1826 | return; | ||
1827 | } | ||
1828 | s->bulk_lock--; | ||
1829 | |||
1830 | if (0 < s->bulk_changes) | ||
1831 | { | ||
1832 | ril_epoch (solver); | ||
1833 | s->bulk_changes = 0; | ||
1834 | } | ||
1771 | } | 1835 | } |
1772 | 1836 | ||
1773 | /** | 1837 | /** |
@@ -1816,6 +1880,8 @@ GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *p | |||
1816 | GNUNET_i2s (peer)); | 1880 | GNUNET_i2s (peer)); |
1817 | } | 1881 | } |
1818 | 1882 | ||
1883 | ril_epoch(s); | ||
1884 | |||
1819 | return agent->address_inuse; | 1885 | return agent->address_inuse; |
1820 | } | 1886 | } |
1821 | 1887 | ||
@@ -1858,6 +1924,8 @@ GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdenti | |||
1858 | envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, | 1924 | envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, |
1859 | GNUNET_YES); | 1925 | GNUNET_YES); |
1860 | 1926 | ||
1927 | ril_epoch(s); | ||
1928 | |||
1861 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1929 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1862 | "API_stop_get_preferred_address() Paused agent for peer '%s' with %s address\n", | 1930 | "API_stop_get_preferred_address() Paused agent for peer '%s' with %s address\n", |
1863 | GNUNET_i2s (peer), agent->address_inuse->plugin); | 1931 | GNUNET_i2s (peer), agent->address_inuse->plugin); |