irregular_stream_buffer.hh revision 13669:24ef552b4d6d
1/**
2 * Copyright (c) 2018 Metempsy Technology Consulting
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Javier Bueno
29 */
30
31/**
32 * Implementation of the Irregular Stream Buffer prefetcher
33 * Reference:
34 *   Jain, A., & Lin, C. (2013, December). Linearizing irregular memory
35 *   accesses for improved correlated prefetching. In Proceedings of the
36 *   46th Annual IEEE/ACM International Symposium on Microarchitecture
37 *   (pp. 247-259). ACM.
38 */
39
40#ifndef __MEM_CACHE_PREFETCH_IRREGULAR_STREAM_BUFFER_HH__
41#define __MEM_CACHE_PREFETCH_IRREGULAR_STREAM_BUFFER_HH__
42
43#include "base/callback.hh"
44#include "mem/cache/prefetch/associative_set.hh"
45#include "mem/cache/prefetch/queued.hh"
46
47struct IrregularStreamBufferPrefetcherParams;
48
49class IrregularStreamBufferPrefetcher : public QueuedPrefetcher
50{
51    /** Maximum value of the confidence counters */
52    const unsigned maxCounterValue;
53    /** Size in bytes of a temporal stream */
54    const size_t chunkSize;
55    /** Number of prefetch candidates per Physical-to-Structural entry */
56    const unsigned prefetchCandidatesPerEntry;
57    /** Number of maximum prefetches requests created when predicting */
58    const unsigned degree;
59
60    /**
61     * Training Unit Entry datatype, it holds the last accessed address and
62     * its secure flag
63     */
64    struct TrainingUnitEntry : public TaggedEntry {
65        Addr lastAddress;
66        bool lastAddressSecure;
67    };
68    /** Map of PCs to Training unit entries */
69    AssociativeSet<TrainingUnitEntry> trainingUnit;
70
71    /** Address Mapping entry, holds an address and a confidence counter */
72    struct AddressMapping {
73        Addr address;
74        unsigned counter;
75        AddressMapping() : address(0), counter(0)
76        {}
77    };
78
79    /**
80     * Maps a set of contiguous addresses to another set of (not necessarily
81     * contiguos) addresses, with their corresponding confidence counters
82     */
83    struct AddressMappingEntry : public TaggedEntry {
84        std::vector<AddressMapping> mappings;
85        AddressMappingEntry(size_t num_mappings) : mappings(num_mappings)
86        {}
87        void reset() override
88        {
89            for (auto &entry : mappings) {
90                entry.address = 0;
91                entry.counter = 0;
92            }
93        }
94    };
95
96    /** Physical-to-Structured mappings table */
97    AssociativeSet<AddressMappingEntry> psAddressMappingCache;
98    /** Structured-to-Physical mappings table */
99    AssociativeSet<AddressMappingEntry> spAddressMappingCache;
100    /**
101     * Counter of allocated structural addresses, increased by "chunkSize",
102     * each time a new structured address is allocated
103     */
104    uint64_t structuralAddressCounter;
105
106    /**
107     * Add a mapping to the Structured-to-Physica mapping table
108     * @param structuralAddress structural address
109     * @param is_secure whether this page is inside the secure memory area
110     * @param physical_address corresponding physical address
111     */
112    void addStructuralToPhysicalEntry(Addr structuralAddress, bool is_secure,
113                                      Addr physical_address);
114
115    /**
116     * Obtain the Physical-to-Structured mapping entry of the given physical
117     * address. If the entry does not exist a new one is allocated, replacing
118     * an existing one if needed.
119     * @param paddr physical address
120     * @param is_secure whether this page is inside the secure memory area
121     * @result reference to the entry
122     */
123    AddressMapping& getPSMapping(Addr paddr, bool is_secure);
124  public:
125    IrregularStreamBufferPrefetcher(
126        const IrregularStreamBufferPrefetcherParams *p);
127    ~IrregularStreamBufferPrefetcher() {}
128    void calculatePrefetch(const PrefetchInfo &pfi,
129                           std::vector<AddrPriority> &addresses) override;
130};
131#endif//__MEM_CACHE_PREFETCH_IRREGULAR_STREAM_BUFFER_HH__
132