gem5 v24.0.0.0
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):
55 BasePartitioningPolicy(params), cacheSize(params.cache_size),
56 blkSize(params.blk_size), partitionIDs(params.partition_ids),
57 capacities(params.capacities)
58{
59 // check if ids and capacities vectors are the same length
60 if (this->partitionIDs.size() != this->capacities.size()) {
61 fatal("MaxCapacity Partitioning Policy configuration invalid: ids and "
62 "capacities arrays are not equal lengths");
63 }
64
65 // calculate total cache block count to use when creating allocation maps
66 const uint64_t total_block_cnt = this->cacheSize / this->blkSize;
67
68 // check allocations and create map
69 for (auto i = 0; i < this->partitionIDs.size(); i++) {
70 const uint64_t partition_id = this->partitionIDs[i];
71 const double cap_frac = capacities[i];
72
73 // check Capacity Fraction (cap_frac) is actually a fraction in [0,1]
74 if (!(cap_frac >= 0 && cap_frac <= 1)) {
75 fatal("MaxCapacity Partitioning Policy for PartitionID %d has "
76 "Capacity Fraction %f outside of [0,1] range", partition_id,
77 cap_frac);
78 }
79
80 const uint64_t allocated_block_cnt = cap_frac * total_block_cnt;
81 partitionIdMaxCapacity.emplace(partition_id, allocated_block_cnt);
82
83 DPRINTF(PartitionPolicy, "Configured MaxCapacity Partitioning Policy "
84 "for PartitionID: %d to use portion of size %f (%d cache blocks "
85 "of %d total)\n", partition_id, cap_frac, allocated_block_cnt,
86 total_block_cnt);
87
88 }
89}
90
91void
94 const uint64_t id) const
95{
96 if (// No entries to filter
97 entries.empty() ||
98 // This partition_id is not policed
100 // This partition_id has not yet used the cache
102 // The partition_id usage is below the maximum
104 return;
105
106 // Limit reached, restrict allocation only to blocks owned by
107 // the Partition ID
108 entries.erase(std::remove_if(entries.begin(), entries.end(),
109 [id](ReplaceableEntry *entry) {
110 CacheBlk *blk = static_cast<CacheBlk *>(entry);
111 return blk->getPartitionId() != id;
112 }), entries.end());
113}
114
115void
117{
118 // sanity check current allocation does not exceed its configured maximum
119 assert(partitionIdCurCapacity[partition_id] <=
120 partitionIdMaxCapacity[partition_id]);
121
122 partitionIdCurCapacity[partition_id] += 1;
123}
124
125void
127{
128 // sanity check current allocation will not cause underflow
129 assert(partitionIdCurCapacity[partition_id] > 0);
130
131 partitionIdCurCapacity[partition_id] -= 1;
132}
133
134} // namespace partitioning_policy
135
136} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
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.
const uint64_t blkSize
Cache block size in number of bytes.
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...
std::unordered_map< uint64_t, uint64_t > partitionIdCurCapacity
Map of PartitionIDs and currently allocated blck coutns.
const uint64_t cacheSize
Cache size in number of bytes.
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
Bitfield< 7 > i
Definition misc_types.hh:67
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0