From 22767565f30944dc0c3bb8a1c810564d7f0dbc72 Mon Sep 17 00:00:00 2001 From: Vignesh Babu Date: Thu, 17 Sep 2020 11:15:46 -0700 Subject: [PATCH] adding an api function to register a netdevice to any available tracer with a spinner task --- src/api/Kronos_definitions.h | 2 + src/api/Kronos_functions.c | 17 +++++ src/api/Kronos_functions.h | 1 + src/api/py_extensions.c | 46 +++++++------ src/core/common.c | 107 ++++++++++++++++--------------- src/core/kronos_cmds.h | 1 + src/core/module.c | 5 +- src/core/module.h | 2 +- src/tracer/libperf/Makefile | 2 +- src/tracer/libperf/config.status | 4 +- src/tracer/libperf/src/Makefile | 2 +- 11 files changed, 113 insertions(+), 76 deletions(-) diff --git a/src/api/Kronos_definitions.h b/src/api/Kronos_definitions.h index 7eb2ea3..900f6c9 100755 --- a/src/api/Kronos_definitions.h +++ b/src/api/Kronos_definitions.h @@ -17,5 +17,7 @@ #define INITIALIZE_EXP 'K' #define RUN_DILATED_HRTIMERS 'L' +#define ADD_NETDEVICE_TO_VT_CONTROL 'M' + #endif diff --git a/src/api/Kronos_functions.c b/src/api/Kronos_functions.c index e562ea5..33ad0ea 100644 --- a/src/api/Kronos_functions.c +++ b/src/api/Kronos_functions.c @@ -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) diff --git a/src/api/Kronos_functions.h b/src/api/Kronos_functions.h index 8ff735e..94ec4dc 100644 --- a/src/api/Kronos_functions.h +++ b/src/api/Kronos_functions.h @@ -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(); diff --git a/src/api/py_extensions.c b/src/api/py_extensions.c index 2097e6f..00e0a08 100644 --- a/src/api/py_extensions.c +++ b/src/api/py_extensions.c @@ -27,7 +27,7 @@ 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; @@ -35,17 +35,12 @@ static PyObject * py_addToExp(PyObject *self, PyObject *args) { 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)) @@ -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)) @@ -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; @@ -87,7 +82,7 @@ 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; @@ -95,9 +90,20 @@ static PyObject * py_set_netdevice_owner(PyObject *self, PyObject *args) { 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); @@ -106,7 +112,7 @@ 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); @@ -114,7 +120,7 @@ static PyObject * py_stopExp(PyObject *self, PyObject *args) { 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; @@ -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; @@ -137,7 +143,7 @@ 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); @@ -145,7 +151,7 @@ static PyObject * py_progress(PyObject *self, PyObject *args) { static PyObject * py_fire_timers(PyObject *self, PyObject *args) { - int ret; + int ret = 1; ret = fire_timers(); return Py_BuildValue("i", ret); @@ -153,7 +159,7 @@ static PyObject * py_fire_timers(PyObject *self, PyObject *args) { 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; @@ -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); @@ -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); @@ -207,6 +213,7 @@ 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 }, @@ -214,7 +221,6 @@ static PyMethodDef kronos_functions_methods[] = { { "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} }; diff --git a/src/core/common.c b/src/core/common.c index 4ddad7e..0f43d90 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -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, @@ -928,86 +928,93 @@ int handle_stop_exp_cmd() { * write_buffer: , * 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; } diff --git a/src/core/kronos_cmds.h b/src/core/kronos_cmds.h index 7450db7..e97ea8f 100644 --- a/src/core/kronos_cmds.h +++ b/src/core/kronos_cmds.h @@ -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 diff --git a/src/core/module.c b/src/core/module.c index 8f8da2d..31192ba 100644 --- a/src/core/module.c +++ b/src/core/module.c @@ -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); diff --git a/src/core/module.h b/src/core/module.h index fca8fa4..120ea53 100644 --- a/src/core/module.h +++ b/src/core/module.h @@ -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, diff --git a/src/tracer/libperf/Makefile b/src/tracer/libperf/Makefile index ea6cbd3..db3d1f2 100644 --- a/src/tracer/libperf/Makefile +++ b/src/tracer/libperf/Makefile @@ -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 diff --git a/src/tracer/libperf/config.status b/src/tracer/libperf/config.status index 658e6f2..3174bca 100755 --- a/src/tracer/libperf/config.status +++ b/src/tracer/libperf/config.status @@ -442,7 +442,7 @@ ac_pwd='/home/kronos/Kronos/src/tracer/libperf' srcdir='.' INSTALL='/usr/bin/install -c' MKDIR_P='/bin/mkdir -p' -AWK='mawk' +AWK='gawk' test -n "$AWK" || AWK=awk # The default lists apply if the user does not specify any file. ac_need_defaults=: @@ -881,7 +881,7 @@ S["am__tar"]="$${TAR-tar} chof - \"$$tardir\"" S["AMTAR"]="$${TAR-tar}" S["am__leading_dot"]="." S["SET_MAKE"]="" -S["AWK"]="mawk" +S["AWK"]="gawk" S["mkdir_p"]="$(MKDIR_P)" S["MKDIR_P"]="/bin/mkdir -p" S["INSTALL_STRIP_PROGRAM"]="$(install_sh) -c -s" diff --git a/src/tracer/libperf/src/Makefile b/src/tracer/libperf/src/Makefile index f04cfd9..c169dcb 100644 --- a/src/tracer/libperf/src/Makefile +++ b/src/tracer/libperf/src/Makefile @@ -230,7 +230,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