Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp502500pxv; Wed, 30 Jun 2021 10:25:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw49rgRbVwRt4/jCZ+8wFTTt4dapxntG2TGsdNOQBGCa58I6QkXw7t8RfA6izYh9J1dFuhP X-Received: by 2002:a02:cb0f:: with SMTP id j15mr2189038jap.11.1625073917925; Wed, 30 Jun 2021 10:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625073917; cv=none; d=google.com; s=arc-20160816; b=g4/l03R0h4orDhTrNwIF2yNpgccaSHiZZb5OT0ze8MOOEKxQ9UqqcmJMuGw/JL6Fet 1jGbN5u9M0RhkSsFfvLSTjoFL7TAZltJQGQTu8ZjVNSUCMo5IySqvfYbhTzS4MKvHF3R qlTrISG+KgdWVc1bwIdpFQmiAbfcfkC5M6g/mKzuiQID7ZdwOre3tpmd2u0/mxjCSfVR jg3Ob/QEfn7maKBwoIehJ5bOU0NeiRLUGoGzlH2R3BzQdQvgoqR+QcnrkdX3nk4q3XLp Ead0K+yf0eVQXJrHWyR52F8IuS1IpjDQVFBaWTgm8lFqMgAR8ZrEMi75UtW0MZF8VK1T p9nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vhnOGef0sPmNlJywcIoZifbiotTa+6TqccJpl2GlLXU=; b=D1PRXSGeYh15/gOYK7XVt0pqjMa1RKer7ZT5ZBzzwlDM+lnER057iXGFb0Ho2wd57M iCuVd3uKgi/iKt7LpJMgGpqsKMlY7LBw7JEGvVR8ivevSPWY/Pc4Aeiv/lPLrbvHKXHx nKbv6AXG/OYAtUlVucgcA7F4Fd/mHeMHayqkp4OIR3lC4mFyjAR/LCnEJow9jH7Ht3Fq wd3slbpXLYVuI6ji9sX9kAfgpPmc/fdMCO3wHu1eF6HN/MypRS5/UmoVDAV6kYptnfQD DRkBPj1kpFNYqLJJOlDALMRYATi+oG+PjMfdBv2PoHMz2nOVKJC/d65CFQEpZIdo742O u2eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vc4i9yi8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si5873526ilc.117.2021.06.30.10.25.05; Wed, 30 Jun 2021 10:25:17 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vc4i9yi8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230191AbhF3R1C (ORCPT + 99 others); Wed, 30 Jun 2021 13:27:02 -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