Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ class Runtime {
int ipc_sock_server_fd_;
std::map<uint64_t, int> ipc_sock_server_conns_;
std::mutex ipc_sock_server_lock_;
os::Thread ipc_sock_server_thread_;

lazy_ptr<AsyncEventsInfo> asyncSignals_;
lazy_ptr<AsyncEventsInfo> asyncExceptions_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,13 @@ hsa_status_t Runtime::IPCCreate(void* ptr, size_t len, hsa_amd_ipc_memory_t* han
std::lock_guard<std::mutex> lock(ipc_sock_server_lock_);
#if defined(__linux__)
if (!ipc_sock_server_conns_.size()) { // create new runtime socket server
// Ensure any previous IPC server thread handle is released before starting a new one.
if (ipc_sock_server_thread_) {
os::WaitForThread(ipc_sock_server_thread_);
os::CloseThread(ipc_sock_server_thread_);
ipc_sock_server_thread_ = nullptr;
}

struct sockaddr_un address;
ipc_sock_server_fd_ = socket(AF_UNIX, SOCK_STREAM, 0);
assert(ipc_sock_server_fd_ > -1 && "DMA buffer could not be exported for IPC!");
Expand All @@ -1453,15 +1460,29 @@ hsa_status_t Runtime::IPCCreate(void* ptr, size_t len, hsa_amd_ipc_memory_t* han
address.sun_path[0] = 0; // first NULL char creates unlisted abstract socket
int err = bind(ipc_sock_server_fd_, (struct sockaddr *)&address, sizeof(struct sockaddr_un));
assert(!err && "Connection to export DMA buffer not made!");
if (err) return HSA_STATUS_ERROR;
if (err) {
close(ipc_sock_server_fd_);
ipc_sock_server_fd_ = -1;
return HSA_STATUS_ERROR;
}
err = listen(ipc_sock_server_fd_, 1);
assert(!err && "Connection to export DMA buffer not made!");
if (err) return HSA_STATUS_ERROR;
if (err) {
close(ipc_sock_server_fd_);
ipc_sock_server_fd_ = -1;
return HSA_STATUS_ERROR;
}

// Spin server client acceptance into a socket server thread.
// Socket server needs to last for the lifetime of the runtime instance
// as the attach life cycle is unknown.
os::CreateThread(AsyncIPCSockServerConnLoop, NULL);
ipc_sock_server_thread_ = os::CreateThread(AsyncIPCSockServerConnLoop, NULL);
Comment thread
shwetagkhatri marked this conversation as resolved.
if (!ipc_sock_server_thread_) {
ipc_sock_server_conns_.clear();
close(ipc_sock_server_fd_);
ipc_sock_server_fd_ = -1;
return HSA_STATUS_ERROR;
}
}
Comment thread
shwetagkhatri marked this conversation as resolved.
#else
assert(!"Unimplemented! Do we really need this?");
Expand Down Expand Up @@ -2358,8 +2379,8 @@ Runtime::Runtime()
internal_queue_create_notifier_user_data_(nullptr),
ref_count_(0),
kfd_version{},
ipc_sock_server_fd_(0) {

ipc_sock_server_fd_(0),
ipc_sock_server_thread_(nullptr) {
virtual_mem_api_supported_ = false;
ipc_dmabuf_supported_ = false;
xnack_enabled_ = false;
Expand Down Expand Up @@ -2449,6 +2470,12 @@ void Runtime::Unload() {
IPCClientImport(getpid(), IPC_SOCK_SERVER_CONN_CLOSE_HANDLE,
0, nullptr, nullptr, nullptr, false, 0);

if (ipc_sock_server_thread_) {
os::WaitForThread(ipc_sock_server_thread_);
os::CloseThread(ipc_sock_server_thread_);
ipc_sock_server_thread_ = nullptr;
}

svm_profile_.reset(nullptr);

UnloadTools();
Expand Down