mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-27 07:44:16 +08:00
fix(sysman): Replace normal pointers with smart pointers (14/n)
Replacing normal pointers by smart pointers in performance module of L0 sysman. Related-To: LOCI-2810 Signed-off-by: Singh, Prasoon <prasoon.singh@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
26a2a2829e
commit
531779ffaf
@@ -31,9 +31,9 @@ bool LinuxPerformanceImp::isPerformanceSupported(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OsPerformance *OsPerformance::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId, zes_engine_type_flag_t domain) {
|
||||
LinuxPerformanceImp *pLinuxPerformanceImp = new LinuxPerformanceImp(pOsSysman, onSubdevice, subdeviceId, domain);
|
||||
return static_cast<OsPerformance *>(pLinuxPerformanceImp);
|
||||
std::unique_ptr<OsPerformance> OsPerformance::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId, zes_engine_type_flag_t domain) {
|
||||
std::unique_ptr<LinuxPerformanceImp> pLinuxPerformanceImp = std::make_unique<LinuxPerformanceImp>(pOsSysman, onSubdevice, subdeviceId, domain);
|
||||
return pLinuxPerformanceImp;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -212,9 +212,9 @@ LinuxPerformanceImp::LinuxPerformanceImp(OsSysman *pOsSysman, ze_bool_t onSubdev
|
||||
init();
|
||||
}
|
||||
|
||||
OsPerformance *OsPerformance::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId, zes_engine_type_flag_t domain) {
|
||||
LinuxPerformanceImp *pLinuxPerformanceImp = new LinuxPerformanceImp(pOsSysman, onSubdevice, subdeviceId, domain);
|
||||
return static_cast<OsPerformance *>(pLinuxPerformanceImp);
|
||||
std::unique_ptr<OsPerformance> OsPerformance::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId, zes_engine_type_flag_t domain) {
|
||||
std::unique_ptr<LinuxPerformanceImp> pLinuxPerformanceImp = std::make_unique<LinuxPerformanceImp>(pOsSysman, onSubdevice, subdeviceId, domain);
|
||||
return pLinuxPerformanceImp;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
* Copyright (C) 2021-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "level_zero/tools/source/sysman/os_sysman.h"
|
||||
#include <level_zero/zes_api.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class OsPerformance {
|
||||
@@ -20,7 +22,7 @@ class OsPerformance {
|
||||
|
||||
virtual bool isPerformanceSupported(void) = 0;
|
||||
|
||||
static OsPerformance *create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId, zes_engine_type_flag_t domain);
|
||||
static std::unique_ptr<OsPerformance> create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId, zes_engine_type_flag_t domain);
|
||||
virtual ~OsPerformance() {}
|
||||
};
|
||||
|
||||
|
||||
@@ -16,21 +16,13 @@
|
||||
namespace L0 {
|
||||
|
||||
PerformanceHandleContext::~PerformanceHandleContext() {
|
||||
for (auto &pPerformance : handleList) {
|
||||
if (pPerformance) {
|
||||
delete pPerformance;
|
||||
pPerformance = nullptr;
|
||||
}
|
||||
handleList.pop_back();
|
||||
}
|
||||
handleList.clear();
|
||||
}
|
||||
|
||||
void PerformanceHandleContext::createHandle(ze_device_handle_t deviceHandle, zes_engine_type_flag_t domain) {
|
||||
Performance *pPerformance = new PerformanceImp(pOsSysman, deviceHandle, domain);
|
||||
std::unique_ptr<Performance> pPerformance = std::make_unique<PerformanceImp>(pOsSysman, deviceHandle, domain);
|
||||
if (pPerformance->isPerformanceEnabled == true) {
|
||||
handleList.push_back(pPerformance);
|
||||
} else {
|
||||
delete pPerformance;
|
||||
handleList.push_back(std::move(pPerformance));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2022 Intel Corporation
|
||||
* Copyright (C) 2021-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -44,7 +44,7 @@ struct PerformanceHandleContext {
|
||||
ze_result_t performanceGet(uint32_t *pCount, zes_perf_handle_t *phPerformance);
|
||||
|
||||
OsSysman *pOsSysman = nullptr;
|
||||
std::vector<Performance *> handleList = {};
|
||||
std::vector<std::unique_ptr<Performance>> handleList = {};
|
||||
|
||||
private:
|
||||
void createHandle(ze_device_handle_t deviceHandle, zes_engine_type_flag_t domain);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2022 Intel Corporation
|
||||
* Copyright (C) 2021-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -44,11 +44,6 @@ PerformanceImp::PerformanceImp(OsSysman *pOsSysman, ze_device_handle_t handle, z
|
||||
init();
|
||||
}
|
||||
|
||||
PerformanceImp::~PerformanceImp() {
|
||||
if (pOsPerformance != nullptr) {
|
||||
delete pOsPerformance;
|
||||
pOsPerformance = nullptr;
|
||||
}
|
||||
}
|
||||
PerformanceImp::~PerformanceImp() = default;
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
* Copyright (C) 2021-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -24,7 +24,7 @@ class PerformanceImp : public Performance, NEO::NonCopyableOrMovableClass {
|
||||
PerformanceImp() = delete;
|
||||
PerformanceImp(OsSysman *pOsSysman, ze_device_handle_t handle, zes_engine_type_flag_t domain);
|
||||
~PerformanceImp() override;
|
||||
OsPerformance *pOsPerformance = nullptr;
|
||||
std::unique_ptr<OsPerformance> pOsPerformance;
|
||||
|
||||
void init();
|
||||
|
||||
|
||||
@@ -104,10 +104,10 @@ WddmPerformanceImp::WddmPerformanceImp(OsSysman *pOsSysman, ze_bool_t onSubdevic
|
||||
pKmdSysManager = &pWddmSysmanImp->getKmdSysManager();
|
||||
}
|
||||
|
||||
OsPerformance *OsPerformance::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId,
|
||||
zes_engine_type_flag_t domain) {
|
||||
WddmPerformanceImp *pWddmPerformanceImp = new WddmPerformanceImp(pOsSysman, onSubdevice, subdeviceId, domain);
|
||||
return static_cast<OsPerformance *>(pWddmPerformanceImp);
|
||||
std::unique_ptr<OsPerformance> OsPerformance::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId,
|
||||
zes_engine_type_flag_t domain) {
|
||||
std::unique_ptr<WddmPerformanceImp> pWddmPerformanceImp = std::make_unique<WddmPerformanceImp>(pOsSysman, onSubdevice, subdeviceId, domain);
|
||||
return pWddmPerformanceImp;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -85,27 +85,24 @@ TEST_F(ZesPerformanceFixture, GivenValidOfjectsOfClassPerformanceImpAndPerforman
|
||||
// Check destructors of PerformanceImp and PerformanceHandleContext
|
||||
std::unique_ptr<PerformanceHandleContext> pPerformanceHandleContext1 = std::make_unique<PerformanceHandleContext>(pOsSysman);
|
||||
for (const auto &deviceHandle : deviceHandles) {
|
||||
Performance *pPerformance1 = new PerformanceImp(pOsSysman, deviceHandle, ZES_ENGINE_TYPE_FLAG_MEDIA);
|
||||
pPerformanceHandleContext1->handleList.push_back(pPerformance1);
|
||||
Performance *pPerformance2 = new PerformanceImp(pOsSysman, deviceHandle, ZES_ENGINE_TYPE_FLAG_COMPUTE);
|
||||
pPerformanceHandleContext1->handleList.push_back(pPerformance2);
|
||||
std::unique_ptr<Performance> pPerformance1 = std::make_unique<PerformanceImp>(pOsSysman, deviceHandle, ZES_ENGINE_TYPE_FLAG_MEDIA);
|
||||
pPerformanceHandleContext1->handleList.push_back(std::move(pPerformance1));
|
||||
std::unique_ptr<Performance> pPerformance2 = std::make_unique<PerformanceImp>(pOsSysman, deviceHandle, ZES_ENGINE_TYPE_FLAG_COMPUTE);
|
||||
pPerformanceHandleContext1->handleList.push_back(std::move(pPerformance2));
|
||||
}
|
||||
|
||||
// Check branches of destructors of PerformanceImp and PerformanceHandleContext
|
||||
std::unique_ptr<PerformanceHandleContext> pPerformanceHandleContext2 = std::make_unique<PerformanceHandleContext>(pOsSysman);
|
||||
for (const auto &deviceHandle : deviceHandles) {
|
||||
Performance *pPerformance1 = new PerformanceImp(pOsSysman, deviceHandle, ZES_ENGINE_TYPE_FLAG_MEDIA);
|
||||
pPerformanceHandleContext2->handleList.push_back(pPerformance1);
|
||||
Performance *pPerformance2 = new PerformanceImp(pOsSysman, deviceHandle, ZES_ENGINE_TYPE_FLAG_COMPUTE);
|
||||
pPerformanceHandleContext2->handleList.push_back(pPerformance2);
|
||||
std::unique_ptr<Performance> pPerformance1 = std::make_unique<PerformanceImp>(pOsSysman, deviceHandle, ZES_ENGINE_TYPE_FLAG_MEDIA);
|
||||
pPerformanceHandleContext2->handleList.push_back(std::move(pPerformance1));
|
||||
std::unique_ptr<Performance> pPerformance2 = std::make_unique<PerformanceImp>(pOsSysman, deviceHandle, ZES_ENGINE_TYPE_FLAG_COMPUTE);
|
||||
pPerformanceHandleContext2->handleList.push_back(std::move(pPerformance2));
|
||||
}
|
||||
|
||||
for (auto &handle : pPerformanceHandleContext2->handleList) {
|
||||
auto pPerformanceImp = static_cast<PerformanceImp *>(handle);
|
||||
delete pPerformanceImp->pOsPerformance;
|
||||
auto pPerformanceImp = static_cast<PerformanceImp *>(handle.get());
|
||||
pPerformanceImp->pOsPerformance = nullptr;
|
||||
delete handle;
|
||||
handle = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,8 @@ class ZesPerformanceFixture : public SysmanMultiDeviceFixture {
|
||||
ptestSysfsAccess = std::make_unique<MockPerformanceSysfsAccess>();
|
||||
pOriginalSysfsAccess = pLinuxSysmanImp->pSysfsAccess;
|
||||
pLinuxSysmanImp->pSysfsAccess = ptestSysfsAccess.get();
|
||||
for (auto &handle : pSysmanDeviceImp->pPerformanceHandleContext->handleList) {
|
||||
delete handle;
|
||||
handle = nullptr;
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.pop_back();
|
||||
}
|
||||
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.clear();
|
||||
uint32_t subDeviceCount = 0;
|
||||
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr);
|
||||
if (subDeviceCount == 0) {
|
||||
@@ -85,11 +82,8 @@ TEST_F(ZesPerformanceFixture, GivenValidSysmanHandleWhenRetrievingPerfThenValidH
|
||||
|
||||
TEST_F(ZesPerformanceFixture, GivenInAnyDomainTypeIfcanReadFailsWhenGettingPerfHandlesThenZeroHandlesAreRetrieved) {
|
||||
ptestSysfsAccess->mockCanReadResult = ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
|
||||
for (auto &handle : pSysmanDeviceImp->pPerformanceHandleContext->handleList) {
|
||||
delete handle;
|
||||
handle = nullptr;
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.pop_back();
|
||||
}
|
||||
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.clear();
|
||||
|
||||
PublicLinuxPerformanceImp *pLinuxPerformanceImp = new PublicLinuxPerformanceImp(pOsSysman, 1, 0u, ZES_ENGINE_TYPE_FLAG_MEDIA);
|
||||
EXPECT_FALSE(pLinuxPerformanceImp->isPerformanceSupported());
|
||||
@@ -108,11 +102,8 @@ TEST_F(ZesPerformanceFixture, GivenInAnyDomainTypeIfcanReadFailsWhenGettingPerfH
|
||||
|
||||
TEST_F(ZesPerformanceFixture, GivenInAnyDomainTypeIfSysfsReadForMediaAndComputeScaleFailsWhileGettingPerfHandlesThenZeroHandlesAreRetrieved) {
|
||||
ptestSysfsAccess->mockReadResult = ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
|
||||
for (auto &handle : pSysmanDeviceImp->pPerformanceHandleContext->handleList) {
|
||||
delete handle;
|
||||
handle = nullptr;
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.pop_back();
|
||||
}
|
||||
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.clear();
|
||||
|
||||
PublicLinuxPerformanceImp *pLinuxPerformanceImp = new PublicLinuxPerformanceImp(pOsSysman, 1, 0u, ZES_ENGINE_TYPE_FLAG_MEDIA);
|
||||
EXPECT_FALSE(pLinuxPerformanceImp->isPerformanceSupported());
|
||||
@@ -126,11 +117,8 @@ TEST_F(ZesPerformanceFixture, GivenInAnyDomainTypeIfSysfsReadForMediaAndComputeS
|
||||
}
|
||||
|
||||
TEST_F(ZesPerformanceFixture, GivenInAnyDomainTypeIfMediaAndBaseFreqFactorSysfsNodesAreAbsentWhenGettingPerfHandlesThenZeroHandlesAreRetrieved) {
|
||||
for (auto &handle : pSysmanDeviceImp->pPerformanceHandleContext->handleList) {
|
||||
delete handle;
|
||||
handle = nullptr;
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.pop_back();
|
||||
}
|
||||
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.clear();
|
||||
ptestSysfsAccess->mockReadResult = ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
PublicLinuxPerformanceImp *pLinuxPerformanceImp = new PublicLinuxPerformanceImp(pOsSysman, 1, 0u, ZES_ENGINE_TYPE_FLAG_MEDIA);
|
||||
EXPECT_FALSE(pLinuxPerformanceImp->isPerformanceSupported());
|
||||
@@ -174,11 +162,8 @@ TEST_F(ZesPerformanceFixture, GivenValidPerfHandleWhenGettingConfigThenSuccessIs
|
||||
}
|
||||
|
||||
TEST_F(ZesPerformanceFixture, GivenValidPerfHandlesWhenInvalidMultiplierValuesAreReturnedBySysfsInterfaceThenUnknownErrorIsReturned) {
|
||||
for (auto &handle : pSysmanDeviceImp->pPerformanceHandleContext->handleList) {
|
||||
delete handle;
|
||||
handle = nullptr;
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.pop_back();
|
||||
}
|
||||
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.clear();
|
||||
ptestSysfsAccess->isReturnUnknownFailure = true;
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->init(deviceHandles, device);
|
||||
auto handles = getPerfHandles(mockHandleCount);
|
||||
@@ -189,11 +174,8 @@ TEST_F(ZesPerformanceFixture, GivenValidPerfHandlesWhenInvalidMultiplierValuesAr
|
||||
}
|
||||
|
||||
TEST_F(ZesPerformanceFixture, GivenValidPerfHandlesWhenBaseAndMediaFreqFactorNodesAreAbsentThenUnsupportedFeatureIsReturned) {
|
||||
for (auto &handle : pSysmanDeviceImp->pPerformanceHandleContext->handleList) {
|
||||
delete handle;
|
||||
handle = nullptr;
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.pop_back();
|
||||
}
|
||||
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.clear();
|
||||
ptestSysfsAccess->isMediaBaseFailure = true;
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->init(deviceHandles, device);
|
||||
auto handles = getPerfHandles(mockHandleCount);
|
||||
@@ -331,11 +313,8 @@ TEST_F(ZesPerformanceFixture, GivenValidPerfHandlesButSysfsReadsFailAtDifferentB
|
||||
|
||||
TEST_F(ZesPerformanceFixture, GivenValidOfjectsOfClassPerformanceImpAndPerformanceHandleContextThenDuringObjectReleaseCheckDestructorBranches) {
|
||||
for (auto &handle : pSysmanDeviceImp->pPerformanceHandleContext->handleList) {
|
||||
auto pPerformanceImp = static_cast<PerformanceImp *>(handle);
|
||||
delete pPerformanceImp->pOsPerformance;
|
||||
auto pPerformanceImp = static_cast<PerformanceImp *>(handle.get());
|
||||
pPerformanceImp->pOsPerformance = nullptr;
|
||||
delete handle;
|
||||
handle = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,9 +35,6 @@ class SysmanDevicePerformanceFixture : public SysmanDeviceFixture {
|
||||
pOriginalKmdSysManager = pWddmSysmanImp->pKmdSysManager;
|
||||
pWddmSysmanImp->pKmdSysManager = pKmdSysManager.get();
|
||||
|
||||
for (auto handle : pSysmanDeviceImp->pPerformanceHandleContext->handleList) {
|
||||
delete handle;
|
||||
}
|
||||
pSysmanDeviceImp->pPerformanceHandleContext->handleList.clear();
|
||||
uint32_t subDeviceCount = 0;
|
||||
std::vector<ze_device_handle_t> deviceHandles;
|
||||
|
||||
Reference in New Issue
Block a user