Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: fix mintime resource tree corruption bug #281

Merged
merged 2 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions resource/planner/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand Down Expand Up @@ -1053,15 +1050,16 @@ 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);

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);
Expand Down Expand Up @@ -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;
}
Expand Down
71 changes: 70 additions & 1 deletion resource/planner/test/planner_test01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();

Expand All @@ -776,6 +843,8 @@ int main (int argc, char *argv[])

test_resource_service_flow ();

test_more_add_remove ();

done_testing ();

return EXIT_SUCCESS;
Expand Down