From patchwork Mon Jan 22 16:00:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souradeep Chakrabarti X-Patchwork-Id: 190260 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2731295dyb; Mon, 22 Jan 2024 09:45:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRwhjHTjejM9kv8Y8U5tST1X9J9CLVPtR9SL8tLJT6zaXMLZ8SoEQ3TlFr/4JQViAF7D7b X-Received: by 2002:a17:90a:4297:b0:290:6b66:620b with SMTP id p23-20020a17090a429700b002906b66620bmr1101784pjg.12.1705945509169; Mon, 22 Jan 2024 09:45:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705945509; cv=pass; d=google.com; s=arc-20160816; b=Z3na2/+UpMRlF1ilC+Xw9PwK7eFFSoN5cABZyhiGe0QE/OZmSFZLa5gzBa6gyDxmM3 ji4uPSuInPVt13bu7uoq9teymUmd3b3uKosYFMFs6eYx+Tf4RK62uhZeq1XhlJ8J9jK2 AoH2bMsrcrEp5ocC6Ei1yzWdmDAJISVZG9efHUIPUwwGN5D0+9hvxrNj0YJrp/Xj2tfG 7bx1F1jrrBA7QURYoiQq3rHDEtppccMv6yTzLFvSwSojAUly6KMHIhO770m8Zlsv3/Rs u+tDCUl5inQ6GIMhk25gImyvSwbH96lhvN5xMzVNbPrzUxSnLOb0XNQwlU5V2HDHvfxu IL8A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=Qh4vCcMbs6V3VMTJ7hXH2GEKRppPqxUeLFTB/Ig1nok=; fh=tZ+d+kaZjTJMarg6XpXtL9/z8hMSaArJbuj7ZVP9x6U=; b=ZhJrHAt5RGOCtDSnlmy3B/O0nk5ph8ekHTer6KYiPS0qvs+k5nUBOsHlWF9Jai5hd4 ngEdFKM2BM36ptoUlAPpqpADHwD5NHk8rFUdykHyebJE+uy/fiudNa7Go2LUl1muxKPv Atj/ucz4gxkVRHeQYn2bxbUAtP74xaa0oT/hkC454K0YVuXaYFXZcqfwtGVyb9/+Ou1X 0k3Q3smivHoTSDSnhQ1wjG2NjGn5tgypslfrAcujgfM+PeuODo5Jai4SRBHMzT1a2hIL FQKLZKavRMtNcPIvwOMsNR3z1q74VBoTtEuSIIoRM845WTe5AUTp56dmXNqyZu/trEJ4 zMXw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=N23px74w; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-33642-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33642-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x22-20020a170902b41600b001d5c0d1b012si8144441plr.634.2024.01.22.09.45.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 09:45:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33642-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=N23px74w; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-33642-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33642-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5D7AAB21C75 for ; Mon, 22 Jan 2024 17:12:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B163662801; Mon, 22 Jan 2024 16:01:09 +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="N23px74w" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 382953D98E; Mon, 22 Jan 2024 16:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705939266; cv=none; b=W0JvS0awyPjEkb0c2aC06MrXd9vcyAcRYYyqMiWheXH/3k6hV1aWRenihFQ22RBkyFiZZpCbytVngAwBixCP/48jdwhQ/cX6Cq99gS4RmolyYeF5RLEwU/VAaQidRUMuXhUy0ogH9cVkdw/vs4fSEDeBNTNGLFrooWSZDKkxphc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705939266; c=relaxed/simple; bh=JWip2UTTjunONm5W+kW2X28AocSMuT6jlRKMeBFBPOA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=M/Ch+cC4EAocHcFPwuuj6/EgZVw1yPCoZBmShIwB0hWl+9xfHQDVsrRi32jInD0n2ap020w5WCqxBjpwAfl0k+BxlaPFa/gza5IvtETayfbbNZ/pmLAsCwZG0YiXG8dUluRwIvz6z/lz3B2ogg2cDu4AUPNm67M1MfTaEgwD3y0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=N23px74w; arc=none smtp.client-ip=13.77.154.182 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 E25BD20E2C02; Mon, 22 Jan 2024 08:01:04 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E25BD20E2C02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1705939264; bh=Qh4vCcMbs6V3VMTJ7hXH2GEKRppPqxUeLFTB/Ig1nok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N23px74wTcNO34y5h/tnwy1lEk8dvEtQYrqnTVCDGVbnRH06yc+Ki/5bNRlVWJ2Vr 7rMl1+Yi2szlI1yf3g72dhTCeuU+J6dqb/WXI+PcKIduRljq3HKd4dy3KbBFHjYspD b6HRhp94ef3ZANNZJaHp1vXgVQ7gHaudnOAjaM7o= From: Souradeep Chakrabarti To: 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, yury.norov@gmail.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 Cc: schakrabarti@microsoft.com, paulros@microsoft.com Subject: [PATCH 1/4 V2 net-next] cpumask: add cpumask_weight_andnot() Date: Mon, 22 Jan 2024 08:00:56 -0800 Message-Id: <1705939259-2859-2-git-send-email-schakrabarti@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1705939259-2859-1-git-send-email-schakrabarti@linux.microsoft.com> References: <1705939259-2859-1-git-send-email-schakrabarti@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788813518258787343 X-GMAIL-MSGID: 1788813518258787343 From: Yury Norov Similarly to cpumask_weight_and(), cpumask_weight_andnot() is a handy helper that may help to avoid creating an intermediate mask just to calculate number of bits that set in a 1st given mask, and clear in 2nd one. Signed-off-by: Yury Norov Reviewed-by: Jacob Keller --- include/linux/bitmap.h | 12 ++++++++++++ include/linux/cpumask.h | 13 +++++++++++++ lib/bitmap.c | 7 +++++++ 3 files changed, 32 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 99451431e4d6..5814e9ee40ba 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -54,6 +54,7 @@ struct device; * bitmap_full(src, nbits) Are all bits set in *src? * bitmap_weight(src, nbits) Hamming Weight: number set bits * bitmap_weight_and(src1, src2, nbits) Hamming Weight of and'ed bitmap + * bitmap_weight_andnot(src1, src2, nbits) Hamming Weight of andnot'ed bitmap * bitmap_set(dst, pos, nbits) Set specified bit area * bitmap_clear(dst, pos, nbits) Clear specified bit area * bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area @@ -169,6 +170,8 @@ bool __bitmap_subset(const unsigned long *bitmap1, unsigned int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits); unsigned int __bitmap_weight_and(const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int nbits); +unsigned int __bitmap_weight_andnot(const unsigned long *bitmap1, + const unsigned long *bitmap2, unsigned int nbits); void __bitmap_set(unsigned long *map, unsigned int start, int len); void __bitmap_clear(unsigned long *map, unsigned int start, int len); @@ -425,6 +428,15 @@ unsigned long bitmap_weight_and(const unsigned long *src1, return __bitmap_weight_and(src1, src2, nbits); } +static __always_inline +unsigned long bitmap_weight_andnot(const unsigned long *src1, + const unsigned long *src2, unsigned int nbits) +{ + if (small_const_nbits(nbits)) + return hweight_long(*src1 & ~(*src2) & BITMAP_LAST_WORD_MASK(nbits)); + return __bitmap_weight_andnot(src1, src2, nbits); +} + static __always_inline void bitmap_set(unsigned long *map, unsigned int start, unsigned int nbits) { diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index cfb545841a2c..228c23eb36d2 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -719,6 +719,19 @@ static inline unsigned int cpumask_weight_and(const struct cpumask *srcp1, return bitmap_weight_and(cpumask_bits(srcp1), cpumask_bits(srcp2), small_cpumask_bits); } +/** + * cpumask_weight_andnot - Count of bits in (*srcp1 & ~*srcp2) + * @srcp1: the cpumask to count bits (< nr_cpu_ids) in. + * @srcp2: the cpumask to count bits (< nr_cpu_ids) in. + * + * Return: count of bits set in both *srcp1 and *srcp2 + */ +static inline unsigned int cpumask_weight_andnot(const struct cpumask *srcp1, + const struct cpumask *srcp2) +{ + return bitmap_weight_andnot(cpumask_bits(srcp1), cpumask_bits(srcp2), small_cpumask_bits); +} + /** * cpumask_shift_right - *dstp = *srcp >> n * @dstp: the cpumask result diff --git a/lib/bitmap.c b/lib/bitmap.c index 09522af227f1..b97692854966 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -348,6 +348,13 @@ unsigned int __bitmap_weight_and(const unsigned long *bitmap1, } EXPORT_SYMBOL(__bitmap_weight_and); +unsigned int __bitmap_weight_andnot(const unsigned long *bitmap1, + const unsigned long *bitmap2, unsigned int bits) +{ + return BITMAP_WEIGHT(bitmap1[idx] & ~bitmap2[idx], bits); +} +EXPORT_SYMBOL(__bitmap_weight_andnot); + void __bitmap_set(unsigned long *map, unsigned int start, int len) { unsigned long *p = map + BIT_WORD(start); From patchwork Mon Jan 22 16:00:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souradeep Chakrabarti X-Patchwork-Id: 190230 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2712921dyb; Mon, 22 Jan 2024 09:12:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8qM4eqeR0ox3tBwhNQtIazEuSBA8APWvELsEiiE3+4w97C/Q2gvpxo+NuOySTIC1psnkI X-Received: by 2002:ac2:5589:0:b0:50e:7ab4:2ac with SMTP id v9-20020ac25589000000b0050e7ab402acmr1847927lfg.130.1705943576564; Mon, 22 Jan 2024 09:12:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705943576; cv=pass; d=google.com; s=arc-20160816; b=ZPxxea0c9xIgLEt7/l75bRZA47vIGZKrYbUhTY5sRf8Pdkc9oT14/dcsUA33K1N+ek J7V4ez90pYswJUXzQH+b2oQA6puvdU89gpe98zF1i+DKoGmCkBdZwcMRBPrU4mKM+fDS mYjqJ8Zml/chDHzV2QQaxqAfffnF5fk9LsTSQCrtAKdlQARP4pie12A3Arf96TO1N3XI 8zZkzL44a9T+Hy2ab+2cCVUgpTjouqOCqtrX9I1Nldp7M+yMWojrbgzETeKeSIWKF89I HDdZ4TuXbEnXHG7QFEZuTmPJY6uxb9rQlbyR6SSah/RhTk28ElTWv5i38A+9VBTWdqSx xO9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=ZPRu3SXlIUr+8W26d0LPvybxMOuIzrvNRUu535P0XZM=; fh=tZ+d+kaZjTJMarg6XpXtL9/z8hMSaArJbuj7ZVP9x6U=; b=EiNEF+F5Gd9Q0hcJqoL6yisUWwkC2iNzHLkpq1nJDDUeEiS7yZ4mSxQQgbkznB4otz yKArROoCN6dFMMZc5PUNQDcgOVDT5WZD3Q567Iyh0JObpUoa4bFhy6/m/3OGOUrmkBkf Gc7mBBkgSO9Z+Lkt1MymgxZ4BBpMW/MsTQOFUDYToUC7dpW4/MyHFZSwkazgdul2Yod8 U8ZS51Y7WsqAXMXlfhWHtx9KgLGqytHecELWV23M34JcA6pdhTBk2xTAm/5A7OEcXQBS QArUWU8AV45UMTo8sQpa9dfcPbyHK8glYgK2WaLC87igFzzhoH1tOqls+C5OmoLeTT8Z T1cA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=AKDgAkWL; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-33643-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33643-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id n7-20020a170906378700b00a2ac142722fsi10901100ejc.167.2024.01.22.09.12.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 09:12:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33643-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=AKDgAkWL; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-33643-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33643-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2D7961F268C3 for ; Mon, 22 Jan 2024 17:12:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF80762807; Mon, 22 Jan 2024 16:01:09 +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="AKDgAkWL" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EFA5C4CDE6; Mon, 22 Jan 2024 16:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705939267; cv=none; b=Bof/Fqf+LpVYyUVzZMf97H4TINowQb937cM845vpybQfe1NkqJa3I1M/P52Y5NBkeoNfrTFKkzFwvI/td2g/w1wecUr8o1NyhH4t/4Rv/oB2nCuKfPkvsIse6i2Os5YHbxrPgUbkvfVhGDiv4O6iMFZP8v7KtDy++l6vPrnGZbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705939267; c=relaxed/simple; bh=2TbGyVSXByR1bZJMjbZ9qzvNekm4PoMQJkQoldzGsDY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=pSbwWUXbegyHh+hQK8hd4a0vbH8d/aGDOIPNCVMCJst6m39eixqMq1ieUaceiRWhsQ2LgzEmld/nlcQhhdRrPcqPhJGxDXEqRuPa9gFl6j/irw/VGh+v70SKOiQtu8HYoj1jV+NoU+QVW6FqQ3oNmNwFMp+R8lHlnXZuBNhRoSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=AKDgAkWL; arc=none smtp.client-ip=13.77.154.182 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 9530920E2C0A; Mon, 22 Jan 2024 08:01:05 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9530920E2C0A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1705939265; bh=ZPRu3SXlIUr+8W26d0LPvybxMOuIzrvNRUu535P0XZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AKDgAkWLzV0U2zIt5nj8Hi0D4OHGYOOGV3Jne5X/sd99ywR4usOMFH6coqLERn/l3 ndFr+yoL29aSILQLoy0OU/u+dBKEUp8egDYY0jczB8HT/jXsuEDIF1sZ69eQQ6RYMN u4zD16Bf97ZboTWtoF3yKmvNaqYe321T80IICyjA= From: Souradeep Chakrabarti To: 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, yury.norov@gmail.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 Cc: schakrabarti@microsoft.com, paulros@microsoft.com Subject: [PATCH 2/4 V2 net-next] cpumask: define cleanup function for cpumasks Date: Mon, 22 Jan 2024 08:00:57 -0800 Message-Id: <1705939259-2859-3-git-send-email-schakrabarti@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1705939259-2859-1-git-send-email-schakrabarti@linux.microsoft.com> References: <1705939259-2859-1-git-send-email-schakrabarti@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788811491277710420 X-GMAIL-MSGID: 1788811491277710420 From: Yury Norov Now we can simplify code that allocates cpumasks for local needs. Signed-off-by: Yury Norov --- include/linux/cpumask.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 228c23eb36d2..1c29947db848 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -7,6 +7,7 @@ * set of CPUs in a system, one bit position per CPU number. In general, * only nr_cpu_ids (<= NR_CPUS) bits are valid. */ +#include #include #include #include @@ -990,6 +991,8 @@ static inline bool cpumask_available(cpumask_var_t mask) } #endif /* CONFIG_CPUMASK_OFFSTACK */ +DEFINE_FREE(free_cpumask_var, struct cpumask *, if (_T) free_cpumask_var(_T)); + /* It's common to want to use cpu_all_mask in struct member initializers, * so it has to refer to an address rather than a pointer. */ extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS); From patchwork Mon Jan 22 16:00:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souradeep Chakrabarti X-Patchwork-Id: 190231 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2713169dyb; Mon, 22 Jan 2024 09:13:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFflcqL8Z3c5RCXC+shITNz+10Ewm/raPjtymaI32q02pJVIOSI8xMbuAnvlcXT5uypwP9z X-Received: by 2002:a17:907:9210:b0:a28:c7fe:5458 with SMTP id ka16-20020a170907921000b00a28c7fe5458mr2013261ejb.94.1705943596234; Mon, 22 Jan 2024 09:13:16 -0800 (PST) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h26-20020a170906591a00b00a30915e18a2si321087ejq.1035.2024.01.22.09.13.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 09:13:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33644-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linux.microsoft.com header.s=default header.b=SubS0tyP; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-33644-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33644-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (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 am.mirrors.kernel.org (Postfix) with ESMTPS id D7B5A1F25A69 for ; Mon, 22 Jan 2024 17:13:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18486629E6; Mon, 22 Jan 2024 16:01:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="SubS0tyP" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C20114CDFF; Mon, 22 Jan 2024 16:01:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705939268; cv=none; b=mmKNjd5DQ520O/F1AaNT8wDhcKvwZYGvKWF7L4Vd2XBQEb78LVF4aw+z3OM2Myzjmbc3H7WrBFo3ls/3H8Kh/aDoW9J/z58AtAGm8eQ7LjalrespIY/nk6yWcP5ucEnAaHv3TBGiQehdPGsUlYHQI05AeyfPCfQnge55sY5Z/4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705939268; c=relaxed/simple; bh=N8bi7iOk7SkztwFK/cTk8Cvbzl4tKg+IpZOOTeXUr6o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=ryYj9hDnYEGnj6gMPOIHMh3hp4yE4ei5b/6a6TP7UTX77VlDD3hTIq2kWXY33Ww3fkfzoqnLYryEUDTFwSGKcxdcO3Rq2FVJXdxMHm7EU4e9Q+t0o2HiWC9MS9x+iq9QNu8rgE4BzobL4jHF1sBVfh3hdVw4VUQl3xhF8USbuZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=SubS0tyP; arc=none smtp.client-ip=13.77.154.182 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 6E9C320E2C18; Mon, 22 Jan 2024 08:01:06 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6E9C320E2C18 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1705939266; bh=cbmGLa7jFFF/JRYGhEzNHaYORqYhPABgjUC6W0VOrNU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SubS0tyP8urJZaV8+SNr5Mkqmw9yXRsJhNyyr4V5+6DV7itg2ID45oGaGKIrssbbh ghRzfxu3Ebzvpvtj3LbIdMVYlX8scdA4VTb+4imrCnnzru9vRrAcidMD0yf6eCzC6h C0UJK4W/oXcKKXZ0+52O9z3n7r36Ol8G/Iudqd4s= From: Souradeep Chakrabarti To: 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, yury.norov@gmail.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 Cc: schakrabarti@microsoft.com, paulros@microsoft.com Subject: [PATCH 3/4 V2 net-next] net: mana: add a function to spread IRQs per CPUs Date: Mon, 22 Jan 2024 08:00:58 -0800 Message-Id: <1705939259-2859-4-git-send-email-schakrabarti@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1705939259-2859-1-git-send-email-schakrabarti@linux.microsoft.com> References: <1705939259-2859-1-git-send-email-schakrabarti@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788811512437037002 X-GMAIL-MSGID: 1788811512437037002 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 The irq_setup() routine introduced in this patch leverages the for_each_numa_hop_mask() iterator and assigns IRQs to sibling groups as described above. According to [1], for NUMA-aware but sibling-ignorant IRQ distribution based on cpumask_local_spread() performance test results look like this: /ntttcp -r -m 16 NTTTCP for Linux 1.4.0 --------------------------------------------------------- 08:05:20 INFO: 17 threads created 08:05:28 INFO: Network activity progressing... 08:06:28 INFO: Test run completed. 08:06:28 INFO: Test cycle finished. 08:06:28 INFO: ##### Totals: ##### 08:06:28 INFO: test duration :60.00 seconds 08:06:28 INFO: total bytes :630292053310 08:06:28 INFO: throughput :84.04Gbps 08:06:28 INFO: retrans segs :4 08:06:28 INFO: cpu cores :192 08:06:28 INFO: cpu speed :3799.725MHz 08:06:28 INFO: user :0.05% 08:06:28 INFO: system :1.60% 08:06:28 INFO: idle :96.41% 08:06:28 INFO: iowait :0.00% 08:06:28 INFO: softirq :1.94% 08:06:28 INFO: cycles/byte :2.50 08:06:28 INFO: cpu busy (all) :534.41% For NUMA- and sibling-aware IRQ distribution, the same test works 15% faster: /ntttcp -r -m 16 NTTTCP for Linux 1.4.0 --------------------------------------------------------- 08:08:51 INFO: 17 threads created 08:08:56 INFO: Network activity progressing... 08:09:56 INFO: Test run completed. 08:09:56 INFO: Test cycle finished. 08:09:56 INFO: ##### Totals: ##### 08:09:56 INFO: test duration :60.00 seconds 08:09:56 INFO: total bytes :741966608384 08:09:56 INFO: throughput :98.93Gbps 08:09:56 INFO: retrans segs :6 08:09:56 INFO: cpu cores :192 08:09:56 INFO: cpu speed :3799.791MHz 08:09:56 INFO: user :0.06% 08:09:56 INFO: system :1.81% 08:09:56 INFO: idle :96.18% 08:09:56 INFO: iowait :0.00% 08:09:56 INFO: softirq :1.95% 08:09:56 INFO: cycles/byte :2.25 08:09:56 INFO: cpu busy (all) :569.22% [1] https://lore.kernel.org/all/20231211063726.GA4977@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net/ Signed-off-by: Yury Norov Co-developed-by: Souradeep Chakrabarti --- .../net/ethernet/microsoft/mana/gdma_main.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c index d33b27214539..05a0ac054823 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -1249,6 +1249,35 @@ void mana_gd_free_res_map(struct gdma_resource *r) r->size = 0; } +static __maybe_unused int irq_setup(unsigned int *irqs, unsigned int len, int node) +{ + const struct cpumask *next, *prev = cpu_none_mask; + cpumask_var_t cpus __free(free_cpumask_var); + int cpu, weight; + + if (!alloc_cpumask_var(&cpus, GFP_KERNEL)) + return -ENOMEM; + + rcu_read_lock(); + for_each_numa_hop_mask(next, node) { + weight = cpumask_weight_andnot(next, prev); + while (weight > 0) { + cpumask_andnot(cpus, next, prev); + for_each_cpu(cpu, cpus) { + if (len-- == 0) + goto done; + irq_set_affinity_and_hint(*irqs++, topology_sibling_cpumask(cpu)); + cpumask_andnot(cpus, cpus, topology_sibling_cpumask(cpu)); + --weight; + } + } + prev = next; + } +done: + rcu_read_unlock(); + return 0; +} + static int mana_gd_setup_irqs(struct pci_dev *pdev) { unsigned int max_queues_per_port = num_online_cpus(); From patchwork Mon Jan 22 16:00:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souradeep Chakrabarti X-Patchwork-Id: 190232 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2714957dyb; Mon, 22 Jan 2024 09:16:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqaqhdJ0MWs+LZdOzW+jrPJsJzHXgt546PTEw5iT8rxjvGBYRRn4fE386C0Au4lcfccytb X-Received: by 2002:a17:903:1248:b0:1d5:ecfe:4d69 with SMTP id u8-20020a170903124800b001d5ecfe4d69mr6102330plh.49.1705943771888; Mon, 22 Jan 2024 09:16:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705943771; cv=pass; d=google.com; s=arc-20160816; b=emr0F4Usoc4ajZB5dZkwYO7T1ySfHmdcaz49yvcWQFkRdKAHgJp5UXsbwwDyMKf8BI wEtTVU2MgA/mxhxDcfYLJNwmDLq3xmDb7pLedsO7xy2yUGSwWoqhlz/H/y+nsC8ChENr //TbbTrbJ47/SQIDhc4mmIWLN4ud54Zj+HDYdEhA6Y1hoYvqbIYjR4ehwiIgm6xx2J49 zTuJpnVKXPQ1OtYrkQ2clKLfXSTHJHHS92FsGUBQpKHx0RnqCgviB/5uL4zu1kIl4vQd LbSTt9BAwcp/JTxQMZPQPTgQHNJ9x8MS4hfhtZfeZqCEVvB/I/9iBr2DH7eRHH43cgbg qhcw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=xk+J9offpgOWbG5/MefCVQrVZHtpJxME2AVu0bJoiYU=; fh=i0uHiUPKHfc1dSxTUTgp1cL8PKSGIUKO6qVCzrDTDzE=; b=r3Py6M/peobQ3y0pqU5JeXUhJO7fWuAa/GjAo30fSnYu4kajFazccG0f2W97t6eu1t KnQwiFCWIomaLTNB114NGLU/uf83Uae7wtdPyGjaloijn/j5pfQv05DhF1CrwQHXNGfN 1tB/6cUjbbeys/PmWeb0PRSbwGo+6fCa9EDddF0Qq/2+ZM+RMtUPJnhatOIM5/osfzEE Ma00Iv0VWam7Lvr+zh331IbjFG0ZuOqm/sibFZ/c8Q3d9M9FYFwtRV6csiUPkJphMJh+ FiXaFP3LUxcrDCwGzHO8TJMqxNxd/IP3AsRPKnoelMXEqnhCWr/e0vpbkjqoGOfLUWCc hULA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=bHcvl2ma; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-33645-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33645-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jj18-20020a170903049200b001d6f7b3f65csi8284206plb.43.2024.01.22.09.16.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 09:16:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33645-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=bHcvl2ma; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-33645-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33645-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 85B1D286959 for ; Mon, 22 Jan 2024 17:13:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB1374CDFF; Mon, 22 Jan 2024 16:01:11 +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="bHcvl2ma" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 715BF4D117; Mon, 22 Jan 2024 16:01:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705939268; cv=none; b=f5hMBI6aV+aZKx8rQlIEDX5F5aaGWznoxd5qw4V2Ijvobh8GyoX3ZDoaDajr4eMqrOUDMNtXCeQjI/jdLpvdbTUj3x8C2ljQZORSw8MKsVb/Mn5c/0KTxeAEfzGMClHzzeR8NZ+cTbqjZx5GiZkOIeq9CtVe2suzeja4LdYzyWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705939268; c=relaxed/simple; bh=/V4sb8LgDiZWE3Juc5rPE5tfHJq1izPIerz9v0keYy0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=LxmBnZ6XwfVFnaK/90y00EQt4h4nYaysH5yw5yIxjjHzfCEpXhUf5A4EyaUb5QjiErvO+l0rc8YYNN+4kD6HsNScYEDeIGs7qtxUHzqBEm6QQtoxO6I0l7u/TEWRm4bQ3o5DeIlcDTLFdnaRYu2Wm4aqvZe/nURGRBcFGbv7jp4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=bHcvl2ma; arc=none smtp.client-ip=13.77.154.182 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 5796220E2C09; Mon, 22 Jan 2024 08:01:07 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5796220E2C09 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1705939267; bh=xk+J9offpgOWbG5/MefCVQrVZHtpJxME2AVu0bJoiYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bHcvl2mayTfpazeaOQG9hVEQXa1ILyF8kUGfhE6iASJYmYhatoicq0AOly7Z4LuxU H8pbA507JOC4hRlF4LhZTc2OqPFEtH+7i6rGcIkjT6Pi8J4XzqVb6iTQRtHFpwW2zl aUezifPhXwAXFcDmV/+9GazlNkX72BqxTEoZr+IY= From: Souradeep Chakrabarti To: 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, yury.norov@gmail.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 Cc: schakrabarti@microsoft.com, paulros@microsoft.com, Souradeep Chakrabarti Subject: [PATCH 4/4 V2 net-next] net: mana: Assigning IRQ affinity on HT cores Date: Mon, 22 Jan 2024 08:00:59 -0800 Message-Id: <1705939259-2859-5-git-send-email-schakrabarti@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1705939259-2859-1-git-send-email-schakrabarti@linux.microsoft.com> References: <1705939259-2859-1-git-send-email-schakrabarti@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788811647643093881 X-GMAIL-MSGID: 1788811696685915164 Existing MANA design assigns IRQ to every CPU, including sibling hyper-threads. This may cause multiple IRQs to be active simultaneously in the same core and may reduce the network performance. Improve the performance by assigning IRQ to non sibling CPUs in local NUMA node. The performance improvement we are getting using ntttcp with following patch is around 15 percent against existing design and approximately 11 percent, when trying to assign one IRQ in each core across NUMA nodes, if enough cores are present. The change will improve the performance for the system with high number of CPU, where number of CPUs in a node is more than 64 CPUs. Nodes with 64 CPUs or less than 64 CPUs will not be affected by this change. The performance study was done using ntttcp tool in Azure. The node had 2 nodes with 32 cores each, total 128 vCPU and number of channels were 32 for 32 RX rings. The below table shows a comparison between existing design and new design: IRQ node-num core-num CPU performance(%) 1 0 | 0 0 | 0 0 | 0-1 0 2 0 | 0 0 | 1 1 | 2-3 3 3 0 | 0 1 | 2 2 | 4-5 10 4 0 | 0 1 | 3 3 | 6-7 15 5 0 | 0 2 | 4 4 | 8-9 15 --- --- 25 0 | 0 12| 24 24| 48-49 12 --- 32 0 | 0 15| 31 31| 62-63 12 33 0 | 0 16| 0 32| 0-1 10 --- 64 0 | 0 31| 31 63| 62-63 0 Signed-off-by: Souradeep Chakrabarti --- .../net/ethernet/microsoft/mana/gdma_main.c | 61 +++++++++++++++---- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c index 05a0ac054823..1332db9a08eb 100644 --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c @@ -1249,7 +1249,7 @@ void mana_gd_free_res_map(struct gdma_resource *r) r->size = 0; } -static __maybe_unused int irq_setup(unsigned int *irqs, unsigned int len, int node) +static int irq_setup(unsigned int *irqs, unsigned int len, int node) { const struct cpumask *next, *prev = cpu_none_mask; cpumask_var_t cpus __free(free_cpumask_var); @@ -1280,13 +1280,16 @@ static __maybe_unused int irq_setup(unsigned int *irqs, unsigned int len, int no static int mana_gd_setup_irqs(struct pci_dev *pdev) { - unsigned int max_queues_per_port = num_online_cpus(); struct gdma_context *gc = pci_get_drvdata(pdev); + unsigned int max_queues_per_port; struct gdma_irq_context *gic; unsigned int max_irqs, cpu; - int nvec, irq; + int start_irq_index = 1; + int nvec, *irqs, irq; int err, i = 0, j; + cpus_read_lock(); + max_queues_per_port = num_online_cpus(); if (max_queues_per_port > MANA_MAX_NUM_QUEUES) max_queues_per_port = MANA_MAX_NUM_QUEUES; @@ -1294,8 +1297,18 @@ static int mana_gd_setup_irqs(struct pci_dev *pdev) max_irqs = max_queues_per_port + 1; nvec = pci_alloc_irq_vectors(pdev, 2, max_irqs, PCI_IRQ_MSIX); - if (nvec < 0) + if (nvec < 0) { + cpus_read_unlock(); return nvec; + } + if (nvec <= num_online_cpus()) + start_irq_index = 0; + + irqs = kmalloc_array((nvec - start_irq_index), sizeof(int), GFP_KERNEL); + if (!irqs) { + err = -ENOMEM; + goto free_irq_vector; + } gc->irq_contexts = kcalloc(nvec, sizeof(struct gdma_irq_context), GFP_KERNEL); @@ -1323,17 +1336,41 @@ static int mana_gd_setup_irqs(struct pci_dev *pdev) goto free_irq; } - err = request_irq(irq, mana_gd_intr, 0, gic->name, gic); - if (err) - goto free_irq; - - cpu = cpumask_local_spread(i, gc->numa_node); - irq_set_affinity_and_hint(irq, cpumask_of(cpu)); + if (!i) { + err = request_irq(irq, mana_gd_intr, 0, gic->name, gic); + if (err) + goto free_irq; + + /* If number of IRQ is one extra than number of online CPUs, + * then we need to assign IRQ0 (hwc irq) and IRQ1 to + * same CPU. + * Else we will use different CPUs for IRQ0 and IRQ1. + * Also we are using cpumask_local_spread instead of + * cpumask_first for the node, because the node can be + * mem only. + */ + if (start_irq_index) { + cpu = cpumask_local_spread(i, gc->numa_node); + irq_set_affinity_and_hint(irq, cpumask_of(cpu)); + } else { + irqs[start_irq_index] = irq; + } + } else { + irqs[i - start_irq_index] = irq; + err = request_irq(irqs[i - start_irq_index], mana_gd_intr, 0, + gic->name, gic); + if (err) + goto free_irq; + } } + err = irq_setup(irqs, (nvec - start_irq_index), gc->numa_node); + if (err) + goto free_irq; + gc->max_num_msix = nvec; gc->num_msix_usable = nvec; - + cpus_read_unlock(); return 0; free_irq: @@ -1346,8 +1383,10 @@ static int mana_gd_setup_irqs(struct pci_dev *pdev) } kfree(gc->irq_contexts); + kfree(irqs); gc->irq_contexts = NULL; free_irq_vector: + cpus_read_unlock(); pci_free_irq_vectors(pdev); return err; }