Skip to content
Snippets Groups Projects
Commit a88719c3 authored by Bouquillon Fabien's avatar Bouquillon Fabien
Browse files

entrain d'ajouter un indice d'iteration pour les blocks dans un chemin (boucles)

parent ece5fa96
Branches
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ ARMCC=arm-none-eabi-gcc
CXXFLAGS += -std=c++11 -O0 -g3 -I ../otawa-core2-build/otawa/include/ -I ../otawa-core2-build/elm/include/ -I ../include/
all: clean explo.so install application large_loop loop_cond large_loop_vuln
all: clean explo.so install application large_loop loop_cond large_loop_vuln loop_nested
# binaire: binaire.c
# $(ARMCC) -nostdlib -nostdinc -static -o binaire binaire.c
......@@ -31,6 +31,8 @@ large_loop: large_loop.c
large_loop_vuln: large_loop_vuln.c
$(ARMCC) -nostdlib -nostdinc -static -o large_loop_vuln large_loop_vuln.c
loop_nested: loop_nested.c
$(ARMCC) -nostdlib -nostdinc -static -o loop_nested loop_nested.c
loop_cond: loop_cond.c
$(ARMCC) -nostdlib -nostdinc -static -o loop_cond loop_cond.c
......
......@@ -58,8 +58,10 @@ int main(int argc, char **argv) {
//FLOW_FACTS_PATH(conf_trivial) = argv[2];
// Platform description
CACHE_CONFIG_PATH(conf) = "xmc4500/cache.xml";
PROCESSOR_PATH(conf) = "xmc4500/pipeline.xml";
CACHE_CONFIG_PATH(conf) = "cache_simple.xml";
PROCESSOR_PATH(conf) = "/home/fabien/cristal/otawa-plugins/application/hardware/pipeline/lpc2138.xml";
MEMORY_PATH(conf) = "/home/fabien/cristal/otawa-plugins/application/hardware/memory/lpc2138.xml";
//PROCESSOR_PATH(conf) = "xmc4500/pipeline.xml";
//MEMORY_PATH(conf) = "xmc4500/memory.xml";
// Generic processor
......
......@@ -231,14 +231,14 @@ namespace otawa {
}
unsigned long time_bblock(BasicBlock* bb) {
std::cout << " -- BB -- " << std::endl;
for(auto i : *bb) {
//std::cout << "instruction:" << ipet::TIME(i) << std::endl;
}
std::cout << " -------- " << std::endl;
// unsigned long time_bblock(BasicBlock* bb) {
// std::cout << " -- BB -- " << std::endl;
// for(auto i : *bb) {
// //std::cout << "instruction:" << ipet::TIME(i) << std::endl;
// }
// std::cout << " -------- " << std::endl;
}
// }
int get_exit_id_of_cfg(CFG *cfg) {
for(CFG::BlockIter block_iter = cfg->blocks(); block_iter(); block_iter++) {
......@@ -288,11 +288,13 @@ namespace otawa {
// if the loop header exist return the nb of iteration
Block *bh = Loop::of(b)->header();
if(bh->isBasic()) {
std::cout << "BASIC iteration:";
return TOTAL_ITERATION(bh->toBasic()->first());
}
// if the CFG is the main function
if(b->cfg()->callers().count() == 0) {
std::cout << "TOP iteration:";
return 1;
}
......@@ -301,6 +303,7 @@ namespace otawa {
for(int i = 0; i < b->cfg()->callers().count(); i++) {
total += compute_total_iteration(b->cfg()->callers()[i]);
}
std::cout << "FCT iteration:";
return total;
}
......@@ -312,7 +315,7 @@ namespace otawa {
std::cout << "ExecTimeBasic "<< ipet::TIME(b->toBasic()) << std::endl;
// if(Loop::of(b)->header() != NULL) {
std::cout << "total iteration: " << compute_total_iteration(b) << std::endl;
std::cout << "total iteration: " << compute_total_iteration(b) << " weight:" << WEIGHT(b->toBasic()) << std::endl;
// }
// time_bblock(b->toBasic());
......@@ -330,6 +333,7 @@ namespace otawa {
category_t status = cache::CATEGORY(lb);
const hard::Cache *cache = lb->lblockset()->cache();
otawa::Address lb_id = cache->round(lb->address());
std::cout << "cache block:" << lb_id.page() << ":" << lb_id.offset() << "-" << cache->line(lb_id) << std::endl;
//std::cout << ipet::TIME(lb->instruction()) << "--" << cache->line(lb_id) << ":" <<lb_id.page() << ":" << lb_id.offset() << " " ;
switch(status) {
case FIRST_HIT:
......@@ -401,7 +405,91 @@ namespace otawa {
}
//----------------------------------------------------------------------
// Testing function to test presence of a block in a given loop
//---------------------------------------------------------------------
bool block_is_in_fct(CFG* cfg, Block* b) {
for(CFG::BlockIter bi = cfg->blocks(); bi(); bi++) {
Block *block = *bi;
if(block == b) {
return true;
}
if(block->isSynth()) {
if(block_is_in_fct(block->toSynth()->callee(),b)) {
return true;
}
}
}
return false;
}
bool block_is_in_loop(Loop* l, Block* b) {
for(Loop::BlockIter b_iter = l->blocks().begin(); b_iter.ended(); b_iter.next()) {
Block* b_tmp = b_iter.item();
if(b_tmp == b) {
return true;
}
// if(b_tmp->isBasic()) {
// if(LOOP_HEADER(b_tmp->toBasic())) {
// Loop *l_tmp = Loop::of(b_tmp->toBasic());
// if(block_is_in_loop(l_tmp, b)) {
// return true;
// }
// }
// }
if(b_tmp->isSynth()) {
if(block_is_in_fct(b_tmp->toSynth()->callee(),b)){
return true;
}
}
}
for(auto sl: l->subLoops()) {
if(block_is_in_loop(sl, b)) {
return true;
}
}
return false;
}
void explo_block_for_loop(WorkSpace *ws, Loop* l) {
const CFGCollection *coll = INVOLVED_CFGS(ws);
for(CFGCollection::Iter cfg_iter(*coll); cfg_iter(); cfg_iter++) {
CFG* cfg = *cfg_iter;
for(CFG::BlockIter bi = cfg->blocks(); bi(); bi++) {
//std::cout << "here" << std::endl;
Block *block = *bi;
if(block_is_in_loop(l, block)) {
std::cout << " " << bi->id();
}
}
}
}
void explo_loop(WorkSpace *ws) {
const CFGCollection *coll = INVOLVED_CFGS(ws);
for(CFGCollection::Iter cfg_iter(*coll); cfg_iter(); cfg_iter++) {
CFG* cfg = *cfg_iter;
for(CFG::BlockIter bi = cfg->blocks(); bi(); bi++) {
Block *block = *bi;
if(block->isBasic()) {
BasicBlock *bb = block->toBasic();
if(LOOP_HEADER(bb)) {
Loop *l = Loop::of(bb);
std::cout << "Loop(" << l->address().offset() << ":" << l->address().page() << ")";
explo_block_for_loop(ws, l);
std::cout << std::endl;
}
}
}
}
}
//--------------------------------------------------------------------
void ExploProcessor::processWorkSpace(WorkSpace *ws) {
const CFGCollection *coll = INVOLVED_CFGS(ws);
......@@ -412,18 +500,20 @@ namespace otawa {
std::cout << std::endl;
}
std::cout << "################# LOOP EXPLO ################" << std::endl;
std::vector<std::vector<Block*>> paths;
std::vector<std::vector<Block*>> tmp;
explo_fct(ENTRY_CFG(ws)->exit(), paths, tmp);
// std::cout << "################# LOOP EXPLO ################" << std::endl;
// std::vector<std::vector<Block*>> paths;
// std::vector<std::vector<Block*>> tmp;
// explo_fct(ENTRY_CFG(ws)->exit(), paths, tmp);
for(int i = 0; i < paths.size(); i++) {
std::cout << "PATH[" << i << "]:";
for(int j = 0; j < paths[i].size(); j++) {
std::cout << paths[i][j]->id() << "->";
}
std::cout << "start" << endl;
}
// for(int i = 0; i < paths.size(); i++) {
// std::cout << "PATH[" << i << "]:";
// for(int j = 0; j < paths[i].size(); j++) {
// std::cout << paths[i][j]->id() << "->";
// }
// std::cout << "start" << endl;
// }
//explo_loop(ws);
}
......
......@@ -11,14 +11,18 @@ ARMCC=arm-none-eabi-gcc
CXXFLAGS += -std=c++11 -O0 -g -I ../otawa-core2-build/otawa/include/ -I ../otawa-core2-build/elm/include/
all: clean vulnerability.so install application large_loop binaire tasks_sequential
all: clean vulnerability.so install application large_loop binaire test_loop_function test_loop_easy
large_loop: large_loop.c
$(ARMCC) -nostdlib -nostdinc -static -o large_loop large_loop.c
tasks_sequential: tasks_sequential.c
$(ARMCC) -nostdlib -nostdinc -static -o tasks_sequential tasks_sequential.c
test_loop_function: test_loop_function.c
$(ARMCC) -nostdlib -nostdinc -static -o test_loop_function test_loop_function.c -emain
test_loop_easy: test_loop_easy.c
$(ARMCC) -nostdlib -nostdinc -static -o test_loop_easy test_loop_easy.c -emain
binaire: binaire.c
$(ARMCC) -nostdlib -nostdinc -static -o binaire binaire.c
......
No preview for this file type
......@@ -14,13 +14,15 @@
#include <otawa/ipet/FlowFactLoader.h>
#include <otawa/etime/features.h>
#include "include/vulnerability.h"
#include <iostream>
#include <fstream>
using namespace otawa; //comme import
using namespace otawa::vulnerability;
int main(int argc, char **argv) {
if(argc != 3) {
std::cout << "Error number of argument. Usage:" << argv[0] << " <binary> <flow fact>" << std::endl;
if(argc != 4) {
std::cout << "Error number of argument. Usage:" << argv[0] << " <binary> <flow fact> <output file>" << std::endl;
exit(1);
}
WorkSpace *ws = NULL;
......@@ -35,7 +37,8 @@ int main(int argc, char **argv) {
// Platform description
CACHE_CONFIG_PATH(conf) = "cache.xml";
PROCESSOR_PATH(conf) = "xmc4500/pipeline.xml";
PROCESSOR_PATH(conf) = "/home/fabien/cristal/otawa-plugins/application/hardware/pipeline/lpc2138.xml";
MEMORY_PATH(conf) = "/home/fabien/cristal/otawa-plugins/application/hardware/memory/lpc2138.xml";
ws = manager.load(argv[1], conf);
ws->run("otawa::Virtualizer", conf);
......@@ -44,4 +47,63 @@ int main(int argc, char **argv) {
ws->require(otawa::ipet::WCET_FEATURE, conf);
ws->require(DynFeature("otawa::vulnerability::VULNERABILITY_FEATURE"), conf);
std::cout << "vulnerability:" << VUL(ws) << " WCET:" << ipet::WCET(ws) << std::endl;
std::ofstream file(argv[3]);
file << ipet::WCET(ws) << "," << VUL(ws) << std::endl;
const CFGCollection *coll = INVOLVED_CFGS(ws);
for(CFGCollection::Iter cfg_iter(*coll); cfg_iter(); cfg_iter++) {
for(CFG::BlockIter block_iter = cfg_iter->blocks(); block_iter(); block_iter++) {
if(block_iter->isBasic()) {
BasicBlock *bb = block_iter->toBasic();
AllocArray<LBlock *> *lblock_array = BB_LBLOCKS(bb);
for(int i = 0; i < lblock_array->count(); i++) {
LBlock *lb = (*lblock_array)[i];
struct LBlock_vulnerability * lb_vul = LB_VUL(lb);
if(lb_vul->vulnerability_max > 0) {
file << "(" << lb_vul->addr.offset() << "," << lb_vul->addr.page() << "," << lb_vul->vulnerability_max << "," << lb_vul->vulnerable_data << "," << lb_vul->reload_cost;
for(int j = 0; j < lb_vul->list_bb_path.size(); j++) {
if(lb_vul->list_bb_path[j]->isBasic()) {
AllocArray<LBlock *> *lblock_array_tmp = BB_LBLOCKS(lb_vul->list_bb_path[j]->toBasic());
for(int k = 0; k < lblock_array_tmp->count(); k++) {
LBlock *lb_tmp = (*lblock_array_tmp)[k];
struct LBlock_vulnerability * lb_vul_tmp = LB_VUL(lb_tmp);
if(lb_vul_tmp->vulnerability_max > 0) {
file << "(" << lb_vul_tmp->addr.offset() << "," << lb_vul_tmp->addr.page() << "," << lb_vul_tmp->reload_cost << ")";
}
}
}
}
file << ")" << std::endl;
}
}
}
}
}
for(CFGCollection::Iter cfg_iter(*coll); cfg_iter(); cfg_iter++) {
for(CFG::BlockIter block_iter = cfg_iter->blocks(); block_iter(); block_iter++) {
if(block_iter->isBasic()) {
BasicBlock *bb = block_iter->toBasic();
AllocArray<LBlock *> *lblock_array = BB_LBLOCKS(bb);
for(int i = 0; i < lblock_array->count(); i++) {
LBlock *lb = (*lblock_array)[i];
struct LBlock_vulnerability * lb_vul = LB_VUL(lb);
if(lb_vul->vulnerability_max > 0) {
file << "(" << lb_vul->addr.offset() << "," << lb_vul->addr.page();
AllocArray<LBlock *> *lblock_array_tmp = BB_LBLOCKS(bb);
for(int j = 0; j < lblock_array_tmp->count(); j++) {
LBlock *lb_tmp = (*lblock_array_tmp)[j];
file << "(" << lb_vul->addr.offset() << "," << lb_vul->addr.page() << "," << lb_vul->reload_cost << ")";
}
file << ")" << std::endl ;
}
}
}
}
}
}
No preview for this file type
// Function main
loop "main" + 0xc8 total 10;
\ No newline at end of file
loop "main" + 0xc8 max 10 total 10;
\ No newline at end of file
......@@ -33,7 +33,48 @@ namespace otawa { namespace vulnerability {
// std::vector<std::vector<Block*>> &result,
// const hard::Cache* cache);
void explo_path(std::vector<std::vector<Block*>>& result, std::vector<Block*> path, Block* b, Address cb, const hard::Cache * cache);
struct PVBlock {
Block* b;
long iteration;
};
void explo_path(std::vector<std::vector<PVBlock>>& result, std::vector<PVBlock> path, Block* b, Address cb, const hard::Cache * cache, ilp::System* sys, std::vector<PVBlock> &blocks_on_path);
bool not_present_in_ucb(Address cb,
Block* b,
const hard::Cache *cache);
bool not_present_out_ucb(Address cb,
Block* b,
const hard::Cache *cache);
bool present_in_bb(Address cb,
Block* b,
const hard::Cache *cache);
long compute_path_cost(std::vector<PVBlock> path, ilp::System* sys);
std::vector<PVBlock> path_in_fct(CFG *fct,
Address cb,
const hard::Cache *cache,
ilp::System *sys,
std::vector<PVBlock> &blocks_on_path);
std::vector<PVBlock> path_through_fct(CFG *fct,
Address cb,
const hard::Cache *cache,
ilp::System *sys,
std::vector<PVBlock> &blocks_on_path);
std::vector<PVBlock> path_in_loop(BasicBlock *bh,
Address cb,
const hard::Cache *cache,
ilp::System *sys,
std::vector<PVBlock> &blocks_on_path);
std::vector<PVBlock> path_through_loop(BasicBlock *bh,
Address cb,
const hard::Cache *cache,
ilp::System *sys,
std::vector<PVBlock> &blocks_on_path);
class VulnerabilityProcessor : public Processor {
public:
......@@ -49,15 +90,35 @@ protected:
extern p::feature VULNERABILITY_FEATURE;
// Declaration structures
typedef struct {
// typedef struct {
// otawa::Address addr;
// cache::LBlock* lb;
// long reload_time;
// }LBlock_miss;
// typedef struct {
// std::vector<LBlock_miss> lblocks;
// long vulnerability;
// } Struct_path;
struct LBlock_vulnerability{
otawa::Address addr;
long reload_time;
}LBlock_vulnerable;
cache::LBlock* lb;
long reload_cost;
long vulnerability_max;
long vulnerable_data; // vulnerable data * iteration max
std::vector<Block*> list_bb_path;
LBlock_vulnerability() {
lb = 0;
reload_cost = 0;
vulnerability_max = 0;
vulnerable_data = 0;
}
typedef struct {
std::vector<LBlock_vulnerable> lblocks;
long vulnerability;
} Struct_path;
};
//declaration propriete
/*
......@@ -69,6 +130,8 @@ extern Identifier<DAGHNode*> DAG_HNODE;
void start_rmb_lmb_computation(WorkSpace *ws);
extern Identifier<struct Memory_block *> MB_STRUCT;
extern Identifier<struct LBlock_vulnerability*> LB_VUL;
}
}
#endif
int fct() {
int i;
i++;
i++;
i++;
i++;
i++;
i++;
if(i > 5) {
i++;
i++;
} else {
i++;
i++;
i++;
i++;
}
i++;
i++;
i++;
i++;
i++;
i++;
}
int main() {
int i;
i++;
i++;
i++;
i++;
i++;
i++;
i += fct();
if(i > 5) {
i++;
i++;
} else {
i++;
i++;
i++;
i++;
}
if(i > 5) {
i++;
i++;
} else {
i++;
i++;
i++;
i++;
}
if(i > 5) {
i++;
i++;
} else {
i++;
i++;
i++;
i++;
}
if(i > 5) {
i++;
i++;
} else {
i++;
i++;
i++;
i++;
}
i += fct();
i++;
i++;
i++;
i++;
i++;
i++;
return i;
}
This diff is collapsed.
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment