nova: speed up cap selector allocation

Issue #485
This commit is contained in:
Alexander Boettcher
2013-08-27 11:14:49 +02:00
committed by Norman Feske
parent fb2998e534
commit ff29f85cc9
2 changed files with 25 additions and 16 deletions

View File

@ -23,6 +23,7 @@ namespace Genode {
{ {
protected: protected:
addr_t _next;
Bit_array<WORDS> _array; Bit_array<WORDS> _array;
void _reserve(addr_t bit_start, size_t const num_cap) void _reserve(addr_t bit_start, size_t const num_cap)
@ -34,32 +35,40 @@ namespace Genode {
public: public:
Bit_allocator() : _next(0) { }
addr_t alloc(size_t const num_log2) addr_t alloc(size_t const num_log2)
{ {
addr_t const step = 1UL << num_log2; addr_t const step = 1UL << num_log2;
addr_t i = 0; addr_t max = ~0UL;
try { do
/* {
* Throws exception if array is * accessed outside bounds try
*/ {
while (true) { /* throws exception if array is accessed outside bounds */
if (_array.get(i, step)) { for (addr_t i = _next & ~(step - 1); i < max; i += step) {
i += step; if (_array.get(i, step))
continue; continue;
_array.set(i, step);
_next = i + step;
return i;
} }
_array.set(i, step); } catch (Bit_array_invalid_index_access) { }
return i;
} max = _next;
} catch (Bit_array_invalid_index_access) {} _next = 0;
} while (max != 0);
throw Bit_array_out_of_indexes(); throw Bit_array_out_of_indexes();
} }
void free(addr_t const bit_start, void free(addr_t const bit_start, size_t const num_log2)
size_t const num_log2)
{ {
_array.clear(bit_start, 1UL << num_log2); _array.clear(bit_start, 1UL << num_log2);
_next = bit_start;
} }
}; };

View File

@ -48,7 +48,7 @@ void Cap_selector_allocator::free(addr_t cap, size_t num_caps_log2)
} }
Cap_selector_allocator::Cap_selector_allocator() Cap_selector_allocator::Cap_selector_allocator() : Bit_allocator()
{ {
/* initialize lock */ /* initialize lock */
alloc_lock(); alloc_lock();