diff --git a/resource/planner/planner.c b/resource/planner/planner.c index 8478c31ac..5a4d32ad7 100644 --- a/resource/planner/planner.c +++ b/resource/planner/planner.c @@ -446,7 +446,7 @@ static scheduled_point_t *get_or_new_point (planner_t *ctx, int64_t at) point->at = at; point->in_mt_resource_tree = 0; point->new_point = 1; - point->ref_count = 1; + point->ref_count = 0; memcpy (point->scheduled, state->scheduled, sizeof (point->scheduled)); memcpy (point->remaining, state->remaining, sizeof(point->remaining)); scheduled_point_insert (point, spt); @@ -476,8 +476,6 @@ static int update_points_add_span (planner_t *ctx, zlist_t *list, span_t *span) scheduled_point_t *point = NULL; for (point = zlist_first (list); point; point = zlist_next (list)) { int i = 0; - if (!(point->new_point)) - point->ref_count++; for (i = 0; i < span->dimension; ++i) { point->scheduled[i] += span->planned[i]; point->remaining[i] -= span->planned[i]; @@ -498,7 +496,6 @@ static int update_points_subtract_span (planner_t *ctx, zlist_t *list, scheduled_point_t *point = NULL; for (point = zlist_first (list); point; point = zlist_next (list)) { int i = 0; - point->ref_count--; for (i = 0; i < span->dimension; ++i) { point->scheduled[i] -= span->planned[i]; point->remaining[i] += span->planned[i]; @@ -1053,7 +1050,9 @@ int64_t planner_add_span (planner_t *ctx, int64_t start_time, restore_track_points (ctx); list = zlist_new (); start_point = get_or_new_point (ctx, span->start); + start_point->ref_count++; last_point = get_or_new_point (ctx, span->last); + last_point->ref_count++; fetch_overlap_points (ctx, span->start, duration, list); update_points_add_span (ctx, list, span); @@ -1061,7 +1060,6 @@ int64_t planner_add_span (planner_t *ctx, int64_t start_time, start_point->new_point = 0; span->start_p = start_point; last_point->new_point = 0; - last_point->ref_count++; span->last_p = last_point; update_mintime_resource_tree (ctx, list); @@ -1094,19 +1092,26 @@ int planner_rem_span (planner_t *ctx, int64_t span_id) restore_track_points (ctx); list = zlist_new (); duration = span->last - span->start; + span->start_p->ref_count--; + span->last_p->ref_count--; fetch_overlap_points (ctx, span->start, duration, list); update_points_subtract_span (ctx, list, span); update_mintime_resource_tree (ctx, list); span->in_system = 0; - span->last_p->ref_count--; if (span->start_p->ref_count == 0) { + struct rb_root *mtrt = &(ctx->mt_resource_tree); scheduled_point_remove (span->start_p, &(ctx->sched_point_tree)); + if (span->start_p->in_mt_resource_tree) + mintime_resource_remove (span->start_p, mtrt); free (span->start_p); span->start_p = NULL; } if (span->last_p->ref_count == 0) { + struct rb_root *mtrt = &(ctx->mt_resource_tree); scheduled_point_remove (span->last_p, &(ctx->sched_point_tree)); + if (span->last_p->in_mt_resource_tree) + mintime_resource_remove (span->last_p, mtrt); free (span->last_p); span->last_p = NULL; } diff --git a/resource/planner/test/planner_test01.cpp b/resource/planner/test/planner_test01.cpp index 1f7e5ad53..4d0f72ac1 100644 --- a/resource/planner/test/planner_test01.cpp +++ b/resource/planner/test/planner_test01.cpp @@ -752,9 +752,76 @@ static int test_resource_service_flow () return 0; } +static int test_more_add_remove () +{ + int rc; + int64_t span1, span2, span3, span4, span5, span6; + size_t len = 4; + bool bo = false; + const uint64_t resource_totals[] = {100000, 10000, 10000, 1000}; + const uint64_t resource1[] = {36, 0, 0, 0}; + const uint64_t resource2[] = {3600, 0, 0, 0}; + const uint64_t resource3[] = {1800, 0, 0, 0}; + const uint64_t resource4[] = {1152, 0, 0, 100}; + const uint64_t resource5[] = {2304, 0, 0, 64}; + const uint64_t resource6[] = {468, 0, 0, 13}; + const char *resource_types[] = {"core", "gpu", "socket", "node"}; + planner_t *ctx = NULL; + std::stringstream ss; + + errno = 0; + to_stream (0, INT64_MAX, resource_totals, + (const char **)resource_types, len, ss); + ctx = planner_new (0, INT64_MAX, resource_totals, resource_types, len); + ok ((ctx && !errno), "new with (%s)", ss.str ().c_str ()); + ss.str (""); + + span1 = planner_add_span (ctx, 0, 600, resource1, len); + bo = (bo || span1 == -1); + span2 = planner_add_span (ctx, 0, 57600, resource2, len); + bo = (bo || span2 == -1); + span3 = planner_add_span (ctx, 57600, 57600, resource3, len); + bo = (bo || span3 == -1); + span4 = planner_add_span (ctx, 115200, 57600, resource4, len); + bo = (bo || span4 == -1); + span5 = planner_add_span (ctx, 172800, 57600, resource5, len); + bo = (bo || span5 == -1); + span6 = planner_add_span (ctx, 115200, 900, resource6, len); + bo = (bo || span6 == -1); + + rc = planner_rem_span (ctx, span1); + bo = (bo || rc == -1); + rc = planner_rem_span (ctx, span2); + bo = (bo || rc == -1); + rc = planner_rem_span (ctx, span3); + bo = (bo || rc == -1); + rc = planner_rem_span (ctx, span4); + bo = (bo || rc == -1); + rc = planner_rem_span (ctx, span5); + bo = (bo || rc == -1); + rc = planner_rem_span (ctx, span6); + bo = (bo || rc == -1); + + span1 = planner_add_span (ctx, 0, 600, resource1, len); + bo = (bo || span1 == -1); + span2 = planner_add_span (ctx, 0, 57600, resource2, len); + bo = (bo || span2 == -1); + span3 = planner_add_span (ctx, 57600, 57600, resource3, len); + bo = (bo || span3 == -1); + span4 = planner_add_span (ctx, 115200, 57600, resource4, len); + bo = (bo || span4 == -1); + span5 = planner_add_span (ctx, 172800, 57600, resource5, len); + bo = (bo || span5 == -1); + span6 = planner_add_span (ctx, 115200, 900, resource6, len); + bo = (bo || span6 == -1); + + ok (!bo && !errno, "more add-remove-add test works"); + return 0; +} + int main (int argc, char *argv[]) { - plan (61); + plan (63); test_planner_getters (); @@ -776,6 +843,8 @@ int main (int argc, char *argv[]) test_resource_service_flow (); + test_more_add_remove (); + done_testing (); return EXIT_SUCCESS;