base.cc revision 12703
12810SN/A/*
211893Snikos.nikoleris@arm.com * Copyright (c) 2013,2016 ARM Limited
39796Sprakash.ramrakhyani@arm.com * All rights reserved.
49796Sprakash.ramrakhyani@arm.com *
59796Sprakash.ramrakhyani@arm.com * The license below extends only to copyright in the software and shall
69796Sprakash.ramrakhyani@arm.com * not be construed as granting a license to any other intellectual
79796Sprakash.ramrakhyani@arm.com * property including but not limited to intellectual property relating
89796Sprakash.ramrakhyani@arm.com * to a hardware implementation of the functionality of the software
99796Sprakash.ramrakhyani@arm.com * licensed hereunder.  You may use the software subject to the license
109796Sprakash.ramrakhyani@arm.com * terms below provided that you ensure that this notice is replicated
119796Sprakash.ramrakhyani@arm.com * unmodified and in its entirety in all distributions of the software,
129796Sprakash.ramrakhyani@arm.com * modified or unmodified, in source code or in binary form.
139796Sprakash.ramrakhyani@arm.com *
142810SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan
152810SN/A * All rights reserved.
162810SN/A *
172810SN/A * Redistribution and use in source and binary forms, with or without
182810SN/A * modification, are permitted provided that the following conditions are
192810SN/A * met: redistributions of source code must retain the above copyright
202810SN/A * notice, this list of conditions and the following disclaimer;
212810SN/A * redistributions in binary form must reproduce the above copyright
222810SN/A * notice, this list of conditions and the following disclaimer in the
232810SN/A * documentation and/or other materials provided with the distribution;
242810SN/A * neither the name of the copyright holders nor the names of its
252810SN/A * contributors may be used to endorse or promote products derived from
262810SN/A * this software without specific prior written permission.
272810SN/A *
282810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392810SN/A *
402810SN/A * Authors: Erik Hallnor
412810SN/A *          Ron Dreslinski
422810SN/A */
432810SN/A
442810SN/A/**
452810SN/A * @file
462810SN/A * Definitions of BaseTags.
472810SN/A */
482810SN/A
4911486Snikos.nikoleris@arm.com#include "mem/cache/tags/base.hh"
5011486Snikos.nikoleris@arm.com
515338Sstever@gmail.com#include "mem/cache/base.hh"
522810SN/A#include "sim/sim_exit.hh"
532810SN/A
549796Sprakash.ramrakhyani@arm.comBaseTags::BaseTags(const Params *p)
5511893Snikos.nikoleris@arm.com    : ClockedObject(p), blkSize(p->block_size), blkMask(blkSize - 1),
5611893Snikos.nikoleris@arm.com      size(p->size),
5711722Ssophiane.senni@gmail.com      lookupLatency(p->tag_latency),
5811722Ssophiane.senni@gmail.com      accessLatency(p->sequential_access ?
5911722Ssophiane.senni@gmail.com                    p->tag_latency + p->data_latency :
6011722Ssophiane.senni@gmail.com                    std::max(p->tag_latency, p->data_latency)),
6112513Sodanrc@yahoo.com.br      cache(nullptr),
6212513Sodanrc@yahoo.com.br      warmupBound((p->warmup_percentage/100.0) * (p->size / p->block_size)),
6312629Sodanrc@yahoo.com.br      warmedUp(false), numBlocks(p->size / p->block_size),
6412629Sodanrc@yahoo.com.br      dataBlks(new uint8_t[p->size]) // Allocate data storage in one big chunk
659796Sprakash.ramrakhyani@arm.com{
669796Sprakash.ramrakhyani@arm.com}
679796Sprakash.ramrakhyani@arm.com
682810SN/Avoid
692810SN/ABaseTags::setCache(BaseCache *_cache)
702810SN/A{
7110360Sandreas.hansson@arm.com    assert(!cache);
722810SN/A    cache = _cache;
732810SN/A}
742810SN/A
752810SN/Avoid
7612636Sodanrc@yahoo.com.brBaseTags::insertBlock(PacketPtr pkt, CacheBlk *blk)
7712636Sodanrc@yahoo.com.br{
7812636Sodanrc@yahoo.com.br    // Get address
7912636Sodanrc@yahoo.com.br    Addr addr = pkt->getAddr();
8012636Sodanrc@yahoo.com.br
8112636Sodanrc@yahoo.com.br    // If we're replacing a block that was previously valid update
8212636Sodanrc@yahoo.com.br    // stats for it. This can't be done in findBlock() because a
8312636Sodanrc@yahoo.com.br    // found block might not actually be replaced there if the
8412636Sodanrc@yahoo.com.br    // coherence protocol says it can't be.
8512636Sodanrc@yahoo.com.br    if (blk->isValid()) {
8612636Sodanrc@yahoo.com.br        totalRefs += blk->refCount;
8712636Sodanrc@yahoo.com.br        ++sampledRefs;
8812636Sodanrc@yahoo.com.br
8912636Sodanrc@yahoo.com.br        invalidate(blk);
9012636Sodanrc@yahoo.com.br        blk->invalidate();
9112636Sodanrc@yahoo.com.br    }
9212636Sodanrc@yahoo.com.br
9312636Sodanrc@yahoo.com.br    // Previous block, if existed, has been removed, and now we have
9412636Sodanrc@yahoo.com.br    // to insert the new one
9512636Sodanrc@yahoo.com.br
9612636Sodanrc@yahoo.com.br    // Deal with what we are bringing in
9712636Sodanrc@yahoo.com.br    MasterID master_id = pkt->req->masterId();
9812636Sodanrc@yahoo.com.br    assert(master_id < cache->system->maxMasters());
9912636Sodanrc@yahoo.com.br    occupancies[master_id]++;
10012636Sodanrc@yahoo.com.br
10112691Sodanrc@yahoo.com.br    // Insert block with tag, src master id and task id
10212691Sodanrc@yahoo.com.br    blk->insert(extractTag(addr), pkt->isSecure(), master_id,
10312691Sodanrc@yahoo.com.br                pkt->req->taskId());
10412636Sodanrc@yahoo.com.br
10512703Snikos.nikoleris@arm.com    tagsInUse++;
10612703Snikos.nikoleris@arm.com    if (!warmedUp && tagsInUse.value() >= warmupBound) {
10712703Snikos.nikoleris@arm.com        warmedUp = true;
10812703Snikos.nikoleris@arm.com        warmupCycle = curTick();
10912703Snikos.nikoleris@arm.com    }
11012703Snikos.nikoleris@arm.com
11112636Sodanrc@yahoo.com.br    // We only need to write into one tag and one data block.
11212636Sodanrc@yahoo.com.br    tagAccesses += 1;
11312636Sodanrc@yahoo.com.br    dataAccesses += 1;
11412636Sodanrc@yahoo.com.br}
11512636Sodanrc@yahoo.com.br
11612636Sodanrc@yahoo.com.brvoid
1179796Sprakash.ramrakhyani@arm.comBaseTags::regStats()
1182810SN/A{
11911522Sstephan.diestelhorst@arm.com    ClockedObject::regStats();
12011522Sstephan.diestelhorst@arm.com
1212810SN/A    using namespace Stats;
12211522Sstephan.diestelhorst@arm.com
1232810SN/A    tagsInUse
1249796Sprakash.ramrakhyani@arm.com        .name(name() + ".tagsinuse")
1252810SN/A        .desc("Cycle average of tags in use")
1262810SN/A        ;
1272810SN/A
1282810SN/A    totalRefs
1299796Sprakash.ramrakhyani@arm.com        .name(name() + ".total_refs")
1302810SN/A        .desc("Total number of references to valid blocks.")
1312810SN/A        ;
1322810SN/A
1332810SN/A    sampledRefs
1349796Sprakash.ramrakhyani@arm.com        .name(name() + ".sampled_refs")
1352810SN/A        .desc("Sample count of references to valid blocks.")
1362810SN/A        ;
1372810SN/A
1382810SN/A    avgRefs
1399796Sprakash.ramrakhyani@arm.com        .name(name() + ".avg_refs")
1402810SN/A        .desc("Average number of references to valid blocks.")
1412810SN/A        ;
1422810SN/A
1432810SN/A    avgRefs = totalRefs/sampledRefs;
1442810SN/A
1452810SN/A    warmupCycle
1469796Sprakash.ramrakhyani@arm.com        .name(name() + ".warmup_cycle")
1472810SN/A        .desc("Cycle when the warmup percentage was hit.")
1482810SN/A        ;
1492810SN/A
1506978SLisa.Hsu@amd.com    occupancies
1518833Sdam.sunwoo@arm.com        .init(cache->system->maxMasters())
1529796Sprakash.ramrakhyani@arm.com        .name(name() + ".occ_blocks")
1538833Sdam.sunwoo@arm.com        .desc("Average occupied blocks per requestor")
1546978SLisa.Hsu@amd.com        .flags(nozero | nonan)
1556978SLisa.Hsu@amd.com        ;
1568833Sdam.sunwoo@arm.com    for (int i = 0; i < cache->system->maxMasters(); i++) {
1578833Sdam.sunwoo@arm.com        occupancies.subname(i, cache->system->getMasterName(i));
1588833Sdam.sunwoo@arm.com    }
1596978SLisa.Hsu@amd.com
1606978SLisa.Hsu@amd.com    avgOccs
1619796Sprakash.ramrakhyani@arm.com        .name(name() + ".occ_percent")
1626978SLisa.Hsu@amd.com        .desc("Average percentage of cache occupancy")
1638833Sdam.sunwoo@arm.com        .flags(nozero | total)
1646978SLisa.Hsu@amd.com        ;
1658833Sdam.sunwoo@arm.com    for (int i = 0; i < cache->system->maxMasters(); i++) {
1668833Sdam.sunwoo@arm.com        avgOccs.subname(i, cache->system->getMasterName(i));
1678833Sdam.sunwoo@arm.com    }
1686978SLisa.Hsu@amd.com
1696978SLisa.Hsu@amd.com    avgOccs = occupancies / Stats::constant(numBlocks);
1706978SLisa.Hsu@amd.com
17110024Sdam.sunwoo@arm.com    occupanciesTaskId
17210024Sdam.sunwoo@arm.com        .init(ContextSwitchTaskId::NumTaskId)
17310024Sdam.sunwoo@arm.com        .name(name() + ".occ_task_id_blocks")
17410024Sdam.sunwoo@arm.com        .desc("Occupied blocks per task id")
17510024Sdam.sunwoo@arm.com        .flags(nozero | nonan)
17610024Sdam.sunwoo@arm.com        ;
17710024Sdam.sunwoo@arm.com
17810024Sdam.sunwoo@arm.com    ageTaskId
17910024Sdam.sunwoo@arm.com        .init(ContextSwitchTaskId::NumTaskId, 5)
18010024Sdam.sunwoo@arm.com        .name(name() + ".age_task_id_blocks")
18110024Sdam.sunwoo@arm.com        .desc("Occupied blocks per task id")
18210024Sdam.sunwoo@arm.com        .flags(nozero | nonan)
18310024Sdam.sunwoo@arm.com        ;
18410024Sdam.sunwoo@arm.com
18510024Sdam.sunwoo@arm.com    percentOccsTaskId
18610024Sdam.sunwoo@arm.com        .name(name() + ".occ_task_id_percent")
18710024Sdam.sunwoo@arm.com        .desc("Percentage of cache occupancy per task id")
18810024Sdam.sunwoo@arm.com        .flags(nozero)
18910024Sdam.sunwoo@arm.com        ;
19010024Sdam.sunwoo@arm.com
19110024Sdam.sunwoo@arm.com    percentOccsTaskId = occupanciesTaskId / Stats::constant(numBlocks);
19210024Sdam.sunwoo@arm.com
19310025Stimothy.jones@arm.com    tagAccesses
19410025Stimothy.jones@arm.com        .name(name() + ".tag_accesses")
19510025Stimothy.jones@arm.com        .desc("Number of tag accesses")
19610025Stimothy.jones@arm.com        ;
19710025Stimothy.jones@arm.com
19810025Stimothy.jones@arm.com    dataAccesses
19910025Stimothy.jones@arm.com        .name(name() + ".data_accesses")
20010025Stimothy.jones@arm.com        .desc("Number of data accesses")
20110025Stimothy.jones@arm.com        ;
20210025Stimothy.jones@arm.com
20310024Sdam.sunwoo@arm.com    registerDumpCallback(new BaseTagsDumpCallback(this));
2042810SN/A    registerExitCallback(new BaseTagsCallback(this));
2052810SN/A}
206