stride.hh revision 13426:d2b0e9ec67f1
15643Sgblack@eecs.umich.edu/*
25643Sgblack@eecs.umich.edu * Copyright (c) 2012-2013, 2015 ARM Limited
35643Sgblack@eecs.umich.edu * All rights reserved
45643Sgblack@eecs.umich.edu *
55643Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall
65643Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual
75643Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating
85643Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software
95643Sgblack@eecs.umich.edu * licensed hereunder.  You may use the software subject to the license
105643Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated
115643Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software,
125643Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form.
135643Sgblack@eecs.umich.edu *
145643Sgblack@eecs.umich.edu * Copyright (c) 2005 The Regents of The University of Michigan
155643Sgblack@eecs.umich.edu * All rights reserved.
165643Sgblack@eecs.umich.edu *
175643Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
185643Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
195643Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
205643Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
215643Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
225643Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
235643Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
245643Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
255643Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
265643Sgblack@eecs.umich.edu * this software without specific prior written permission.
275643Sgblack@eecs.umich.edu *
285643Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
295643Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
305643Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3111793Sbrandon.potter@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3211793Sbrandon.potter@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336138Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
345651Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
358746Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
368232Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
375657Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
385643Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
395643Sgblack@eecs.umich.edu *
405643Sgblack@eecs.umich.edu * Authors: Ron Dreslinski
415643Sgblack@eecs.umich.edu */
429805Sstever@gmail.com
439808Sstever@gmail.com/**
449805Sstever@gmail.com * @file
455643Sgblack@eecs.umich.edu * Describes a strided prefetcher.
467913SBrad.Beckmann@amd.com */
477913SBrad.Beckmann@amd.com
487913SBrad.Beckmann@amd.com#ifndef __MEM_CACHE_PREFETCH_STRIDE_HH__
497913SBrad.Beckmann@amd.com#define __MEM_CACHE_PREFETCH_STRIDE_HH__
507913SBrad.Beckmann@amd.com
516136Sgblack@eecs.umich.edu#include <string>
525643Sgblack@eecs.umich.edu#include <unordered_map>
535643Sgblack@eecs.umich.edu#include <vector>
545653Sgblack@eecs.umich.edu
555653Sgblack@eecs.umich.edu#include "base/types.hh"
565653Sgblack@eecs.umich.edu#include "mem/cache/prefetch/queued.hh"
575653Sgblack@eecs.umich.edu#include "mem/packet.hh"
585827Sgblack@eecs.umich.edu
595653Sgblack@eecs.umich.edustruct StridePrefetcherParams;
6014290Sgabeblack@google.com
6114290Sgabeblack@google.comclass StridePrefetcher : public QueuedPrefetcher
6214291Sgabeblack@google.com{
6314290Sgabeblack@google.com  protected:
645643Sgblack@eecs.umich.edu    const int maxConf;
655643Sgblack@eecs.umich.edu    const int threshConf;
667913SBrad.Beckmann@amd.com    const int minConf;
677913SBrad.Beckmann@amd.com    const int startConf;
687913SBrad.Beckmann@amd.com
697913SBrad.Beckmann@amd.com    const int pcTableAssoc;
707913SBrad.Beckmann@amd.com    const int pcTableSets;
719807Sstever@gmail.com
727913SBrad.Beckmann@amd.com    const bool useMasterId;
739805Sstever@gmail.com
749807Sstever@gmail.com    const int degree;
757913SBrad.Beckmann@amd.com
767913SBrad.Beckmann@amd.com    struct StrideEntry
7713784Sgabeblack@google.com    {
7813784Sgabeblack@google.com        /** Default constructor */
799805Sstever@gmail.com        StrideEntry();
809805Sstever@gmail.com
819805Sstever@gmail.com        /** Invalidate the entry */
8214290Sgabeblack@google.com        void invalidate();
8314290Sgabeblack@google.com
8414290Sgabeblack@google.com        Addr instAddr;
8514290Sgabeblack@google.com        Addr lastAddr;
869805Sstever@gmail.com        bool isSecure;
879805Sstever@gmail.com        int stride;
889805Sstever@gmail.com        int confidence;
899805Sstever@gmail.com    };
909805Sstever@gmail.com
919805Sstever@gmail.com    class PCTable
929805Sstever@gmail.com    {
939805Sstever@gmail.com      public:
949805Sstever@gmail.com        /**
959805Sstever@gmail.com         * Default constructor. Create a table with given parameters.
969805Sstever@gmail.com         *
979805Sstever@gmail.com         * @param assoc Associativity of the table.
985643Sgblack@eecs.umich.edu         * @param sets Number of sets in the table.
9911144Sjthestness@gmail.com         * @param name Name of the prefetcher.
10011144Sjthestness@gmail.com         */
10111144Sjthestness@gmail.com        PCTable(int assoc, int sets, const std::string name);
10211144Sjthestness@gmail.com
10311144Sjthestness@gmail.com        /**
10411144Sjthestness@gmail.com         * Default destructor.
10511144Sjthestness@gmail.com         */
10611144Sjthestness@gmail.com        ~PCTable();
1075643Sgblack@eecs.umich.edu
1085643Sgblack@eecs.umich.edu        /**
1095643Sgblack@eecs.umich.edu         * Search for an entry in the pc table.
1105643Sgblack@eecs.umich.edu         *
1115643Sgblack@eecs.umich.edu         * @param pc The PC to look for.
1125643Sgblack@eecs.umich.edu         * @param is_secure True if the target memory space is secure.
11313229Sgabeblack@google.com         * @return Pointer to the entry.
1145643Sgblack@eecs.umich.edu         */
1155643Sgblack@eecs.umich.edu        StrideEntry* findEntry(Addr pc, bool is_secure);
11613229Sgabeblack@google.com
1175643Sgblack@eecs.umich.edu        /**
1185643Sgblack@eecs.umich.edu         * Find a replacement victim to make room for given PC.
1195643Sgblack@eecs.umich.edu         *
1205643Sgblack@eecs.umich.edu         * @param pc The PC value.
1215898Sgblack@eecs.umich.edu         * @return The victimized entry.
1229805Sstever@gmail.com         */
1235643Sgblack@eecs.umich.edu        StrideEntry* findVictim(Addr pc);
1245643Sgblack@eecs.umich.edu
1255643Sgblack@eecs.umich.edu      private:
1265643Sgblack@eecs.umich.edu        const std::string name() {return _name; }
1275643Sgblack@eecs.umich.edu        const int pcTableAssoc;
1285643Sgblack@eecs.umich.edu        const int pcTableSets;
1295643Sgblack@eecs.umich.edu        const std::string _name;
1305643Sgblack@eecs.umich.edu        std::vector<std::vector<StrideEntry>> entries;
1315643Sgblack@eecs.umich.edu
13213229Sgabeblack@google.com        /**
1335643Sgblack@eecs.umich.edu         * PC hashing function to index sets in the table.
1345643Sgblack@eecs.umich.edu         *
13513229Sgabeblack@google.com         * @param pc The PC value.
1365643Sgblack@eecs.umich.edu         * @return The set to which this PC maps.
1375643Sgblack@eecs.umich.edu         */
1385643Sgblack@eecs.umich.edu        Addr pcHash(Addr pc) const;
1395643Sgblack@eecs.umich.edu    };
1405898Sgblack@eecs.umich.edu    std::unordered_map<int, PCTable> pcTables;
1419805Sstever@gmail.com
1425643Sgblack@eecs.umich.edu    /**
1435643Sgblack@eecs.umich.edu     * Try to find a table of entries for the given context. If none is
1445643Sgblack@eecs.umich.edu     * found, a new table is created.
1455643Sgblack@eecs.umich.edu     *
1465643Sgblack@eecs.umich.edu     * @param context The context to be searched for.
1475643Sgblack@eecs.umich.edu     * @return The table corresponding to the given context.
1487913SBrad.Beckmann@amd.com     */
1495643Sgblack@eecs.umich.edu    PCTable* findTable(int context);
1505643Sgblack@eecs.umich.edu
1515643Sgblack@eecs.umich.edu    /**
1527913SBrad.Beckmann@amd.com     * Create a PC table for the given context.
1535643Sgblack@eecs.umich.edu     *
1545643Sgblack@eecs.umich.edu     * @param context The context of the new PC table.
1555643Sgblack@eecs.umich.edu     * @return The new PC table
1565643Sgblack@eecs.umich.edu     */
1575643Sgblack@eecs.umich.edu    PCTable* allocateNewContext(int context);
1585643Sgblack@eecs.umich.edu
1595643Sgblack@eecs.umich.edu  public:
1605643Sgblack@eecs.umich.edu    StridePrefetcher(const StridePrefetcherParams *p);
1615643Sgblack@eecs.umich.edu
1625643Sgblack@eecs.umich.edu    void calculatePrefetch(const PacketPtr &pkt,
1635643Sgblack@eecs.umich.edu                           std::vector<AddrPriority> &addresses) override;
1645643Sgblack@eecs.umich.edu};
1655643Sgblack@eecs.umich.edu
1665643Sgblack@eecs.umich.edu#endif // __MEM_CACHE_PREFETCH_STRIDE_HH__
1675643Sgblack@eecs.umich.edu