Skip to content

Commit

Permalink
i#5843 scheduler: Add query of input workload (#6246)
Browse files Browse the repository at this point in the history
Adds a new stream API get_input_workload_ordinal() which allows the
output stream to figure out which workload its current input stream came
from.

Adds a couple of sanity tests.

Issue: #5843
  • Loading branch information
derekbruening authored Aug 5, 2023
1 parent bd11f79 commit 61cf86d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
11 changes: 11 additions & 0 deletions clients/drcachesim/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,17 @@ scheduler_tmpl_t<RecordType, ReaderType>::get_input_ordinal(output_ordinal_t out
return outputs_[output].cur_input;
}

template <typename RecordType, typename ReaderType>
int
scheduler_tmpl_t<RecordType, ReaderType>::get_workload_ordinal(output_ordinal_t output)
{
if (output < 0 || output >= static_cast<output_ordinal_t>(outputs_.size()))
return -1;
if (outputs_[output].cur_input < 0)
return -1;
return inputs_[outputs_[output].cur_input].workload;
}

template <typename RecordType, typename ReaderType>
bool
scheduler_tmpl_t<RecordType, ReaderType>::is_record_synthetic(output_ordinal_t output)
Expand Down
17 changes: 17 additions & 0 deletions clients/drcachesim/scheduler/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,18 @@ template <typename RecordType, typename ReaderType> class scheduler_tmpl_t {
{
return scheduler_->get_input_ordinal(ordinal_);
}
/**
* Returns the ordinal for the workload which is the source of the current input
* stream feeding this output stream. This workload ordinal is the index into the
* vector of type #dynamorio::drmemtrace::scheduler_tmpl_t::input_workload_t
* passed to init(). Returns -1 if there is no current input for this output
* stream.
*/
virtual int
get_input_workload_ordinal()
{
return scheduler_->get_workload_ordinal(ordinal_);
}
/**
* Returns the value of the most recently seen #TRACE_MARKER_TYPE_TIMESTAMP
* marker.
Expand Down Expand Up @@ -1080,6 +1092,11 @@ template <typename RecordType, typename ReaderType> class scheduler_tmpl_t {
input_ordinal_t
get_input_ordinal(output_ordinal_t output);

// Returns the workload ordinal value for the current input stream scheduled on
// the 'output_ordinal'-th output stream.
int
get_workload_ordinal(output_ordinal_t output);

// Returns whether the current record for the current input stream scheduled on
// the 'output_ordinal'-th output stream is synthetic.
bool
Expand Down
12 changes: 11 additions & 1 deletion clients/drcachesim/tests/scheduler_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ test_serial()
for (scheduler_t::stream_status_t status = stream->next_record(memref);
status != scheduler_t::STATUS_EOF; status = stream->next_record(memref)) {
assert(status == scheduler_t::STATUS_OK);
// There is just one workload so we expect to always see 0 as the ordinal.
assert(stream->get_input_workload_ordinal() == 0);
if (memref.marker.type == TRACE_TYPE_MARKER &&
memref.marker.marker_type == TRACE_MARKER_TYPE_TIMESTAMP) {
assert(memref.marker.marker_value > last_timestamp);
Expand Down Expand Up @@ -784,6 +786,7 @@ test_real_file_queries_and_filters(const char *testdir)
assert(false);
auto *stream = scheduler.get_stream(0);
memref_t memref;
int max_workload_index = 0;
int max_input_index = 0;
std::set<memref_tid_t> tids_seen;
for (scheduler_t::stream_status_t status = stream->next_record(memref);
Expand All @@ -792,10 +795,17 @@ test_real_file_queries_and_filters(const char *testdir)
assert(memref.instr.tid == TID_1_A || memref.instr.tid == TID_2_A ||
memref.instr.tid == TID_2_B);
tids_seen.insert(memref.instr.tid);
if (stream->get_input_workload_ordinal() > max_workload_index)
max_workload_index = stream->get_input_workload_ordinal();
if (stream->get_input_stream_ordinal() > max_input_index)
max_input_index = stream->get_input_stream_ordinal();
if (stream->get_input_stream_ordinal() == 0)
assert(stream->get_input_workload_ordinal() == 0);
else
assert(stream->get_input_workload_ordinal() == 1);
}
// Ensure 3 input streams and test input queries.
// Ensure 2 input workloads with 3 streams with proper names.
assert(max_workload_index == 1);
assert(max_input_index == 2);
assert(scheduler.get_input_stream_count() == 3);
assert(scheduler.get_input_stream_name(0) ==
Expand Down

0 comments on commit 61cf86d

Please sign in to comment.