public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 1/4] bitops: Introduce assign_bit()
       [not found]   ` <1503332323.2571.5.camel@wdc.com>
@ 2017-08-22  8:30     ` Lukas Wunner
  2017-08-22  9:27       ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Lukas Wunner @ 2017-08-22  8:30 UTC (permalink / raw)
  To: Bart Van Assche, Andrew Morton, Neil Brown, Peter Zijlstra,
	Ingo Molnar, Theodore Ts'o, Borislav Petkov, H. Peter Anvin,
	Denys Vlasenko
  Cc: linus.walleij@linaro.org, agk@redhat.com, phil@raspberrypi.org,
	linux-gpio@vger.kernel.org, m.duckeck@kunbus.de,
	snitzer@redhat.com, linux-kernel

On Mon, Aug 21, 2017 at 04:18:44PM +0000, Bart Van Assche wrote:
> On Mon, 2017-08-21 at 15:12 +0200, Lukas Wunner wrote:
> > Cc: Bart Van Assche <bart.vanassche@wdc.com>
> > Cc: Alasdair Kergon <agk@redhat.com>
> > Cc: Mike Snitzer <snitzer@redhat.com>
> > Signed-off-by: Lukas Wunner <lukas@wunner.de>
> 
> This Cc-list is incomplete. Previous <linux/bitops.h> patches went in
> through Andrew Morton's tree so I think an ack from Andrew Morton is
> needed before this patch can be sent to Linus Torvalds. Please also
> Cc other frequent contributors to this header file, e.g. Ingo Molnar
> and Peter Zijlstra. Please also consider to Cc the LKML for this patch
> or even for the entire series.

Fair enough, adding more folks to cc.  Does anyone have objections
or comments to the below patch and to merging it through linux-gpio?

It's part of this series:
https://www.spinics.net/lists/linux-gpio/msg25067.html

Looking at the mnemonics of x86 and arm I couldn't find one which
would avoid the jump and be faster/shorter than the inline functions
below, so putting this in include/linux/bitops.h (rather than
arch/*/include/asm/) seemed appropriate.  Can anyone imagine
doing the same quicker with inline assembly?


> > +static __always_inline void assign_bit(bool value, long nr,
> > +				       volatile unsigned long *addr)
>
> Why has __always_inline been specified? What makes you think that you know
> better than the compiler whether or not these functions should be inlined?

I carried this over from existing functions, see e.g. commit 1a1d48a4a8fd
("linux/bitmap: Force inlining of bitmap weight functions").

Thanks,

Lukas

-- >8 --
Subject: [PATCH 1/4] bitops: Introduce assign_bit()

A common idiom is to assign a value to a bit with:

    if (value)
        set_bit(nr, addr);
    else
        clear_bit(nr, addr);

Likewise common is the one-line expression variant:

    value ? set_bit(nr, addr) : clear_bit(nr, addr);

Commit 9a8ac3ae682e ("dm mpath: cleanup QUEUE_IF_NO_PATH bit
manipulation by introducing assign_bit()") introduced assign_bit()
to the md subsystem for brevity.

Make it available to others, in particular gpiolib and the upcoming
driver for Maxim MAX3191x industrial serializer chips.

Cc: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Alasdair Kergon <agk@redhat.com>
Cc: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
---
 drivers/md/dm-mpath.c  |  8 --------
 include/linux/bitops.h | 24 ++++++++++++++++++++++++
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 0e8ab5bb3575..c79c113b7e7d 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -638,14 +638,6 @@ static void process_queued_bios(struct work_struct *work)
 	blk_finish_plug(&plug);
 }
 
-static void assign_bit(bool value, long nr, unsigned long *addr)
-{
-	if (value)
-		set_bit(nr, addr);
-	else
-		clear_bit(nr, addr);
-}
-
 /*
  * If we run out of usable paths, should we queue I/O or error it?
  */
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index a83c822c35c2..097af36887c0 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -226,6 +226,30 @@ static inline unsigned long __ffs64(u64 word)
 	return __ffs((unsigned long)word);
 }
 
+/**
+ * assign_bit - Assign value to a bit in memory
+ * @value: the value to assign
+ * @nr: the bit to set
+ * @addr: the address to start counting from
+ */
+static __always_inline void assign_bit(bool value, long nr,
+				       volatile unsigned long *addr)
+{
+	if (value)
+		set_bit(nr, addr);
+	else
+		clear_bit(nr, addr);
+}
+
+static __always_inline void __assign_bit(bool value, long nr,
+					 volatile unsigned long *addr)
+{
+	if (value)
+		__set_bit(nr, addr);
+	else
+		__clear_bit(nr, addr);
+}
+
 #ifdef __KERNEL__
 
 #ifndef set_mask_bits
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/4] bitops: Introduce assign_bit()
  2017-08-22  8:30     ` [PATCH 1/4] bitops: Introduce assign_bit() Lukas Wunner
@ 2017-08-22  9:27       ` Peter Zijlstra
  2017-08-22 10:04         ` Lukas Wunner
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2017-08-22  9:27 UTC (permalink / raw)
  To: Lukas Wunner
  Cc: Bart Van Assche, Andrew Morton, Neil Brown, Ingo Molnar,
	Theodore Ts'o, Borislav Petkov, H. Peter Anvin,
	Denys Vlasenko, linus.walleij@linaro.org, agk@redhat.com,
	phil@raspberrypi.org, linux-gpio@vger.kernel.org,
	m.duckeck@kunbus.de, snitzer@redhat.com, linux-kernel

On Tue, Aug 22, 2017 at 10:30:50AM +0200, Lukas Wunner wrote:
> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> index a83c822c35c2..097af36887c0 100644
> --- a/include/linux/bitops.h
> +++ b/include/linux/bitops.h
> @@ -226,6 +226,30 @@ static inline unsigned long __ffs64(u64 word)
>  	return __ffs((unsigned long)word);
>  }
>  
> +/**
> + * assign_bit - Assign value to a bit in memory
> + * @value: the value to assign
> + * @nr: the bit to set
> + * @addr: the address to start counting from
> + */
> +static __always_inline void assign_bit(bool value, long nr,
> +				       volatile unsigned long *addr)
> +{
> +	if (value)
> +		set_bit(nr, addr);
> +	else
> +		clear_bit(nr, addr);
> +}
> +
> +static __always_inline void __assign_bit(bool value, long nr,
> +					 volatile unsigned long *addr)
> +{
> +	if (value)
> +		__set_bit(nr, addr);
> +	else
> +		__clear_bit(nr, addr);
> +}
> +

I dislike the argument order, in C you naturally write: dst = src. So I
would have expected:

	assign_bit(nr, addr, val);

but we have quite a few of these backwards functions in the kernel (like
most of the atomic_t family) and I didn't check to see if the existing
bitops are part of that 'tradition'.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/4] bitops: Introduce assign_bit()
  2017-08-22  9:27       ` Peter Zijlstra
@ 2017-08-22 10:04         ` Lukas Wunner
  0 siblings, 0 replies; 3+ messages in thread
From: Lukas Wunner @ 2017-08-22 10:04 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Bart Van Assche, Andrew Morton, Neil Brown, Ingo Molnar,
	Theodore Ts'o, Borislav Petkov, H. Peter Anvin,
	Denys Vlasenko, linus.walleij@linaro.org, agk@redhat.com,
	phil@raspberrypi.org, linux-gpio@vger.kernel.org,
	m.duckeck@kunbus.de, snitzer@redhat.com, linux-kernel

On Tue, Aug 22, 2017 at 11:27:31AM +0200, Peter Zijlstra wrote:
> On Tue, Aug 22, 2017 at 10:30:50AM +0200, Lukas Wunner wrote:
> > diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> > index a83c822c35c2..097af36887c0 100644
> > --- a/include/linux/bitops.h
> > +++ b/include/linux/bitops.h
> > @@ -226,6 +226,30 @@ static inline unsigned long __ffs64(u64 word)
> >  	return __ffs((unsigned long)word);
> >  }
> >  
> > +/**
> > + * assign_bit - Assign value to a bit in memory
> > + * @value: the value to assign
> > + * @nr: the bit to set
> > + * @addr: the address to start counting from
> > + */
> > +static __always_inline void assign_bit(bool value, long nr,
> > +				       volatile unsigned long *addr)
> > +{
> > +	if (value)
> > +		set_bit(nr, addr);
> > +	else
> > +		clear_bit(nr, addr);
> > +}
> > +
> > +static __always_inline void __assign_bit(bool value, long nr,
> > +					 volatile unsigned long *addr)
> > +{
> > +	if (value)
> > +		__set_bit(nr, addr);
> > +	else
> > +		__clear_bit(nr, addr);
> > +}
> > +
> 
> I dislike the argument order, in C you naturally write: dst = src. So I
> would have expected:
> 
> 	assign_bit(nr, addr, val);
> 
> but we have quite a few of these backwards functions in the kernel (like
> most of the atomic_t family) and I didn't check to see if the existing
> bitops are part of that 'tradition'.

The functions in include/linux/bitmap.h do follow the dst-then-src
pattern.  I carried over the argument order from Bart's function
to minimize the impact on the md subsystem, but will be happy to
respin with the order you're suggesting.  Will wait a bit though
to see if there are further comments.

Thanks,

Lukas

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-08-22 10:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1503319573.git.lukas@wunner.de>
     [not found] ` <5487a5f7d1a4be1bb13e7d1f392281d18c0e935e.1503319573.git.lukas@wunner.de>
     [not found]   ` <1503332323.2571.5.camel@wdc.com>
2017-08-22  8:30     ` [PATCH 1/4] bitops: Introduce assign_bit() Lukas Wunner
2017-08-22  9:27       ` Peter Zijlstra
2017-08-22 10:04         ` Lukas Wunner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox