12810SN/A/* 213427Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria 310771Sstephan.diestelhorst@arm.com * Copyright (c) 2012-2013, 2015 ARM Limited 410028SGiacomo.Gabrielli@arm.com * All rights reserved 510028SGiacomo.Gabrielli@arm.com * 610028SGiacomo.Gabrielli@arm.com * The license below extends only to copyright in the software and shall 710028SGiacomo.Gabrielli@arm.com * not be construed as granting a license to any other intellectual 810028SGiacomo.Gabrielli@arm.com * property including but not limited to intellectual property relating 910028SGiacomo.Gabrielli@arm.com * to a hardware implementation of the functionality of the software 1010028SGiacomo.Gabrielli@arm.com * licensed hereunder. You may use the software subject to the license 1110028SGiacomo.Gabrielli@arm.com * terms below provided that you ensure that this notice is replicated 1210028SGiacomo.Gabrielli@arm.com * unmodified and in its entirety in all distributions of the software, 1310028SGiacomo.Gabrielli@arm.com * modified or unmodified, in source code or in binary form. 1410028SGiacomo.Gabrielli@arm.com * 152810SN/A * Copyright (c) 2005 The Regents of The University of Michigan 162810SN/A * All rights reserved. 172810SN/A * 182810SN/A * Redistribution and use in source and binary forms, with or without 192810SN/A * modification, are permitted provided that the following conditions are 202810SN/A * met: redistributions of source code must retain the above copyright 212810SN/A * notice, this list of conditions and the following disclaimer; 222810SN/A * redistributions in binary form must reproduce the above copyright 232810SN/A * notice, this list of conditions and the following disclaimer in the 242810SN/A * documentation and/or other materials provided with the distribution; 252810SN/A * neither the name of the copyright holders nor the names of its 262810SN/A * contributors may be used to endorse or promote products derived from 272810SN/A * this software without specific prior written permission. 282810SN/A * 292810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 332810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 382810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402810SN/A * 412810SN/A * Authors: Ron Dreslinski 4213427Sodanrc@yahoo.com.br * Daniel Carvalho 432810SN/A */ 442810SN/A 452810SN/A/** 462810SN/A * @file 473861SN/A * Describes a strided prefetcher. 482810SN/A */ 492810SN/A 5010623Smitch.hayenga@arm.com#ifndef __MEM_CACHE_PREFETCH_STRIDE_HH__ 5110623Smitch.hayenga@arm.com#define __MEM_CACHE_PREFETCH_STRIDE_HH__ 522810SN/A 5312727Snikos.nikoleris@arm.com#include <string> 5411168Sandreas.hansson@arm.com#include <unordered_map> 5513424Sodanrc@yahoo.com.br#include <vector> 5611168Sandreas.hansson@arm.com 5712727Snikos.nikoleris@arm.com#include "base/types.hh" 5810623Smitch.hayenga@arm.com#include "mem/cache/prefetch/queued.hh" 5913427Sodanrc@yahoo.com.br#include "mem/cache/replacement_policies/replaceable_entry.hh" 6012727Snikos.nikoleris@arm.com#include "mem/packet.hh" 6112727Snikos.nikoleris@arm.com 6213427Sodanrc@yahoo.com.brclass BaseReplacementPolicy; 6312727Snikos.nikoleris@arm.comstruct StridePrefetcherParams; 642810SN/A 6510623Smitch.hayenga@arm.comclass StridePrefetcher : public QueuedPrefetcher 662810SN/A{ 672810SN/A protected: 6810623Smitch.hayenga@arm.com const int maxConf; 6910623Smitch.hayenga@arm.com const int threshConf; 7010623Smitch.hayenga@arm.com const int minConf; 7110623Smitch.hayenga@arm.com const int startConf; 725875Ssteve.reinhardt@amd.com 7310623Smitch.hayenga@arm.com const int pcTableAssoc; 7410623Smitch.hayenga@arm.com const int pcTableSets; 755875Ssteve.reinhardt@amd.com 7610623Smitch.hayenga@arm.com const bool useMasterId; 7710623Smitch.hayenga@arm.com 7810623Smitch.hayenga@arm.com const int degree; 7910623Smitch.hayenga@arm.com 8013427Sodanrc@yahoo.com.br /** Replacement policy used in the PC tables. */ 8113427Sodanrc@yahoo.com.br BaseReplacementPolicy* replacementPolicy; 8213427Sodanrc@yahoo.com.br 8313427Sodanrc@yahoo.com.br struct StrideEntry : public ReplaceableEntry 842810SN/A { 8513426Sodanrc@yahoo.com.br /** Default constructor */ 8613426Sodanrc@yahoo.com.br StrideEntry(); 8713426Sodanrc@yahoo.com.br 8813426Sodanrc@yahoo.com.br /** Invalidate the entry */ 8913426Sodanrc@yahoo.com.br void invalidate(); 9010623Smitch.hayenga@arm.com 915875Ssteve.reinhardt@amd.com Addr instAddr; 9210623Smitch.hayenga@arm.com Addr lastAddr; 9310028SGiacomo.Gabrielli@arm.com bool isSecure; 942810SN/A int stride; 955875Ssteve.reinhardt@amd.com int confidence; 965875Ssteve.reinhardt@amd.com }; 972810SN/A 9810771Sstephan.diestelhorst@arm.com class PCTable 9910771Sstephan.diestelhorst@arm.com { 10010771Sstephan.diestelhorst@arm.com public: 10113425Sodanrc@yahoo.com.br /** 10213425Sodanrc@yahoo.com.br * Default constructor. Create a table with given parameters. 10313425Sodanrc@yahoo.com.br * 10413425Sodanrc@yahoo.com.br * @param assoc Associativity of the table. 10513425Sodanrc@yahoo.com.br * @param sets Number of sets in the table. 10613425Sodanrc@yahoo.com.br * @param name Name of the prefetcher. 10713427Sodanrc@yahoo.com.br * @param replacementPolicy Replacement policy used by the table. 10813425Sodanrc@yahoo.com.br */ 10913427Sodanrc@yahoo.com.br PCTable(int assoc, int sets, const std::string name, 11013427Sodanrc@yahoo.com.br BaseReplacementPolicy* replacementPolicy); 11113424Sodanrc@yahoo.com.br 11213425Sodanrc@yahoo.com.br /** 11313425Sodanrc@yahoo.com.br * Default destructor. 11413425Sodanrc@yahoo.com.br */ 11513425Sodanrc@yahoo.com.br ~PCTable(); 11610771Sstephan.diestelhorst@arm.com 11713425Sodanrc@yahoo.com.br /** 11813425Sodanrc@yahoo.com.br * Search for an entry in the pc table. 11913425Sodanrc@yahoo.com.br * 12013425Sodanrc@yahoo.com.br * @param pc The PC to look for. 12113425Sodanrc@yahoo.com.br * @param is_secure True if the target memory space is secure. 12213425Sodanrc@yahoo.com.br * @return Pointer to the entry. 12313425Sodanrc@yahoo.com.br */ 12413425Sodanrc@yahoo.com.br StrideEntry* findEntry(Addr pc, bool is_secure); 12510771Sstephan.diestelhorst@arm.com 12613425Sodanrc@yahoo.com.br /** 12713425Sodanrc@yahoo.com.br * Find a replacement victim to make room for given PC. 12813425Sodanrc@yahoo.com.br * 12913425Sodanrc@yahoo.com.br * @param pc The PC value. 13013425Sodanrc@yahoo.com.br * @return The victimized entry. 13113425Sodanrc@yahoo.com.br */ 13213425Sodanrc@yahoo.com.br StrideEntry* findVictim(Addr pc); 13313425Sodanrc@yahoo.com.br 13410771Sstephan.diestelhorst@arm.com private: 13510771Sstephan.diestelhorst@arm.com const std::string name() {return _name; } 13610771Sstephan.diestelhorst@arm.com const int pcTableSets; 13710771Sstephan.diestelhorst@arm.com const std::string _name; 13813425Sodanrc@yahoo.com.br std::vector<std::vector<StrideEntry>> entries; 13910771Sstephan.diestelhorst@arm.com 14013425Sodanrc@yahoo.com.br /** 14113427Sodanrc@yahoo.com.br * Replacement policy used by StridePrefetcher. 14213427Sodanrc@yahoo.com.br */ 14313427Sodanrc@yahoo.com.br BaseReplacementPolicy* replacementPolicy; 14413427Sodanrc@yahoo.com.br 14513427Sodanrc@yahoo.com.br /** 14613425Sodanrc@yahoo.com.br * PC hashing function to index sets in the table. 14713425Sodanrc@yahoo.com.br * 14813425Sodanrc@yahoo.com.br * @param pc The PC value. 14913425Sodanrc@yahoo.com.br * @return The set to which this PC maps. 15013425Sodanrc@yahoo.com.br */ 15113425Sodanrc@yahoo.com.br Addr pcHash(Addr pc) const; 15210771Sstephan.diestelhorst@arm.com }; 15313425Sodanrc@yahoo.com.br std::unordered_map<int, PCTable> pcTables; 1542810SN/A 15513423Sodanrc@yahoo.com.br /** 15613425Sodanrc@yahoo.com.br * Try to find a table of entries for the given context. If none is 15713425Sodanrc@yahoo.com.br * found, a new table is created. 15813423Sodanrc@yahoo.com.br * 15913425Sodanrc@yahoo.com.br * @param context The context to be searched for. 16013425Sodanrc@yahoo.com.br * @return The table corresponding to the given context. 16113423Sodanrc@yahoo.com.br */ 16213425Sodanrc@yahoo.com.br PCTable* findTable(int context); 16313423Sodanrc@yahoo.com.br 16413425Sodanrc@yahoo.com.br /** 16513425Sodanrc@yahoo.com.br * Create a PC table for the given context. 16613425Sodanrc@yahoo.com.br * 16713425Sodanrc@yahoo.com.br * @param context The context of the new PC table. 16813425Sodanrc@yahoo.com.br * @return The new PC table 16913425Sodanrc@yahoo.com.br */ 17013425Sodanrc@yahoo.com.br PCTable* allocateNewContext(int context); 17110053Smitch.hayenga+gem5@gmail.com 1722810SN/A public: 17310623Smitch.hayenga@arm.com StridePrefetcher(const StridePrefetcherParams *p); 1742810SN/A 17513551Sjavier.bueno@metempsy.com void calculatePrefetch(const PrefetchInfo &pfi, 17613422Sodanrc@yahoo.com.br std::vector<AddrPriority> &addresses) override; 1772810SN/A}; 1782810SN/A 17910623Smitch.hayenga@arm.com#endif // __MEM_CACHE_PREFETCH_STRIDE_HH__ 180