Skip to content

Commit 2993556

Browse files
fix(sysman): Changes in the Device Reset Implementation
- The unbind and bind operations in the device reset are now used for the FLR and Cold Reset and not for Warm reset. Related-To: NEO-10452 Signed-off-by: Bari, Pratik <[email protected]> Source: 317e4d8
1 parent 8e0fe98 commit 2993556

File tree

4 files changed

+62
-22
lines changed

4 files changed

+62
-22
lines changed

level_zero/sysman/source/api/global_operations/linux/sysman_os_global_operations_imp.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,12 @@ ze_result_t LinuxGlobalOperationsImp::resetImpl(ze_bool_t force, zes_reset_type_
311311
std::string flrPath = resetName + functionLevelReset;
312312
resetName = pFsAccess->getBaseName(resetName);
313313

314-
// Unbind the device from the kernel driver.
315-
result = pSysfsAccess->unbindDevice(resetName);
316-
if (ZE_RESULT_SUCCESS != result) {
317-
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to unbind device:%s and returning error:0x%x \n", __FUNCTION__, resetName.c_str(), result);
318-
return result;
314+
if (resetType == ZES_RESET_TYPE_FLR || resetType == ZES_RESET_TYPE_COLD) {
315+
result = pSysfsAccess->unbindDevice(resetName);
316+
if (ZE_RESULT_SUCCESS != result) {
317+
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to unbind device:%s and returning error:0x%x \n", __FUNCTION__, resetName.c_str(), result);
318+
return result;
319+
}
319320
}
320321

321322
std::vector<::pid_t> processes;
@@ -372,11 +373,12 @@ ze_result_t LinuxGlobalOperationsImp::resetImpl(ze_bool_t force, zes_reset_type_
372373
return result;
373374
}
374375

375-
// Rebind the device to the kernel driver.
376-
result = pSysfsAccess->bindDevice(resetName);
377-
if (ZE_RESULT_SUCCESS != result) {
378-
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to rebind the device to the kernel driver and returning error:0x%x \n", __FUNCTION__, result);
379-
return result;
376+
if (resetType == ZES_RESET_TYPE_FLR || resetType == ZES_RESET_TYPE_COLD) {
377+
result = pSysfsAccess->bindDevice(resetName);
378+
if (ZE_RESULT_SUCCESS != result) {
379+
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to bind the device to the kernel driver and returning error:0x%x \n", __FUNCTION__, result);
380+
return result;
381+
}
380382
}
381383

382384
return pLinuxSysmanImp->reInitSysmanDeviceResources();

level_zero/sysman/test/unit_tests/sources/global_operations/linux/test_zes_global_operations.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023 Intel Corporation
2+
* Copyright (C) 2023-2024 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -798,6 +798,25 @@ TEST_F(SysmanGlobalOperationsFixture, GivenForceTrueWhenCallingResetThenSuccessI
798798
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
799799
}
800800

801+
TEST_F(SysmanGlobalOperationsFixture,
802+
GivenPermissionDeniedWhenCallingGetDeviceStateThenZeResultErrorInsufficientPermissionsIsReturned) {
803+
804+
pSysfsAccess->isRootSet = false;
805+
ze_result_t result = zesDeviceReset(device, true);
806+
EXPECT_EQ(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS, result);
807+
}
808+
809+
TEST_F(SysmanGlobalOperationsFixture, GivenDeviceInUseWhenCallingResetThenZeResultErrorHandleObjectInUseIsReturned) {
810+
811+
pProcfsAccess->ourDevicePid = pProcfsAccess->extraPid;
812+
pProcfsAccess->ourDeviceFd = pProcfsAccess->extraFd;
813+
814+
pProcfsAccess->mockListProcessCall.push_back(DEVICE_IN_USE);
815+
pProcfsAccess->isRepeated.push_back(true);
816+
ze_result_t result = zesDeviceReset(device, false);
817+
EXPECT_EQ(ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE, result);
818+
}
819+
801820
TEST_F(SysmanGlobalOperationsIntegratedFixture,
802821
GivenPermissionDeniedWhenCallingGetDeviceStateThenZeResultErrorInsufficientPermissionsIsReturned) {
803822

level_zero/tools/source/sysman/global_operations/linux/os_global_operations_imp.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2023 Intel Corporation
2+
* Copyright (C) 2020-2024 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -231,11 +231,12 @@ ze_result_t LinuxGlobalOperationsImp::resetImpl(ze_bool_t force, zes_reset_type_
231231
std::string flrPath = resetName + functionLevelReset;
232232
resetName = pFsAccess->getBaseName(resetName);
233233

234-
// Unbind the device from the kernel driver.
235-
result = pSysfsAccess->unbindDevice(resetName);
236-
if (ZE_RESULT_SUCCESS != result) {
237-
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to unbind device:%s and returning error:0x%x \n", __FUNCTION__, resetName.c_str(), result);
238-
return result;
234+
if (resetType == ZES_RESET_TYPE_FLR || resetType == ZES_RESET_TYPE_COLD) {
235+
result = pSysfsAccess->unbindDevice(resetName);
236+
if (ZE_RESULT_SUCCESS != result) {
237+
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to unbind device:%s and returning error:0x%x \n", __FUNCTION__, resetName.c_str(), result);
238+
return result;
239+
}
239240
}
240241

241242
std::vector<::pid_t> processes;
@@ -292,10 +293,12 @@ ze_result_t LinuxGlobalOperationsImp::resetImpl(ze_bool_t force, zes_reset_type_
292293
return result;
293294
}
294295

295-
result = pSysfsAccess->bindDevice(resetName);
296-
if (ZE_RESULT_SUCCESS != result) {
297-
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to bind the device to the kernel driver and returning error:0x%x \n", __FUNCTION__, result);
298-
return result;
296+
if (resetType == ZES_RESET_TYPE_FLR || resetType == ZES_RESET_TYPE_COLD) {
297+
result = pSysfsAccess->bindDevice(resetName);
298+
if (ZE_RESULT_SUCCESS != result) {
299+
NEO::printDebugString(NEO::debugManager.flags.PrintDebugMessages.get(), stderr, "Error@ %s(): Failed to bind the device to the kernel driver and returning error:0x%x \n", __FUNCTION__, result);
300+
return result;
301+
}
299302
}
300303

301304
return pLinuxSysmanImp->initDevice();

level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2023 Intel Corporation
2+
* Copyright (C) 2020-2024 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -805,6 +805,22 @@ TEST_F(SysmanGlobalOperationsFixture, GivenForceTrueWhenCallingResetThenSuccessI
805805
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
806806
}
807807

808+
TEST_F(SysmanGlobalOperationsFixture, GivenPermissionDeniedWhenCallingGetDeviceStateThenZeResultErrorInsufficientPermissionsIsReturned) {
809+
pSysfsAccess->isRootSet = false;
810+
ze_result_t result = zesDeviceReset(device, true);
811+
EXPECT_EQ(ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS, result);
812+
}
813+
814+
TEST_F(SysmanGlobalOperationsFixture, GivenDeviceInUseWhenCallingResetThenZeResultErrorHandleObjectInUseIsReturned) {
815+
816+
pProcfsAccess->ourDevicePid = pProcfsAccess->extraPid;
817+
pProcfsAccess->ourDeviceFd = pProcfsAccess->extraFd;
818+
pProcfsAccess->mockListProcessCall.push_back(DEVICE_IN_USE);
819+
pProcfsAccess->isRepeated.push_back(true);
820+
ze_result_t result = zesDeviceReset(device, false);
821+
EXPECT_EQ(ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE, result);
822+
}
823+
808824
TEST_F(SysmanGlobalOperationsIntegratedFixture, GivenPermissionDeniedWhenCallingGetDeviceStateThenZeResultErrorInsufficientPermissionsIsReturned) {
809825
pSysfsAccess->isRootSet = false;
810826
ze_result_t result = zesDeviceReset(device, true);

0 commit comments

Comments
 (0)