Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp9251694ioo; Sun, 5 Jun 2022 09:06:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSOQ/r9XB+GCAQHdj2Ifw+K8Ao/O6B/wpkvSovOIa6Ecks4uArw0ibpaP3wsg87XanmFPM X-Received: by 2002:a17:902:f687:b0:167:58bb:c43f with SMTP id l7-20020a170902f68700b0016758bbc43fmr10041963plg.136.1654445201024; Sun, 05 Jun 2022 09:06:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654445201; cv=none; d=google.com; s=arc-20160816; b=u1TzOdmBiQOmokDRvKKmA1vVSSiqQQf4YCIXr5ng2XPxkOyiCOrcOWYg5lPEkKamLu IBVyeelsIVMs3tfIdq+pA9zHdaXktLZfgBIKQ2SPTD+lR9uZBkoLCLoMPZBM1e8+ZiuW 00kUTKcenljRkLVW9bIQyI/jLpw1/QdN0mtrNKtqhGa8J3aCHQvAWwhCAKj4Z5X5iJty LuGnmYV2261FPO7tt3++GYTXGXePOE7BI416jRj1XDzdWoSXZu2hRLWzMksu2KuGQhSb xd8aqHS/nht2njBrwBU9V1JA4KXDQ+re5Buc62ll0MOrhtJDZvvMkPGMepf+j/o0oH7T EXIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RlH4HZM0GOqehDVq13X1kPLT+UzzEP8AsxwqPXI0mFY=; b=smlWnzxbG2d9FM4talqxFkA2nM4iy7Ov/UFHvxe3weqbK4R6WAZu4IC2g1hbmgRx3+ KPd9Redxr1Zz8L9aCj1uxTY9lL5Iv5ma+eNXVLC/CiKopPxNQVOFPiHvG6nBEVcx/yoA JnETNojUWd+vanCeWjmFb6MTIvgIWYDV0wW5kd1Ak1Ayyh5/Zc490yNDzzIA/ElKFdK0 6xUjipqld/Rv4ucaQJzvuZSbYhZX0szghE9/jDpXaLz0w7Icy6WDd5E7UQRNQtj898O1 8aSRsXDq8d6iO4bUMvEcIsOfSajd3M95ZB6/WYiLws4YnN52wTIB8gB0a8FK3FoWpyYh XdsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="bX//7ZiM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qe5-20020a17090b4f8500b001bfc324fc16si23390114pjb.99.2022.06.05.09.06.28; Sun, 05 Jun 2022 09:06:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="bX//7ZiM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346926AbiFCSed (ORCPT + 99 others); Fri, 3 Jun 2022 14:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347315AbiFCSdo (ORCPT ); Fri, 3 Jun 2022 14:33:44 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67912666B9; Fri, 3 Jun 2022 11:20:05 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id a2so13881866lfc.2; Fri, 03 Jun 2022 11:20:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RlH4HZM0GOqehDVq13X1kPLT+UzzEP8AsxwqPXI0mFY=; b=bX//7ZiM/H5LhAkbNcM8/xvoODjgfNAHEhkyyI4yEL5mstgwWA+J3Bf0SS40+tDU+7 N9ikUcNaLvA2IWal7UZUsg2+rOiJ0A/g8b6WCWlucj5LRv/vFTwX70YGK89jvx5B+bId 93Sm8LkTanpXKOl90Rm+0Gz6ekRjFqlQW5A6jvYiAViz/9Lpix2m9VsgONUbbe2s5CXI c5y9NartHaqWvzkKHl6/UIZGKeCbQGdh7hUSEVi4PbWxYNTtX/rBYRl+1+evWnrIYI8u yvLwB0wj6ND5okCP1TW0YLVNANMrfIRfXC+DEqEBC6Ax159TkX6Vn0oWaeOSHkALE58d 9/+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RlH4HZM0GOqehDVq13X1kPLT+UzzEP8AsxwqPXI0mFY=; b=5Fi29qONkuLeMCS8J8kBssTsS5pEz6SN5u8/E7I2rXfvznackLetPtNT3f3hh/Ue/B ZODz7lL2Msp0ss3xtbxOO0tTkqyfbkI+ISS9s/vW3VnXEjqajeFGI1HbQ+VsZB2meXZ9 u/3dsEKhoMhTxcLAwfVMd/Fa+GWpLIhvCJP4qxrND+TRZAyJ6c7t1LYjsqooGD2txo8p 0piHcByL3K7xLTpUDIOFKfZdSzqQ6h8LeInLKY00Bq+P0D1+eFjRo7pFB3WgZKx3+U1L +AabhlmulalA0JA6Rneg6wcHG7AMdkxHFqSXoZs5RnPQ4VG2e4PvfP3xurv0OBd1K4du FArQ== X-Gm-Message-State: AOAM532E90rIhJohurdZnDyzgr8aGPd3Ry7wHWt/a8o4rylnF0hpD52B uE1dyNE9uxtBHHdejitX7uh/b948JzV3JVAvCcG5TDbc X-Received: by 2002:a05:6512:b2a:b0:479:12f5:91ba with SMTP id w42-20020a0565120b2a00b0047912f591bamr5371166lfu.443.1654280402791; Fri, 03 Jun 2022 11:20:02 -0700 (PDT) MIME-Version: 1.0 References: <20220603055156.2830463-1-irogers@google.com> <495f2924138069abaf49269b2c3bd1e4f5f4362e.camel@perches.com> In-Reply-To: <495f2924138069abaf49269b2c3bd1e4f5f4362e.camel@perches.com> From: Andrii Nakryiko Date: Fri, 3 Jun 2022 11:19:51 -0700 Message-ID: Subject: Re: [PATCH v2] libbpf: Fix is_pow_of_2 To: Joe Perches Cc: Ian Rogers , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Networking , bpf , open list , Yuze Chi Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 3, 2022 at 9:58 AM Joe Perches wrote: > > On Thu, 2022-06-02 at 22:57 -0700, Ian Rogers wrote: > > On Thu, Jun 2, 2022 at 10:52 PM Ian Rogers wrote: > > > From: Yuze Chi > [] > > > diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h > [] > > > @@ -580,4 +580,9 @@ struct bpf_link * usdt_manager_attach_usdt(struct usdt_manager *man, > > > const char *usdt_provider, const char *usdt_name, > > > __u64 usdt_cookie); > > > > > > +static inline bool is_pow_of_2(size_t x) > > > +{ > > > + return x && (x & (x - 1)) == 0; > > > +} > > > + > > > #endif /* __LIBBPF_LIBBPF_INTERNAL_H */ > > If speed of execution is a potential issue, maybe: It's not, as it's not in any sort of high-frequency hot path. But even if it was, we should be careful with __builtin_popcount() because depending on target CPU architecture __builtin_popcount() can be turned into a helper function call instead of using hardware instruction. But either way, keeping it simple is prefereable. > > #if __has_builtin(__builtin_popcount) > return __builtin_popcount(x) == 1; > #else > return x && (x & (x-1)) == 0; > #endif >