Skip to content

Commit

Permalink
refactoring existing code and adding EXP-CS handling code to support …
Browse files Browse the repository at this point in the history
…integration with s3FNet
  • Loading branch information
Vignesh2208 committed Sep 21, 2020
1 parent 761467f commit a6d3c42
Show file tree
Hide file tree
Showing 111 changed files with 4,463 additions and 149,991 deletions.
10 changes: 5 additions & 5 deletions examples/cmds_to_run_file.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sysbench --test=cpu --cpu-max-prime=10000 --num-threads=1 run
sysbench --test=cpu --cpu-max-prime=10000 --num-threads=1 run
sysbench --test=cpu --cpu-max-prime=10000 --num-threads=1 run
sysbench --test=cpu --cpu-max-prime=10000 --num-threads=1 run
sysbench --test=cpu --cpu-max-prime=10000 --num-threads=1 run
/home/kronos/Kronos/src/tracer/tests/sleep-test/test
/home/kronos/Kronos/src/tracer/tests/sleep-test/test
/home/kronos/Kronos/src/tracer/tests/sleep-test/test
/home/kronos/Kronos/src/tracer/tests/sleep-test/test
/home/kronos/Kronos/src/tracer/tests/sleep-test/test
150 changes: 150 additions & 0 deletions examples/example_exp_cs_vt_experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import sys
import os
import time
import kronos_functions as kf
import sys
import argparse
import threading
import logging

EXP_CBE = 1
EXP_CS = 2

def start_new_dilated_process(tracer_id, timeline_id, cmd_to_run, log_file_fd,
exp_type):

newpid = os.fork()
if newpid == 0:
os.dup2(log_file_fd, sys.stdout.fileno())
os.dup2(log_file_fd, sys.stderr.fileno())
args = ["tracer", "-t", str(timeline_id), "-i", str(tracer_id),
"-c", cmd_to_run]
os.execvp(args[0], args)
else:
return newpid


def worker_thread_fn(progress_ns_per_round, num_progress_rounds, timeline_id):
logging.info("Running Timeline: %d for %d rounds ... ", timeline_id,
num_progress_rounds)

start_time = float(time.time())
if num_progress_rounds > 0 :
num_finished_rounds = 0
while num_finished_rounds < num_progress_rounds:
kf.progressTimelineBy(timeline_id, progress_ns_per_round)
num_finished_rounds += 1

elapsed_time = float(time.time()) - start_time
logging.info("Timeline: %d finished. Total time elapsed (secs) = %f",
timeline_id, elapsed_time)


def main():


parser = argparse.ArgumentParser()


parser.add_argument('--cmds_to_run_file', dest='cmds_to_run_file',
help='path to file containing commands to run', \
type=str, default='cmds_to_run_file.txt')


parser.add_argument('--progress_ns_per_round', dest='progress_ns_per_round',
help='Number of insns per round', type=int,
default=1000000)

parser.add_argument('--num_progress_rounds', dest='num_progress_rounds',
help='Number of rounds to run', type=int,
default=1000)

parser.add_argument('--exp_type', dest='exp_type',
help='Number of rounds to run', type=int, default=EXP_CS)

parser.add_argument('--num_timelines', dest='num_timelines',
help='Number of timelines in CS experiment', type=int,
default=1)

args = parser.parse_args()
log_fds = []
tracer_pids = []
cmds_to_run = []

worker_threads = []

logging.basicConfig(level=logging.INFO)

if not os.path.isfile(args.cmds_to_run_file):
logging.info("Commands file path is incorrect !")
sys.exit(0)
fd1 = open(args.cmds_to_run_file, "r")
cmds_to_run = [x.strip() for x in fd1.readlines()]
fd1.close()
for i in range(0, len(cmds_to_run)) :
with open("/tmp/tracer_log_%d.txt" %(i), "w") as f:
pass
log_fds = [ os.open("/tmp/tracer_log_%d.txt" %(i), os.O_RDWR | os.O_CREAT ) \
for i in range(0, len(cmds_to_run)) ]
num_tracers = len(cmds_to_run)
num_timelines = len(cmds_to_run)
#num_timelines = args.num_timelines

input('Press any key to continue !')
for i in range(0, num_tracers) :
with open("/tmp/tracer_log_%d.txt" %(i), "w") as f:
pass
log_fds = [ os.open("/tmp/tracer_log_%d.txt" %(i), os.O_RDWR | os.O_CREAT ) \
for i in range(0, num_tracers) ]

logging.info("Initializing VT Module !")
if kf.initializeVTExp(args.exp_type, num_timelines, num_tracers) < 0 :
logging.info("VT module initialization failed ! Make sure you are running\
the dilated kernel and kronos module is loaded !")
sys.exit(0)

input('Press any key to continue !')

logging.info("Starting all commands to run !")

for i in range(0, num_tracers):
logging.info("Starting tracer: %d", i + 1)
start_new_dilated_process(i + 1, i % num_timelines,
cmds_to_run[i], log_fds[i], args.exp_type)
input('Press any key to continue !')

logging.info("Synchronizing and freezing tracers ...")
while kf.synchronizeAndFreeze() <= 0:
logging.info("VT Module >> Synchronize and Freeze failed."
" Retrying in 1 sec")
time.sleep(1)

input('Press any key to continue !')

for index in range(num_timelines):
logging.info("Main : create and start thread %d.", index)
x = threading.Thread(target=worker_thread_fn,
args=(args.progress_ns_per_round, args.num_progress_rounds, index))
worker_threads.append(x)
x.start()

for index, thread in enumerate(worker_threads):
logging.info("Main : before joining thread %d.", index)
thread.join()
logging.info("Main : thread %d done", index)


input("Press Enter to continue...")
logging.info("Stopping Synchronized Experiment !")
kf.stopExp()

for fd in log_fds:
os.close(fd)

logging.info("Finished ! Logs of each ith tracer can be found "
"in /tmp/tracer_log_i.txt")



if __name__ == "__main__":
main()
6 changes: 3 additions & 3 deletions examples/example_vt_experiment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import os
import time
import vt_functions as kf
import kronos_functions as kf
import sys
import argparse

Expand Down Expand Up @@ -46,11 +46,11 @@ def main():

parser.add_argument('--num_insns_per_round', dest='num_insns_per_round',
help='Number of insns per round', type=int,
default=1000)
default=1000000)

parser.add_argument('--num_progress_rounds', dest='num_progress_rounds',
help='Number of rounds to run', type=int,
default=50000)
default=1000)

args = parser.parse_args()

Expand Down
8 changes: 4 additions & 4 deletions scripts/x64_synchronizer.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <time.h>
int main(int argc, char *argv[])
{
while(1) {
usleep(1000000);
}
return 0;
while(1) {
usleep(1000000);
}
return 0;
}

43 changes: 34 additions & 9 deletions src/api/py_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ static PyObject *py_initializeExp(PyObject *self, PyObject *args) {
return Py_BuildValue("i", ret);
}

static PyObject *py_initializeVTExp(PyObject *self, PyObject *args) {
int ret;
int n_tracers;
int exp_type;
int n_timelines;
if (!PyArg_ParseTuple(args, "iii", &exp_type, &n_timelines, &n_tracers))
return NULL;

ret = initializeVtExp(exp_type, n_timelines, n_tracers);
return Py_BuildValue("i", ret);
}


static PyObject *py_progress_by(PyObject *self, PyObject *args) {
s64 duration;
int num_rounds;
Expand All @@ -53,37 +66,49 @@ static PyObject *py_progress_by(PyObject *self, PyObject *args) {
return Py_BuildValue("i", ret);
}

static PyObject *py_progressTimelineBy(PyObject *self, PyObject *args) {
s64 duration;
int timeline_id;
int ret;

if (!PyArg_ParseTuple(args, "iL", &timeline_id, &duration)) return NULL;
ret = progressTimelineBy(timeline_id, duration);
return Py_BuildValue("i", ret);
}

static PyObject *py_synchronizeAndFreeze(PyObject *self, PyObject *args) {
int ret;
ret = synchronizeAndFreeze();
return Py_BuildValue("i", ret);
}

static PyMethodDef vt_functions_methods[] = {
static PyMethodDef kronos_functions_methods[] = {
{"synchronizeAndFreeze", py_synchronizeAndFreeze, METH_VARARGS, NULL},
{"getTimePID", py_gettime_pid, METH_VARARGS, NULL},
{"getCurrentVirtualTime", py_getCurrentVirtualTime, METH_VARARGS, NULL},
{"setNetDeviceOwner", py_setNetDeviceOwner, METH_VARARGS, NULL},
{"stopExp", py_stopExp, METH_VARARGS, NULL},
{"initializeExp", py_initializeExp, METH_VARARGS, NULL},
{"initializeVTExp", py_initializeVTExp, METH_VARARGS, NULL},
{"progressBy", py_progress_by, METH_VARARGS, NULL},
{"progressTimelineBy", py_progressTimelineBy, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}};

#if PY_MAJOR_VERSION <= 2

void initvt_functions(void) {
Py_InitModule3("vt_functions", vt_functions_methods,
"virtual time functions");
void initkronos_functions(void) {
Py_InitModule3("kronos_functions", kronos_functions_methods,
"Kronos API functions");
}

#elif PY_MAJOR_VERSION >= 3

static struct PyModuleDef vt_api_definition = {
PyModuleDef_HEAD_INIT, "vt functions",
"A Python module that exposes vt module's API", -1, vt_functions_methods};
PyMODINIT_FUNC PyInit_vt_functions(void) {
static struct PyModuleDef kronos_api_definition = {
PyModuleDef_HEAD_INIT, "kronos functions",
"A Python module that exposes kronos module's API", -1, kronos_functions_methods};
PyMODINIT_FUNC PyInit_kronos_functions(void) {
Py_Initialize();
return PyModule_Create(&vt_api_definition);
return PyModule_Create(&kronos_api_definition);
}

#endif
Loading

0 comments on commit a6d3c42

Please sign in to comment.