store_set.cc

来自「M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作」· CC 代码 · 共 349 行

CC
349
字号
/* * Copyright (c) 2004, 2005, 2006 * The Regents of The University of Michigan * All Rights Reserved * * This code is part of the M5 simulator. * * Permission is granted to use, copy, create derivative works and * redistribute this software and such derivative works for any * purpose, so long as the copyright notice above, this grant of * permission, and the disclaimer below appear in all copies made; and * so long as the name of The University of Michigan is not used in * any advertising or publicity pertaining to the use or distribution * of this software without specific, written prior authorization. * * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND * WITHOUT WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE. THE REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE * LIABLE FOR ANY DAMAGES, INCLUDING DIRECT, SPECIAL, INDIRECT, * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM * ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH * DAMAGES. * * Authors: Kevin T. Lim */#include "base/intmath.hh"#include "base/misc.hh"#include "base/trace.hh"#include "cpu/o3/store_set.hh"StoreSet::StoreSet(int _SSIT_size, int _LFST_size)    : SSITSize(_SSIT_size), LFSTSize(_LFST_size){    DPRINTF(StoreSet, "StoreSet: Creating store set object.\n");    DPRINTF(StoreSet, "StoreSet: SSIT size: %i, LFST size: %i.\n",            SSITSize, LFSTSize);    if (!isPowerOf2(SSITSize)) {        fatal("Invalid SSIT size!\n");    }    SSIT.resize(SSITSize);    validSSIT.resize(SSITSize);    for (int i = 0; i < SSITSize; ++i)        validSSIT[i] = false;    if (!isPowerOf2(LFSTSize)) {        fatal("Invalid LFST size!\n");    }    LFST.resize(LFSTSize);    validLFST.resize(LFSTSize);    for (int i = 0; i < LFSTSize; ++i) {        validLFST[i] = false;        LFST[i] = 0;    }    indexMask = SSITSize - 1;    offsetBits = 2;}StoreSet::~StoreSet(){}voidStoreSet::init(int _SSIT_size, int _LFST_size){    SSITSize = _SSIT_size;    LFSTSize = _LFST_size;    DPRINTF(StoreSet, "StoreSet: Creating store set object.\n");    DPRINTF(StoreSet, "StoreSet: SSIT size: %i, LFST size: %i.\n",            SSITSize, LFSTSize);    SSIT.resize(SSITSize);    validSSIT.resize(SSITSize);    for (int i = 0; i < SSITSize; ++i)        validSSIT[i] = false;    LFST.resize(LFSTSize);    validLFST.resize(LFSTSize);    for (int i = 0; i < LFSTSize; ++i) {        validLFST[i] = false;        LFST[i] = 0;    }    indexMask = SSITSize - 1;    offsetBits = 2;}voidStoreSet::violation(Addr store_PC, Addr load_PC){    int load_index = calcIndex(load_PC);    int store_index = calcIndex(store_PC);    assert(load_index < SSITSize && store_index < SSITSize);    bool valid_load_SSID = validSSIT[load_index];    bool valid_store_SSID = validSSIT[store_index];    if (!valid_load_SSID && !valid_store_SSID) {        // Calculate a new SSID here.        SSID new_set = calcSSID(load_PC);        validSSIT[load_index] = true;        SSIT[load_index] = new_set;        validSSIT[store_index] = true;        SSIT[store_index] = new_set;        assert(new_set < LFSTSize);        DPRINTF(StoreSet, "StoreSet: Neither load nor store had a valid "                "storeset, creating a new one: %i for load %#x, store %#x\n",                new_set, load_PC, store_PC);    } else if (valid_load_SSID && !valid_store_SSID) {        SSID load_SSID = SSIT[load_index];        validSSIT[store_index] = true;        SSIT[store_index] = load_SSID;        assert(load_SSID < LFSTSize);        DPRINTF(StoreSet, "StoreSet: Load had a valid store set.  Adding "                "store to that set: %i for load %#x, store %#x\n",                load_SSID, load_PC, store_PC);    } else if (!valid_load_SSID && valid_store_SSID) {        SSID store_SSID = SSIT[store_index];        validSSIT[load_index] = true;        SSIT[load_index] = store_SSID;        DPRINTF(StoreSet, "StoreSet: Store had a valid store set: %i for "                "load %#x, store %#x\n",                store_SSID, load_PC, store_PC);    } else {        SSID load_SSID = SSIT[load_index];        SSID store_SSID = SSIT[store_index];        assert(load_SSID < LFSTSize && store_SSID < LFSTSize);        // The store set with the lower number wins        if (store_SSID > load_SSID) {            SSIT[store_index] = load_SSID;            DPRINTF(StoreSet, "StoreSet: Load had smaller store set: %i; "                    "for load %#x, store %#x\n",                    load_SSID, load_PC, store_PC);        } else {            SSIT[load_index] = store_SSID;            DPRINTF(StoreSet, "StoreSet: Store had smaller store set: %i; "                    "for load %#x, store %#x\n",                    store_SSID, load_PC, store_PC);        }    }}voidStoreSet::insertLoad(Addr load_PC, InstSeqNum load_seq_num){    // Does nothing.    return;}voidStoreSet::insertStore(Addr store_PC, InstSeqNum store_seq_num,                      unsigned tid){    int index = calcIndex(store_PC);    int store_SSID;    assert(index < SSITSize);    if (!validSSIT[index]) {        // Do nothing if there's no valid entry.        return;    } else {        store_SSID = SSIT[index];        assert(store_SSID < LFSTSize);        // Update the last store that was fetched with the current one.        LFST[store_SSID] = store_seq_num;        validLFST[store_SSID] = 1;        storeList[store_seq_num] = store_SSID;        DPRINTF(StoreSet, "Store %#x updated the LFST, SSID: %i\n",                store_PC, store_SSID);    }}InstSeqNumStoreSet::checkInst(Addr PC){    int index = calcIndex(PC);    int inst_SSID;    assert(index < SSITSize);    if (!validSSIT[index]) {        DPRINTF(StoreSet, "Inst %#x with index %i had no SSID\n",                PC, index);        // Return 0 if there's no valid entry.        return 0;    } else {        inst_SSID = SSIT[index];        assert(inst_SSID < LFSTSize);        if (!validLFST[inst_SSID]) {            DPRINTF(StoreSet, "Inst %#x with index %i and SSID %i had no "                    "dependency\n", PC, index, inst_SSID);            return 0;        } else {            DPRINTF(StoreSet, "Inst %#x with index %i and SSID %i had LFST "                    "inum of %i\n", PC, index, inst_SSID, LFST[inst_SSID]);            return LFST[inst_SSID];        }    }}voidStoreSet::issued(Addr issued_PC, InstSeqNum issued_seq_num, bool is_store){    // This only is updated upon a store being issued.    if (!is_store) {        return;    }    int index = calcIndex(issued_PC);    int store_SSID;    assert(index < SSITSize);    SeqNumMapIt store_list_it = storeList.find(issued_seq_num);    if (store_list_it != storeList.end()) {        storeList.erase(store_list_it);    }    // Make sure the SSIT still has a valid entry for the issued store.    if (!validSSIT[index]) {        return;    }    store_SSID = SSIT[index];    assert(store_SSID < LFSTSize);    // If the last fetched store in the store set refers to the store that    // was just issued, then invalidate the entry.    if (validLFST[store_SSID] && LFST[store_SSID] == issued_seq_num) {        DPRINTF(StoreSet, "StoreSet: store invalidated itself in LFST.\n");        validLFST[store_SSID] = false;    }}voidStoreSet::squash(InstSeqNum squashed_num, unsigned tid){    DPRINTF(StoreSet, "StoreSet: Squashing until inum %i\n",            squashed_num);    int idx;    SeqNumMapIt store_list_it = storeList.begin();    //@todo:Fix to only delete from correct thread    while (!storeList.empty()) {        idx = (*store_list_it).second;        if ((*store_list_it).first <= squashed_num) {            break;        }        bool younger = LFST[idx] > squashed_num;        if (validLFST[idx] && younger) {            DPRINTF(StoreSet, "Squashed [sn:%lli]\n", LFST[idx]);            validLFST[idx] = false;            storeList.erase(store_list_it++);        } else if (!validLFST[idx] && younger) {            storeList.erase(store_list_it++);        }    }}voidStoreSet::clear(){    for (int i = 0; i < SSITSize; ++i) {        validSSIT[i] = false;    }    for (int i = 0; i < LFSTSize; ++i) {        validLFST[i] = false;    }    storeList.clear();}voidStoreSet::dump(){    cprintf("storeList.size(): %i\n", storeList.size());    SeqNumMapIt store_list_it = storeList.begin();    int num = 0;    while (store_list_it != storeList.end()) {        cprintf("%i: [sn:%lli] SSID:%i\n",                num, (*store_list_it).first, (*store_list_it).second);        num++;        store_list_it++;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?