Skip to content

cpu-affinity test fail on Archlinux #956

@tijko

Description

@tijko

Running Archlinux kernel 4.8.13-1 with the latest versions of Python 3.6.0 and psutil 5.1.0:

python test_linux.py
......
======================================================================
FAIL: test_linux.TestProcessAgainstStatus.test_cpu_affinity
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tijko/psutil/psutil/tests/test_linux.py", line 1278, in test_cpu_affinity
    self.proc.cpu_affinity(), list(range(min_, max_ + 1)))
AssertionError: Lists differ: [0, 1, 2, 3] != [0, 1, 2, 3, 4, 5, 6, 7]

Second list contains 4 additional elements.
First extra element 4:
4

- [0, 1, 2, 3]
+ [0, 1, 2, 3, 4, 5, 6, 7]

The test value for cpus_allowed is being read from /proc/$/status and where as I have the kernel configured with CONFIG_HOTPLUG_CPU=y set.

From cpuset.h:

If !CONFIG_HOTPLUG_CPU, present == possible, and active == online.

The cpu_possible_mask is fixed at boot time, as the set of CPU id's
that it is possible might ever be plugged in at anytime during the
life of that system boot. The cpu_present_mask is dynamic(*),
representing which CPUs are currently plugged in. And
cpu_online_mask is the dynamic subset of cpu_present_mask,
indicating those CPUs available for scheduling.

If HOTPLUG is enabled, then cpu_possible_mask is forced to have
all NR_CPUS bits set, otherwise it is just the set of CPUs that
ACPI reports present at boot.

It would seem that if cpu-hotplugging is enabled this value is the mask with all the bits flipped by default at boot-time, even if they're non-existent.

FWIW, if you call psutil.cpu_affinity(cpus_allowed) where cpus_allowed is a list of cpus from status. After this call, the correct value is listed in status, where it goes from say [0-7] to [0-3].

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions