diff options
Diffstat (limited to 'src/sim')
-rw-r--r-- | src/sim/system.cc | 50 | ||||
-rw-r--r-- | src/sim/system.hh | 67 |
2 files changed, 95 insertions, 22 deletions
diff --git a/src/sim/system.cc b/src/sim/system.cc index 38eed1c2a..911ee5d9b 100644 --- a/src/sim/system.cc +++ b/src/sim/system.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014,2017 ARM Limited + * Copyright (c) 2011-2014,2017-2018 ARM Limited * All rights reserved * * The license below extends only to copyright in the software and shall @@ -135,11 +135,11 @@ System::System(Params *p) // Get the generic system master IDs MasterID tmp_id M5_VAR_USED; - tmp_id = getMasterId("writebacks"); + tmp_id = getMasterId(this, "writebacks"); assert(tmp_id == Request::wbMasterId); - tmp_id = getMasterId("functional"); + tmp_id = getMasterId(this, "functional"); assert(tmp_id == Request::funcMasterId); - tmp_id = getMasterId("interrupt"); + tmp_id = getMasterId(this, "interrupt"); assert(tmp_id == Request::intMasterId); if (FullSystem) { @@ -492,15 +492,27 @@ printSystems() } MasterID -System::getMasterId(std::string master_name) +System::getGlobalMasterId(std::string master_name) +{ + return _getMasterId(nullptr, master_name); +} + +MasterID +System::getMasterId(const SimObject* master, std::string submaster) +{ + auto master_name = leafMasterName(master, submaster); + return _getMasterId(master, master_name); +} + +MasterID +System::_getMasterId(const SimObject* master, std::string master_name) { - // strip off system name if the string starts with it if (startswith(master_name, name())) master_name = master_name.erase(0, name().size() + 1); // CPUs in switch_cpus ask for ids again after switching - for (int i = 0; i < masterIds.size(); i++) { - if (masterIds[i] == master_name) { + for (int i = 0; i < masters.size(); i++) { + if (masters[i].masterName == master_name) { return i; } } @@ -514,18 +526,32 @@ System::getMasterId(std::string master_name) "You must do so in init().\n"); } - masterIds.push_back(master_name); + // Generate a new MasterID incrementally + MasterID master_id = masters.size(); + + // Append the new Master metadata to the group of system Masters. + masters.emplace_back(master, master_name, master_id); + + return masters.back().masterId; +} - return masterIds.size() - 1; +std::string +System::leafMasterName(const SimObject* master, const std::string& submaster) +{ + // Get the full master name by appending the submaster name to + // the root SimObject master name + auto master_name = master->name() + "." + submaster; + return master_name; } std::string System::getMasterName(MasterID master_id) { - if (master_id >= masterIds.size()) + if (master_id >= masters.size()) fatal("Invalid master_id passed to getMasterName()\n"); - return masterIds[master_id]; + const auto& master_info = masters[master_id]; + return master_info.masterName; } System * diff --git a/src/sim/system.hh b/src/sim/system.hh index a72f2a762..0d26ffa0d 100644 --- a/src/sim/system.hh +++ b/src/sim/system.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014 ARM Limited + * Copyright (c) 2012, 2014, 2018 ARM Limited * All rights reserved * * The license below extends only to copyright in the software and shall @@ -57,6 +57,7 @@ #include "base/statistics.hh" #include "config/the_isa.hh" #include "enums/MemoryMode.hh" +#include "mem/mem_master.hh" #include "mem/mem_object.hh" #include "mem/physical.hh" #include "mem/port.hh" @@ -320,31 +321,77 @@ class System : public MemObject * It's used to uniquely id any master in the system by name for things * like cache statistics. */ - std::vector<std::string> masterIds; + std::vector<MasterInfo> masters; ThermalModel * thermalModel; public: - /** Request an id used to create a request object in the system. All objects + /** + * Request an id used to create a request object in the system. All objects * that intend to issues requests into the memory system must request an id * in the init() phase of startup. All master ids must be fixed by the * regStats() phase that immediately precedes it. This allows objects in * the memory system to understand how many masters may exist and * appropriately name the bins of their per-master stats before the stats - * are finalized + * are finalized. + * + * Registers a MasterID: + * This method takes two parameters, one of which is optional. + * The first one is the master object, and it is compulsory; in case + * a object has multiple (sub)masters, a second parameter must be + * provided and it contains the name of the submaster. The method will + * create a master's name by concatenating the SimObject name with the + * eventual submaster string, separated by a dot. + * + * As an example: + * For a cpu having two masters: a data master and an instruction master, + * the method must be called twice: + * + * instMasterId = getMasterId(cpu, "inst"); + * dataMasterId = getMasterId(cpu, "data"); + * + * and the masters' names will be: + * - "cpu.inst" + * - "cpu.data" + * + * @param master SimObject related to the master + * @param submaster String containing the submaster's name + * @return the master's ID. + */ + MasterID getMasterId(const SimObject* master, + std::string submaster = std::string()); + + /** + * Registers a GLOBAL MasterID, which is a MasterID not related + * to any particular SimObject; since no SimObject is passed, + * the master gets registered by providing the full master name. + * + * @param masterName full name of the master + * @return the master's ID. */ - MasterID getMasterId(std::string req_name); + MasterID getGlobalMasterId(std::string master_name); - /** Get the name of an object for a given request id. + /** + * Get the name of an object for a given request id. */ std::string getMasterName(MasterID master_id); /** Get the number of masters registered in the system */ - MasterID maxMasters() - { - return masterIds.size(); - } + MasterID maxMasters() { return masters.size(); } + + protected: + /** helper function for getMasterId */ + MasterID _getMasterId(const SimObject* master, std::string master_name); + + /** + * Helper function for constructing the full (sub)master name + * by providing the root master and the relative submaster name. + */ + std::string leafMasterName(const SimObject* master, + const std::string& submaster); + + public: void regStats() override; /** |