Skip to content

Commit

Permalink
i#6938 sched migrate: Fix quantum underflow
Browse files Browse the repository at this point in the history
Fix bug underflowing quantum time when trying to correct overshoot but
the quantum just expired and so is 0; or, we're replaying.
Adds an assert.

A test will come in the forthcoming rebalance test for per-output
runqueues, which is where this bug was discovered.

Issue: #6938
  • Loading branch information
derekbruening committed Sep 9, 2024
1 parent 6630c73 commit 8e4fd76
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions clients/drcachesim/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3488,7 +3488,7 @@ scheduler_tmpl_t<RecordType, ReaderType>::next_record(output_ordinal_t output,
VPRINT(this, 4,
"next_record[%d]: input %d hit end of instr quantum\n", output,
input->index);
preempt = !need_new_input;
preempt = true;
need_new_input = true;
input->instrs_in_quantum = 0;
++outputs_[output]
Expand All @@ -3510,10 +3510,12 @@ scheduler_tmpl_t<RecordType, ReaderType>::next_record(output_ordinal_t output,
// in between (e.g., scatter/gather long sequence of reads/writes) by
// setting input->switching_pre_instruction.
record_type_is_instr_boundary(record, outputs_[output].last_record)) {
VPRINT(this, 4,
"next_record[%d]: hit end of time quantum after %" PRIu64 "\n",
output, input->time_spent_in_quantum);
preempt = !need_new_input;
VPRINT(
this, 4,
"next_record[%d]: input %d hit end of time quantum after %" PRIu64
"\n",
output, input->index, input->time_spent_in_quantum);
preempt = true;
need_new_input = true;
input->time_spent_in_quantum = 0;
++outputs_[output]
Expand Down Expand Up @@ -3555,12 +3557,16 @@ scheduler_tmpl_t<RecordType, ReaderType>::next_record(output_ordinal_t output,
lock.lock();
VPRINT(this, 5, "next_record_mid[%d]: switching from %d to %d\n", output,
prev_input, outputs_[output].cur_input);
if (!preempt) {
if (!preempt && // Already reset to 0 for preempt.
options_.mapping == MAP_TO_ANY_OUTPUT) {
if (options_.quantum_unit == QUANTUM_INSTRUCTIONS &&
record_type_is_instr_boundary(record,
outputs_[output].last_record)) {
assert(inputs_[prev_input].instrs_in_quantum > 0);
--inputs_[prev_input].instrs_in_quantum;
} else if (options_.quantum_unit == QUANTUM_TIME) {
assert(inputs_[prev_input].time_spent_in_quantum >=
cur_time - prev_time_in_quantum);
inputs_[prev_input].time_spent_in_quantum -=
(cur_time - prev_time_in_quantum);
}
Expand Down

0 comments on commit 8e4fd76

Please sign in to comment.