Skip to content

Commit

Permalink
Enable sleep for all waiters
Browse files Browse the repository at this point in the history
Enable sleep for all waiters with event age tracking support kernel.

-v2: update comments

Change-Id: Icd4e1e8d83b4a54e9f6aaa99691a6573211b3337
Signed-off-by: James Zhu <James.Zhu@amd.com>
  • Loading branch information
James Zhu authored and James Zhu committed Jun 5, 2023
1 parent e1f5bdb commit 7d26afd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/core/runtime/interrupt_signal.cpp
Expand Up @@ -144,8 +144,15 @@ hsa_signal_value_t InterruptSignal::WaitRelaxed(

uint32_t prior = waiting_++;
MAKE_SCOPE_GUARD([&]() { waiting_--; });
// Allow only the first waiter to sleep (temporary, known to be bad).
if (prior != 0) wait_hint = HSA_WAIT_STATE_ACTIVE;

uint64_t event_age = 1;

if (!core::Runtime::runtime_singleton_->KfdVersion().supports_event_age) {
event_age = 0;
// Allow only the first waiter to sleep. Without event age tracking,
// race condition can cause some threads to sleep without wakeup since missing interrupt.
if (prior != 0) wait_hint = HSA_WAIT_STATE_ACTIVE;
}

int64_t value;

Expand Down Expand Up @@ -209,7 +216,7 @@ hsa_signal_value_t InterruptSignal::WaitRelaxed(
uint64_t ct=timer::duration_cast<std::chrono::milliseconds>(
time_remaining).count();
wait_ms = (ct>0xFFFFFFFEu) ? 0xFFFFFFFEu : ct;
hsaKmtWaitOnEvent(event_, wait_ms);
hsaKmtWaitOnEvent_Ext(event_, wait_ms, &event_age);
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/core/runtime/signal.cpp
Expand Up @@ -197,8 +197,10 @@ uint32_t Signal::WaitAny(uint32_t signal_count, const hsa_signal_t* hsa_signals,
for (uint32_t i = 0; i < signal_count; i++) signals[i]->waiting_--;
});

// Allow only the first waiter to sleep (temporary, known to be bad).
if (prior != 0) wait_hint = HSA_WAIT_STATE_ACTIVE;
if (!core::Runtime::runtime_singleton_->KfdVersion().supports_event_age)
// Allow only the first waiter to sleep. Without event age tracking,
// race condition can cause some threads to sleep without wakeup since missing interrupt.
if (prior != 0) wait_hint = HSA_WAIT_STATE_ACTIVE;

// Ensure that all signals in the list can be slept on.
if (wait_hint != HSA_WAIT_STATE_ACTIVE) {
Expand Down Expand Up @@ -229,6 +231,11 @@ uint32_t Signal::WaitAny(uint32_t signal_count, const hsa_signal_t* hsa_signals,
if (signal_count > small_size) delete[] evts;
});

uint64_t event_age[unique_evts] = {0};
if (core::Runtime::runtime_singleton_->KfdVersion().supports_event_age)
for (uint32_t i = 0; i < unique_evts; i++)
event_age[i] = 1;

int64_t value;

timer::fast_clock::time_point start_time = timer::fast_clock::now();
Expand Down Expand Up @@ -309,7 +316,7 @@ uint32_t Signal::WaitAny(uint32_t signal_count, const hsa_signal_t* hsa_signals,
uint64_t ct=timer::duration_cast<std::chrono::milliseconds>(
time_remaining).count();
wait_ms = (ct>0xFFFFFFFEu) ? 0xFFFFFFFEu : ct;
hsaKmtWaitOnMultipleEvents(evts, unique_evts, false, wait_ms);
hsaKmtWaitOnMultipleEvents_Ext(evts, unique_evts, false, wait_ms, event_age);
}
}

Expand Down

0 comments on commit 7d26afd

Please sign in to comment.