ealanos: Added flag for debug messages in Superblock.

This commit is contained in:
Michael Mueller
2025-10-17 16:51:08 +02:00
parent e3fff92481
commit 1dd70b3e3e

View File

@@ -12,6 +12,7 @@
#ifndef __INCLUDE__EALANOS__MEMORY__SUPERBLOCK_H_ #ifndef __INCLUDE__EALANOS__MEMORY__SUPERBLOCK_H_
#define __INCLUDE__EALANOS__MEMORY__SUPERBLOCK_H_ #define __INCLUDE__EALANOS__MEMORY__SUPERBLOCK_H_
#include "base/log.h"
#include <ealanos/util/lifo_queue.h> #include <ealanos/util/lifo_queue.h>
#include <base/stdint.h> #include <base/stdint.h>
#include <base/ram_allocator.h> #include <base/ram_allocator.h>
@@ -92,23 +93,28 @@ class Ealan::Memory::Superblock : public Hyperblock
alignas(64) Genode::addr_t _start{0}; /* Start address of the blocks */ alignas(64) Genode::addr_t _start{0}; /* Start address of the blocks */
public: public:
Superblock(Genode::size_t sz) : _size_class(sz) Superblock(Genode::size_t sz, bool debug=false) : _size_class(sz)
{ {
if (_size_class > SIZE) { if (_size_class > SIZE) {
Genode::error("Size class ", _size_class, " is bigger than superblock size ", SIZE); Genode::error("Size class ", _size_class, " is bigger than superblock size ", SIZE);
} }
/*Genode::log("Superblock SIZE=", SIZE, " BASE=", BASE, " this at ", this); Genode::addr_t end = reinterpret_cast<Genode::addr_t>(this) + SIZE - sizeof(Block) - _size_class;
if (debug) {
Genode::log("Superblock SIZE=", SIZE, " BASE=", BASE, " this at ", this);
Genode::log("Block metadata size is ", sizeof(Block)); Genode::log("Block metadata size is ", sizeof(Block));
Genode::log("Size class of superblock is ", _size_class); Genode::log("Size class of superblock is ", _size_class);
Genode::log("Superblock ends at ", reinterpret_cast<void*>(_end)); Genode::log("Superblock ends at ", reinterpret_cast<void*>(end));
Genode::log("Capacity is ", capacity()); Genode::log("Capacity is ", capacity());
Genode::log("-------------------");*/ Genode::log("-------------------");
}
Genode::addr_t end = reinterpret_cast<Genode::addr_t>(this) + SIZE - sizeof(Block) - _size_class;
for (Genode::addr_t block = reinterpret_cast<Genode::addr_t>(&_start); block < end; block += sizeof(Block) + _size_class) { for (Genode::addr_t block = reinterpret_cast<Genode::addr_t>(&_start); block < end; block += sizeof(Block) + _size_class) {
Block *b = reinterpret_cast<Block *>(block); Block *b = reinterpret_cast<Block *>(block);
b->_superblock = this; b->_superblock = this;
_blocks.enqueue(b); _blocks.enqueue(b);
if (debug)
Genode::log("Enqueued block ", b);
} }
} }
@@ -131,13 +137,11 @@ class Ealan::Memory::Superblock : public Hyperblock
} }
Block *block = reinterpret_cast<Block *>(&_start); Block *block = reinterpret_cast<Block *>(&_start);
Block *end = reinterpret_cast<Block *>(reinterpret_cast<Genode::addr_t>(this) + SIZE - 64); Block *end = reinterpret_cast<Block *>(reinterpret_cast<Genode::addr_t>(this) + SIZE -
while (block < end) { 64); while (block < end) { Genode::addr_t next = reinterpret_cast<Genode::addr_t>(block)
Genode::addr_t next = reinterpret_cast<Genode::addr_t>(block) + sizeof(Block) + _size_class; + sizeof(Block) + _size_class; if (block->_superblock == nullptr) { if
if (block->_superblock == nullptr) { (block->reserve(this)) { return reinterpret_cast<void
if (block->reserve(this)) { *>(reinterpret_cast<Genode::addr_t>(block) + 64);
return reinterpret_cast<void *>(reinterpret_cast<Genode::addr_t>(block) +
64);
} }
} }
block = reinterpret_cast<Block *>(next); block = reinterpret_cast<Block *>(next);
@@ -179,8 +183,10 @@ class Ealan::Memory::Superblock : public Hyperblock
Block *b = reinterpret_cast<Block *>(reinterpret_cast<Genode::addr_t>(ptr) - 64); Block *b = reinterpret_cast<Block *>(reinterpret_cast<Genode::addr_t>(ptr) - 64);
Block *end = reinterpret_cast<Block *>(reinterpret_cast<Genode::addr_t>(this) + SIZE); Block *end = reinterpret_cast<Block *>(reinterpret_cast<Genode::addr_t>(this) + SIZE);
if (b > --end) /*if (b > --end && b < reinterpret_cast<Block *>(this)) {
Genode::warning("freeing Block that does not belong to this superblock");
return; return;
}*/
_blocks.enqueue(b); _blocks.enqueue(b);
} }