Skip to content

Conversation

@cjams
Copy link
Contributor

@cjams cjams commented Nov 2, 2021

Add a new bitmap_t that represents an array-based bitmap.
Implement alloc/free and various functions for bitmap operations.
Add div_round_up helper macro for computing the number of longs
that a given bitmap should be.

Signed-off-by: Connor Davis [email protected]

Issue #145

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

include/bitmap.h Outdated
int nbits;
} bitmap_t;

static inline bitmap_t *bitmap_alloc(int nbits) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would place bitmap_alloc() and bitmap_free() into bitmap.c file and declare them as non-inline functions.

include/bitmap.h Outdated
if (NULL == map)
return NULL;

map->word = kmalloc(BITS_TO_LONGS(nbits) * __SIZEOF_LONG__);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better would be kzmalloc(); or add explicit memset(map->word, 0, size)

include/bitmap.h Outdated
int nbits;
} bitmap_t;

static inline bitmap_t *bitmap_alloc(int nbits) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: nbits could be unsigned

include/bitmap.h Outdated
Comment on lines 87 to 70
static inline int bitmap_find_first_clear(const bitmap_t *map) {
if (NULL == map || NULL == map->word)
return INT_MAX;

for (int i = 0; i < BITS_TO_LONGS(map->nbits); i++) {
int ret = __builtin_ffsl(~map->word[i]);
if (0 == ret)
continue;

return i * BITS_PER_LONG + ret - 1;
}

return INT_MAX;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one appears identical to bitmap_find_first_set()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is except for the negation on map->word[i]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I missed that, my bad.

@cjams cjams requested a review from a team as a code owner November 15, 2021 17:12
Add a new bitmap_t that represents an array-based bitmap.
Implement alloc/free and various functions for bitmap operations.
Add div_round_up helper macro for computing the number of longs
that a given bitmap should be.

Signed-off-by: Connor Davis <[email protected]>
Copy link
Contributor

@dkgupta-amzn dkgupta-amzn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@dkgupta-amzn dkgupta-amzn merged commit ffb0e79 into KernelTestFramework:mainline Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants