Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp508897pxv; Wed, 30 Jun 2021 10:35:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwo5XoCwGAdXpomPgYzeopjLqUll3vBoIrF9OPEbVRq1kssWFFwFQWT1kAbwu6vOJ5otJpO X-Received: by 2002:a02:a153:: with SMTP id m19mr9926837jah.105.1625074509509; Wed, 30 Jun 2021 10:35:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625074509; cv=none; d=google.com; s=arc-20160816; b=QZb1dF6uS9pk8XqTO0sB9xqBQBZkNh24UlXkzHTMUH7VUB285scGNMY7T4CJRC9vh4 +JPIMEo19OCiAcHuo43vS+NU+Xk8tzm5ZgrGvPO117+/m2eMgYCsW7Vp5MdI3nBihHiJ IB3NwNVNsAMxCp54UTqBEJV+cP9M7JrhjEi55oTj61u5+mBUNYzVWa5VGMMV/YnIGbWT z7qUF8u52NO5hRco/NcZfM50Im7Qwso0exgeks+MphO3A+Su5zdsuVZMEyHwztK8Qd41 Sqvs3+d9voxptMmjeYZ9J9cWbPkbLo+YMRusK+ADv9nzgZEUE/WOz4ZzXLfL+THOFp8/ fcNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject; bh=M84yROwXmbZtKNnJ0VRrSgUyntkfr8In2MQUjSnS7+M=; b=zoxNCC3j8YJ0lge/ed2HFHOr+tDOZfRkL6+qR8G8r6yxWhjiKNUv1xHR7496Yn4NGR +Lh6xoukHUMAE/KbAL+11eCNC8lE/+F0AoJmVr41eKjBeO3kHJW/2y8v9XX3WxmA2Zae 40tIPMK+y9NlRAlkkVURUGX3xUJQEzOL0gtAA0fdc1ysEv7F11qmvcZA/i41asZwR34Q itlbSKv0RJWBy6eVcnxwXspqRW1hVdBUde65Os63uSqIlQnW+NMehvIq8gnNeFErlxCw RNXA0W5XvpIDswK1D04koZ66AXzYnkGogF9Lhyj8MFbMId3K6zNpc196I7UkB2y3amV8 XrvA== 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 r4si21544147ioh.93.2021.06.30.10.34.57; Wed, 30 Jun 2021 10:35:09 -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 S232745AbhF3Rgp (ORCPT + 99 others); Wed, 30 Jun 2021 13:36:45 -0400 Received: from mga04.intel.com ([192.55.52.120]:54091 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229573AbhF3Rgp (ORCPT ); Wed, 30 Jun 2021 13:36:45 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10031"; a="206574695" X-IronPort-AV: E=Sophos;i="5.83,312,1616482800"; d="scan'208";a="206574695" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jun 2021 10:33:50 -0700 X-IronPort-AV: E=Sophos;i="5.83,312,1616482800"; d="scan'208";a="457340742" Received: from abaydur-mobl1.ccr.corp.intel.com (HELO [10.249.227.67]) ([10.249.227.67]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jun 2021 10:33:47 -0700 Subject: Re: [PATCH v8 09/22] tools lib: Introduce bitmap_intersects() operation 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 References: From: "Bayduraev, Alexey V" Organization: Intel Corporation Message-ID: Date: Wed, 30 Jun 2021 20:33:44 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30.06.2021 20:24, Arnaldo Carvalho de Melo wrote: > Em Wed, Jun 30, 2021 at 06:54:48PM +0300, Alexey Bayduraev escreveu: >> Introduce bitmap_intersects() routine that tests whether > > Is this _adopting_ bitmap_intersects() from the kernel sources? Yes, __bitmap_intersects is copy-pasted from the kernel sources, like the others in bitmap.h Regards, Alexey > >> 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 >> >