#! /bin/zsh # here are some useful zsh commands # that will facilitate running experiments # using the system described in this report # misc now-ns () { echo $((`date +%s`*10**9 + `date +%N`)) } get-group () { awk '{print $5}' < /proc/$1/stat } # this is cgroup 0 # a cgroup is a set of processes # that can be stopped and resumed collectively BE_PATH=/sys/fs/cgroup/freezer/0 # the cgroup path STATE_FILE=$BE_PATH/freezer.state # and state: either FROZEN or THAWED TASK_FILE=$BE_PATH/tasks # PIDs of processes included # if cgroup 0 has not been created, use this to create it: # the permissions are set so that you don't need root # either to add/remove a process to the group, # nor to have it stopped or resumed be-init () { if [[ ! -d $BE_PATH ]]; then su -c "mkdir $BE_PATH; chmod a=wr $STATE_FILE $TASK_FILE" fi be-start } # manually set the state of the cgroup: # normally, this will not be done # but for debugging be-stop () { echo FROZEN > $STATE_FILE } be-start () { echo THAWED > $STATE_FILE } # this runs a program on BE, and # adds the PID to the cgroup be-task () { taskset -c $BE_CORE $@ & local pid=$! echo $pid >> $TASK_FILE } # play a multimedia file with mplayer2(1) on BE be-mp () { be-task mplayer --ao=null --loop=0 -noconsolecontrols -fs \ $1 &> /dev/null } # memory stress(1) with N spinners of malloc(3)/free(3) # on either core cc-stress () { stress --vm $1 -t 60 } cont-be-stress () { while (true) { be-stress 10 10 } } be-stress () { local amp=$1 local time=$2 local io=$((4*$amp)) local vm=$((2*$amp)) local vmb=$((128*2**((log($amp)/log(2)))))M be-task stress --io $io \ --vm $vm \ --vm-bytes $vmb \ --timeout $time > /dev/null } be-movie () { be-mp ~/box/Wlad_Pulev.mp4 } be-kill () { killall -9 $@ 2> /dev/null }