how to detect if isolcpus is activated?
What you look for should be found inside this virtual file:
/sys/devices/system/cpu/isolated
and the reverse in
/sys/devices/system/cpu/present // Thanks to John Zwinck
From drivers/base/cpu.c
we see that the source displayed is the kernel variable cpu_isolated_map
:
static ssize_t print_cpus_isolated(struct device *dev,
n = scnprintf(buf, len, "%*pbl\n", cpumask_pr_args(cpu_isolated_map));
...
static DEVICE_ATTR(isolated, 0444, print_cpus_isolated, NULL);
and cpu_isolated_map
is exactly what gets set by kernel/sched/core.c
at boot:
/* Setup the mask of cpus configured for isolated domains */
static int __init isolated_cpu_setup(char *str)
{
int ret;
alloc_bootmem_cpumask_var(&cpu_isolated_map);
ret = cpulist_parse(str, cpu_isolated_map);
if (ret) {
pr_err("sched: Error, all isolcpus= values must be between 0 and %d\n", nr_cpu_ids);
return 0;
}
return 1;
}
But as you observed, someone could have modified the affinity of processes, including daemon-spawned ones, cron
, systemd
and so on. If that happens, new processes will be spawned inheriting the modified affinity mask, not the one set by isolcpus
.
So the above will give you isolcpus
as you requested, but that might still not be helpful.
Supposing that you find out that isolcpus
has been issued, but has not "taken", this unwanted behaviour could be derived by some process realizing that it is bound to only CPU=0
, believing it is in monoprocessor mode by mistake, and helpfully attempting to "set things right" by resetting the affinity mask. If that was the case, you might try and isolate CPUS 0-5 instead of 1-6, and see whether this happens to work.
One of the easier ways to detect if isolcpus
is consulting proc
to see which parameters were passed to the kernel in runtime.
For that, you would use:
$cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-4.8.0-1-amd64 root=/dev/sda1 ro isolcpus=2,3 quiet
As you can see, in this particular example isolcpus=2,3
was passed as an argument to the running kernel.
You can also use taskset
pointed to PID 1. As PID 1 is the standard PID for the first task launched by the kernel, we can take as a pretty good indication that it will reflect whether we have isolcpus
working. As in:
$taskset -cp 1
pid 1's current affinity list: 0,1
Comparing with the lscpu
command in the same server:
$lscpu | grep CPU.s
CPU(s): 4
On-line CPU(s) list: 0-3
NUMA node0 CPU(s): 0-3
As it can be seen, lscpu
is showing 4 CPU/cores, while taskset
is only showing 0,1, so this shows isolcpus
is working here.
Have a look to at: How to ensure exclusive CPU availability for a running process?
You can check Cpus_allowed and Cpus_allowed_list for current shell process to see what cpus were reserved
cat /proc/$$/status|tail -6
for eg
Cpus_allowed_list: 0-1, 3-5
means that the cpu=2 was reserved by isolcpus
on a 6 cpus server