Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5958486rwb; Wed, 7 Sep 2022 10:23:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR5oAU79GnfHFLK0FMP/QaS9Kau3TS0Lhcw60Imy+jnggdlqxzA19V7DfpfyyoxlXIzwURCG X-Received: by 2002:aa7:d150:0:b0:44e:3c06:d719 with SMTP id r16-20020aa7d150000000b0044e3c06d719mr4037246edo.265.1662571402736; Wed, 07 Sep 2022 10:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662571402; cv=none; d=google.com; s=arc-20160816; b=bBwH8BKjPdFiEac8GqNIdx0veu3DeV+05VVJb/P6BLKORfsk9W5HjQbgGyCwlERXrY OdU2rkvoEatWyEgRHJIanRf8S6GeN4MvSWbM42rDKgz7Yb4sBGdEHHZdRPGjB6jInS5J R9lU4KbeTikokvQz86+9bIu2LoTGS/i2i23LsorzYb8PTj5rO06Hkp+fv9w2Y2rQELnz qLSUvE4TPu053/RR8hH67ZUSPgI2Lu+hbv1qZzk0DIZrgeOfLaeoMWTulXVfAl1R/5GX EWeWoQzdFREE5jEPNE6wYVldaoIMt6EvK7A3cg8TYHdpo/+zi4KIlm42MCByMnv91vMM KPYA== 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=bzVsEFvOi3nSHTdMpS6nXLuMs4XDbeJqE6fT5/16cdo=; b=bGzxkkV+fkm9XiaKEaGr18NDt8og0zOwPliLE8mdV6W2Ig333joV+NMTqpWQrru/f0 KPH9ij2fCBXFekgzZZn2DnMQfrpB2COPQUTx3fhn3hL+zcPs+TbtXfP9NpwyBFCM5Ddv eyj9p+LS15xfTBsU4OnZWWnqxDMqP3ttRKuFYZKxXqQWIT9dtGM71nb6GUznuVXpLUrm QJkPTpxy4vo5QTvYiKaqNb+qiil/frmQmSCqnYNsU1bFSTeEY5hbiq6c1j5HW4to7Sts R4k0xo+g14lG7cI3AaoPhYp2GmurEQpnxsAl8yPhnSXKU2dy1q/sMA19N7EiPnCFzdmH 688Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=gAcmwcHd; 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 v6-20020a056402348600b0043c2919cfd3si3783029edc.602.2022.09.07.10.22.57; Wed, 07 Sep 2022 10:23:22 -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=gAcmwcHd; 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 S230042AbiIGQ54 (ORCPT + 99 others); Wed, 7 Sep 2022 12:57:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbiIGQ5l (ORCPT ); Wed, 7 Sep 2022 12:57:41 -0400 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8105CBD1E9 for ; Wed, 7 Sep 2022 09:57:33 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id j6so10929147qkl.10 for ; Wed, 07 Sep 2022 09:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=bzVsEFvOi3nSHTdMpS6nXLuMs4XDbeJqE6fT5/16cdo=; b=gAcmwcHdLlvOrAxJw+SJ83nMXkhFfWW3yMW+CEqGVi3z70+YfMOFt+WnV1AqSqCXtQ /deTP8FNJVVicypDwG/UhQ+pFp5oGTz/omH9WRSo23wdKx7HU+M1ekMZkj4dME4x4H12 tWWpzC2OUZDDr6jlAojqZ21XCXjPFAAjotsGqyfNUiLAxGPPGfgLLIRpH8H2h6zcQ2AO ANLRY7L5bH5WFOxjxXgcZDJHQYkc7ziXO2Dre0+vfWAENeaRkAek+wuXrcYBfXwqJtqV wcz5l79wI5Ki+FOvDXXeX5Qaab9mxVKiIbpIPYUAhacHTZLFuHhifMWpCVEhFIaMRpYO Fz7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=bzVsEFvOi3nSHTdMpS6nXLuMs4XDbeJqE6fT5/16cdo=; b=28z2VlKtZs9XE2nxiN8hiOnG2YLaBK9Ujwoqvn6Zezu5MSIxBpneoAxMNafINnbbpM QBwNm1k6fdnEYVdE50Id3xfqdkRFwNyJT5a8ZZZWohs3s1mplhTMqOuC0JJqFPsAWUUJ SGj6tAgWyZzqMz/12QQuLQKRykRMO0p1lZ98M8jczLVHwuUNSLsPQ4IO/wmlnWyLVbPN QAR6bBvQRiNM3X9iREPA34pEYNFe9qDsvzH8icS1GaKEAd6Wb/oGv7ceVUtA0ZIMzFss 0+azlwYeahTx5o6hEIKY3H328AiWe65zyvTJfSOWHzH9QAcCMBZZNp3Qant1lC6pmfa6 zd+g== X-Gm-Message-State: ACgBeo2oBFH58fxfLdoUeM/U32M4yzogBZD5OfsLcSJWnwc6SzFnuAyx +F/gDl5EKVGJxgjxkqO0+Uw= X-Received: by 2002:a05:620a:f13:b0:6bb:ebe9:d787 with SMTP id v19-20020a05620a0f1300b006bbebe9d787mr3284684qkl.663.1662569852024; Wed, 07 Sep 2022 09:57:32 -0700 (PDT) Received: from localhost ([2601:4c1:c100:2270:2bb2:71a4:3b6f:3d50]) by smtp.gmail.com with ESMTPSA id bs36-20020a05620a472400b006b9c6d590fasm13911534qkb.61.2022.09.07.09.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 09:57:31 -0700 (PDT) Date: Wed, 7 Sep 2022 09:57:30 -0700 From: Yury Norov To: Valentin Schneider Cc: Linus Torvalds , linux-kernel@vger.kernel.org, Alexey Klimov , Andy Shevchenko , Andy Whitcroft , Catalin Marinas , David Laight , Dennis Zhou , Guenter Roeck , Kees Cook , Rasmus Villemoes , Russell King Subject: Re: [PATCH v3 3/4] lib/find_bit: optimize find_next_bit() functions Message-ID: References: <20220827175807.4017673-1-yury.norov@gmail.com> <20220827175807.4017673-4-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Wed, Sep 07, 2022 at 05:27:08PM +0100, Valentin Schneider wrote: > On 27/08/22 10:58, Yury Norov wrote: > > +#define FIND_NEXT_BIT(FETCH, MUNGE, size, start) \ > > +({ \ > > + unsigned long mask, idx, tmp, sz = (size), __start = (start); \ > > + \ > > + if (unlikely(__start >= sz)) \ > > + goto out; \ > > + \ > > + mask = MUNGE(BITMAP_FIRST_WORD_MASK(__start)); \ > > + idx = __start / BITS_PER_LONG; \ > > + \ > > + for (tmp = (FETCH) & mask; !tmp; tmp = (FETCH)) { \ > > + if (idx > sz / BITS_PER_LONG) \ > > Does that want to be Yes, I already fixed this. > if (idx + 1 >= sz / BITS_PER_LONG) > > ? > > Consider this as used in _find_next_bit() for an all-zero 128-bit wide > bitmap (two ULL's), providing the memory contiguous to the bitmap is also > zero then this will only stop at idx=3, so that's fetching two ULLs too > far. > > > + goto out; \ > > + idx++; \ > > + } \ > > + \ > > + sz = min(idx * BITS_PER_LONG + __ffs(MUNGE(tmp)), sz); \ > > +out: \ > > + sz; \ > > +})