Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 1 | /* |
Daniel | 153a33b | 2018-11-11 15:52:08 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018 Inria |
Stephan Diestelhorst | cb8856f | 2015-03-27 04:56:03 -0400 | [diff] [blame] | 3 | * Copyright (c) 2012-2013, 2015 ARM Limited |
Giacomo Gabrielli | aefe9cc | 2014-01-24 15:29:30 -0600 | [diff] [blame] | 4 | * All rights reserved |
| 5 | * |
| 6 | * The license below extends only to copyright in the software and shall |
| 7 | * not be construed as granting a license to any other intellectual |
| 8 | * property including but not limited to intellectual property relating |
| 9 | * to a hardware implementation of the functionality of the software |
| 10 | * licensed hereunder. You may use the software subject to the license |
| 11 | * terms below provided that you ensure that this notice is replicated |
| 12 | * unmodified and in its entirety in all distributions of the software, |
| 13 | * modified or unmodified, in source code or in binary form. |
| 14 | * |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 15 | * Copyright (c) 2005 The Regents of The University of Michigan |
| 16 | * All rights reserved. |
| 17 | * |
| 18 | * Redistribution and use in source and binary forms, with or without |
| 19 | * modification, are permitted provided that the following conditions are |
| 20 | * met: redistributions of source code must retain the above copyright |
| 21 | * notice, this list of conditions and the following disclaimer; |
| 22 | * redistributions in binary form must reproduce the above copyright |
| 23 | * notice, this list of conditions and the following disclaimer in the |
| 24 | * documentation and/or other materials provided with the distribution; |
| 25 | * neither the name of the copyright holders nor the names of its |
| 26 | * contributors may be used to endorse or promote products derived from |
| 27 | * this software without specific prior written permission. |
| 28 | * |
| 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 32 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 33 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 34 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 35 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 36 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 37 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 38 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 40 | */ |
| 41 | |
| 42 | /** |
| 43 | * @file |
Steve Reinhardt | f655932 | 2006-12-18 21:53:06 -0800 | [diff] [blame] | 44 | * Describes a strided prefetcher. |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 45 | */ |
| 46 | |
Mitch Hayenga | df82a2d | 2014-12-23 09:31:18 -0500 | [diff] [blame] | 47 | #ifndef __MEM_CACHE_PREFETCH_STRIDE_HH__ |
| 48 | #define __MEM_CACHE_PREFETCH_STRIDE_HH__ |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 49 | |
Nikos Nikoleris | 56865ad | 2018-05-03 12:14:41 +0100 | [diff] [blame] | 50 | #include <string> |
Andreas Hansson | 22c0419 | 2015-10-12 04:07:59 -0400 | [diff] [blame] | 51 | #include <unordered_map> |
Daniel | 3a3e172 | 2018-11-13 20:47:51 +0100 | [diff] [blame] | 52 | #include <vector> |
Andreas Hansson | 22c0419 | 2015-10-12 04:07:59 -0400 | [diff] [blame] | 53 | |
Daniel R. Carvalho | 31b3487 | 2019-12-29 14:18:22 +0100 | [diff] [blame] | 54 | #include "base/sat_counter.hh" |
Nikos Nikoleris | 56865ad | 2018-05-03 12:14:41 +0100 | [diff] [blame] | 55 | #include "base/types.hh" |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 56 | #include "mem/cache/prefetch/associative_set.hh" |
Mitch Hayenga | df82a2d | 2014-12-23 09:31:18 -0500 | [diff] [blame] | 57 | #include "mem/cache/prefetch/queued.hh" |
Daniel | 153a33b | 2018-11-11 15:52:08 +0100 | [diff] [blame] | 58 | #include "mem/cache/replacement_policies/replaceable_entry.hh" |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 59 | #include "mem/cache/tags/indexing_policies/set_associative.hh" |
Nikos Nikoleris | 56865ad | 2018-05-03 12:14:41 +0100 | [diff] [blame] | 60 | #include "mem/packet.hh" |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 61 | #include "params/StridePrefetcherHashedSetAssociative.hh" |
Nikos Nikoleris | 56865ad | 2018-05-03 12:14:41 +0100 | [diff] [blame] | 62 | |
Daniel R. Carvalho | 974a47d | 2021-05-09 12:32:07 -0300 | [diff] [blame] | 63 | namespace gem5 |
| 64 | { |
| 65 | |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 66 | class BaseIndexingPolicy; |
Daniel R. Carvalho | 17897bb | 2021-05-06 07:24:06 -0300 | [diff] [blame] | 67 | GEM5_DEPRECATED_NAMESPACE(ReplacementPolicy, replacement_policy); |
| 68 | namespace replacement_policy |
| 69 | { |
Daniel R. Carvalho | 523d42d | 2019-12-28 23:38:21 +0100 | [diff] [blame] | 70 | class Base; |
| 71 | } |
Nikos Nikoleris | 56865ad | 2018-05-03 12:14:41 +0100 | [diff] [blame] | 72 | struct StridePrefetcherParams; |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 73 | |
Daniel R. Carvalho | df72e9d | 2021-05-08 07:32:23 -0300 | [diff] [blame] | 74 | GEM5_DEPRECATED_NAMESPACE(Prefetcher, prefetch); |
| 75 | namespace prefetch |
| 76 | { |
Daniel R. Carvalho | 0be2496 | 2019-12-29 00:45:44 +0100 | [diff] [blame] | 77 | |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 78 | /** |
| 79 | * Override the default set associative to apply a specific hash function |
| 80 | * when extracting a set. |
| 81 | */ |
| 82 | class StridePrefetcherHashedSetAssociative : public SetAssociative |
| 83 | { |
| 84 | protected: |
| 85 | uint32_t extractSet(const Addr addr) const override; |
| 86 | Addr extractTag(const Addr addr) const override; |
| 87 | |
| 88 | public: |
| 89 | StridePrefetcherHashedSetAssociative( |
Gabe Black | 91d83cc | 2020-10-07 06:49:23 -0700 | [diff] [blame] | 90 | const StridePrefetcherHashedSetAssociativeParams &p) |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 91 | : SetAssociative(p) |
| 92 | { |
| 93 | } |
| 94 | ~StridePrefetcherHashedSetAssociative() = default; |
| 95 | }; |
| 96 | |
Daniel R. Carvalho | 0be2496 | 2019-12-29 00:45:44 +0100 | [diff] [blame] | 97 | class Stride : public Queued |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 98 | { |
| 99 | protected: |
Daniel R. Carvalho | 31b3487 | 2019-12-29 14:18:22 +0100 | [diff] [blame] | 100 | /** Initial confidence counter value for the pc tables. */ |
Daniel R. Carvalho | 833a60a | 2019-08-12 09:59:07 +0200 | [diff] [blame] | 101 | const SatCounter8 initConfidence; |
Daniel R. Carvalho | 31b3487 | 2019-12-29 14:18:22 +0100 | [diff] [blame] | 102 | |
| 103 | /** Confidence threshold for prefetch generation. */ |
| 104 | const double threshConf; |
Steve Reinhardt | 89a7fb0 | 2009-02-16 08:56:40 -0800 | [diff] [blame] | 105 | |
Shivani Parekh | 392c1ce | 2020-08-24 11:47:44 -0700 | [diff] [blame] | 106 | const bool useRequestorId; |
Mitch Hayenga | df82a2d | 2014-12-23 09:31:18 -0500 | [diff] [blame] | 107 | |
| 108 | const int degree; |
| 109 | |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 110 | /** |
| 111 | * Information used to create a new PC table. All of them behave equally. |
| 112 | */ |
| 113 | const struct PCTableInfo |
| 114 | { |
| 115 | const int assoc; |
| 116 | const int numEntries; |
Daniel | 153a33b | 2018-11-11 15:52:08 +0100 | [diff] [blame] | 117 | |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 118 | BaseIndexingPolicy* const indexingPolicy; |
Daniel R. Carvalho | 17897bb | 2021-05-06 07:24:06 -0300 | [diff] [blame] | 119 | replacement_policy::Base* const replacementPolicy; |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 120 | |
| 121 | PCTableInfo(int assoc, int num_entries, |
| 122 | BaseIndexingPolicy* indexing_policy, |
Daniel R. Carvalho | 17897bb | 2021-05-06 07:24:06 -0300 | [diff] [blame] | 123 | replacement_policy::Base* repl_policy) |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 124 | : assoc(assoc), numEntries(num_entries), |
Daniel R. Carvalho | 17897bb | 2021-05-06 07:24:06 -0300 | [diff] [blame] | 125 | indexingPolicy(indexing_policy), replacementPolicy(repl_policy) |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 126 | { |
| 127 | } |
| 128 | } pcTableInfo; |
| 129 | |
| 130 | /** Tagged by hashed PCs. */ |
| 131 | struct StrideEntry : public TaggedEntry |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 132 | { |
Daniel R. Carvalho | 833a60a | 2019-08-12 09:59:07 +0200 | [diff] [blame] | 133 | StrideEntry(const SatCounter8& init_confidence); |
Daniel | d7a1db5 | 2018-11-11 17:56:08 +0100 | [diff] [blame] | 134 | |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 135 | void invalidate() override; |
Mitch Hayenga | df82a2d | 2014-12-23 09:31:18 -0500 | [diff] [blame] | 136 | |
Mitch Hayenga | df82a2d | 2014-12-23 09:31:18 -0500 | [diff] [blame] | 137 | Addr lastAddr; |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 138 | int stride; |
Daniel R. Carvalho | 833a60a | 2019-08-12 09:59:07 +0200 | [diff] [blame] | 139 | SatCounter8 confidence; |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 140 | }; |
Daniel R. Carvalho | 2848288 | 2019-12-29 10:14:26 +0100 | [diff] [blame] | 141 | typedef AssociativeSet<StrideEntry> PCTable; |
Daniel | 2b619af | 2018-11-11 16:11:40 +0100 | [diff] [blame] | 142 | std::unordered_map<int, PCTable> pcTables; |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 143 | |
Daniel | 359a2ef | 2018-11-13 20:59:50 +0100 | [diff] [blame] | 144 | /** |
Daniel | 2b619af | 2018-11-11 16:11:40 +0100 | [diff] [blame] | 145 | * Try to find a table of entries for the given context. If none is |
| 146 | * found, a new table is created. |
Daniel | 359a2ef | 2018-11-13 20:59:50 +0100 | [diff] [blame] | 147 | * |
Daniel | 2b619af | 2018-11-11 16:11:40 +0100 | [diff] [blame] | 148 | * @param context The context to be searched for. |
| 149 | * @return The table corresponding to the given context. |
Daniel | 359a2ef | 2018-11-13 20:59:50 +0100 | [diff] [blame] | 150 | */ |
Daniel | 2b619af | 2018-11-11 16:11:40 +0100 | [diff] [blame] | 151 | PCTable* findTable(int context); |
Daniel | 359a2ef | 2018-11-13 20:59:50 +0100 | [diff] [blame] | 152 | |
Daniel | 2b619af | 2018-11-11 16:11:40 +0100 | [diff] [blame] | 153 | /** |
| 154 | * Create a PC table for the given context. |
| 155 | * |
| 156 | * @param context The context of the new PC table. |
| 157 | * @return The new PC table |
| 158 | */ |
| 159 | PCTable* allocateNewContext(int context); |
Mitch Hayenga | 771c864 | 2014-01-29 23:21:26 -0600 | [diff] [blame] | 160 | |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 161 | public: |
Gabe Black | 91d83cc | 2020-10-07 06:49:23 -0700 | [diff] [blame] | 162 | Stride(const StridePrefetcherParams &p); |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 163 | |
Javier Bueno | 38f87da | 2018-11-18 00:50:08 +0100 | [diff] [blame] | 164 | void calculatePrefetch(const PrefetchInfo &pfi, |
Daniel | 67e45b8 | 2018-11-11 11:55:37 +0100 | [diff] [blame] | 165 | std::vector<AddrPriority> &addresses) override; |
Ron Dreslinski | ed8564a | 2006-06-28 11:02:14 -0400 | [diff] [blame] | 166 | }; |
| 167 | |
Daniel R. Carvalho | df72e9d | 2021-05-08 07:32:23 -0300 | [diff] [blame] | 168 | } // namespace prefetch |
Daniel R. Carvalho | 974a47d | 2021-05-09 12:32:07 -0300 | [diff] [blame] | 169 | } // namespace gem5 |
Daniel R. Carvalho | 0be2496 | 2019-12-29 00:45:44 +0100 | [diff] [blame] | 170 | |
Mitch Hayenga | df82a2d | 2014-12-23 09:31:18 -0500 | [diff] [blame] | 171 | #endif // __MEM_CACHE_PREFETCH_STRIDE_HH__ |