Running Perf
You may need to run Perf to measure behaviour of code. It is restricted for security reasons, but there are a couple of options.
Note that Valdrind can be run on any machine (including any CSIL workstation or a VM). It doesn't need special permissions.
In A Virtual Machine: no
Perf won't give meaningful results in a virtual machine (including WSL2, Amazon EC2 instances, etc). The hardware counters that it uses are not passed through to VMs.
Your Computer, with admin access
If you have a non-VM Linux installation on your computer, then you should be able to run Perf.
User access to the performance counters isn't enabled by default: there are security implications, but if you broadly-trust everyone using your computer, you can temporarily enable (until reboot) with this command:
echo 0 | sudo tee /proc/sys/kernel/perf_event_paranoid
Or have it enabled on every restart with this command to create a config file to enable it:
echo "kernel.perf_event_paranoid = 0" | sudo tee /etc/sysctl.d/99-perf.conf
In CSIL
Perf has been enabled on a few CSIL workstations for use by this course. You can SSH to these computers and run Perf there. Your home directory should be there, so you can edit and compile on any CSIL machine, and just run code on these:
- asb9820u-b01.csil.sfu.ca
- asb9838nu-a05.csil.sfu.ca
- asb9838nu-a06.csil.sfu.ca
Update July 28: these machines have also been configured with perf
enabled. Perhaps they will be more stable than the others:
- asb9838nu-a08.csil.sfu.ca
- asb9838nu-a09.csil.sfu.ca
- asb9838nu-a15.csil.sfu.ca
From Your Computer
- If you're off campus, activate the SFU VPN.
- Edit your code on your computer, make sure it works, etc.
- Copy the source to CSIL: "
scp -P24 code.c USERNAME@csil-cpu1.csil.sfu.ca:
" or the equivalent in your favourite SCP/SFTP client. - Connect to one of the perf-enabled CSIL workstations by SSH": "
ssh -p24 USERNAME@COMPUTERNAME
" or the equivalent in your favourite SSH client. - In that remote SSH terminal, compile and run: "
gcc … code.c
" and "perf stat …
".
From CSIL
- Edit your code on a CSIL workstation, make sure it works, etc.
- Compile it on the workstation.
- Connect to one of the perf-enabled CSIL workstations by SSH: "
ssh -p24 USERNAME@COMPUTERNAME
" in a terminal window. - In that remote SSH terminal, run it: "
perf stat …
".