From patchwork Mon Jan 29 06:21:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souradeep Chakrabarti X-Patchwork-Id: 193267 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp389440dyb; Sun, 28 Jan 2024 22:23:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVvpX7e46CVT8He4Dv/nq+UCZHo8BVGVBzz/ZZLHjsohX6x3wIj03RsOGDOlk9ZJXns1iC X-Received: by 2002:ae9:e409:0:b0:783:1a32:a62c with SMTP id q9-20020ae9e409000000b007831a32a62cmr4571451qkc.149.1706509397161; Sun, 28 Jan 2024 22:23:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706509397; cv=pass; d=google.com; s=arc-20160816; b=DFAq2v50/+V4tEKc7f9edtZR90MDvMb9wzy5EGJ+gIdcpfLle/Hr4grhEsvjVZGEj2 UfEsb5aCv1/q3XillpEgEt69xiP3EXG0fUKxeq0gnKbQrIk3acAjg5OFZUGg1IRKXbgW Tw5BncMnDSjS5xUWSfkq+VOq266qS7IhYzdo7rVW/Gg4HgMhdbquGB7jgpVDWW0a9y/e 8VxNVa46SVFbEcR5d0h55gBmvEdHk2MRAylLpDnesvumpJm4AXGoYg8WgJqSe7ikC18V tz4bJ2qBYDAs5j/ra381pnh8arsQYz4yDjaxqkljLTU0ie4Bq8c0LKpf2zDit3ALidvS Qbug== 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=wNoxBap/mgmN19VWA3DMecWHPbW/ZIED350thzCv6t/dCz4aiuBmJthRDyibgHJzja 8FNJy7V0dUZzIBgd1hWO1KDl+He7RrC9ZHK2Ij1QvcolZ/NHEKz7LgxB1NrE/9Ilb5kv MNP3GgcaeHY1PAKo5x0PZWAL5gfa3+kGLNuiQINMn07sY5CdmaCJtA8pPZjWL95W0+VT 7WAx2vWhoE9SiEgf7veRQohQO0qH1Y+rp+A7QDtTF9O+xJuQl3T0KuPacq+UO69V7OMK weba6D4lG4ttsSgQK2anz9EQJt1arpwh8VVn+sfzyMHaXBscMwPopsto8mJXkMcOdHV5 vlJA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=C11V5SYu; 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-42225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42225-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c15-20020a05620a164f00b00783dcad7227si5946474qko.517.2024.01.28.22.23.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:23:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=C11V5SYu; 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-42225-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42225-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EDDFB1C22425 for ; Mon, 29 Jan 2024 06:23:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8699524C8; Mon, 29 Jan 2024 06:21:36 +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="C11V5SYu" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 402A84C629; Mon, 29 Jan 2024 06:21:32 +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=1706509293; cv=none; b=TdkxLIO+TqpwqT/nzDjcuwuvrsKbC6gr979pvOOSZwc5v1CNTYoQmo+TGx5osaaTvt6CiB5Tc2/qTZyCNo+EgN36E1dp4RjLQCGT4I0GTXShlGbbBU0Rllc+2MDT9iOcy6A+3I3SFFG7wV9rbd51wSbtpmTaagYTPcAF88iymUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509293; c=relaxed/simple; bh=JWip2UTTjunONm5W+kW2X28AocSMuT6jlRKMeBFBPOA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=fX5EU0Lfhd9zwlczt5Bjt9Tv46hUecpNLQ5ZsxI2vnNbNzr/N3oxfPyGqpc5iX+N+4wo0SfmxpUSCuusgOAe31sFNq+Beik4p4drrM199AGUBBWsFV1PxsIbHKVsJbvwkfshgU6dJJ+lYW8GTCIOnJI8WSiBK406cv3gVmaJkcQ= 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=C11V5SYu; 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 AFFC420E67D4; Sun, 28 Jan 2024 22:21:26 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AFFC420E67D4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1706509286; bh=Qh4vCcMbs6V3VMTJ7hXH2GEKRppPqxUeLFTB/Ig1nok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C11V5SYuf6FExFn0KKr+UA0GfphvYgEKbgmfBpugNq/RJemDlCfcLJHmmENkQaT+r yg+PlOFu/8Uopt6suDXj6TGUz3jdAh0xNQzC1NPPCIuQ10jsrMR+056At5idjoxIs3 +heXAAG4NSNuH3BYJmXuwHz08GVf06NbgCnmo5Y4= 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 V3 net-next] cpumask: add cpumask_weight_andnot() Date: Sun, 28 Jan 2024 22:21:04 -0800 Message-Id: <1706509267-17754-2-git-send-email-schakrabarti@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1706509267-17754-1-git-send-email-schakrabarti@linux.microsoft.com> References: <1706509267-17754-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: 1789404797465088680 X-GMAIL-MSGID: 1789404797465088680 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 29 06:21:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souradeep Chakrabarti X-Patchwork-Id: 193268 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp389530dyb; Sun, 28 Jan 2024 22:23:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUpQWjx9EKeVrNyx4Y2XGeCnDFegGo0UZ1GJhkpG0lrAteHJlJrzgDFOEzvIN4/FLHnsqh X-Received: by 2002:a17:906:b35a:b0:a31:d17c:f4ef with SMTP id cd26-20020a170906b35a00b00a31d17cf4efmr5350222ejb.20.1706509418937; Sun, 28 Jan 2024 22:23:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706509418; cv=pass; d=google.com; s=arc-20160816; b=IwdVqyZRrmUhHxFeV2AkcCfFHRYJPnb3UMwgLarbp77INwNLfos/gZGYDDIHlKIeQI uvahT762rJU1T1xali5lEEACLWRE4nYHVGLwhLyLY3EjkjSMr7+1+IDAY4S5odQD6q09 YmcCI617siOas/IqB5A4QlYBqWK4JJwGnnSTRk9wvYZFYt8Pf9P80oWtvp/iOll9rA0A ev//+3npYj4qv4dcL1aSAkPnjaVvV87AIV1w23nmEpllQQi9mN5eZfafDeqsphzSmBAD bHpK71GGPGs5uIOZbsd4lnHbnq6ixVziRXW1y/ksv20rZ6LqG7Zmm2eA3twaHewCXoJr QOiw== 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=V94S5IHv8RP+W4w/zbqt/IxTuQ5P7aFfcHZUQWYco2GgvA6kzZcJULGu9pAMAL05an 8Xs64KMysI6cM/R+MZpGJUYGzk11l5bslfOvuEhoUnqGI4Bk5Ivx0SO8najOm9NrG1ah UN0AsG16EP0hUQgb3eUT9oK91jn6k1jybexdY33PgfdFWpukspBhctQcl2dtS7ebaFX8 hX8wQBc3ySrUQLhU8xxCe/AOQNd10/lKwApXeMEYjlS66xQJxVO7XfHLhkJMet37Jjyn LtF2eS7EE8LbzuGk28RQpKyn5N/T0vyT+dIo6C3XpgikPcXAIunGoVnK3ezV2bg+25Po Pp4g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=L+BQGoB0; 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-42228-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42228-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. [147.75.80.249]) by mx.google.com with ESMTPS id y8-20020a170906558800b00a35a0186ac0si984843ejp.132.2024.01.28.22.23.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:23:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42228-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=L+BQGoB0; 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-42228-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42228-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 5B9FD1F2151F for ; Mon, 29 Jan 2024 06:23:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B852537F1; Mon, 29 Jan 2024 06:21:38 +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="L+BQGoB0" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E2764D5AC; Mon, 29 Jan 2024 06:21:34 +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=1706509295; cv=none; b=A+zjDz3OteoA+f/fRXoR97NjXwJEEyoHZANL3wMH24RnwXsnsFWsUikMdtCKPg5KNA5GJ5FsobzcWE8MVKVcFkGrQ+zF/zhYrDCLC9g+TYCcg5eiRFXFwyTB/QGsVpOvPJJhzcXBmKpvIp7Aw89QJZ2I3qdB7qVkpfDwzKW2Xbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509295; c=relaxed/simple; bh=2TbGyVSXByR1bZJMjbZ9qzvNekm4PoMQJkQoldzGsDY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=UEYFrlbzfmgxCOJvW21doYaTY5etEl44/ske7Hl+TX0jGtw9HNIj0NrApoA5TgD/QYvtcneT7hG/JFO2v9w6PaEopwQ+im5EFDq/kJ96MqjFIqrRhmepyOfhXzKOvZcxqvRGVe5Fgo/IqdXoOgGTXaVZuB1leCSPE2XAlb23Y48= 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=L+BQGoB0; 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 CEEE520E67D7; Sun, 28 Jan 2024 22:21:28 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CEEE520E67D7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1706509288; bh=ZPRu3SXlIUr+8W26d0LPvybxMOuIzrvNRUu535P0XZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L+BQGoB0GLE+KyyR0PnFVug/r66VXfnIBCw46epW85csspHZObEUXpA36eCL+5aXG FkaJ3jqMQoLOZsqelD/vHDM6Ja6B9RlA4q5ScoO7MIn7t/vAJgyYtq1RbDYMeYC+59 dUE+JuQXkzd2DGn8h3CGkjEUpMh1Cxd/15HY7InE= 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 V3 net-next] cpumask: define cleanup function for cpumasks Date: Sun, 28 Jan 2024 22:21:05 -0800 Message-Id: <1706509267-17754-3-git-send-email-schakrabarti@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1706509267-17754-1-git-send-email-schakrabarti@linux.microsoft.com> References: <1706509267-17754-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: 1789404820095097846 X-GMAIL-MSGID: 1789404820095097846 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 29 06:21:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souradeep Chakrabarti X-Patchwork-Id: 193266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp389380dyb; Sun, 28 Jan 2024 22:23:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3OXxmyaQ8mRQM1OeQDQVqYdRPqvGdAdQrahlYMk/XnmwXOfGBu/BgAM4Z/qabE2RQ8nnm X-Received: by 2002:a17:906:4a83:b0:a35:c868:ba8e with SMTP id x3-20020a1709064a8300b00a35c868ba8emr626876eju.25.1706509387568; Sun, 28 Jan 2024 22:23:07 -0800 (PST) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cf7-20020a170906b2c700b00a340763070fsi3279878ejb.296.2024.01.28.22.23.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 22:23:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42224-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linux.microsoft.com header.s=default header.b=fTM4uUAS; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-42224-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42224-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 33A501F20F71 for ; Mon, 29 Jan 2024 06:23:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 638FD51C5D; Mon, 29 Jan 2024 06:21:36 +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="fTM4uUAS" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CCBBB4C61B; Mon, 29 Jan 2024 06:21:31 +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=1706509293; cv=none; b=lKQ65LAeNVoSMpBJToTf1BhqoV3px9DLgmI82jw2owzh6Lt5COgypm5xYf2C9QbnMZuQP9R+zQ6DAopBL8tq/dRgGmIqbdwbgQQ2z+FJX5sDHG3nkuzT+k5uU00/Ku6kkLPSr5ajrnbhtd7a/d5VWUCGGwtuDbY0dioN59I0shc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706509293; c=relaxed/simple; bh=N8bi7iOk7SkztwFK/cTk8Cvbzl4tKg+IpZOOTeXUr6o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=Q25Uhfd+1swETI170ojfrD0PWJY+gDo3U4+7Ae3tbHm7WKPPm9TqTjoO/NGOF7lcFpa6jTlmNBNgQeawdoiEft9FH9xGHC91PWTq1Af9+E7VDMO2TG6YtYcuuT8nM/YAba7rFSoICWON/Rikf9lPhPD2u4qIVPl6LFATvMqGZHo= 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=fTM4uUAS; 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 A45CF20E67DD; Sun, 28 Jan 2024 22:21:31 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A45CF20E67DD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1706509291; bh=cbmGLa7jFFF/JRYGhEzNHaYORqYhPABgjUC6W0VOrNU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fTM4uUASsrsw0lUMV9oWOriY9qpLMW/WpE9/0DpfNxiqa7rK3epemT4zo6e3Wak8R Q8NM1fueDR8k8tBeeta4jFwJ0PaGJkxhqod6HEx9GtLH38Nw1NKJZFCC8rlg1yxoJb KQ5xzutMQDJqqwAEydRUEp/0WLK5OUnSWFSNEm8g= 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 V3 net-next] net: mana: add a function to spread IRQs per CPUs Date: Sun, 28 Jan 2024 22:21:06 -0800 Message-Id: <1706509267-17754-4-git-send-email-schakrabarti@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1706509267-17754-1-git-send-email-schakrabarti@linux.microsoft.com> References: <1706509267-17754-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: 1789404787273012678 X-GMAIL-MSGID: 1789404787273012678 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();