Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit ab15da4

Browse files
vsytchanusha GodavarthySurya
authored andcommitted
SWDEV-283981 - [PAL] Support hostcall SQ interrupt
Note that this requires base driver CL#2340320+ to have SQ interrupt functionality enabled by default. Change-Id: I04b936819ebe1eb7cf5de1db4fafe83af3a1b5f6
1 parent 0afd6e1 commit ab15da4

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

device/devhostcall.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,10 @@ void HostcallListener::removeBuffer(HostcallBuffer* buffer) {
335335

336336
bool HostcallListener::initialize(const amd::Device &dev) {
337337
doorbell_ = dev.createSignal();
338-
#ifdef WITH_HSA_DEVICE
339-
auto ws = device::Signal::WaitState::Blocked;
340-
#else
338+
#if defined(WITH_PAL_DEVICE) && !defined(_WIN32)
341339
auto ws = device::Signal::WaitState::Active;
340+
#else
341+
auto ws = device::Signal::WaitState::Blocked;
342342
#endif
343343
if ((doorbell_ == nullptr) || !doorbell_->Init(dev, SIGNAL_INIT, ws)) {
344344
return false;

device/pal/palsignal.cpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ namespace pal {
2929

3030
Signal::~Signal() {
3131
dev_->context().svmFree(amdSignal_);
32+
33+
if (ws_ == device::Signal::WaitState::Blocked) {
34+
#if defined(_WIN32)
35+
Pal::Result result = Pal::Result::Success;
36+
37+
Pal::UnregisterEventInfo eventInfo = {};
38+
eventInfo.pEvent = &event_;
39+
eventInfo.trackingType = Pal::EventTrackingType::ShaderInterrupt;
40+
result = dev_->iDev()->UnregisterEvent(eventInfo);
41+
if (result != Pal::Result::Success) {
42+
ClPrint(amd::LOG_ERROR, amd::LOG_QUEUE,
43+
"Failed to unregister SQ event needed for hostcall buffer");
44+
}
45+
#endif
46+
}
3247
}
3348

3449
bool Signal::Init(const amd::Device& dev, uint64_t init, device::Signal::WaitState ws) {
@@ -47,6 +62,47 @@ bool Signal::Init(const amd::Device& dev, uint64_t init, device::Signal::WaitSta
4762
amdSignal_ = new (buffer) amd_signal_t();
4863
amdSignal_->value = init;
4964

65+
if (ws_ == device::Signal::WaitState::Blocked) {
66+
#if defined(_WIN32)
67+
Pal::Result result = Pal::Result::Success;
68+
69+
Util::EventCreateFlags flags = {};
70+
flags.manualReset = false;
71+
flags.initiallySignaled = false;
72+
result = event_.Init(flags);
73+
if (result != Pal::Result::Success) {
74+
ClPrint(amd::LOG_ERROR, amd::LOG_QUEUE,
75+
"Failed to create Pal::Util::Event needed for hostcall buffer");
76+
return false;
77+
}
78+
79+
result = event_.Set();
80+
if (result != Pal::Result::Success) {
81+
ClPrint(amd::LOG_ERROR, amd::LOG_QUEUE,
82+
"Failed to set Pal::Util::Event needed for hostcall buffer");
83+
return false;
84+
}
85+
86+
Pal::RegisterEventInfo eventInputInfo = {};
87+
eventInputInfo.pEvent = &event_;
88+
eventInputInfo.trackingType = Pal::EventTrackingType::ShaderInterrupt;
89+
Pal::RegisterEventOutputInfo eventOutputInfo = {};
90+
result = dev_->iDev()->RegisterEvent(
91+
eventInputInfo,
92+
&eventOutputInfo);
93+
if (result != Pal::Result::Success) {
94+
ClPrint(amd::LOG_ERROR, amd::LOG_QUEUE,
95+
"Failed to register SQ event needed for hostcall buffer");
96+
return false;
97+
}
98+
amdSignal_->event_id = eventOutputInfo.shaderInterrupt.eventId;
99+
amdSignal_->event_mailbox_ptr = eventOutputInfo.shaderInterrupt.eventMailboxGpuVa;
100+
ClPrint(amd::LOG_INFO, amd::LOG_INIT,
101+
"Registered SQ event %d with mailbox slot %p",
102+
amdSignal_->event_id, amdSignal_->event_mailbox_ptr);
103+
#endif
104+
}
105+
50106
return true;
51107
}
52108

@@ -67,7 +123,19 @@ uint64_t Signal::Wait(uint64_t value, device::Signal::Condition c, uint64_t time
67123
} (c);
68124

69125
if (ws_ == device::Signal::WaitState::Blocked) {
70-
guarantee(false, "Unimplemented");
126+
#if defined(_WIN32)
127+
Pal::Result result = Pal::Result::Success;
128+
129+
float timeoutInSec = timeout / (1000 * 1000);
130+
result = event_.Wait(timeoutInSec);
131+
132+
if (result != Pal::Result::Success) {
133+
return -1;
134+
}
135+
136+
std::atomic_thread_fence(std::memory_order_acquire);
137+
return amdSignal_->value;
138+
#endif
71139
} else if (ws_ == device::Signal::WaitState::Active) {
72140
auto start = amd::Os::timeNanos();
73141
while (true) {

device/pal/palsignal.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include <amd_hsa_signal.h>
2626

27+
#include "palEvent.h"
28+
2729
namespace pal {
2830

2931
class Device;
@@ -32,6 +34,7 @@ class Signal: public device::Signal {
3234
private:
3335
const Device* dev_;
3436
amd_signal_t* amdSignal_;
37+
Util::Event event_;
3538

3639
public:
3740
~Signal() override;

0 commit comments

Comments
 (0)