From: Nathan Chancellor <nathan@kernel.org>
To: Brian Norris <briannorris@chromium.org>
Cc: Yury Norov <yury.norov@gmail.com>,
linux-kernel@vger.kernel.org, Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Nick Desaulniers <ndesaulniers@google.com>,
llvm@lists.linux.dev, Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Kees Cook <kees@kernel.org>
Subject: Re: [PATCH v3 1/4] find: Switch from inline to __always_inline
Date: Fri, 2 Aug 2024 16:07:15 -0700 [thread overview]
Message-ID: <20240802230715.GA959572@thelio-3990X> (raw)
In-Reply-To: <20240719005127.2449328-1-briannorris@chromium.org>
Hi Brian,
On Thu, Jul 18, 2024 at 05:50:37PM -0700, Brian Norris wrote:
> From: Yury Norov <yury.norov@gmail.com>
>
> 'inline' keyword is only a recommendation for compiler. If it decides to
> not inline find_bit nodemask functions, the whole small_const_nbits()
> machinery doesn't work.
>
> This is how a standard GCC 11.3.0 does for my x86_64 build now. This patch
> replaces 'inline' directive with unconditional '__always_inline' to make
> sure that there's always a chance for compile-time optimization. It doesn't
> change size of kernel image, according to bloat-o-meter.
>
> [[ Brian: split out from:
> Subject: [PATCH 1/3] bitmap: switch from inline to __always_inline
> https://lore.kernel.org/all/20221027043810.350460-2-yury.norov@gmail.com/
> But rewritten, as there were too many conflicts. ]]
>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> Co-developed-by: Brian Norris <briannorris@chromium.org>
> Signed-off-by: Brian Norris <briannorris@chromium.org>
> Reviewed-by: Kees Cook <kees@kernel.org>
Sorry for taking some time to review this. Overall, this seems
reasonable, especially given the numbers that you provided in the third
patch. I would expect the compiler to be able to optimize better at some
callsites with this.
For the series:
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
> ---
>
> Changes in v3:
> - newly split out in v3
>
> include/linux/find.h | 50 ++++++++++++++++++++++----------------------
> 1 file changed, 25 insertions(+), 25 deletions(-)
>
> diff --git a/include/linux/find.h b/include/linux/find.h
> index 5dfca4225fef..68685714bc18 100644
> --- a/include/linux/find.h
> +++ b/include/linux/find.h
> @@ -52,7 +52,7 @@ unsigned long _find_next_bit_le(const unsigned long *addr, unsigned
> * Returns the bit number for the next set bit
> * If no bits are set, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
> unsigned long offset)
> {
> @@ -81,7 +81,7 @@ unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
> * Returns the bit number for the next set bit
> * If no bits are set, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_next_and_bit(const unsigned long *addr1,
> const unsigned long *addr2, unsigned long size,
> unsigned long offset)
> @@ -112,7 +112,7 @@ unsigned long find_next_and_bit(const unsigned long *addr1,
> * Returns the bit number for the next set bit
> * If no bits are set, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_next_andnot_bit(const unsigned long *addr1,
> const unsigned long *addr2, unsigned long size,
> unsigned long offset)
> @@ -142,7 +142,7 @@ unsigned long find_next_andnot_bit(const unsigned long *addr1,
> * Returns the bit number for the next set bit
> * If no bits are set, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_next_or_bit(const unsigned long *addr1,
> const unsigned long *addr2, unsigned long size,
> unsigned long offset)
> @@ -171,7 +171,7 @@ unsigned long find_next_or_bit(const unsigned long *addr1,
> * Returns the bit number of the next zero bit
> * If no bits are zero, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
> unsigned long offset)
> {
> @@ -198,7 +198,7 @@ unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
> * Returns the bit number of the first set bit.
> * If no bits are set, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_first_bit(const unsigned long *addr, unsigned long size)
> {
> if (small_const_nbits(size)) {
> @@ -224,7 +224,7 @@ unsigned long find_first_bit(const unsigned long *addr, unsigned long size)
> * Returns the bit number of the N'th set bit.
> * If no such, returns >= @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_nth_bit(const unsigned long *addr, unsigned long size, unsigned long n)
> {
> if (n >= size)
> @@ -249,7 +249,7 @@ unsigned long find_nth_bit(const unsigned long *addr, unsigned long size, unsign
> * Returns the bit number of the N'th set bit.
> * If no such, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_nth_and_bit(const unsigned long *addr1, const unsigned long *addr2,
> unsigned long size, unsigned long n)
> {
> @@ -276,7 +276,7 @@ unsigned long find_nth_and_bit(const unsigned long *addr1, const unsigned long *
> * Returns the bit number of the N'th set bit.
> * If no such, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_nth_andnot_bit(const unsigned long *addr1, const unsigned long *addr2,
> unsigned long size, unsigned long n)
> {
> @@ -332,7 +332,7 @@ unsigned long find_nth_and_andnot_bit(const unsigned long *addr1,
> * Returns the bit number for the next set bit
> * If no bits are set, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_first_and_bit(const unsigned long *addr1,
> const unsigned long *addr2,
> unsigned long size)
> @@ -357,7 +357,7 @@ unsigned long find_first_and_bit(const unsigned long *addr1,
> * Returns the bit number for the first set bit
> * If no bits are set, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_first_and_and_bit(const unsigned long *addr1,
> const unsigned long *addr2,
> const unsigned long *addr3,
> @@ -381,7 +381,7 @@ unsigned long find_first_and_and_bit(const unsigned long *addr1,
> * Returns the bit number of the first cleared bit.
> * If no bits are zero, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size)
> {
> if (small_const_nbits(size)) {
> @@ -402,7 +402,7 @@ unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size)
> *
> * Returns the bit number of the last set bit, or size.
> */
> -static inline
> +static __always_inline
> unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
> {
> if (small_const_nbits(size)) {
> @@ -425,7 +425,7 @@ unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
> * Returns the bit number for the next set bit, or first set bit up to @offset
> * If no bits are set, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_next_and_bit_wrap(const unsigned long *addr1,
> const unsigned long *addr2,
> unsigned long size, unsigned long offset)
> @@ -448,7 +448,7 @@ unsigned long find_next_and_bit_wrap(const unsigned long *addr1,
> * Returns the bit number for the next set bit, or first set bit up to @offset
> * If no bits are set, returns @size.
> */
> -static inline
> +static __always_inline
> unsigned long find_next_bit_wrap(const unsigned long *addr,
> unsigned long size, unsigned long offset)
> {
> @@ -465,7 +465,7 @@ unsigned long find_next_bit_wrap(const unsigned long *addr,
> * Helper for for_each_set_bit_wrap(). Make sure you're doing right thing
> * before using it alone.
> */
> -static inline
> +static __always_inline
> unsigned long __for_each_wrap(const unsigned long *bitmap, unsigned long size,
> unsigned long start, unsigned long n)
> {
> @@ -506,20 +506,20 @@ extern unsigned long find_next_clump8(unsigned long *clump,
>
> #if defined(__LITTLE_ENDIAN)
>
> -static inline unsigned long find_next_zero_bit_le(const void *addr,
> - unsigned long size, unsigned long offset)
> +static __always_inline
> +unsigned long find_next_zero_bit_le(const void *addr, unsigned long size, unsigned long offset)
> {
> return find_next_zero_bit(addr, size, offset);
> }
>
> -static inline unsigned long find_next_bit_le(const void *addr,
> - unsigned long size, unsigned long offset)
> +static __always_inline
> +unsigned long find_next_bit_le(const void *addr, unsigned long size, unsigned long offset)
> {
> return find_next_bit(addr, size, offset);
> }
>
> -static inline unsigned long find_first_zero_bit_le(const void *addr,
> - unsigned long size)
> +static __always_inline
> +unsigned long find_first_zero_bit_le(const void *addr, unsigned long size)
> {
> return find_first_zero_bit(addr, size);
> }
> @@ -527,7 +527,7 @@ static inline unsigned long find_first_zero_bit_le(const void *addr,
> #elif defined(__BIG_ENDIAN)
>
> #ifndef find_next_zero_bit_le
> -static inline
> +static __always_inline
> unsigned long find_next_zero_bit_le(const void *addr, unsigned
> long size, unsigned long offset)
> {
> @@ -546,7 +546,7 @@ unsigned long find_next_zero_bit_le(const void *addr, unsigned
> #endif
>
> #ifndef find_first_zero_bit_le
> -static inline
> +static __always_inline
> unsigned long find_first_zero_bit_le(const void *addr, unsigned long size)
> {
> if (small_const_nbits(size)) {
> @@ -560,7 +560,7 @@ unsigned long find_first_zero_bit_le(const void *addr, unsigned long size)
> #endif
>
> #ifndef find_next_bit_le
> -static inline
> +static __always_inline
> unsigned long find_next_bit_le(const void *addr, unsigned
> long size, unsigned long offset)
> {
> --
> 2.45.2.1089.g2a221341d9-goog
>
prev parent reply other threads:[~2024-08-02 23:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-19 0:50 [PATCH v3 1/4] find: Switch from inline to __always_inline Brian Norris
2024-07-19 0:50 ` [PATCH v3 2/4] bitmap: " Brian Norris
2024-07-19 0:50 ` [PATCH v3 3/4] cpumask: " Brian Norris
2024-08-02 21:19 ` Brian Norris
2024-08-03 13:21 ` Yury Norov
2024-07-19 0:50 ` [PATCH v3 4/4] nodemask: " Brian Norris
2024-08-02 23:07 ` Nathan Chancellor [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240802230715.GA959572@thelio-3990X \
--to=nathan@kernel.org \
--cc=briannorris@chromium.org \
--cc=justinstitt@google.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=ndesaulniers@google.com \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox