Skip to content

Commit

Permalink
Add code to simualte fault
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoneDutto committed Sep 5, 2020
1 parent e6c9ec1 commit fe2a1dc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
15 changes: 11 additions & 4 deletions ML/eval_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import sys
import torch.nn as nn
import numpy as np
from sklearn.preprocessing import StandardScaler


PATH= "/home/sgundo/Desktop/Tesi/OS_FaultMonitor/ML/"
len_index = 20
Expand Down Expand Up @@ -34,18 +36,21 @@ def forward(self, x):

def eval(feat):
X = np.array(feat)
X= scaler.transform(X)
X = torch.from_numpy(X).float()
X = X.unsqueeze(0)
y = model(X)
y = torch.log_softmax(y, dim=1)
_, y = torch.max(y, dim = 1)

return y.item()

f_s = True # read metrics from file or receive it from socket
flip = 0
cmd = sys.argv[1]
bi = sys.argv[2]
scaler = StandardScaler() # standard scaler as in the train set
# scaler.mean_ =
# scaler.var_ =
model = BinaryClassification()
model.load_state_dict(torch.load(PATH+bi+".pth", map_location=torch.device('cpu')))
model.eval()
Expand All @@ -59,13 +64,15 @@ def eval(feat):
first_line = file.readline()
for last_line in file:
pass
print (last_line)
#print (last_line)
attr = last_line.split()
attr = attr[3:]
print(attr)
#print(attr)
attr_int = [int(i) for i in attr]
if len(attr_int) == 7:
eval(attr_int)
#response = eval(attr_int)
response = 1
print("Evaluation: "+str(response))

else:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
Expand Down
Binary file removed ML/model_NN50_20.pth
Binary file not shown.
3 changes: 1 addition & 2 deletions cmd/monitor
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ do

done
echo "comando lanciato $cmd"

conf="instr_retired,unhalted_ref_cycles_fixed,cycles,instr,llc_references,llc_misses,branch_instr_retired"
nohup pmctrack -T 1 -c $conf $cmd > $cmd.out
pmctrack -o $cmd.out -T 1 -c $conf $cmd
python3 /home/sgundo/Desktop/Tesi/OS_FaultMonitor/ML/eval_proc.py $cmd $target
# pid=$!
# echo $pid
Expand Down
26 changes: 26 additions & 0 deletions cmd/prova.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include<time.h>

/*
Simple program to simulate a fault with a 50% chance
*/

int main(int argc, char* argv[]){
int i = 0;
int *ptr1, *ptr2=NULL;
for(i=0;i<10000000;i++);

srand(time(0));
ptr1 = &i;
//printf("Pointer value before %p\n", ptr1);
ptr2 = (int *) ((uintptr_t) ptr1 | (uintptr_t) 0xFFF000); //simulate a fault by changing a pointer
//printf("Pointer value after %p\n", ptr2);
if((rand()%2)==0)
i = *ptr2;
else
i = *ptr1;

//printf("Intero %d\n", i);
}

0 comments on commit fe2a1dc

Please sign in to comment.