Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1217939ybl; Tue, 3 Dec 2019 03:44:22 -0800 (PST) X-Google-Smtp-Source: APXvYqy6bKjD4gmTXegcVuYNfG78PvPYAQBjuUKGEO6sMFZc+RKXo7UOLl+ecebTkVYdQyBCVccM X-Received: by 2002:aca:f083:: with SMTP id o125mr3059954oih.122.1575373462591; Tue, 03 Dec 2019 03:44:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575373462; cv=none; d=google.com; s=arc-20160816; b=aQTx2YZwvoCFhHB0s1K3CAegimwwvRFoQR2GTqrnyImf2UXELFgClMj1ZnVbqWkz7A rvPiJqheQ2pKzJfLyFBbrneXA/ZP/s/ktuba1XT+27f01hTtF82Tuljawtt9EWLLVnl7 BZWyd65wDpciu526ccNX9rMjVFrR8riHgTxceo2uLsOUL62B3UQhthfltm39h7EDxGwi qvgAkzIfbePql/FOfVKKZ4OLb4m7/+ufOfuGB0DuONPOT5rKuzvcRMUoHVBm7QoIc5k9 cOOhC5hQ3gz7YRIcpsB3CeKO1XQQ9/PNLdrLFYfftsMZi9kiLLx9Gq5vsObk+ccGwSl8 Wg4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:references:cc:to:from:subject; bh=4N0t83ocMmrvl9/Thjyor4sfuejYaqQj7ANoSIaSlEs=; b=a7PuqsnxGG5I05gfpC3+7YP/S0dpdqv5XMOvpbYeVa2Qfoutgg9QV5RKDiKErVaJ4Y 2mGmupBXUcTOPZklUYuHB/k1AXVOcBt4WValLpP1f2kx2jzGHLQb0KQO0L0+12hhWS8F OzG89KnQidWS/QaYlozPs72lRYSP86yOb7Sj0MHccxAC43Ea2tquF/NfBZS0i2mil4qu 2NyVG12Hf8GItvARDxOKZ6ePf5095wQ3rshI1gGH/95i4SWofEqcuEMMeMDWO1n/xbmK aCaHZECsDuJmufED1Bz7Xk6Uf/GmtM3qsKFycK6LS/uovGqJSdyDeg0+99a0y41zceO1 Y1Ew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id q9si1134462oif.92.2019.12.03.03.44.10; Tue, 03 Dec 2019 03:44:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726017AbfLCLnj (ORCPT + 99 others); Tue, 3 Dec 2019 06:43:39 -0500 Received: from mga17.intel.com ([192.55.52.151]:35644 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725773AbfLCLnj (ORCPT ); Tue, 3 Dec 2019 06:43:39 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Dec 2019 03:43:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,273,1571727600"; d="scan'208";a="208456799" Received: from linux.intel.com ([10.54.29.200]) by fmsmga007.fm.intel.com with ESMTP; 03 Dec 2019 03:43:38 -0800 Received: from [10.125.253.16] (abudanko-mobl.ccr.corp.intel.com [10.125.253.16]) by linux.intel.com (Postfix) with ESMTP id 3283358033E; Tue, 3 Dec 2019 03:43:35 -0800 (PST) Subject: [PATCH v5 1/3] tools bitmap: implement bitmap_equal() operation at bitmap API From: Alexey Budankov To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel References: Organization: Intel Corp. Message-ID: <43757993-0b28-d8af-a6c7-ede12e3a6877@linux.intel.com> Date: Tue, 3 Dec 2019 14:43:33 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Extend tools bitmap API with bitmap_equal() implementation. The implementation has been derived from the kernel. Extend tools bitmap API with bitmap_free() implementation for symmetry with bitmap_alloc() function. Signed-off-by: Alexey Budankov --- tools/include/linux/bitmap.h | 30 ++++++++++++++++++++++++++++++ tools/lib/bitmap.c | 15 +++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 05dca5c203f3..477a1cae513f 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h @@ -15,6 +15,8 @@ void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, const unsigned long *bitmap2, int bits); int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int bits); +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); #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) @@ -123,6 +125,15 @@ static inline unsigned long *bitmap_alloc(int nbits) return calloc(1, BITS_TO_LONGS(nbits) * sizeof(unsigned long)); } +/* + * bitmap_free - Free bitmap + * @bitmap: pointer to bitmap + */ +static inline void bitmap_free(unsigned long *bitmap) +{ + free(bitmap); +} + /* * bitmap_scnprintf - print bitmap list into buffer * @bitmap: bitmap @@ -148,4 +159,23 @@ static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, return __bitmap_and(dst, src1, src2, nbits); } +#ifdef __LITTLE_ENDIAN +#define BITMAP_MEM_ALIGNMENT 8 +#else +#define BITMAP_MEM_ALIGNMENT (8 * sizeof(unsigned long)) +#endif +#define BITMAP_MEM_MASK (BITMAP_MEM_ALIGNMENT - 1) +#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) + +static inline int bitmap_equal(const unsigned long *src1, + const unsigned long *src2, unsigned int nbits) +{ + if (small_const_nbits(nbits)) + return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits)); + if (__builtin_constant_p(nbits & BITMAP_MEM_MASK) && + IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT)) + return !memcmp(src1, src2, nbits / 8); + return __bitmap_equal(src1, src2, nbits); +} + #endif /* _PERF_BITOPS_H */ diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c index 38494782be06..5043747ef6c5 100644 --- a/tools/lib/bitmap.c +++ b/tools/lib/bitmap.c @@ -71,3 +71,18 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, BITMAP_LAST_WORD_MASK(bits)); return result != 0; } + +int __bitmap_equal(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 0; + + if (bits % BITS_PER_LONG) + if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) + return 0; + + return 1; +} -- 2.20.1