From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3FC66C4332F for ; Tue, 11 Oct 2022 06:15:02 +0000 (UTC) Received: from localhost ([::1]:44618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oi8Xb-00048s-J6 for qemu-devel@archiver.kernel.org; Tue, 11 Oct 2022 02:15:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi8Ml-0000sb-Sb for qemu-devel@nongnu.org; Tue, 11 Oct 2022 02:03:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45358) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oi8Mh-0004ue-98 for qemu-devel@nongnu.org; Tue, 11 Oct 2022 02:03:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665468219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=pk31QPmss5w3QGxY1+C2Gq/HIYVauHjhZhK0JRsAJWU=; b=fAybRKSNuPt5onJzeZyVm1PUe4Bgc3a1hBLMaZtdxTuz8uN0qEmuSQqJE8luE+2tuUIoZ5 zvqwyivKCXGGl1mCxRrBky/2i9wQ42iTJx4+UxjiFAUX1gSMQqOPOKZZCW7vWc0YqWApW9 +xo2rNYrYbqbqefIs7i/uZa0Jly8iko= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-412--bFGXOw_P_aCRo-pTegGbA-1; Tue, 11 Oct 2022 02:03:36 -0400 X-MC-Unique: -bFGXOw_P_aCRo-pTegGbA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC7F387B2A0; Tue, 11 Oct 2022 06:03:35 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.110]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB45C1410F36; Tue, 11 Oct 2022 06:03:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A814121E691D; Tue, 11 Oct 2022 08:03:34 +0200 (CEST) From: Markus Armbruster To: David Hildenbrand Cc: qemu-devel@nongnu.org, Michal Privoznik , Igor Mammedov , "Michael S. Tsirkin" , Paolo Bonzini , Daniel P. =?utf-8?Q?Berrang=C3=A9?= , Eduardo Habkost , "Dr . David Alan Gilbert" , Eric Blake , Richard Henderson , Stefan Weil Subject: Re: [PATCH v2 4/7] util: Add write-only "node-affinity" property for ThreadContext References: <20221010091117.88603-1-david@redhat.com> <20221010091117.88603-5-david@redhat.com> Date: Tue, 11 Oct 2022 08:03:34 +0200 In-Reply-To: <20221010091117.88603-5-david@redhat.com> (David Hildenbrand's message of "Mon, 10 Oct 2022 11:11:14 +0200") Message-ID: <8735buj3rd.fsf@pond.sub.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" David Hildenbrand writes: > Let's make it easier to pin threads created via a ThreadContext to > all CPUs currently belonging to a given set of NUMA nodes -- which is the > common case. > > "node-affinity" is simply a shortcut for setting "cpu-affinity" manually > to the list of CPUs belonging to the set of nodes. This property can only > be written. > > A simple QEMU example to set the CPU affinity to Node 1 on a system with > two NUMA nodes, 24 CPUs each: > qemu-system-x86_64 -S \ > -object thread-context,id=tc1,node-affinity=1 > > And we can query the cpu-affinity via HMP/QMP: > (qemu) qom-get tc1 cpu-affinity > [ > 1, > 3, > 5, > 7, > 9, > 11, > 13, > 15, > 17, > 19, > 21, > 23, > 25, > 27, > 29, > 31, > 33, > 35, > 37, > 39, > 41, > 43, > 45, > 47 > ] Double-checking my understanding: on this system, the even CPUs belong to NUMA node 0, and the odd ones to node 1. Setting node-affinity=1 is therefore sugar for setting cpu-affinity to the set of even CPUs. Correct? > We cannot query the node-affinity: > (qemu) qom-get tc1 node-affinity > Error: Insufficient permission to perform this operation The error message is somewhat misleading. "Insufficient permission" suggests this could work if I had more "permission". Not the case. The message comes from object_property_get(), i.e. it's not this patch's fault. I'll post a patch to improve it. > 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. > > Note that if the CPUs for a node change due do physical CPU hotplug or > hotunplug (e.g., lscpu output changes) after the ThreadContext was started, > the CPU affinity will not get updated. > > Reviewed-by: Michal Privoznik > Signed-off-by: David Hildenbrand > --- > qapi/qom.json | 9 ++++- > util/meson.build | 2 +- > util/thread-context.c | 84 +++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 93 insertions(+), 2 deletions(-) > > diff --git a/qapi/qom.json b/qapi/qom.json > index 67d47f4051..cb6f700c0c 100644 > --- a/qapi/qom.json > +++ b/qapi/qom.json > @@ -839,10 +839,17 @@ > # created in the thread context (default: QEMU main thread > # affinity) > # > +# @node-affinity: the list of node numbers that will be resolved to a list > +# of CPU numbers used as CPU affinity. This is a shortcut for > +# specifying the list of CPU numbers belonging to the nodes > +# manually by setting @cpu-affinity. (default: QEMU main thread > +# affinity) > +# > # Since: 7.2 > ## > { 'struct': 'ThreadContextProperties', > - 'data': { '*cpu-affinity': ['uint16'] } } > + 'data': { '*cpu-affinity': ['uint16'], > + '*node-affinity': ['uint16'] } } > > > ## [...]