xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long
@ 2020-12-09 15:54 Olaf Hering
  2020-12-09 15:54 ` [PATCH v1 2/3] tools: remove unused ORDER_LONG Olaf Hering
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Olaf Hering @ 2020-12-09 15:54 UTC (permalink / raw)
  To: xen-devel; +Cc: Olaf Hering, Ian Jackson, Wei Liu

Allocate enough memory so that the returned pointer can be safely
accessed as an array of unsigned long.

The actual bitmap size in units of bytes, as returned by bitmap_size,
remains unchanged.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 tools/libs/ctrl/xc_bitops.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h
index 3d3a09772a..d6c5ea5138 100644
--- a/tools/libs/ctrl/xc_bitops.h
+++ b/tools/libs/ctrl/xc_bitops.h
@@ -21,7 +21,10 @@ static inline unsigned long bitmap_size(unsigned long nr_bits)
 
 static inline void *bitmap_alloc(unsigned long nr_bits)
 {
-    return calloc(1, bitmap_size(nr_bits));
+    unsigned long longs;
+
+    longs = (nr_bits + BITS_PER_LONG - 1) / BITS_PER_LONG;
+    return calloc(longs, sizeof(unsigned long));
 }
 
 static inline void bitmap_set(void *addr, unsigned long nr_bits)


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

* [PATCH v1 2/3] tools: remove unused ORDER_LONG
  2020-12-09 15:54 [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long Olaf Hering
@ 2020-12-09 15:54 ` Olaf Hering
  2020-12-15 16:20   ` Wei Liu
  2020-12-09 15:54 ` [PATCH v1 3/3] tools: add API to work with sevaral bits at once Olaf Hering
  2020-12-15 16:11 ` [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long Wei Liu
  2 siblings, 1 reply; 8+ messages in thread
From: Olaf Hering @ 2020-12-09 15:54 UTC (permalink / raw)
  To: xen-devel; +Cc: Olaf Hering, Ian Jackson, Wei Liu

There are no users left, xenpaging has its own variant.
The last user was removed with commit 11d0044a168994de85b9b328452292852aedc871

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 tools/libs/ctrl/xc_bitops.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h
index d6c5ea5138..f0bac4a071 100644
--- a/tools/libs/ctrl/xc_bitops.h
+++ b/tools/libs/ctrl/xc_bitops.h
@@ -6,9 +6,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-/* Needed by several includees, but no longer used for bitops. */
 #define BITS_PER_LONG (sizeof(unsigned long) * 8)
-#define ORDER_LONG (sizeof(unsigned long) == 4 ? 5 : 6)
 
 #define BITMAP_ENTRY(_nr,_bmap) ((_bmap))[(_nr) / 8]
 #define BITMAP_SHIFT(_nr) ((_nr) % 8)


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

* [PATCH v1 3/3] tools: add API to work with sevaral bits at once
  2020-12-09 15:54 [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long Olaf Hering
  2020-12-09 15:54 ` [PATCH v1 2/3] tools: remove unused ORDER_LONG Olaf Hering
@ 2020-12-09 15:54 ` Olaf Hering
  2020-12-15 16:22   ` Wei Liu
  2020-12-15 16:11 ` [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long Wei Liu
  2 siblings, 1 reply; 8+ messages in thread
From: Olaf Hering @ 2020-12-09 15:54 UTC (permalink / raw)
  To: xen-devel; +Cc: Olaf Hering, Ian Jackson, Wei Liu

Introduce new API to test if a fixed number of bits is clear or set,
and clear or set them all at once.

The caller has to make sure the input bitnumber is a multiply of BITS_PER_LONG.

This API avoids the loop over each bit in a known range just to see
if all of them are either clear or set.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 tools/libs/ctrl/xc_bitops.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h
index f0bac4a071..92f38872fb 100644
--- a/tools/libs/ctrl/xc_bitops.h
+++ b/tools/libs/ctrl/xc_bitops.h
@@ -77,4 +77,29 @@ static inline void bitmap_or(void *_dst, const void *_other,
         dst[i] |= other[i];
 }
 
+static inline int test_bit_long_set(unsigned long nr_base, const void *_addr)
+{
+    const unsigned long *addr = _addr;
+    unsigned long val = addr[nr_base / BITS_PER_LONG];
+    return val == ~0;
+}
+
+static inline int test_bit_long_clear(unsigned long nr_base, const void *_addr)
+{
+    const unsigned long *addr = _addr;
+    unsigned long val = addr[nr_base / BITS_PER_LONG];
+    return val == 0;
+}
+
+static inline void clear_bit_long(unsigned long nr_base, void *_addr)
+{
+    unsigned long *addr = _addr;
+    addr[nr_base / BITS_PER_LONG] = 0;
+}
+
+static inline void set_bit_long(unsigned long nr_base, void *_addr)
+{
+    unsigned long *addr = _addr;
+    addr[nr_base / BITS_PER_LONG] = ~0;
+}
 #endif  /* XC_BITOPS_H */


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

* Re: [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long
  2020-12-09 15:54 [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long Olaf Hering
  2020-12-09 15:54 ` [PATCH v1 2/3] tools: remove unused ORDER_LONG Olaf Hering
  2020-12-09 15:54 ` [PATCH v1 3/3] tools: add API to work with sevaral bits at once Olaf Hering
@ 2020-12-15 16:11 ` Wei Liu
  2 siblings, 0 replies; 8+ messages in thread
From: Wei Liu @ 2020-12-15 16:11 UTC (permalink / raw)
  To: Olaf Hering; +Cc: xen-devel, Ian Jackson, Wei Liu

On Wed, Dec 09, 2020 at 04:54:49PM +0100, Olaf Hering wrote:
> Allocate enough memory so that the returned pointer can be safely
> accessed as an array of unsigned long.
> 
> The actual bitmap size in units of bytes, as returned by bitmap_size,
> remains unchanged.
> 
> Signed-off-by: Olaf Hering <olaf@aepfle.de>

Acked-by: Wei Liu <wl@xen.org>

I can see where you're coming from. This (internal) API's returned
pointer is being assigned to unsigned long *.

> ---
>  tools/libs/ctrl/xc_bitops.h | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h
> index 3d3a09772a..d6c5ea5138 100644
> --- a/tools/libs/ctrl/xc_bitops.h
> +++ b/tools/libs/ctrl/xc_bitops.h
> @@ -21,7 +21,10 @@ static inline unsigned long bitmap_size(unsigned long nr_bits)
>  
>  static inline void *bitmap_alloc(unsigned long nr_bits)
>  {
> -    return calloc(1, bitmap_size(nr_bits));
> +    unsigned long longs;
> +
> +    longs = (nr_bits + BITS_PER_LONG - 1) / BITS_PER_LONG;
> +    return calloc(longs, sizeof(unsigned long));
>  }
>  
>  static inline void bitmap_set(void *addr, unsigned long nr_bits)


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

* Re: [PATCH v1 2/3] tools: remove unused ORDER_LONG
  2020-12-09 15:54 ` [PATCH v1 2/3] tools: remove unused ORDER_LONG Olaf Hering
@ 2020-12-15 16:20   ` Wei Liu
  0 siblings, 0 replies; 8+ messages in thread
From: Wei Liu @ 2020-12-15 16:20 UTC (permalink / raw)
  To: Olaf Hering; +Cc: xen-devel, Ian Jackson, Wei Liu

On Wed, Dec 09, 2020 at 04:54:50PM +0100, Olaf Hering wrote:
> There are no users left, xenpaging has its own variant.
> The last user was removed with commit 11d0044a168994de85b9b328452292852aedc871
> 
> Signed-off-by: Olaf Hering <olaf@aepfle.de>

Acked-by: Wei Liu <wl@xen.org>


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

* Re: [PATCH v1 3/3] tools: add API to work with sevaral bits at once
  2020-12-09 15:54 ` [PATCH v1 3/3] tools: add API to work with sevaral bits at once Olaf Hering
@ 2020-12-15 16:22   ` Wei Liu
  2020-12-15 16:29     ` Olaf Hering
  0 siblings, 1 reply; 8+ messages in thread
From: Wei Liu @ 2020-12-15 16:22 UTC (permalink / raw)
  To: Olaf Hering; +Cc: xen-devel, Ian Jackson, Wei Liu

On Wed, Dec 09, 2020 at 04:54:51PM +0100, Olaf Hering wrote:
> Introduce new API to test if a fixed number of bits is clear or set,
> and clear or set them all at once.
> 
> The caller has to make sure the input bitnumber is a multiply of BITS_PER_LONG.
> 
> This API avoids the loop over each bit in a known range just to see
> if all of them are either clear or set.
> 
> Signed-off-by: Olaf Hering <olaf@aepfle.de>

I would rather these be introduced along side their callers.

> ---
>  tools/libs/ctrl/xc_bitops.h | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h
> index f0bac4a071..92f38872fb 100644
> --- a/tools/libs/ctrl/xc_bitops.h
> +++ b/tools/libs/ctrl/xc_bitops.h
> @@ -77,4 +77,29 @@ static inline void bitmap_or(void *_dst, const void *_other,
>          dst[i] |= other[i];
>  }
>  
> +static inline int test_bit_long_set(unsigned long nr_base, const void *_addr)

What's wrong with requiring the input addr be const unsigned long *?


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

* Re: [PATCH v1 3/3] tools: add API to work with sevaral bits at once
  2020-12-15 16:22   ` Wei Liu
@ 2020-12-15 16:29     ` Olaf Hering
  2020-12-15 16:30       ` Wei Liu
  0 siblings, 1 reply; 8+ messages in thread
From: Olaf Hering @ 2020-12-15 16:29 UTC (permalink / raw)
  To: Wei Liu; +Cc: xen-devel, Ian Jackson

[-- Attachment #1: Type: text/plain, Size: 318 bytes --]

Am Tue, 15 Dec 2020 16:22:44 +0000
schrieb Wei Liu <wl@xen.org>:

> What's wrong with requiring the input addr be const unsigned long *?

Probably nothing. In the end I just borrowed the prototypes from the other functions in this file.

I will resend with this change once I have the consumers ready.

Olaf

[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v1 3/3] tools: add API to work with sevaral bits at once
  2020-12-15 16:29     ` Olaf Hering
@ 2020-12-15 16:30       ` Wei Liu
  0 siblings, 0 replies; 8+ messages in thread
From: Wei Liu @ 2020-12-15 16:30 UTC (permalink / raw)
  To: Olaf Hering; +Cc: Wei Liu, xen-devel, Ian Jackson

On Tue, Dec 15, 2020 at 05:29:17PM +0100, Olaf Hering wrote:
> Am Tue, 15 Dec 2020 16:22:44 +0000
> schrieb Wei Liu <wl@xen.org>:
> 
> > What's wrong with requiring the input addr be const unsigned long *?
> 
> Probably nothing. In the end I just borrowed the prototypes from the other functions in this file.
> 
> I will resend with this change once I have the consumers ready.

Okay.

I will push the first two shortly.

Wei.

> 
> Olaf




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

end of thread, other threads:[~2020-12-15 16:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-09 15:54 [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long Olaf Hering
2020-12-09 15:54 ` [PATCH v1 2/3] tools: remove unused ORDER_LONG Olaf Hering
2020-12-15 16:20   ` Wei Liu
2020-12-09 15:54 ` [PATCH v1 3/3] tools: add API to work with sevaral bits at once Olaf Hering
2020-12-15 16:22   ` Wei Liu
2020-12-15 16:29     ` Olaf Hering
2020-12-15 16:30       ` Wei Liu
2020-12-15 16:11 ` [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long Wei Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).