diff options
author | Giacomo Travaglini <giacomo.travaglini@arm.com> | 2018-05-10 14:37:27 +0100 |
---|---|---|
committer | Giacomo Travaglini <giacomo.travaglini@arm.com> | 2018-09-07 13:16:20 +0000 |
commit | 53cdcdee663c614d134174edea57b98a15385679 (patch) | |
tree | 0be8fe01736511047b22bb4732d3f61b72612c71 /src/sim/system.cc | |
parent | 8fee83d1ff0abf23226138c36a995dfe3ce70516 (diff) | |
download | gem5-53cdcdee663c614d134174edea57b98a15385679.tar.xz |
sim: Add System method for MasterID lookup
A new method (lookupMasterId) has been added to the System. A client
should use it when querying the System for the MasterID of a particular
master. It changes from getMasterId since it is
not registering a new MasterID if the master is not found in the
master's list.
Change-Id: I701158d22e235085bba9ab91154fbb702cae1467
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/11969
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'src/sim/system.cc')
-rw-r--r-- | src/sim/system.cc | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/src/sim/system.cc b/src/sim/system.cc index 74bc94ee8..fc2578f86 100644 --- a/src/sim/system.cc +++ b/src/sim/system.cc @@ -491,8 +491,55 @@ printSystems() System::printSystems(); } +std::string +System::stripSystemName(const std::string& master_name) const +{ + if (startswith(master_name, name())) { + return master_name.substr(name().size()); + } else { + return master_name; + } +} + +MasterID +System::lookupMasterId(const SimObject* obj) const +{ + MasterID id = Request::invldMasterId; + + // number of occurrences of the SimObject pointer + // in the master list. + auto obj_number = 0; + + for (int i = 0; i < masters.size(); i++) { + if (masters[i].obj == obj) { + id = i; + obj_number++; + } + } + + fatal_if(obj_number > 1, + "Cannot lookup MasterID by SimObject pointer: " + "More than one master is sharing the same SimObject\n"); + + return id; +} + +MasterID +System::lookupMasterId(const std::string& master_name) const +{ + std::string name = stripSystemName(master_name); + + for (int i = 0; i < masters.size(); i++) { + if (masters[i].masterName == name) { + return i; + } + } + + return Request::invldMasterId; +} + MasterID -System::getGlobalMasterId(std::string master_name) +System::getGlobalMasterId(const std::string& master_name) { return _getMasterId(nullptr, master_name); } @@ -505,14 +552,13 @@ System::getMasterId(const SimObject* master, std::string submaster) } MasterID -System::_getMasterId(const SimObject* master, std::string master_name) +System::_getMasterId(const SimObject* master, const std::string& master_name) { - if (startswith(master_name, name())) - master_name = master_name.erase(0, name().size() + 1); + std::string name = stripSystemName(master_name); // CPUs in switch_cpus ask for ids again after switching for (int i = 0; i < masters.size(); i++) { - if (masters[i].masterName == master_name) { + if (masters[i].masterName == name) { return i; } } @@ -530,7 +576,7 @@ System::_getMasterId(const SimObject* master, std::string master_name) MasterID master_id = masters.size(); // Append the new Master metadata to the group of system Masters. - masters.emplace_back(master, master_name, master_id); + masters.emplace_back(master, name, master_id); return masters.back().masterId; } |