diff --git a/.gitignore b/.gitignore index b21a6e7..736ffad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ netreplay +powercap __pycache__ rpxy_* records/ diff --git a/README.md b/README.md index a36deab..261ba9a 100644 --- a/README.md +++ b/README.md @@ -352,6 +352,13 @@ python exp.py run local python plots.py prof ``` +### RAPL + +```bash +gcc -O3 powercap.c -o powercap +sudo chmod u+s powercap +``` + ## Problems ### Youtube diff --git a/exp.py b/exp.py index 657940a..1f6f011 100644 --- a/exp.py +++ b/exp.py @@ -4,15 +4,18 @@ import os, sys, subprocess CONFIGS = { "debug": { "experiments": [ + "impl-cipher-ver", + "impl-cert-ver", + "impl-kex-ver", "zrtt", ], "setups": [ - #"none-local", + "none-local", "client-local", - #"server-local", + "server-local", ], "records": [ - { "filename": "youtube", "repeat": 1 }, + { "filename": "wikipedia", "repeat": 1 }, ], "repodir": "/home/tuxmain/reps/tlsbench", "expdir": "/dev/shm/exp", @@ -22,6 +25,7 @@ CONFIGS = { "p2_repodir": "/home/tuxmain/reps/tlsbench", "wattmeter": False, "perf": False, + "rapl": False, "perf_dir": "/home/tuxmain/.cache/exp", "p3_suffix": ".localhost", "p3_port_plain": 8080, @@ -50,6 +54,7 @@ CONFIGS = { "p2_repodir": "/home/tuxmain/reps/tlsbench", "wattmeter": False, "perf": True, + "rapl": False, "perf_dir": "/home/tuxmain/.cache/exp", "p3_suffix": ".localhost", "p3_port_plain": 8080, @@ -69,7 +74,7 @@ CONFIGS = { "server", ], "records": [ - { "filename": "youtube", "repeat": 1 }, + { "filename": "wikipedia", "repeat": 500 }, ], "repodir": "/home/tuxmain/reps/tlsbench", "expdir": "/dev/shm/exp", @@ -81,10 +86,11 @@ CONFIGS = { "p2_repodir": "/home/exp/exp", "wattmeter": True, "perf": False, + "rapl": False, "p3_suffix": "", "p3_port_plain": 80, "p3_port_tls": 443, - "idle": "idle - - - - - - - 600.000081539154 0.0 896 4792 0.5399999999999991 -", + "idle": "idle - - - - - - - 600.000081539154 0.0 896 4792 0.5399999999999991 0 -", }, "pi3-local": { "experiments": [ @@ -108,6 +114,7 @@ CONFIGS = { "p2_repodir": "/home/exp/exp", "wattmeter": False, "perf": True, + "rapl": False, "perf_dir": "/home/exp/.cache/exp", "p3_suffix": ".localhost", "p3_port_plain": 8080, @@ -139,10 +146,11 @@ CONFIGS = { "p2_repodir": "/home/exp/exp", "wattmeter": True, "perf": False, + "rapl": False, "p3_suffix": "", "p3_port_plain": 80, "p3_port_tls": 443, - "idle": "idle - - - - - - - 600.0001013278961 0.0 735 4942 1.7759999999999962 -", + "idle": "idle - - - - - - - 600.0001013278961 0.0 735 4942 1.7759999999999962 0 -", }, "core2-local": { "experiments": [ @@ -166,6 +174,66 @@ CONFIGS = { "p2_repodir": "/home/exp/exp", "wattmeter": False, "perf": True, + "rapl": False, + "perf_dir": "/home/exp/.cache/exp", + "p3_suffix": ".localhost", + "p3_port_plain": 8080, + "p3_port_tls": 8443, + }, + # i7-4790 -> i5-7300HQ + "i5": { + "experiments": [ + "impl-cipher-ver", + "impl-cert-ver", + "impl-kex-ver", + ], + "setups": [ + "none", + "client", + "server", + ], + "records": [ + { "filename": "wikipedia", "repeat": 100 }, + ], + "repodir": "/home/tuxmain/reps/tlsbench", + "expdir": "/dev/shm/exp", + "log_backup_dir": "/home/tuxmain", + "p2_hostname": "192.168.3.42", + "p2_addr": "192.168.3.42", + "p2_ssh": "exp@192.168.3.42", + "p2_psw": None, + "p2_repodir": "/home/exp/exp", + "wattmeter": True, + "perf": False, + "rapl": True, + "p3_suffix": "", + "p3_port_plain": 80, + "p3_port_tls": 443, + "idle": "idle - - - - - - - 600.0001013278961 0.0 735 4942 1.7759999999999962 0 -", + }, + "i5-local": { + "experiments": [ + "impl-cipher-ver", + "impl-cert-ver", + "impl-kex-ver", + ], + "setups": [ + "none-local", + "client-local", + "server-local", + ], + "records": [ + { "filename": "wikipedia", "repeat": 10 }, + ], + "repodir": "/home/exp/exp", + "expdir": "/dev/shm/exp", + "log_backup_dir": "/home/exp", + "p2_hostname": "localhost", + "p2_addr": "127.0.0.1", + "p2_repodir": "/home/exp/exp", + "wattmeter": False, + "perf": True, + "rapl": False, "perf_dir": "/home/exp/.cache/exp", "p3_suffix": ".localhost", "p3_port_plain": 8080, @@ -234,9 +302,10 @@ CERT_SIGN_ALGS = [ IMPLS = [ "aws_lc", # Amazon's Rust crypto widely used in Rust stuff "boring", # Google's fork of OpenSSL used in Chrome and Android + "graviola", # New crypto in Rust "openssl", # widely used "ring", # used in most Rust stuff - #"symcrypt", # Microsoft's crypto + "symcrypt", # Microsoft's crypto #"wolfcrypt" # used in embedded (won't build with rpxy for now) ] # Symmetric ciphers @@ -346,7 +415,7 @@ EXPERIMENTS = { # Some algorithms are not available in all implementations def alg_filter(kex, cert, cipher, impl): - if "MLKEM" in kex and impl != "openssl" and impl != "aws_lc": + if "MLKEM" in kex and impl != "openssl" and impl != "aws_lc" and impl != "graviola": return False if kex == "SECP256R1MLKEM768" and impl == "openssl": return False @@ -584,14 +653,15 @@ def make_rpxy_config(outdir, domains, cryptodir, config_name, p3_suffix, p3_port )) f.close() -def make_everything(expdir, domains, make_ca, p3_suffix, p3_port_plain, p3_port_tls): - os.makedirs(expdir, exist_ok=True) - if expdir[-1] != "/": - expdir += "/" - for alg in CERT_SIGN_ALGS: - algdir = expdir+"certs/"+alg - os.makedirs(algdir, exist_ok=True) - make_certs(algdir, domains, alg, make_ca) +def make_everything(expdir, domains, make_ca, config_only, p3_suffix, p3_port_plain, p3_port_tls): + if not config_only: + os.makedirs(expdir, exist_ok=True) + if expdir[-1] != "/": + expdir += "/" + for alg in CERT_SIGN_ALGS: + algdir = expdir+"certs/"+alg + os.makedirs(algdir, exist_ok=True) + make_certs(algdir, domains, alg, make_ca) # this will be a symbolic link to the chosen certs directory cryptodir = expdir+"current_certs" configdir = expdir+"configs/" @@ -671,6 +741,15 @@ def get_net_stat(ssh): bytes_out = int(items[8]) return (bytes_in, bytes_out) +def get_rapl_energy(ssh, expdir): + res = ssh_run(ssh, expdir+"/powercap", hide=True) + items = res.split("\n") + energy = 0 + for item in items: + if item != "" and item != "-1": + energy += int(item) + return energy + def run_exp(config, only_record=None, idle=False): ssh = None if "p2_ssh" in config: @@ -702,7 +781,7 @@ def run_exp(config, only_record=None, idle=False): logfile_name = "log-"+timestr logfile_path = expdir+"/"+logfile_name logfile = open(logfile_path, "w") - logfile.write("exp impl alg kex cipher ed setup record time cpu bytes_in bytes_out Wh prof\n") + logfile.write("exp impl alg kex cipher ed setup record time cpu bytes_in bytes_out Wh Wh_rapl prof\n") logfile.close() perf_dir = "" @@ -715,27 +794,34 @@ def run_exp(config, only_record=None, idle=False): rpxy_cpu = get_cpu_stat(ssh) p2_bytes_in, p2_bytes_out = get_net_stat(ssh) energy = 0 + energy_rapl if config["wattmeter"]: energy = wattmeter.get_meter() + if config["rapl"]: + energy_rapl = get_rapl_energy(ssh) start = time.time() time.sleep(600) end = time.time() new_energy = 0 + new_energy_rapl = 0 if config["wattmeter"]: new_energy = wattmeter.get_meter() + if config["rapl"]: + new_energy_rapl = get_rapl_energy(ssh) new_p2_bytes_in, new_p2_bytes_out = get_net_stat(ssh) new_rpxy_cpu = get_cpu_stat(ssh) rpxy_cpu_diff = new_rpxy_cpu - rpxy_cpu p2_bytes_in_diff = new_p2_bytes_in - p2_bytes_in p2_bytes_out_diff = new_p2_bytes_out - p2_bytes_out energy_diff = new_energy - energy + energy_rapl_diff = new_energy_rapl - energy_rapl time_diff = end - start while True: try: with open(logfile_path, "a") as logfile: - logfile.write(f"idle - - - - - - - {time_diff} {rpxy_cpu_diff} {p2_bytes_in_diff} {p2_bytes_out_diff} {energy_diff} -\n") + logfile.write(f"idle - - - - - - - {time_diff} {rpxy_cpu_diff} {p2_bytes_in_diff} {p2_bytes_out_diff} {energy_diff} {energy_rapl_diff} -\n") logfile.close() break except Exception as e: @@ -790,8 +876,11 @@ def run_exp(config, only_record=None, idle=False): rpxy_cpu = get_cpu_stat(ssh) p2_bytes_in, p2_bytes_out = get_net_stat(ssh) energy = 0 + energy_rapl = 0 if config["wattmeter"]: energy = wattmeter.get_meter() + if config["rapl"]: + energy_rapl = get_rapl_energy(ssh) start = time.time() netreplay = run_netreplay( @@ -841,8 +930,11 @@ def run_exp(config, only_record=None, idle=False): end = time.time() new_energy = 0 + new_energy_rapl = 0 if config["wattmeter"]: new_energy = wattmeter.get_meter() + if config["rapl"]: + new_energy_rapl = get_rapl_energy(ssh) new_p2_bytes_in, new_p2_bytes_out = get_net_stat(ssh) new_rpxy_cpu = get_cpu_stat(ssh) record_filename = record["filename"] @@ -850,11 +942,12 @@ def run_exp(config, only_record=None, idle=False): p2_bytes_in_diff = new_p2_bytes_in - p2_bytes_in p2_bytes_out_diff = new_p2_bytes_out - p2_bytes_out energy_diff = new_energy - energy + energy_rapl_diff = new_energy_rapl - energy_rapl time_diff = end - start while True: try: with open(logfile_path, "a") as logfile: - logfile.write(f"{expname} {impl} {alg} {kex} {cipher} {earlydata} {setup} {record_filename} {time_diff} {rpxy_cpu_diff} {p2_bytes_in_diff} {p2_bytes_out_diff} {energy_diff} {prof_filename}\n") + logfile.write(f"{expname} {impl} {alg} {kex} {cipher} {earlydata} {setup} {record_filename} {time_diff} {rpxy_cpu_diff} {p2_bytes_in_diff} {p2_bytes_out_diff} {energy_diff} {energy_rapl_diff} {prof_filename}\n") logfile.close() break except Exception as e: @@ -909,14 +1002,15 @@ def connect_ssh(config): if __name__ == "__main__": if len(sys.argv) < 2 or sys.argv[1] in ["h", "help", "?", "-h", "-help", "--help", "/?"]: print("""Options: - make [-c] Create everything - cert Select cert signature algorithm - send Send configs and certs to p2 - update-certs Update system's certs - run Run experiment + make [-c] [-o] Create everything + cert Select cert signature algorithm + send Send configs and certs to p2 + update-certs Update system's certs + run Run experiment Make options: -c Make CA cert (otherwise use already existing one) + -o Make only configs (do not make certs) Cert options: One of: {sig_algs} @@ -940,7 +1034,8 @@ Run options: if opt == "make": config = CONFIGS[sys.argv[2]] make_ca = "-c" in sys.argv - make_everything(config["expdir"], DOMAINS, make_ca, config["p3_suffix"], config["p3_port_plain"], config["p3_port_tls"]) + config_only = "-o" in sys.argv + make_everything(config["expdir"], DOMAINS, make_ca, config_only, config["p3_suffix"], config["p3_port_plain"], config["p3_port_tls"]) elif opt == "cert": alg = sys.argv[3] if not alg in CERT_SIGN_ALGS: diff --git a/powercap.c b/powercap.c new file mode 100644 index 0000000..c33d4c5 --- /dev/null +++ b/powercap.c @@ -0,0 +1,24 @@ +// gcc -O3 powercap.c -o powercap + +#include +#include + +void read_energy(char *path) { + FILE *fd = fopen(path, "r"); + if(fd) { + char buf[32]; + int len = fread(buf, 1, 31, fd); + fclose(fd); + buf[len] = 0; + printf("%s", buf); + } else { + printf("-1\n"); + } +} + +int main() { + read_energy("/sys/class/powercap/intel-rapl/subsystem/intel-rapl:0:0/energy_uj"); + read_energy("/sys/class/powercap/intel-rapl/subsystem/intel-rapl:0:1/energy_uj"); + read_energy("/sys/class/powercap/intel-rapl/subsystem/intel-rapl:0:2/energy_uj"); + return 0; +}