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=-6.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no 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 B5AE3C433E9 for ; Sun, 27 Dec 2020 22:04:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83B362242A for ; Sun, 27 Dec 2020 22:04:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726260AbgL0WEE (ORCPT ); Sun, 27 Dec 2020 17:04:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:42066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726208AbgL0WEE (ORCPT ); Sun, 27 Dec 2020 17:04:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 313262242A; Sun, 27 Dec 2020 22:03:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609106603; bh=gQ23fPbegXnDwD7TFyM8SYshRz6kzvTEijfM7w8+3s0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=eP3I77v/R0SuCfmOw5xMVPxQnv7vqNSHyEb7kTOVyaOZ56khQIC881SVGrCvmRuK/ OnGKFQmEba8jgBZfYtBJesyyezVYlmLJBBG5TbALHXgihg0mgp9u2ugEiaJYvE8LHh 21A0ExJ0hASZRD8stNtGn1jR15j6gRyE4V6d5calcnUKi9ph1/hg7PXnZokDkU9Sid a2SxFj7ukZSCw1ttAyk6DXtPfKYYCohivw5nxHOOPg6tf6O4JZDuV2H0FJzVPDYGzC stWxbH8KXccygJLVdQnwgqfZbDZgv6R7PK/PHxxP+2vN1AVylU6Xip5xt/VWhKO/F5 FZHmn9dBUPs+w== Received: by mail-ot1-f51.google.com with SMTP id n42so7770925ota.12; Sun, 27 Dec 2020 14:03:23 -0800 (PST) X-Gm-Message-State: AOAM532R4llhtRLxOWgVET0xMYZu5SJnsiCH5LkX7MO+h6bZ9At8DG4N 9h+slvgjWzmcDqIWZFRRt2N3G8Q0t0WbcD7pzdE= X-Google-Smtp-Source: ABdhPJyy+i6e8QV64+vlH7BXLIF7x52lnf5sVIHwLc1ReRHJuAXnbd8gDZmUHonkqTZ2Cj12WLLoqyQ2phtmg8WnFeI= X-Received: by 2002:a9d:7a4b:: with SMTP id z11mr31374431otm.305.1609106602554; Sun, 27 Dec 2020 14:03:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Arnd Bergmann Date: Sun, 27 Dec 2020 23:03:06 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/5] clump_bits: Introduce the for_each_set_clump macro To: Syed Nayyar Waris Cc: Linus Walleij , Andy Shevchenko , William Breathitt Gray , Michal Simek , Arnd Bergmann , Robert Richter , Bartosz Golaszewski , Masahiro Yamada , Andrew Morton , Zhang Rui , Daniel Lezcano , Amit Kucheria , linux-arch , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , Linux ARM , Linux PM list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On Sat, Dec 26, 2020 at 7:42 AM Syed Nayyar Waris wrote: > > This macro iterates for each group of bits (clump) with set bits, > within a bitmap memory region. For each iteration, "start" is set to > the bit offset of the found clump, while the respective clump value is > stored to the location pointed by "clump". Additionally, the > bitmap_get_value() and bitmap_set_value() functions are introduced to > respectively get and set a value of n-bits in a bitmap memory region. > The n-bits can have any size from 1 to BITS_PER_LONG. size less > than 1 or more than BITS_PER_LONG causes undefined behaviour. > Moreover, during setting value of n-bit in bitmap, if a situation arise > that the width of next n-bit is exceeding the word boundary, then it > will divide itself such that some portion of it is stored in that word, > while the remaining portion is stored in the next higher word. Similar > situation occurs while retrieving the value from bitmap. > > GCC gives warning in bitmap_set_value(): https://godbolt.org/z/rjx34r > Add explicit check to see if the value being written into the bitmap > does not fall outside the bitmap. > The situation that it is falling outside would never be possible in the > code because the boundaries are required to be correct before the > function is called. The responsibility is on the caller for ensuring the > boundaries are correct. > The code change is simply to silence the GCC warning messages > because GCC is not aware that the boundaries have already been checked. > As such, we're better off using __builtin_unreachable() here because we > can avoid the latency of the conditional check entirely. Didn't the __builtin_unreachable() end up leading to an objtool warning about incorrect stack frames for the code path that leads into the undefined behavior? I thought I saw a message from the 0day build bot about that and didn't expect to see it again after that. Can you actually measure any performance difference compared to BUG_ON() that avoids the undefined behavior? Practically all CPUs from the past 20 years have branch predictors that should completely hide measurable overhead from this. Arnd 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=-4.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no 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 A3992C433E0 for ; Sun, 27 Dec 2020 22:05:30 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5904E22A84 for ; Sun, 27 Dec 2020 22:05:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5904E22A84 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4EULVkUEmJXLiVoPEMO+dMwwJh+49siqCdXFiBfzhRk=; b=2pCbViFrQal9RQBdf06wQPUy8 CHdoxft5b16UQk5EDY8CVYg2QXTisRcKakd2coQOlsI47FPKo8SPpHDPVIFSZs6wJveEhznuGwiN2 OkwNrw0L3AERBmRzSDt9whYXW+S8S/TziiKNUnws6GobSwb8ZPCcqqla0zqO1pJbicoVp1wYPU4ir 65Q5UgPcFkgt62FE03csJhdtY1RqIucbysirJkQInIrzxZep3wh1AuW11l0SBrbS4Ak9CdVTgqFSe kPlpOBI0b40iqxDLBWBgx7JZI3wrKHM7NJBNxafxOLC2Q0hlMpJuuRhcOmVwl1RhpcwdTg3oOeQdw yme/12eVA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kte8N-0003xI-2L; Sun, 27 Dec 2020 22:03:27 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kte8L-0003wp-13 for linux-arm-kernel@lists.infradead.org; Sun, 27 Dec 2020 22:03:26 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 38B6022AAA for ; Sun, 27 Dec 2020 22:03:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609106603; bh=gQ23fPbegXnDwD7TFyM8SYshRz6kzvTEijfM7w8+3s0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=eP3I77v/R0SuCfmOw5xMVPxQnv7vqNSHyEb7kTOVyaOZ56khQIC881SVGrCvmRuK/ OnGKFQmEba8jgBZfYtBJesyyezVYlmLJBBG5TbALHXgihg0mgp9u2ugEiaJYvE8LHh 21A0ExJ0hASZRD8stNtGn1jR15j6gRyE4V6d5calcnUKi9ph1/hg7PXnZokDkU9Sid a2SxFj7ukZSCw1ttAyk6DXtPfKYYCohivw5nxHOOPg6tf6O4JZDuV2H0FJzVPDYGzC stWxbH8KXccygJLVdQnwgqfZbDZgv6R7PK/PHxxP+2vN1AVylU6Xip5xt/VWhKO/F5 FZHmn9dBUPs+w== Received: by mail-ot1-f46.google.com with SMTP id w3so7766590otp.13 for ; Sun, 27 Dec 2020 14:03:23 -0800 (PST) X-Gm-Message-State: AOAM530Dugry9IEMFw4RF1EnpjLLd76tLCxEcYmUeeg7nJpozR6fxY2r 8s9HjKlb/l583mvVsNpRs6H4582OXAUfFqJ7Fx0= X-Google-Smtp-Source: ABdhPJyy+i6e8QV64+vlH7BXLIF7x52lnf5sVIHwLc1ReRHJuAXnbd8gDZmUHonkqTZ2Cj12WLLoqyQ2phtmg8WnFeI= X-Received: by 2002:a9d:7a4b:: with SMTP id z11mr31374431otm.305.1609106602554; Sun, 27 Dec 2020 14:03:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Arnd Bergmann Date: Sun, 27 Dec 2020 23:03:06 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/5] clump_bits: Introduce the for_each_set_clump macro To: Syed Nayyar Waris X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201227_170325_203682_796BA943 X-CRM114-Status: GOOD ( 24.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch , Amit Kucheria , Arnd Bergmann , Masahiro Yamada , "linux-kernel@vger.kernel.org" , Linus Walleij , Daniel Lezcano , William Breathitt Gray , Michal Simek , Bartosz Golaszewski , Robert Richter , "open list:GPIO SUBSYSTEM" , Linux PM list , Andrew Morton , Andy Shevchenko , Zhang Rui , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sat, Dec 26, 2020 at 7:42 AM Syed Nayyar Waris wrote: > > This macro iterates for each group of bits (clump) with set bits, > within a bitmap memory region. For each iteration, "start" is set to > the bit offset of the found clump, while the respective clump value is > stored to the location pointed by "clump". Additionally, the > bitmap_get_value() and bitmap_set_value() functions are introduced to > respectively get and set a value of n-bits in a bitmap memory region. > The n-bits can have any size from 1 to BITS_PER_LONG. size less > than 1 or more than BITS_PER_LONG causes undefined behaviour. > Moreover, during setting value of n-bit in bitmap, if a situation arise > that the width of next n-bit is exceeding the word boundary, then it > will divide itself such that some portion of it is stored in that word, > while the remaining portion is stored in the next higher word. Similar > situation occurs while retrieving the value from bitmap. > > GCC gives warning in bitmap_set_value(): https://godbolt.org/z/rjx34r > Add explicit check to see if the value being written into the bitmap > does not fall outside the bitmap. > The situation that it is falling outside would never be possible in the > code because the boundaries are required to be correct before the > function is called. The responsibility is on the caller for ensuring the > boundaries are correct. > The code change is simply to silence the GCC warning messages > because GCC is not aware that the boundaries have already been checked. > As such, we're better off using __builtin_unreachable() here because we > can avoid the latency of the conditional check entirely. Didn't the __builtin_unreachable() end up leading to an objtool warning about incorrect stack frames for the code path that leads into the undefined behavior? I thought I saw a message from the 0day build bot about that and didn't expect to see it again after that. Can you actually measure any performance difference compared to BUG_ON() that avoids the undefined behavior? Practically all CPUs from the past 20 years have branch predictors that should completely hide measurable overhead from this. Arnd _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel