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

GdbServer: Rework sleeping #4208

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Sonicadvance1
Copy link
Member

@Sonicadvance1 Sonicadvance1 commented Dec 10, 2024

This is enough to get GdbServer working for my simple test case again.

Some things of note:

  • There is now a callback which signals to GdbServer when a thread is
    created.
  • Thread sleeping is now a single uint32_t futex word for knowing when a
    thread is sleeping and if we need to signal it to wake up.
  • GdbServer thread sleeping versus ThreadManager thread sleeping
    distinction has been removed. GdbServer now uses ThreadManager to put
    a thread to sleep.

This still only gets the attach at startup scheme of gdbserver working.
I haven't yet dived back in to getting arbitrary attach working.
Primarily the work necessary here is actually getting thread creation at
the start to stop and wait for gdbserver to attach. Then actually
sleeping correctly while gdbserver is communicating with gdb.

@Sonicadvance1 Sonicadvance1 force-pushed the gdbserver_rework_sleeping branch 4 times, most recently from e1d8d38 to 0b2abf9 Compare December 11, 2024 20:29
@Sonicadvance1
Copy link
Member Author

Removed the dependency on #4208 for this PR since this is independent.

@Sonicadvance1 Sonicadvance1 force-pushed the gdbserver_rework_sleeping branch from 0b2abf9 to 19a92ab Compare December 12, 2024 20:57
@pmatos
Copy link
Collaborator

pmatos commented Dec 13, 2024

Removed the dependency on #4208 for this PR since this is independent.

You probably meant to reference some other PR here, since #4208 is this PR.

@Sonicadvance1 Sonicadvance1 force-pushed the gdbserver_rework_sleeping branch 2 times, most recently from 08b7dca to 8621f25 Compare December 16, 2024 18:35
This is enough to get GdbServer working for my simple test case again.

Some things of note:
- There is now a callback which signals to GdbServer when a thread is
  created.
- Thread sleeping is now a single uint32_t futex word for knowing when a
  thread is sleeping and if we need to signal it to wake up.
- GdbServer thread sleeping versus ThreadManager thread sleeping
  distinction has been removed. GdbServer now uses ThreadManager to put
  a thread to sleep.

This still only gets the attach at startup scheme of gdbserver working.
I haven't yet dived back in to getting arbitrary attach working.
Primarily the work necessary here is actually getting thread creation at
the start to stop and wait for gdbserver to attach. Then actually
sleeping correctly while gdbserver is communicating with gdb.
@Sonicadvance1 Sonicadvance1 force-pushed the gdbserver_rework_sleeping branch from 7c9bbc5 to f79cb4e Compare December 18, 2024 19:32
@Sonicadvance1 Sonicadvance1 force-pushed the gdbserver_rework_sleeping branch from f79cb4e to a0159e1 Compare December 20, 2024 19:59
class InspectableLatch final {
public:
bool Wait(struct timespec* Timeout = nullptr) {
LOGMAN_THROW_A_FMT(Mutex.load() != HAS_SIGNALED, "Stale signal mutex!");
Copy link
Member

Choose a reason for hiding this comment

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

This line breaks pre-signaled latches, doesn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

It specifically doesn't support pre-signaled latches. That's one of the two reasons why I implemented this.

Copy link
Member

Choose a reason for hiding this comment

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

Why did you copy my docstring proposal if pre-signaling is not supported? The two are in direct contradiction as-is.

That's one of the two reasons why I implemented this.

You implemented InspectableLatch in order to be able to... not support something? Why?

(FTR I'd suggest not live-iterating the docstring any further until we find a suitable alternative, since I feel like I'm understanding increasingly less what this class is trying to achieve but GitHub makes going back to your older revisions a pain.)

}

void NotifyOne() {
#if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED
Copy link
Member

Choose a reason for hiding this comment

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

Another unnecessary preprocessor guard.

@@ -81,8 +157,7 @@ struct ThreadStateObject : public FEXCore::Allocator::FEXAllocOperators {
std::atomic<SignalEvent> SignalReason {SignalEvent::Nothing};

// Thread pause handling
std::atomic_bool ThreadSleeping {false};
FEXCore::InterruptableConditionVariable ThreadPaused;
InspectableLatch ThreadSleeping;
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be a poor name, since ThreadSleeping.HasWaiter() can't be made sense of in isolation.

Something like ThreadWakeupLatch/ThreadResumeLatch/ThreadUnpauseLatch seem more reasonable: ThreadResumeLatch.HasWaiter() and ThreadResumeLatch.NotifyOne() are both clear without having to jump around the source.

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.

3 participants