fix: remove perf open from the initialization path

Related-To: NEO-11975

Signed-off-by: Joshua Santosh Ranjan <joshua.santosh.ranjan@intel.com>
This commit is contained in:
Joshua Santosh Ranjan
2024-07-11 07:18:02 +00:00
committed by Compute-Runtime-Automation
parent 63478808a7
commit 2e5bf8d24d
10 changed files with 56 additions and 52 deletions

View File

@@ -172,14 +172,9 @@ bool MetricIpSamplingLinuxImp::isDependencyAvailable() {
return false; return false;
} }
uint32_t notifyEveryNReports = 1u; const auto drm = device.getOsInterface().getDriverModel()->as<NEO::Drm>();
uint32_t samplingPeriod = 100; auto ioctlHelper = drm->getIoctlHelper();
return ioctlHelper->isEuStallSupported();
ze_result_t status = startMeasurement(notifyEveryNReports, samplingPeriod);
if (stream != -1) {
stopMeasurement();
}
return status == ZE_RESULT_SUCCESS ? true : false;
} }
ze_result_t MetricIpSamplingLinuxImp::getMetricsTimerResolution(uint64_t &timerResolution) { ze_result_t MetricIpSamplingLinuxImp::getMetricsTimerResolution(uint64_t &timerResolution) {

View File

@@ -189,6 +189,15 @@ HWTEST2_F(MetricIpSamplingLinuxTestPrelim, givenI915PerfIoctlEnableFailsWhenStar
EXPECT_EQ(metricIpSamplingOsInterface->startMeasurement(notifyEveryNReports, samplingPeriodNs), ZE_RESULT_ERROR_UNKNOWN); EXPECT_EQ(metricIpSamplingOsInterface->startMeasurement(notifyEveryNReports, samplingPeriodNs), ZE_RESULT_ERROR_UNKNOWN);
} }
HWTEST2_F(MetricIpSamplingLinuxTestPrelim, givenGetEuStallPropertiesWhenStartMeasurementIsCalledThenReturnFailure, IsPVC) {
auto drm = static_cast<DrmPrelimMock *>(device->getOsInterface().getDriverModel()->as<NEO::Drm>());
drm->setIoctlHelperPrelim20Mock();
uint32_t notifyEveryNReports = 0, samplingPeriodNs = 10000;
EXPECT_EQ(metricIpSamplingOsInterface->startMeasurement(notifyEveryNReports, samplingPeriodNs), ZE_RESULT_ERROR_UNKNOWN);
drm->restoreIoctlHelperPrelim20();
}
HWTEST2_F(MetricIpSamplingLinuxTestPrelim, givenCloseSucceedsWhenStopMeasurementIsCalledThenReturnSuccess, IsPVC) { HWTEST2_F(MetricIpSamplingLinuxTestPrelim, givenCloseSucceedsWhenStopMeasurementIsCalledThenReturnSuccess, IsPVC) {
VariableBackup<int> backupCloseFuncRetval(&NEO::SysCalls::closeFuncRetVal, 0); VariableBackup<int> backupCloseFuncRetval(&NEO::SysCalls::closeFuncRetVal, 0);
@@ -290,32 +299,6 @@ HWTEST2_F(MetricIpSamplingLinuxTestPrelim, GivenSupportedProductFamilyAndSupport
} }
} }
HWTEST2_F(MetricIpSamplingLinuxTestPrelim, GivenDriverOpenFailsWhenIsDependencyAvailableIsCalledThenReturnFailure, IsPVC) {
auto hwInfo = neoDevice->getRootDeviceEnvironment().getMutableHardwareInfo();
hwInfo->platform.eProductFamily = productFamily;
hwInfo->platform.usDeviceID = NEO::pvcXtDeviceIds.front();
auto drm = static_cast<DrmPrelimMock *>(device->getOsInterface().getDriverModel()->as<NEO::Drm>());
VariableBackup<int> backupCsTimeStampFrequency(&drm->storedCsTimestampFrequency, 0);
VariableBackup<int> backupStoredRetVal(&drm->storedRetVal, -1);
EXPECT_FALSE(metricIpSamplingOsInterface->isDependencyAvailable());
}
HWTEST2_F(MetricIpSamplingLinuxTestPrelim, GivenIoctlHelperFailsWhenIsDependencyAvailableIsCalledThenReturnFailure, IsPVC) {
auto hwInfo = neoDevice->getRootDeviceEnvironment().getMutableHardwareInfo();
hwInfo->platform.eProductFamily = productFamily;
hwInfo->platform.usDeviceID = NEO::pvcXtDeviceIds.front();
auto drm = static_cast<DrmPrelimMock *>(device->getOsInterface().getDriverModel()->as<NEO::Drm>());
drm->setIoctlHelperPrelim20Mock();
EXPECT_FALSE(metricIpSamplingOsInterface->isDependencyAvailable());
drm->restoreIoctlHelperPrelim20();
}
struct MetricIpSamplingLinuxMultiDeviceTest : public ::testing::Test { struct MetricIpSamplingLinuxMultiDeviceTest : public ::testing::Test {
std::unique_ptr<UltDeviceFactory> createDevices(uint32_t numSubDevices) { std::unique_ptr<UltDeviceFactory> createDevices(uint32_t numSubDevices) {

View File

@@ -139,6 +139,7 @@ class IoctlHelper {
virtual int getResetStats(ResetStats &resetStats, uint32_t *status, ResetStatsFault *resetStatsFault) = 0; virtual int getResetStats(ResetStats &resetStats, uint32_t *status, ResetStatsFault *resetStatsFault) = 0;
virtual bool getEuStallProperties(std::array<uint64_t, 12u> &properties, uint64_t dssBufferSize, virtual bool getEuStallProperties(std::array<uint64_t, 12u> &properties, uint64_t dssBufferSize,
uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) = 0; uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) = 0;
virtual bool isEuStallSupported() = 0;
virtual uint32_t getEuStallFdParameter() = 0; virtual uint32_t getEuStallFdParameter() = 0;
virtual bool perfOpenEuStallStream(uint32_t euStallFdParameter, std::array<uint64_t, 12u> &properties, int32_t *stream) = 0; virtual bool perfOpenEuStallStream(uint32_t euStallFdParameter, std::array<uint64_t, 12u> &properties, int32_t *stream) = 0;
virtual bool perfDisableEuStallStream(int32_t *stream) = 0; virtual bool perfDisableEuStallStream(int32_t *stream) = 0;
@@ -290,6 +291,7 @@ class IoctlHelperUpstream : public IoctlHelperI915 {
int vmBind(const VmBindParams &vmBindParams) override; int vmBind(const VmBindParams &vmBindParams) override;
int vmUnbind(const VmBindParams &vmBindParams) override; int vmUnbind(const VmBindParams &vmBindParams) override;
int getResetStats(ResetStats &resetStats, uint32_t *status, ResetStatsFault *resetStatsFault) override; int getResetStats(ResetStats &resetStats, uint32_t *status, ResetStatsFault *resetStatsFault) override;
bool isEuStallSupported() override;
bool getEuStallProperties(std::array<uint64_t, 12u> &properties, uint64_t dssBufferSize, uint64_t samplingRate, bool getEuStallProperties(std::array<uint64_t, 12u> &properties, uint64_t dssBufferSize, uint64_t samplingRate,
uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) override; uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) override;
uint32_t getEuStallFdParameter() override; uint32_t getEuStallFdParameter() override;
@@ -372,6 +374,7 @@ class IoctlHelperPrelim20 : public IoctlHelperI915 {
uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) override; uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) override;
bool perfOpenEuStallStream(uint32_t euStallFdParameter, std::array<uint64_t, 12u> &properties, int32_t *stream) override; bool perfOpenEuStallStream(uint32_t euStallFdParameter, std::array<uint64_t, 12u> &properties, int32_t *stream) override;
bool perfDisableEuStallStream(int32_t *stream) override; bool perfDisableEuStallStream(int32_t *stream) override;
bool isEuStallSupported() override;
uint32_t getEuStallFdParameter() override; uint32_t getEuStallFdParameter() override;
UuidRegisterResult registerUuid(const std::string &uuid, uint32_t uuidClass, uint64_t ptr, uint64_t size) override; UuidRegisterResult registerUuid(const std::string &uuid, uint32_t uuidClass, uint64_t ptr, uint64_t size) override;
UuidRegisterResult registerStringClassUuid(const std::string &uuid, uint64_t ptr, uint64_t size) override; UuidRegisterResult registerStringClassUuid(const std::string &uuid, uint64_t ptr, uint64_t size) override;

View File

@@ -561,6 +561,10 @@ std::optional<DrmParam> IoctlHelperPrelim20::getHasPageFaultParamId() {
return DrmParam::paramHasPageFault; return DrmParam::paramHasPageFault;
}; };
bool IoctlHelperPrelim20::isEuStallSupported() {
return true;
}
bool IoctlHelperPrelim20::getEuStallProperties(std::array<uint64_t, 12u> &properties, uint64_t dssBufferSize, uint64_t samplingRate, bool IoctlHelperPrelim20::getEuStallProperties(std::array<uint64_t, 12u> &properties, uint64_t dssBufferSize, uint64_t samplingRate,
uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) { uint64_t pollPeriod, uint64_t engineInstance, uint64_t notifyNReports) {
properties[0] = prelim_drm_i915_eu_stall_property_id::PRELIM_DRM_I915_EU_STALL_PROP_BUF_SZ; properties[0] = prelim_drm_i915_eu_stall_property_id::PRELIM_DRM_I915_EU_STALL_PROP_BUF_SZ;
@@ -590,7 +594,7 @@ bool IoctlHelperPrelim20::perfOpenEuStallStream(uint32_t euStallFdParameter, std
I915_PERF_FLAG_FD_NONBLOCK; I915_PERF_FLAG_FD_NONBLOCK;
param.num_properties = sizeof(properties) / 16; param.num_properties = sizeof(properties) / 16;
param.properties_ptr = reinterpret_cast<uintptr_t>(properties.data()); param.properties_ptr = reinterpret_cast<uintptr_t>(properties.data());
*stream = ioctl(this->drm.getFileDescriptor(), DrmIoctl::perfOpen, &param); *stream = ioctl(DrmIoctl::perfOpen, &param);
if (*stream < 0) { if (*stream < 0) {
PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get() && (*stream < 0), stderr, PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get() && (*stream < 0), stderr,
"%s failed errno = %d | ret = %d \n", "DRM_IOCTL_I915_PERF_OPEN", errno, *stream); "%s failed errno = %d | ret = %d \n", "DRM_IOCTL_I915_PERF_OPEN", errno, *stream);

View File

@@ -195,6 +195,10 @@ std::optional<DrmParam> IoctlHelperUpstream::getHasPageFaultParamId() {
return std::nullopt; return std::nullopt;
}; };
bool IoctlHelperUpstream::isEuStallSupported() {
return false;
}
bool IoctlHelperUpstream::getEuStallProperties(std::array<uint64_t, 12u> &properties, uint64_t dssBufferSize, bool IoctlHelperUpstream::getEuStallProperties(std::array<uint64_t, 12u> &properties, uint64_t dssBufferSize,
uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance, uint64_t samplingRate, uint64_t pollPeriod, uint64_t engineInstance,
uint64_t notifyNReports) { uint64_t notifyNReports) {

View File

@@ -82,6 +82,7 @@ class IoctlHelperXe : public IoctlHelper {
int getResetStats(ResetStats &resetStats, uint32_t *status, ResetStatsFault *resetStatsFault) override; int getResetStats(ResetStats &resetStats, uint32_t *status, ResetStatsFault *resetStatsFault) override;
bool getEuStallProperties(std::array<uint64_t, 12u> &properties, uint64_t dssBufferSize, uint64_t samplingRate, uint64_t pollPeriod, bool getEuStallProperties(std::array<uint64_t, 12u> &properties, uint64_t dssBufferSize, uint64_t samplingRate, uint64_t pollPeriod,
uint64_t engineInstance, uint64_t notifyNReports) override; uint64_t engineInstance, uint64_t notifyNReports) override;
bool isEuStallSupported() override;
uint32_t getEuStallFdParameter() override; uint32_t getEuStallFdParameter() override;
bool perfOpenEuStallStream(uint32_t euStallFdParameter, std::array<uint64_t, 12u> &properties, int32_t *stream) override; bool perfOpenEuStallStream(uint32_t euStallFdParameter, std::array<uint64_t, 12u> &properties, int32_t *stream) override;
bool perfDisableEuStallStream(int32_t *stream) override; bool perfDisableEuStallStream(int32_t *stream) override;

View File

@@ -32,4 +32,8 @@ int IoctlHelperXe::perfOpenIoctl(DrmIoctl request, void *arg) {
return 0; return 0;
} }
bool IoctlHelperXe::isEuStallSupported() {
return false;
}
} // namespace NEO } // namespace NEO

View File

@@ -371,6 +371,10 @@ TEST_F(IoctlPrelimHelperTests, givenValidInputWhenFillVmBindUserFenceThenProperV
EXPECT_EQ(expectedSize, sizeof(prelimVmBindExtUserFence)); EXPECT_EQ(expectedSize, sizeof(prelimVmBindExtUserFence));
} }
TEST_F(IoctlPrelimHelperTests, givenPrelimWhenCallingIsEuStallSupportedThenTrueIsReturned) {
EXPECT_TRUE(ioctlHelper.isEuStallSupported());
}
TEST_F(IoctlPrelimHelperTests, givenPrelimWhenGettingEuStallPropertiesThenCorrectPropertiesAreReturned) { TEST_F(IoctlPrelimHelperTests, givenPrelimWhenGettingEuStallPropertiesThenCorrectPropertiesAreReturned) {
std::array<uint64_t, 12u> properties = {}; std::array<uint64_t, 12u> properties = {};
EXPECT_TRUE(ioctlHelper.getEuStallProperties(properties, 0x101, 0x102, 0x103, 1, 20u)); EXPECT_TRUE(ioctlHelper.getEuStallProperties(properties, 0x101, 0x102, 0x103, 1, 20u));
@@ -387,6 +391,14 @@ TEST_F(IoctlPrelimHelperTests, givenPrelimWhenGettingEuStallPropertiesThenCorrec
EXPECT_EQ(properties[11], 20u); EXPECT_EQ(properties[11], 20u);
} }
TEST_F(IoctlPrelimHelperTests, givenPrelimWhenCallingPerfOpenEuStallStreamWithInvalidArgumentsThenFailureReturned) {
std::array<uint64_t, 12u> properties = {};
int32_t invalidStream = -1;
DrmMock *mockDrm = reinterpret_cast<DrmMock *>(drm.get());
mockDrm->failPerfOpen = true;
EXPECT_FALSE(ioctlHelper.perfOpenEuStallStream(0u, properties, &invalidStream));
}
TEST_F(IoctlPrelimHelperTests, givenPrelimWhenGettingEuStallFdParameterThenCorrectIoctlValueIsReturned) { TEST_F(IoctlPrelimHelperTests, givenPrelimWhenGettingEuStallFdParameterThenCorrectIoctlValueIsReturned) {
EXPECT_EQ(static_cast<uint32_t>(PRELIM_I915_PERF_FLAG_FD_EU_STALL), ioctlHelper.getEuStallFdParameter()); EXPECT_EQ(static_cast<uint32_t>(PRELIM_I915_PERF_FLAG_FD_EU_STALL), ioctlHelper.getEuStallFdParameter());
} }
@@ -436,11 +448,6 @@ struct MockIoctlHelperPrelim20 : IoctlHelperPrelim20 {
return -1; return -1;
} }
} }
if (request == DrmIoctl::perfOpen) {
if (failPerfOpen) {
return -1;
}
}
return IoctlHelperPrelim20::ioctl(fd, request, arg); return IoctlHelperPrelim20::ioctl(fd, request, arg);
} }
bool checkWhetherGemCreateExtContainsMemPolicy(void *arg) { bool checkWhetherGemCreateExtContainsMemPolicy(void *arg) {
@@ -563,18 +570,6 @@ TEST(IoctlPrelimHelperPerfTests, givenCalltoPerfDisableEuStallStreamWithInvalidS
EXPECT_FALSE(mockIoctlHelper.perfDisableEuStallStream(&invalidFd)); EXPECT_FALSE(mockIoctlHelper.perfDisableEuStallStream(&invalidFd));
} }
TEST(IoctlPrelimHelperPerfTests, givenPrelimWhenCallingPerfOpenEuStallStreamWithInvalidArgumentsThenFailureReturned) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmMock>(*executionEnvironment->rootDeviceEnvironments[0]);
MockIoctlHelperPrelim20 mockIoctlHelper{*drm};
mockIoctlHelper.initialize();
int32_t invalidFd = -1;
mockIoctlHelper.failPerfOpen = true;
std::array<uint64_t, 12u> properties = {};
EXPECT_FALSE(mockIoctlHelper.perfOpenEuStallStream(0u, properties, &invalidFd));
}
TEST(IoctlPrelimHelperPerfTests, givenCalltoPerfOpenEuStallStreamWithInvalidStreamWithEnableSetToFailThenFailureReturned) { TEST(IoctlPrelimHelperPerfTests, givenCalltoPerfOpenEuStallStreamWithInvalidStreamWithEnableSetToFailThenFailureReturned) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>(); auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmMock>(*executionEnvironment->rootDeviceEnvironments[0]); auto drm = std::make_unique<DrmMock>(*executionEnvironment->rootDeviceEnvironments[0]);

View File

@@ -520,6 +520,13 @@ TEST(IoctlHelperTestsUpstream, givenUpstreamWhenSetVmPrefetchThenReturnTrue) {
EXPECT_TRUE(ioctlHelper->setVmPrefetch(0, 0, 0, 0)); EXPECT_TRUE(ioctlHelper->setVmPrefetch(0, 0, 0, 0));
} }
TEST(IoctlHelperTestsUpstream, whenCallingIsEuStallSupportedThenFalseIsReturned) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]);
auto ioctlHelper = drm->getIoctlHelper();
EXPECT_FALSE(ioctlHelper->isEuStallSupported());
}
TEST(IoctlHelperTestsUpstream, whenCallingGetEuStallPropertiesThenFailueIsReturned) { TEST(IoctlHelperTestsUpstream, whenCallingGetEuStallPropertiesThenFailueIsReturned) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>(); auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]); auto drm = std::make_unique<DrmTipMock>(*executionEnvironment->rootDeviceEnvironments[0]);

View File

@@ -97,3 +97,11 @@ TEST(IoctlHelperXeTest, whenCallingPerfDisableIoctlThenProperValueIsReturned) {
int32_t invalidFd = -1; int32_t invalidFd = -1;
EXPECT_EQ(0, xeIoctlHelper.get()->ioctl(invalidFd, DrmIoctl::perfDisable, nullptr)); EXPECT_EQ(0, xeIoctlHelper.get()->ioctl(invalidFd, DrmIoctl::perfDisable, nullptr));
} }
TEST(IoctlHelperXeTest, whenCallingIsEuStallSupportedThenFalseIsReturned) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
auto drm = DrmMockXe::create(*executionEnvironment->rootDeviceEnvironments[0]);
auto xeIoctlHelper = std::make_unique<IoctlHelperXe>(*drm);
EXPECT_NE(nullptr, xeIoctlHelper);
EXPECT_FALSE(xeIoctlHelper.get()->isEuStallSupported());
}