Skip to content

Commit ccf5abc

Browse files
committed
planner: add update functionality
Problem: when updating the Fluxion resource graph the `planner` scheduled points' remaining resource count must be updated. Add an `update` function to add or subtract from the current remaining resource count at each scheduled point. Create a guard to ensure the remaining count is nonnegative.
1 parent 84a5ad4 commit ccf5abc

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

resource/planner/c++/planner.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,30 @@ int planner::restore_track_points ()
229229
return rc;
230230
}
231231

232+
int planner::update_total (uint64_t resource_total)
233+
{
234+
int64_t delta = resource_total - m_total_resources;
235+
int64_t tmp = 0;
236+
scheduled_point_t *point = nullptr;
237+
if (delta == 0)
238+
return 0;
239+
m_total_resources = static_cast<int64_t> (resource_total);
240+
point = m_sched_point_tree.get_state (m_plan_start);
241+
while (point) {
242+
// Prevent remaining from taking negative values. This should
243+
// reduce likelihood of errors when adding and removing spans.
244+
// If the performance penalty is non-negligible we can
245+
// investigate letting remaining take negative values.
246+
tmp = point->remaining + delta;
247+
if (tmp >= 0)
248+
point->remaining = tmp;
249+
else
250+
point->remaining = 0;
251+
point = m_sched_point_tree.next (point);
252+
}
253+
return 0;
254+
}
255+
232256
int64_t planner::get_total_resources () const
233257
{
234258
return m_total_resources;

resource/planner/c++/planner.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class planner {
5151
int erase ();
5252
int reinitialize (int64_t base_time, uint64_t duration);
5353
int restore_track_points ();
54+
int update_total (uint64_t resource_total);
5455

5556
// Resources and duration
5657
int64_t get_total_resources () const;

resource/planner/c/planner.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,19 @@ int64_t planner_span_resource_count (planner_t *ctx, int64_t span_id);
229229
*/
230230
bool planners_equal (planner_t *lhs, planner_t *rhs);
231231

232+
/*! Update the resource count to support elasticity.
233+
*
234+
* \param ctx opaque planner context returned from planner_new.
235+
* \param resource_total
236+
* 64-bit unsigned integer of
237+
* the total count of available resources
238+
* of the resource type.
239+
* \return 0 on success; -1 on an error with errno set as follows:
240+
* EINVAL: invalid argument.
241+
*/
242+
int planner_update_total (planner_t *ctx,
243+
uint64_t resource_total);
244+
232245
#ifdef __cplusplus
233246
}
234247
#endif

resource/planner/c/planner_c_interface.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,12 @@ extern "C" bool planners_equal (planner_t *lhs, planner_t *rhs)
698698
return (*(lhs->plan) == *(rhs->plan));
699699
}
700700

701+
extern "C" int planner_update_total (planner_t *ctx,
702+
uint64_t resource_total)
703+
{
704+
return ctx->plan->update_total (resource_total);
705+
}
706+
701707
/*
702708
* vi: ts=4 sw=4 expandtab
703709
*/

0 commit comments

Comments
 (0)