Refactored PoolControllerMap.

This commit is contained in:
Iron Prando da Silva
2022-02-15 10:45:54 +01:00
parent 8ad9cb05f7
commit 8c3f4349ba
12 changed files with 128 additions and 50 deletions

View File

@@ -112,8 +112,10 @@ add_executable(TraceAnalyzer
simulationdialog.cpp
businessObjects/dependencymodels.cpp
businessObjects/dramTimeDependencies/common/common.cpp
businessObjects/dramTimeDependencies/dbEntries/DDR3dbphaseentry.cpp
businessObjects/dramTimeDependencies/deviceDependencies/activatewindowpoolcontroller.cpp
businessObjects/dramTimeDependencies/deviceDependencies/poolcontroller.cpp
businessObjects/dramTimeDependencies/deviceDependencies/poolcontrollermap.cpp
businessObjects/dramTimeDependencies/deviceDependencies/dramtimedependenciesIF.cpp
businessObjects/dramTimeDependencies/deviceDependencies/DDR3TimeDependencies.cpp
businessObjects/dramTimeDependencies/configurations/configurationfactory.cpp

View File

@@ -0,0 +1,10 @@
#include "common.h"
bool QStringsComparator::operator()(const QString& s1, const QString& s2) {
return s1.compare(s2) < 0;
}
bool QStringsComparator::compareQStrings(const QString& s1, const QString& s2) {
return s1.compare(s2) < 0;
}

View File

@@ -39,6 +39,7 @@
#include <vector>
#include <map>
#include <QString>
#include <QJsonDocument>
#include <QJsonValue>
#include <QJsonArray>

View File

@@ -15,11 +15,11 @@ DependencyMap ConfigurationIF::getDependencies(std::vector<QString>& commands) c
return mDeviceDeps->getDependencies(commands);
}
ActivateWindowPoolController ConfigurationIF::getAWPools() const {
PoolControllerMap ConfigurationIF::getPools() const {
if (!mDeviceDeps)
throw std::invalid_argument("Invalid DRAMTimeDependenciesIF object in 'ConfigurationIF::getAWPools'.");
return mDeviceDeps->getAWPools();
return mDeviceDeps->getPools();
}
const QString ConfigurationIF::getDeviceName(const TraceDB& tdb) {

View File

@@ -16,7 +16,7 @@ class ConfigurationIF {
// Delegated methods
const uint getClk() const;
DependencyMap getDependencies(std::vector<QString>& commands) const;
ActivateWindowPoolController getAWPools() const;
PoolControllerMap getPools() const;
static const QString getDeviceName(const TraceDB& tdb);

View File

@@ -45,7 +45,7 @@ void DDR3TimeDependencies::mInitializeValues() {
burstLength = mMemspecJson["memarchitecturespec"].toObject()["burstLength"].toInt();
dataRate = mMemspecJson["memarchitecturespec"].toObject()["dataRate"].toInt();
mPoolSizes.insert({"FAW", 4});
mPools.insert({"FAW", {4, {"ACT"}}});
tRP = tCK * mMemspecJson["memtimingspec"].toObject()["RP"].toInt();
tRAS = tCK * mMemspecJson["memtimingspec"].toObject()["RAS"].toInt();

View File

@@ -69,8 +69,8 @@ DRAMTimeDependenciesIF::getDependencies(std::vector<QString>& dependencyFilter)
return dependenciesMap;
}
ActivateWindowPoolController DRAMTimeDependenciesIF::getAWPools() const {
return ActivateWindowPoolController(mPoolSizes);
PoolControllerMap DRAMTimeDependenciesIF::getPools() const {
return PoolControllerMap(mPools);
}
void DRAMTimeDependenciesIF::mFilterDependencyList(std::vector<TimeDependency>& dependencyList, const std::vector<QString>& dependencyFilter) const {
@@ -172,11 +172,3 @@ uint DRAMTimeDependenciesIF::mFindVectorMaximum(const std::vector<TimeDependency
return maxElement->timeValue;
}
bool QStringsComparator::operator()(const QString& s1, const QString& s2) {
return s1.compare(s2) < 0;
}
bool QStringsComparator::compareQStrings(const QString& s1, const QString& s2) {
return s1.compare(s2) < 0;
}

View File

@@ -0,0 +1,47 @@
#include "poolcontroller.h"
#include <algorithm>
PoolController::PoolController(const uint poolSize, const std::vector<QString>& dependencies)
: mDependencies(mAuxSortInput(dependencies))
{
mPoolSize = poolSize;
}
void PoolController::clear() {
mPool.clear();
mCount = 0;
}
void PoolController::push(DBDependencyEntry dep) {
mPool.push_back(dep);
mCount++;
}
void PoolController::increment() {
mCount++;
}
void PoolController::merge(std::vector<DBDependencyEntry>& depEntries) {
if(mCount >= mPoolSize) {
depEntries.insert( depEntries.end(), mPool.begin(), mPool.end() );
}
}
bool PoolController::isDependency(const QString& phaseName) {
return std::binary_search(
mDependencies.begin(),
mDependencies.end(),
phaseName,
QStringsComparator::compareQStrings
);
}
std::vector<QString> PoolController::mAuxSortInput(std::vector<QString> vec) {
std::sort(vec.begin(), vec.end(), QStringsComparator::compareQStrings);
return vec;
}

View File

@@ -0,0 +1,26 @@
#pragma once
#include "businessObjects/dramTimeDependencies/common/common.h"
class PoolController {
public:
PoolController(const uint poolSize, const std::vector<QString>& dependencies);
~PoolController() = default;
void clear();
void push(DBDependencyEntry);
void increment();
void merge(std::vector<DBDependencyEntry>& depEntries);
bool isDependency(const QString& phaseName);
protected:
const std::vector<QString> mDependencies;
std::vector<DBDependencyEntry> mPool;
uint mCount = 0;
uint mPoolSize = 0;
protected:
static std::vector<QString> mAuxSortInput(std::vector<QString> vec);
};

View File

@@ -33,52 +33,53 @@
* Iron Prando da Silva
*/
#include "activatewindowpoolcontroller.h"
ActivateWindowPoolController::ActivateWindowPoolController(const std::map<QString, uint, QStringsComparator>& poolSizes) {
mPoolSizes = poolSizes;
for (const auto& p : poolSizes) {
mPools.insert({p.first, {}});
mCounts.insert({p.first, 0});
mPools[p.first].reserve(32);
}
#include "poolcontrollermap.h"
PoolControllerMap::PoolControllerMap(const std::map<QString, PoolController, QStringsComparator>& pools) {
mPools = pools;
}
void ActivateWindowPoolController::clear() {
void PoolControllerMap::clear() {
for (auto& p : mPools) {
p.second.clear();
mCounts[p.first] = 0;
}
}
void ActivateWindowPoolController::push(const QString& poolName, DBDependencyEntry dep) {
void PoolControllerMap::push(const QString& poolName, DBDependencyEntry dep) {
auto pool = mPools.find(poolName);
if (pool != mPools.end()) {
pool->second.push_back(dep);
mCounts[poolName]++;
pool->second.push(dep);
} else {
// TODO throw?
}
}
void ActivateWindowPoolController::increment(const QString& poolName) {
void PoolControllerMap::increment(const QString& poolName) {
auto pool = mPools.find(poolName);
if (pool != mPools.end()) {
mCounts[poolName]++;
pool->second.increment();
} else {
// TODO throw?
}
}
void ActivateWindowPoolController::merge(std::vector<DBDependencyEntry>& depEntries) {
for (const auto& p : mPools) {
if(mCounts[p.first] >= mPoolSizes[p.first]) {
depEntries.insert( depEntries.end(), p.second.begin(), p.second.end() );
}
void PoolControllerMap::merge(std::vector<DBDependencyEntry>& depEntries) {
for (auto& p : mPools) {
p.second.merge(depEntries);
}
}
bool PoolControllerMap::isDependency(const QString& poolName, const QString& phaseName) {
auto pool = mPools.find(poolName);
if (pool != mPools.end()) {
return pool->second.isDependency(phaseName);
} else {
// TODO throw?
return false;
}
}

View File

@@ -35,21 +35,21 @@
#pragma once
#include "businessObjects/dramTimeDependencies/common/common.h"
#include "poolcontroller.h"
class ActivateWindowPoolController {
class PoolControllerMap {
public:
ActivateWindowPoolController(const std::map<QString, uint, QStringsComparator>& poolSizes);
~ActivateWindowPoolController() = default;
PoolControllerMap(const std::map<QString, PoolController, QStringsComparator>& pools);
~PoolControllerMap() = default;
void clear();
void push(const QString& poolName, DBDependencyEntry);
void increment(const QString& poolName);
void merge(std::vector<DBDependencyEntry>& depEntries);
bool isDependency(const QString& poolName, const QString& phaseName);
protected:
std::map<QString, std::vector<DBDependencyEntry>, QStringsComparator> mPools;
std::map<QString, uint, QStringsComparator> mCounts;
std::map<QString, uint, QStringsComparator> mPoolSizes;
std::map<QString, PoolController, QStringsComparator> mPools;
};

View File

@@ -185,7 +185,7 @@ PhaseDependenciesTracker::mCalculateDependencies(const std::shared_ptr<Configura
DependencyMap deviceDependencies = deviceConfig->getDependencies(commands);
// Tries to find all timing dependencies for each phase on the trace
ActivateWindowPoolController poolController = deviceConfig->getAWPools();
PoolControllerMap poolController = deviceConfig->getPools();
for (size_t i = 1; i < phases.size(); i++) {
// NAW dependencies variables reset
poolController.clear();
@@ -220,12 +220,10 @@ PhaseDependenciesTracker::mCalculateDependencies(const std::shared_ptr<Configura
// Captures activate window dependencies
QString poolName = dep.phaseDep.left(poolSubstrPos);
// TODO - modify structures so the condition can be checked as below
// if (poolController.isDependency(poolName, otherPhase->phaseName)) {
if (otherPhase->phaseName == "ACT") {
if (poolController.isDependency(poolName, otherPhase->phaseName)) {
if (timeDiff == dep.timeValue) {
// Captures only the first (exactly matching time) ACT in
// the ACT window as a dependency
// Captures only the first (exactly matching time) phase in
// the pool window as a dependency
poolController.push(poolName, DBDependencyEntry{
phase->id,
phase->phaseName,
@@ -259,6 +257,7 @@ PhaseDependenciesTracker::mCalculateDependencies(const std::shared_ptr<Configura
}
// TODO remove this - must be substituted by the pool controller
// Capture command bus dependencies
if (timeDiff == deviceConfig->getClk()) {
entries.emplace_back(DBDependencyEntry{