Skip to content

Commit

Permalink
Support tlm memory alignment on systems with >4k pages
Browse files Browse the repository at this point in the history
  • Loading branch information
janweinstock committed Apr 14, 2024
1 parent a376a69 commit a6e3834
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions include/vcml/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ typedef enum vcml_alignment {

VCML_TYPEINFO(alignment);

inline vcml_alignment host_page_alignment() {
static const size_t pgsz = mwr::get_page_size();
return pgsz ? (vcml_alignment)ctz(pgsz) : VCML_ALIGN_NONE;
}

istream& operator>>(istream& is, alignment& a);
ostream& operator<<(ostream& os, alignment a);

Expand Down
6 changes: 3 additions & 3 deletions src/vcml/protocols/tlm_memory_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ tlm_memory::~tlm_memory() {
void tlm_memory::init(const string& shared, size_t size, alignment al) {
VCML_ERROR_ON(m_size, "memory already initialized");

// mmap automatically aligns up to 4k, for larger alignments we
// reserve extra space to include an aligned start address plus size
u64 extra = (al > VCML_ALIGN_4K) ? (1ull << al) - 1 : 0;
// mmap automatically aligns up to host page size, for larger alignments
// we reserve extra space to include an aligned start address plus size
u64 extra = (al > host_page_alignment()) ? (1ull << al) - 1 : 0;
m_size = size + extra;

int fd = -1;
Expand Down

0 comments on commit a6e3834

Please sign in to comment.