Repository navigation
memory: added requesting alignment for buffer heap #1694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,10 @@ struct block_hdr { | |
| uint16_t used; /* usage flags for page */ | ||
| } __packed; | ||
|
|
||
| struct alignment_hdr { | ||
| uint32_t alignment_shift; | ||
| }; | ||
|
|
||
| struct block_map { | ||
| uint16_t block_size; /* size of block in bytes */ | ||
| uint16_t count; /* number of blocks in map */ | ||
|
|
@@ -105,9 +109,10 @@ struct mm { | |
| /* heap allocation and free */ | ||
| void *_malloc(int zone, uint32_t caps, size_t bytes); | ||
| void *_zalloc(int zone, uint32_t caps, size_t bytes); | ||
| void *_balloc(int zone, uint32_t caps, size_t bytes); | ||
| void *_balloc(int zone, uint32_t caps, size_t bytes, uint32_t alignment); | ||
|
dabekjakub marked this conversation as resolved.
Resolved
|
||
| void *_realloc(void *ptr, int zone, uint32_t caps, size_t bytes); | ||
| void *_brealloc(void *ptr, int zone, uint32_t caps, size_t bytes); | ||
| void *_brealloc(void *ptr, int zone, uint32_t caps, size_t bytes, | ||
| uint32_t alignment); | ||
| void rfree(void *ptr); | ||
|
|
||
| #if CONFIG_DEBUG_HEAP | ||
|
|
@@ -143,7 +148,7 @@ void rfree(void *ptr); | |
| #define rballoc(zone, caps, bytes) \ | ||
| ({void *_ptr; \ | ||
| do { \ | ||
| _ptr = _balloc(zone, caps, bytes); \ | ||
| _ptr = _balloc(zone, caps, bytes, 0); \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default alignment should be cache line size. It will be due to the buffer placement, but it's always better to show it explicitly. |
||
| if (!_ptr) { \ | ||
| trace_error(TRACE_CLASS_MEM, \ | ||
| "failed to alloc 0x%x bytes caps 0x%x", \ | ||
|
|
@@ -169,7 +174,33 @@ void rfree(void *ptr); | |
| #define rbrealloc(ptr, zone, caps, bytes) \ | ||
| ({void *_ptr; \ | ||
| do { \ | ||
| _ptr = _brealloc(ptr, zone, caps, bytes); \ | ||
| _ptr = _brealloc(ptr, zone, caps, bytes, 0); \ | ||
| if (!_ptr) { \ | ||
| trace_error(TRACE_CLASS_MEM, \ | ||
| "failed to alloc 0x%x bytes caps 0x%x", \ | ||
| bytes, caps); \ | ||
| alloc_trace_buffer_heap(zone, caps, bytes); \ | ||
| } \ | ||
| } while (0); \ | ||
| _ptr; }) | ||
|
|
||
| #define rbrealloc_a(ptr, zone, caps, bytes, alignment) \ | ||
| ({void *_ptr; \ | ||
| do { \ | ||
| _ptr = _brealloc(ptr, zone, caps, bytes, alignment); \ | ||
| if (!_ptr) { \ | ||
| trace_error(TRACE_CLASS_MEM, \ | ||
| "failed to alloc 0x%x bytes caps 0x%x", \ | ||
| bytes, caps); \ | ||
| alloc_trace_buffer_heap(zone, caps, bytes); \ | ||
| } \ | ||
| } while (0); \ | ||
| _ptr; }) | ||
|
|
||
| #define rballoc(zone, caps, bytes, alignment) \ | ||
| ({void *_ptr; \ | ||
| do { \ | ||
| _ptr = _balloc(zone, caps, bytes, alignment); \ | ||
| if (!_ptr) { \ | ||
| trace_error(TRACE_CLASS_MEM, \ | ||
| "failed to alloc 0x%x bytes caps 0x%x", \ | ||
|
|
@@ -186,11 +217,16 @@ void alloc_trace_buffer_heap(int zone, uint32_t caps, size_t bytes); | |
|
|
||
| #define rmalloc(zone, caps, bytes) _malloc(zone, caps, bytes) | ||
| #define rzalloc(zone, caps, bytes) _zalloc(zone, caps, bytes) | ||
| #define rballoc(zone, caps, bytes) _balloc(zone, caps, bytes) | ||
| #define rballoc(zone, caps, bytes) _balloc(zone, caps, bytes, 0) | ||
| #define rballoc_a(zone, caps, bytes, alignment) \ | ||
| _balloc(zone, caps, bytes, alignment) | ||
| #define rrealloc(ptr, zone, caps, bytes) \ | ||
| _realloc(ptr, zone, caps, bytes) | ||
| #define rbrealloc(ptr, zone, caps, bytes) \ | ||
| _brealloc(ptr, zone, caps, bytes) | ||
| _brealloc(ptr, zone, caps, bytes, 0) | ||
| #define rbrealloc_a(ptr, zone, caps, bytes, alignment) \ | ||
| _brealloc(ptr, zone, caps, bytes, alignment) | ||
|
|
||
|
dabekjakub marked this conversation as resolved.
Resolved
|
||
|
|
||
| #endif | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit message is empty? Please give more information about why this change is needed. Also please use imperative mood as pointed out in a previous comment.
So, please use something like this:
I am pretty sure everything is clear for you because you worked on that. But please have mercy on some poor
guys wanting to understand the code on months later.