Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp438025pxv; Wed, 30 Jun 2021 08:59:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5Vpyq4SF/imkTf0E63u30yp7j3VYjMqsLdLFQ69vEEi1Hv5S/M1MnlX5iHgvNfQDP1zFk X-Received: by 2002:a05:6402:518d:: with SMTP id q13mr18050657edd.387.1625068752936; Wed, 30 Jun 2021 08:59:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625068752; cv=none; d=google.com; s=arc-20160816; b=Ayj9F2RngaeQbSEX7mAqMl+RqpRr5pgt7FyF6CZLV0l96WUDEADN8rRkJYWYHXWeMN v/RWF2YWYTMYqdSAfBA0ZwQjGZtu1Jyb0lc8CXdALFn68v+otzaa8OLyT+lVHr0/T8y6 zFkNZBxxi0CLnLjJLmsm/aWCZrJ1dPnW7Vc+NZ2+nQUCR/FSSV4RM5UDUiju1YIpwUVJ cmmV8Dh6UpeOVucKkDj0XibT0KNshjeu9+gyKzPhuJTcnth5c07E+G0PoHqcdeb4Sj0M ZggKHUHPzsnq4xSMBw48xPurAu7XcOCelCRm2BypyFMzJNhMKksMWsaL4krlbeh/9LXb vWHQ== 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; bh=rFRsi0I6IOdUVSDzlmqiHBOfoHJsCe4liw8tmTMFBzk=; b=N0rPbJjQ8bVFRfWsxRRLtBdd5WoEzAmrKgSMGPV9rgGYF+9cWPM0zS2zlsrlMEvr51 n+zbv61VnusoxwrHfI3royZL9qfHKFQ6Xm4TE3aq8kicyyRL7tVaks/3BfoFJF+1Bfnm JxF5gkm5RLucIuBX4vQLib5iiNVG6IfRw6gqNy26c7eq4PUhE+F7qWEeXgDLkw2SHja7 caAtvUoBIRWSv69W/MGy2m9BSigd1/akdulDfNW1Mukxsm8cgBvJF7MLHt3e0eFPf2+E mh0azxXbjCPWTUGVqEfb6TtXVXFv78XQD+Ft7xpxJKthzXzxvYcHB5I7tpuN3lTJUAZw f7xQ== 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 dq21si20048220ejc.181.2021.06.30.08.58.48; Wed, 30 Jun 2021 08:59:12 -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 S235995AbhF3P7A (ORCPT + 99 others); Wed, 30 Jun 2021 11:59:00 -0400 Received: from mga01.intel.com ([192.55.52.88]:4002 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235916AbhF3P67 (ORCPT ); Wed, 30 Jun 2021 11:58:59 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10031"; a="230015692" X-IronPort-AV: E=Sophos;i="5.83,312,1616482800"; d="scan'208";a="230015692" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jun 2021 08:55:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,312,1616482800"; d="scan'208";a="559099694" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga001.fm.intel.com with ESMTP; 30 Jun 2021 08:55:32 -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 , Riccardo Mancini Subject: [PATCH v8 09/22] tools lib: Introduce bitmap_intersects() operation Date: Wed, 30 Jun 2021 18:54:48 +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 Acked-by: Namhyung Kim 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