aboutsummaryrefslogtreecommitdiff
path: root/sandbox
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/.gitignore2
-rw-r--r--sandbox/config19
-rw-r--r--sandbox/config_beaglebone19
-rw-r--r--sandbox/config_rpi19
-rw-r--r--sandbox/pure-read/Makefile10
-rw-r--r--sandbox/pure-read/read.c88
-rwxr-xr-xsandbox/run_beaglebone.sh138
-rwxr-xr-xsandbox/run_host.sh74
8 files changed, 369 insertions, 0 deletions
diff --git a/sandbox/.gitignore b/sandbox/.gitignore
new file mode 100644
index 0000000..841d798
--- /dev/null
+++ b/sandbox/.gitignore
@@ -0,0 +1,2 @@
+ina260-zmq-publisher
+pure-read/read \ No newline at end of file
diff --git a/sandbox/config b/sandbox/config
new file mode 100644
index 0000000..317165f
--- /dev/null
+++ b/sandbox/config
@@ -0,0 +1,19 @@
+# Global Configuration:
+inadev="2:0x40 2:0x41 2:0x42 2:0x43"
+bbhost=debian@192.168.6.2
+delaypurezmq=10
+delayiperfpure=10
+
+# Pure Read Experiments:
+nread=500000
+readrest=60
+
+# ZMQ Experiments:
+zmqrest=60
+zmqduration=300
+hostip=192.168.7.1
+zmqport=5556
+zmqlogdelay=0
+zmqloginterval=60
+zmqmsgsize=20242880
+zmqmaxqueue=1
diff --git a/sandbox/config_beaglebone b/sandbox/config_beaglebone
new file mode 100644
index 0000000..317165f
--- /dev/null
+++ b/sandbox/config_beaglebone
@@ -0,0 +1,19 @@
+# Global Configuration:
+inadev="2:0x40 2:0x41 2:0x42 2:0x43"
+bbhost=debian@192.168.6.2
+delaypurezmq=10
+delayiperfpure=10
+
+# Pure Read Experiments:
+nread=500000
+readrest=60
+
+# ZMQ Experiments:
+zmqrest=60
+zmqduration=300
+hostip=192.168.7.1
+zmqport=5556
+zmqlogdelay=0
+zmqloginterval=60
+zmqmsgsize=20242880
+zmqmaxqueue=1
diff --git a/sandbox/config_rpi b/sandbox/config_rpi
new file mode 100644
index 0000000..376065a
--- /dev/null
+++ b/sandbox/config_rpi
@@ -0,0 +1,19 @@
+# Global Configuration:
+inadev="1:0x41"
+bbhost=pi@10.128.0.93
+delaypurezmq=0
+delayiperfpure=5
+
+# Pure Read Experiments:
+nread=500000
+readrest=5
+
+# ZMQ Experiments:
+zmqrest=5
+zmqduration=60
+hostip=10.128.0.133
+zmqport=5556
+zmqlogdelay=0
+zmqloginterval=10
+zmqmsgsize=20242880
+zmqmaxqueue=1 \ No newline at end of file
diff --git a/sandbox/pure-read/Makefile b/sandbox/pure-read/Makefile
new file mode 100644
index 0000000..353835b
--- /dev/null
+++ b/sandbox/pure-read/Makefile
@@ -0,0 +1,10 @@
+
+all: read
+
+read: read.c
+ gcc $^ -o $@
+
+clean:
+ - rm read
+
+.PHONY: clean \ No newline at end of file
diff --git a/sandbox/pure-read/read.c b/sandbox/pure-read/read.c
new file mode 100644
index 0000000..539933d
--- /dev/null
+++ b/sandbox/pure-read/read.c
@@ -0,0 +1,88 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+
+#define BUFFER_SIZE 255
+#define IN_MEM (inmem!=0)
+
+typedef struct power_data {
+ float power; // Power value
+ long ts; // Associated timestamp
+ long nsecs; // Associated nanosecs
+} power_data;
+
+int main(int argc, char *argv[])
+{
+ if(argc != 4){
+ printf("Usage: %s <device-id> <nread> <inmem>\n\
+ \rFor <device-id>, see folder name in /sys/kernel/ina260/",argv[0]);
+ exit(1);
+ }
+
+ char *deviceid=argv[1];
+ int nread=atoi(argv[2]);
+ int inmem=atoi(argv[3]);
+
+ if(nread<=0){
+ printf("<nread> must be greater than 0\n");
+ exit(3);
+ }
+
+ // File to read
+ char path[255];
+ sprintf(path, "/sys/kernel/ina260/%s/power", deviceid);
+
+ // Open file
+ int fd;
+ char buff[BUFFER_SIZE];
+ fd = open(path, O_RDONLY);
+ if(fd<0){
+ perror(path);
+ exit(2);
+ }
+
+ // Check if its in memory reading
+ power_data *data;
+ if(IN_MEM){
+ data=malloc(sizeof(power_data)*nread);
+ if(data == NULL){
+ perror("Cannot allocate enough memory for in memory reads");
+ exit(4);
+ }
+ }
+
+ // Perform reads
+ float power=-1;
+ struct timespec power_ts;
+ clock_gettime(CLOCK_REALTIME, &power_ts);
+
+ printf("startat:%ld\n", power_ts.tv_sec);
+ for(int i=0;i<nread;i++){
+ read(fd, buff, BUFFER_SIZE);
+ // Get power measurement timestamp:
+ clock_gettime(CLOCK_REALTIME, &power_ts);
+ power=atof(buff);
+ if(IN_MEM){
+ data[i].power=power;
+ data[i].ts=power_ts.tv_sec;
+ data[i].nsecs=power_ts.tv_nsec;
+ }
+ else{
+ printf("%s %11ld %10ld> Power is %fW\n",deviceid, power_ts.tv_sec,power_ts.tv_nsec,power);
+ }
+ lseek(fd,0,SEEK_SET);
+ }
+ close(fd);
+
+ if(IN_MEM){
+ // We only print now (most I/O will happend at the end and this must be visible on the results)
+ for(int i=0;i<nread;i++){
+ printf("%s %11ld %10ld> Power is %fW\n",deviceid, data[i].ts, data[i].nsecs, data[i].power);
+ }
+ free(data);
+ }
+ printf("endat:%ld\n", time(NULL));
+ return 0;
+}
diff --git a/sandbox/run_beaglebone.sh b/sandbox/run_beaglebone.sh
new file mode 100755
index 0000000..c610c6e
--- /dev/null
+++ b/sandbox/run_beaglebone.sh
@@ -0,0 +1,138 @@
+#!/usr/bin/env bash
+
+set -e
+
+wai=$(dirname $(readlink -f "$0")) # Current script directory
+source ${wai}/config
+
+info () {
+ echo -e "\033[0;32m$@\033[0m"
+}
+
+abort () {
+ echo -e "\033[0;31m$@\033[0m"
+ exit 1
+}
+
+iperf-run () {
+ info "---------- Running iperf test ----------"
+ iperf -c ${hostip}
+}
+
+pure-read () {
+ local clean="${1:-1}"
+ local inmem="${2:-0}"
+ info "---------- Running pure read experiments (inmem=${inmem},clean=${clean}) ----------"
+ info "Ensuring that ina260 devices are connected..."
+ for dev in $inadev
+ do
+ bus=$(echo $dev|cut -d: -f1)
+ addr=$(echo $dev|cut -d: -f2)
+ [ -z $(ls /sys/kernel/ina260/ |grep "${bus}-.*${addr#0x}") ] && echo ina260 $addr | sudo tee "/sys/bus/i2c/devices/i2c-${bus}/new_device"
+ [ -z $(ls /sys/kernel/ina260/ |grep "${bus}-.*${addr#0x}") ] && abort "Cannot connect $dev"
+ done
+ info "Compiling..."
+ make -C ${wai}/pure-read -B
+ [ $clean -eq 1 ] && rm -f ${wai}/pure_read_bus*.out
+ local ndev=$(echo $inadev|wc -w)
+ for usen in $(seq 1 $ndev)
+ do
+ info "Run $nread read over $usen devices"
+ local n=0
+ unset pids # Erase previous pids
+ for dev in $inadev
+ do
+ local bus=$(echo $dev|cut -d: -f1)
+ local addr=$(echo $dev|cut -d: -f2)
+ local devicepath=$(realpath /sys/kernel/ina260/${bus}-*${addr#0x})
+ local deviceid=$(basename ${devicepath})
+ local logfile=${wai}/pure_read_bus${bus}_addr${addr}_usen${usen}_nread${nread}_inmem${inmem}.out
+ echo "${bus}:${addr}:${usen}:${nread}:${deviceid}" > ${logfile}
+ /usr/bin/time -f "statsline:%P:%M" ${wai}/pure-read/read $deviceid $nread $inmem &>> ${logfile} &
+ pids[${i}]=$!
+ n=$(( n + 1 ))
+ [ $n -eq $usen ] && break
+ done
+ # Wait for all pids
+ for pid in ${pids[*]}; do
+ wait $pid
+ done
+ sync # Ensure that I/O are applied on sdcard
+ info "Beaglebone is resting for ${readrest}s"
+ sleep ${readrest}
+ done
+ # Generate the results
+ info "Collecting logs..."
+ local csv="${wai}/pure_read.csv"
+ [ $clean -eq 1 ] && echo "bus,addr,usen,nread,deviceid,startat,endat,inmem,cpu_usage,resident,timestamp,nsecs,power" > "$csv"
+ for logfile in ${wai}/pure_read_bus*inmem${inmem}.out
+ do
+ local bus=$(head -n1 "$logfile"|cut -d: -f1)
+ local addr=$(head -n1 "$logfile"|cut -d: -f2)
+ local usen=$(head -n1 "$logfile"|cut -d: -f3)
+ local nread=$(head -n1 "$logfile"|cut -d: -f4)
+ local deviceid="${bus}-${addr}"
+ local startat=$(cat "$logfile"|grep startat|cut -d: -f2)
+ local endat=$(cat "$logfile"|grep endat|cut -d: -f2)
+ local cpu_usage=$(cat "$logfile"|grep statsline|cut -d: -f2|awk '{print(($0+0)/100)}')
+ local resident=$(cat "$logfile"|grep statsline|cut -d: -f3|awk '{print(($0+0)*1000)}')
+ local infos="${bus},${addr},${usen},${nread},${deviceid},${startat},${endat},${inmem},${cpu_usage},${resident}"
+ awk '/Power is/ { print("'${infos}',"$2+0","$3+0","$6+0)}' "$logfile" >> "$csv"
+ done
+}
+
+zmq () {
+ echo "---------- Running zmq experiments ----------"
+ info "Disconnecting all ina260..."
+ for dev in $(ls /sys/kernel/ina260/)
+ do
+ dev=$(basename $dev)
+ bus=$(echo $dev|cut -d\- -f1)
+ addr=$(echo $dev|cut -d\- -f2)
+ echo 0x${addr} | sudo tee /sys/bus/i2c/devices/i2c-${bus}/delete_device
+ done
+ # Setup publisher
+ cd ${wai}/ina260-zmq-publisher
+ rm -f publisher_*.log
+ info "Compiling..."
+ make -B
+ # Run experiments (add one new ina260 at each loop)
+ local n=1
+ for dev in $inadev
+ do
+ info "Run zmq over $n devices for ${zmqduration}s"
+ bus=$(echo $dev|cut -d: -f1)
+ addr=$(echo $dev|cut -d: -f2)
+ [ -z $(ls /sys/kernel/ina260/ |grep "${bus}-.*${addr#0x}") ] && echo ina260 $addr | sudo tee "/sys/bus/i2c/devices/i2c-${bus}/new_device"
+ [ -z $(ls /sys/kernel/ina260/ |grep "${bus}-.*${addr#0x}") ] && abort "Cannot connect $dev"
+ # Run experiment
+ sed "s/^KEY=.*/KEY=usen$n/g" -i config.mk
+ make publish &
+ sleep ${zmqduration}
+ kill -s SIGINT $(cat pid)
+ # Wait for all publisher processes to end:
+ for pid in $(cat pid)
+ do
+ while ps -p $pid > /dev/null; do continue; done
+ done
+ # Done
+ n=$(( n + 1 ))
+ info "Beaglebone is resting for ${zmqrest}s"
+ sleep $zmqrest
+ done
+ cd ${wai} # Go back to last directory
+}
+
+##### Run experiments
+# Network benchmark
+iperf-run
+info "Sleep ${delayiperfpure}s before starting pure-read experiments..."
+sleep ${delayiperfpure}
+# Pure read
+pure-read 1 1 # Do in memory first!
+pure-read 0 0 # This way, we are sure in file has no impact
+# Sleep
+info "Sleep ${delaypurezmq}s before starting zmq experiments..."
+sleep ${delaypurezmq}
+# ZMQ
+zmq \ No newline at end of file
diff --git a/sandbox/run_host.sh b/sandbox/run_host.sh
new file mode 100755
index 0000000..c107d4b
--- /dev/null
+++ b/sandbox/run_host.sh
@@ -0,0 +1,74 @@
+#!/usr/bin/env bash
+set -e
+wai=$(dirname $(readlink -f "$0")) # Current script directory
+zmq=${wai}/ina260-zmq-publisher
+source ${wai}/config # Load experiment configuration
+bbexec="ssh -q ${bbhost}"
+nosync="no" # change this to yes ONLY FOR TESTS
+
+# Ensure zmq publisher is available
+[ ! -d "${zmq}" ] && git clone https://gitlab.com/manzerbredes/ina260-zmq-publisher.git "${zmq}"
+# Configuring zmq project
+echo "Configuring ina260-zmq-publisher"
+sed "s/^SUBSCRIBER_ADDR=.*/SUBSCRIBER_ADDR=${hostip}/g" -i ${zmq}/config.mk
+sed "s/^ZMQ_PORT=.*/ZMQ_PORT=${zmqport}/g" -i ${zmq}/config.mk
+sed "s/^LOG_DELAY=.*/LOG_DELAY=${zmqlogdelay}/g" -i ${zmq}/config.mk
+sed "s/^LOG_INTERVAL=.*/LOG_INTERVAL=${zmqloginterval}/g" -i ${zmq}/config.mk
+sed "s/^ZMQ_MSG_SIZE=.*/ZMQ_MSG_SIZE=${zmqmsgsize}/g" -i ${zmq}/config.mk
+sed "s/^MAX_QUEUE=.*/MAX_QUEUE=${zmqmaxqueue}/g" -i ${zmq}/config.mk
+
+# Setting up beaglebone
+[ ${nosync} != "yes" ] && rsync -avh --exclude=".git*" --exclude="ina260-zmq-publisher/data" ina260-zmq-publisher pure-read run_beaglebone.sh config ${bbhost}:sandbox/
+
+# Cleaning previous results
+[ -x "${zmq}/data" ] && rm -rf "${zmq}/data"
+
+##### Run experiments
+# Start zmq subscriber on the host
+echo "Starting subscriber"
+cd $zmq
+make -B
+make subscribe &
+zmqpid=$!
+cd - > /dev/null
+# Start iperf
+iperf -s -fm -o netstats.txt &
+iperfpid=$!
+# Start experiments
+$bbexec "cd sandbox && ./run_beaglebone.sh"
+
+# Collect pure-read results
+echo "Fetching pure-read results"
+rsync -avh ${bbhost}:sandbox/pure_read.csv ${wai}/../analysis/results/
+
+# Collect zmq results
+echo "Formatting zmq results"
+. ${wai}/config
+zmqcsv="${wai}/../analysis/results/zmq.csv"
+echo "bus,addr,deviceid,usen,duration,loginterval,logdelay,rest,msgsize,timestamp,nsecs,power" > "$zmqcsv"
+for exp in ${zmq}/data/*
+do
+ usen=$(basename $exp|sed "s/usen//g")
+ for dev in $exp/*
+ do
+ deviceid=$(basename $dev)
+ bus=$(echo $deviceid|cut -d\- -f1)
+ addr=0x$(echo $deviceid|cut -d\- -f2|awk '{print $0+0}')
+ infos="${bus},${addr},${bus}-${addr},${usen},${zmqduration},${zmqloginterval},${zmqlogdelay},${zmqrest},${zmqmsgsize}"
+ cat $dev/* | awk '!/timestamp/{print("'$infos',"$0)}' >> "$zmqcsv"
+ done
+done
+
+# Collecting iperf results
+echo "Formatting iperf results"
+bw=$(cat netstats.txt |awk -F '[ -]+' '/sec/{print $8}') # Mbps
+iperfcsv="${wai}/../analysis/results/iperf.csv"
+echo "bw" > "$iperfcsv"
+echo "${bw}" >> "$iperfcsv"
+
+# Stopping zmq subscriber and iperf
+echo "Stopping subscriber..."
+kill $zmqpid
+echo "Stopping iperf..."
+kill $iperfpid
+echo "Finished congratulations!"