2018-07-06 09:46:32

by Chris Wilson

[permalink] [raw]
Subject: [PATCH] bitops: Introduce BITS_PER_TYPE

net_dim.h has a rather useful extension to BITS_PER_BYTE to compute the
number of bits in a type (BITS_PER_BYTE * sizeof(T)), so promote the
macro to bitops.h, alongside BITS_PER_BYTE, for wider usage.

Signed-off-by: Chris Wilson <[email protected]>
Cc: Jani Nikula <[email protected]>
Cc: Andy Gospodarek <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Ingo Molnar <[email protected]>
---
include/linux/bitops.h | 3 ++-
include/linux/net_dim.h | 1 -
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 4cac4e1a72ff..091cb17d1a9b 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -11,7 +11,8 @@
#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
#define BITS_PER_BYTE 8
-#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
+#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
+#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
#endif

/*
diff --git a/include/linux/net_dim.h b/include/linux/net_dim.h
index 29ed8fd6379a..14f1734e740a 100644
--- a/include/linux/net_dim.h
+++ b/include/linux/net_dim.h
@@ -326,7 +326,6 @@ static inline void net_dim_sample(u16 event_ctr,
}

#define NET_DIM_NEVENTS 64
-#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
#define BIT_GAP(bits, end, start) ((((end) - (start)) + BIT_ULL(bits)) & (BIT_ULL(bits) - 1))

static inline void net_dim_calc_stats(struct net_dim_sample *start,
--
2.18.0



2018-07-06 10:06:51

by Jani Nikula

[permalink] [raw]
Subject: Re: [PATCH] bitops: Introduce BITS_PER_TYPE

On Fri, 06 Jul 2018, Chris Wilson <[email protected]> wrote:
> net_dim.h has a rather useful extension to BITS_PER_BYTE to compute the
> number of bits in a type (BITS_PER_BYTE * sizeof(T)), so promote the
> macro to bitops.h, alongside BITS_PER_BYTE, for wider usage.
>
> Signed-off-by: Chris Wilson <[email protected]>
> Cc: Jani Nikula <[email protected]>
> Cc: Andy Gospodarek <[email protected]>
> Cc: David S. Miller <[email protected]>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Ingo Molnar <[email protected]>

Reviewed-by: Jani Nikula <[email protected]>

> ---
> include/linux/bitops.h | 3 ++-
> include/linux/net_dim.h | 1 -
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> index 4cac4e1a72ff..091cb17d1a9b 100644
> --- a/include/linux/bitops.h
> +++ b/include/linux/bitops.h
> @@ -11,7 +11,8 @@
> #define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
> #define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
> #define BITS_PER_BYTE 8
> -#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
> +#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
> +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
> #endif
>
> /*
> diff --git a/include/linux/net_dim.h b/include/linux/net_dim.h
> index 29ed8fd6379a..14f1734e740a 100644
> --- a/include/linux/net_dim.h
> +++ b/include/linux/net_dim.h
> @@ -326,7 +326,6 @@ static inline void net_dim_sample(u16 event_ctr,
> }
>
> #define NET_DIM_NEVENTS 64
> -#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
> #define BIT_GAP(bits, end, start) ((((end) - (start)) + BIT_ULL(bits)) & (BIT_ULL(bits) - 1))
>
> static inline void net_dim_calc_stats(struct net_dim_sample *start,

--
Jani Nikula, Intel Open Source Graphics Center

2018-07-06 17:50:44

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] bitops: Introduce BITS_PER_TYPE

On 07/06/18 02:44, Chris Wilson wrote:
> net_dim.h has a rather useful extension to BITS_PER_BYTE to compute the
> number of bits in a type (BITS_PER_BYTE * sizeof(T)), so promote the
> macro to bitops.h, alongside BITS_PER_BYTE, for wider usage.
>
> Signed-off-by: Chris Wilson <[email protected]>
> Cc: Jani Nikula <[email protected]>
> Cc: Andy Gospodarek <[email protected]>
> Cc: David S. Miller <[email protected]>
> Cc: Thomas Gleixner <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> ---
> include/linux/bitops.h | 3 ++-
> include/linux/net_dim.h | 1 -
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> index 4cac4e1a72ff..091cb17d1a9b 100644
> --- a/include/linux/bitops.h
> +++ b/include/linux/bitops.h
> @@ -11,7 +11,8 @@
> #define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
> #define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
> #define BITS_PER_BYTE 8
> -#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
> +#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
> +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
> #endif
>
> /*

doesn't <linux/net_dim.h> need to #include <linux/bitops.h> ?


> diff --git a/include/linux/net_dim.h b/include/linux/net_dim.h
> index 29ed8fd6379a..14f1734e740a 100644
> --- a/include/linux/net_dim.h
> +++ b/include/linux/net_dim.h
> @@ -326,7 +326,6 @@ static inline void net_dim_sample(u16 event_ctr,
> }
>
> #define NET_DIM_NEVENTS 64
> -#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
> #define BIT_GAP(bits, end, start) ((((end) - (start)) + BIT_ULL(bits)) & (BIT_ULL(bits) - 1))
>
> static inline void net_dim_calc_stats(struct net_dim_sample *start,
>


--
~Randy

2018-07-06 17:53:45

by Chris Wilson

[permalink] [raw]
Subject: Re: [PATCH] bitops: Introduce BITS_PER_TYPE

Quoting Randy Dunlap (2018-07-06 18:48:55)
>
> On 07/06/18 02:44, Chris Wilson wrote:
> > net_dim.h has a rather useful extension to BITS_PER_BYTE to compute the
> > number of bits in a type (BITS_PER_BYTE * sizeof(T)), so promote the
> > macro to bitops.h, alongside BITS_PER_BYTE, for wider usage.
> >
> > Signed-off-by: Chris Wilson <[email protected]>
> > Cc: Jani Nikula <[email protected]>
> > Cc: Andy Gospodarek <[email protected]>
> > Cc: David S. Miller <[email protected]>
> > Cc: Thomas Gleixner <[email protected]>
> > Cc: Andrew Morton <[email protected]>
> > Cc: Ingo Molnar <[email protected]>
> > ---
> > include/linux/bitops.h | 3 ++-
> > include/linux/net_dim.h | 1 -
> > 2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> > index 4cac4e1a72ff..091cb17d1a9b 100644
> > --- a/include/linux/bitops.h
> > +++ b/include/linux/bitops.h
> > @@ -11,7 +11,8 @@
> > #define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
> > #define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
> > #define BITS_PER_BYTE 8
> > -#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
> > +#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
> > +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
> > #endif
> >
> > /*
>
> doesn't <linux/net_dim.h> need to #include <linux/bitops.h> ?

It already has to in order to obtain BITS_PER_BYTE. Just doesn't do so
directly.
-Chris

2018-07-06 17:58:00

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] bitops: Introduce BITS_PER_TYPE

On 07/06/18 10:51, Chris Wilson wrote:
> Quoting Randy Dunlap (2018-07-06 18:48:55)
>>
>> On 07/06/18 02:44, Chris Wilson wrote:
>>> net_dim.h has a rather useful extension to BITS_PER_BYTE to compute the
>>> number of bits in a type (BITS_PER_BYTE * sizeof(T)), so promote the
>>> macro to bitops.h, alongside BITS_PER_BYTE, for wider usage.
>>>
>>> Signed-off-by: Chris Wilson <[email protected]>
>>> Cc: Jani Nikula <[email protected]>
>>> Cc: Andy Gospodarek <[email protected]>
>>> Cc: David S. Miller <[email protected]>
>>> Cc: Thomas Gleixner <[email protected]>
>>> Cc: Andrew Morton <[email protected]>
>>> Cc: Ingo Molnar <[email protected]>
>>> ---
>>> include/linux/bitops.h | 3 ++-
>>> include/linux/net_dim.h | 1 -
>>> 2 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
>>> index 4cac4e1a72ff..091cb17d1a9b 100644
>>> --- a/include/linux/bitops.h
>>> +++ b/include/linux/bitops.h
>>> @@ -11,7 +11,8 @@
>>> #define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
>>> #define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
>>> #define BITS_PER_BYTE 8
>>> -#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
>>> +#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
>>> +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
>>> #endif
>>>
>>> /*
>>
>> doesn't <linux/net_dim.h> need to #include <linux/bitops.h> ?
>
> It already has to in order to obtain BITS_PER_BYTE. Just doesn't do so
> directly.

Right. and does that work on all $ARCHes?

Please see Documentation/process/submit-checklist.rst, rule #1:
1) If you use a facility then #include the file that defines/declares
that facility. Don't depend on other header files pulling in ones
that you use.


thanks,
--
~Randy

2018-07-06 18:01:40

by Chris Wilson

[permalink] [raw]
Subject: Re: [PATCH] bitops: Introduce BITS_PER_TYPE

Quoting Randy Dunlap (2018-07-06 18:55:57)
> On 07/06/18 10:51, Chris Wilson wrote:
> > Quoting Randy Dunlap (2018-07-06 18:48:55)
> >>
> >> On 07/06/18 02:44, Chris Wilson wrote:
> >>> net_dim.h has a rather useful extension to BITS_PER_BYTE to compute the
> >>> number of bits in a type (BITS_PER_BYTE * sizeof(T)), so promote the
> >>> macro to bitops.h, alongside BITS_PER_BYTE, for wider usage.
> >>>
> >>> Signed-off-by: Chris Wilson <[email protected]>
> >>> Cc: Jani Nikula <[email protected]>
> >>> Cc: Andy Gospodarek <[email protected]>
> >>> Cc: David S. Miller <[email protected]>
> >>> Cc: Thomas Gleixner <[email protected]>
> >>> Cc: Andrew Morton <[email protected]>
> >>> Cc: Ingo Molnar <[email protected]>
> >>> ---
> >>> include/linux/bitops.h | 3 ++-
> >>> include/linux/net_dim.h | 1 -
> >>> 2 files changed, 2 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
> >>> index 4cac4e1a72ff..091cb17d1a9b 100644
> >>> --- a/include/linux/bitops.h
> >>> +++ b/include/linux/bitops.h
> >>> @@ -11,7 +11,8 @@
> >>> #define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
> >>> #define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
> >>> #define BITS_PER_BYTE 8
> >>> -#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
> >>> +#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
> >>> +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
> >>> #endif
> >>>
> >>> /*
> >>
> >> doesn't <linux/net_dim.h> need to #include <linux/bitops.h> ?
> >
> > It already has to in order to obtain BITS_PER_BYTE. Just doesn't do so
> > directly.
>
> Right. and does that work on all $ARCHes?

It's a pre-existing dependency in the header, net_dim.h cannot
compile unless BITS_PER_BYTE is defined i.e. bitops.h is included.
The patch does not affect that.
-Chris

2018-07-06 18:39:07

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] bitops: Introduce BITS_PER_TYPE

On 07/06/18 11:00, Chris Wilson wrote:
> Quoting Randy Dunlap (2018-07-06 18:55:57)
>> On 07/06/18 10:51, Chris Wilson wrote:
>>> Quoting Randy Dunlap (2018-07-06 18:48:55)
>>>>
>>>> On 07/06/18 02:44, Chris Wilson wrote:
>>>>> net_dim.h has a rather useful extension to BITS_PER_BYTE to compute the
>>>>> number of bits in a type (BITS_PER_BYTE * sizeof(T)), so promote the
>>>>> macro to bitops.h, alongside BITS_PER_BYTE, for wider usage.
>>>>>
>>>>> Signed-off-by: Chris Wilson <[email protected]>
>>>>> Cc: Jani Nikula <[email protected]>
>>>>> Cc: Andy Gospodarek <[email protected]>
>>>>> Cc: David S. Miller <[email protected]>
>>>>> Cc: Thomas Gleixner <[email protected]>
>>>>> Cc: Andrew Morton <[email protected]>
>>>>> Cc: Ingo Molnar <[email protected]>
>>>>> ---
>>>>> include/linux/bitops.h | 3 ++-
>>>>> include/linux/net_dim.h | 1 -
>>>>> 2 files changed, 2 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
>>>>> index 4cac4e1a72ff..091cb17d1a9b 100644
>>>>> --- a/include/linux/bitops.h
>>>>> +++ b/include/linux/bitops.h
>>>>> @@ -11,7 +11,8 @@
>>>>> #define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
>>>>> #define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
>>>>> #define BITS_PER_BYTE 8
>>>>> -#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
>>>>> +#define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
>>>>> +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
>>>>> #endif
>>>>>
>>>>> /*
>>>>
>>>> doesn't <linux/net_dim.h> need to #include <linux/bitops.h> ?
>>>
>>> It already has to in order to obtain BITS_PER_BYTE. Just doesn't do so
>>> directly.
>>
>> Right. and does that work on all $ARCHes?
>
> It's a pre-existing dependency in the header, net_dim.h cannot
> compile unless BITS_PER_BYTE is defined i.e. bitops.h is included.
> The patch does not affect that.

Yes, I see. net_dim.h should have #included bits.h and/or bitops.h previously.

thanks,
--
~Randy

2018-07-06 21:59:47

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] bitops: Introduce BITS_PER_TYPE

On Fri, 6 Jul 2018 10:44:58 +0100 Chris Wilson <[email protected]> wrote:

> net_dim.h has a rather useful extension to BITS_PER_BYTE to compute the
> number of bits in a type (BITS_PER_BYTE * sizeof(T)), so promote the
> macro to bitops.h, alongside BITS_PER_BYTE, for wider usage.

A bit of grepping shows that there's quite a lot of code which does
sizeof(blah)*BITS_PER_BYTE. Fun newbie project.