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

Add unscheduled-thread modeling to the drmemtrace scheduler #6822

Closed
derekbruening opened this issue May 21, 2024 · 0 comments
Closed

Add unscheduled-thread modeling to the drmemtrace scheduler #6822

derekbruening opened this issue May 21, 2024 · 0 comments
Assignees

Comments

@derekbruening
Copy link
Contributor

The drmemtrace scheduler currently has support for TRACE_MARKER_TYPE_DIRECT_SWITCH but it does not fully model "unscheduled" threads which will not run until explicitly woken up by another thread. This issue covers adding this support through new markers for waiting, resuming, and timeouts.

@derekbruening derekbruening self-assigned this May 21, 2024
derekbruening added a commit that referenced this issue May 21, 2024
Refactors the scheduler marker processing into two virtual functions
subclasses can override: the initialization time header marker reading
now has process_next_initial_record() while regular processing has
process_marker().

No change in functionality.  Future work will add "unscheduled thread"
support with new markers, building on this refactoring.

Issue: #6822
derekbruening added a commit that referenced this issue May 21, 2024
Refactors the scheduler marker processing into two virtual functions
subclasses can override: the initialization time header marker reading
now has process_next_initial_record() while regular processing has
process_marker().

No change in functionality. Future work will add "unscheduled thread"
support with new markers, building on this refactoring.

Issue: #6822
derekbruening added a commit that referenced this issue May 24, 2024
Augments the drmemtrace scheduler with a new notion of an
"unscheduled" input which, if it has no timeout, is not runnable
indefinitely until another input explicitly wakes it up.

Adds 3 new markers:
+ TRACE_MARKER_TYPE_SYSCALL_UNSCHEDULE, which makes the caller
  "unscheduled".
+ TRACE_MARKER_TYPE_SYSCALL_SCHEDULE, which makes a target no longer
  "unscheduled".
+ TRACE_MARKER_TYPE_SYSCALL_ARG_TIMEOUT which adds a timeout parameter
  to TRACE_MARKER_TYPE_SYSCALL_UNSCHEDULE and
  TRACE_MARKER_TYPE_DIRECT_THREAD_SWITCH

Adds handling for the new marker types.

Changes TRACE_MARKER_TYPE_DIRECT_THREAD_SWITCH to make the source
input unscheduled, unless a timeout is passed which is honored
(previously it was ignored and the syscall latency was used as the
block time if it was over the thresholds).

Adds a fallback in case unscheduled inputs are left with no
schedulable inputs.

Adds unit tests.

Also tested on a large trace with many real-world cases of these
direct switches and unschedulable threads.

Issue: #6822
derekbruening added a commit that referenced this issue May 29, 2024
Augments the drmemtrace scheduler with a new notion of an "unscheduled"
input which, if it has no timeout, is not runnable indefinitely until
another input explicitly wakes it up.

Adds 3 new markers:
+ TRACE_MARKER_TYPE_SYSCALL_UNSCHEDULE, which makes the caller
"unscheduled".
+ TRACE_MARKER_TYPE_SYSCALL_SCHEDULE, which makes a target no longer
"unscheduled".
+ TRACE_MARKER_TYPE_SYSCALL_ARG_TIMEOUT which adds a timeout parameter
to TRACE_MARKER_TYPE_SYSCALL_UNSCHEDULE and
TRACE_MARKER_TYPE_DIRECT_THREAD_SWITCH

Adds handling for the new marker types.

Changes TRACE_MARKER_TYPE_DIRECT_THREAD_SWITCH to make the source input
unscheduled, unless a timeout is passed which is honored (previously it
was ignored and the syscall latency was used as the block time if it was
over the thresholds).

Adds a fallback in case a state is reached with no schedulable inputs
yet some number of unscheduled inputs who would otherwise hang forever.

Adds unit tests.

Also tested on a large trace with many real-world cases of these direct
switches and unschedulable threads.

Issue: #6822
derekbruening added a commit that referenced this issue May 30, 2024
Adds drmemtrace view tool support for the 3 new markers added
in PR #6826.

Issue: #6822
derekbruening added a commit that referenced this issue May 31, 2024
Adds drmemtrace view tool support for the 3 new markers added in PR
#6826.

Issue: #6822
derekbruening added a commit that referenced this issue Jun 21, 2024
Adds support for threads starting out in an "unscheduled" state.  This
is accomplished by always reading ahead in each input and looking for
a TRACE_MARKER_TYPE_SYSCALL_UNSCHEDULE marker *before* the first
instruction.  Normally such a marker indicates the invocation of a
system call and is after the system call instruction; for
start-unscheduled threads it is present at the system call exit at the
start of the trace.

Changes the scheduler's virtual method process_next_initial_record()
to make the booleans on finding certain markers input-and-output
parameters and moves filetype marker handling and timestamp recording
into the function.  This also fixes a problem where an input's initial
next_timestamp was replaced with the 2nd timestamp if a subclass read
ahead.

The extra readahead causes complexities elsewhere which are addressed:
+ The reader caches the last cpuid to use for synthetic recores
  on skipping.
+ Generalizes the existing scheduler handling of readahead (the
  "recorded_in_schedule" field in input_info_t) to store a count of
  pre-read instructions, which will generally be either 0 or 1.  Adds
  a new internal interface get_instr_ordinal() to get the input
  reader's instruction ordinal minus the pre-read count.

Changes raw2trace's virtual function process_marker_additionally() to
process_marker() and moves all marker processing (including
timestamps, which are not markers in the raw format) there, to better
support subclasses inserting start-unscheduled markers and deciding
whether to insert new markers either before or after pre-existing
markers.

Adds a scheduler test for the new feature.

Issue: #6822
derekbruening added a commit that referenced this issue Jun 22, 2024
Adds support for threads starting out in an "unscheduled" state. This is
accomplished by always reading ahead in each input and looking for a
TRACE_MARKER_TYPE_SYSCALL_UNSCHEDULE marker *before* the first
instruction. Normally such a marker indicates the invocation of a system
call and is after the system call instruction; for start-unscheduled
threads it is present at the system call exit at the start of the trace.

Changes the scheduler's virtual method process_next_initial_record() to
make the booleans on finding certain markers input-and-output parameters
and moves filetype marker handling and timestamp recording into the
function. This also fixes a problem where an input's initial
next_timestamp was replaced with the 2nd timestamp if a subclass read
ahead.

The extra readahead causes complexities elsewhere which are addressed:
+ The reader caches the last cpuid to use for synthetic recores on
skipping.
+ Generalizes the existing scheduler handling of readahead (the
"recorded_in_schedule" field in input_info_t) to store a count of
pre-read instructions, which will generally be either 0 or 1. Adds a new
internal interface get_instr_ordinal() to get the input reader's
instruction ordinal minus the pre-read count.

Changes raw2trace's virtual function process_marker_additionally() to
process_marker() and moves all marker processing (including timestamps,
which are not markers in the raw format) there, to better support
subclasses inserting start-unscheduled markers and deciding whether to
insert new markers either before or after pre-existing markers.

Adds a scheduler test for the new feature.

Issue: #6822
derekbruening added a commit that referenced this issue Jun 25, 2024
Adds a new virtual raw2trace per-record action point
observe_entry_output() for use in subclasses to compute statistics or
possibly trim nearly-empty start-unscheduled threads.

Issue: #6822
derekbruening added a commit that referenced this issue Jun 25, 2024
Adds a new virtual raw2trace per-record action point
observe_entry_output() for use in subclasses to compute statistics or
possibly trim nearly-empty start-unscheduled threads.

Issue: #6822
derekbruening added a commit that referenced this issue Jul 15, 2024
Adds a missing closing '>' to the drmemtrace view tool's output for a
syscall that makes a thread become unscheduled.

Issue: #6822
derekbruening added a commit that referenced this issue Jul 16, 2024
Adds a missing closing '>' to the drmemtrace view tool's output for a
syscall that makes a thread become unscheduled.

Issue: #6822
derekbruening added a commit that referenced this issue Sep 26, 2024
Fixes a bug for going-unscheduled actions where scaling a small
timeout rounds it down to 0, which is then interpreted as an infinite
timeout.

Adds a unit test that fails without the fix.

Issue: #6822
derekbruening added a commit that referenced this issue Sep 27, 2024
Fixes a bug where an input that just went unscheduled indefinitely
will be resumed if there are no other inputs to run.

Adds a unit test that fails without the fix.

Issue: #6959, #6822
derekbruening added a commit that referenced this issue Sep 27, 2024
Fixes a bug for going-unscheduled actions where scaling a small timeout
rounds it down to 0, which is then interpreted as an infinite timeout.

Adds a unit test that fails without the fix.

Issue: #6822
derekbruening added a commit that referenced this issue Sep 28, 2024
Fixes a bug where an input that just went unscheduled indefinitely will
be resumed if there are no other inputs to run.

Adds a unit test that fails without the fix.

Issue: #6959, #6822
derekbruening added a commit that referenced this issue Oct 1, 2024
Adds a new drmemtrace scheduler option
scheduler_options_t.honor_infinite_timeouts and a CLI parameter
-sched_infinite_timeouts, both off by default.  If turned on, these
match the previous behavior.

Changes the default behavior to use the (scaled per the scale
parameter) maximum block timeout for indefinitely-unscheduled cases,
rather than using an infinite timeout.  This avoids waiting a long
time for things like background threads that do nothing but wait the
entire duration of a trace.

Adds unit test variants for both infinite and max-timeout.

Tested on a large application where this did not noticeably decrease
the successful number of direct switches, but did reduce the idle time
which was too high previously.

Issue: #6822
derekbruening added a commit that referenced this issue Oct 2, 2024
Adds a new drmemtrace scheduler option
scheduler_options_t.honor_infinite_timeouts and a CLI parameter
-sched_infinite_timeouts, both off by default. If turned on, these match
the previous behavior.

Changes the default behavior to use the (scaled per the scale parameter)
maximum block timeout for indefinitely-unscheduled cases, rather than
using an infinite timeout. This avoids waiting a long time for things
like background threads that do nothing but wait the entire duration of
a trace.

Adds unit test variants for both infinite and max-timeout.

Tested on a large application where this did not noticeably decrease the
successful number of direct switches, but did reduce the idle time which
was too high previously.

Issue: #6822
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant