File: driver_handle.cpp

package info (click to toggle)
intel-compute-runtime 26.05.37020.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,596 kB
  • sloc: cpp: 976,037; lisp: 2,096; sh: 704; makefile: 162
file content (80 lines) | stat: -rw-r--r-- 2,202 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Copyright (C) 2026 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "level_zero/core/source/driver/driver_handle.h"

#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/os_interface/linux/ipc_socket_server.h"

namespace NEO {

void IpcSocketServerDeleter::operator()(IpcSocketServer *ptr) const {
    delete ptr;
}

} // namespace NEO

namespace L0 {

bool DriverHandle::initializeIpcSocketServer() {
    std::lock_guard<std::mutex> lock(ipcSocketServerMutex);

    if (ipcSocketServer && ipcSocketServer->isRunning()) {
        return true;
    }

    ipcSocketServer.reset(new NEO::IpcSocketServer());
    if (!ipcSocketServer->initialize()) {
        PRINT_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr,
                     "DriverHandle: Failed to initialize IPC socket server\n");
        ipcSocketServer.reset();
        return false;
    }

    PRINT_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stderr,
                 "DriverHandle: IPC socket server initialized at %s\n",
                 ipcSocketServer->getSocketPath().c_str());
    return true;
}

void DriverHandle::shutdownIpcSocketServer() {
    std::lock_guard<std::mutex> lock(ipcSocketServerMutex);
    if (ipcSocketServer) {
        ipcSocketServer->shutdown();
        ipcSocketServer.reset();
    }
}

bool DriverHandle::registerIpcHandleWithServer(uint64_t handleId, int fd) {
    std::lock_guard<std::mutex> lock(ipcSocketServerMutex);

    if (!ipcSocketServer || !ipcSocketServer->isRunning()) {
        return false;
    }

    return ipcSocketServer->registerHandle(handleId, fd);
}

bool DriverHandle::unregisterIpcHandleWithServer(uint64_t handleId) {
    std::lock_guard<std::mutex> lock(ipcSocketServerMutex);

    if (!ipcSocketServer || !ipcSocketServer->isRunning()) {
        return false;
    }

    return ipcSocketServer->unregisterHandle(handleId);
}

std::string DriverHandle::getIpcSocketServerPath() {
    std::lock_guard<std::mutex> lock(ipcSocketServerMutex);
    if (ipcSocketServer && ipcSocketServer->isRunning()) {
        return ipcSocketServer->getSocketPath();
    }
    return "";
}

} // namespace L0