mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 09:09:04 +08:00
feature: Add ioctl helper function to set external context
Related-To: NEO-11817 Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
41a89ac26f
commit
bf5953c091
@@ -22,7 +22,14 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
void IoctlHelper::setExternalContext(ExternalCtx *ctx) {
|
||||
externalCtx = ctx;
|
||||
}
|
||||
|
||||
int IoctlHelper::ioctl(DrmIoctl request, void *arg) {
|
||||
if (externalCtx) {
|
||||
return externalCtx->ioctl(externalCtx->handle, drm.getFileDescriptor(), getIoctlRequestValue(request), arg, false);
|
||||
}
|
||||
return drm.ioctl(request, arg);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <cinttypes>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -87,6 +88,13 @@ struct ResetStatsFault {
|
||||
uint16_t flags;
|
||||
};
|
||||
|
||||
using IoctlFunc = std::function<int(void *, int, unsigned long int, void *, bool)>;
|
||||
|
||||
struct ExternalCtx {
|
||||
void *handle = nullptr;
|
||||
IoctlFunc ioctl = nullptr;
|
||||
};
|
||||
|
||||
using MemRegionsVec = StackVec<MemoryClassInstance, 5>;
|
||||
using VmBindExtSetPatT = uint8_t[40];
|
||||
using VmBindExtUserFenceT = uint8_t[56];
|
||||
@@ -98,6 +106,7 @@ class IoctlHelper {
|
||||
static std::unique_ptr<IoctlHelper> getI915Helper(const PRODUCT_FAMILY productFamily, const std::string &prelimVersion, Drm &drm);
|
||||
virtual int ioctl(DrmIoctl request, void *arg);
|
||||
virtual int ioctl(int fd, DrmIoctl request, void *arg);
|
||||
virtual void setExternalContext(ExternalCtx *ctx);
|
||||
|
||||
virtual bool initialize() = 0;
|
||||
virtual bool isSetPairAvailable() = 0;
|
||||
@@ -214,6 +223,7 @@ class IoctlHelper {
|
||||
|
||||
protected:
|
||||
Drm &drm;
|
||||
ExternalCtx *externalCtx = nullptr;
|
||||
};
|
||||
|
||||
class IoctlHelperI915 : public IoctlHelper {
|
||||
|
||||
@@ -2402,3 +2402,28 @@ TEST(IoctlHelperXeTest, givenCorrectEuPerDssTypeWhenCheckingIfTopologyIsEuPerDss
|
||||
EXPECT_FALSE(MockIoctlHelperXe::isEuPerDssTopologyType(DRM_XE_TOPO_DSS_GEOMETRY));
|
||||
EXPECT_FALSE(MockIoctlHelperXe::isEuPerDssTopologyType(DRM_XE_TOPO_DSS_COMPUTE));
|
||||
}
|
||||
|
||||
TEST(IoctlHelperXeTest, givenIoctlHelperWhenSettingExtContextThenCallExternalIoctlFunction) {
|
||||
MockExecutionEnvironment executionEnvironment{};
|
||||
std::unique_ptr<Drm> drm{Drm::create(std::make_unique<HwDeviceIdDrm>(0, ""), *executionEnvironment.rootDeviceEnvironments[0])};
|
||||
IoctlHelperXe ioctlHelper{*drm};
|
||||
|
||||
bool ioctlCalled = false;
|
||||
ResetStats resetStats{};
|
||||
EXPECT_TRUE(ioctlHelper.ioctl(DrmIoctl::getResetStats, &resetStats));
|
||||
EXPECT_FALSE(ioctlCalled);
|
||||
|
||||
int handle = 0;
|
||||
IoctlFunc ioctl = [&](void *, int, unsigned long int, void *, bool) { ioctlCalled=true; return 0; };
|
||||
ExternalCtx ctx{&handle, ioctl};
|
||||
|
||||
ioctlHelper.setExternalContext(&ctx);
|
||||
ioctlCalled = false;
|
||||
EXPECT_EQ(0, ioctlHelper.ioctl(DrmIoctl::getResetStats, &resetStats));
|
||||
EXPECT_TRUE(ioctlCalled);
|
||||
|
||||
ioctlHelper.setExternalContext(nullptr);
|
||||
ioctlCalled = false;
|
||||
EXPECT_TRUE(ioctlHelper.ioctl(DrmIoctl::getResetStats, &resetStats));
|
||||
EXPECT_FALSE(ioctlCalled);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user