Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4510815pxj; Tue, 22 Jun 2021 01:46:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTb9FvwWMaO+78HnZ432uZkeKFYGf2XjxdyPLHVeTKpUcAoFwk1awXCMMPFBBC6NIPr945 X-Received: by 2002:a17:907:2645:: with SMTP id ar5mr2841435ejc.37.1624351571925; Tue, 22 Jun 2021 01:46:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624351571; cv=none; d=google.com; s=arc-20160816; b=c42HIyzgTbesLf5SqPPRfONCRL/j4B2l5kiIkAbBS5dOysjzF+kvkqrgcSTDaaiIfr xHablo18br28PdiMdTPU8urSVADgmOvURV+Q+RyizBojqGY68SqgTabYn36iYe2ngaYP kkSsacRSfhXh1SzLBNDNsTojCaHraID9y98RIvCu2P4opFbF0XLvA+9XfloIVcmU7h7O ds5eB344fGbu0H1bQu9OaspFZ1XO2VPu2bMgn4T0jI09JC5swjA4Hw4+aUaZn/uz5UcM Ipj/rJdYObijpAHypkEILwmNAAa6m5+PBte6qUbszh2cM+HH4A+/+D/1fpSg2LC6EJ4m FzIw== 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=xMzYYyeLLykPNp/Y1dii6ryck7tVGq0Nu8hD+1JQd6Y41q2lSg+Y1EgBGZj37BP/65 QRtPyu0Fhl6enHsBE8Hf2E7RqvOY+G1Vc441l1irsAasWgrVH6g96r3tov9NlYl/GzJm rc2HrD5NkCjULUseuX4RTRv6rJyr1GmBth7XNlwuArKP6CsBke2B3PcZZECCNR2yyEXU RAJp2qAFinWK4jGA9NQADamxBRl0NApfNO9/DDvKVSK04rEQHwpqbgb617nLoLt0RgCX 9pf1Y8e1cswOG3MG/VN22vCzI9oUF+DnnaKUY/5ey+HnKwPD9Jnamsk2JdjenM3UfVE2 g65g== 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 3si13371005ejl.715.2021.06.22.01.45.49; Tue, 22 Jun 2021 01:46:11 -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 S231201AbhFVIpd (ORCPT + 99 others); Tue, 22 Jun 2021 04:45:33 -0400 Received: from mga05.intel.com ([192.55.52.43]:57636 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231202AbhFVIp3 (ORCPT ); Tue, 22 Jun 2021 04:45:29 -0400 IronPort-SDR: exWo9i/hOZIBlEKJ8tcKLpbmB0cwukX0lHO+v1yxkhtKf56WN4zJq/ochFWbFFCilnPC0MKVHr PkeQdndYnSNg== X-IronPort-AV: E=McAfee;i="6200,9189,10022"; a="292641572" X-IronPort-AV: E=Sophos;i="5.83,291,1616482800"; d="scan'208";a="292641572" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 01:43:01 -0700 IronPort-SDR: Ni+v0rxX/uMqi2KSHrHWHrbK+I2qvr2ato3lI0A74Kfj94Wt5zPbq1FXuMBNfrvun6W64pL4Zj HFiMq6x7BH5Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,291,1616482800"; d="scan'208";a="417332563" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga007.fm.intel.com with ESMTP; 22 Jun 2021 01:42:59 -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 v7 09/20] tools lib: Introduce bitmap_intersects() operation Date: Tue, 22 Jun 2021 11:42:18 +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