Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5218577pxj; Wed, 26 May 2021 05:47:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzX5RBY1OxW0GNbtxkTKyW8TwHIsT/QfneUnZl3BWPdiTK1FCNXuR5CijZ4uWmzFozXCxf/ X-Received: by 2002:a50:bec1:: with SMTP id e1mr37619396edk.116.1622033219911; Wed, 26 May 2021 05:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622033219; cv=none; d=google.com; s=arc-20160816; b=OpR2MxJpSOa0IVn7U75zoQpY7EDC8QUkWmm4yRCjhhlWQBDbsvCIqCYlBHHITFs+ds 9UpBlubPJGsogYGmhNvRlBUWcuHkeZb4B2aRknmctZfE9F2u1ccOg8jgZaHQoV9v9ufc TK2CrM9MUmVDv//bTnQRAjao31EacRFvA3J+TlupANFu5dglFO9DjKRTT9jfWGotKhHg ubuzXPWlkQM9IVD46NFJh1/b+HzuPWXWgcFQPPynjlxP4tB3TZXp7VizD7JnNUZlcYHB Vt4ZJcJN7Af2bjzz4BW8B8V5i01VnwtzrVdXr88miecZjgU5N0K47bXTWa19RbLHLk1G z1GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=vQbBzCHPnVcE+EVWs1q+9rpv/Nm7UumOVTwnWAlg79E=; b=Bcr+V/P6ouaLI4RyT/4a9ohvxwXhVmOz7iWpyvlyCQD2ufZnb2xv4HFc5KJ6soBmJ1 YTRoi0JVmFx3TRG6VJcYgIWdJm0f0dZHKwkL/tkCr4cXjESrLB3gTZdl/dCFZaDDL+8k yKFjDMH1hyYa2xtMVDIEU58XrmRXBwOHr2rqZnK3lEezLGP1wEObhOAFZa/G13kIExr/ Uw4XUrxTUOIRcXjmV0mKUlXFXhPi9swb8Bs38DSKCSeS6Lt+3w4EyKpr36AgJ1XgmWhU A1nEDxJlyn0VJdXpglhBP10QwosyXZt+RP1nw3FsHjlDm5UzGH3MGmociWGQWbVeLgDq Yl/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id da5si16440909edb.538.2021.05.26.05.46.35; Wed, 26 May 2021 05:46:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234300AbhEZKzd (ORCPT + 99 others); Wed, 26 May 2021 06:55:33 -0400 Received: from mga02.intel.com ([134.134.136.20]:1577 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234302AbhEZKzS (ORCPT ); Wed, 26 May 2021 06:55:18 -0400 IronPort-SDR: nL6quLu+KOclqaIRoPDBXIdc3QuaarZH9yRDpm/fXeTM9Kci28QdmHxkZpvojl+pwTSfA2g62z 8tzKdPECV18A== X-IronPort-AV: E=McAfee;i="6200,9189,9995"; a="189556452" X-IronPort-AV: E=Sophos;i="5.82,331,1613462400"; d="scan'208";a="189556452" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 03:53:45 -0700 IronPort-SDR: EuyINrXHuHOYnU+WPDNEAdl8akRc+Z9BS8kVsOrDVgG/2jMyG5VzSHl1iUDCYsJSjggvA4lS5k TTpORvqFE1Ww== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,331,1613462400"; d="scan'208";a="436079263" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by orsmga007.jf.intel.com with ESMTP; 26 May 2021 03:53:42 -0700 From: Alexey Bayduraev To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov Subject: [PATCH v6 09/20] tools lib: Introduce bitmap_intersects() operation Date: Wed, 26 May 2021 13:53:02 +0300 Message-Id: X-Mailer: git-send-email 2.19.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce bitmap_intersects() routine that tests whether bitmaps bitmap1 and bitmap2 intersects. This routine will be used during thread masks initialization. Acked-by: Andi Kleen Signed-off-by: Alexey Bayduraev --- tools/include/linux/bitmap.h | 11 +++++++++++ tools/lib/bitmap.c | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 330dbf7509cc..9d959bc24859 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h @@ -18,6 +18,8 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, int __bitmap_equal(const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int bits); void bitmap_clear(unsigned long *map, unsigned int start, int len); +int __bitmap_intersects(const unsigned long *bitmap1, + const unsigned long *bitmap2, unsigned int bits); #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) @@ -170,4 +172,13 @@ static inline int bitmap_equal(const unsigned long *src1, return __bitmap_equal(src1, src2, nbits); } +static inline int bitmap_intersects(const unsigned long *src1, + const unsigned long *src2, unsigned int nbits) +{ + if (small_const_nbits(nbits)) + return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0; + else + return __bitmap_intersects(src1, src2, nbits); +} + #endif /* _PERF_BITOPS_H */ diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c index f4e914712b6f..db466ef7be9d 100644 --- a/tools/lib/bitmap.c +++ b/tools/lib/bitmap.c @@ -86,3 +86,17 @@ int __bitmap_equal(const unsigned long *bitmap1, return 1; } + +int __bitmap_intersects(const unsigned long *bitmap1, + const unsigned long *bitmap2, unsigned int bits) +{ + unsigned int k, lim = bits/BITS_PER_LONG; + for (k = 0; k < lim; ++k) + if (bitmap1[k] & bitmap2[k]) + return 1; + + if (bits % BITS_PER_LONG) + if ((bitmap1[k] & bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) + return 1; + return 0; +} -- 2.19.0