Skip to contentSkip to conversation

new functions libxl_bitmap_{or,and}

PATCH Superseded Linda Jacobson 3 participants 4 messages Apr 13, 2015 – Apr 14, 2015

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 new functions libxl_bitmap_{or,and}

provide logical and and or of two bitmaps

---

v.1 updated comments and format
v.2 rewrote bitmap functions to manipulate bytes not bits

---
 tools/libxl/libxl_utils.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_utils.h |  5 ++++
 2 files changed, 79 insertions(+)
tools/libxl/libxl_utils.c +74 -0
index 9053b27..5c7178f 100644
@@ -691,6 +691,80 @@ void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit)
     bitmap->map[bit / 8] &= ~(1 << (bit & 7));
 }
 
+/* provide logical or and logical and of two bitmaps */
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map,
+                    libxl_bitmap *map1, libxl_bitmap *map2)
+{
+    GC_INIT(ctx);
+    int rc;
+    uint32_t i;
+    libxl_bitmap *lgmap;
+    libxl_bitmap *smap;
+
+    if (map1->size > map2->size) {
+        lgmap = map1;
+        smap = map2;
+    }
+    else {
+        lgmap = map2;
+        smap = map1;
+    }
+
+    rc = libxl_bitmap_alloc(ctx, or_map, lgmap->size * 8);
+    if (rc)
+        goto out;
+
+    /*
+     *  if bitmaps aren't the same size, their union (logical or) will
+     *  be size of larger bit map.  Any bit past the end of the
+     *  smaller bit map, will match the larger one.
+     */
+    for (i = 0; i < smap->size; i++)
+        or_map->map[i] = (smap->map[i] | lgmap->map[i]);
+
+    for (i = smap->size; i < lgmap->size; i++)
+        or_map->map[i] = lgmap->map[i];
+
+out:
+    GC_FREE;
+    return rc;
+}
+
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
+                     libxl_bitmap *map1, libxl_bitmap *map2)
+{
+    GC_INIT(ctx);    
+    int rc;
+    uint32_t i;
+    libxl_bitmap *lgmap, *smap;
+
+    if (map1->size >  map2->size) {
+        lgmap = map1;
+        smap = map2;
+    }
+    else {
+        lgmap = map2;
+        smap = map1;
+    }
+
+
+    rc = libxl_bitmap_alloc(ctx, and_map, smap->size * 8);
+    if (rc)
+        goto out;
+
+    /* 
+     *  if bitmaps aren't same size, their 'and' will be size of
+     *  smaller bit map
+     */
+    for (i = 0; i < and_map->size; i++)
+        and_map->map[i] = (lgmap->map[i] & smap->map[i]);
+
+out: 
+    GC_FREE;
+    return rc;
+
+}
+
 int libxl_bitmap_count_set(const libxl_bitmap *bitmap)
 {
     int i, nr_set_bits = 0;
tools/libxl/libxl_utils.h +5 -0
index acacdd9..1c0086b 100644
@@ -90,6 +90,11 @@ int libxl_bitmap_test(const libxl_bitmap *bitmap, int bit);
 void libxl_bitmap_set(libxl_bitmap *bitmap, int bit);
 void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit);
 int libxl_bitmap_count_set(const libxl_bitmap *cpumap);
+/* or and and functions for two bitmaps */
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map,
+                    libxl_bitmap *map1, libxl_bitmap *map2); 
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
+                     libxl_bitmap *map1, libxl_bitmap *map2);
 char *libxl_bitmap_to_hex_string(libxl_ctx *ctx, const libxl_bitmap *cpumap);
 static inline void libxl_bitmap_set_any(libxl_bitmap *bitmap)
 {
Signature · 1 line
1.9.1
#1 lore raw

Thanks, we're getting there. If my comments confuse you please just ask for clarification.

There is no need to change the subject line. However, it would be useful if you have some kind of version number in you subject line. That is

[PATCH vX] libxl: provide libxl_bimap_{and,or}

You can do this by supplying --subject-prefix= to git format-patch

git format-patch -1 --subject-prefix="[PATCH vX]" ...

where X refers to your version number.

Quoted 2 lines · Linda Jacobson

provide logical and and or of two bitmaps

And the SoB line should be here.

Quoted 16 lines

---

v.1 updated comments and format
v.2 rewrote bitmap functions to manipulate bytes not bits

---
 tools/libxl/libxl_utils.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_utils.h |  5 ++++
 2 files changed, 79 insertions(+)
tools/libxl/libxl_utils.c +0 -0
index 9053b27..5c7178f 100644

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 694

Quoted 4 lines
tools/libxl/libxl_utils.c +1 -0
@@ -691,6 +691,80 @@ void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit)
     bitmap->map[bit / 8] &= ~(1 << (bit & 7));
 }
 
+/* provide logical or and logical and of two bitmaps */

Normally we take the line before as the comment for the function that follows it. So you don't need to mention "and" function here.

Actually I don't think you need a comment for such obvious function at all.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 696

Quoted 2 lines
tools/libxl/libxl_utils.c +2 -0
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map,
+                    libxl_bitmap *map1, libxl_bitmap *map2)

Actually I think you need to constify map1 and map2. I.e.

const libxl_bitmap *map1,
const libxl_bitmap *map2)

Sorry for not having mentioned these earlier. Since you're going to resend due to other issues so you might as well just take care of these nits.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 703

Quoted 7 lines
tools/libxl/libxl_utils.c +7 -0
+{
+    GC_INIT(ctx);
+    int rc;
+    uint32_t i;
+    libxl_bitmap *lgmap;
+    libxl_bitmap *smap;
+

Constify these as well.

And probably use better name like large_map and small_map?

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 708

Quoted 5 lines
tools/libxl/libxl_utils.c +5 -0
+    if (map1->size > map2->size) {
+        lgmap = map1;
+        smap = map2;
+    }
+    else {

Coding style. Should be

       } else {

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 718

Quoted 10 lines
tools/libxl/libxl_utils.c +10 -0
+        lgmap = map2;
+        smap = map1;
+    }
+
+    rc = libxl_bitmap_alloc(ctx, or_map, lgmap->size * 8);
+    if (rc)
+        goto out;
+
+    /*
+     *  if bitmaps aren't the same size, their union (logical or) will

If

Quoted 6 lines
tools/libxl/libxl_utils.c +6 -0
+     *  be size of larger bit map.  Any bit past the end of the
+     *  smaller bit map, will match the larger one.
+     */
+    for (i = 0; i < smap->size; i++)
+        or_map->map[i] = (smap->map[i] | lgmap->map[i]);
+

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 734

Quoted 10 lines
tools/libxl/libxl_utils.c +10 -0
+    for (i = smap->size; i < lgmap->size; i++)
+        or_map->map[i] = lgmap->map[i];
+
+out:
+    GC_FREE;
+    return rc;
+}
+
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
+                     libxl_bitmap *map1, libxl_bitmap *map2)

Constify map1 and map2.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 739

Quoted 5 lines
tools/libxl/libxl_utils.c +5 -0
+{
+    GC_INIT(ctx);    
+    int rc;
+    uint32_t i;
+    libxl_bitmap *lgmap, *smap;

Constify lgmap and smap.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 708

Quoted 6 lines
tools/libxl/libxl_utils.c +6 -0
+
+    if (map1->size >  map2->size) {
+        lgmap = map1;
+        smap = map2;
+    }
+    else {

Coding style.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 756

Quoted 11 lines
tools/libxl/libxl_utils.c +11 -0
+        lgmap = map2;
+        smap = map1;
+    }
+
+
+    rc = libxl_bitmap_alloc(ctx, and_map, smap->size * 8);
+    if (rc)
+        goto out;
+
+    /* 
+     *  if bitmaps aren't same size, their 'and' will be size of

If

Quoted 19 lines
tools/libxl/libxl_utils.c +11 -0
+     *  smaller bit map
+     */
+    for (i = 0; i < and_map->size; i++)
+        and_map->map[i] = (lgmap->map[i] & smap->map[i]);
+
+out: 
+    GC_FREE;
+    return rc;
+
+}
+
 int libxl_bitmap_count_set(const libxl_bitmap *bitmap)
 {
     int i, nr_set_bits = 0;
tools/libxl/libxl_utils.h +0 -0
index acacdd9..1c0086b 100644

tools/libxl/libxl_utils.h int libxl_bitmap_test(const libxl_bitmap *bitmap, int bit); · line 93

Quoted 4 lines
tools/libxl/libxl_utils.h +1 -0
@@ -90,6 +90,11 @@ int libxl_bitmap_test(const libxl_bitmap *bitmap, int bit);
 void libxl_bitmap_set(libxl_bitmap *bitmap, int bit);
 void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit);
 int libxl_bitmap_count_set(const libxl_bitmap *cpumap);
+/* or and and functions for two bitmaps */

Or

tools/libxl/libxl_utils.h int libxl_bitmap_test(const libxl_bitmap *bitmap, int bit); · line 97

Quoted 4 lines
tools/libxl/libxl_utils.h +4 -0
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map,
+                    libxl_bitmap *map1, libxl_bitmap *map2); 
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
+                     libxl_bitmap *map1, libxl_bitmap *map2);

Constify map1 and map2.

Wei.

Quoted 5 lines
tools/libxl/libxl_utils.h +0 -0
 char *libxl_bitmap_to_hex_string(libxl_ctx *ctx, const libxl_bitmap *cpumap);
 static inline void libxl_bitmap_set_any(libxl_bitmap *bitmap)
 {
Signature · 1 line
1.9.1
author
#2 lore raw
Quoted 7 lines · Wei Liu

Thanks, we're getting there. If my comments confuse you please just ask for clarification.

There is no need to change the subject line. However, it would be useful if you have some kind of version number in you subject line. That is

Quoted 5 lines
    [PATCH vX] libxl: provide libxl_bimap_{and,or}

You can do this by supplying --subject-prefix= to git format-patch

    git format-patch -1 --subject-prefix="[PATCH vX]" ...

What version do you want me to use at this point? I've sort of lost count, since many changes have been style changes. I am assuming you usually reserve new versions for substantive changes?

Quoted 7 lines

where X refers to your version number.

Quoted 2 lines · Linda Jacobson

provide logical and and or of two bitmaps

And the SoB line should be here.

What does SoB stand for in this context?

Quoted 20 lines
Quoted 20 lines

---

v.1 updated comments and format
v.2 rewrote bitmap functions to manipulate bytes not bits

---
  tools/libxl/libxl_utils.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++
  tools/libxl/libxl_utils.h |  5 ++++
  2 files changed, 79 insertions(+)
tools/libxl/libxl_utils.c +0 -0
index 9053b27..5c7178f 100644
@@ -691,6 +691,80 @@ void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit)
      bitmap->map[bit / 8] &= ~(1 << (bit & 7));
  }
 
Quoted 6 lines

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 694

Quoted 1 line
tools/libxl/libxl_utils.c +1 -0
+/* provide logical or and logical and of two bitmaps */

Normally we take the line before as the comment for the function that follows it. So you don't need to mention "and" function here.

Actually I don't think you need a comment for such obvious function at all.

I'll take it out.

Quoted 7 lines

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 696

Quoted 3 lines
tools/libxl/libxl_utils.c +2 -0
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map,
+                    libxl_bitmap *map1, libxl_bitmap *map2)

Actually I think you need to constify map1 and map2. I.e.

const libxl_bitmap *map1,
const libxl_bitmap *map2)

How come? Out of curiosity.

Quoted 15 lines

Sorry for not having mentioned these earlier. Since you're going to resend due to other issues so you might as well just take care of these nits.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 703

Quoted 7 lines
tools/libxl/libxl_utils.c +7 -0
+{
+    GC_INIT(ctx);
+    int rc;
+    uint32_t i;
+    libxl_bitmap *lgmap;
+    libxl_bitmap *smap;
+

Constify these as well.

Quoted 1 line

And probably use better name like large_map and small_map?

OK. Happy to. Earlier someone complained about my names being too verbose.

Linda

Quoted 107 lines

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 708

Quoted 6 lines
tools/libxl/libxl_utils.c +5 -0
+    if (map1->size > map2->size) {
+        lgmap = map1;
+        smap = map2;
+    }
+    else {

Coding style. Should be

        } else {

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 718

Quoted 10 lines
tools/libxl/libxl_utils.c +10 -0
+        lgmap = map2;
+        smap = map1;
+    }
+
+    rc = libxl_bitmap_alloc(ctx, or_map, lgmap->size * 8);
+    if (rc)
+        goto out;
+
+    /*
+     *  if bitmaps aren't the same size, their union (logical or) will

If

Quoted 6 lines
tools/libxl/libxl_utils.c +6 -0
+     *  be size of larger bit map.  Any bit past the end of the
+     *  smaller bit map, will match the larger one.
+     */
+    for (i = 0; i < smap->size; i++)
+        or_map->map[i] = (smap->map[i] | lgmap->map[i]);
+

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 734

Quoted 10 lines
tools/libxl/libxl_utils.c +10 -0
+    for (i = smap->size; i < lgmap->size; i++)
+        or_map->map[i] = lgmap->map[i];
+
+out:
+    GC_FREE;
+    return rc;
+}
+
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
+                     libxl_bitmap *map1, libxl_bitmap *map2)

Constify map1 and map2.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 739

Quoted 5 lines
tools/libxl/libxl_utils.c +5 -0
+{
+    GC_INIT(ctx);
+    int rc;
+    uint32_t i;
+    libxl_bitmap *lgmap, *smap;

Constify lgmap and smap.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 708

Quoted 6 lines
tools/libxl/libxl_utils.c +6 -0
+
+    if (map1->size >  map2->size) {
+        lgmap = map1;
+        smap = map2;
+    }
+    else {

Coding style.

tools/libxl/libxl_utils.c void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) · line 756

Quoted 11 lines
tools/libxl/libxl_utils.c +11 -0
+        lgmap = map2;
+        smap = map1;
+    }
+
+
+    rc = libxl_bitmap_alloc(ctx, and_map, smap->size * 8);
+    if (rc)
+        goto out;
+
+    /*
+     *  if bitmaps aren't same size, their 'and' will be size of

If

Quoted 19 lines
tools/libxl/libxl_utils.c +11 -0
+     *  smaller bit map
+     */
+    for (i = 0; i < and_map->size; i++)
+        and_map->map[i] = (lgmap->map[i] & smap->map[i]);
+
+out:
+    GC_FREE;
+    return rc;
+
+}
+
  int libxl_bitmap_count_set(const libxl_bitmap *bitmap)
  {
      int i, nr_set_bits = 0;
tools/libxl/libxl_utils.h +0 -0
index acacdd9..1c0086b 100644

tools/libxl/libxl_utils.h int libxl_bitmap_test(const libxl_bitmap *bitmap, int bit); · line 93

Quoted 4 lines
tools/libxl/libxl_utils.h +1 -0
@@ -90,6 +90,11 @@ int libxl_bitmap_test(const libxl_bitmap *bitmap, int bit);
  void libxl_bitmap_set(libxl_bitmap *bitmap, int bit);
  void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit);
  int libxl_bitmap_count_set(const libxl_bitmap *cpumap);
+/* or and and functions for two bitmaps */

Or

tools/libxl/libxl_utils.h int libxl_bitmap_test(const libxl_bitmap *bitmap, int bit); · line 97

Quoted 4 lines
tools/libxl/libxl_utils.h +4 -0
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map,
+                    libxl_bitmap *map1, libxl_bitmap *map2);
+int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map,
+                     libxl_bitmap *map1, libxl_bitmap *map2);

Constify map1 and map2.

Wei.

Quoted 5 lines
tools/libxl/libxl_utils.h +0 -0
  char *libxl_bitmap_to_hex_string(libxl_ctx *ctx, const libxl_bitmap *cpumap);
  static inline void libxl_bitmap_set_any(libxl_bitmap *bitmap)
  {
Signature · 1 line
1.9.1
#3 lore raw

Hi Linda,

Hi Linda,

Quoted 8 lines · Linda
Quoted 7 lines · Wei Liu

Thanks, we're getting there. If my comments confuse you please just ask for clarification.

There is no need to change the subject line. However, it would be useful if you have some kind of version number in you subject line. That is

Quoted 7 lines
Quoted 5 lines
    [PATCH vX] libxl: provide libxl_bimap_{and,or}

You can do this by supplying --subject-prefix= to git format-patch

    git format-patch -1 --subject-prefix="[PATCH vX]" ...

What version do you want me to use at this point? I've sort of lost count, since many changes have been style changes.

IIRC, this is the v3, so the next will be v4.

Quoted 1 line

I am assuming you usually reserve new versions for substantive changes?

The version number should be incremented every time you send a new version of the patch to the mailing list.

Quoted 8 lines
Quoted 7 lines

where X refers to your version number.

Quoted 2 lines · Linda Jacobson

provide logical and and or of two bitmaps

And the SoB line should be here.

What does SoB stand for in this context?

Signed-off-by.

As said on a previous mail, everything after "---" will be dropped when the committer will apply your patch to the tree. So your SoB will disappear too.

You have to move it before the "---"

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

---

v.1 updated comments and format
v.2 rewrote bitmap functions to manipulate bytes not bits

[..]

Quoted 8 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map,
+                    libxl_bitmap *map1, libxl_bitmap *map2)

Actually I think you need to constify map1 and map2. I.e.

const libxl_bitmap *map1,
const libxl_bitmap *map2)

How come? Out of curiosity.

You know that the 2 bitmaps won't be modified within function. Constifying them will allow the compiler to catch any attempt to modify the content of the bitmap.

Regards,

Signature · 1 line
Julien Grall