Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2653160rbb; Wed, 28 Feb 2024 08:23:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUBi0yqt8YEVjb7sKniMezThd+lILOD5xHSbvVz5zS+2ESizaUt9MBvqowJZ0aEJW4QwM8TBm29vpE8Yfj7jrQv5OU/nMABkq9sFdkdiQ== X-Google-Smtp-Source: AGHT+IGUsB1LpatEyGRlz+HhNJvkd6X2j3Q7hPjzLnLiqdAnVTf8/btjkPte1vzFynKSHg0jV5aS X-Received: by 2002:ac2:504c:0:b0:512:e00b:8da4 with SMTP id a12-20020ac2504c000000b00512e00b8da4mr119706lfm.53.1709137410326; Wed, 28 Feb 2024 08:23:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709137410; cv=pass; d=google.com; s=arc-20160816; b=avyDjm6g8pUYRqEnBlqLNTXZ/kdh2C+lLZ0ZdHFuld1o2Y6p0Z7DnsqZ0SV5+Phto+ DLjEGgfyrrNAN91aXsMBanwyfMLMe4pvYTTJZTZ/MIF6wqXcIpzepL2WOybwSCnq527F DPtt2FcB+YeTqtfnrfxkwQLRyb2pU8lSazFUeTtHJU5NCo6TMAKg4QpAp2xqKXUCB2wM /TozVlfavh/j06bdKdzOQ9uCR7nk+pDT5s7wZTyndsf90PB6ihI+ekkhMrGzhQKAeDtU sY9llhiTkNRtQDy4cWH4qcjsFjr43ZP/er7xTD3wBeTz54qbmwYJ60Mrcag+zC26x77F 2//Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HbOEijThNH46+MKcExlVA1bAK6/6kIlRSRkEOFZjgxo=; fh=cja32Mmb8sLHZdDhvqswTJ/Wpv4xigg6jMatsYlqzFQ=; b=LtLdLuQP2R2UyiDsZXTWAFS+SDU83BzmM3yXFXrQdILHbn13q9NztUZ+vcGC/TsE+m gQBXBqIKFtbsOyvrtVy1hUUPStXkJ1jHAIP9AFIUNXWHuqlitS7t6nn/KdJCeTcp+4c1 W+EeEBIEH1R3pZfZVWia//p+ue0Tq0tl/PoX5BAcWzELM2QK0OP4DfSTUv0/2r+AjWig HEfk9koJcZE6sNkJUZ2TDZE5J8tzfL2V60N8tty9Bg1RgtuipBvHm4EDNIf/6rG0Y6i3 gLxqgW3yKHY+h+fk8yeslofTR7puQZCRP11Mh12MbsfTJN8lLMSa9iUub1W6THr+zl6i U5Qg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eDgfBREh; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-85356-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85356-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gh11-20020a170906e08b00b00a440dc31068si483427ejb.657.2024.02.28.08.23.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 08:23:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85356-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eDgfBREh; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-85356-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85356-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E6B561F2390C for ; Wed, 28 Feb 2024 16:23:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3281A6EF13; Wed, 28 Feb 2024 16:23:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eDgfBREh" Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (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 CA0C320DD5; Wed, 28 Feb 2024 16:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709137393; cv=none; b=f2uPpJWRp+cVyrFnNjP+70pF2wbxWHOWFpzYD/dco2VCcMNEoD05fxEZttBLh5cQZr0Yx2on+g1zFuL/ORbaWNhKmPTyorMpuM1usaYNCUuhVnFSGU1Xez1kOz5lJ2s4UUAljapJAm8nkjPuh0h0yQbAFXHLs1kTwraVoqtP0sY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709137393; c=relaxed/simple; bh=aKP3XKivBDkL7DKrt74vUAYWeR8YG5sZXUYI3JgNld8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Z3UvC7i/YJFKEGfiabpOVnk9USsZEnQ7weD+5Oy50UUUggHQRRGd4FB1De5ZIxuBwIQTKj1vCSkAPXK5qq2VEi6YRqSjPHRG8rejKwW5VNsoP45ST9LADF9s+W871refMRBD+UDYH/b3K4o040Sxj+lzmabLTmeCITodJbQMrdI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eDgfBREh; arc=none smtp.client-ip=209.85.128.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-60925d20af0so23003627b3.2; Wed, 28 Feb 2024 08:23:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709137391; x=1709742191; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=HbOEijThNH46+MKcExlVA1bAK6/6kIlRSRkEOFZjgxo=; b=eDgfBREhJUB32VSCBwiB9bs6+sMMXnn41wdepPJ53stqXOS7i7BIYvrrmr3tPHvodg WGACZf2oI5zJv0qVu1fMlpA9qO/0cowy2PzudSkqIaLOxI01ZZymtxsUcfL+7anIk2+F zLiBQqa13jLvwTD5p/kKda9dQzgqdv08cr5gFz1SsrRPtmQihttrXNuPOr/Ss+NqIg2y 4oJpClzNZohC14sif75ggcFNCZzF3s5m6ZNpcohjLHnWJbF/qpGlcjabiLGEkjitINBi roU+uCncDYYVhSkoLF5HXGBW9MHQMAVyLMHPcGTx9ah4QggNpKF5MDzQaiXL9grB4cPs 0uKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709137391; x=1709742191; 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 :message-id:reply-to; bh=HbOEijThNH46+MKcExlVA1bAK6/6kIlRSRkEOFZjgxo=; b=YRvF6lHWJa3/urHc22BGM/XYTyvROevIKTBklfrUWLx/uOrMKK835dO3fzmPHIqzik NaeyGx4dCkgWX4kmheDcURZzKOZ8QbMbL51Z755tAam6fK3XaLvpRtnMdvkAVjVSHYth 5JW0FJn1hO198RPmgIA+LwoIXp9k6hgz8RNZT3fUUapZRdGqUMWdrjEBmOibY3ku1xgR hv5v4xHIF+FmLnAy7ah2ecg9/CPjGA9AIn+AlUw2juU1gsmLq66g419Krh/A8KS+yV5Q ytoDeZ3XTBZeJuwMfyFFOXxwOlaNvyTACa8N3tGHl9rsfztp878EhkEhgdtf5k/CMzjK EfXw== X-Forwarded-Encrypted: i=1; AJvYcCV5FyU0dAa61VOe3hvEXSsnoDoaCieBb7wvoC9rKcYEKPZ3E8T7PhlzzVcyXj05QlvZCeahDzqjfU7MAwNKK0q/jKfeZLrhBkHnwkT8DAf9Yu23yu/uih/vE0Cch3XksZ/FhEfDLwICR7Q0nOrP+UCFsDrpqfpFKj3obNb070NmO4Rlhr3M3lfZKFqA9888wIM8jZducyhyqIAJ6pQt X-Gm-Message-State: AOJu0YwfVfpJ/rChWYMVdhx/W0TkudIDXSP0mYGnB4u7A4MKwFNGubXD q/9uzauhha0lfiOOTfcQ9aW84JRo43ZUvh6O+Jlu2JukKuW81Cqh X-Received: by 2002:a81:4054:0:b0:609:205c:82b2 with SMTP id m20-20020a814054000000b00609205c82b2mr5476474ywn.0.1709137390676; Wed, 28 Feb 2024 08:23:10 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:2256:57ae:919c:373f]) by smtp.gmail.com with ESMTPSA id o15-20020a81de4f000000b00607fe5723e6sm2380884ywl.109.2024.02.28.08.23.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 08:23:10 -0800 (PST) Date: Wed, 28 Feb 2024 08:23:09 -0800 From: Yury Norov To: Alexander Lobakin Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Michal Swiatkowski , Marcin Szycik , Wojciech Drewek , Andy Shevchenko , Rasmus Villemoes , Alexander Potapenko , Jiri Pirko , Ido Schimmel , Przemek Kitszel , Simon Horman , linux-btrfs@vger.kernel.org, dm-devel@redhat.com, ntfs3@lists.linux.dev, linux-s390@vger.kernel.org, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko Subject: Re: [PATCH net-next v5 06/21] bitops: let the compiler optimize {__,}assign_bit() Message-ID: References: <20240201122216.2634007-1-aleksander.lobakin@intel.com> <20240201122216.2634007-7-aleksander.lobakin@intel.com> 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-Disposition: inline In-Reply-To: <20240201122216.2634007-7-aleksander.lobakin@intel.com> On Thu, Feb 01, 2024 at 01:22:01PM +0100, Alexander Lobakin wrote: > Since commit b03fc1173c0c ("bitops: let optimize out non-atomic bitops > on compile-time constants"), the compilers are able to expand inline > bitmap operations to compile-time initializers when possible. > However, during the round of replacement if-__set-else-__clear with > __assign_bit() as per Andy's advice, bloat-o-meter showed +1024 bytes > difference in object code size for one module (even one function), > where the pattern: > > DECLARE_BITMAP(foo) = { }; // on the stack, zeroed > > if (a) > __set_bit(const_bit_num, foo); > if (b) > __set_bit(another_const_bit_num, foo); > ... > > is heavily used, although there should be no difference: the bitmap is > zeroed, so the second half of __assign_bit() should be compiled-out as > a no-op. > I either missed the fact that __assign_bit() has bitmap pointer marked > as `volatile` (as we usually do for bitops) or was hoping that the > compilers would at least try to look past the `volatile` for > __always_inline functions. Anyhow, due to that attribute, the compilers > were always compiling the whole expression and no mentioned compile-time > optimizations were working. > > Convert __assign_bit() to a macro since it's a very simple if-else and > all of the checks are performed inside __set_bit() and __clear_bit(), > thus that wrapper has to be as transparent as possible. After that > change, despite it showing only -20 bytes change for vmlinux (due to > that it's still relatively unpopular), no drastic code size changes > happen when replacing if-set-else-clear for onstack bitmaps with > __assign_bit(), meaning the compiler now expands them to the actual > operations will all the expected optimizations. > > Atomic assign_bit() is less affected due to its nature, but let's > convert it to a macro as well to keep the code consistent and not > leave a place for possible suboptimal codegen. Moreover, with certain > kernel configuration it actually gives some saves (x86): > > do_ip_setsockopt 4154 4099 -55 > > Suggested-by: Yury Norov # assign_bit(), too > Cc: Andy Shevchenko > Reviewed-by: Przemek Kitszel > Signed-off-by: Alexander Lobakin Acked-by: Yury Norov