File: cache_info.h

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (94 lines) | stat: -rw-r--r-- 3,118 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (C) 2021-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

#include "shared/source/helpers/common_types.h"
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "shared/source/os_interface/linux/clos_cache.h"
#include "shared/source/utilities/spinlock.h"

#include <array>
#include <cstddef>
#include <cstdint>

namespace NEO {

class IoctlHelper;

struct CacheReservationParameters {
    size_t maxSize{0U};
    uint32_t maxNumRegions{0U};
    uint16_t maxNumWays{0U};
};

struct CacheInfo : NEO::NonCopyableAndNonMovableClass {
    CacheInfo(IoctlHelper &ioctlHelper, const CacheReservationParameters l2Limits, const CacheReservationParameters l3Limits)
        : l2ReservationLimits{l2Limits},
          l3ReservationLimits{l3Limits},
          cacheReserve{ioctlHelper} {

        reservedCacheRegionsSize.fill(0UL);
    }

    MOCKABLE_VIRTUAL ~CacheInfo();

    size_t getMaxReservationCacheSize(CacheLevel cacheLevel) const {
        return getLimitsForCacheLevel(cacheLevel).maxSize;
    }

    size_t getMaxReservationNumCacheRegions(CacheLevel cacheLevel) const {
        return getLimitsForCacheLevel(cacheLevel).maxNumRegions;
    }

    size_t getMaxReservationNumWays(CacheLevel cacheLevel) const {
        return getLimitsForCacheLevel(cacheLevel).maxNumWays;
    }

    CacheRegion reserveCacheRegion(CacheLevel cacheLevel, size_t cacheReservationSize) {
        std::unique_lock<SpinLock> lock{mtx};
        return reserveRegion(cacheLevel, cacheReservationSize);
    }

    CacheRegion freeCacheRegion(CacheLevel cacheLevel, CacheRegion regionIndex) {
        std::unique_lock<SpinLock> lock{mtx};
        return freeRegion(cacheLevel, regionIndex);
    }

    MOCKABLE_VIRTUAL bool getCacheRegion(size_t regionSize, CacheRegion regionIndex) {
        std::unique_lock<SpinLock> lock{mtx};
        return getRegion(regionSize, regionIndex);
    }

    CacheLevel getLevelForRegion(CacheRegion regionIndex) const {
        DEBUG_BREAK_IF(regionIndex == CacheRegion::defaultRegion);
        DEBUG_BREAK_IF(regionIndex >= CacheRegion::count);
        return (regionIndex == CacheRegion::region3 ? CacheLevel::level2 : CacheLevel::level3);
    }

    CacheLevel getLevelForRegion(uint16_t regionIndex) const {
        return getLevelForRegion(toCacheRegion(regionIndex));
    }

  protected:
    CacheRegion reserveRegion(CacheLevel cacheLevel, size_t cacheReservationSize);
    CacheRegion freeRegion(CacheLevel cacheLevel, CacheRegion regionIndex);
    bool isRegionReserved(CacheRegion regionIndex, [[maybe_unused]] size_t regionSize) const;
    bool getRegion(size_t regionSize, CacheRegion regionIndex);
    const CacheReservationParameters &getLimitsForCacheLevel(CacheLevel cacheLevel) const;

  protected:
    CacheReservationParameters l2ReservationLimits{};
    CacheReservationParameters l3ReservationLimits{};
    ClosCacheReservation cacheReserve;
    std::array<size_t, toUnderlying(CacheRegion::count)> reservedCacheRegionsSize;
    SpinLock mtx;
};

static_assert(NEO::NonCopyableAndNonMovable<CacheInfo>);

} // namespace NEO