Commit aaa78d1a authored by Maeva Ramarjiaona's avatar Maeva Ramarjiaona

changing the structure so that calculating the previous access doesn't require...

changing the structure so that calculating the previous access doesn't require to calculate the ExistHit analysis twice
parent f00f409f
#ifndef LRUSECURITY_ACSS_MANAGER_H_
#define LRUSECURITY_ACSS_MANAGER_H_
#include <otawa/icat3/features.h>
#include <otawa/cfg/features.h>
#include <lrumc/features.h>
namespace lrusecurity
{
class CacheState;
class ACSSManager
{
public:
ACSSManager(otawa::WorkSpace* ws);
~ACSSManager(void);
void start(otawa::Block* b);
void update(const otawa::icache::Access& acc);
int existHitAge(const otawa::icat3::LBlock* b);
otawa::Address prev(const otawa::icat3::LBlock *b);
void print(const otawa::icat3::LBlock* b, otawa::io::Output& out);
private:
CacheState& use(int set);
lrumc::ACSSManager _underlyingManager;
const otawa::icat3::LBlockCollection& _coll;
elm::Vector<int> _used;
otawa::Block* _b;
CacheState** _states;
bool _hasPrev;
};
} // namespace lrusecurity
#endif // LRUSECURITY_ACSS_MANAGER_H_
......@@ -3,25 +3,15 @@
#include <otawa/icache/features.h>
#include <otawa/icat3/features.h>
#include <otawa/util/Bag.h>
namespace lrusecurity
{
class ACSSecurity
class ACSSecurity : public AllocArray<otawa::Address>
{
public:
ACSSecurity(){
_acs = otawa::icat3::ACS();
};
inline ACSSecurity(otawa::icat3::ACS acs) {
_acs = acs;
_prev = otawa::Bag<otawa::icache::Access>();
ACSSecurity();
ACSSecurity(int n, otawa::Adress ad = otawa::Address()){
for (int i = 0 ; i<n ; i++)
this.[i] = otawa::Address();
}
void copy(ACSSecurity b){
_acs.copy(b._acs);
_prev = otawa::Bag<otawa::icache::Access>(b._prev);
};
otawa::icat3::ACS _acs;
otawa::Bag<otawa::icache::Access> _prev;
};
}
#endif //LRUSECURITY_ACSSECURITY_H_H
}
......@@ -20,6 +20,23 @@ enum class SecurityCategory{
UNSAFE
};
class ACSSManager
{
public:
ACSSManager(otawa::WorkSpace *ws);
~ACSSManager(void);
void start(otawa::Block *b);
void update(const otawa::icache::Access& acc);
int existHitAge(const otawa::icat3::LBlock *lb);
void print(const otawa::icat3::LBlock *lb, elm::io::Output& out = elm::cout);
private:
CacheState& use(int set);
const otawa::icat3::LBlockCollection& coll;
elm::Vector<int> used;
otawa::Block *_b;
CacheState **_states;
};
//Specifying which calls are making the program unsafe
extern otawa::p::feature SECURITY_CATEGORY_FEATURE;
extern otawa::p::id<SecurityCategory> SECURITY_CATEGORY;
......
#ifndef LRUSECURITY_CACHE_STATE_H_
#define LRUSECURITY_CACHE_STATE_H_
#include "Prev/ExistHitPrevDomain.h"
namespace lrusecurity
{
class CacheState
{
public:
CacheState(const otawa::icat3::LBlockCollection& coll, int set) :
_existHitPrevDomain(coll, set, nullptr),
_PrevState(nullptr),
{
}
~CacheState()
{
if(_existHitState)
delete _PrevState;
}
ExistHitPrevDomain _existHitPrevDomain;
typename ExistHitPrevDomain::t* _PrevState;
};
} // namespace lrusecurity
#endif // LRUSECURITY_CACHE_STATE_H_
......@@ -22,63 +22,22 @@ ExistHitPrevDomain::ExistHitPrevDomain(
bool ExistHitPrevDomain::equals(const t& acss, const t& bcss) const
{
icat3::ACS a = acss._acs;
icat3::ACS b = bcss._acs;
for(int i = 0; i < _n; i++)
if(a[i] != b[i])
return false;
for (int i = 0; i < _n; i++)
if (acss._prev != bcss._prev)
return false;
return true;
for (int i = 0; i < _n; i++)
if (acss[i] != bcss[i])
return false;
return true;
}
void ExistHitPrevDomain::join(t& dcss, const t& scss)
{
icat3::ACS& d = dcss._acs;
const icat3::ACS& s = scss._acs;
for(int i = 0; i < _n; i++) {
// d[i] = min(d[i], s[i])
if(d[i] == icat3::BOT_AGE)
d[i] = s[i];
else if(s[i] != icat3::BOT_AGE)
d[i] = min(d[i], s[i]);
}
//join of the Prev is a union
int fullsize = dcss._prev.size()+scss._prev.size();
Bag<icache::Access> newbag = Bag<icache::Access>(fullsize);
for (int i = 0 ; i < fullsize; ++i){
if (i < dcss._prev.size())
newbag[i] = dcss._prev[i];
else
newbag[i] = scss._prev[i - dcss._prev.size()];
}
dcss._prev = newbag;
for (int i = 0; i < _n; i++)
if (scss[i] != Address())
dcss[i] = scss[i];
}
void ExistHitPrevDomain::fetch(t& acss, const icache::Access ac, lrupreanalysis::ACSManager& mustManager)
void ExistHitPrevDomain::fetch(t& acss, const icat3::LBlock *lb, lrupreanalysis::ACSManager& mustManager)
{
icat3::LBlock *lb = icat3::LBLOCK(ac);
int b = lb->index();
icat3::ACS a = acss._acs;
if(a[0] == icat3::BOT_AGE)
return;
for(int i = 0; i < _n; i++) {
ASSERT(a[i] != icat3::BOT_AGE);
if(i == b)
continue;
if(a[i] < mustManager.mustAge(lb) && a[i] < _A)
a[i]++;
}
a[b] = 0;
//Updating prev
for(int i = 0; i < _n; i++) {
if (a[i] == _A)
acss._prev = *new Bag<icache::Access>();
if (i == b)
acss._prev = *new Bag<icache::Access>(1, &ac);
}
int b = lb->index;
}
void ExistHitPrevDomain::update(const icache::Access& access, t& a, lrupreanalysis::ACSManager& mustManager)
......
#include <lrusecurity/ACSSecurityManager.h>
#include <otawa/icat3/features.h>
#include <lrusecurity/features.h>
#include "CacheState.h"
using namespace otawa;
namespace lrusecurity
{
ACSSecurityManager::ACSSecurityManager(WorkSpace* ws) :
_underlyingManager(ws),
_coll(**icat3::LBLOCKS(ws)),
_b(nullptr)
{
_states = new CacheState*[_coll.sets()];
array::set(_states, _coll.sets(), null<CacheState>());
_hasPrev = ws->isProvided(lrusecurity::EXIST_HIT_PREV_ANALYSIS_FEATURE);
}
ACSSecurityManager::~ACSSecurityManager()
{
for(int i = 0; i < _coll.sets(); ++i)
if(_states[i] != nullptr)
delete _states[i];
delete[] _states;
}
void ACSSecurityManager::start(otawa::Block* b)
{
ASSERT(b);
_b = b;
_underlyingManager.start(b);
_used.clear();
}
void ACSSecurityManager::update(const icache::Access& acc)
{
icat3::LBlock* lb = icat3::LBLOCK(acc);
CacheState& state = use(lb->set());
if(_hasPrev)
state._existHitPrevDomain.update(acc, *state._existHitPrevState, _underlyingManager);
}
int ACSSecurityManager::existHitAge(const icat3::LBlock* lb)
{
return _underlyingManager.existHitAge(lb);
}
Address ACSSecurityManager::prev(const icat3::LBlock *lb)
{
if (! _hasPrev)
return 0; //FIXME
else
return use(lb->set())._existHitPrevState->get(lb->index());
}
void ACSSecurityManager::print(const icat3::LBlock* lb, Output& out)
{
CacheState& state = use(lb->set());
if(_hasPrev) {
out << "{Prev: ";
state._existHitDomain.print(*state._existHitState, out);
}
}
CacheState& ACSSecurityManager::use(int set)
{
if(!_used.contains(set)) {
if(_states[set] == nullptr)
_states[set] = new CacheState(_coll, set);
if(_hasExistHitPrev) {
if(_states[set]->_existHitState == nullptr)
_states[set]->_existHitPrevState = new ExistHitPrevDomain::t;
_states[set]->_existHitPrevDomain.copy(*_states[set]->_existHitState, (*EXIST_HIT_PREV_IN(_b))[set]);
}
_used.add(set);
}
return *_states[set];
}
} // namespace lrusecurity
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment