stride.hh revision 3349
12810SN/A/*
212724Snikos.nikoleris@arm.com * Copyright (c) 2005 The Regents of The University of Michigan
38856Sandreas.hansson@arm.com * All rights reserved.
48856Sandreas.hansson@arm.com *
58856Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without
68856Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are
78856Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright
88856Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer;
98856Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright
108856Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the
118856Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution;
128856Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its
138856Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from
142810SN/A * this software without specific prior written permission.
152810SN/A *
162810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272810SN/A *
282810SN/A * Authors: Ron Dreslinski
292810SN/A */
302810SN/A
312810SN/A/**
322810SN/A * @file
332810SN/A * Describes a strided prefetcher based on template policies.
342810SN/A */
352810SN/A
362810SN/A#ifndef __MEM_CACHE_PREFETCH_STRIDE_PREFETCHER_HH__
372810SN/A#define __MEM_CACHE_PREFETCH_STRIDE_PREFETCHER_HH__
382810SN/A
392810SN/A#include "base/misc.hh" // fatal, panic, and warn
402810SN/A
4112724Snikos.nikoleris@arm.com#include "mem/cache/prefetch/prefetcher.hh"
422810SN/A
432810SN/A/**
442810SN/A * A template-policy based cache. The behavior of the cache can be altered by
452810SN/A * supplying different template policies. TagStore handles all tag and data
462810SN/A * storage @sa TagStore. Buffering handles all misses and writes/writebacks
472810SN/A * @sa MissQueue. Coherence handles all coherence policy details @sa
482810SN/A * UniCoherence, SimpleMultiCoherence.
4911486Snikos.nikoleris@arm.com */
5011486Snikos.nikoleris@arm.comtemplate <class TagStore, class Buffering>
5112724Snikos.nikoleris@arm.comclass StridePrefetcher : public Prefetcher<TagStore, Buffering>
5212724Snikos.nikoleris@arm.com{
538232Snate@binkert.org  protected:
5412724Snikos.nikoleris@arm.com
5513222Sodanrc@yahoo.com.br    Buffering* mq;
5612724Snikos.nikoleris@arm.com    TagStore* tags;
5711486Snikos.nikoleris@arm.com
5812724Snikos.nikoleris@arm.com    class strideEntry
5912724Snikos.nikoleris@arm.com    {
6012724Snikos.nikoleris@arm.com      public:
6113352Snikos.nikoleris@arm.com        Addr IAddr;
6212724Snikos.nikoleris@arm.com        Addr MAddr;
6312724Snikos.nikoleris@arm.com        int stride;
6412724Snikos.nikoleris@arm.com        int64_t confidence;
6512724Snikos.nikoleris@arm.com
662810SN/A/*	bool operator < (strideEntry a,strideEntry b)
672810SN/A        {
682810SN/A            if (a.confidence == b.confidence) {
698856Sandreas.hansson@arm.com                return true; //??????
708856Sandreas.hansson@arm.com            }
718856Sandreas.hansson@arm.com            else return a.confidence < b.confidence;
728922Swilliam.wang@arm.com            }*/
7312084Sspwilson2@wisc.edu    };
7412084Sspwilson2@wisc.edu    Addr* lastMissAddr[64/*MAX_CPUS*/];
758856Sandreas.hansson@arm.com
768856Sandreas.hansson@arm.com    std::list<strideEntry*> table[64/*MAX_CPUS*/];
774475SN/A    Tick latency;
7811053Sandreas.hansson@arm.com    int degree;
795034SN/A    bool useCPUId;
8012724Snikos.nikoleris@arm.com
8112724Snikos.nikoleris@arm.com
8211377Sandreas.hansson@arm.com  public:
8311377Sandreas.hansson@arm.com
8412724Snikos.nikoleris@arm.com    StridePrefetcher(int size, bool pageStop, bool serialSquash,
8512724Snikos.nikoleris@arm.com                     bool cacheCheckPush, bool onlyData,
8613352Snikos.nikoleris@arm.com                     Tick latency, int degree, bool useCPUId)
8712724Snikos.nikoleris@arm.com        :Prefetcher<TagStore, Buffering>(size, pageStop, serialSquash,
8812724Snikos.nikoleris@arm.com                                         cacheCheckPush, onlyData),
8912724Snikos.nikoleris@arm.com         latency(latency), degree(degree), useCPUId(useCPUId)
9012724Snikos.nikoleris@arm.com    {
9112724Snikos.nikoleris@arm.com    }
9211053Sandreas.hansson@arm.com
9311722Ssophiane.senni@gmail.com    ~StridePrefetcher() {}
9411722Ssophiane.senni@gmail.com
9511722Ssophiane.senni@gmail.com    void calculatePrefetch(PacketPtr &pkt, std::list<Addr> &addresses,
9611722Ssophiane.senni@gmail.com                           std::list<Tick> &delays)
979263Smrinmoy.ghosh@arm.com    {
9813418Sodanrc@yahoo.com.br//	Addr blkAddr = pkt->paddr & ~(Addr)(this->blkSize-1);
995034SN/A        int cpuID = pkt->req->getCpuNum();
10011331Sandreas.hansson@arm.com        if (!useCPUId) cpuID = 0;
10112724Snikos.nikoleris@arm.com
10210884Sandreas.hansson@arm.com        /* Scan Table for IAddr Match */
1034626SN/A/*	std::list<strideEntry*>::iterator iter;
10410360Sandreas.hansson@arm.com        for (iter=table[cpuID].begin();
10511484Snikos.nikoleris@arm.com             iter !=table[cpuID].end();
1065034SN/A             iter++) {
1078883SAli.Saidi@ARM.com            if ((*iter)->IAddr == pkt->pc) break;
1088833Sdam.sunwoo@arm.com        }
1094458SN/A
11011377Sandreas.hansson@arm.com        if (iter != table[cpuID].end()) {
11111377Sandreas.hansson@arm.com            //Hit in table
11211377Sandreas.hansson@arm.com
11311377Sandreas.hansson@arm.com            int newStride = blkAddr - (*iter)->MAddr;
11411377Sandreas.hansson@arm.com            if (newStride == (*iter)->stride) {
11511377Sandreas.hansson@arm.com                (*iter)->confidence++;
11611331Sandreas.hansson@arm.com            }
11711331Sandreas.hansson@arm.com            else {
11812724Snikos.nikoleris@arm.com                (*iter)->stride = newStride;
11912843Srmk35@cl.cam.ac.uk                (*iter)->confidence--;
12012724Snikos.nikoleris@arm.com            }
12113419Sodanrc@yahoo.com.br
12212724Snikos.nikoleris@arm.com            (*iter)->MAddr = blkAddr;
12312724Snikos.nikoleris@arm.com
12412724Snikos.nikoleris@arm.com            for (int d=1; d <= degree; d++) {
12512724Snikos.nikoleris@arm.com                Addr newAddr = blkAddr + d * newStride;
12612724Snikos.nikoleris@arm.com                if (this->pageStop &&
12712724Snikos.nikoleris@arm.com                    (blkAddr & ~(TheISA::VMPageSize - 1)) !=
12812724Snikos.nikoleris@arm.com                    (newAddr & ~(TheISA::VMPageSize - 1)))
1292810SN/A                {
1302810SN/A                    //Spanned the page, so now stop
1313013SN/A                    this->pfSpanPage += degree - d + 1;
1328856Sandreas.hansson@arm.com                    return;
1332810SN/A                }
1343013SN/A                else
13510714Sandreas.hansson@arm.com                {
1362810SN/A                    addresses.push_back(newAddr);
1379614Srene.dejong@arm.com                    delays.push_back(latency);
1389614Srene.dejong@arm.com                }
1399614Srene.dejong@arm.com            }
14010345SCurtis.Dunham@arm.com        }
14110714Sandreas.hansson@arm.com        else {
14210345SCurtis.Dunham@arm.com            //Miss in table
1439614Srene.dejong@arm.com            //Find lowest confidence and replace
1442810SN/A
1452810SN/A        }
1462810SN/A*/    }
1478856Sandreas.hansson@arm.com};
1482810SN/A
1493013SN/A#endif // __MEM_CACHE_PREFETCH_STRIDE_PREFETCHER_HH__
15010714Sandreas.hansson@arm.com