qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 3/7] util: Introduce ThreadContext user-creatable object


From: David Hildenbrand
Subject: Re: [PATCH v1 3/7] util: Introduce ThreadContext user-creatable object
Date: Thu, 29 Sep 2022 18:05:08 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0

+##
+# @ThreadContextProperties:
+#
+# Properties for thread context objects.
+#
+# @cpu-affinity: the CPU affinity for all threads created in the thread
+#                context (default: QEMU main thread affinity)
+#
+# Since: 7.2
+##
+{ 'struct': 'ThreadContextProperties',
+  'data': { '*cpu-affinity': ['uint16'] } }

I understand this is a list of affinities.  What I poor ignorant me
doesn't understand is the meaning of the list index.  Or in other words,
the list maps some range [0:N] to affinities, but what are the numbers
being mapped there?

Assume you have 8 physical CPUs.

$ lscpu
...

NUMA:
   NUMA node(s):          1
   NUMA node0 CPU(s):     0-7
...

You will provide the CPU IDs here, for example as in patch #7 example:

qemu-system-x86_64 -m 1G \
  -object thread-context,id=tc1,cpu-affinity=3-4 \
  -object 
memory-backend-ram,id=pc.ram,size=1G,prealloc=on,prealloc-threads=2,prealloc-context=tc1
\
  -machine memory-backend=pc.ram \
  -S -monitor stdio -sandbox enable=on,resourcecontrol=deny


Details about CPU affinities in general can be found in the man page of taskset:

https://man7.org/linux/man-pages/man1/taskset.1.html

Is @cpu-affinity a set of CPU numbers?

Yes! For now I added to the description:

...
    General information about CPU affinities can be found in the man page of
    taskset:
        CPU affinity is a scheduler property that "bonds" a process to a given
        set of CPUs on the system. The Linux scheduler will honor the given CPU
        affinity and the process will not run on any other CPUs.
...
    A simple QEMU example to set the CPU affinity to CPU 0,1,6,7 would be:
        qemu-system-x86_64 -S \
          -object thread-context,id=tc1,cpu-affinity=0-1,cpu-affinity=6-7
And we can query it via HMP/QMP:
        (qemu) qom-get tc1 cpu-affinity
        [
            0,
            1,
            6,
            7
        ]
But note that due to dynamic library loading this example will not work
    before we actually make use of thread_context_create_thread() in QEMU
    code, because the type will otherwise not get registered.




Please let me know how I can further clarify this, that would help, thanks!

What happens when you try to create a thread context object with CPU
affinities on a host system that doesn't support CPU affinities?

qemu_thread_set_affinity() will fail and setting the attribute will result
in a "Setting CPU affinity failed".

Thanks!

--
Thanks,

David / dhildenb




reply via email to

[Prev in Thread] Current Thread [Next in Thread]