blob: 2b70765ba4ac1b6ad17d280f2e0e9f3cea9fa97c [file] [log] [blame]
Ron Dreslinskied8564a2006-06-28 11:02:14 -04001/*
Daniel153a33b2018-11-11 15:52:08 +01002 * Copyright (c) 2018 Inria
Stephan Diestelhorstcb8856f2015-03-27 04:56:03 -04003 * Copyright (c) 2012-2013, 2015 ARM Limited
Giacomo Gabrielliaefe9cc2014-01-24 15:29:30 -06004 * 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 Dreslinskied8564a2006-06-28 11:02:14 -040015 * 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 Dreslinskied8564a2006-06-28 11:02:14 -040040 */
41
42/**
43 * @file
Steve Reinhardtf6559322006-12-18 21:53:06 -080044 * Describes a strided prefetcher.
Ron Dreslinskied8564a2006-06-28 11:02:14 -040045 */
46
Mitch Hayengadf82a2d2014-12-23 09:31:18 -050047#ifndef __MEM_CACHE_PREFETCH_STRIDE_HH__
48#define __MEM_CACHE_PREFETCH_STRIDE_HH__
Ron Dreslinskied8564a2006-06-28 11:02:14 -040049
Nikos Nikoleris56865ad2018-05-03 12:14:41 +010050#include <string>
Andreas Hansson22c04192015-10-12 04:07:59 -040051#include <unordered_map>
Daniel3a3e1722018-11-13 20:47:51 +010052#include <vector>
Andreas Hansson22c04192015-10-12 04:07:59 -040053
Daniel R. Carvalho31b34872019-12-29 14:18:22 +010054#include "base/sat_counter.hh"
Nikos Nikoleris56865ad2018-05-03 12:14:41 +010055#include "base/types.hh"
Daniel R. Carvalho28482882019-12-29 10:14:26 +010056#include "mem/cache/prefetch/associative_set.hh"
Mitch Hayengadf82a2d2014-12-23 09:31:18 -050057#include "mem/cache/prefetch/queued.hh"
Daniel153a33b2018-11-11 15:52:08 +010058#include "mem/cache/replacement_policies/replaceable_entry.hh"
Daniel R. Carvalho28482882019-12-29 10:14:26 +010059#include "mem/cache/tags/indexing_policies/set_associative.hh"
Nikos Nikoleris56865ad2018-05-03 12:14:41 +010060#include "mem/packet.hh"
Daniel R. Carvalho28482882019-12-29 10:14:26 +010061#include "params/StridePrefetcherHashedSetAssociative.hh"
Nikos Nikoleris56865ad2018-05-03 12:14:41 +010062
Daniel R. Carvalho974a47d2021-05-09 12:32:07 -030063namespace gem5
64{
65
Daniel R. Carvalho28482882019-12-29 10:14:26 +010066class BaseIndexingPolicy;
Daniel R. Carvalho17897bb2021-05-06 07:24:06 -030067GEM5_DEPRECATED_NAMESPACE(ReplacementPolicy, replacement_policy);
68namespace replacement_policy
69{
Daniel R. Carvalho523d42d2019-12-28 23:38:21 +010070 class Base;
71}
Nikos Nikoleris56865ad2018-05-03 12:14:41 +010072struct StridePrefetcherParams;
Ron Dreslinskied8564a2006-06-28 11:02:14 -040073
Daniel R. Carvalhodf72e9d2021-05-08 07:32:23 -030074GEM5_DEPRECATED_NAMESPACE(Prefetcher, prefetch);
75namespace prefetch
76{
Daniel R. Carvalho0be24962019-12-29 00:45:44 +010077
Daniel R. Carvalho28482882019-12-29 10:14:26 +010078/**
79 * Override the default set associative to apply a specific hash function
80 * when extracting a set.
81 */
82class 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 Black91d83cc2020-10-07 06:49:23 -070090 const StridePrefetcherHashedSetAssociativeParams &p)
Daniel R. Carvalho28482882019-12-29 10:14:26 +010091 : SetAssociative(p)
92 {
93 }
94 ~StridePrefetcherHashedSetAssociative() = default;
95};
96
Daniel R. Carvalho0be24962019-12-29 00:45:44 +010097class Stride : public Queued
Ron Dreslinskied8564a2006-06-28 11:02:14 -040098{
99 protected:
Daniel R. Carvalho31b34872019-12-29 14:18:22 +0100100 /** Initial confidence counter value for the pc tables. */
Daniel R. Carvalho833a60a2019-08-12 09:59:07 +0200101 const SatCounter8 initConfidence;
Daniel R. Carvalho31b34872019-12-29 14:18:22 +0100102
103 /** Confidence threshold for prefetch generation. */
104 const double threshConf;
Steve Reinhardt89a7fb02009-02-16 08:56:40 -0800105
Shivani Parekh392c1ce2020-08-24 11:47:44 -0700106 const bool useRequestorId;
Mitch Hayengadf82a2d2014-12-23 09:31:18 -0500107
108 const int degree;
109
Daniel R. Carvalho28482882019-12-29 10:14:26 +0100110 /**
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;
Daniel153a33b2018-11-11 15:52:08 +0100117
Daniel R. Carvalho28482882019-12-29 10:14:26 +0100118 BaseIndexingPolicy* const indexingPolicy;
Daniel R. Carvalho17897bb2021-05-06 07:24:06 -0300119 replacement_policy::Base* const replacementPolicy;
Daniel R. Carvalho28482882019-12-29 10:14:26 +0100120
121 PCTableInfo(int assoc, int num_entries,
122 BaseIndexingPolicy* indexing_policy,
Daniel R. Carvalho17897bb2021-05-06 07:24:06 -0300123 replacement_policy::Base* repl_policy)
Daniel R. Carvalho28482882019-12-29 10:14:26 +0100124 : assoc(assoc), numEntries(num_entries),
Daniel R. Carvalho17897bb2021-05-06 07:24:06 -0300125 indexingPolicy(indexing_policy), replacementPolicy(repl_policy)
Daniel R. Carvalho28482882019-12-29 10:14:26 +0100126 {
127 }
128 } pcTableInfo;
129
130 /** Tagged by hashed PCs. */
131 struct StrideEntry : public TaggedEntry
Ron Dreslinskied8564a2006-06-28 11:02:14 -0400132 {
Daniel R. Carvalho833a60a2019-08-12 09:59:07 +0200133 StrideEntry(const SatCounter8& init_confidence);
Danield7a1db52018-11-11 17:56:08 +0100134
Daniel R. Carvalho28482882019-12-29 10:14:26 +0100135 void invalidate() override;
Mitch Hayengadf82a2d2014-12-23 09:31:18 -0500136
Mitch Hayengadf82a2d2014-12-23 09:31:18 -0500137 Addr lastAddr;
Ron Dreslinskied8564a2006-06-28 11:02:14 -0400138 int stride;
Daniel R. Carvalho833a60a2019-08-12 09:59:07 +0200139 SatCounter8 confidence;
Ron Dreslinskied8564a2006-06-28 11:02:14 -0400140 };
Daniel R. Carvalho28482882019-12-29 10:14:26 +0100141 typedef AssociativeSet<StrideEntry> PCTable;
Daniel2b619af2018-11-11 16:11:40 +0100142 std::unordered_map<int, PCTable> pcTables;
Ron Dreslinskied8564a2006-06-28 11:02:14 -0400143
Daniel359a2ef2018-11-13 20:59:50 +0100144 /**
Daniel2b619af2018-11-11 16:11:40 +0100145 * Try to find a table of entries for the given context. If none is
146 * found, a new table is created.
Daniel359a2ef2018-11-13 20:59:50 +0100147 *
Daniel2b619af2018-11-11 16:11:40 +0100148 * @param context The context to be searched for.
149 * @return The table corresponding to the given context.
Daniel359a2ef2018-11-13 20:59:50 +0100150 */
Daniel2b619af2018-11-11 16:11:40 +0100151 PCTable* findTable(int context);
Daniel359a2ef2018-11-13 20:59:50 +0100152
Daniel2b619af2018-11-11 16:11:40 +0100153 /**
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 Hayenga771c8642014-01-29 23:21:26 -0600160
Ron Dreslinskied8564a2006-06-28 11:02:14 -0400161 public:
Gabe Black91d83cc2020-10-07 06:49:23 -0700162 Stride(const StridePrefetcherParams &p);
Ron Dreslinskied8564a2006-06-28 11:02:14 -0400163
Javier Bueno38f87da2018-11-18 00:50:08 +0100164 void calculatePrefetch(const PrefetchInfo &pfi,
Daniel67e45b82018-11-11 11:55:37 +0100165 std::vector<AddrPriority> &addresses) override;
Ron Dreslinskied8564a2006-06-28 11:02:14 -0400166};
167
Daniel R. Carvalhodf72e9d2021-05-08 07:32:23 -0300168} // namespace prefetch
Daniel R. Carvalho974a47d2021-05-09 12:32:07 -0300169} // namespace gem5
Daniel R. Carvalho0be24962019-12-29 00:45:44 +0100170
Mitch Hayengadf82a2d2014-12-23 09:31:18 -0500171#endif // __MEM_CACHE_PREFETCH_STRIDE_HH__