Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3375541pxy; Tue, 4 May 2021 00:08:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzheERUv26UjuDcl6YNLzVaWJ2SbZkJu+Dnp+o7JdbO1Pem1pmvh8e1NhGYQ6T26KE0G7Kb X-Received: by 2002:a62:d409:0:b029:27d:338:1cca with SMTP id a9-20020a62d4090000b029027d03381ccamr22812741pfh.25.1620112111758; Tue, 04 May 2021 00:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620112111; cv=none; d=google.com; s=arc-20160816; b=KkISmsoxaT5PnacQVQPRh+A/1Oeei9hZpn7Cp3jUUwYhJNpustAJRFQtdOIaxpTdgJ XfvJAhQqYC8hZjs/80TkSjy1Yc9dBzceijqe8vs/eUVlPVH0z8RJjOc/De/PjCtrHvk8 xfav8h77/Qy/b9nOkqAYaXS3wXcOhJ4kClg/Ta5AT2zKiBrBx2zJ1UMf6HxMVKb8YVlO K6LIqndKPt9uywiFNKqB45HWh2d5+cernOJlfRr+YMmzjpgfB2zAxaAcEpQWX+Hab0OR k+4PRZvsHvnpnWa2s12yG5r5ByEQ8W8yC/hecsK8HM4TMYzMUjFCWF20fzyAzM6fS+fF 0//Q== 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=CPucxsKXOd5FFFpJT2+ACBx+HUtwy/Fmy8BA+XFyr9o=; b=Tj4+Ev3IaN//lSUC89EEyP9bhjw5iaqE/YR1rDrXXMFvpc/98PehWgwJ0MDWGTIKCY Uaks1TlGc3RUBBU5J6ItpmNKxs1ZoS9k2zS2BcZXIxKroRqjlV+11ZGAx/RW/Fyn7AQX JslBP5nLOu8FMuvUgT7k76zKcfTP1Qvp4XD1lhhUYJMUfRP1q+ZL1CX2/fQk9IwZwi03 FSs70W3oGFOFsr/xs+gwYq3aFKYXz+Qc/Or+yjqruNSwGtpbvlsJRGAOtxQu0w77hYFP YtbxJzMDJXTF3Mp6o152b464Z36/cJ9VULAxF6usSn48OWCbJId5tSGifKDRGCNdQPpb N6DQ== 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 n10si2934367plc.81.2021.05.04.00.08.19; Tue, 04 May 2021 00:08:31 -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 S230163AbhEDHHr (ORCPT + 99 others); Tue, 4 May 2021 03:07:47 -0400 Received: from mga14.intel.com ([192.55.52.115]:4376 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230040AbhEDHHZ (ORCPT ); Tue, 4 May 2021 03:07:25 -0400 IronPort-SDR: rvjhtqyzYc4HLc1VQNhC3+we1XG7pJoCGtMXPaY9R1J76LKNkrhXDN6dbb8IMT644nUKFBly7T +OvR9sMmUGfQ== X-IronPort-AV: E=McAfee;i="6200,9189,9973"; a="197534538" X-IronPort-AV: E=Sophos;i="5.82,271,1613462400"; d="scan'208";a="197534538" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 00:05:59 -0700 IronPort-SDR: V9Ra87L4nOH6km8gO5xNTMigeVOsTZxMYNjNC+KueNI1ARdbEkADhXiGe6KJNrCy2wmBxMRoD5 HBAKJ2Avcqew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,271,1613462400"; d="scan'208";a="450895511" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga004.fm.intel.com with ESMTP; 04 May 2021 00:05:40 -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 v5 09/20] tools lib: introduce bitmap_intersects() operation Date: Tue, 4 May 2021 10:04:44 +0300 Message-Id: <65ef6a2c0aabd22c067944ad0f74c9d14818fd00.1619781188.git.alexey.v.bayduraev@linux.intel.com> 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 477a1cae513f..2eb1d1084543 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))) @@ -178,4 +180,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 5043747ef6c5..3cc3a5b43bb5 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