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

i#6822 unscheduled: Add unscheduled-input drmemtrace support #6826

Merged
merged 3 commits into from
May 29, 2024

Conversation

derekbruening
Copy link
Contributor

@derekbruening derekbruening commented 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 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

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
@abhinav92003
Copy link
Contributor

I started the review but I feel I need to spend more time with this PR. This review will be a bit delayed. Sorry about that.

clients/drcachesim/common/trace_entry.h Show resolved Hide resolved
clients/drcachesim/common/trace_entry.h Outdated Show resolved Hide resolved
clients/drcachesim/scheduler/scheduler.cpp Outdated Show resolved Hide resolved
clients/drcachesim/common/trace_entry.h Show resolved Hide resolved
clients/drcachesim/common/trace_entry.h Show resolved Hide resolved
clients/drcachesim/scheduler/scheduler.cpp Outdated Show resolved Hide resolved
clients/drcachesim/common/trace_entry.h Outdated Show resolved Hide resolved
case TRACE_MARKER_TYPE_SYSCALL_UNSCHEDULE:
if (!options_.honor_direct_switches)
break;
if (input.skip_next_unscheduled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain this further. It's interesting that a prior "schedule" marker may have such an effect on a future "unschedule", especially because the "schedule" marker docs say "if it were currently unschedulable".

What real world scenario is this trying to model? What if the "do-not-unschedule" input was blocked on a I/O syscall?

Also, (not saying that we should) what's the rationale behind skip_next_unscheduled being a bool and not an int (maybe multiple other threads want to "schedule" the thread), therefore the thread should get that many get-out-of-unschedulable-state tokens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real-world kernel allows only a single skip. I believe the real-world feature's rationale is to avoid the need for synchronization in some not-uncommon pattern of calls but I'm not sure I know what that pattern is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real-world kernel allows only a single skip.

Multiple threads could want some blocked thread to be scheduled, perhaps at different times in the app's execution, but at the same time when the trace is simulated/scheduled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

especially because the "schedule" marker docs say "if it were currently unschedulable".

This was updated, as noted in the other thread.

Multiple threads could want some blocked thread to be scheduled, perhaps at different times in the app's execution, but at the same time when the trace is simulated/scheduled.

Maybe. There are many theoretical cases. This re-scheduling is always going to be best-effort. Trying to have a queue of wakers seems just as likely to cause non-representative behavior than to fix it though so it does not seem worth going in that direction. Added a comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the "schedule" events get lost due to getting accumulated, then the target thready may experience a hang if some of its "unschedulable" events don't get matched up with a "schedule".

clients/drcachesim/scheduler/scheduler.cpp Show resolved Hide resolved
@derekbruening derekbruening merged commit 7673d42 into master May 29, 2024
17 checks passed
@derekbruening derekbruening deleted the i6822-unscheduled branch May 29, 2024 00:13
derekbruening added a commit that referenced this pull request 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 pull request May 31, 2024
Adds drmemtrace view tool support for the 3 new markers added in PR
#6826.

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

Successfully merging this pull request may close these issues.

2 participants