Skip to content

Commit

Permalink
planner: add update functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
milroy committed Jan 13, 2024
1 parent bdb1530 commit d6240ab
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
20 changes: 20 additions & 0 deletions resource/planner/c++/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,26 @@ int planner::restore_track_points ()
return rc;
}

int planner::update (uint64_t resource_total)
{
int64_t delta = resource_total - m_total_resources;
m_total_resources = static_cast<int64_t> (resource_total);
scheduled_point_t *point = nullptr;
if (delta == 0)
return 0;
point = m_sched_point_tree.get_state (m_plan_start);
while (point) {
// Allow remaining to be negative. This should only happen for
// reservations, which will be removed and rescheduled during the
// next cycle. Planner C interface checks should catch negative
// remaining while adding spans. Return code is int rather than
// void as we may need checks in the future.
point->remaining = point->remaining + delta;
point = m_sched_point_tree.next (point);
}
return 0;
}

int64_t planner::get_total_resources () const
{
return m_total_resources;
Expand Down
1 change: 1 addition & 0 deletions resource/planner/c++/planner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class planner {
int erase ();
int reinitialize (int64_t base_time, uint64_t duration);
int restore_track_points ();
int update (uint64_t resource_total);

// Resources and duration
int64_t get_total_resources () const;
Expand Down
15 changes: 15 additions & 0 deletions resource/planner/c/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ int64_t planner_span_resource_count (planner_t *ctx, int64_t span_id);
*/
bool planners_equal (planner_t *lhs, planner_t *rhs);

/*! Update the counts and resource types to support elasticity.
*
* \param resource_total
* 64-bit unsigned integer of
* the total count of available resources
* of the resource type.
* \param resource_type
* string containing
* the planner resource type.
* \return 0 on success; -1 on an error with errno set as follows:
* EINVAL: invalid argument.
*/
int planner_update (planner_t *ctx,
uint64_t resource_total);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 6 additions & 0 deletions resource/planner/c/planner_c_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,12 @@ extern "C" bool planners_equal (planner_t *lhs, planner_t *rhs)
return (*(lhs->plan) == *(rhs->plan));
}

extern "C" int planner_update (planner_t *ctx,
uint64_t resource_total)
{
return ctx->plan->update (resource_total);
}

/*
* vi: ts=4 sw=4 expandtab
*/

0 comments on commit d6240ab

Please sign in to comment.