Skip to content
  • David Hildenbrand's avatar
    7730f32c
    util: Introduce qemu_thread_set_affinity() and qemu_thread_get_affinity() · 7730f32c
    David Hildenbrand authored
    
    
    Usually, we let upper layers handle CPU pinning, because
    pthread_setaffinity_np() (-> sched_setaffinity()) is blocked via
    seccomp when starting QEMU with
        -sandbox enable=on,resourcecontrol=deny
    
    However, we want to configure and observe the CPU affinity of threads
    from QEMU directly in some cases when the sandbox option is either not
    enabled or not active yet.
    
    So let's add a way to configure CPU pinning via
    qemu_thread_set_affinity() and obtain CPU affinity via
    qemu_thread_get_affinity() and implement them under POSIX using
    pthread_setaffinity_np() + pthread_getaffinity_np().
    
    Implementation under Windows is possible using SetProcessAffinityMask()
    + GetProcessAffinityMask(), however, that is left as future work.
    
    Reviewed-by: default avatarMichal Privoznik <mprivozn@redhat.com>
    Message-Id: <20221014134720.168738-3-david@redhat.com>
    Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
    7730f32c
    util: Introduce qemu_thread_set_affinity() and qemu_thread_get_affinity()
    David Hildenbrand authored
    
    
    Usually, we let upper layers handle CPU pinning, because
    pthread_setaffinity_np() (-> sched_setaffinity()) is blocked via
    seccomp when starting QEMU with
        -sandbox enable=on,resourcecontrol=deny
    
    However, we want to configure and observe the CPU affinity of threads
    from QEMU directly in some cases when the sandbox option is either not
    enabled or not active yet.
    
    So let's add a way to configure CPU pinning via
    qemu_thread_set_affinity() and obtain CPU affinity via
    qemu_thread_get_affinity() and implement them under POSIX using
    pthread_setaffinity_np() + pthread_getaffinity_np().
    
    Implementation under Windows is possible using SetProcessAffinityMask()
    + GetProcessAffinityMask(), however, that is left as future work.
    
    Reviewed-by: default avatarMichal Privoznik <mprivozn@redhat.com>
    Message-Id: <20221014134720.168738-3-david@redhat.com>
    Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
Loading