From: David Hildenbrand <david@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, "Michal Privoznik" <mprivozn@redhat.com>,
"Igor Mammedov" <imammedo@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
"Eric Blake" <eblake@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Stefan Weil" <sw@weilnetz.de>
Subject: Re: [PATCH v1 3/7] util: Introduce ThreadContext user-creatable object
Date: Thu, 29 Sep 2022 13:18:48 +0200 [thread overview]
Message-ID: <27748202-1370-dff7-29da-7bcf4226c227@redhat.com> (raw)
In-Reply-To: <87fsgatowz.fsf@pond.sub.org>
On 29.09.22 13:12, Markus Armbruster wrote:
> David Hildenbrand <david@redhat.com> writes:
>
>> Setting the CPU affinity of QEMU threads is a bit problematic, because
>> QEMU doesn't always have permissions to set the CPU affinity itself,
>> for example, with seccomp after initialized by QEMU:
>> -sandbox enable=on,resourcecontrol=deny
>>
>> While upper layers are already aware how to handl;e CPU affinities for
>
> Typo in handle.
Thanks!
>
>> long-lived threads like iothreads or vcpu threads, especially short-lived
>> threads, as used for memory-backend preallocation, are more involved to
>> handle. These threads are created on demand and upper layers are not even
>> able to identify and configure them.
>>
>> Introduce the concept of a ThreadContext, that is essentially a thread
>> used for creating new threads. All threads created via that context
>> thread inherit the configured CPU affinity. Consequently, it's
>> sufficient to create a ThreadContext and configure it once, and have all
>> threads created via that ThreadContext inherit the same CPU affinity.
>>
>> The CPU affinity of a ThreadContext can be configured two ways:
>>
>> (1) Obtaining the thread id via the "thread-id" property and setting the
>> CPU affinity manually.
>>
>> (2) Setting the "cpu-affinity" property and letting QEMU try set the
>> CPU affinity itself. This will fail if QEMU doesn't have permissions
>> to do so anymore after seccomp was initialized.
>
> Could you provide usage examples?
Patch #7 and the cover letter contain examples. I can add another
example here.
>> +##
>> +# @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
Please let me know how I can further clarify this, that would help, thanks!
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2022-09-29 12:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-28 16:45 [PATCH v1 0/7] hostmem: NUMA-aware memory preallocation using ThreadContext David Hildenbrand
2022-09-28 16:45 ` [PATCH v1 1/7] util: Cleanup and rename os_mem_prealloc() David Hildenbrand
2022-09-28 16:45 ` [PATCH v1 2/7] util: Introduce qemu_thread_set_affinity() and qemu_thread_get_affinity() David Hildenbrand
2022-09-28 16:45 ` [PATCH v1 3/7] util: Introduce ThreadContext user-creatable object David Hildenbrand
2022-09-29 11:12 ` Markus Armbruster
2022-09-29 11:18 ` David Hildenbrand [this message]
2022-09-29 12:25 ` Markus Armbruster
2022-09-29 16:05 ` David Hildenbrand
2022-09-28 16:45 ` [PATCH v1 4/7] util: Add write-only "node-affinity" property for ThreadContext David Hildenbrand
2022-09-29 11:13 ` Markus Armbruster
2022-09-30 9:17 ` David Hildenbrand
2022-09-28 16:45 ` [PATCH v1 5/7] util: Make qemu_prealloc_mem() optionally consume a ThreadContext David Hildenbrand
2022-09-28 16:45 ` [PATCH v1 6/7] hostmem: Allow for specifying a ThreadContext for preallocation David Hildenbrand
2022-09-28 16:45 ` [PATCH v1 7/7] vl: Allow ThreadContext objects to be created before the sandbox option David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=27748202-1370-dff7-29da-7bcf4226c227@redhat.com \
--to=david@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=eduardo@habkost.net \
--cc=imammedo@redhat.com \
--cc=mprivozn@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).