Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide APIs for CPU isolation (benchmarks) #2157

Open
giampaolo opened this issue Oct 19, 2022 · 0 comments
Open

Provide APIs for CPU isolation (benchmarks) #2157

giampaolo opened this issue Oct 19, 2022 · 0 comments

Comments

@giampaolo
Copy link
Owner

giampaolo commented Oct 19, 2022

Benchmarking is a complex science, see: https://easyperf.net/blog/2019/08/02/Perf-measurement-environment-on-Linux.
It seems like an important aspect of benchmarking is asking the kernel to isolate a certain CPU, so that only a benchmark script can use it and avoid sharing that CPU with other processes.

It must be noted that psutil already provides some tools which one typically wants to run before a benchmark:

def set_highest_priority():
    """Set highest CPU and I/O priority (requires root)."""
    p = psutil.Process()
    if psutil.WINDOWS:
        p.nice(psutil.HIGH_PRIORITY_CLASS)
    else:
        p.nice(-20)

    if psutil.LINUX:
        p.ionice(psutil.IOPRIO_CLASS_RT, value=7)
    elif psutil.WINDOWS:
        p.ionice(psutil.IOPRIO_HIGH)

It would be nice if the above code could be extended to allow something like this:

>>> psutil.cpu_isolation()  # get
[]
>>> psutil.cpu_isolation([1, 2])  # set
>>> psutil.cpu_isolation()
[1, 2]
>>>
>>> psutil.Process().cpu_affinity([1, 2])  # isolate this process
>>>

Useful URLs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant