From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 784A3C11F65 for ; Wed, 30 Jun 2021 17:24:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 557676146D for ; Wed, 30 Jun 2021 17:24:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232422AbhF3R1E (ORCPT ); Wed, 30 Jun 2021 13:27:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:56374 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229792AbhF3R07 (ORCPT ); Wed, 30 Jun 2021 13:26:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C46F261429; Wed, 30 Jun 2021 17:24:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625073870; bh=AtVx8zMxugVqeuPOoEk1jrOi31ee/q40+sbSDpOdn1I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Vc4i9yi86S6FdYtzHdbjyHASOeD/49AmWeR+WoyDbArJzAA2uysS41odZuHdLz97s rwLaf2nTzWUUNd8akCax3oFt3YEJBnDKvTfAReDNKuWHv7FRQw6LH1C2pBbBOTSYd9 ujgxwSO2QLLuDNcq3R8DIFUT7RTmOQ/oYKrB4q9v1E+yy46AfzKbao83JEBf1CHR9T 3yNFz8l3kf1h1JFH+NCpPP6vZTQ7kZQ9YfpVc525O7JAey9Z05PyDBeq16Dl+b4Brb pxB+Jhm8HtzwR9Ul4K0JRC8Ma2VLV/palYm+Jnx3ZQ6nx2R3TmHBrb1X01Ht9EbYYM mPA3KRKqUzwLg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id DAEFF40B1A; Wed, 30 Jun 2021 14:24:26 -0300 (-03) Date: Wed, 30 Jun 2021 14:24:26 -0300 From: Arnaldo Carvalho de Melo To: Alexey Bayduraev Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , Riccardo Mancini Subject: Re: [PATCH v8 09/22] tools lib: Introduce bitmap_intersects() operation Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > 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 > -- - Arnaldo