gem5 v24.1.0.1
Loading...
Searching...
No Matches
max_capacity_pp.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 ARM Limited
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
39
40#include <algorithm>
41#include <string>
42
43#include "base/logging.hh"
44#include "base/trace.hh"
45#include "params/MaxCapacityPartitioningPolicy.hh"
46
47namespace gem5
48{
49
50namespace partitioning_policy
51{
52
54 (const MaxCapacityPartitioningPolicyParams &params):
56 totalBlockCount(params.cache_size / params.blk_size),
57 partitionIDs(params.partition_ids),
58 capacities(params.capacities)
59{
60 // check if ids and capacities vectors are the same length
61 if (this->partitionIDs.size() != this->capacities.size()) {
62 fatal("MaxCapacity Partitioning Policy configuration invalid: ids and "
63 "capacities arrays are not equal lengths");
64 }
65
66 // check allocations and create map
67 for (auto i = 0; i < this->partitionIDs.size(); i++) {
68 const uint64_t partition_id = this->partitionIDs[i];
69 const double cap_frac = capacities[i];
70
71 // Configure partition
72 configurePartition(partition_id, cap_frac);
73 }
74}
75
76void
78 double cap_frac)
79{
80 // check Capacity Fraction (cap_frac) is actually a fraction in [0,1]
81 panic_if(!(cap_frac >= 0 && cap_frac <= 1),
82 "MaxCapacity Partitioning Policy for PartitionID %d has "
83 "Capacity Fraction %f outside of [0,1] range", partition_id,
84 cap_frac);
85
86 const uint64_t allocated_block_cnt = cap_frac * totalBlockCount;
87 partitionIdMaxCapacity.emplace(partition_id, allocated_block_cnt);
88
89 DPRINTF(PartitionPolicy, "Configured MaxCapacity Partitioning Policy "
90 "for PartitionID: %d to use portion of size %f (%d cache blocks "
91 "of %d total)\n", partition_id, cap_frac, allocated_block_cnt,
93}
94
95void
98 const uint64_t id) const
99{
100 if (// No entries to filter
101 entries.empty() ||
102 // This partition_id is not policed
104 // This partition_id has not yet used the cache
106 // The partition_id usage is below the maximum
108 return;
109
110 // Limit reached, restrict allocation only to blocks owned by
111 // the Partition ID
112 entries.erase(std::remove_if(entries.begin(), entries.end(),
113 [id](ReplaceableEntry *entry) {
114 CacheBlk *blk = static_cast<CacheBlk *>(entry);
115 return blk->getPartitionId() != id;
116 }), entries.end());
117}
118
119void
121{
122 // sanity check current allocation does not exceed its configured maximum
123 assert(partitionIdCurCapacity[partition_id] <=
124 partitionIdMaxCapacity[partition_id]);
125
126 partitionIdCurCapacity[partition_id] += 1;
127}
128
129void
131{
132 // sanity check current allocation will not cause underflow
133 assert(partitionIdCurCapacity[partition_id] > 0);
134
135 partitionIdCurCapacity[partition_id] -= 1;
136}
137
138} // namespace partitioning_policy
139
140} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
A Partitioning Policy is a cache partitioning mechanism that limits the cache block allocations in a ...
Definition base_pp.hh:68
void notifyAcquire(const uint64_t partition_id) override
Notify of acquisition of ownership of a cache line.
void notifyRelease(const uint64_t partition_id) override
Notify of release of ownership of a cache line.
std::unordered_map< uint64_t, uint64_t > partitionIdMaxCapacity
Map of PartitionIDs and maximum allocatable cache block counts; On evictions full partitions are prio...
void configurePartition(uint64_t partition_id, double cap_frac)
Set the maximum capacity (as a fraction) for the provided partition.
std::unordered_map< uint64_t, uint64_t > partitionIdCurCapacity
Map of PartitionIDs and currently allocated blck coutns.
const uint64_t totalBlockCount
Total number of cache blocks.
const std::vector< uint64_t > partitionIDs
Vector of partitionIDs the policy operates on.
MaxCapacityPartitioningPolicy(const MaxCapacityPartitioningPolicyParams &params)
const std::vector< double > capacities
Vector of capacity fractions to enforce on the policied partitionIDs.
void filterByPartition(std::vector< ReplaceableEntry * > &entries, const uint64_t partition_id) const override
Filters the allocatable cache blocks for a memory request based on its PartitionID and policy allocat...
STL vector class.
Definition stl.hh:37
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
Bitfield< 7 > i
Definition misc_types.hh:67
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36

Generated on Mon Jan 13 2025 04:28:38 for gem5 by doxygen 1.9.8