Welcome! Log In Create A New Profile

Advanced

[PATCH 1/7] tools lib: Add bitmap_alloc function

Posted by Jiri Olsa 
Jiri Olsa
[PATCH 1/7] tools lib: Add bitmap_alloc function
December 13, 2016 05:58AM
Adding bitmap_alloc function to dynamically allocate bitmap.

Link: http:[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/include/linux/bitmap.h | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h
index 28f5493da491..66ddd992e690 100644
--- a/tools/include/linux/bitmap.h
+++ b/tools/include/linux/bitmap.h
@@ -3,6 +3,7 @@

#include <string.h>
#include <linux/bitops.h>
+#include <stdlib.h>

#define DECLARE_BITMAP(name,bits) \
unsigned long name[BITS_TO_LONGS(bits)]
@@ -65,4 +66,13 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)
return (old & mask) != 0;
}

+/**
+ * bitmap_alloc - Allocate bitmap
+ * @nr: Bit to set
+ */
+static inline unsigned long *bitmap_alloc(int nbits)
+{
+ return malloc(BITS_TO_LONGS(nbits) * sizeof(unsigned long));
+}
+
#endif /* _PERF_BITOPS_H */
--
2.4.11
David Ahern
Re: [PATCH 1/7] tools lib: Add bitmap_alloc function
December 13, 2016 05:58AM
On 8/1/16 12:02 PM, Jiri Olsa wrote:
> @@ -65,4 +66,13 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)
> return (old & mask) != 0;
> }
>
> +/**
> + * bitmap_alloc - Allocate bitmap
> + * @nr: Bit to set
> + */
> +static inline unsigned long *bitmap_alloc(int nbits)
> +{
> + return malloc(BITS_TO_LONGS(nbits) * sizeof(unsigned long));
> +}
> +
> #endif /* _PERF_BITOPS_H */

calloc? Can't imagine any user wanting an uninitialized bitmap.
Jiri Olsa
Re: [PATCH 1/7] tools lib: Add bitmap_alloc function
December 13, 2016 05:58AM
On Mon, Aug 01, 2016 at 12:45:18PM -0600, David Ahern wrote:
> On 8/1/16 12:02 PM, Jiri Olsa wrote:
> > @@ -65,4 +66,13 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)
> > return (old & mask) != 0;
> > }
> >
> > +/**
> > + * bitmap_alloc - Allocate bitmap
> > + * @nr: Bit to set
> > + */
> > +static inline unsigned long *bitmap_alloc(int nbits)
> > +{
> > + return malloc(BITS_TO_LONGS(nbits) * sizeof(unsigned long));
> > +}
> > +
> > #endif /* _PERF_BITOPS_H */
>
> calloc? Can't imagine any user wanting an uninitialized bitmap.

hum, right.. all my code used bitmap_zero,
but zalloc would be better choice in here

thanks,
jirka
Jiri Olsa
[PATCHv2 1/7] tools lib: Add bitmap_alloc function
December 13, 2016 05:59AM
On Tue, Aug 02, 2016 at 11:33:59AM +0200, Jiri Olsa wrote:
> On Mon, Aug 01, 2016 at 12:45:18PM -0600, David Ahern wrote:
> > On 8/1/16 12:02 PM, Jiri Olsa wrote:
> > > @@ -65,4 +66,13 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)
> > > return (old & mask) != 0;
> > > }
> > >
> > > +/**
> > > + * bitmap_alloc - Allocate bitmap
> > > + * @nr: Bit to set
> > > + */
> > > +static inline unsigned long *bitmap_alloc(int nbits)
> > > +{
> > > + return malloc(BITS_TO_LONGS(nbits) * sizeof(unsigned long));
> > > +}
> > > +
> > > #endif /* _PERF_BITOPS_H */
> >
> > calloc? Can't imagine any user wanting an uninitialized bitmap.
>
> hum, right.. all my code used bitmap_zero,
> but zalloc would be better choice in here

v2 attached, thanks

jirka


---
Adding bitmap_alloc function to dynamically allocate bitmap.

Link: http:[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
---
tools/include/linux/bitmap.h | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h
index 28f5493da491..60c44b615902 100644
--- a/tools/include/linux/bitmap.h
+++ b/tools/include/linux/bitmap.h
@@ -3,6 +3,7 @@

#include <string.h>
#include <linux/bitops.h>
+#include <stdlib.h>

#define DECLARE_BITMAP(name,bits) \
unsigned long name[BITS_TO_LONGS(bits)]
@@ -65,4 +66,13 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)
return (old & mask) != 0;
}

+/**
+ * bitmap_alloc - Allocate bitmap
+ * @nr: Bit to set
+ */
+static inline unsigned long *bitmap_alloc(int nbits)
+{
+ return calloc(1, BITS_TO_LONGS(nbits) * sizeof(unsigned long));
+}
+
#endif /* _PERF_BITOPS_H */
--
2.4.11
Jiri Olsa
Re: [PATCHv2 1/7] tools lib: Add bitmap_alloc function
December 13, 2016 05:59AM
On Tue, Aug 02, 2016 at 09:56:16AM -0300, Arnaldo Carvalho de Melo wrote:
> Em Tue, Aug 02, 2016 at 01:33:02PM +0200, Jiri Olsa escreveu:
> > ---
> > Adding bitmap_alloc function to dynamically allocate bitmap.
>
> Why should we deviate from the kernel way of doing things, where, AFAIK,
> there is no such bitmap_alloc() function?

well, because I need it dynamically allocated and calling
bitmap_alloc(nbits) seems more reasonable to me than calling
the calloc below

jirka

>
> [[email protected] linux]$ find . -type f | xargs grep -w bitmap_alloc
> [[email protected] linux]$
>
> - Arnaldo
>
> > Link: http:[email protected]
> > Signed-off-by: Jiri Olsa <[email protected]>
> > ---
> > tools/include/linux/bitmap.h | 10 ++++++++++
> > 1 file changed, 10 insertions(+)
> >
> > diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h
> > index 28f5493da491..60c44b615902 100644
> > --- a/tools/include/linux/bitmap.h
> > +++ b/tools/include/linux/bitmap.h
> > @@ -3,6 +3,7 @@
> >
> > #include <string.h>
> > #include <linux/bitops.h>
> > +#include <stdlib.h>
> >
> > #define DECLARE_BITMAP(name,bits) \
> > unsigned long name[BITS_TO_LONGS(bits)]
> > @@ -65,4 +66,13 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)
> > return (old & mask) != 0;
> > }
> >
> > +/**
> > + * bitmap_alloc - Allocate bitmap
> > + * @nr: Bit to set
> > + */
> > +static inline unsigned long *bitmap_alloc(int nbits)
> > +{
> > + return calloc(1, BITS_TO_LONGS(nbits) * sizeof(unsigned long));
> > +}
> > +
> > #endif /* _PERF_BITOPS_H */
> > --
> > 2.4.11
Sorry, only registered users may post in this forum.

Click here to login