Linux – how to detect if isolcpus is activated

kernellinux

How to detect if isolcpus is activated and on which cpus, when for example you connect for the first time on a server.
Conditions:

not spawning any process to see where it will be migrated.

The use case is that isolcpus=1-7 on a 6 cores i7, seems to not activate isolcpus at boot, and i would like to know if its possible from /proc/, /sys or any kernel internals which can be read in userspace, to provide a clear status of activation of isolcpus and which cpu are concerned.
Or even read active setting of the scheduler which is the first concerned by isolcpus.

Consider the uptime is so big, that dmesg is no more displaying boot log to detect any error at startup.
Basic answer like "look at kernel cmd line" will not be accepted 🙂

Best Answer

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.

Related Question