Skip to content

Commit

Permalink
adding an api function to register a netdevice to any available trace…
Browse files Browse the repository at this point in the history
…r with a spinner task
  • Loading branch information
Vignesh2208 committed Sep 17, 2020
1 parent b476ae0 commit 2276756
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 76 deletions.
2 changes: 2 additions & 0 deletions src/api/Kronos_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
#define INITIALIZE_EXP 'K'
#define RUN_DILATED_HRTIMERS 'L'

#define ADD_NETDEVICE_TO_VT_CONTROL 'M'


#endif
17 changes: 17 additions & 0 deletions src/api/Kronos_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ int set_netdevice_owner(int tracer_pid, char * intf_name) {
return -1;

}

int add_netdevice_to_vt_control(char * intf_name) {
if (intf_name == NULL || strlen(intf_name) > IFNAMESIZ)
return -1;


if (isModuleLoaded()) {
char command[100];
flush_buffer(command, 100);
sprintf(command, "%c,%s", ADD_NETDEVICE_TO_VT_CONTROL, intf_name);
return send_to_kronos(command);
}

return -1;

}

int gettimepid(int pid) {

if (pid <= 0)
Expand Down
1 change: 1 addition & 0 deletions src/api/Kronos_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ int update_tracer_params(int tracer_pid, float relative_cpu_speed,
u32 n_round_instructions);
int write_tracer_results(char * result);
int set_netdevice_owner(int tracer_pid, char * intf_name);
int add_netdevice_to_vt_control(char * intf_name);
int gettimepid(int pid);

int startExp();
Expand Down
46 changes: 26 additions & 20 deletions src/api/py_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,20 @@ int o_get_stats(ioctl_args * args) {
static PyObject * py_addToExp(PyObject *self, PyObject *args) {
float rel_cpu_speed;
u32 n_insns;
int ret;
int ret = 1;

if (!PyArg_ParseTuple(args, "fl", &rel_cpu_speed, &n_insns))
return NULL;
ret = addToExp(rel_cpu_speed, n_insns);
return Py_BuildValue("i", ret);
}

static PyObject * py_hello(PyObject *self, PyObject *args) {
int ret = 1;
hello();
return Py_BuildValue("i", ret);
}


static PyObject * py_addToExp_sp(PyObject *self, PyObject *args) {
float rel_cpu_speed;
u32 n_insns;
int ret;
int ret = 1;
pid_t pid;

if (!PyArg_ParseTuple(args, "fli", &rel_cpu_speed, &n_insns, &pid))
Expand All @@ -58,7 +53,7 @@ static PyObject * py_addToExp_sp(PyObject *self, PyObject *args) {
static PyObject * py_update_tracer_params(PyObject *self, PyObject *args) {
float rel_cpu_speed;
u32 n_insns;
int ret;
int ret = 1;
pid_t pid;

if (!PyArg_ParseTuple(args, "ifl", &pid, &rel_cpu_speed, &n_insns))
Expand All @@ -71,7 +66,7 @@ static PyObject * py_update_tracer_params(PyObject *self, PyObject *args) {
static PyObject * py_write_tracer_results(PyObject *self, PyObject *args) {
float rel_cpu_speed;
u32 n_insns;
int ret;
int ret = 1;
pid_t pid;
char * command;

Expand All @@ -87,17 +82,28 @@ static PyObject * py_set_netdevice_owner(PyObject *self, PyObject *args) {

int pid;
char * intf_name;
int ret;
int ret = 1;

if (!PyArg_ParseTuple(args, "is", &pid, &intf_name))
return NULL;
ret = set_netdevice_owner(pid, intf_name);
return Py_BuildValue("i", ret);
}

static PyObject * py_add_netdevice_to_vt_control(PyObject *self, PyObject *args) {

char * intf_name;
int ret = 1;

if (!PyArg_ParseTuple(args, "s", &intf_name))
return NULL;
ret = add_netdevice_to_vt_control(intf_name);
return Py_BuildValue("i", ret);
}

static PyObject * py_startExp(PyObject *self, PyObject *args) {

int ret;
int ret = 1;

ret = startExp();
return Py_BuildValue("i", ret);
Expand All @@ -106,15 +112,15 @@ static PyObject * py_startExp(PyObject *self, PyObject *args) {

static PyObject * py_stopExp(PyObject *self, PyObject *args) {

int ret;
int ret = 1;

ret = stopExp();
return Py_BuildValue("i", ret);
}

static PyObject * py_initializeExp(PyObject *self, PyObject *args) {

int ret;
int ret = 1;
int n_tracers;
if (!PyArg_ParseTuple(args, "i", &n_tracers))
return NULL;
Expand All @@ -126,7 +132,7 @@ static PyObject * py_initializeExp(PyObject *self, PyObject *args) {

static PyObject * py_progress_n_rounds(PyObject *self, PyObject *args) {
int n_rounds;
int ret;
int ret = 1;

if (!PyArg_ParseTuple(args, "i", &n_rounds))
return NULL;
Expand All @@ -137,23 +143,23 @@ static PyObject * py_progress_n_rounds(PyObject *self, PyObject *args) {

static PyObject * py_progress(PyObject *self, PyObject *args) {

int ret;
int ret = 1;

ret = progress();
return Py_BuildValue("i", ret);
}

static PyObject * py_fire_timers(PyObject *self, PyObject *args) {

int ret;
int ret = 1;

ret = fire_timers();
return Py_BuildValue("i", ret);
}

static PyObject * py_synchronizeAndFreeze(PyObject *self, PyObject *args) {
int n_tracers;
int ret;
int ret = 1;

if (!PyArg_ParseTuple(args, "i", &n_tracers))
return NULL;
Expand All @@ -167,7 +173,7 @@ static PyObject * py_get_experiment_stats(PyObject *self, PyObject *arg) {
args.round_error = 0;
args.round_error_sq = 0;
args.n_rounds = 0;
int ret;
int ret = 1;


ret = get_experiment_stats(&args);
Expand All @@ -184,7 +190,7 @@ static PyObject * py_o_get_experiment_stats(PyObject *self, PyObject *arg) {
args.round_error = 0;
args.round_error_sq = 0;
args.n_rounds = 0;
int ret;
int ret = 1;

ret = o_get_stats(&args);

Expand All @@ -207,14 +213,14 @@ static PyMethodDef kronos_functions_methods[] = {
{ "update_tracer_params", py_update_tracer_params, METH_VARARGS, NULL },
{ "write_tracer_results", py_write_tracer_results, METH_VARARGS, NULL },
{ "set_netdevice_owner", py_set_netdevice_owner, METH_VARARGS, NULL },
{ "add_netdevice_to_vt_control", py_add_netdevice_to_vt_control, METH_VARARGS, NULL },
{ "startExp", py_startExp, METH_VARARGS, NULL },
{ "stopExp", py_stopExp, METH_VARARGS, NULL },
{ "initializeExp", py_initializeExp, METH_VARARGS, NULL },
{ "progress_n_rounds", py_progress_n_rounds, METH_VARARGS, NULL },
{ "progress", py_progress, METH_VARARGS, NULL },
{ "fire_timers", py_fire_timers, METH_VARARGS, NULL},
{ "get_experiment_stats", py_get_experiment_stats, METH_VARARGS, NULL },
{ "hello", py_hello, METH_VARARGS, NULL },
{ "o_get_experiment_stats", py_o_get_experiment_stats, METH_VARARGS, NULL },
{NULL, NULL, 0, NULL}
};
Expand Down
107 changes: 57 additions & 50 deletions src/core/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ int register_tracer_process(char * write_buffer) {
mutex_unlock(&exp_lock);

if (should_create_spinner) {
PDEBUG_I("Register Tracer: Pid: %d, ID: %d, dilation factor: %d, "
PDEBUG_E("Register Tracer: Pid: %d, ID: %d, dilation factor: %d, "
"freeze_quantum: %d, assigned cpu: %d, quantum_n_insns: %d. "
"Spinner pid = %d\n", current->pid, new_tracer->tracer_id,
new_tracer->dilation_factor, new_tracer->freeze_quantum,
Expand Down Expand Up @@ -928,86 +928,93 @@ int handle_stop_exp_cmd() {
* write_buffer: <tracer_pid>,<network device name>
* Can be called after successfull synchronize and freeze command
**/
int handle_set_netdevice_owner_cmd(char * write_buffer) {
int handle_set_netdevice_owner_cmd(char * write_buffer, int attach_to_any_tracer) {


char dev_name[IFNAMSIZ];
int pid;
int pid_or_id = 0;
struct pid * pid_struct = NULL;
int i = 0;
struct net * net;
struct task_struct * task;
tracer * curr_tracer;
tracer * curr_tracer = NULL;
int found = 0;
int next_idx = 0;

for (i = 0; i < IFNAMSIZ; i++)
dev_name[i] = '\0';

pid = atoi(write_buffer);
int next_idx = get_next_value(write_buffer);

if (!attach_to_any_tracer) {
pid_or_id = atoi(write_buffer);
next_idx = get_next_value(write_buffer);
}

for (i = 0; * (write_buffer + next_idx + i) != '\0'
&& *(write_buffer + next_idx + i) != ',' && i < IFNAMSIZ ; i++)
dev_name[i] = *(write_buffer + next_idx + i);

PDEBUG_A("Set Net Device Owner: Received Pid: %d, Dev Name: %s\n",
pid, dev_name);

if (attach_to_any_tracer)
PDEBUG_A("Set Net Device Owner: Dev Name: %s. Attempting to attach to any tracer..\n",
dev_name);
else
PDEBUG_A("Set Net Device Owner: Received Pid: %d, Dev Name: %s\n",
pid_or_id, dev_name);

struct net_device * dev;
for_each_process(task) {
if (task != NULL) {
if (task->pid == pid) {
pid_struct = get_task_pid(task, PIDTYPE_PID);
found = 1;

if (attach_to_any_tracer) {
for (i = 1; i <= tracer_num; i++) {
curr_tracer = hmap_get_abs(&get_tracer_by_id, i);
if (curr_tracer && curr_tracer->spinner_task)
break;
}
}
}
else
curr_tracer = hmap_get_abs(&get_tracer_by_pid, pid_or_id);


if (!curr_tracer) {
PDEBUG_E("No suitable tracer found. Failed to set Net Device Owner for: %s\n", dev_name);
return FAIL;
}

if (task && found) {
curr_tracer = hmap_get_abs(&get_tracer_by_pid, task->pid);
if (!curr_tracer)
return FAIL;

get_tracer_struct_read(curr_tracer);
task = curr_tracer->spinner_task;
put_tracer_struct_read(curr_tracer);
if (!task) {
PDEBUG_E("Must have spinner task to "
"be able to set net device owner\n");
return FAIL;
}
get_tracer_struct_read(curr_tracer);
task = curr_tracer->spinner_task;
put_tracer_struct_read(curr_tracer);
if (!task) {
PDEBUG_E("Must have spinner task to "
"be able to set net device owner\n");
return FAIL;
}

pid_struct = get_task_pid(task, PIDTYPE_PID);
if (!pid_struct) {
PDEBUG_E("Pid Struct of spinner task not found for tracer: %d\n",
curr_tracer->tracer_task->pid);
return FAIL;
}
pid_struct = get_task_pid(task, PIDTYPE_PID);
if (!pid_struct) {
PDEBUG_E("Pid Struct of spinner task not found for tracer: %d\n",
curr_tracer->tracer_task->pid);
return FAIL;
}

write_lock_bh(&dev_base_lock);
for_each_net(net) {
for_each_netdev(net, dev) {
if (dev != NULL) {
if (strcmp(dev->name, dev_name) == 0) {
PDEBUG_A("Set Net Device Owner: "
"Found Specified Net Device: %s\n", dev_name);
dev->owner_pid = pid_struct;
found = 1;
}
write_lock_bh(&dev_base_lock);
for_each_net(net) {
for_each_netdev(net, dev) {
if (dev != NULL) {
if (strcmp(dev->name, dev_name) == 0) {
PDEBUG_A("Set Net Device Owner: "
"Found Specified Net Device: %s\n", dev_name);
dev->owner_pid = pid_struct;
found = 1;
break;
}
}
}

write_unlock_bh(&dev_base_lock);

} else {
PDEBUG_E("Failed to set Net Device Owner for: %s\n", dev_name);
return FAIL;
if (found)
break;
}

write_unlock_bh(&dev_base_lock);



return SUCCESS;
}
Expand Down
1 change: 1 addition & 0 deletions src/core/kronos_cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define TRACER_RESULTS 'J'
#define INITIALIZE_EXP 'K'
#define RUN_DILATED_HRTIMERS 'L'
#define ADD_NETDEVICE_TO_VT_CONTROL 'M'


#endif
5 changes: 4 additions & 1 deletion src/core/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ ssize_t status_write(struct file *file, const char __user *buffer,
ret = handle_tracer_results(write_buffer + 2);
mutex_unlock(&file_lock);
} else if (write_buffer[0] == SET_NETDEVICE_OWNER) {
ret = handle_set_netdevice_owner_cmd(write_buffer + 2);
ret = handle_set_netdevice_owner_cmd(write_buffer + 2, 0);
mutex_unlock(&file_lock);
} else if (write_buffer[0] == ADD_NETDEVICE_TO_VT_CONTROL) {
ret = handle_set_netdevice_owner_cmd(write_buffer + 2, 1);
mutex_unlock(&file_lock);
} else if (write_buffer[0] == GETTIMEPID) {
ret = handle_gettimepid(write_buffer + 2);
Expand Down
2 changes: 1 addition & 1 deletion src/core/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ extern void update_all_tracers_virtual_time(int cpuID);
extern void resume_all_syscall_blocked_processes_from_tracer(unsigned long arg);
extern int handle_tracer_results(char * buffer);
extern int handle_stop_exp_cmd();
extern int handle_set_netdevice_owner_cmd(char * write_buffer);
extern int handle_set_netdevice_owner_cmd(char * write_buffer, int is_arg_tracer_id);
extern int do_dialated_poll(unsigned int nfds, struct poll_list *list,
struct poll_wqueues *wait, struct task_struct * tsk);
extern int do_dialated_select(int n, fd_set_bits *fds, struct task_struct * tsk,
Expand Down
2 changes: 1 addition & 1 deletion src/tracer/libperf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ AR = ar
AUTOCONF = ${SHELL} /home/kronos/Kronos/src/tracer/libperf/build-aux/missing autoconf
AUTOHEADER = ${SHELL} /home/kronos/Kronos/src/tracer/libperf/build-aux/missing autoheader
AUTOMAKE = ${SHELL} /home/kronos/Kronos/src/tracer/libperf/build-aux/missing automake-1.15
AWK = mawk
AWK = gawk
CC = gcc
CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2
Expand Down
Loading

0 comments on commit 2276756

Please sign in to comment.