mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-24 21:18:24 +08:00
Remove cache info base class
There is only one implementation of said class and we don't even adhere to the interface it provides. Signed-off-by: Daniel Chabrowski <daniel.chabrowski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
2d92379fe8
commit
4d4ccfd128
@@ -8,7 +8,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/allocator_helper.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cache_info.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cache_info_impl.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cache_info.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/clos_cache.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/clos_cache.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/clos_helper.h
|
||||
|
||||
73
shared/source/os_interface/linux/cache_info.cpp
Normal file
73
shared/source/os_interface/linux/cache_info.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/linux/cache_info.h"
|
||||
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
CacheInfo::~CacheInfo() {
|
||||
for (auto const &cacheRegion : cacheRegionsReserved) {
|
||||
cacheReserve.freeCache(CacheLevel::Level3, cacheRegion.first);
|
||||
}
|
||||
cacheRegionsReserved.clear();
|
||||
}
|
||||
|
||||
CacheRegion CacheInfo::reserveRegion(size_t cacheReservationSize) {
|
||||
uint16_t numWays = (maxReservationNumWays * cacheReservationSize) / maxReservationCacheSize;
|
||||
if (DebugManager.flags.ClosNumCacheWays.get() != -1) {
|
||||
numWays = DebugManager.flags.ClosNumCacheWays.get();
|
||||
cacheReservationSize = (numWays * maxReservationCacheSize) / maxReservationNumWays;
|
||||
}
|
||||
auto regionIndex = cacheReserve.reserveCache(CacheLevel::Level3, numWays);
|
||||
if (regionIndex == CacheRegion::None) {
|
||||
return CacheRegion::None;
|
||||
}
|
||||
cacheRegionsReserved.insert({regionIndex, cacheReservationSize});
|
||||
|
||||
return regionIndex;
|
||||
}
|
||||
|
||||
CacheRegion CacheInfo::freeRegion(CacheRegion regionIndex) {
|
||||
auto search = cacheRegionsReserved.find(regionIndex);
|
||||
if (search != cacheRegionsReserved.end()) {
|
||||
cacheRegionsReserved.erase(search);
|
||||
return cacheReserve.freeCache(CacheLevel::Level3, regionIndex);
|
||||
}
|
||||
return CacheRegion::None;
|
||||
}
|
||||
|
||||
bool CacheInfo::isRegionReserved(CacheRegion regionIndex, [[maybe_unused]] size_t regionSize) const {
|
||||
auto search = cacheRegionsReserved.find(regionIndex);
|
||||
if (search != cacheRegionsReserved.end()) {
|
||||
if (DebugManager.flags.ClosNumCacheWays.get() != -1) {
|
||||
auto numWays = DebugManager.flags.ClosNumCacheWays.get();
|
||||
regionSize = (numWays * maxReservationCacheSize) / maxReservationNumWays;
|
||||
}
|
||||
DEBUG_BREAK_IF(search->second != regionSize);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CacheInfo::getRegion(size_t regionSize, CacheRegion regionIndex) {
|
||||
if (regionIndex == CacheRegion::Default) {
|
||||
return true;
|
||||
}
|
||||
if (!isRegionReserved(regionIndex, regionSize)) {
|
||||
auto regionIdx = reserveRegion(regionSize);
|
||||
if (regionIdx == CacheRegion::None) {
|
||||
return false;
|
||||
}
|
||||
DEBUG_BREAK_IF(regionIdx != regionIndex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
* Copyright (C) 2021-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -7,8 +7,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/source/os_interface/linux/clos_cache.h"
|
||||
#include "shared/source/utilities/spinlock.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
@@ -27,13 +31,66 @@ enum class CacheRegion : uint16_t {
|
||||
None = 0xFFFF
|
||||
};
|
||||
|
||||
struct CacheInfo {
|
||||
CacheInfo() = default;
|
||||
virtual ~CacheInfo() = 0;
|
||||
|
||||
virtual bool getCacheRegion(size_t regionSize, CacheRegion regionIndex) = 0;
|
||||
enum class CacheLevel : uint16_t {
|
||||
Default = 0,
|
||||
Level3 = 3
|
||||
};
|
||||
|
||||
inline CacheInfo::~CacheInfo(){};
|
||||
class Drm;
|
||||
|
||||
struct CacheInfo {
|
||||
CacheInfo(Drm &drm, size_t maxReservationCacheSize, uint32_t maxReservationNumCacheRegions, uint16_t maxReservationNumWays)
|
||||
: maxReservationCacheSize(maxReservationCacheSize),
|
||||
maxReservationNumCacheRegions(maxReservationNumCacheRegions),
|
||||
maxReservationNumWays(maxReservationNumWays),
|
||||
cacheReserve(drm) {
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL ~CacheInfo();
|
||||
|
||||
CacheInfo(const CacheInfo &) = delete;
|
||||
CacheInfo &operator=(const CacheInfo &) = delete;
|
||||
|
||||
size_t getMaxReservationCacheSize() const {
|
||||
return maxReservationCacheSize;
|
||||
}
|
||||
|
||||
size_t getMaxReservationNumCacheRegions() const {
|
||||
return maxReservationNumCacheRegions;
|
||||
}
|
||||
|
||||
size_t getMaxReservationNumWays() const {
|
||||
return maxReservationNumWays;
|
||||
}
|
||||
|
||||
CacheRegion reserveCacheRegion(size_t cacheReservationSize) {
|
||||
std::unique_lock<SpinLock> lock{mtx};
|
||||
return reserveRegion(cacheReservationSize);
|
||||
}
|
||||
|
||||
CacheRegion freeCacheRegion(CacheRegion regionIndex) {
|
||||
std::unique_lock<SpinLock> lock{mtx};
|
||||
return freeRegion(regionIndex);
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL bool getCacheRegion(size_t regionSize, CacheRegion regionIndex) {
|
||||
std::unique_lock<SpinLock> lock{mtx};
|
||||
return getRegion(regionSize, regionIndex);
|
||||
}
|
||||
|
||||
protected:
|
||||
CacheRegion reserveRegion(size_t cacheReservationSize);
|
||||
CacheRegion freeRegion(CacheRegion regionIndex);
|
||||
bool isRegionReserved(CacheRegion regionIndex, [[maybe_unused]] size_t regionSize) const;
|
||||
bool getRegion(size_t regionSize, CacheRegion regionIndex);
|
||||
|
||||
protected:
|
||||
size_t maxReservationCacheSize;
|
||||
uint32_t maxReservationNumCacheRegions;
|
||||
uint16_t maxReservationNumWays;
|
||||
ClosCacheReservation cacheReserve;
|
||||
std::unordered_map<CacheRegion, size_t> cacheRegionsReserved;
|
||||
SpinLock mtx;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
#include "shared/source/os_interface/linux/cache_info.h"
|
||||
#include "shared/source/os_interface/linux/clos_cache.h"
|
||||
#include "shared/source/utilities/spinlock.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class Drm;
|
||||
|
||||
enum class CacheLevel : uint16_t {
|
||||
Default = 0,
|
||||
Level3 = 3
|
||||
};
|
||||
|
||||
class CacheInfoImpl : public CacheInfo {
|
||||
public:
|
||||
CacheInfoImpl(Drm &drm, size_t maxReservationCacheSize, uint32_t maxReservationNumCacheRegions, uint16_t maxReservationNumWays)
|
||||
: maxReservationCacheSize(maxReservationCacheSize), maxReservationNumCacheRegions(maxReservationNumCacheRegions), maxReservationNumWays(maxReservationNumWays), cacheReserve(drm) {
|
||||
}
|
||||
|
||||
~CacheInfoImpl() override {
|
||||
for (auto const &cacheRegion : cacheRegionsReserved) {
|
||||
cacheReserve.freeCache(CacheLevel::Level3, cacheRegion.first);
|
||||
}
|
||||
cacheRegionsReserved.clear();
|
||||
}
|
||||
|
||||
size_t getMaxReservationCacheSize() const {
|
||||
return maxReservationCacheSize;
|
||||
}
|
||||
|
||||
size_t getMaxReservationNumCacheRegions() const {
|
||||
return maxReservationNumCacheRegions;
|
||||
}
|
||||
|
||||
size_t getMaxReservationNumWays() const {
|
||||
return maxReservationNumWays;
|
||||
}
|
||||
|
||||
CacheRegion reserveCacheRegion(size_t cacheReservationSize) {
|
||||
std::unique_lock<SpinLock> lock{mtx};
|
||||
return reserveRegion(cacheReservationSize);
|
||||
}
|
||||
|
||||
CacheRegion freeCacheRegion(CacheRegion regionIndex) {
|
||||
std::unique_lock<SpinLock> lock{mtx};
|
||||
return freeRegion(regionIndex);
|
||||
}
|
||||
|
||||
bool getCacheRegion(size_t regionSize, CacheRegion regionIndex) override {
|
||||
std::unique_lock<SpinLock> lock{mtx};
|
||||
return getRegion(regionSize, regionIndex);
|
||||
}
|
||||
|
||||
protected:
|
||||
CacheRegion reserveRegion(size_t cacheReservationSize) {
|
||||
uint16_t numWays = (maxReservationNumWays * cacheReservationSize) / maxReservationCacheSize;
|
||||
if (DebugManager.flags.ClosNumCacheWays.get() != -1) {
|
||||
numWays = DebugManager.flags.ClosNumCacheWays.get();
|
||||
cacheReservationSize = (numWays * maxReservationCacheSize) / maxReservationNumWays;
|
||||
}
|
||||
auto regionIndex = cacheReserve.reserveCache(CacheLevel::Level3, numWays);
|
||||
if (regionIndex == CacheRegion::None) {
|
||||
return CacheRegion::None;
|
||||
}
|
||||
cacheRegionsReserved.insert({regionIndex, cacheReservationSize});
|
||||
|
||||
return regionIndex;
|
||||
}
|
||||
|
||||
CacheRegion freeRegion(CacheRegion regionIndex) {
|
||||
auto search = cacheRegionsReserved.find(regionIndex);
|
||||
if (search != cacheRegionsReserved.end()) {
|
||||
cacheRegionsReserved.erase(search);
|
||||
return cacheReserve.freeCache(CacheLevel::Level3, regionIndex);
|
||||
}
|
||||
return CacheRegion::None;
|
||||
}
|
||||
|
||||
bool isRegionReserved(CacheRegion regionIndex, [[maybe_unused]] size_t regionSize) const {
|
||||
auto search = cacheRegionsReserved.find(regionIndex);
|
||||
if (search != cacheRegionsReserved.end()) {
|
||||
if (DebugManager.flags.ClosNumCacheWays.get() != -1) {
|
||||
auto numWays = DebugManager.flags.ClosNumCacheWays.get();
|
||||
regionSize = (numWays * maxReservationCacheSize) / maxReservationNumWays;
|
||||
}
|
||||
DEBUG_BREAK_IF(search->second != regionSize);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool getRegion(size_t regionSize, CacheRegion regionIndex) {
|
||||
if (regionIndex == CacheRegion::Default) {
|
||||
return true;
|
||||
}
|
||||
if (!isRegionReserved(regionIndex, regionSize)) {
|
||||
auto regionIdx = reserveRegion(regionSize);
|
||||
if (regionIdx == CacheRegion::None) {
|
||||
return false;
|
||||
}
|
||||
DEBUG_BREAK_IF(regionIdx != regionIndex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t maxReservationCacheSize;
|
||||
uint32_t maxReservationNumCacheRegions;
|
||||
uint16_t maxReservationNumWays;
|
||||
ClosCacheReservation cacheReserve;
|
||||
std::unordered_map<CacheRegion, size_t> cacheRegionsReserved;
|
||||
SpinLock mtx;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "shared/source/os_interface/linux/drm_allocation.h"
|
||||
|
||||
#include "shared/source/memory_manager/residency.h"
|
||||
#include "shared/source/os_interface/linux/cache_info_impl.h"
|
||||
#include "shared/source/os_interface/linux/cache_info.h"
|
||||
#include "shared/source/os_interface/linux/drm_buffer_object.h"
|
||||
#include "shared/source/os_interface/linux/drm_memory_manager.h"
|
||||
#include "shared/source/os_interface/linux/ioctl_helper.h"
|
||||
@@ -53,7 +53,7 @@ bool DrmAllocation::setCacheRegion(Drm *drm, CacheRegion regionIndex) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto cacheInfo = static_cast<CacheInfoImpl *>(drm->getCacheInfo());
|
||||
auto cacheInfo = drm->getCacheInfo();
|
||||
if (cacheInfo == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "shared/source/helpers/hw_info.h"
|
||||
#include "shared/source/helpers/ptr_math.h"
|
||||
#include "shared/source/os_interface/driver_info.h"
|
||||
#include "shared/source/os_interface/linux/cache_info_impl.h"
|
||||
#include "shared/source/os_interface/linux/cache_info.h"
|
||||
#include "shared/source/os_interface/linux/clos_helper.h"
|
||||
#include "shared/source/os_interface/linux/drm_engine_mapper.h"
|
||||
#include "shared/source/os_interface/linux/drm_gem_close_worker.h"
|
||||
@@ -973,7 +973,7 @@ void Drm::setupCacheInfo(const HardwareInfo &hwInfo) {
|
||||
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
|
||||
|
||||
if (DebugManager.flags.ClosEnabled.get() == 0 || hwHelper.getNumCacheRegions() == 0) {
|
||||
this->cacheInfo.reset(new CacheInfoImpl(*this, 0, 0, 0));
|
||||
this->cacheInfo.reset(new CacheInfo(*this, 0, 0, 0));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -987,7 +987,7 @@ void Drm::setupCacheInfo(const HardwareInfo &hwInfo) {
|
||||
const size_t maxReservationCacheSize = (totalCacheSize * maxReservationNumWays) / maxNumWays;
|
||||
const uint32_t maxReservationNumCacheRegions = hwHelper.getNumCacheRegions() - 1;
|
||||
|
||||
this->cacheInfo.reset(new CacheInfoImpl(*this, maxReservationCacheSize, maxReservationNumCacheRegions, maxReservationNumWays));
|
||||
this->cacheInfo.reset(new CacheInfo(*this, maxReservationCacheSize, maxReservationNumCacheRegions, maxReservationNumWays));
|
||||
}
|
||||
|
||||
void Drm::getPrelimVersion(std::string &prelimVersion) {
|
||||
|
||||
Reference in New Issue
Block a user