From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12E9B26B973 for ; Fri, 9 Jan 2026 18:59:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767985195; cv=none; b=S+GAjl/vg3Qrh2PUSRDub3KFiqH/rqtBG/i+IIZgg35IYxS2Ge2jsXLPxZ26he74s3vxVuVs1+GWNAFHg5s2LBXKJwKyec+BvA01xH18bdW4RrAwGGwi4izap19lVMDNRnGbvBwBG2qSOfGUJ4B3iRGHoNkCRmYq8yGp/HCk/8w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767985195; c=relaxed/simple; bh=uScdok5oKrrBPDUVpGiv5Gb4sK6LB8kL4EL+Z2nbhxI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XIW/JneDoQsJGZECLMxR4rvIvngMjNWTlwAlSK9s86B1u6fK87+ebqWtLlmbvkqJTwT655NNSTgpDi9o5+eyQaofsQkaOOEYOA3Ogg3xCjspBeQoN0L7Xsnls/AJPCmfFZoAAQTiW0WtLkeFTO4d0DR82g0XYZQWcZI2xTrcVe4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=SLZrIzp7; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="SLZrIzp7" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4775dbde730so4185675e9.3 for ; Fri, 09 Jan 2026 10:59:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1767985192; x=1768589992; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=nPBBWhSrHOb8/y2UC/73t03W3zCNIxhqStnSsstocTs=; b=SLZrIzp7BhYph4LjuJ6HZMLGo6EfvXqxOUCeHlRk3dEQ2oCfUw72NWQTkH0wkTZL9P NRnx5NC75EJlzFQM92x4i82w0rmIfldb+838W+ykEJ75lHQHSHM5rLDGADVss1e+malZ YAximW/eXjp/KgVkyLgSwZWs7I3lQAm7h3hebG0NjXD6QBNCXoQtBGx1BZaT/RRO4pHi KIHqJsPQGq3wrJZ/y1zEJvPpGsoFqPkq8xxVjrxWxFR8UeoNAGbOBvziTXn0yvJSwjUs aw3VS1GZ7nTscDh7ic+DRzsOvQ5RVlyVdfiXm0K84uqoMXR/Wq0m+E+7eqRnA7N7uFp3 YE/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767985192; x=1768589992; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nPBBWhSrHOb8/y2UC/73t03W3zCNIxhqStnSsstocTs=; b=vjS4C8YUzJu+9vq1DtOVFj12MLGXrw/5BEGd7B9RnznlBaFL+0bQkw2c+rWjEWYmRf HOjVFxCC3faZa1pjfaNFGYp/q0X27j9cpsj93UHX6bV462yUSnB4G2PTKjzAkMsxhQKy ESq8h0mT2q+yCXix69S6YPPw5XlJRg7vDyOSt4HUCpbpaEd0QTif0YITH64gY0//2Fge bRYLYwgZ17Z/kPkitswJ35DQK2VTSOVhw4vX0WAN4Eo+Wz5UQXdhfrDrezyl7xtTy/lg uRTdTg4A821DGgoOZBMNZMtBSyWSctx0+VdXZVJOgPL5oVzUVc90Zbpc3avC5g+72hyC SIpg== X-Forwarded-Encrypted: i=1; AJvYcCUP3Ypnu6YGckF7eeuBJlb972S7GG1+WQ1JkfPnJFiLn71avQMTw/mNr32pcUevfWNyu83EYwgpgyr3wWU=@vger.kernel.org X-Gm-Message-State: AOJu0YyuOIiQE440EwZggh2bmV2mUvj9xy6OEjJElOFqX5swos48uMKF GNxEDzvceUwbpFmbLxK4hmS+ydTccieeesk0dsLR5Hoj3Oao/mL98GXU0VP4s+d5Atw= X-Gm-Gg: AY/fxX69BQpr4hFeSZcllVz1rrD1a0jVNMBh6TJdMukwp/5wMly9Q9svBVdrEuECLDR Dng8ejeXBOs6pJ+p0zqI5n1bbMmA7+OGezWdCymqjvwPUhUL7sMJfwnyB37Pa4FohV2j0ZUHLku GvooYJvZEAOaST+EXi3t+mjNWMu+Q1ZUgsGUoPkt2/zdHNnvhSXIF3nExc/HK5sPvnqNnsHZmdH 64O3u1H5VyK+wd24HR7gjKYiiOq8LtdGx+L37kT4fzS0wvewyBQrEd56sANXOCA5IvH6ZuSzkaM Ko/cykPHTq2o//n6vVt+OZIiqowxwitRwuOgCou4DpeltaoF/+pJDptLU3Vj0XL19Gvb3jqvrbK 08bIOKT3j/zlRCTH2JcmM9F1OYkEKhBdqJRy+5/wcJH0VEB4+g4IvW1fEAaqe1YAzYdsk55F27q CZDUAdcHwBzkQcAGjh/mY6sAGtGBgXVuLbZTujC+zaYSM0e9FvtHkVv7q6Lh87kx7IqO8MO/X6X Wto X-Google-Smtp-Source: AGHT+IFnv0/umzCvB2jH1GFNCpbEzjxjcIrrVv2+1Ed18DgXhDBfP+apnNX39rpk9LJ/oIIcwvaiog== X-Received: by 2002:a05:600c:3b19:b0:477:7bd8:8f2d with SMTP id 5b1f17b1804b1-47d84b3faefmr78923875e9.8.1767985189922; Fri, 09 Jan 2026 10:59:49 -0800 (PST) Received: from mordecai (dynamic-2a00-1028-83b8-1e7a-3010-3bd6-8521-caf1.ipv6.o2.cz. [2a00:1028:83b8:1e7a:3010:3bd6:8521:caf1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47d871a1e11sm66191645e9.19.2026.01.09.10.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jan 2026 10:59:49 -0800 (PST) Date: Fri, 9 Jan 2026 19:59:46 +0100 From: Petr Tesarik To: Kuan-Wei Chiu Cc: Yury Norov , Rasmus Villemoes , Richard Henderson , Matt Turner , Magnus Lindholm , Vineet Gupta , Geert Uytterhoeven , "Maciej W. Rozycki" , Thomas Bogendoerfer , Madhavan Srinivasan , Michael Ellerman , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Chris Zankel , Max Filippov , Patrik Jakobsson , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Robin Murphy , Joerg Roedel , Will Deacon , Jakub Kicinski , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Oliver Neukum , Arnd Bergmann , Andrew Morton , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Pablo Neira Ayuso , Florian Westphal , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 0/2] Helper to isolate least-significant bit Message-ID: <20260109195946.551a2693@mordecai> In-Reply-To: References: X-Mailer: Claws Mail 4.3.1 (GTK 3.24.51; x86_64-suse-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 10 Jan 2026 01:20:59 +0800 Kuan-Wei Chiu wrote: > Hi Petr, > > On Fri, Jan 09, 2026 at 05:41:34PM +0100, Petr Tesarik wrote: > > Isolation of the least significant bit can be achieved with 3 basic > > ALU operations which are already open-coded in various places in the > > kernel. > > > > However, since other places less efficient constructs, for example > > `1UL << ffs(x)`, I assume the trick is known only to some authors, and > > it's worth adding a helper to promote its use. > > Just out of curiosity, are there any existing users employing 1 << > ffs(x) (or other inefficient variants) in performance-critical > hotpaths? > > From a quick grep, I only found one instance in drivers/clk/ti/mux.c > matching the 1 << ffs(x) pattern. However, this doesn't appear to be a > bottleneck since it is followed by ti_clk_ll_ops->clk_writel(...). The > latency of the MMIO write would likely overshadow the savings of a few > ALU cycles. Most expressions are a bit more complex, like this one in page_cache_async_ra(): align = 1UL << min(ra->order, ffs(max_pages) - 1); Or split across multiple lines, like this one in sata_down_spd_limit(): bit = ffs(mask) - 1; mask = 1 << bit; I agree that there is most likely no measurable performance win. The resulting machine code merely looks quite silly on architectures without an instruction to do ffs() and a little bit silly on architectures where the instruction has a slightly different semantics (bit position numbering and/or handling of zero value). > Additionally, it seems that patch #2 focuses on replacing the x & -x > implementation with the new API, rather than converting inefficient > constructs like 1 << ffs(x) to use ffs_val(). This is correct. This patch series merely introduces the helper. Patch 2/2 was created mechanically. I haven't sent any follow-up yet to replace inefficient use, because that would require more effort, and I'm trying to get some early feedback first (that's why the series is tagged RFC). If we agree that it's worth the effort, and I split the patches by subsystem, it may become a rather long series. Petr T