Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1448766rdd; Wed, 10 Jan 2024 22:13:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEuRrNpup/z4/CsEHEXth9+AvDgAbNmPSO2/tWeEJoBATaLPsRx1aN+X2TAb1KOZEETRnH X-Received: by 2002:a05:620a:3711:b0:783:4eb:1bd0 with SMTP id de17-20020a05620a371100b0078304eb1bd0mr1171371qkb.0.1704953619348; Wed, 10 Jan 2024 22:13:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704953619; cv=none; d=google.com; s=arc-20160816; b=wF/a2diR7c/pkEetIh9F74bck8+QXHwtz00kCCcwVriRQckNXa9TIDjJrZB28mP7qz arb5dWitXJPLVxEnLNUhgyC4ZS+5aEkoMrogkK6x/GPMu50whYZ6qfUcaeweNXU7iIBH AMOvYsCTz6JNvzZeeg/yiJ0YkYy4sXCDDFtT09XSsbw3YFdE5nxyqPjo3hL80f4FfEDK 3okCD8t6zQCG7ydAKR5AECswbyleiM6p36RL4htJhcQcJsFXVZpyQ2oIk1S/kIV9Wdmg c9TC7XEaJAC0jGyRSezRRLkqfArLzax5xbsK3XwkfArekw9jk4pkjUVuhBpmPl494at6 vxsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature:dkim-filter; bh=Vx6uwJdgmYeQ9YCQC3Gj9uTpE/Inxmh3nP0kQERH+Cs=; fh=2QV9/3rZQH/DK2Rdb94AW+KjZuJcYUL4jgikCaWAlbY=; b=noDo8kL7nN2Ts4RO1YkY2H80K6yrYVfaJmDW4bGqKkNPhnW3CkTGOWqimANTgI7Sch SPlpbutH7FCEBn+4D8geM9PUAXrHHY8sdnZs6pXtaoA1lxFcvgNQSD3mLI0mVoxC+T6i hm93mDdHhhjzaeUVzK1pskmlz42ehOHHApcNYnkzAX/Xwpo83OE7e9yjEjMfdelTFS4r elRZuA3t0rtPv1f5+dHu67BMiXhIC7RVxPRXjb1Mma6tFKHVG/yd4HkcIzFG6DDuEo+H RQP3u9CJri6RNvpMDzNx0RYGkzsAIRlluvVE6l2Rd+HsBQLMuTSkOR0lZr5VGIIYo0Za f8Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=F4ppTMFL; spf=pass (google.com: domain of linux-kernel+bounces-23083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pa42-20020a05620a832a00b007811f296177si321981qkn.192.2024.01.10.22.13.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 22:13:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=F4ppTMFL; spf=pass (google.com: domain of linux-kernel+bounces-23083-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0743B1C22EF8 for ; Thu, 11 Jan 2024 06:13:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18DFC2916; Thu, 11 Jan 2024 06:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="F4ppTMFL" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9456C5382; Thu, 11 Jan 2024 06:13:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1099) id 7A36A209C43A; Wed, 10 Jan 2024 22:13:19 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7A36A209C43A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1704953599; bh=Vx6uwJdgmYeQ9YCQC3Gj9uTpE/Inxmh3nP0kQERH+Cs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=F4ppTMFLicty7Ad4PVvjI+E3NO/r6Mx6EgTdjLUiDZxrRcX4ztiUXZlY76P9z3EEg 1gnXNyMrQ3FnE4aSOYMK8WKwXEy3RN6o4TpI6SANKlk4H8UwCSKirPUch22vAsvXjr 6c4N1IcWWNeQLsTlBakVSokhRjGDSJ0Svpo1x6FQ= Date: Wed, 10 Jan 2024 22:13:19 -0800 From: Souradeep Chakrabarti To: Michael Kelley Cc: Yury Norov , "kys@microsoft.com" , "haiyangz@microsoft.com" , "wei.liu@kernel.org" , "decui@microsoft.com" , "davem@davemloft.net" , "edumazet@google.com" , "kuba@kernel.org" , "pabeni@redhat.com" , "longli@microsoft.com" , "leon@kernel.org" , "cai.huoqing@linux.dev" , "ssengar@linux.microsoft.com" , "vkuznets@redhat.com" , "tglx@linutronix.de" , "linux-hyperv@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-rdma@vger.kernel.org" , "schakrabarti@microsoft.com" , "paulros@microsoft.com" Subject: Re: [PATCH 3/4 net-next] net: mana: add a function to spread IRQs per CPUs Message-ID: <20240111061319.GC5436@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1704797478-32377-1-git-send-email-schakrabarti@linux.microsoft.com> <1704797478-32377-4-git-send-email-schakrabarti@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) On Wed, Jan 10, 2024 at 12:27:54AM +0000, Michael Kelley wrote: > From: Yury Norov Sent: Tuesday, January 9, 2024 3:29 PM > > > > Hi Michael, > > > > So, I'm just a guy who helped to formulate the heuristics in an > > itemized form, and implement them using the existing kernel API. > > I have no access to MANA machines and I ran no performance tests > > myself. > > Agreed. :-) Given the heritage of the patch, I should have clarified > that my question was directed to Souradeep. Regardless, your work > on the cpumask manipulation made everything better and clearer. > > > > > On Tue, Jan 09, 2024 at 07:22:38PM +0000, Michael Kelley wrote: > > > From: Souradeep Chakrabarti Sent: > > Tuesday, January 9, 2024 2:51 AM > > > > > > > > From: Yury Norov > > > > > > > > Souradeep investigated that the driver performs faster if IRQs are > > > > spread on CPUs with the following heuristics: > > > > > > > > 1. No more than one IRQ per CPU, if possible; > > > > 2. NUMA locality is the second priority; > > > > 3. Sibling dislocality is the last priority. > > > > > > > > Let's consider this topology: > > > > > > > > Node 0 1 > > > > Core 0 1 2 3 > > > > CPU 0 1 2 3 4 5 6 7 > > > > > > > > The most performant IRQ distribution based on the above topology > > > > and heuristics may look like this: > > > > > > > > IRQ Nodes Cores CPUs > > > > 0 1 0 0-1 > > > > 1 1 1 2-3 > > > > 2 1 0 0-1 > > > > 3 1 1 2-3 > > > > 4 2 2 4-5 > > > > 5 2 3 6-7 > > > > 6 2 2 4-5 > > > > 7 2 3 6-7 > > > > > > I didn't pay attention to the detailed discussion of this issue > > > over the past 2 to 3 weeks during the holidays in the U.S., but > > > the above doesn't align with the original problem as I understood > > > it. I thought the original problem was to avoid putting IRQs on > > > both hyper-threads in the same core, and that the perf > > > improvements are based on that configuration. At least that's > > > what the commit message for Patch 4/4 in this series says. > > > > Yes, and the original distribution suggested by Souradeep looks very > > similar: > > > > IRQ Nodes Cores CPUs > > 0 1 0 0 > > 1 1 1 2 > > 2 1 0 1 > > 3 1 1 3 > > 4 2 2 4 > > 5 2 3 6 > > 6 2 2 5 > > 7 2 3 7 > > > > I just added a bit more flexibility, so that kernel may pick any > > sibling for the IRQ. As I understand, both approaches have similar > > performance. Probably my fine-tune added another half-percent... > > > > Souradeep, can you please share the exact numbers on this? > > > > > The above chart results in 8 IRQs being assigned to the 8 CPUs, > > > probably with 1 IRQ per CPU. At least on x86, if the affinity > > > mask for an IRQ contains multiple CPUs, matrix_find_best_cpu() > > > should balance the IRQ assignments between the CPUs in the mask. > > > So the original problem is still present because both hyper-threads > > > in a core are likely to have an IRQ assigned. > > > > That's what I think, if the topology makes us to put IRQs in the > > same sibling group, the best thing we can to is to rely on existing > > balancing mechanisms in a hope that they will do their job well. > > > > > Of course, this example has 8 IRQs and 8 CPUs, so assigning an > > > IRQ to every hyper-thread may be the only choice. If that's the > > > case, maybe this just isn't a good example to illustrate the > > > original problem and solution. > > > > Yeah... This example illustrates the order of IRQ distribution. > > I really doubt that if we distribute IRQs like in the above example, > > there would be any difference in performance. But I think it's quite > > a good illustration. I could write the title for the table like this: > > > > The order of IRQ distribution for the best performance > > based on [...] may look like this. > > > > > But even with a better example > > > where the # of IRQs is <= half the # of CPUs in a NUMA node, > > > I don't think the code below accomplishes the original intent. > > > > > > Maybe I've missed something along the way in getting to this > > > version of the patch. Please feel free to set me straight. :-) > > > > Hmm. So if the number of IRQs is the half # of CPUs in the nodes, > > which is 2 in the example above, the distribution will look like > > this: > > > > IRQ Nodes Cores CPUs > > 0 1 0 0-1 > > 1 1 1 2-3 > > > > And each IRQ belongs to a different sibling group. This follows > > the rules above. > > > > I think of it like we assign an IRQ to a group of 2 CPUs, so from > > the heuristic #1 perspective, each CPU is assigned with 1/2 of the > > IRQ. > > > > If I add one more IRQ, then according to the heuristics, NUMA locality > > trumps sibling dislocality, so we'd assign IRO to the same node on any > > core. My algorithm assigns it to the core #0: > > > > 2 1 0 0-1 > > > > This doubles # of IRQs for the CPUs 0 and 1: from 1/2 to 1. > > > > The next IRQ should be assigned to the same node again, and we've got > > the only choice: > > > > > > 3 1 1 2-3 > > > > Starting from IRQ #5, the node #1 is full - each CPU is assigned with > > exactly one IRQ, and the heuristic #1 makes us to switch to the other > > node; and then do the same thing: > > > > 4 2 2 4-5 > > 5 2 3 6-7 > > 6 2 2 4-5 > > 7 2 3 6-7 > > > > So I think the algorithm is correct... Really hope the above makes > > sense. :) If so, I can add it to the commit message for patch #3. > > Thinking about it further, I agree with you. If we want NUMA > locality to trump avoiding hyper-threads in the same core, then > I'm good with the algorithm. If I think of the "weight" variable > in your function as the "number of IRQs to assign to CPUs in > this NUMA hop", then it makes sense to decrement it by 1 > each time irq_set_affinity_and_hint() is called. I was confused > by likely removing multiple cpus from the "cpus" cpumask > juxtaposed with decrementing "weight" by only 1, and by my > preconception that to get the perf benefit we wanted to avoid > hyper-threads in the same core. > > > > > Nevertheless... Souradeep, in addition to the performance numbers, can > > you share your topology and actual IRQ distribution that gains 15%? I > > think it should be added to the patch #4 commit message. > > Yes -- this is the key thing for me. What is the configuration that > shows the 15% performance gain? Patch 3/4 and Patch 4/4 in the > series need to be consistent in describing when there's a performance > benefit and when there's no significant difference. In Patch 4/4, > the mana driver creates IRQs equal to the # of CPUs, up to > MANA_MAX_NUM_QUEUES, which is 64. So the new algorithm > still assigns IRQs to both hyper-threads in cores in the local NUMA > node (unless the node is bigger than 64 CPUs, which I don't think > happens in Azure today). For the first hop from the local NUMA > node, IRQs might get assigned to only one hyper-thread in a core > if the total CPU count in the VM is more than 64. The test topology was used to check the performance between cpu_local_spread() and the new approach is : Case 1 IRQ Nodes Cores CPUs 0 1 0 0-1 1 1 1 2-3 2 1 2 4-5 3 1 3 6-7 and with existing cpu_local_spread() Case 2 IRQ Nodes Cores CPUs 0 1 0 0 1 1 0 1 2 1 1 2 3 1 1 3 Total 4 channels were used, which was set up by ethtool. case 1 with ntttcp has given 15 percent better performance, than case 2. During the test irqbalance was disabled as well. Also you are right, with 64CPU system this approach will spread the irqs like the cpu_local_spread() but in the future we will offer MANA nodes, with more than 64 CPUs. There it this new design will give better performance. I will add this performance benefit details in commit message of next version. > > Michael