Skip to content

Commit 018e585

Browse files
Extract HwDeviceId from Drm
Related-To: NEO-4208 Change-Id: I1678ad92cab2a369769b93da69dc46a1d515f261 Signed-off-by: Jablonski, Mateusz <[email protected]>
1 parent 8560b2b commit 018e585

21 files changed

+142
-25
lines changed

core/os_interface/linux/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ set(NEO_CORE_OS_INTERFACE_LINUX
2323
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler.cpp
2424
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler.h
2525
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config.cpp
26+
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id.h
27+
${CMAKE_CURRENT_SOURCE_DIR}/hw_device_id_linux.cpp
2628
${CMAKE_CURRENT_SOURCE_DIR}/linux_inc.cpp
2729
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_query.cpp
2830
${CMAKE_CURRENT_SOURCE_DIR}/engine_info.h
@@ -43,6 +45,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX
4345
${CMAKE_CURRENT_SOURCE_DIR}/os_time_linux.h
4446
${CMAKE_CURRENT_SOURCE_DIR}/page_table_manager_functions.cpp
4547
${CMAKE_CURRENT_SOURCE_DIR}/print.cpp
48+
${CMAKE_CURRENT_SOURCE_DIR}/sys_calls.h
4649
)
4750

4851
set_property(GLOBAL PROPERTY NEO_CORE_OS_INTERFACE_LINUX ${NEO_CORE_OS_INTERFACE_LINUX})

core/os_interface/linux/drm_neo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int Drm::ioctl(unsigned long request, void *arg) {
5656
int ret;
5757
SYSTEM_ENTER();
5858
do {
59-
ret = ::ioctl(fd, request, arg);
59+
ret = ::ioctl(getFileDescriptor(), request, arg);
6060
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
6161
SYSTEM_LEAVE(request);
6262
return ret;

core/os_interface/linux/drm_neo.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99
#include "core/helpers/basic_math.h"
1010
#include "core/os_interface/linux/engine_info.h"
11+
#include "core/os_interface/linux/hw_device_id.h"
1112
#include "core/os_interface/linux/memory_info.h"
1213
#include "core/utilities/api_intercept.h"
1314

@@ -65,7 +66,7 @@ class Drm {
6566
bool isPreemptionSupported() const { return preemptionSupported; }
6667

6768
MOCKABLE_VIRTUAL void checkPreemptionSupport();
68-
int getFileDescriptor() const { return fd; }
69+
inline int getFileDescriptor() const { return hwDeviceId->getFileDescriptor(); }
6970
uint32_t createDrmContext();
7071
void destroyDrmContext(uint32_t drmContextId);
7172
void setLowPriorityContextParam(uint32_t drmContextId);
@@ -99,12 +100,12 @@ class Drm {
99100
drm_i915_gem_context_param_sseu sseu{};
100101
bool preemptionSupported = false;
101102
bool nonPersistentContextsSupported = false;
102-
int fd;
103+
std::unique_ptr<HwDeviceId> hwDeviceId;
103104
int deviceId = 0;
104105
int revisionId = 0;
105106
GTTYPE eGtType = GTTYPE_UNDEFINED;
106107
RootDeviceEnvironment &rootDeviceEnvironment;
107-
Drm(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : fd(fd), rootDeviceEnvironment(rootDeviceEnvironment) {}
108+
Drm(std::unique_ptr<HwDeviceId> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment) : hwDeviceId(std::move(hwDeviceIdIn)), rootDeviceEnvironment(rootDeviceEnvironment) {}
108109
std::unique_ptr<EngineInfo> engineInfo;
109110
std::unique_ptr<MemoryInfo> memoryInfo;
110111

core/os_interface/linux/drm_null_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class DrmNullDevice : public Drm {
3838
}
3939
}
4040

41-
DrmNullDevice(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(fd, rootDeviceEnvironment), gpuTimestamp(0){};
41+
DrmNullDevice(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::move(hwDeviceId), rootDeviceEnvironment), gpuTimestamp(0){};
4242

4343
protected:
4444
uint64_t gpuTimestamp;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (C) 2020 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
#include "core/helpers/non_copyable_or_moveable.h"
10+
11+
namespace NEO {
12+
13+
class HwDeviceId : NonCopyableClass {
14+
public:
15+
HwDeviceId(int fileDescriptorIn) : fileDescriptor(fileDescriptorIn) {}
16+
~HwDeviceId();
17+
constexpr int getFileDescriptor() const { return fileDescriptor; }
18+
19+
protected:
20+
const int fileDescriptor;
21+
};
22+
} // namespace NEO
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (C) 2020 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "core/os_interface/linux/hw_device_id.h"
9+
#include "core/os_interface/linux/sys_calls.h"
10+
11+
namespace NEO {
12+
13+
HwDeviceId::~HwDeviceId() {
14+
SysCalls::close(fileDescriptor);
15+
}
16+
17+
} // namespace NEO
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (C) 2020 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
namespace NEO {
11+
namespace SysCalls {
12+
int close(int fileDescriptor);
13+
}
14+
} // namespace NEO
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (C) 2020 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "core/os_interface/linux/sys_calls.h"
9+
10+
#include <unistd.h>
11+
12+
namespace NEO {
13+
namespace SysCalls {
14+
int close(int fileDescriptor) {
15+
return ::close(fileDescriptor);
16+
}
17+
} // namespace SysCalls
18+
} // namespace NEO

runtime/dll/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ set(RUNTIME_SRCS_DLL_LINUX
4747
${CMAKE_CURRENT_SOURCE_DIR}/linux/drm_neo_create.cpp
4848
${CMAKE_CURRENT_SOURCE_DIR}/linux/options_linux.cpp
4949
${CMAKE_CURRENT_SOURCE_DIR}/linux/os_interface.cpp
50+
${NEO_SOURCE_DIR}/core/os_interface/linux/sys_calls_linux.cpp
5051
)
5152

5253
set(RUNTIME_SRCS_DLL_WINDOWS

runtime/dll/linux/drm_neo_create.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ const DeviceDescriptor deviceDescriptorTable[] = {
3434

3535
static std::array<Drm *, 1> drms = {{nullptr}};
3636

37-
Drm::~Drm() {
38-
close(fd);
39-
fd = -1;
40-
}
37+
Drm::~Drm() = default;
4138

4239
Drm *Drm::get(int32_t deviceOrdinal) {
4340
if (static_cast<uint32_t>(deviceOrdinal) >= drms.size())
@@ -138,9 +135,9 @@ Drm *Drm::create(int32_t deviceOrdinal, RootDeviceEnvironment &rootDeviceEnviron
138135

139136
std::unique_ptr<Drm> drmObject;
140137
if (DebugManager.flags.EnableNullHardware.get() == true) {
141-
drmObject.reset(new DrmNullDevice(fd, rootDeviceEnvironment));
138+
drmObject.reset(new DrmNullDevice(std::make_unique<HwDeviceId>(fd), rootDeviceEnvironment));
142139
} else {
143-
drmObject.reset(new Drm(fd, rootDeviceEnvironment));
140+
drmObject.reset(new Drm(std::make_unique<HwDeviceId>(fd), rootDeviceEnvironment));
144141
}
145142

146143
// Get HW version (I915_drm.h)

0 commit comments

Comments
 (0)