fix bug: negative remaining slack turns to be a large number when assign it to a uint64_t type of value

main
xiaosuGW 3 years ago
parent c64a45b214
commit f53255bbf3

@ -23,13 +23,18 @@ sandbox_set_as_running(struct sandbox *sandbox, sandbox_state_t last_state)
case SANDBOX_RUNNABLE: {
uint64_t start_execution = now - system_start_timestamp;
uint64_t last = sandbox->last_update_timestamp;
uint32_t last_rs = sandbox->remaining_slack;
sandbox->remaining_slack -= (now - sandbox->last_update_timestamp);
uint64_t last_rs = sandbox->remaining_slack;
int64_t rs = sandbox->remaining_slack - (now - sandbox->last_update_timestamp);
if (rs < 0) {
sandbox->remaining_slack = 0;
} else {
sandbox->remaining_slack = rs;
}
sandbox->last_update_timestamp = now;
sandbox->runnable_duration += duration_of_last_state;
current_sandbox_set(sandbox);
runtime_worker_threads_deadline[worker_thread_idx] = sandbox->absolute_deadline;
mem_log("time %lu sandbox starts running, request id:%d name %s obj=%p remaining slack %lu, last_rs %u now %lu last %lu \n", start_execution,
mem_log("time %lu sandbox starts running, request id:%d name %s obj=%p remaining slack %lu, last_rs %lu now %lu last %lu \n", start_execution,
sandbox->id, sandbox->module->name, sandbox, sandbox->remaining_slack, last_rs, now, last);
/* Does not handle context switch because the caller knows if we need to use fast or slow switched */
break;

@ -182,8 +182,11 @@ listener_thread_main(void *dummy)
next_module = next_module->next_module;
}
uint64_t remaining_slack = module->relative_deadline - estimated_execution_time;
int64_t remaining_slack = module->relative_deadline - estimated_execution_time;
if (remaining_slack < 0) {
remaining_slack = 0;
}
/* Allocate a Sandbox Request */
struct sandbox_request *sandbox_request =
sandbox_request_allocate(module, true, 0, module->name, client_socket,

Loading…
Cancel
Save