Linux CPU Core Isolation for a Process
Today we will isolate a CPU core, deny the Linux scheduler from using it, and assign it to a specific process. It can be used to ensure CPU core availability for critical processes and can be useful in many cases (especially on CPUs with asymmetric cores, like E and P cores in Intel desktop CPUs).
In my case, I’m working with Raspberry Pi with my students for the past couple of weeks, so, as an example in this post, we will make the process use a dedicated core on the RPi.
First we should edit our /boot/firmware/cmdline.txt and add this parameter to the end of the string:
IMPORTANT! The file should contain only one string. Don’t add another string, otherwise the system will not boot!
After this operation, just reboot your RPi, and the Linux kernel will not use that core anymore. Next we will assign this core to the daemon we will do it for the Tor process. Run the command:
Use your service name instead of <SERVICE.NAME>. You will see the text editor, add this parameter there and save the file:
Then restart the service and it will be started attached to our isolated core:
Check if everything works correctly. Find the process ID and check if it uses the correct core:
In the second command, use the process ID from the first command instead of “1111”.
Distro-specific paths
/boot/firmware/cmdline.txt is specific to Raspberry OS. Depending on the used Linux distro and bootloader, the kernel command line arguments may be stored in different locations. So, it may be /etc/default/grub or a specifically named file in the directory /boot/loader/entries/. Check the documentation.
Isolating the Tor process
My students love to use the Tor network and create Tor Hidden Services. But isolating the Tor process is a bit tricky because the “tor” process is a dummy service. To use the real process on the dedicated core, we should create the file /etc/systemd/system/[email protected] and put this configuration inside:
Then reload the systemd and restart the Tor service: