stride.hh revision 11439
12686Sksewell@umich.edu/*
22100SN/A * Copyright (c) 2012-2013, 2015 ARM Limited
35254Sksewell@umich.edu * All rights reserved
45254Sksewell@umich.edu *
55254Sksewell@umich.edu * The license below extends only to copyright in the software and shall
65254Sksewell@umich.edu * not be construed as granting a license to any other intellectual
75254Sksewell@umich.edu * property including but not limited to intellectual property relating
85254Sksewell@umich.edu * to a hardware implementation of the functionality of the software
95254Sksewell@umich.edu * licensed hereunder.  You may use the software subject to the license
105254Sksewell@umich.edu * terms below provided that you ensure that this notice is replicated
115254Sksewell@umich.edu * unmodified and in its entirety in all distributions of the software,
125254Sksewell@umich.edu * modified or unmodified, in source code or in binary form.
135254Sksewell@umich.edu *
145254Sksewell@umich.edu * Copyright (c) 2005 The Regents of The University of Michigan
155254Sksewell@umich.edu * All rights reserved.
165254Sksewell@umich.edu *
175254Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
185254Sksewell@umich.edu * modification, are permitted provided that the following conditions are
195254Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
205254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
215254Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
225254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
235254Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
245254Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
255254Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
265254Sksewell@umich.edu * this software without specific prior written permission.
275254Sksewell@umich.edu *
285254Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
295254Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
305254Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
315254Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322706Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332022SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342022SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352043SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362024SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372024SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382043SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392686Sksewell@umich.edu *
404661Sksewell@umich.edu * Authors: Ron Dreslinski
412022SN/A */
422083SN/A
432686Sksewell@umich.edu/**
442101SN/A * @file
452043SN/A * Describes a strided prefetcher.
462043SN/A */
472101SN/A
482101SN/A#ifndef __MEM_CACHE_PREFETCH_STRIDE_HH__
496384Sgblack@eecs.umich.edu#define __MEM_CACHE_PREFETCH_STRIDE_HH__
506384Sgblack@eecs.umich.edu
516384Sgblack@eecs.umich.edu#include <unordered_map>
526384Sgblack@eecs.umich.edu
536384Sgblack@eecs.umich.edu#include "mem/cache/prefetch/queued.hh"
546384Sgblack@eecs.umich.edu#include "params/StridePrefetcher.hh"
552101SN/A
562101SN/Aclass StridePrefetcher : public QueuedPrefetcher
572101SN/A{
582046SN/A  protected:
592686Sksewell@umich.edu    const int maxConf;
602686Sksewell@umich.edu    const int threshConf;
612686Sksewell@umich.edu    const int minConf;
622470SN/A    const int startConf;
632686Sksewell@umich.edu
644661Sksewell@umich.edu    const int pcTableAssoc;
655222Sksewell@umich.edu    const int pcTableSets;
665222Sksewell@umich.edu
672686Sksewell@umich.edu    const bool useMasterId;
688588Sgblack@eecs.umich.edu
692470SN/A    const int degree;
702241SN/A
712101SN/A    struct StrideEntry
722495SN/A    {
732495SN/A        StrideEntry() : instAddr(0), lastAddr(0), isSecure(false), stride(0),
748588Sgblack@eecs.umich.edu                        confidence(0)
752101SN/A        { }
766384Sgblack@eecs.umich.edu
776384Sgblack@eecs.umich.edu        Addr instAddr;
786384Sgblack@eecs.umich.edu        Addr lastAddr;
798588Sgblack@eecs.umich.edu        bool isSecure;
806384Sgblack@eecs.umich.edu        int stride;
812495SN/A        int confidence;
822101SN/A    };
832101SN/A
842495SN/A    class PCTable
852495SN/A    {
862495SN/A      public:
872495SN/A        PCTable(int assoc, int sets, const std::string name) :
882495SN/A            pcTableAssoc(assoc), pcTableSets(sets), _name(name) {}
892495SN/A        StrideEntry** operator[] (int context) {
902495SN/A            auto it = entries.find(context);
912495SN/A            if (it != entries.end())
922495SN/A                return it->second;
932495SN/A
942495SN/A            return allocateNewContext(context);
952495SN/A        }
962495SN/A
972101SN/A        ~PCTable();
988588Sgblack@eecs.umich.edu      private:
992101SN/A        const std::string name() {return _name; }
1002101SN/A        const int pcTableAssoc;
1018588Sgblack@eecs.umich.edu        const int pcTableSets;
1022101SN/A        const std::string _name;
1036384Sgblack@eecs.umich.edu        std::unordered_map<int, StrideEntry**> entries;
1046384Sgblack@eecs.umich.edu
1056384Sgblack@eecs.umich.edu        StrideEntry** allocateNewContext(int context);
1068588Sgblack@eecs.umich.edu    };
1078588Sgblack@eecs.umich.edu    PCTable pcTable;
1086384Sgblack@eecs.umich.edu
1092101SN/A    bool pcTableHit(Addr pc, bool is_secure, int master_id, StrideEntry* &entry);
1102101SN/A    StrideEntry* pcTableVictim(Addr pc, int master_id);
1112495SN/A
1122495SN/A    Addr pcHash(Addr pc) const;
1132495SN/A  public:
1142495SN/A
1152495SN/A    StridePrefetcher(const StridePrefetcherParams *p);
1166384Sgblack@eecs.umich.edu
1176384Sgblack@eecs.umich.edu    void calculatePrefetch(const PacketPtr &pkt,
1186384Sgblack@eecs.umich.edu                           std::vector<AddrPriority> &addresses);
1196384Sgblack@eecs.umich.edu};
1206384Sgblack@eecs.umich.edu
1212495SN/A#endif // __MEM_CACHE_PREFETCH_STRIDE_HH__
1226384Sgblack@eecs.umich.edu