refactor: decouple ClosCacheReservation from Drm

The dependency towards `Drm` is unnecessary and only makes testing more
difficult. Instead, dependency towards `IoctlHelper` alone only is
sufficient.

Related-To: NEO-10158
Signed-off-by: Maciej Bielski <maciej.bielski@intel.com>
This commit is contained in:
Maciej Bielski
2024-07-30 17:53:09 +00:00
committed by Compute-Runtime-Automation
parent 1f79f867e6
commit 790bb84841
10 changed files with 32 additions and 34 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2022 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -16,14 +16,14 @@
namespace NEO {
class Drm;
class IoctlHelper;
struct CacheInfo {
CacheInfo(Drm &drm, size_t maxReservationCacheSize, uint32_t maxReservationNumCacheRegions, uint16_t maxReservationNumWays)
CacheInfo(IoctlHelper &ioctlHelper, size_t maxReservationCacheSize, uint32_t maxReservationNumCacheRegions, uint16_t maxReservationNumWays)
: maxReservationCacheSize(maxReservationCacheSize),
maxReservationNumCacheRegions(maxReservationNumCacheRegions),
maxReservationNumWays(maxReservationNumWays),
cacheReserve(drm) {
cacheReserve{ioctlHelper} {
}
MOCKABLE_VIRTUAL ~CacheInfo();

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -7,9 +7,7 @@
#include "shared/source/os_interface/linux/clos_cache.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/common_types.h"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/linux/ioctl_helper.h"
#include <cerrno>
@@ -39,15 +37,15 @@ CacheRegion ClosCacheReservation::freeCache(CacheLevel cacheLevel, CacheRegion c
}
CacheRegion ClosCacheReservation::allocEntry() {
return drm.getIoctlHelper()->closAlloc();
return ioctlHelper.closAlloc();
}
CacheRegion ClosCacheReservation::freeEntry(CacheRegion closIndex) {
return drm.getIoctlHelper()->closFree(closIndex);
return ioctlHelper.closFree(closIndex);
}
uint16_t ClosCacheReservation::allocCacheWay(CacheRegion closIndex, CacheLevel cacheLevel, uint16_t numWays) {
return drm.getIoctlHelper()->closAllocWays(closIndex, static_cast<uint16_t>(cacheLevel), numWays);
return ioctlHelper.closAllocWays(closIndex, static_cast<uint16_t>(cacheLevel), numWays);
}
} // namespace NEO

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2022 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -12,13 +12,13 @@
namespace NEO {
class Drm;
class IoctlHelper;
enum class CacheLevel : uint16_t;
enum class CacheRegion : uint16_t;
class ClosCacheReservation {
public:
ClosCacheReservation(Drm &drm) : drm(drm) {}
ClosCacheReservation(IoctlHelper &ioctlHelper) : ioctlHelper{ioctlHelper} {}
CacheRegion reserveCache(CacheLevel cacheLevel, uint16_t numWays);
CacheRegion freeCache(CacheLevel cacheLevel, CacheRegion closIndex);
@@ -28,7 +28,7 @@ class ClosCacheReservation {
CacheRegion freeEntry(CacheRegion closIndex);
uint16_t allocCacheWay(CacheRegion closIndex, CacheLevel cacheLevel, uint16_t numWays);
Drm &drm;
IoctlHelper &ioctlHelper;
};
} // namespace NEO

View File

@@ -979,7 +979,7 @@ void Drm::setupCacheInfo(const HardwareInfo &hwInfo) {
auto &gfxCoreHelper = rootDeviceEnvironment.getHelper<GfxCoreHelper>();
if (debugManager.flags.ClosEnabled.get() == 0 || gfxCoreHelper.getNumCacheRegions() == 0) {
this->cacheInfo.reset(new CacheInfo(*this, 0, 0, 0));
this->cacheInfo.reset(new CacheInfo{*ioctlHelper, 0, 0, 0});
return;
}
@@ -993,7 +993,7 @@ void Drm::setupCacheInfo(const HardwareInfo &hwInfo) {
const size_t maxReservationCacheSize = (totalCacheSize * maxReservationNumWays) / maxNumWays;
const uint32_t maxReservationNumCacheRegions = gfxCoreHelper.getNumCacheRegions() - 1;
this->cacheInfo.reset(new CacheInfo(*this, maxReservationCacheSize, maxReservationNumCacheRegions, maxReservationNumWays));
this->cacheInfo.reset(new CacheInfo(*ioctlHelper, maxReservationCacheSize, maxReservationNumCacheRegions, maxReservationNumWays));
}
void Drm::getPrelimVersion(std::string &prelimVersion) {