mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-22 10:17:01 +08:00
Prepare cache setup and reservation logic to be extended w.r.t other cache-levels. Conceptually this change is like adding a switch-statement, in several places, in which existing code makes a single (and only) case. This is caused by splitting larger development to ease the review. Further cases will be added in following steps. Such approach sometimes creates code which may seem redundant but it is meant to simplify plugging following extensions in an easy way. Related-To: NEO-12837 Signed-off-by: Maciej Bielski <maciej.bielski@intel.com>
85 lines
2.9 KiB
C++
85 lines
2.9 KiB
C++
/*
|
|
* Copyright (C) 2022-2025 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/common_types.h"
|
|
#include "shared/source/helpers/debug_helpers.h"
|
|
|
|
namespace NEO {
|
|
|
|
CacheInfo::~CacheInfo() {
|
|
// skip the defaultRegion
|
|
constexpr auto regionStart{toUnderlying(CacheRegion::region1)};
|
|
constexpr auto regionEnd{toUnderlying(CacheRegion::count)};
|
|
|
|
for (auto regionIndex{regionStart}; regionIndex < regionEnd; ++regionIndex) {
|
|
if (reservedCacheRegionsSize[regionIndex]) {
|
|
cacheReserve.freeCache(CacheLevel::level3, toCacheRegion(regionIndex));
|
|
reservedCacheRegionsSize[regionIndex] = 0u;
|
|
}
|
|
}
|
|
}
|
|
|
|
CacheRegion CacheInfo::reserveRegion(size_t cacheReservationSize) {
|
|
auto &limits{l3ReservationLimits};
|
|
|
|
uint16_t numWays = (limits.maxNumWays * cacheReservationSize) / limits.maxSize;
|
|
if (debugManager.flags.ClosNumCacheWays.get() != -1) {
|
|
numWays = debugManager.flags.ClosNumCacheWays.get();
|
|
cacheReservationSize = (numWays * limits.maxSize) / limits.maxNumWays;
|
|
}
|
|
auto regionIndex = cacheReserve.reserveCache(CacheLevel::level3, numWays);
|
|
if (regionIndex == CacheRegion::none) {
|
|
return CacheRegion::none;
|
|
}
|
|
DEBUG_BREAK_IF(regionIndex == CacheRegion::defaultRegion);
|
|
DEBUG_BREAK_IF(regionIndex >= CacheRegion::count);
|
|
reservedCacheRegionsSize[toUnderlying(regionIndex)] = cacheReservationSize;
|
|
|
|
return regionIndex;
|
|
}
|
|
|
|
CacheRegion CacheInfo::freeRegion(CacheRegion regionIndex) {
|
|
if (regionIndex < CacheRegion::count && reservedCacheRegionsSize[toUnderlying(regionIndex)] > 0u) {
|
|
reservedCacheRegionsSize[toUnderlying(regionIndex)] = 0u;
|
|
return cacheReserve.freeCache(CacheLevel::level3, regionIndex);
|
|
}
|
|
return CacheRegion::none;
|
|
}
|
|
|
|
bool CacheInfo::isRegionReserved(CacheRegion regionIndex, [[maybe_unused]] size_t expectedRegionSize) const {
|
|
auto &limits{l3ReservationLimits};
|
|
|
|
if (regionIndex < CacheRegion::count && reservedCacheRegionsSize[toUnderlying(regionIndex)]) {
|
|
if (debugManager.flags.ClosNumCacheWays.get() != -1) {
|
|
auto numWays = debugManager.flags.ClosNumCacheWays.get();
|
|
expectedRegionSize = (numWays * limits.maxSize) / limits.maxNumWays;
|
|
}
|
|
DEBUG_BREAK_IF(expectedRegionSize != reservedCacheRegionsSize[toUnderlying(regionIndex)]);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool CacheInfo::getRegion(size_t regionSize, CacheRegion regionIndex) {
|
|
if (regionIndex == CacheRegion::defaultRegion) {
|
|
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
|