stride.hh revision 13424
12SN/A/*
21762SN/A * Copyright (c) 2012-2013, 2015 ARM Limited
32SN/A * All rights reserved
42SN/A *
52SN/A * The license below extends only to copyright in the software and shall
62SN/A * not be construed as granting a license to any other intellectual
72SN/A * property including but not limited to intellectual property relating
82SN/A * to a hardware implementation of the functionality of the software
92SN/A * licensed hereunder.  You may use the software subject to the license
102SN/A * terms below provided that you ensure that this notice is replicated
112SN/A * unmodified and in its entirety in all distributions of the software,
122SN/A * modified or unmodified, in source code or in binary form.
132SN/A *
142SN/A * Copyright (c) 2005 The Regents of The University of Michigan
152SN/A * All rights reserved.
162SN/A *
172SN/A * Redistribution and use in source and binary forms, with or without
182SN/A * modification, are permitted provided that the following conditions are
192SN/A * met: redistributions of source code must retain the above copyright
202SN/A * notice, this list of conditions and the following disclaimer;
212SN/A * redistributions in binary form must reproduce the above copyright
222SN/A * notice, this list of conditions and the following disclaimer in the
232SN/A * documentation and/or other materials provided with the distribution;
242SN/A * neither the name of the copyright holders nor the names of its
252SN/A * contributors may be used to endorse or promote products derived from
262SN/A * this software without specific prior written permission.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292665Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372432SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
381147SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
393453Sgblack@eecs.umich.edu *
402984Sgblack@eecs.umich.edu * Authors: Ron Dreslinski
412984Sgblack@eecs.umich.edu */
421147SN/A
432517SN/A/**
442984Sgblack@eecs.umich.edu * @file
4556SN/A * Describes a strided prefetcher.
462SN/A */
472680Sktlim@umich.edu
482SN/A#ifndef __MEM_CACHE_PREFETCH_STRIDE_HH__
493453Sgblack@eecs.umich.edu#define __MEM_CACHE_PREFETCH_STRIDE_HH__
502SN/A
513453Sgblack@eecs.umich.edu#include <string>
522SN/A#include <unordered_map>
533453Sgblack@eecs.umich.edu#include <vector>
543453Sgblack@eecs.umich.edu
553453Sgblack@eecs.umich.edu#include "base/types.hh"
563453Sgblack@eecs.umich.edu#include "mem/cache/prefetch/queued.hh"
573453Sgblack@eecs.umich.edu#include "mem/packet.hh"
582SN/A
593453Sgblack@eecs.umich.edustruct StridePrefetcherParams;
603453Sgblack@eecs.umich.edu
613453Sgblack@eecs.umich.educlass StridePrefetcher : public QueuedPrefetcher
622SN/A{
633453Sgblack@eecs.umich.edu  protected:
643453Sgblack@eecs.umich.edu    const int maxConf;
652SN/A    const int threshConf;
663453Sgblack@eecs.umich.edu    const int minConf;
673453Sgblack@eecs.umich.edu    const int startConf;
683453Sgblack@eecs.umich.edu
692SN/A    const int pcTableAssoc;
703453Sgblack@eecs.umich.edu    const int pcTableSets;
712SN/A
723453Sgblack@eecs.umich.edu    const bool useMasterId;
733453Sgblack@eecs.umich.edu
742SN/A    const int degree;
753453Sgblack@eecs.umich.edu
763453Sgblack@eecs.umich.edu    struct StrideEntry
773453Sgblack@eecs.umich.edu    {
782SN/A        StrideEntry() : instAddr(0), lastAddr(0), isSecure(false), stride(0),
793453Sgblack@eecs.umich.edu                        confidence(0)
803453Sgblack@eecs.umich.edu        { }
813453Sgblack@eecs.umich.edu
823453Sgblack@eecs.umich.edu        Addr instAddr;
833453Sgblack@eecs.umich.edu        Addr lastAddr;
843453Sgblack@eecs.umich.edu        bool isSecure;
852SN/A        int stride;
863453Sgblack@eecs.umich.edu        int confidence;
872SN/A    };
883453Sgblack@eecs.umich.edu
893453Sgblack@eecs.umich.edu    class PCTable
903453Sgblack@eecs.umich.edu    {
913453Sgblack@eecs.umich.edu      public:
922SN/A        PCTable(int assoc, int sets, const std::string name) :
933453Sgblack@eecs.umich.edu            pcTableAssoc(assoc), pcTableSets(sets), _name(name) {}
943453Sgblack@eecs.umich.edu
953453Sgblack@eecs.umich.edu        std::vector<std::vector<StrideEntry>>& operator[] (int context) {
963453Sgblack@eecs.umich.edu            auto it = entries.find(context);
973453Sgblack@eecs.umich.edu            if (it != entries.end())
983453Sgblack@eecs.umich.edu                return it->second;
993453Sgblack@eecs.umich.edu
1002SN/A            return allocateNewContext(context);
1013453Sgblack@eecs.umich.edu        }
1023453Sgblack@eecs.umich.edu
1033453Sgblack@eecs.umich.edu        ~PCTable();
1042SN/A      private:
1053453Sgblack@eecs.umich.edu        const std::string name() {return _name; }
1063453Sgblack@eecs.umich.edu        const int pcTableAssoc;
1072SN/A        const int pcTableSets;
1083453Sgblack@eecs.umich.edu        const std::string _name;
1093453Sgblack@eecs.umich.edu        std::unordered_map<int, std::vector<std::vector<StrideEntry>>> entries;
1103453Sgblack@eecs.umich.edu
1113453Sgblack@eecs.umich.edu        std::vector<std::vector<StrideEntry>>& allocateNewContext(int context);
1123453Sgblack@eecs.umich.edu    };
1133453Sgblack@eecs.umich.edu    PCTable pcTable;
1143453Sgblack@eecs.umich.edu
1153453Sgblack@eecs.umich.edu    /**
1163453Sgblack@eecs.umich.edu     * Search for an entry in the pc table.
1173453Sgblack@eecs.umich.edu     *
1183453Sgblack@eecs.umich.edu     * @param pc The PC to look for.
1193453Sgblack@eecs.umich.edu     * @param is_secure True if the target memory space is secure.
1203453Sgblack@eecs.umich.edu     * @param master_id The context.
1213453Sgblack@eecs.umich.edu     * @return Pointer to the entry.
1223453Sgblack@eecs.umich.edu     */
1232SN/A    StrideEntry* findEntry(Addr pc, bool is_secure, int master_id);
1243453Sgblack@eecs.umich.edu
1253453Sgblack@eecs.umich.edu    StrideEntry* pcTableVictim(Addr pc, int master_id);
1263453Sgblack@eecs.umich.edu
1273453Sgblack@eecs.umich.edu    Addr pcHash(Addr pc) const;
1283453Sgblack@eecs.umich.edu  public:
1293453Sgblack@eecs.umich.edu
1303453Sgblack@eecs.umich.edu    StridePrefetcher(const StridePrefetcherParams *p);
1312SN/A
1322SN/A    void calculatePrefetch(const PacketPtr &pkt,
133                           std::vector<AddrPriority> &addresses) override;
134};
135
136#endif // __MEM_CACHE_PREFETCH_STRIDE_HH__
137